boost rtree of box gives wrong intersection with segment

混江龙づ霸主 提交于 2019-12-06 06:19:57

As unlikely as it seems, this appears to me to be a bug.

The first version that even compiles this is Boost 1.56. All previous versions fail with

BOOST_MPL_ASSERT_MSG
    (
        false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
        , (types<Geometry>)
    );

But, even though the code is compiled, it does not seem to be correct...: the intersects call that underlies the query predicate itself returns "false positive" it seems.

Much simplified: 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));
}

UPDATE

Interestingly, it seems to work correctly sometimes for 2d. I'm not sure the outcome isn't simply undefined...

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?
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!