A high performance linear algebra library using native JS arrays. Geared
towards 3D graphics and use with Graphics.WebGL
. All vectors are immutable.
Four dimensional vector type
Creates a new 4-element vector with the given x, y, z, and w values.
The set functions create a new copy of the vector, updating a single field.
Extract the x component of a vector.
Extract the y component of a vector.
Extract the z component of a vector.
Extract the w component of a vector.
Update the x component of a vector, returning a new vector.
Update the y component of a vector, returning a new vector.
Update the z component of a vector, returning a new vector.
Update the w component of a vector, returning a new vector.
Vector addition: a + b
Vector subtraction: a - b
Vector negation: -a
Multiply the vector by a scalar: s * v
The dot product of a and b
A unit vector with the same direction as the given vector: a / |a|
The normalized direction from b to a: (a - b) / |a - b|
length, lengthSquared, distance, distanceSquared
Convert a vector to a tuple.
Convert a tuple to a vector.
Convert a vector to a record.
Convert a record to a vector.
module Math.Vector4 exposing (..)
{-| A high performance linear algebra library using native JS arrays. Geared
towards 3D graphics and use with `Graphics.WebGL`. All vectors are immutable.
# Create
@docs Vec4, vec4
# Get and Set
The set functions create a new copy of the vector, updating a single field.
@docs getX, getY, getZ, getW, setX, setY, setZ, setW
# Operations
@docs add, sub, negate, scale, dot, normalize, direction,
length, lengthSquared, distance, distanceSquared
# Conversions
@docs toTuple, fromTuple, toRecord, fromRecord
-}
import Native.Math.Vector4
{-| Four dimensional vector type -}
type Vec4 = Vec4
{-| Creates a new 4-element vector with the given x, y, z, and w values. -}
vec4 : Float -> Float -> Float -> Float -> Vec4
vec4 = Native.Math.Vector4.vec4
{-| Extract the x component of a vector. -}
getX : Vec4 -> Float
getX = Native.Math.Vector4.getX
{-| Extract the y component of a vector. -}
getY : Vec4 -> Float
getY = Native.Math.Vector4.getY
{-| Extract the z component of a vector. -}
getZ : Vec4 -> Float
getZ = Native.Math.Vector4.getZ
{-| Extract the w component of a vector. -}
getW : Vec4 -> Float
getW = Native.Math.Vector4.getW
{-| Update the x component of a vector, returning a new vector. -}
setX : Float -> Vec4 -> Vec4
setX = Native.Math.Vector4.setX
{-| Update the y component of a vector, returning a new vector. -}
setY : Float -> Vec4 -> Vec4
setY = Native.Math.Vector4.setY
{-| Update the z component of a vector, returning a new vector. -}
setZ : Float -> Vec4 -> Vec4
setZ = Native.Math.Vector4.setZ
{-| Update the w component of a vector, returning a new vector. -}
setW : Float -> Vec4 -> Vec4
setW = Native.Math.Vector4.setW
{-| Convert a vector to a tuple. -}
toTuple : Vec4 -> (Float,Float,Float,Float)
toTuple = Native.Math.Vector4.toTuple
{-| Convert a vector to a record. -}
toRecord : Vec4 -> { x:Float, y:Float, z:Float, w:Float }
toRecord = Native.Math.Vector4.toRecord
{-| Convert a tuple to a vector. -}
fromTuple : (Float,Float,Float,Float) -> Vec4
fromTuple = Native.Math.Vector4.fromTuple
{-| Convert a record to a vector. -}
fromRecord : { x:Float, y:Float, z:Float, w:Float } -> Vec4
fromRecord = Native.Math.Vector4.fromRecord
{-| Vector addition: a + b -}
add : Vec4 -> Vec4 -> Vec4
add = Native.Math.Vector4.add
{-| Vector subtraction: a - b -}
sub : Vec4 -> Vec4 -> Vec4
sub = Native.Math.Vector4.sub
{-| Vector negation: -a -}
negate : Vec4 -> Vec4
negate = Native.Math.Vector4.neg
{-| The normalized direction from b to a: (a - b) / |a - b| -}
direction : Vec4 -> Vec4 -> Vec4
direction = Native.Math.Vector4.direction
{-| The length of the given vector: |a| -}
length : Vec4 -> Float
length = Native.Math.Vector4.length
{-| The square of the length of the given vector: |a| * |a| -}
lengthSquared : Vec4 -> Float
lengthSquared = Native.Math.Vector4.lengthSquared
{-| The distance between two vectors. -}
distance : Vec4 -> Vec4 -> Float
distance = Native.Math.Vector4.distance
{-| The square of the distance between two vectors. -}
distanceSquared : Vec4 -> Vec4 -> Float
distanceSquared = Native.Math.Vector4.distanceSquared
{-| A unit vector with the same direction as the given vector: a / |a| -}
normalize : Vec4 -> Vec4
normalize = Native.Math.Vector4.normalize
{-| Multiply the vector by a scalar: s * v -}
scale : Float -> Vec4 -> Vec4
scale = Native.Math.Vector4.scale
{-| The dot product of a and b -}
dot : Vec4 -> Vec4 -> Float
dot = Native.Math.Vector4.dot