Boost rtree为段查询的某些交集提供了错误的交集结果。 在这种情况下,边界框是y = 0时的y平面10×10平方。我使用从(2,1,0)到(2,1,10)的z对齐线查询。有趣的是,如果我使用一个框进行查询而不是一个段,那么它会按预期工作。当盒子不是平面时,也会出现这种情况,只需将最小角移动到(0,-5,0),它仍然会发生。
我是否使用了这个错误或者它是一个提升中的错误?
编辑:在Boost 1.56和1.59上试过这个。
#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); // fails here
ASSERT_EQ(0, out.size());
}
编辑:问题正在移动以提升邮件列表:lists.boost.org/geometry/2015/09/3472.php
答案 0 :(得分:5)
尽管看起来不太可能,但在我看来这是一个错误。
第一个甚至编译它的版本是Boost 1.56。以前的所有版本都以
失败BOOST_MPL_ASSERT_MSG
(
false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
, (types<Geometry>)
);
但是,即使编译代码,它似乎也不正确......:查询谓词本身的intersects
调用似乎返回“误报”。
很简化: Live On Coliru
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/segment.hpp>
namespace bg = boost::geometry;
typedef bg::model::point<int, 3, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef bg::model::segment<point> segment;
int main() {
box y0rect = box{point{0, 0, 0}, point{10, 0, 10}};
segment seg{point{2, 1, 0}, point{2, 1, 10}};
bg::correct(y0rect);
bg::correct(seg);
assert(!bg::intersects(seg, y0rect));
}
<强>更新强>
有趣的是,它似乎正常工作 有时 2d。我不确定结果是不是简单的未定义......
<强> Live On Coliru 强>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/segment.hpp>
namespace bg = boost::geometry;
typedef bg::model::point<int, 4, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef bg::model::segment<point> segment;
int main() {
box y0rect = box{point{0, 0}, point{10, 10}};
bg::correct(y0rect);
{
segment seg{point{12, 0}, point{20, 10}};
bg::correct(seg);
assert(!bg::intersects(seg, y0rect));
}
{
segment seg{point{2, 0}, point{8, 6}};
bg::correct(seg);
assert(bg::intersects(seg, y0rect));
}
{
segment seg{point{2, 0}, point{18, 6}};
bg::correct(seg);
assert(bg::intersects(seg, y0rect)); // OOPS BREAKS?
}
}