2024-12-01 12:04:30 -08:00

558 lines
11 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>CPML documentation</title>
<link rel="stylesheet" href="../ldoc_new.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LEEF Math</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
<li><a href="#Fields">Fields</a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/bound2.html">bound2</a></li>
<li><a href="../modules/bound3.html">bound3</a></li>
<li><a href="../modules/bvh.html">bvh</a></li>
<li><a href="../modules/color.html">color</a></li>
<li><a href="../modules/constants.html">constants</a></li>
<li><a href="../modules/intersect.html">intersect</a></li>
<li><a href="../modules/mat4.html">mat4</a></li>
<li><a href="../modules/mesh.html">mesh</a></li>
<li><a href="../modules/octree.html">octree</a></li>
<li><a href="../modules/quat.html">quat</a></li>
<li><a href="../modules/simplex.html">simplex</a></li>
<li><strong>utils</strong></li>
<li><a href="../modules/vec2.html">vec2</a></li>
<li><a href="../modules/vec3.html">vec3</a></li>
</ul>
<h2>Topics</h2>
<ul class="">
<li><a href="../topics/readme.md.html">readme</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>utils</code></h1>
<p>Various utility functions</p>
<p>
</p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#clamp">clamp (value, min, max)</a></td>
<td class="summary">Clamps a value within the specified range.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#deadzone">deadzone (value, size)</a></td>
<td class="summary">Returns <code>value</code> if it is equal or greater than |<code>size</code>|, or 0.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#threshold">threshold (value, threshold)</a></td>
<td class="summary">Check if value is equal or greater than threshold.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#tolerance">tolerance (value, threshold)</a></td>
<td class="summary">Check if value is equal or less than threshold.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#map">map (value, min_in, max_in, min_out, max_out)</a></td>
<td class="summary">Scales a value from one range to another.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#lerp">lerp (low, high, progress)</a></td>
<td class="summary">Linear interpolation.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#decay">decay (low, high, rate, dt)</a></td>
<td class="summary">Exponential decay</td>
</tr>
<tr>
<td class="name" nowrap><a href="#smoothstep">smoothstep (progress, low, high)</a></td>
<td class="summary">Hermite interpolation.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#wrap">wrap (value, limit)</a></td>
<td class="summary">Wrap <code>value</code> around if it exceeds <code>limit</code>.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_pot">is_pot (value)</a></td>
<td class="summary">Check if a value is a power-of-two.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sign">sign (value)</a></td>
<td class="summary">Get the sign of a number
returns 1 for positive values, -1 for negative and 0 for zero.</td>
</tr>
</table>
<h2><a href="#Fields">Fields</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#round">round</a></td>
<td class="summary">Round number at a given precision.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_nan">is_nan</a></td>
<td class="summary">Check if a value is NaN
Returns true if a number is not a valid number</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "clamp"></a>
<strong>clamp (value, min, max)</strong>
</dt>
<dd>
Clamps a value within the specified range.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
Input value
</li>
<li><span class="parameter">min</span>
Minimum output value
</li>
<li><span class="parameter">max</span>
Maximum output value
</li>
</ul>
<h3>Returns:</h3>
<ol>
number
</ol>
</dd>
<dt>
<a name = "deadzone"></a>
<strong>deadzone (value, size)</strong>
</dt>
<dd>
Returns <code>value</code> if it is equal or greater than |<code>size</code>|, or 0.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
</li>
<li><span class="parameter">size</span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
number
</ol>
</dd>
<dt>
<a name = "threshold"></a>
<strong>threshold (value, threshold)</strong>
</dt>
<dd>
Check if value is equal or greater than threshold.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
</li>
<li><span class="parameter">threshold</span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
boolean
</ol>
</dd>
<dt>
<a name = "tolerance"></a>
<strong>tolerance (value, threshold)</strong>
</dt>
<dd>
Check if value is equal or less than threshold.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
</li>
<li><span class="parameter">threshold</span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
boolean
</ol>
</dd>
<dt>
<a name = "map"></a>
<strong>map (value, min_in, max_in, min_out, max_out)</strong>
</dt>
<dd>
Scales a value from one range to another.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
Input value
</li>
<li><span class="parameter">min_in</span>
Minimum input value
</li>
<li><span class="parameter">max_in</span>
Maximum input value
</li>
<li><span class="parameter">min_out</span>
Minimum output value
</li>
<li><span class="parameter">max_out</span>
Maximum output value
</li>
</ul>
<h3>Returns:</h3>
<ol>
number
</ol>
</dd>
<dt>
<a name = "lerp"></a>
<strong>lerp (low, high, progress)</strong>
</dt>
<dd>
Linear interpolation.
Performs linear interpolation between 0 and 1 when <code>low</code> &lt; <code>progress</code> &lt; <code>high</code>.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">low</span>
value to return when <code>progress</code> is 0
</li>
<li><span class="parameter">high</span>
value to return when <code>progress</code> is 1
</li>
<li><span class="parameter">progress</span>
(0-1)
</li>
</ul>
<h3>Returns:</h3>
<ol>
number
</ol>
</dd>
<dt>
<a name = "decay"></a>
<strong>decay (low, high, rate, dt)</strong>
</dt>
<dd>
Exponential decay
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">low</span>
initial value
</li>
<li><span class="parameter">high</span>
target value
</li>
<li><span class="parameter">rate</span>
portion of the original value remaining per second
</li>
<li><span class="parameter">dt</span>
time delta
</li>
</ul>
<h3>Returns:</h3>
<ol>
number
</ol>
</dd>
<dt>
<a name = "smoothstep"></a>
<strong>smoothstep (progress, low, high)</strong>
</dt>
<dd>
Hermite interpolation.
Performs smooth Hermite interpolation between 0 and 1 when <code>low</code> &lt; <code>progress</code> &lt; <code>high</code>.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">progress</span>
(0-1)
</li>
<li><span class="parameter">low</span>
value to return when <code>progress</code> is 0
</li>
<li><span class="parameter">high</span>
value to return when <code>progress</code> is 1
</li>
</ul>
<h3>Returns:</h3>
<ol>
number
</ol>
</dd>
<dt>
<a name = "wrap"></a>
<strong>wrap (value, limit)</strong>
</dt>
<dd>
Wrap <code>value</code> around if it exceeds <code>limit</code>.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
</li>
<li><span class="parameter">limit</span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
number
</ol>
</dd>
<dt>
<a name = "is_pot"></a>
<strong>is_pot (value)</strong>
</dt>
<dd>
Check if a value is a power-of-two.
Returns true if a number is a valid power-of-two, otherwise false.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
boolean
</ol>
</dd>
<dt>
<a name = "sign"></a>
<strong>sign (value)</strong>
</dt>
<dd>
Get the sign of a number
returns 1 for positive values, -1 for negative and 0 for zero.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
number
</ol>
</dd>
</dl>
<h2 class="section-header "><a name="Fields"></a>Fields</h2>
<dl class="function">
<dt>
<a name = "round"></a>
<strong>round</strong>
</dt>
<dd>
Round number at a given precision.
Truncates <code>value</code> at <code>precision</code> points after the decimal (whole number if
left unspecified).
<ul>
<li><span class="parameter">value</span>
</li>
<li><span class="parameter">precision</span>
</li>
</ul>
</dd>
<dt>
<a name = "is_nan"></a>
<strong>is_nan</strong>
</dt>
<dd>
Check if a value is NaN
Returns true if a number is not a valid number
<ul>
<li><span class="parameter">value</span>
</li>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/lunarmodules/ldoc">LDoc 1.5.0</a></i>
<i style="float:right;">Last updated 2024-12-01 12:04:18 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>