math/vec2
src/math/vec2.tur
defn
vec2
(vec2 [x :float y :float] :int)
construct a 2D vector.
Parameters
| x | x component | |
| y | y component |
Returns
Opaque :int handle to a heap-allocated Vec2.
Example
(vec2 1.0 2.0)
Since: P1
defn
v2-x
(v2-x [v :int] :float)
get the x component.
defn
v2-y
(v2-y [v :int] :float)
get the y component.
defn
v2-add
(v2-add [a :int b :int] :int)
add two Vec2 values.
Parameters
| a | first vector | |
| b | second vector |
Returns
New Vec2 representing a + b.
Example
(v2-add (vec2 1.0 2.0) (vec2 3.0 4.0)) ; => (4.0, 6.0)
Since: P1
defn
v2-sub
(v2-sub [a :int b :int] :int)
subtract two Vec2 values.
Since: P1
defn
v2-scale
(v2-scale [v :int s :float] :int)
scale a Vec2 by a scalar.
Parameters
| v | vector | |
| s | scalar factor |
Returns
New Vec2 with each component multiplied by s.
Example
(v2-scale (vec2 1.0 2.0) 3.0) ; => (3.0, 6.0)
Since: P1
defn
v2-dot
(v2-dot [a :int b :int] :float)
dot product of two Vec2 values.
Since: P1
defn
v2-length
(v2-length [v :int] :float)
Euclidean length of a Vec2.
Since: P1
defn
v2-normalize
(v2-normalize [v :int] :int)
return a unit-length Vec2.
Since: P1
defn
v2-lerp
(v2-lerp [a :int b :int t :float] :int)
linearly interpolate between two Vec2 values.
Parameters
| a | start vector | |
| b | end vector | |
| t | interpolation factor (0.0=a, 1.0=b) |
Since: P1