36 lines
No EOL
2.5 KiB
HTML
36 lines
No EOL
2.5 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Math.clamp — Ludic</title>
|
||
<meta name="description" content="Constrain a value to the range [lo, hi].">
|
||
<link rel="stylesheet" href="base.css">
|
||
<link rel="stylesheet" href="docs.css">
|
||
</head>
|
||
<body>
|
||
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
|
||
<main class="wrap item">
|
||
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="ns-math.html">Math</a> <span>›</span> <span class="here">Math.clamp</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-method">method</span>
|
||
<h1 id="top">Math.clamp</h1>
|
||
</div>
|
||
<code class="sig">Math.clamp(v, lo, hi) -> int</code>
|
||
<div class="desc"><p>Returns <code>v</code> held inside the inclusive range <code>lo</code>..<code>hi</code>: below <code>lo</code> it returns <code>lo</code>, above <code>hi</code> it returns <code>hi</code>, otherwise <code>v</code> unchanged. It is the single-call form of <code>Math.max(lo, Math.min(v, hi))</code> and works for <code>int</code> and <code>fixed</code> alike. Use it to keep a camera inside the world, a slider within its track, or a stat within its legal bounds. The bare form <code>clamp(v, lo, hi)</code> is kept as a convenience alias.</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-v"><code class="pname">v</code><span class="pdesc">the value to constrain</span></div><div class="param" id="param-lo"><code class="pname">lo</code><span class="pdesc">the lowest allowed result (inclusive)</span></div><div class="param" id="param-hi"><code class="pname">hi</code><span class="pdesc">the highest allowed result (inclusive)</span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program CameraBounds {
|
||
const WORLD_WIDTH: int = 320
|
||
|
||
var camera_x: int = 0
|
||
|
||
handler Follow phase Update {
|
||
camera_x = Math.clamp(camera_x, 0, WORLD_WIDTH - 1)
|
||
}
|
||
}</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |