snipt

Ctrl+h for KB shortcuts

Clojure

Clojure in-circle?

1
2
3
4
5
6
7
8
(defn in-circle? [point width]
  (let [mid (/ width 2)
        r mid
        dx (- (point :x) mid)
        dy (- (point :y) mid)]
    (<= (+ (* dx dx)
               (* dy dy))
            (* r r))))
https://snipt.net/embed/689a286c99b06e3dcd6880711c6e4e64/
/raw/689a286c99b06e3dcd6880711c6e4e64/
689a286c99b06e3dcd6880711c6e4e64
clojure
Clojure
8
2019-05-08T22:06:59
True
False
False
/api/public/snipt/53204/
clojure-in-circle
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="p">(</span><span class="kd">defn </span><span class="nv">in-circle?</span> <span class="p">[</span><span class="nv">point</span> <span class="nv">width</span><span class="p">]</span> </span><span id="L-2"><a name="L-2"></a> <span class="p">(</span><span class="k">let </span><span class="p">[</span><span class="nv">mid</span> <span class="p">(</span><span class="nb">/ </span><span class="nv">width</span> <span class="mi">2</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">r</span> <span class="nv">mid</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">dx</span> <span class="p">(</span><span class="nb">- </span><span class="p">(</span><span class="nf">point</span> <span class="ss">:x</span><span class="p">)</span> <span class="nv">mid</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a> <span class="nv">dy</span> <span class="p">(</span><span class="nb">- </span><span class="p">(</span><span class="nf">point</span> <span class="ss">:y</span><span class="p">)</span> <span class="nv">mid</span><span class="p">)]</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">(</span><span class="nb">&lt;= </span><span class="p">(</span><span class="nb">+ </span><span class="p">(</span><span class="nb">* </span><span class="nv">dx</span> <span class="nv">dx</span><span class="p">)</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">(</span><span class="nb">* </span><span class="nv">dy</span> <span class="nv">dy</span><span class="p">))</span> </span><span id="L-8"><a name="L-8"></a> <span class="p">(</span><span class="nb">* </span><span class="nv">r</span> <span class="nv">r</span><span class="p">))))</span> </span></pre></div> </td></tr></table>
clojure