CGAL / cgal

The public CGAL repository, see the README below
https://github.com/CGAL/cgal#readme
Other
4.67k stars 1.35k forks source link

Segment_Delaunay_graph_Linf_2: 4-corners polygon throws an exception #8249

Open KozhevnikovEvgeny opened 4 weeks ago

KozhevnikovEvgeny commented 4 weeks ago

Issue Details

I use CGAL to create a so-called area skeleton in Linf (L-infinity metrics). I have a bunch of successfully working cases, but the very simple case (one 4-corners polygon) causes an assertion and exception. In console window it looks like:

CGAL error: assertion violation!
Expression : dirq.counterclockwise_in_between(dirp, -dirp)
File       : D:\CGAL\build\include\CGAL/Segment_Delaunay_graph_Linf_2/Bisector_Linf.h
Line       : 667
Explanation:

I tried to debug this issue and remove the assertion statement temporarily there. It works w/o an exception, but at last gives one incorrect edge - the edge from/to the point (0,0) is missing while I have two edges from/to (500, -500) (I would expect edges (0,0)->(400,200) and (500, -500)->(500, 100) but I have (500, -500)->(400, 200) instead of the first one. Thanks in advance.

Source Code

// standard includes
#include <iostream>

// choose the kernel
#include <CGAL/Simple_cartesian.h>
typedef CGAL::Simple_cartesian<int> K; // <double> sucks as well

// typedefs for the traits and the algorithm
#include <CGAL/Segment_Delaunay_graph_Linf_2.h>
#include <CGAL/Segment_Delaunay_graph_Linf_filtered_traits_2.h>
typedef CGAL::Segment_Delaunay_graph_Linf_filtered_traits_without_intersections_2<K> Gt;
typedef CGAL::Segment_Delaunay_graph_Linf_2<Gt> SDG2;

int main()
{
    SDG2 sdg;
    // vertices of the polygon
    std::vector<Gt::Point_2> points;
    points.emplace_back(0, 0);
    points.emplace_back(600, 600);
    points.emplace_back(1000, 0);
    points.emplace_back(500, 100); // (500, -100) works fine. I guess this is because of the angle, bigger then 180 degrees

    //segments of the polygon as a pair of vertex indices
    std::vector<std::pair<std::size_t, std::size_t> > indices;
    indices.push_back(std::make_pair(0, 1));
    indices.push_back(std::make_pair(1, 2));
    indices.push_back(std::make_pair(2, 3));
    indices.push_back(std::make_pair(3, 0));

    sdg.insert_segments(points.begin(), points.end(), indices.begin(), indices.end());

    bool bValid = sdg.is_valid(true, 1);
    std::cout << "CGAL success = " << (bValid ? "TRUE" : "FALSE") << std::endl;

    // Draw the diagram
    sdg.draw_skeleton(std::cout);

    return 0;
}

Environment