mirror of
https://github.com/vrld/HC.git
synced 2024-11-28 14:04:21 +00:00
546 lines
28 KiB
HTML
546 lines
28 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>HC.polygon — HC 0.1-1 documentation</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="top" title="HC 0.1-1 documentation" href="index.html"/>
|
|
<link rel="up" title="Reference" href="reference.html"/>
|
|
<link rel="next" title="HC.spatialhash" href="SpatialHash.html"/>
|
|
<link rel="prev" title="HC.shapes" href="Shapes.html"/>
|
|
|
|
|
|
<script src="_static/js/modernizr.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav" role="document">
|
|
|
|
<div class="wy-grid-for-nav">
|
|
|
|
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-scroll">
|
|
<div class="wy-side-nav-search">
|
|
|
|
|
|
|
|
<a href="index.html" class="icon icon-home"> HC
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<div class="version">
|
|
0.1
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div role="search">
|
|
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
|
|
|
|
|
|
<ul class="current">
|
|
<li class="toctree-l1 current"><a class="reference internal" href="reference.html">Reference</a><ul class="current">
|
|
<li class="toctree-l2"><a class="reference internal" href="MainModule.html">HC</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Shapes.html">HC.shapes</a></li>
|
|
<li class="toctree-l2 current"><a class="current reference internal" href="">HC.polygon</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="SpatialHash.html">HC.spatialhash</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Vector.html">HC.vector</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Class.html">HC.class</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Tutorial</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
|
|
|
|
|
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="index.html">HC</a>
|
|
</nav>
|
|
|
|
|
|
|
|
<div class="wy-nav-content">
|
|
<div class="rst-content">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
|
<ul class="wy-breadcrumbs">
|
|
<li><a href="index.html">Docs</a> »</li>
|
|
|
|
<li><a href="reference.html">Reference</a> »</li>
|
|
|
|
<li>HC.polygon</li>
|
|
<li class="wy-breadcrumbs-aside">
|
|
|
|
|
|
<a href="_sources/Polygon.txt" rel="nofollow"> View page source</a>
|
|
|
|
|
|
</li>
|
|
</ul>
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
<div itemprop="articleBody">
|
|
|
|
<div class="section" id="hc-polygon">
|
|
<h1>HC.polygon<a class="headerlink" href="#hc-polygon" title="Permalink to this headline">¶</a></h1>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">polygon</span> <span class="o">=</span> <span class="nb">require</span> <span class="s1">'</span><span class="s">HC.polygon'</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Polygon class with some handy algorithms. Does not provide collision detection
|
|
- this functionality is provided by <a class="reference internal" href="Shapes.html#newPolygonShape" title="newPolygonShape"><code class="xref js js-func docutils literal"><span class="pre">newPolygonShape()</span></code></a> instead.</p>
|
|
<dl class="class">
|
|
<dt id="Polygon">
|
|
<em class="property">class </em><code class="descname">Polygon</code><span class="sig-paren">(</span><em>x1</em>, <em>y1</em>, <em>...</em>, <em>xn</em>, <em>yn</em><span class="sig-paren">)</span><a class="headerlink" href="#Polygon" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first simple">
|
|
<li><strong>x1,y1, ..., xn,yn</strong> (<em>numbers</em>) – The corners of the polygon. At least three corners are needed.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The polygon object.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Construct a polygon.</p>
|
|
<p>At least three points that are not collinear (i.e. not lying on a straight
|
|
line) are needed to construct the polygon. If there are collinear points, these
|
|
points will be removed. The shape of the polygon is not changed.</p>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">The syntax depends on used class system. The shown syntax works when using
|
|
the bundled <a class="reference external" href="http://vrld.github.com/hump/#hump.class">hump.class</a> or
|
|
<a class="reference external" href="https://bitbucket.org/bartbes/slither">slither</a>.</p>
|
|
</div>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">Polygon</span> <span class="o">=</span> <span class="nb">require</span> <span class="s1">'</span><span class="s">HC.polygon'</span>
|
|
<span class="n">poly</span> <span class="o">=</span> <span class="n">Polygon</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span><span class="mi">50</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span><span class="mi">30</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:unpack">
|
|
<code class="descname">Polygon:unpack</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:unpack" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><code class="docutils literal"><span class="pre">x1,y1,</span> <span class="pre">...,</span> <span class="pre">xn,yn</span></code> - The vertices of the polygon.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Get the polygon’s vertices. Useful for drawing with <code class="docutils literal"><span class="pre">love.graphics.polygon()</span></code>.</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">love</span><span class="p">.</span><span class="n">graphics</span><span class="p">.</span><span class="n">draw</span><span class="p">(</span><span class="s1">'</span><span class="s">line'</span><span class="p">,</span> <span class="n">poly</span><span class="p">:</span><span class="nb">unpack</span><span class="p">())</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:clone">
|
|
<code class="descname">Polygon:clone</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:clone" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A copy of the polygon.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Get a copy of the polygon.</p>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p>Since Lua uses references when simply assigning an existing polygon to a
|
|
variable, unexpected things can happen when operating on the variable. Consider
|
|
this code:</p>
|
|
<div class="last highlight-lua"><div class="highlight"><pre><span class="n">p1</span> <span class="o">=</span> <span class="n">Polygon</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span><span class="mi">50</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span><span class="mi">30</span><span class="p">)</span>
|
|
<span class="n">p2</span> <span class="o">=</span> <span class="n">p1</span> <span class="c1">-- p2 is a reference</span>
|
|
<span class="n">p3</span> <span class="o">=</span> <span class="n">p1</span><span class="p">:</span><span class="n">clone</span><span class="p">()</span> <span class="c1">-- p3 is a clone</span>
|
|
<span class="n">p2</span><span class="p">:</span><span class="n">rotate</span><span class="p">(</span><span class="nb">math.pi</span><span class="p">)</span> <span class="c1">-- p1 will be rotated, too!</span>
|
|
<span class="n">p3</span><span class="p">:</span><span class="n">rotate</span><span class="p">(</span><span class="o">-</span><span class="nb">math.pi</span><span class="p">)</span> <span class="c1">-- only p3 will be rotated</span>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">copy</span> <span class="o">=</span> <span class="n">poly</span><span class="p">:</span><span class="n">clone</span><span class="p">()</span>
|
|
<span class="n">copy</span><span class="p">:</span><span class="n">move</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">20</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:bbox">
|
|
<code class="descname">Polygon:bbox</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:bbox" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><code class="docutils literal"><span class="pre">x1,</span> <span class="pre">y1,</span> <span class="pre">x2,</span> <span class="pre">y2</span></code> - Corners of the counding box.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Get axis aligned bounding box.
|
|
<code class="docutils literal"><span class="pre">x1,</span> <span class="pre">y1</span></code> defines the upper left corner, while <code class="docutils literal"><span class="pre">x2,</span> <span class="pre">y2</span></code> define the lower
|
|
right corner.</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">x1</span><span class="p">,</span><span class="n">y1</span><span class="p">,</span><span class="n">x2</span><span class="p">,</span><span class="n">y2</span> <span class="o">=</span> <span class="n">poly</span><span class="p">:</span><span class="n">bbox</span><span class="p">()</span>
|
|
<span class="c1">-- draw bounding box</span>
|
|
<span class="n">love</span><span class="p">.</span><span class="n">graphics</span><span class="p">.</span><span class="n">rectangle</span><span class="p">(</span><span class="s1">'</span><span class="s">line'</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span><span class="n">y2</span><span class="p">,</span> <span class="n">x2</span><span class="o">-</span><span class="n">x1</span><span class="p">,</span> <span class="n">y2</span><span class="o">-</span><span class="n">y1</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:isConvex">
|
|
<code class="descname">Polygon:isConvex</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:isConvex" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><code class="docutils literal"><span class="pre">true</span></code> if the polygon is convex, <code class="docutils literal"><span class="pre">false</span></code> otherwise.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Test if a polygon is convex, i.e. a line line between any two points inside the
|
|
polygon will lie in the interior of the polygon.</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="c1">-- split into convex sub polygons</span>
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">poly</span><span class="p">:</span><span class="n">isConvex</span><span class="p">()</span> <span class="k">then</span>
|
|
<span class="n">list</span> <span class="o">=</span> <span class="n">poly</span><span class="p">:</span><span class="n">splitConvex</span><span class="p">()</span>
|
|
<span class="k">else</span>
|
|
<span class="n">list</span> <span class="o">=</span> <span class="p">{</span><span class="n">poly</span><span class="p">:</span><span class="n">clone</span><span class="p">()}</span>
|
|
<span class="k">end</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:move">
|
|
<code class="descname">Polygon:move</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:move" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
|
|
<li><strong>x, y</strong> (<em>numbers</em>) – Coordinates of the direction to move.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Move a polygon in a direction..</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">poly</span><span class="p">:</span><span class="n">move</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">)</span> <span class="c1">-- move 10 units right and 5 units up</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:rotate">
|
|
<code class="descname">Polygon:rotate</code><span class="sig-paren">(</span><em>angle</em><span class="optional">[</span>, <em>cx</em>, <em>cy</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:rotate" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
|
|
<li><strong>angle</strong> (<em>number</em>) – The angle to rotate in radians.</li>
|
|
<li><strong>cx, cy</strong> (<em>numbers</em>) – The rotation center (optional).</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Rotate the polygon. You can define a rotation center. If it is omitted, the
|
|
polygon will be rotated around it’s centroid.</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">p1</span><span class="p">:</span><span class="n">rotate</span><span class="p">(</span><span class="nb">math.pi</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span> <span class="c1">-- rotate p1 by 90° around it's center</span>
|
|
<span class="n">p2</span><span class="p">:</span><span class="n">rotate</span><span class="p">(</span><span class="nb">math.pi</span><span class="o">/</span><span class="mi">4</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span><span class="mi">100</span><span class="p">)</span> <span class="c1">-- rotate p2 by 45° around the point 100,100</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:triangulate">
|
|
<code class="descname">Polygon:triangulate</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:triangulate" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><code class="docutils literal"><span class="pre">table</span></code> of Polygons: Triangles that the polygon is composed of.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Split the polygon into triangles.</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">triangles</span> <span class="o">=</span> <span class="n">poly</span><span class="p">:</span><span class="n">triangulate</span><span class="p">()</span>
|
|
<span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">triangle</span> <span class="k">in</span> <span class="nb">ipairs</span><span class="p">(</span><span class="n">triangles</span><span class="p">)</span> <span class="k">do</span>
|
|
<span class="n">triangles</span><span class="p">.</span><span class="n">move</span><span class="p">(</span><span class="nb">math.random</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">10</span><span class="p">),</span> <span class="nb">math.random</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">10</span><span class="p">))</span>
|
|
<span class="k">end</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:splitConvex">
|
|
<code class="descname">Polygon:splitConvex</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:splitConvex" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><code class="docutils literal"><span class="pre">table</span></code> of Polygons: Convex polygons that form the original polygon.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Split the polygon into convex sub polygons.</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">convex</span> <span class="o">=</span> <span class="n">concave_polygon</span><span class="p">:</span><span class="n">splitConvex</span><span class="p">()</span>
|
|
<span class="k">function</span> <span class="nc">love</span><span class="p">.</span><span class="nf">draw</span><span class="p">()</span>
|
|
<span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">poly</span> <span class="k">in</span> <span class="nb">ipairs</span><span class="p">(</span><span class="n">convex</span><span class="p">)</span> <span class="k">do</span>
|
|
<span class="n">love</span><span class="p">.</span><span class="n">graphics</span><span class="p">.</span><span class="n">polygon</span><span class="p">(</span><span class="s1">'</span><span class="s">fill'</span><span class="p">,</span> <span class="n">poly</span><span class="p">:</span><span class="nb">unpack</span><span class="p">())</span>
|
|
<span class="k">end</span>
|
|
<span class="k">end</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:mergedWith">
|
|
<code class="descname">Polygon:mergedWith</code><span class="sig-paren">(</span><em>other</em><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:mergedWith" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first simple">
|
|
<li><strong>other</strong> (<a class="reference internal" href="#Polygon" title="Polygon"><em>Polygon</em></a>) – The polygon to merge with.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The merged polygon, or nil if the two polygons don’t share an edge.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Create a merged polygon of two polygons <strong>if, and only if</strong> the two polygons
|
|
share one complete edge. If the polygons share more than one edge, the result
|
|
may be erroneous.</p>
|
|
<p>This function does not change either polygon, but rather creates a new one.</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="n">merged</span> <span class="o">=</span> <span class="n">p1</span><span class="p">:</span><span class="n">mergedWith</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:contains">
|
|
<code class="descname">Polygon:contains</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:contains" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first simple">
|
|
<li><strong>x, y</strong> (<em>numbers</em>) – Point to test.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><code class="docutils literal"><span class="pre">true</span></code> if <code class="docutils literal"><span class="pre">x,y</span></code> lies in the interior of the polygon.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Test if the polygon contains a given point.</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="k">if</span> <span class="n">button</span><span class="p">:</span><span class="n">contains</span><span class="p">(</span><span class="n">love</span><span class="p">.</span><span class="n">mouse</span><span class="p">.</span><span class="n">getPosition</span><span class="p">())</span> <span class="k">then</span>
|
|
<span class="n">button</span><span class="p">:</span><span class="n">setHovered</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>
|
|
<span class="k">end</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="Polygon:intersectionsWithRay">
|
|
<code class="descname">Polygon:intersectionsWithRay</code><span class="sig-paren">(</span><em>x</em>, <em>y</em>, <em>dx</em>, <em>dy</em><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:intersectionsWithRay" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first simple">
|
|
<li><strong>x, y</strong> (<em>numbers</em>) – Starting point of the ray.</li>
|
|
<li><strong>dx, dy</strong> (<em>numbers</em>) – Direction of the ray.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Table of ray parameters.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Test if the polygon intersects the given ray.
|
|
The ray parameters of the intersections are returned as a table.
|
|
The position of the intersections can be computed as
|
|
<code class="docutils literal"><span class="pre">(x,y)</span> <span class="pre">+</span> <span class="pre">ray_parameter</span> <span class="pre">*</span> <span class="pre">(dx,</span> <span class="pre">dy)</span></code>.</p>
|
|
<dl class="function">
|
|
<dt id="Polygon:intersectsRay">
|
|
<code class="descname">Polygon:intersectsRay</code><span class="sig-paren">(</span><em>x</em>, <em>y</em>, <em>dx</em>, <em>dy</em><span class="sig-paren">)</span><a class="headerlink" href="#Polygon:intersectsRay" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first simple">
|
|
<li><strong>x, y</strong> (<em>numbers</em>) – Starting point of the ray.</li>
|
|
<li><strong>dx, dy</strong> (<em>numbers</em>) – Direction of the ray.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><code class="docutils literal"><span class="pre">intersects,</span> <span class="pre">ray_parameter</span></code> - intersection indicator and ray paremter.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<p>Test if the polygon intersects a ray.
|
|
If the shape intersects the ray, the point of intersection can be computed by
|
|
<code class="docutils literal"><span class="pre">(x,y)</span> <span class="pre">+</span> <span class="pre">ray_parameter</span> <span class="pre">*</span> <span class="pre">(dx,</span> <span class="pre">dy)</span></code>.</p>
|
|
<p><strong>Example</strong>:</p>
|
|
<div class="highlight-lua"><div class="highlight"><pre><span class="k">if</span> <span class="n">poly</span><span class="p">:</span><span class="n">intersectsRay</span><span class="p">(</span><span class="mi">400</span><span class="p">,</span><span class="mi">300</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span><span class="n">dy</span><span class="p">)</span> <span class="k">then</span>
|
|
<span class="n">love</span><span class="p">.</span><span class="n">graphics</span><span class="p">.</span><span class="n">setLine</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c1">-- highlight polygon</span>
|
|
<span class="k">end</span>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<footer>
|
|
|
|
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
|
|
|
<a href="SpatialHash.html" class="btn btn-neutral float-right" title="HC.spatialhash" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
|
|
|
|
|
|
<a href="Shapes.html" class="btn btn-neutral" title="HC.shapes" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
|
|
|
</div>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>
|
|
© Copyright 2015, Matthias Richter.
|
|
|
|
</p>
|
|
</div>
|
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT:'./',
|
|
VERSION:'0.1-1',
|
|
COLLAPSE_INDEX:false,
|
|
FILE_SUFFIX:'.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
|
<script type="text/javascript" src="_static/underscore.js"></script>
|
|
<script type="text/javascript" src="_static/doctools.js"></script>
|
|
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="_static/js/theme.js"></script>
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.StickyNav.enable();
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html> |