Data Structures

Scalar

Validated scalar brands and pure scalar helpers.

This module is the numeric foundation for the branded geometry helpers. Plain number values enter through explicit constructors such as Finite and NonNegative. Once validated, downstream helpers operate only on branded values.

In game code this is useful whenever "just a number" is too weak: viewport sizes, speeds, distances, durations, and geometry values often need explicit non-negative or finite guarantees before they should be stored in the world.

Examples

// Validate raw numbers before geometry or gameplay code relies on them.
const speed = Scalar.Finite.result(12)
const limit = Scalar.Finite.result(8)
if (!speed.ok || !limit.ok) return

// Operate on the branded values after the boundary has been crossed.
const clamped = Scalar.clamp(speed.value, limit.value, speed.value)

Constructors

Non-throwing validation boundaries for finite and constrained scalar values.

Operations

Pure scalar combinators that preserve branding after validation.

clamp

Source

Clamps one finite value between two finite bounds.

The result stays branded because valid branded scalar input cannot produce an invalid scalar output.

lerp

Source

Interpolates between two finite values by one finite amount.

The amount is not clamped. This stays a pure interpolation primitive rather than mixing interpolation with policy.

approach

Source

Moves one finite value toward a target by at most one non-negative delta.

Use this for explicit interpolation-style updates where overshooting the target should be impossible.

inverseLerp

Source

Returns the interpolation amount of one value within a finite input range.

Fails explicitly when the input range has zero size.

remap

Source

Remaps one finite value from one input range to one output range.

Fails explicitly when the input range has zero size.