Construct a two-dimensional vector.
Math
:= []
Math module - small 2D helpers for examples and simple games.
Coordinates use the same screen-space convention as Draw: x grows to the right, y grows downward, and rectangles are top-left plus width/height.
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.
is_eq : _
Rect
:= {
x : F32,
y : F32,
width : F32,
height : F32,
}
Axis-aligned rectangle represented by top-left position and size.
is_eq : _
Circle
:= {
center : Vec2,
radius : F32,
}
Circle represented by center and radius.
is_eq : _