You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CGAL::General_polygon_set_2迭代器版join处理相交图形时崩溃

CGAL General_polygon_set_2::join迭代器重载崩溃问题

为了提升函数效率,我把循环逐个将General_polygon_with_holes_2加入General_polygon_set_2的逻辑,替换成了CGAL文档中接收迭代器的General_polygon_set_2::join重载函数(函数签名:template<class InputIterator > void join (InputIterator begin, InputIterator end))。但只要输入的任意多边形与集合内的多边形相交,程序就会崩溃;而使用单个多边形的join重载函数却能正确处理相交场景。请问是我误用了该方法,还是这属于需要上报的BUG?

经测试,仅在多边形相交时会触发错误,与迭代器中的多边形数量无关。

可复现的简化示例代码

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
#include <CGAL/Gps_circle_segment_traits_2.h>
#include <CGAL/General_polygon_set_2.h>
#include <CGAL/to_rational.h>

#include <vector>

typedef CGAL::Exact_predicates_exact_constructions_kernel   K;
typedef CGAL::Gps_circle_segment_traits_2<K>            T;
typedef T::NT                           NT;
typedef T::Rational_point_2                 Point;
typedef T::X_monotone_curve_2                   C;
typedef T::General_polygon_2                    P;
typedef T::General_polygon_with_holes_2             PWH;
typedef CGAL::General_polygon_set_2<T>              PSet;

int main(int argc, char* argv[])
{
    // Make first polygon.
    const int LEN = 3;
    std::vector<Point> points = { 
        Point(CGAL::to_rational<NT>(1), CGAL::to_rational<NT>(1)),
        Point(CGAL::to_rational<NT>(3), CGAL::to_rational<NT>(1)), 
        Point(CGAL::to_rational<NT>(2), CGAL::to_rational<NT>(3)) 
    };
    C curve;
    P firstBound, secondBound;
    int currI = 0;
    int prevI = LEN - 1;
    while (currI < LEN)
    {
        curve = C(points[prevI], points[currI]);
        firstBound.push_back(curve);
        prevI = currI;
        currI++;
    }
    PWH first, second;
    first.outer_boundary() = firstBound;
    // Make second polygon.
    const int LEN2 = 3;
    std::vector<Point> points2 = { 
        Point(CGAL::to_rational<NT>(2), CGAL::to_rational<NT>(2)),
        Point(CGAL::to_rational<NT>(4), CGAL::to_rational<NT>(2)),
        Point(CGAL::to_rational<NT>(3), CGAL::to_rational<NT>(4)) 
    };
    currI = 0;
    prevI = LEN2 - 1;
    while (currI < LEN2)
    {
        curve = C(points2[prevI], points2[currI]);
        secondBound.push_back(curve);
        prevI = currI;
        currI++;
    }
    // Set up polygon set.
    second.outer_boundary() = secondBound;
    std::vector<PWH> polygons;
    polygons.push_back(second);
    PSet polySet = PSet(first);
    // Program crashes for join.
    polySet.join(polygons.begin(), polygons.end());

    return 0;
}

输入多边形说明

示例中的两个三角形存在重叠区域:

  • 第一个三角形顶点为(1,1)、(3,1)、(2,3)
  • 第二个三角形顶点为(2,2)、(4,2)、(3,4)

内容的提问来源于stack exchange,提问作者Adam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 13:41:03