justgook/alt-linear-algebra/1.0.0

NOTE: the latest version is 2.0.0

AltMath.Vector2

Create

type alias 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

Vector addition: a + b

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 b to a: (a - b) / |a - b|

mul : Vec2 -> Vec2 -> Vec2

Multiply the vector by a vector: a * b

length : Vec2 -> Float

The length of the given vector: |a|

lengthSquared : Vec2 -> Float

The square of the length of the given vector: |a| * |a|

distance : Vec2 -> Vec2 -> Float

The distance between two vectors.

distanceSquared : Vec2 -> Vec2 -> Float

The square of the distance between two vectors.

Conversions

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

Convert a vector to a record.

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

Convert a record to a vector.