为什么boost::geometry::交集不能正确工作
Why boost::geometry::intersection does not work correct?
我编写了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> >
它开始正常工作。所以我不能一直使用先前类型吗?
您需要 correct
输入多边形来满足算法的先决条件:Live On Coliru prints
(((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();
}
相关文章:
- 为什么 decltype(declval()<T>.func()) 可以工作,而 decltype(&T::func) 不能工作?
- 为什么带有 const 关键字的构造函数可以工作,而没有它就不能工作?
- 为什么函数 sleep() 在 klee 执行 Objectfile 时不能工作?
- 为什么这段代码不能工作
- 向下转换到子类的问题,多态不能工作
- c++将字符串转换为char不能工作
- 为什么这个c++成员初始化列表不能工作?
- 为什么没有_Remove_reference, std::move()不能工作
- 为什么c++ Lambda表达式不能工作
- 为什么这个c++链接不能工作?(OSX小牛)
- 为什么cin.getline()不能工作(c++)
- c++类不能工作
- 为什么c++标准库不能工作?
- 为什么这个用于在c++ 11和TR1之间切换的预处理器宏不能工作?
- 什么可能导致我们的应用程序不能工作?c++
- c++宏连接在gcc下不能工作
- 具有可变范围的Std::vector不能工作
- 从c++程序创建tar.gz-archive不能工作
- 为什么main()函数之后的类定义不能工作
- 为什么元组不能工作?