This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

# Math.Vector4

A high performance linear algebra library using native JS arrays. Geared towards 3D graphics and use with `Graphics.WebGL`. All vectors are immutable.

# Create

type Vec4 = Vec4

Four dimensional vector type

vec4 : Float -> Float -> Float -> Float -> Vec4

Creates a new 4-element vector with the given x, y, z, and w values.

# Get and Set

The set functions create a new copy of the vector, updating a single field.

getX : Vec4 -> Float

Extract the x component of a vector.

getY : Vec4 -> Float

Extract the y component of a vector.

getZ : Vec4 -> Float

Extract the z component of a vector.

getW : Vec4 -> Float

Extract the w component of a vector.

setX : Float -> Vec4 -> Vec4

Update the x component of a vector, returning a new vector.

setY : Float -> Vec4 -> Vec4

Update the y component of a vector, returning a new vector.

setZ : Float -> Vec4 -> Vec4

Update the z component of a vector, returning a new vector.

setW : Float -> Vec4 -> Vec4

Update the w component of a vector, returning a new vector.

# Operations

add : Vec4 -> Vec4 -> Vec4

Vector addition: a + b

sub : Vec4 -> Vec4 -> Vec4

Vector subtraction: a - b

negate : Vec4 -> Vec4

Vector negation: -a

scale : Float -> Vec4 -> Vec4

Multiply the vector by a scalar: s * v

dot : Vec4 -> Vec4 -> Float

The dot product of a and b

normalize : Vec4 -> Vec4

A unit vector with the same direction as the given vector: a / |a|

direction : Vec4 -> Vec4 -> Vec4

The normalized direction from b to a: (a - b) / |a - b|

length, lengthSquared, distance, distanceSquared

# Conversions

toTuple : Vec4 -> ( Float, Float, Float, Float )

Convert a vector to a tuple.

fromTuple : ( Float, Float, Float, Float ) -> Vec4

Convert a tuple to a vector.

toRecord : Vec4 -> { x : Float, y : Float, z : Float, w : Float }

Convert a vector to a record.

fromRecord : { x : Float, y : Float, z : Float, w : Float } -> Vec4

Convert a record to a vector.

``````module Math.Vector4
exposing
( Vec4
, vec4
, getX
, getY
, getZ
, getW
, setX
, setY
, setZ
, setW
, sub
, negate
, scale
, dot
, normalize
, direction
, length
, lengthSquared
, distance
, distanceSquared
, toTuple
, fromTuple
, toRecord
, fromRecord
)

{-| 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

{-| 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
```
```