Boost logo

Geometry :

Subject: Re: [geometry] Bug in rtree of box when queried with segment?
From: Adrian Muresan (adi_mur1_at_[hidden])
Date: 2015-09-14 10:34:10


Update, there's an easier way to reproduce this as a box-segment intersection:
http://stackoverflow.com/questions/32457920/boost-rtree-of-box-gives-wrong-intersection-with-segment

      De : Adrian Muresan <adi_mur1_at_[hidden]>
 Ã€Â : "geometry_at_[hidden]" <geometry_at_[hidden]>
 Envoyé le : Mercredi 9 septembre 2015 13h00
 Objet : Bug in rtree of box when queried with segment?
   
Hello,
There seems to be a bug that gives false results when querying a box rtree with a segment like in the example below. In this example the rtree contains a y-planar box, but the bug reproduces even with a non-planar box (have tried with a min corner of {0, -5, 0}). The query segment is a z-aligned line.

Note that if you replace the query with a box instead of a segment then it works as expected. I have tried this with boost 1.56 and 1.59.
Any ideas?Thanks!

#include <vector>
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <vector>
#include <iterator>
#include <memory>

namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
typedef bg::model::point<double, 3, bg::cs::cartesian> point_def;
typedef bg::model::box<point_def> box;
typedef bg::model::segment<point_def> segment;
typedef std::pair<box, size_t> tri_box;
typedef bgi::rtree< tri_box, bgi::linear<8>> tree_type;

using namespace std;

TEST(boost_rtree, cant_intersect_box_with_segment) {
  vector<tri_box> buff(1);
  buff[0].first = box{point_def{0, 0, 0}, point_def{10, 0, 10}};
  buff[0].second = 1;
  tree_type tree(buff);

  segment query{point_def{2, 1, 0}, point_def{2, 1, 10}};
//  box query{point_def{2, 1, 0}, point_def{2, 1, 10}};
  vector<tri_box> out;

  size_t count = tree.query(bgi::intersects(query), back_inserter(out));

  ASSERT_EQ(0, count);
  ASSERT_EQ(0, out.size());
}

  



Geometry list run by mateusz at loskot.net