Math¶
Vanguard.Math and Vanguard.Util.Math provide number helpers commonly needed
for gameplay interpolation, remapping, looping, easing, quantization, and
floating-point comparison.
All helpers validate their numeric contracts. Invalid values use
VG-MATH-001; invalid ranges use
VG-MATH-002.
Constants¶
| Constant | Value | Purpose |
|---|---|---|
EPSILON |
1e-6 |
Default relative tolerance for approximate equality |
TAU |
math.pi * 2 |
One full turn in radians |
Rounding And Quantization¶
round¶
decimalPlaces must be an integer and may be negative to round to tens,
hundreds, and larger places.
snap¶
The increment must be greater than zero.
Interpolation And Mapping¶
lerp¶
alpha is not clamped, so values below zero or above one extrapolate.
inverseLerp¶
The end value must be greater than the start value. The result is not clamped.
map¶
The optional final boolean clamps normalized progress before mapping it to the output range. Output ranges may ascend or descend.
Movement And Easing¶
moveTowards¶
Moves by at most maxDelta without overshooting. maxDelta must be zero or
greater.
smoothstep¶
Normalizes and clamps the value, then applies cubic smoothing.
smootherstep¶
Uses a fifth-order curve with zero first and second derivatives at both ends.
Repeating Values¶
wrap¶
Returns a value in [minimum, maximum). Maximum must be greater than minimum.
pingPong¶
Repeats between zero and length, reflecting at each endpoint. Length must be
greater than zero.
Comparison And Aggregation¶
approximatelyEqual¶
Comparison is relative to the largest magnitude or one, avoiding a tolerance that becomes useless for large values. Epsilon must be non-negative.
average¶
Requires at least one number.
API Summary¶
| Function | Signature |
|---|---|
round |
(value, decimalPlaces?) -> number |
lerp |
(startValue, endValue, alpha) -> number |
inverseLerp |
(startValue, endValue, value) -> number |
map |
(value, inMin, inMax, outMin, outMax, clampResult?) -> number |
approximatelyEqual |
(left, right, epsilon?) -> boolean |
wrap |
(value, minimum, maximum) -> number |
pingPong |
(value, length) -> number |
smoothstep |
(minimum, maximum, value) -> number |
smootherstep |
(minimum, maximum, value) -> number |
moveTowards |
(current, target, maxDelta) -> number |
snap |
(value, increment) -> number |
average |
(...values) -> number |