Boost C++ Libraries: Ticket #13179: geometry::covered_by and geometry::within not working for certain values https://svn.boost.org/trac10/ticket/13179 <p> <em>covered_by</em> and <em>within</em> return false even if the point is obviously located within the polygon, as the following code demonstrates: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/version.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/geometry.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/geometry/geometries/point_xy.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/geometry/geometries/polygon.hpp&gt;</span><span class="cp"></span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">model</span><span class="o">::</span><span class="n">d2</span><span class="o">::</span><span class="n">point_xy</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;</span> <span class="n">Point</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">model</span><span class="o">::</span><span class="n">polygon</span><span class="o">&lt;</span><span class="n">Point</span><span class="o">&gt;</span> <span class="n">Polygon</span><span class="p">;</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Running Boost in version &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">BOOST_VERSION</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">Polygon</span> <span class="n">polygon</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">Point</span><span class="o">&gt;</span> <span class="n">points</span><span class="p">;</span> <span class="n">points</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="mf">68.3</span><span class="p">,</span> <span class="mf">35.5</span><span class="p">));</span> <span class="n">points</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="mf">68.3</span><span class="p">,</span> <span class="mf">35.6</span><span class="p">));</span> <span class="n">points</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="mf">70.3</span><span class="p">,</span> <span class="mf">35.9</span><span class="p">));</span> <span class="n">points</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="mf">70.3</span><span class="p">,</span> <span class="mf">35.8</span><span class="p">));</span> <span class="n">Point</span> <span class="n">point</span><span class="p">(</span><span class="mf">69.2</span><span class="p">,</span> <span class="mf">35.7</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">assign_points</span><span class="p">(</span><span class="n">polygon</span><span class="p">,</span> <span class="n">points</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Point is covered by polygon: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">covered_by</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">polygon</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Point is within by polygon: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">within</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">polygon</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> which gives: </p> <pre class="wiki">Running Boost in version 106500 Point is covered by polygon: 0 Point is within by polygon: 0 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13179 Trac 1.4.3 anonymous Tue, 12 Jun 2018 20:09:08 GMT <link>https://svn.boost.org/trac10/ticket/13179#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13179#comment:1</guid> <description> <p> Replying to <a class="new ticket" href="https://svn.boost.org/trac10/ticket/13179" title="#13179: Bugs: geometry::covered_by and geometry::within not working for certain values (new)">Stanley &lt;stanley.foerster@…&gt;</a>: </p> <blockquote class="citation"> <p> <em>covered_by</em> and <em>within</em> return false even if the point is obviously located within the polygon, as the following code demonstrates: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/version.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/geometry.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/geometry/geometries/point_xy.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/geometry/geometries/polygon.hpp&gt;</span><span class="cp"></span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">model</span><span class="o">::</span><span class="n">d2</span><span class="o">::</span><span class="n">point_xy</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;</span> <span class="n">Point</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">model</span><span class="o">::</span><span class="n">polygon</span><span class="o">&lt;</span><span class="n">Point</span><span class="o">&gt;</span> <span class="n">Polygon</span><span class="p">;</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Running Boost in version &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">BOOST_VERSION</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">Polygon</span> <span class="n">polygon</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">Point</span><span class="o">&gt;</span> <span class="n">points</span><span class="p">;</span> <span class="n">points</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="mf">68.3</span><span class="p">,</span> <span class="mf">35.5</span><span class="p">));</span> <span class="n">points</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="mf">68.3</span><span class="p">,</span> <span class="mf">35.6</span><span class="p">));</span> <span class="n">points</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="mf">70.3</span><span class="p">,</span> <span class="mf">35.9</span><span class="p">));</span> <span class="n">points</span><span class="p">.</span><span class="n">emplace_back</span><span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="mf">70.3</span><span class="p">,</span> <span class="mf">35.8</span><span class="p">));</span> <span class="n">Point</span> <span class="n">point</span><span class="p">(</span><span class="mf">69.2</span><span class="p">,</span> <span class="mf">35.7</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">assign_points</span><span class="p">(</span><span class="n">polygon</span><span class="p">,</span> <span class="n">points</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Point is covered by polygon: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">covered_by</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">polygon</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Point is within by polygon: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">geometry</span><span class="o">::</span><span class="n">within</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">polygon</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> which gives: </p> <pre class="wiki">Running Boost in version 106500 Point is covered by polygon: 0 Point is within by polygon: 0 </pre></blockquote> <p> Did you ever find a work around for this? I'm testing the boost rtree, and it appears that "remove" is not properly drilling down because of the geometry::covered_by.. so even in boost version 1.67 (the latest), I'm stuck using my custom r-tree as boost does not remove all values. NOTE the intersection tests always work (so it seems anyways), as its simply I cannot remove certain values out of the rtree, and my guess is its related to this bug here that you documented. </p> </description> <category>Ticket</category> </item> </channel> </rss>