我为Boost Geometry相交函数编写了下一个测试函数
typedef boost::geometry::model::polygon<boost::tuple<int, int> > Polygon;
void test_boost_intersection() {
Polygon green, blue;
boost::geometry::read_wkt("POLYGON((0 0,0 9,9 9,9 0,0 0))", green);
boost::geometry::read_wkt("POLYGON((2 2,2 9,9 9,9 2,2 2))", blue);
std::deque<Polygon> output;
boost::geometry::intersection(green, blue, output);
BOOST_FOREACH(Polygon const& p, output)
{
std::cout << boost::geometry::dsv(p) << std::endl;
}
};
我预期的输出结果为:
(((2, 2), (2, 9), (9, 9), (9, 2), (2, 2)))
但我得到了:
((((1, 9), (9, 9), (9, 2), (2, 2), (1, 9))))
我使用 Boost 1.54。
如果我要更改第一个多边形,则交集正确。
编辑:当我将多边形类型更改为
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> >
它开始正常工作。所以我不能一直使用以前的类型吗?