Pebble.Game.Math

Small math helpers for game and animation code.

Vectors

Vec2

type alias Vec2 =
    { x : Float
    , y : Float
    }

Two-dimensional floating-point vector.

vec2

vec2 : Float -> Float -> Vec2

Construct a vector from x/y components.

add

add : Vec2 -> Vec2 -> Vec2

Add two vectors.

sub

sub : Vec2 -> Vec2 -> Vec2

Subtract the second vector from the first.

scale

scale : Float -> Vec2 -> Vec2

Scale a vector by a scalar factor.

lengthSquared

lengthSquared : Vec2 -> Float

Squared vector length.

Use this when comparing distances without needing the square root.

distanceSquared

distanceSquared : Vec2 -> Vec2 -> Float

Squared distance between two vectors.

Scalars

clamp

clamp : comparable -> comparable -> comparable -> comparable

Clamp a value between lower and upper bounds.