使用 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?

本文关键字:multi polygon 常规 geometry boost ifference 为什么 使用      更新时间:2023-10-16

给定以下代码:

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