Basic, fast linear algebra operations for working with vectors in Elm.
If you do not work with WebGl, you can use this as a much faster alternative than the elm-explorations/linear-algebra package. See Benchmarks for some performance comparisons. You can use this package as a drop-in replacement of the beforementionend.
a : Vec Float
a =
vec2 1 2
doSomeMath : Vec Float -> Vec Float
doSomeMath b =
b
|> sub a
|> add (vec2 3 4)
|> normalize
|> scale 5
result : Vec Float
result =
doSomeMath (Vec 5 6) --> Vec -5 0 : Vec Float
You can work with integer vectors as well, although most calculations require floats.
In that case it useful to convert it to an integer vector at the first and last step:
doSomeIntMath : Vec Int -> Vec Int
doSomeIntMath =
Math.Vector2.round << doSomeMath << Math.Vector2.toFloat
- elm-explorations/linear-algebra: Way slower, but required for Elm-WebGl.
- justgook/alt-linear-algebra: Uses slower records and only works with floats.
- jjant/linear-algebra: Uses slower records and only works with floats.