704 lines
16 KiB
HTML
704 lines
16 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>utils</title>
|
|
<link rel="stylesheet" href="../ldoc.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>utils</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="$(kind=='Topics' and '' or 'nowrap'">
|
|
<li><a href="../modules/stringutil.html">stringutil</a></li>
|
|
<li><a href="../modules/random.html">random</a></li>
|
|
<li><a href="../modules/noisemanager.html">noisemanager</a></li>
|
|
<li><a href="../modules/nodeutil.html">nodeutil</a></li>
|
|
<li><a href="../modules/posutil.html">posutil</a></li>
|
|
<li><a href="../modules/objectrefutil.html">objectrefutil</a></li>
|
|
<li><a href="../modules/nodeboxutil.html">nodeboxutil</a></li>
|
|
<li><a href="../modules/mapmanipulator.html">mapmanipulator</a></li>
|
|
<li><a href="../modules/fisheryates.html">fisheryates</a></li>
|
|
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
|
<li><a href="../modules/blockutil.html">blockutil</a></li>
|
|
<li><a href="../modules/tango.html">tango</a></li>
|
|
<li><a href="../modules/arraymanipulator.html">arraymanipulator</a></li>
|
|
<li><a href="../modules/inventoryutil.html">inventoryutil</a></li>
|
|
<li><a href="../modules/entityutil.html">entityutil</a></li>
|
|
<li><a href="../modules/scheduler.html">scheduler</a></li>
|
|
<li><a href="../modules/blockedcache.html">blockedcache</a></li>
|
|
<li><strong>mathutil</strong></li>
|
|
<li><a href="../modules/log.html">log</a></li>
|
|
<li><a href="../modules/arrayutil.html">arrayutil</a></li>
|
|
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
|
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
|
<li><a href="../modules/settings.html">settings</a></li>
|
|
<li><a href="../modules/pathutil.html">pathutil</a></li>
|
|
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
|
<li><a href="../modules/interpolate.html">interpolate</a></li>
|
|
<li><a href="../modules/transform.html">transform</a></li>
|
|
<li><a href="../modules/numberutil.html">numberutil</a></li>
|
|
<li><a href="../modules/test.html">test</a></li>
|
|
<li><a href="../modules/facedirutil.html">facedirutil</a></li>
|
|
<li><a href="../modules/constants.html">constants</a></li>
|
|
<li><a href="../modules/minetestex.html">minetestex</a></li>
|
|
<li><a href="../modules/list.html">list</a></li>
|
|
<li><a href="../modules/stopwatch.html">stopwatch</a></li>
|
|
<li><a href="../modules/itemutil.html">itemutil</a></li>
|
|
<li><a href="../modules/color.html">color</a></li>
|
|
<li><a href="../modules/tableutil.html">tableutil</a></li>
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div id="content">
|
|
|
|
<h1>Module <code>mathutil</code></h1>
|
|
<p>Various mathematical functions.</p>
|
|
<p></p>
|
|
|
|
|
|
<h2><a href="#Functions">Functions</a></h2>
|
|
<table class="function_list">
|
|
<tr>
|
|
<td class="name" nowrap><a href="#cantor_pairing">cantor_pairing (a, b)</a></td>
|
|
<td class="summary">Uses the Cantor Pairing function on the two given values and returns
|
|
a unique integer for the given numbers.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#clamp">clamp (value, min, max)</a></td>
|
|
<td class="summary">Clamps one value to the given minimum/maximum values.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#distance">distance (a, b)</a></td>
|
|
<td class="summary">Gets the distance between the two given points or objects.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#direction">direction (source_pos, target_pos)</a></td>
|
|
<td class="summary">Returns a vector indicating the general direction from a to b.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#distance2d">distance2d (a, b)</a></td>
|
|
<td class="summary">Gets the distance between two given points in the x/z plane.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#in_range">in_range (value, min, max)</a></td>
|
|
<td class="summary">Tests if the given value is within the given range.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#intersects">intersects (min_a, max_a, min_b, max_b)</a></td>
|
|
<td class="summary">Checks if the given first two values intersect with the other given values.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#intersects3d">intersects3d (min_a, max_a, min_b, max_b)</a></td>
|
|
<td class="summary">Checks if the given first two positions intersect with the other given
|
|
positions.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#next_lower_prime">next_lower_prime (number)</a></td>
|
|
<td class="summary">Gets the next lower prime from the given number.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#round">round (value, decimal_places)</a></td>
|
|
<td class="summary">Rounds to the nearest number with the given decimal places.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#sign">sign (number)</a></td>
|
|
<td class="summary">Gets the sign of the given number.</td>
|
|
</tr>
|
|
</table>
|
|
<h2><a href="#Fields">Fields</a></h2>
|
|
<table class="function_list">
|
|
<tr>
|
|
<td class="name" nowrap><a href="#SIGNED_8BIT_MAX">SIGNED_8BIT_MAX</a></td>
|
|
<td class="summary">The maximum value a signed 8bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#SIGNED_8BIT_MIN">SIGNED_8BIT_MIN</a></td>
|
|
<td class="summary">The minimum value a signed 8bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#SIGNED_16BIT_MAX">SIGNED_16BIT_MAX</a></td>
|
|
<td class="summary">The maximum value a signed 16bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#SIGNED_16BIT_MIN">SIGNED_16BIT_MIN</a></td>
|
|
<td class="summary">The minimum value a signed 16bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#SIGNED_32BIT_MAX">SIGNED_32BIT_MAX</a></td>
|
|
<td class="summary">The maximum value a signed 32bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#SIGNED_32BIT_MIN">SIGNED_32BIT_MIN</a></td>
|
|
<td class="summary">The minimum value a signed 32bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#UNSIGNED_8BIT_MAX">UNSIGNED_8BIT_MAX</a></td>
|
|
<td class="summary">The maximum value an unsigned 8bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#UNSIGNED_8BIT_MIN">UNSIGNED_8BIT_MIN</a></td>
|
|
<td class="summary">The minimum value an unsigned 8bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#UNSIGNED_16BIT_MAX">UNSIGNED_16BIT_MAX</a></td>
|
|
<td class="summary">The maximum value an unsigned 16bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#UNSIGNED_16BIT_MIN">UNSIGNED_16BIT_MIN</a></td>
|
|
<td class="summary">The minimum value an unsigned 16bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#UNSIGNED_32BIT_MAX">UNSIGNED_32BIT_MAX</a></td>
|
|
<td class="summary">The maximum value an unsigned 32bit integer can have.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#UNSIGNED_32BIT_MIN">UNSIGNED_32BIT_MIN</a></td>
|
|
<td class="summary">The minimum value an unsigned 32bit integer can have.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br/>
|
|
<br/>
|
|
|
|
|
|
<h2><a name="Functions"></a>Functions</h2>
|
|
<dl class="function">
|
|
<dt>
|
|
<a name = "cantor_pairing"></a>
|
|
<strong>cantor_pairing (a, b)</strong>
|
|
</dt>
|
|
<dd>
|
|
Uses the Cantor Pairing function on the two given values and returns
|
|
a unique integer for the given numbers.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">a</span>
|
|
The first value.
|
|
</li>
|
|
<li><span class="parameter">b</span>
|
|
The second value.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
A unique value for the two given values.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "clamp"></a>
|
|
<strong>clamp (value, min, max)</strong>
|
|
</dt>
|
|
<dd>
|
|
Clamps one value to the given minimum/maximum values. Defaults to
|
|
0 to 1 if min/max are omitted.
|
|
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">value</span>
|
|
The value to clamp.
|
|
</li>
|
|
<li><span class="parameter">min</span>
|
|
Optional. The minimum value, defaults to 0.
|
|
</li>
|
|
<li><span class="parameter">max</span>
|
|
Optional. The masximum value, defaults to 1.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
The value clamped to the given range.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "distance"></a>
|
|
<strong>distance (a, b)</strong>
|
|
</dt>
|
|
<dd>
|
|
Gets the distance between the two given points or objects.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">a</span>
|
|
The first object. Either a position or an ObjectRef.
|
|
</li>
|
|
<li><span class="parameter">b</span>
|
|
The second object. Either a position or an ObjectRef.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
The distance between the two given points or objects.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "direction"></a>
|
|
<strong>direction (source_pos, target_pos)</strong>
|
|
</dt>
|
|
<dd>
|
|
Returns a vector indicating the general direction from a to b.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">source_pos</span>
|
|
The source point, a vector.
|
|
</li>
|
|
<li><span class="parameter">target_pos</span>
|
|
The target point, a vector.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
The vector containing the direction, either 1 for the positive
|
|
direction or -1 for the negative one.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "distance2d"></a>
|
|
<strong>distance2d (a, b)</strong>
|
|
</dt>
|
|
<dd>
|
|
Gets the distance between two given points in the x/z plane.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">a</span>
|
|
The first object. Either a position or an ObjectRef.
|
|
</li>
|
|
<li><span class="parameter">b</span>
|
|
The first object. Either a position or an ObjectRef.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
The distance between the two given points or objects in
|
|
the x/z plane.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "in_range"></a>
|
|
<strong>in_range (value, min, max)</strong>
|
|
</dt>
|
|
<dd>
|
|
Tests if the given value is within the given range.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">value</span>
|
|
The value to test.
|
|
</li>
|
|
<li><span class="parameter">min</span>
|
|
The minimum value. It can also be a table with either two values,
|
|
the first being the minimum and the second being the maximum, or
|
|
with two named values, min and max.
|
|
</li>
|
|
<li><span class="parameter">max</span>
|
|
The maximum value. Not used if min is a table.
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "intersects"></a>
|
|
<strong>intersects (min_a, max_a, min_b, max_b)</strong>
|
|
</dt>
|
|
<dd>
|
|
Checks if the given first two values intersect with the other given values.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">min_a</span>
|
|
The first minimum value.
|
|
</li>
|
|
<li><span class="parameter">max_a</span>
|
|
The first maximum value.
|
|
</li>
|
|
<li><span class="parameter">min_b</span>
|
|
The second minimum value.
|
|
</li>
|
|
<li><span class="parameter">max_b</span>
|
|
The second maximum value.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
true if the first values intersect with the second.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "intersects3d"></a>
|
|
<strong>intersects3d (min_a, max_a, min_b, max_b)</strong>
|
|
</dt>
|
|
<dd>
|
|
Checks if the given first two positions intersect with the other given
|
|
positions.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">min_a</span>
|
|
The first minimum value.
|
|
</li>
|
|
<li><span class="parameter">max_a</span>
|
|
The first maximum value.
|
|
</li>
|
|
<li><span class="parameter">min_b</span>
|
|
The second minimum value.
|
|
</li>
|
|
<li><span class="parameter">max_b</span>
|
|
The second maximum value.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
true if the first positions intersect with the second.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "next_lower_prime"></a>
|
|
<strong>next_lower_prime (number)</strong>
|
|
</dt>
|
|
<dd>
|
|
Gets the next lower prime from the given number.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">number</span>
|
|
The number.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
The next lower prime.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "round"></a>
|
|
<strong>round (value, decimal_places)</strong>
|
|
</dt>
|
|
<dd>
|
|
Rounds to the nearest number with the given decimal places.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">value</span>
|
|
The value to round.
|
|
</li>
|
|
<li><span class="parameter">decimal_places</span>
|
|
Optional. The number of decimal places to round to,
|
|
defaults to 0.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
The rounded value.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "sign"></a>
|
|
<strong>sign (number)</strong>
|
|
</dt>
|
|
<dd>
|
|
Gets the sign of the given number.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">number</span>
|
|
The number of which to get the sign.
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>Returns:</h3>
|
|
<ol>
|
|
|
|
1 for a positive number, -1 for a negative one. Zero is considered
|
|
a positive number for this function, there for returns 1.
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
</dl>
|
|
<h2><a name="Fields"></a>Fields</h2>
|
|
<dl class="function">
|
|
<dt>
|
|
<a name = "SIGNED_8BIT_MAX"></a>
|
|
<strong>SIGNED_8BIT_MAX</strong>
|
|
</dt>
|
|
<dd>
|
|
The maximum value a signed 8bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "SIGNED_8BIT_MIN"></a>
|
|
<strong>SIGNED_8BIT_MIN</strong>
|
|
</dt>
|
|
<dd>
|
|
The minimum value a signed 8bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "SIGNED_16BIT_MAX"></a>
|
|
<strong>SIGNED_16BIT_MAX</strong>
|
|
</dt>
|
|
<dd>
|
|
The maximum value a signed 16bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "SIGNED_16BIT_MIN"></a>
|
|
<strong>SIGNED_16BIT_MIN</strong>
|
|
</dt>
|
|
<dd>
|
|
The minimum value a signed 16bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "SIGNED_32BIT_MAX"></a>
|
|
<strong>SIGNED_32BIT_MAX</strong>
|
|
</dt>
|
|
<dd>
|
|
The maximum value a signed 32bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "SIGNED_32BIT_MIN"></a>
|
|
<strong>SIGNED_32BIT_MIN</strong>
|
|
</dt>
|
|
<dd>
|
|
The minimum value a signed 32bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "UNSIGNED_8BIT_MAX"></a>
|
|
<strong>UNSIGNED_8BIT_MAX</strong>
|
|
</dt>
|
|
<dd>
|
|
The maximum value an unsigned 8bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "UNSIGNED_8BIT_MIN"></a>
|
|
<strong>UNSIGNED_8BIT_MIN</strong>
|
|
</dt>
|
|
<dd>
|
|
The minimum value an unsigned 8bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "UNSIGNED_16BIT_MAX"></a>
|
|
<strong>UNSIGNED_16BIT_MAX</strong>
|
|
</dt>
|
|
<dd>
|
|
The maximum value an unsigned 16bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "UNSIGNED_16BIT_MIN"></a>
|
|
<strong>UNSIGNED_16BIT_MIN</strong>
|
|
</dt>
|
|
<dd>
|
|
The minimum value an unsigned 16bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "UNSIGNED_32BIT_MAX"></a>
|
|
<strong>UNSIGNED_32BIT_MAX</strong>
|
|
</dt>
|
|
<dd>
|
|
The maximum value an unsigned 32bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "UNSIGNED_32BIT_MIN"></a>
|
|
<strong>UNSIGNED_32BIT_MIN</strong>
|
|
</dt>
|
|
<dd>
|
|
The minimum value an unsigned 32bit integer can have.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
</div> <!-- id="content" -->
|
|
</div> <!-- id="main" -->
|
|
<div id="about">
|
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.2</a></i>
|
|
</div> <!-- id="about" -->
|
|
</div> <!-- id="container" -->
|
|
</body>
|
|
</html>
|