A high performance linear algebra library using native Elm ADT.
Two dimensional vector type
vec2 : a -> a -> Vec a
Creates a new 2-element vector with the given values.
The set functions create a new copy of the vector, updating a single field.
getX : Vec a -> a
Extract the x component of a vector.
getY : Vec a -> a
Extract the y component of a vector.
setX : a -> Vec a -> Vec a
Update the x component of a vector, returning a new vector.
setY : a -> Vec a -> Vec a
Update the y component of a vector, returning a new vector.
add : Vec number -> Vec number -> Vec number
Vector addition: a + b
sub : Vec number -> Vec number -> Vec number
Vector subtraction: a - b
negate : Vec number -> Vec number
Vector negation: -a
scale : number -> Vec number -> Vec number
Multiply the vector by a scalar: s * v
divBy : Basics.Float -> Vec Basics.Float -> Vec Basics.Float
Divide the vector by a scalar: v / s
Shorthand for scale (1 / s)
dot : Vec number -> Vec number -> number
The dot product of a and b
mul : Vec number -> Vec number -> Vec number
Component-wise multiplication
normalize : Vec Basics.Float -> Vec Basics.Float
A unit vector with the same direction as the given vector: a / |a|
direction : Vec Basics.Float -> Vec Basics.Float -> Vec Basics.Float
The normalized direction from b to a: (a - b) / |a - b|
length : Vec Basics.Float -> Basics.Float
The length of the given vector: |a|
lengthSquared : Vec number -> number
The square of the length of the given vector: |a| * |a|
distance : Vec Basics.Float -> Vec Basics.Float -> Basics.Float
The distance between two vectors.
distanceSquared : Vec number -> Vec number -> number
The square of the distance between two vectors.
mapX : (a -> a) -> Vec a -> Vec a
Map a fn to the x value
mapY : (a -> a) -> Vec a -> Vec a
Map a fn to the y value
map : (a -> b) -> Vec a -> Vec b
Map a fn to the x and y value
apply : Vec (a -> b) -> Vec a -> Vec b
lift2 : (a -> b -> c) -> Vec a -> Vec b -> Vec c
Lift a binary function to vectors.
lift2 (+) (Vec 1 1) (Vec 2 2)
--> Vec 3 3 : Vec number
Keep in mind that this comes at a cost of doing a step extra and if you need performance, you might be better off deconstructing and applying the function manually.
lift3 : (a -> b -> c -> d) -> Vec a -> Vec b -> Vec c -> Vec d
toRecord : Vec a -> { x : a, y : a }
Convert a vector to a record.
fromRecord : { x : a, y : a } -> Vec a
Construct a vector from a record.
fromTuple : ( a, a ) -> Vec a
Construct a vector from a tuple.
toFloat : Vec Basics.Int -> Vec Basics.Float
Convert an integer vector into a float vector.
round : Vec Basics.Float -> Vec Basics.Int
Round the number components to the nearest integer.
floor : Vec Basics.Float -> Vec Basics.Int
Floor function, rounding down.
ceiling : Vec Basics.Float -> Vec Basics.Int
Ceiling function, rounding up.
truncate : Vec Basics.Float -> Vec Basics.Int
Truncate the number components, rounding towards zero.