Construct a three-dimensional vector.
Math
Small 2D vector and rectangle helpers.
Coordinates follow Draw: x increases rightward and y downward. Rectangles
use a top-left position, width, and height.
next = model.position.add(model.velocity.scale(input.time.elapsed_seconds))
Construct a four-dimensional vector.
Construct a two-dimensional vector.
zero : Vec2
The zero vector.
Construct an axis-aligned rectangle.
Construct a circle.
Clamp a value to inclusive lower and upper bounds.
Clamp a value to the inclusive 0-to-1 range.
Linearly interpolate between two scalars; amounts outside 0 to 1 extrapolate.
Square root for game-scale F32 values. Roc's pinned builtins do not expose sqrt yet, so keep this pure Roc.
add : Vec2, Vec2 -> Vec2
Add two vectors component-wise.
sub : Vec2, Vec2 -> Vec2
Subtract two vectors component-wise.
Multiply both vector components by a scalar.
Compute the vector dot product.
length_squared : Vec2 -> F32
Squared vector length, avoiding a square root.
Euclidean vector length.
distance_squared : Vec2, Vec2 -> F32
Squared distance between two points.
Euclidean distance between two points.
normalize : Vec2 -> Vec2
Return a unit vector, or zero when the input has zero length.
Linearly interpolate between two vectors.
Left edge of a rectangle.
Right edge of a rectangle.
Top edge of a rectangle.
Bottom edge of a rectangle.
center : Rect -> Vec2
Center point of a rectangle.
closest_point : Rect, Vec2 -> Vec2
Closest point in or on a rectangle.
Whether a rectangle contains a point, including its edges.
circle_contains : Circle, Vec2 -> Bool
Whether a circle contains a point, including its edge.
Whether two rectangles overlap or touch.
circle_overlaps : Circle, Circle -> Bool
Whether two circles overlap or touch.
circle_rect : Circle, Rect -> Bool
Whether a circle and rectangle overlap or touch.
contains_point : Circle, Vec2 -> Bool
Receiver-friendly aliases for circle queries. The longer names avoid ambiguity with the corresponding rectangle methods.
overlaps_circle : Circle, Circle -> Bool
overlaps_rect : Circle, Rect -> Bool
Vec2
:= {
x : F32,
y : F32,
}
Two-dimensional floating-point vector, also named Draw.Vector2.
Construct a circle.
add : Vec2, Vec2 -> Vec2
Add two vectors component-wise.
sub : Vec2, Vec2 -> Vec2
Subtract two vectors component-wise.
Multiply both vector components by a scalar.
Compute the vector dot product.
length_squared : Vec2 -> F32
Squared vector length, avoiding a square root.
Euclidean vector length.
distance_squared : Vec2, Vec2 -> F32
Squared distance between two points.
Euclidean distance between two points.
normalize : Vec2 -> Vec2
Return a unit vector, or zero when the input has zero length.
Linearly interpolate between two vectors.
encoder_for : encoding -> (Vec2, state -> Try(state, err))
where [
encoding.encode_vec2 : Vec2, state -> Try(state, err),
]
Encode this vector as one semantic leaf for formats that support 2D
vectors. Shader uniform records use this for one GLSL vec2.
Compare two of these values.
Vec3
:= {
x : F32,
y : F32,
z : F32,
}
Three-dimensional floating-point vector.
encoder_for : encoding -> (Vec3, state -> Try(state, err)) where [encoding.encode_vec3 : Vec3, state -> Try(state, err)]
Compare two of these values.
Vec4
:= {
x : F32,
y : F32,
z : F32,
w : F32,
}
Four-dimensional floating-point vector.
encoder_for : encoding -> (Vec4, state -> Try(state, err)) where [encoding.encode_vec4 : Vec4, state -> Try(state, err)]
Rect
:= {
x : F32,
y : F32,
width : F32,
height : F32,
}
Axis-aligned rectangle represented by top-left position and size.
Left edge of a rectangle.
Right edge of a rectangle.
Top edge of a rectangle.
Bottom edge of a rectangle.
center : Rect -> Vec2
Center point of a rectangle.
closest_point : Rect, Vec2 -> Vec2
Closest point in or on a rectangle.
Whether a rectangle contains a point, including its edges.
Whether two rectangles overlap or touch.
Compare two of these values.
Circle
:= {
center : Vec2,
radius : F32,
}
Circle represented by center and radius.
circle_contains : Circle, Vec2 -> Bool
Whether a circle contains a point, including its edge.
circle_overlaps : Circle, Circle -> Bool
Whether two circles overlap or touch.
circle_rect : Circle, Rect -> Bool
Whether a circle and rectangle overlap or touch.
contains_point : Circle, Vec2 -> Bool
Receiver-friendly aliases for circle queries. The longer names avoid ambiguity with the corresponding rectangle methods.
overlaps_circle : Circle, Circle -> Bool
overlaps_rect : Circle, Rect -> Bool
Compare two of these values.