mw-engine/docs/codox/mw-engine.utils.html

78 lines
19 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC ""
"">
<html><head><meta charset="UTF-8" /><title>mw-engine.utils documentation</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">Mw-engine</span> <span class="project-version">0.2.0-SNAPSHOT</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Topics</span></h3><ul><li class="depth-1 "><a href="intro.html"><div class="inner"><span>Introduction to mw-engine</span></div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>mw-engine</span></div></div></li><li class="depth-2 branch"><a href="mw-engine.core.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>core</span></div></a></li><li class="depth-2 branch"><a href="mw-engine.display.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>display</span></div></a></li><li class="depth-2 branch"><a href="mw-engine.drainage.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>drainage</span></div></a></li><li class="depth-2 branch"><a href="mw-engine.flow.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>flow</span></div></a></li><li class="depth-2 branch"><a href="mw-engine.heightmap.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>heightmap</span></div></a></li><li class="depth-2 branch"><a href="mw-engine.natural-rules.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>natural-rules</span></div></a></li><li class="depth-2 branch current"><a href="mw-engine.utils.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>utils</span></div></a></li><li class="depth-2"><a href="mw-engine.world.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>world</span></div></a></li></ul></div><div class="sidebar secondary"><h3><a href="#top"><span class="inner">Public Vars</span></a></h3><ul><li class="depth-1"><a href="mw-engine.utils.html#var-get-cell"><div class="inner"><span>get-cell</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-get-int"><div class="inner"><span>get-int</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-get-int-or-zero"><div class="inner"><span>get-int-or-zero</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-get-least-cell"><div class="inner"><span>get-least-cell</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-get-most-cell"><div class="inner"><span>get-most-cell</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-get-neighbours"><div class="inner"><span>get-neighbours</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-get-neighbours-with-property-value"><div class="inner"><span>get-neighbours-with-property-value</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-get-neighbours-with-state"><div class="inner"><span>get-neighbours-with-state</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-get-num"><div class="inner"><span>get-num</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-in-bounds"><div class="inner"><span>in-bounds</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-in-bounds.3F"><div class="inner"><span>in-bounds?</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-init-generation"><div class="inner"><span>init-generation</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-map-world"><div class="inner"><span>map-world</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-map-world-n-n"><div class="inner"><span>map-world-n-n</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-map-world-p-p"><div class="inner"><span>map-world-p-p</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-member.3F"><div class="inner"><span>member?</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-memo-get-neighbours"><div class="inner"><span>memo-get-neighbours</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-merge-cell"><div class="inner"><span>merge-cell</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-population"><div class="inner"><span>population</span></div></a></li><li class="depth-1"><a href="mw-engine.utils.html#var-set-property"><div class="inner"><span>set-property</span></div></a></li></ul></div><div class="namespace-docs" id="content"><h1 class="anchor" id="top">mw-engine.utils</h1><div class="doc"><div class="markdown"><p>Utility functions needed by MicroWorld and, specifically, in the interpretation of MicroWorld rule.</p>
</div></div><div class="public anchor" id="var-get-cell"><h3>get-cell</h3><div class="usage"><code>(get-cell world x y)</code></div><div class="doc"><div class="markdown"><p>Return the cell a x, y in this world, if any.</p>
<ul>
<li><code>world</code> a world as defined in <a href="mw-engine.world.html">world.clj</a>;</li>
<li><code>x</code> a number which may or may not be a valid x coordinate within that world;</li>
<li><code>y</code> a number which may or may not be a valid y coordinate within that world.</li>
</ul>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L118">view source</a></div></div><div class="public anchor" id="var-get-int"><h3>get-int</h3><div class="usage"><code>(get-int map key)</code></div><div class="doc"><div class="markdown"><p>Get the value of a property expected to be an integer from a map; if not present (or not an integer) return 0.</p>
<ul>
<li><code>map</code> a map;</li>
<li><code>key</code> a symbol or keyword, presumed to be a key into the <code>map</code>.</li>
</ul>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L128">view source</a></div></div><div class="public anchor" id="var-get-int-or-zero"><h3>get-int-or-zero</h3><div class="usage"><code>(get-int-or-zero map property)</code></div><div class="doc"><div class="markdown"><p>Return the value of this <code>property</code> from this <code>map</code> if it is a integer; otherwise return zero.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L36">view source</a></div></div><div class="public anchor" id="var-get-least-cell"><h3>get-least-cell</h3><div class="usage"><code>(get-least-cell cells property)</code></div><div class="doc"><div class="markdown"><p>Return the cell from among these <code>cells</code> which has the lowest numeric value for this <code>property</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L251">view source</a></div></div><div class="public anchor" id="var-get-most-cell"><h3>get-most-cell</h3><div class="usage"><code>(get-most-cell cells property)</code></div><div class="doc"><div class="markdown"><p>Return the cell from among these <code>cells</code> which has the highest numeric value for this <code>property</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L257">view source</a></div></div><div class="public anchor" id="var-get-neighbours"><h3>get-neighbours</h3><div class="usage"><code>(get-neighbours world x y depth)</code><code>(get-neighbours world cell depth)</code><code>(get-neighbours world cell)</code></div><div class="doc"><div class="markdown"><p>Get the neighbours to distance depth of a cell in this world.</p>
<p>Several overloads: * <code>world</code> a world, as described in <a href="mw-engine.world.html">world.clj</a>; * <code>cell</code> a cell within that world Gets immediate neighbours of the specified cell.</p>
<ul>
<li><code>world</code> a world, as described in<a href="mw-engine.world.html">world.clj</a>;</li>
<li><code>cell</code> a cell within that world</li>
<li><code>depth</code> an integer representing the depth to search from the <code>cell</code> Gets neighbours within the specified distance of the cell.</li>
<li>
<p><code>world</code> a world, as described in<a href="mw-engine.world.html">world.clj</a>;</p>
</li>
<li><code>x</code> an integer representing an x coordinate in that world;</li>
<li><code>y</code> an integer representing an y coordinate in that world;</li>
<li><code>depth</code> an integer representing the distance from <a href="x,y">x,y</a> that should be searched Gets the neighbours within the specified distance of the cell at coordinates <a href="x,y">x,y</a> in this world.</li>
</ul>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L178">view source</a></div></div><div class="public anchor" id="var-get-neighbours-with-property-value"><h3>get-neighbours-with-property-value</h3><div class="usage"><code>(get-neighbours-with-property-value world x y depth property value op)</code><code>(get-neighbours-with-property-value world x y depth property value)</code><code>(get-neighbours-with-property-value world cell depth property value)</code><code>(get-neighbours-with-property-value world cell property value)</code></div><div class="doc"><div class="markdown"><p>Get the neighbours to distance depth of the cell at x, y in this world which have this value for this property.</p>
<ul>
<li><code>world</code> a world, as described in <a href="mw-engine.world.html">world.clj</a>;</li>
<li><code>cell</code> a cell within that world;</li>
<li><code>depth</code> an integer representing the distance from <a href="x,y">x,y</a> that should be searched (optional);</li>
<li><code>property</code> a keyword representing a property of the neighbours;</li>
<li><code>value</code> a value of that property (or, possibly, the name of another);</li>
<li><code>op</code> a comparator function to use in place of <code>=</code> (optional).</li>
</ul>
<p>It gets messy.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L206">view source</a></div></div><div class="public anchor" id="var-get-neighbours-with-state"><h3>get-neighbours-with-state</h3><div class="usage"><code>(get-neighbours-with-state world x y depth state)</code><code>(get-neighbours-with-state world cell depth state)</code><code>(get-neighbours-with-state world cell state)</code></div><div class="doc"><div class="markdown"><p>Get the neighbours to distance depth of the cell at x, y in this world which have this state.</p>
<ul>
<li><code>world</code> a world, as described in <a href="mw-engine.world.html">world.clj</a>;</li>
<li><code>cell</code> a cell within that world;</li>
<li><code>depth</code> an integer representing the distance from <a href="x,y">x,y</a> that should be searched;</li>
<li><code>state</code> a keyword representing a state in the world.</li>
</ul>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L235">view source</a></div></div><div class="public anchor" id="var-get-num"><h3>get-num</h3><div class="usage"><code>(get-num map key)</code></div><div class="doc"><div class="markdown"><p>Get the value of a property expected to be a number from a map; if not present (or not a number) return 0.</p>
<ul>
<li><code>map</code> a map;</li>
<li><code>key</code> a symbol or keyword, presumed to be a key into the <code>map</code>.</li>
</ul>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L141">view source</a></div></div><div class="public anchor" id="var-in-bounds"><h3>in-bounds</h3><h4 class="deprecated">deprecated in 1.1.7</h4><div class="usage"><code>(in-bounds world x y)</code></div><div class="doc"><div class="markdown"><p>True if x, y are in bounds for this world (i.e., there is a cell at x, y) else false. <em>DEPRECATED</em>: its a predicate, prefer <code>in-bounds?</code>.</p>
<ul>
<li><code>world</code> a world as defined in <a href="mw-engine.world.html">world.clj</a>;</li>
<li><code>x</code> a number which may or may not be a valid x coordinate within that world;</li>
<li><code>y</code> a number which may or may not be a valid y coordinate within that world.</li>
</ul>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L51">view source</a></div></div><div class="public anchor" id="var-in-bounds.3F"><h3>in-bounds?</h3><h4 class="added">added in 1.1.7</h4><div class="usage"><code>(in-bounds? world x y)</code></div><div class="doc"><div class="markdown"><p>True if x, y are in bounds for this world (i.e., there is a cell at x, y) else false.</p>
<ul>
<li><code>world</code> a world as defined in <a href="mw-engine.world.html">world.clj</a>;</li>
<li><code>x</code> a number which may or may not be a valid x coordinate within that world;</li>
<li><code>y</code> a number which may or may not be a valid y coordinate within that world.</li>
</ul>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L62">view source</a></div></div><div class="public anchor" id="var-init-generation"><h3>init-generation</h3><div class="usage"><code>(init-generation _ cell)</code></div><div class="doc"><div class="markdown"><p>Return a cell like this <code>cell</code>, but having a value for :generation, zero if the cell passed had no integer value for generation, otherwise the value taken from the cell passed. The <code>world</code> argument is present only for consistency with the rule engine and is ignored.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L43">view source</a></div></div><div class="public anchor" id="var-map-world"><h3>map-world</h3><div class="usage"><code>(map-world world function)</code><code>(map-world world function additional-args)</code></div><div class="doc"><div class="markdown"><p>Apply this <code>function</code> to each cell in this <code>world</code> to produce a new world. the arguments to the function will be the world, the cell, and any <code>additional-args</code> supplied. Note that we parallel map over rows but just map over cells within a row. Thats because it isnt worth starting a new thread for each cell, but there may be efficiency gains in running rows in parallel.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L100">view source</a></div></div><div class="public anchor" id="var-map-world-n-n"><h3>map-world-n-n</h3><div class="usage"><code>(map-world-n-n world function)</code><code>(map-world-n-n world function additional-args)</code></div><div class="doc"><div class="markdown"><p>Wholly non-parallel map world implementation; see documentation for <code>map-world</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L73">view source</a></div></div><div class="public anchor" id="var-map-world-p-p"><h3>map-world-p-p</h3><div class="usage"><code>(map-world-p-p world function)</code><code>(map-world-p-p world function additional-args)</code></div><div class="doc"><div class="markdown"><p>Wholly parallel map-world implementation; see documentation for <code>map-world</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L87">view source</a></div></div><div class="public anchor" id="var-member.3F"><h3>member?</h3><div class="usage"><code>(member? elt col)</code></div><div class="doc"><div class="markdown"><p>Return true if elt is a member of col, else false.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L31">view source</a></div></div><div class="public anchor" id="var-memo-get-neighbours"><h3>memo-get-neighbours</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>Memoised get neighbours is more efficient when running deeply recursive algorithms on the same world. But its less efficient when running the engine in its normal iterative style, because then we will rarely call get naighbours on the same cell of the same world twice.</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L164">view source</a></div></div><div class="public anchor" id="var-merge-cell"><h3>merge-cell</h3><div class="usage"><code>(merge-cell world cell)</code></div><div class="doc"><div class="markdown"><p>Return a world like this <code>world</code>, but merge the values from this <code>cell</code> with those from the cell in the world with the same co-ordinates</p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L289">view source</a></div></div><div class="public anchor" id="var-population"><h3>population</h3><div class="usage"><code>(population cell species)</code></div><div class="doc"><div class="markdown"><p>Return the population of this species in this cell. Currently a synonym for <code>get-int</code>, but may not always be (depending whether species are later implemented as actors)</p>
<ul>
<li><code>cell</code> a map;</li>
<li><code>species</code> a keyword representing a species which may populate that cell.</li>
</ul>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L154">view source</a></div></div><div class="public anchor" id="var-set-property"><h3>set-property</h3><div class="usage"><code>(set-property world cell property value)</code><code>(set-property world x y property value)</code></div><div class="doc"><div class="markdown"><p>Return a world like this <code>world</code> but with the value of exactly one <code>property</code> of one <code>cell</code> changed to this <code>value</code></p>
</div></div><div class="src-link"><a href="https://github.com/simon-brooke/mw-engine/blob/master/src/cljc/mw_engine/utils.clj#L273">view source</a></div></div></div></body></html>