math/math
src/math/math.tur
defn
clamp
(clamp [x :float lo :float hi :float] :float)
clamp a float value to [lo, hi].
Parameters
| x | input value | |
| lo | lower bound | |
| hi | upper bound |
Returns
x clamped to [lo, hi].
Example
(clamp 1.5 0.0 1.0) ; => 1.0
Since: P1
defn
lerp
(lerp [a :float b :float t :float] :float)
linear interpolation between a and b by t.
Parameters
| a | start value | |
| b | end value | |
| t | interpolation factor (0.0=a, 1.0=b) |
Returns
a + t*(b-a)
Example
(lerp 0.0 10.0 0.5) ; => 5.0
Since: P1
defn
remap
(remap [x :float in-lo :float in-hi :float out-lo :float out-hi :float] :float)
remap x from [in-lo, in-hi] to [out-lo, out-hi].
Parameters
| x | input value | |
| in-lo | input range low | |
| in-hi | input range high | |
| out-lo | output range low | |
| out-hi | output range high |
Returns
x remapped to [out-lo, out-hi].
Example
(remap 5.0 0.0 10.0 0.0 1.0) ; => 0.5
Since: P1
defn
deg->rad
(deg->rad [deg :float] :float)
convert degrees to radians.
Parameters
| deg | angle in degrees |
Returns
Angle in radians.
Example
(deg->rad 180.0) ; => 3.14159...
Since: P1
defn
rad->deg
(rad->deg [rad :float] :float)
convert radians to degrees.
Parameters
| rad | angle in radians |
Returns
Angle in degrees.
Example
(rad->deg 3.14159) ; => ~180.0
Since: P1
defn
approx-eq
(approx-eq [a :float b :float eps :float] :bool)
test whether two floats are approximately equal within epsilon.
Parameters
| a | first value | |
| b | second value | |
| eps | tolerance (use 1e-6 for most purposes) |
Returns
true if |a - b| < eps.
Example
(approx-eq 0.1 0.10001 1e-4) ; => true
Since: P1