[英]Why boost::geometry::intersection does not work correct?
I wrote next test function for Boost Geometry intersection function 我为Boost几何交叉函数编写了下一个测试函数
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;
}
};
I expected output result as: 我期望输出结果如下:
(((2, 2), (2, 9), (9, 9), (9, 2), (2, 2)))
but I got: 但我得到了:
((((1, 9), (9, 9), (9, 2), (2, 2), (1, 9))))
I use Boost 1.54. 我使用Boost 1.54。
If I'd change first polygon, intersection works correct. 如果我改变第一个多边形,交叉点工作正确。
EDIT: When I changed type of polygon to 编辑:当我改变多边形的类型
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> >
it started to work correct. 它开始正常工作。 So can't I use previous type for all times? 所以我不能一直使用以前的类型吗?
You need to correct
the input polygons to satisfy the algorithm preconditions: Live On Coliru prints 您需要correct
输入多边形以满足算法前提条件: Live On Coliru打印
(((2, 9), (9, 9), (9, 2), (2, 2), (2, 9)))
#include <boost/tuple/tuple.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
#include <boost/foreach.hpp>
typedef boost::geometry::model::polygon<boost::tuple<int, int> > Polygon;
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
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);
boost::geometry::correct(green);
boost::geometry::correct(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;
}
}
int main()
{
test_boost_intersection();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.