Clamp value into [min, max]. When isCyclic is true, an underflow
(value below min) wraps to max and an overflow wraps to min. When it
is false, the value is clamped to the nearest endpoint.
The wrap is one-step: this function does not handle multi-period
overshoot (e.g. value = max + 5 → max + 5 - period). Callers that need
full modular wrap should compose this with a normalization pass.
Parameters
value: number
The candidate value (typically current ± step).
min: number
Inclusive lower bound.
max: number
Inclusive upper bound.
isCyclic: boolean
When true, out-of-range values wrap to the other end.
Clamp
valueinto[min, max]. WhenisCyclicis true, an underflow (value below min) wraps tomaxand an overflow wraps tomin. When it is false, the value is clamped to the nearest endpoint.The wrap is one-step: this function does not handle multi-period overshoot (e.g. value = max + 5 → max + 5 - period). Callers that need full modular wrap should compose this with a normalization pass.