<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<box, triangles> 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'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 <boost/geometry.hpp><br>#include <boost/geometry/index/rtree.hpp><br>#include <boost/geometry/geometries/box.hpp><br>#include <boost/geometry/geometries/point.hpp><br><br>namespace bg = boost::geometry;<br>namespace bgi = boost::geometry::index;<br><br>using point = typename bg::model::point<double, 2, bg::cs::cartesian>;<br>using box = typename bg::model::box<point>;<br><br>bool operator==(point const &a, point const &b)<br>{<br> using bg::get;<br> return get<0>(a) == get<0>(b) && get<1>(a) == get<1>(b);<br>}<br><br>struct triangle<br>{<br> point a;<br> point b;<br> point c;<br><br> bool operator==(triangle const &other) const<br> {<br> return a == other.a && b == other.b && c == other.c;<br> }<br>};<br><br>int main()<br>{<br> using indexed_t = typename std::pair<box, triangle>;<br> using RTree = boost::geometry::index::rtree<indexed_t, boost::geometry::index::rstar<8>>;<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->second == t2); // this fails<br> return 0;<br>}<br></div></div>