Skip to main content
A collection of math utilities for common operations including 2D vector math, rectangle operations, and value clamping.

Installation

Clamping operations

Utilities for constraining numeric values within specified ranges.

clamp

Clamps a value between a minimum and maximum.

clampWithOverflow

Clamps a value with wrapping overflow behavior.
clampWithOverflow wraps values that exceed the range back into the valid range, making it useful for circular buffers and cyclic operations.

Vector2

A 2D vector type with comprehensive operations.

Types

Construction

Creates a new vector from x and y coordinates.

Arithmetic operations

Manipulation

Negates both components of a vector.

Utility

Rectangle

Rectangle type and operations for 2D bounding boxes.

Types

Construction

Creates a rectangle from position and size vectors.

Operations

Expands rectangle to include another rectangle.

Utility

All vector and rectangle operations are immutable - they return new objects rather than modifying existing ones.