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

# Math.Vector2

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 Vec2 = Vec2

Two dimensional vector type

vec2 : Float -> Float -> Vec2

Creates a new 2-element vector with the given values.

# Get and Set

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

getX : Vec2 -> Float

Extract the x component of a vector.

getY : Vec2 -> Float

Extract the y component of a vector.

setX : Float -> Vec2 -> Vec2

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

setY : Float -> Vec2 -> Vec2

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

# Operations

add : Vec2 -> Vec2 -> Vec2

sub : Vec2 -> Vec2 -> Vec2

Vector subtraction: a - b

negate : Vec2 -> Vec2

Vector negation: -a

scale : Float -> Vec2 -> Vec2

Multiply the vector by a scalar: s * v

dot : Vec2 -> Vec2 -> Float

The dot product of a and b

normalize : Vec2 -> Vec2

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

direction : Vec2 -> Vec2 -> Vec2

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

length, lengthSquared, distance, distanceSquared

# Conversions

toTuple : Vec2 -> (Float,Float)

Convert a vector to a tuple.

fromTuple : (Float,Float) -> Vec2

Convert a tuple to a vector.

toRecord : Vec2 -> { x:Float, y:Float }

Convert a vector to a record.

fromRecord : { x:Float, y:Float } -> Vec2

Convert a record to a vector.

``````module Math.Vector2 where
{-| 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 Vec2, vec2

# Get and Set
The set functions create a new copy of the vector, updating a single field.

@docs getX, getY, setX, setY

# Operations
@docs add, sub, negate, scale, dot, normalize, direction,
length, lengthSquared, distance, distanceSquared

# Conversions
@docs toTuple, fromTuple, toRecord, fromRecord
-}

import Native.Math.Vector2

{-| Two dimensional vector type -}
type Vec2 = Vec2

{-| Creates a new 2-element vector with the given values. -}
vec2 : Float -> Float -> Vec2
vec2 = Native.Math.Vector2.vec2

{-| Extract the x component of a vector. -}
getX : Vec2 -> Float
getX = Native.Math.Vector2.getX

{-| Extract the y component of a vector. -}
getY : Vec2 -> Float
getY = Native.Math.Vector2.getY

{-| Update the x component of a vector, returning a new vector. -}
setX : Float -> Vec2 -> Vec2
setX = Native.Math.Vector2.setX

{-| Update the y component of a vector, returning a new vector. -}
setY : Float -> Vec2 -> Vec2
setY = Native.Math.Vector2.setY

{-| Convert a vector to a tuple. -}
toTuple : Vec2 -> (Float,Float)
toTuple = Native.Math.Vector2.toTuple

{-| Convert a vector to a record. -}
toRecord : Vec2 -> { x:Float, y:Float }
toRecord = Native.Math.Vector2.toRecord

{-| Convert a tuple to a vector. -}
fromTuple : (Float,Float) -> Vec2
fromTuple = Native.Math.Vector2.fromTuple

{-| Convert a record to a vector. -}
fromRecord : { x:Float, y:Float } -> Vec2
fromRecord = Native.Math.Vector2.fromRecord

{-| Vector addition: a + b -}
add : Vec2 -> Vec2 -> Vec2

{-| Vector subtraction: a - b -}
sub : Vec2 -> Vec2 -> Vec2
sub = Native.Math.Vector2.sub

{-| Vector negation: -a -}
negate : Vec2 -> Vec2
negate = Native.Math.Vector2.neg

{-| The normalized direction from a to b: (a - b) / |a - b| -}
direction : Vec2 -> Vec2 -> Vec2
direction = Native.Math.Vector2.direction

{-| The length of the given vector: |a| -}
length : Vec2 -> Float
length = Native.Math.Vector2.length

{-| The square of the length of the given vector: |a| * |a| -}
lengthSquared : Vec2 -> Float
lengthSquared = Native.Math.Vector2.lengthSquared

{-| The distance between two vectors. -}
distance : Vec2 -> Vec2 -> Float
distance = Native.Math.Vector2.distance

{-| The square of the distance between two vectors. -}
distanceSquared : Vec2 -> Vec2 -> Float
distanceSquared = Native.Math.Vector2.distanceSquared

{-| A unit vector with the same direction as the given vector: a / |a| -}
normalize : Vec2 -> Vec2
normalize = Native.Math.Vector2.normalize

{-| Multiply the vector by a scalar: s * v -}
scale : Float -> Vec2 -> Vec2
scale = Native.Math.Vector2.scale

{-| The dot product of a and b -}
dot : Vec2 -> Vec2 -> Float
dot = Native.Math.Vector2.dot

```
```