使用 boost::geometry::d ifference,为什么在使用 multi_polygon 而不是使用常规
Using boost::geometry::difference, why am I getting an empty result when using multi_polygon and not with a regular polygon?
给定以下代码:
typedef boost::geometry::model::d2::point_xy<int16_t, boost::geometry::cs::cartesian> Point_t;
typedef boost::geometry::model::polygon<Point_t> Polygon_t;
typedef boost::geometry::model::multi_polygon<Polygon_t> MultiPolygon_t;
std::vector<Point_t> points1;
points1.push_back(Point_t(1473, 627));
points1.push_back(Point_t(1473, 1155));
points1.push_back(Point_t(908, 1155));
points1.push_back(Point_t(908, 627));
Polygon_t poly1;
boost::geometry::assign_points(poly1, points1);
boost::geometry::correct(poly1);
MultiPolygon_t multiPoly;
multiPoly.push_back(poly1);
std::vector<Point_t> points2;
points2.push_back(Point_t(1956, 956));
points2.push_back(Point_t(1956, 1028));
points2.push_back(Point_t(115, 1023));
points2.push_back(Point_t(127, 951));
Polygon_t poly2;
boost::geometry::assign_points(poly2, points2);
boost::geometry::correct(poly2);
MultiPolygon_t resultMulti;
MultiPolygon_t resultSimple;
boost::geometry::difference(multiPoly, poly2, resultMulti);
boost::geometry::difference(poly1, poly2, resultSimple);
bool bMultiEmpty = resultMulti.empty();
bool bSimpleEmpty = resultSimple.empty();
EAGLE_ASSERT(!bSimpleEmpty);
EAGLE_ASSERT(!bMultiEmpty);
我得到的结果:
bSimpleEmpty -> FALSE
bMultiEmpty -> TRUE
我希望结果在这两种情况下都是非空的......多多边形中唯一用于bSimpleEmpty
计算的多边形是相同的。我是否陷入了误解?
使用加速 1.51
请指教!
当使用 16 位整数作为坐标类型的模板参数时,问题似乎是提升库中的溢出。使用双打时似乎可以完美工作。
我没有"断开连接"。您确定使用相同的代码吗?如果是这样,请查看升级 Boost 是否有帮助:
住在科里鲁
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <iostream>
#include <vector>
typedef boost::geometry::model::d2::point_xy<int16_t, boost::geometry::cs::cartesian> Point_t;
typedef boost::geometry::model::polygon<Point_t> Polygon_t;
typedef boost::geometry::model::multi_polygon<Polygon_t> MultiPolygon_t;
int main() {
Polygon_t poly1;
{
std::vector<Point_t> points1;
points1.push_back(Point_t(1473, 627));
points1.push_back(Point_t(1473, 1155));
points1.push_back(Point_t(908, 1155));
points1.push_back(Point_t(908, 627));
boost::geometry::assign_points(poly1, points1);
boost::geometry::correct(poly1);
}
Polygon_t poly2;
{
std::vector<Point_t> points2;
points2.push_back(Point_t(1956, 956));
points2.push_back(Point_t(1956, 1028));
points2.push_back(Point_t(115, 1023));
points2.push_back(Point_t(127, 951));
boost::geometry::assign_points(poly2, points2);
boost::geometry::correct(poly2);
}
//////////////////////////////////
//
MultiPolygon_t multiPoly;
multiPoly.push_back(poly1);
MultiPolygon_t resultMulti;
MultiPolygon_t resultSimple;
boost::geometry::difference(multiPoly, poly2, resultMulti);
boost::geometry::difference(poly1, poly2, resultSimple);
bool bMultiEmpty = resultMulti.empty();
bool bSimpleEmpty = resultSimple.empty();
std::cout << std::boolalpha << bSimpleEmpty << ", " << bMultiEmpty << "n";
}
指纹
true, true
相关文章:
- 可视化C++:发布模式的运行时库作为'Multi-threaded Debug DLL'
- boost beast Websocket Multi Request Server/Client 并不是真正的 mul
- c++如何使用Curl Multi-Interface连续循环
- 在 R 中调用"multi file C++ code with external libraries referenced"
- 适用于Visual Studio 2017的CMake Multi-Project设置
- libcurl进度回调无法与Multi一起使用
- 使用Boost Polygon的减法结果不正确
- 如何使用 std::get 作为 boost-multi-index 容器键的global_fun
- 为什么STD::( multi)集提供非常量迭代方法
- 编译boost时"threading=multi"究竟做了什么
- 从 2D C 列表创建 boost.geometry.model.polygon
- C++ Multi threading
- C++ Multi-threading?
- Increment a variable string & Multi fstream open c++
- "dynamically allocated memory emulating multi-dimensional array"的正确术语?
- windows c++ multi thread
- Visual Studio 字符集 'Not set' vs 'Multi byte character set'
- Boost Multi Index标识索引
- Qt Multi-Threading
- 什么是"Multi Return"函数?