<div dir="ltr"><div dir="ltr">Hi everybody,<br><br>I am trying to use an rtree as an index to a set of triangles to perform some spatial queries.<br>The rtree stores std::pair&lt;box, triangles&gt; where box is the boost geometry box.<br><br>The problem occurs with the nearest query and, in particular, when two or more elements have equivalent boxes,<br> and I look for just one element, the result may be wrong.<br><br>Look at the code below; the problem is that the two triangles have equivalent bounding boxes, and since<br>the query returns just one element, the result is the one I inserted first. Even though the bounding boxes <br>are the same, the two elements are not, I&#39;d like the query to returns t2 instead.<br><br>I think I need to provide an IndexableGetter to my rtree, but according to<br><a href="https://www.boost.org/doc/libs/1_70_0/libs/geometry/doc/html/geometry/spatial_indexes/creation_and_modification.html">https://www.boost.org/doc/libs/1_70_0/libs/geometry/doc/html/geometry/spatial_indexes/creation_and_modification.html</a><br>the returned value has to be one of the Indexable concepts (Point, Box, or Segment) and none of them seems to satisfy<br>my requirements.<br><br>Do I need to make my triangle Indexable? I could not find any reference on how to do that and what methods are required<br>for a type to be indexable; can anyone provide any resources that may be useful?<br><br>Thanks, Andrea.<br><br>#include &lt;boost/geometry.hpp&gt;<br>#include &lt;boost/geometry/index/rtree.hpp&gt;<br>#include &lt;boost/geometry/geometries/box.hpp&gt;<br>#include &lt;boost/geometry/geometries/point.hpp&gt;<br><br>namespace bg = boost::geometry;<br>namespace bgi = boost::geometry::index;<br><br>using point = typename bg::model::point&lt;double, 2, bg::cs::cartesian&gt;;<br>using box = typename bg::model::box&lt;point&gt;;<br><br>bool operator==(point const &amp;a, point const &amp;b)<br>{<br>    using bg::get;<br>    return get&lt;0&gt;(a) == get&lt;0&gt;(b) &amp;&amp; get&lt;1&gt;(a) == get&lt;1&gt;(b);<br>}<br><br>struct triangle<br>{<br>    point a;<br>    point b;<br>    point c;<br><br>    bool operator==(triangle const &amp;other) const<br>    {<br>        return a == other.a &amp;&amp; b == other.b &amp;&amp; c == other.c;<br>    }<br>};<br><br>int main()<br>{<br>    using indexed_t = typename std::pair&lt;box, triangle&gt;;<br>    using RTree = boost::geometry::index::rtree&lt;indexed_t, boost::geometry::index::rstar&lt;8&gt;&gt;;<br><br>    triangle t1{point{0, 0}, point{1, 0}, point{1, 1}};<br>    box b1{point{0, 0}, point{1, 1}};<br><br>    triangle t2{point{0, 0}, point{1, 1}, point{0, 1}};<br>    box b2{point{0, 0}, point{1, 1}};<br><br>    RTree rtree;<br>    rtree.insert({b1, t1});<br>    rtree.insert({b2, t2});<br><br>    auto it = rtree.qbegin(bgi::nearest(point(-1, 0.5), 1));<br><br>    assert(it-&gt;second == t2); // this fails<br>    return 0;<br>}<br></div></div>