|
@@ -10,131 +10,104 @@
|
|
|
<body>
|
|
|
<h1>[name]</h1>
|
|
|
|
|
|
- <div class="desc">Math utility functions</div>
|
|
|
+ <div class="desc">An object with several math utility functions.</div>
|
|
|
|
|
|
- <h2>Properties</h2>
|
|
|
-
|
|
|
- <h2>Methods</h2>
|
|
|
+ <h2>Functions</h2>
|
|
|
|
|
|
<h3>[method:Float clamp]( [page:Float value], [page:Float min], [page:Float max] )</h3>
|
|
|
<div>
|
|
|
- value — Value to be clamped.<br />
|
|
|
- min — Minimum value<br />
|
|
|
- max — Maximum value.
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- Clamps the *value* to be between *min* and *max*.
|
|
|
+ [page:Float value] — Value to be clamped.<br />
|
|
|
+ [page:Float min] — Minimum value.<br />
|
|
|
+ [page:Float max] — Maximum value.<br /><br />
|
|
|
+
|
|
|
+ Clamps the [page:Float value] to be between [page:Float min] and [page:Float max].
|
|
|
</div>
|
|
|
|
|
|
<h3>[method:Float degToRad]( [page:Float degrees] )</h3>
|
|
|
- <div>
|
|
|
- degrees -- [page:Float]
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- Converts degrees to radians.
|
|
|
- </div>
|
|
|
+ <div>Converts degrees to radians.</div>
|
|
|
|
|
|
<h3>[method:Integer euclideanModulo]( [page:Integer n], [page:Integer m] )</h3>
|
|
|
<div>
|
|
|
- n, m --Integers
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- Compute the Euclidian modulo of m % n, that is:
|
|
|
+ [page:Integer n], [page:Integer m] - Integers<br /><br />
|
|
|
+
|
|
|
+ Compute the Euclidian modulo of m % [page:Integer n], that is:
|
|
|
<code>( ( n % m ) + m ) % m</code>
|
|
|
</div>
|
|
|
|
|
|
<h3>[method:UUID generateUUID]( )</h3>
|
|
|
<div>
|
|
|
- Generate a [link:https://en.wikipedia.org/wiki/Universally_unique_identifier UUID] (universally unique identifier).
|
|
|
+ Generate a [link:https://en.wikipedia.org/wiki/Universally_unique_identifier UUID]
|
|
|
+ (universally unique identifier).
|
|
|
</div>
|
|
|
|
|
|
- <h3>[method:Boolean isPowerOfTwo]( n )</h3>
|
|
|
- <div>
|
|
|
- Return *true* if n is a power of 2.
|
|
|
- </div>
|
|
|
+ <h3>[method:Boolean isPowerOfTwo]( [page:Number n] )</h3>
|
|
|
+ <div>Return *true* if [page:Number n] is a power of 2.</div>
|
|
|
|
|
|
<h3>[method:Float lerp]( [page:Float x], [page:Float y], [page:Float t] )</h3>
|
|
|
<div>
|
|
|
- x -- Start point. <br />
|
|
|
- y -- End point. <br />
|
|
|
- t -- Closed unit interval from [0,1].
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- Returns a value [link:https://en.wikipedia.org/wiki/Linear_interpolation linearly interpolated] from two known points based on the given interval.
|
|
|
- </div>
|
|
|
+ [page:Float x] - Start point. <br />
|
|
|
+ [page:Float y] - End point. <br />
|
|
|
+ [page:Float t] - number in the closed interval from [0,1].<br><br />
|
|
|
|
|
|
- <h3>[method:Float mapLinear]( [page:Float x], [page:Float a1], [page:Float a2], [page:Float b1], [page:Float b2] )</h3>
|
|
|
- <div>
|
|
|
- x — Value to be mapped.<br />
|
|
|
- a1 — Minimum value for range A.<br />
|
|
|
- a2 — Maximum value for range A.<br />
|
|
|
- b1 — Minimum value for range B.<br />
|
|
|
- b2 — Maximum value for range B.
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- Linear mapping of *x* from range [*a1*, *a2*] to range [*b1*, *b2*].
|
|
|
+ Returns a value [link:https://en.wikipedia.org/wiki/Linear_interpolation linearly interpolated]
|
|
|
+ from two known points based on the given interval - [page:Float t] = 0 will return [page:Float x]
|
|
|
+ and [page:Float t] = 1 will return [page:Float y].
|
|
|
</div>
|
|
|
|
|
|
- <h3>[method:Integer nearestPowerOfTwo]( n )</h3>
|
|
|
+ <h3>[method:Float mapLinear](
|
|
|
+ [page:Float x],
|
|
|
+ [page:Float a1],
|
|
|
+ [page:Float a2],
|
|
|
+ [page:Float b1],
|
|
|
+ [page:Float b2] )</h3>
|
|
|
<div>
|
|
|
- Return the nearest power of 2 to a given number n.
|
|
|
- </div>
|
|
|
+ [page:Float x] — Value to be mapped.<br />
|
|
|
+ [page:Float a1] — Minimum value for range A.<br />
|
|
|
+ [page:Float a2] — Maximum value for range A.<br />
|
|
|
+ [page:Float b1] — Minimum value for range B.<br />
|
|
|
+ [page:Float b2] — Maximum value for range B.<br /><br />
|
|
|
|
|
|
- <h3>[method:Integer nextPowerOfTwo]( n )</h3>
|
|
|
- <div>
|
|
|
- Return the nearest power of 2 that is bigger than n.
|
|
|
+ Linear mapping of [page:Float x] from range [[page:Float a1], [page:Float a2]] to range [[page:Float b1], [page:Float b2]].
|
|
|
</div>
|
|
|
|
|
|
+ <h3>[method:Integer nearestPowerOfTwo]( [page:Number n] )</h3>
|
|
|
+ <div> Return the nearest power of 2 to a given number [page:Number n].</div>
|
|
|
+
|
|
|
+ <h3>[method:Integer nextPowerOfTwo]( [page:Number n] )</h3>
|
|
|
+ <div>Return the nearest power of 2 that is bigger than [page:Number n].</div>
|
|
|
+
|
|
|
<h3>[method:Float radToDeg]( [page:Float radians] )</h3>
|
|
|
- <div>
|
|
|
- radians -- [page:Float]
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- Converts radians to degrees
|
|
|
- </div>
|
|
|
+ <div>Converts radians to degrees.</div>
|
|
|
|
|
|
<h3>[method:Float randFloat]( [page:Float low], [page:Float high] )</h3>
|
|
|
- <div>
|
|
|
- Random float from *low* to *high* interval.
|
|
|
- </div>
|
|
|
+ <div>Random float in the interval [page:Float low] to [page:Float high].</div>
|
|
|
|
|
|
<h3>[method:Float randFloatSpread]( [page:Float range] )</h3>
|
|
|
- <div>
|
|
|
- Random float from *- range / 2* to *range / 2* interval.
|
|
|
- </div>
|
|
|
+ <div>Random float in the intercal *- [page:Float range] / 2* to *[page:Float range] / 2*.</div>
|
|
|
|
|
|
<h3>[method:Integer randInt]( [page:Integer low], [page:Integer high] )</h3>
|
|
|
- <div>
|
|
|
- Random integer from *low* to *high* interval.
|
|
|
- </div>
|
|
|
-
|
|
|
- <h3>[method:Float random16]()</h3>
|
|
|
- <div>
|
|
|
- Random float from 0 to 1 with 16 bits of randomness.<br />
|
|
|
- Standard Math.random() creates repetitive patterns when applied over larger space.
|
|
|
- </div>
|
|
|
+ <div>Random integer in the interval [page:Float low] to [page:Float high].</div>
|
|
|
|
|
|
<h3>[method:Float smoothstep]( [page:Float x], [page:Float min], [page:Float max] )</h3>
|
|
|
<div>
|
|
|
- x -- The value to evaluate based on its position between min and max. <br />
|
|
|
- min -- Any x value below min will be 0 <br />
|
|
|
- max -- Any x value above max will be 1
|
|
|
- </div>
|
|
|
- <div>
|
|
|
+ [page:Float x] - The value to evaluate based on its position between min and max. <br />
|
|
|
+ [page:Float min] - Any x value below min will be 0.<br />
|
|
|
+ [page:Float max] - Any x value above max will be 1.<br /><br />
|
|
|
+
|
|
|
Returns a value between 0-1 that represents the percentage that x has moved between min and max,
|
|
|
but smoothed or slowed down the closer X is to the min and max.<br/><br/>
|
|
|
|
|
|
- [link:http://en.wikipedia.org/wiki/Smoothstep Wikipedia]
|
|
|
+ See [link:http://en.wikipedia.org/wiki/Smoothstep Smoothstep] for details.
|
|
|
</div>
|
|
|
|
|
|
<h3>[method:Float smootherstep]( [page:Float x], [page:Float min], [page:Float max] )</h3>
|
|
|
<div>
|
|
|
- x -- The value to evaluate based on its position between min and max. <br />
|
|
|
- min -- Any x value below min will be 0 <br />
|
|
|
- max -- Any x value above max will be 1
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- Returns a value between 0-1. It works the same as smoothstep, but more smooth.
|
|
|
+ [page:Float x] - The value to evaluate based on its position between min and max. <br />
|
|
|
+ [page:Float min] - Any x value below min will be 0.<br />
|
|
|
+ [page:Float max] - Any x value above max will be 1.<br /><br />
|
|
|
+
|
|
|
+ Returns a value between 0-1. A [link:https://en.wikipedia.org/wiki/Smoothstep#Variations variation on smoothstep]
|
|
|
+ that has zero 1st and 2nd order derivatives at x=0 and x=1.
|
|
|
</div>
|
|
|
|
|
|
<h2>Source</h2>
|