CGAL / cgal

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

Got CGAL ERROR: precondition violation! while inserting a single Polygon_2 to Polygon_Set_2 #8125

Closed KraftOreo closed 3 months ago

KraftOreo commented 3 months ago

Error Description

I got the following runtime error while inserting one Polygon_2 to an empty Polygon_Set_2:

Using OpenGL context 4.3 GL
terminate called after throwing an instance of 'CGAL::Precondition_exception'
  what():  CGAL ERROR: precondition violation!
Expr: (m_traits.compare_y_at_x_2_object()(p, cv) == EQUAL) && compare_xy(cv.left(), p) == SMALLER && compare_xy(cv.right(), p) == LARGER
File: /path/to/CGAL/include/CGAL/Arr_segment_traits_2.h
Line: 609

Process finished with exit code 134 (interrupted by signal 6:SIGABRT)

Source code

I can reproduce this error at my end with the following code:

#include<CGAL/Simple_cartesian.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include<CGAL/Polygon_2.h>
#include<CGAL/Polygon_set_2.h>
#include<CGAL/Polygon_2_algorithms.h>
#include<CGAL/draw_polygon_2.h>
#include<CGAL/draw_polygon_set_2.h>

typedef double T;
typedef typename CGAL::Simple_cartesian<T> K;
typedef typename K::Point_2 Point_2;
typedef typename K::Segment_2 Segment_2;
typedef typename CGAL::Polygon_2<K> Polygon_2;
typedef typename CGAL::Polygon_set_2<K> Polygon_set_2;

int main(){
  Polygon_set_2 S;
  std::vector<Point_2> vertices2 = {
      Point_2(-1.99618, -1.2929),
      Point_2(-2.7071, -1.99618),
      Point_2(-2.00382, -2.7071),
      Point_2(-1.2929, -2.00382)
  };
    Polygon_2 polygon(vertices2.begin(), vertices2.end());
    CGAL::draw(polygon);
    S.insert(polygon);
    CGAL::draw(S);

  return 0;
}

The first CGAL::draw(polygon); works just fine. I also checked if the polygon is valid, and it turned out to be valid. I also tried different kernels but had no luck. I think this should be an easy fix because this looks like a dumb bug from me, but I can't figure out how because I just started to use CGAL.

Environment

Thanks!

efifogel commented 3 months ago

Use the Epec kernel!


//) o /__ // (__ ( ( ( (/ (/-(-'(/ /

On Sun, 7 Apr 2024 at 08:18, Duo Zhang @.***> wrote:

Error Description

I got the following runtime error while inserting one Polygon_2 to an empty Polygon_Set_2:

Using OpenGL context 4.3 GL terminate called after throwing an instance of 'CGAL::Precondition_exception' what(): CGAL ERROR: precondition violation! Expr: (m_traits.compare_y_at_x_2_object()(p, cv) == EQUAL) && compare_xy(cv.left(), p) == SMALLER && compare_xy(cv.right(), p) == LARGER File: /path/to/CGAL/include/CGAL/Arr_segment_traits_2.h Line: 609

Process finished with exit code 134 (interrupted by signal 6:SIGABRT) Source code

I can reproduce this error at my end with the following code:

include<CGAL/Simple_cartesian.h>

include <CGAL/Exact_predicates_exact_constructions_kernel.h>

include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

include<CGAL/Polygon_2.h>

include<CGAL/Polygon_set_2.h>

include<CGAL/Polygon_2_algorithms.h>

include<CGAL/draw_polygon_2.h>

include<CGAL/draw_polygon_set_2.h>

typedef double T;typedef typename CGAL::Simple_cartesian K;typedef typename K::Point_2 Point_2;typedef typename K::Segment_2 Segment_2;typedef typename CGAL::Polygon_2 Polygon_2;typedef typename CGAL::Polygon_set_2 Polygon_set_2; int main(){ Polygon_set_2 S; std::vector vertices2 = { Point_2(-1.99618, -1.2929), Point_2(-2.7071, -1.99618), Point_2(-2.00382, -2.7071), Point_2(-1.2929, -2.00382) }; Polygon_2 polygon(vertices2.begin(), vertices2.end()); CGAL::draw(polygon); S.insert(polygon); CGAL::draw(S);

return 0; }

The first CGAL::draw(polygon); works just fine. I also checked if the polygon is valid, and it turned out to be valid. I also tried different kernels but had no luck. I think this should be an easy fix because this looks like a dumb bug from me, but I can't figure out how because I just started to use CGAL. Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits): Ubuntu22 64bits
  • Compiler: g++11.4
  • Release or debug mode: Debug mode
  • Specific flags used (if any): -fopenmp -O0 -Wall -fPIC -std=c++17 -Wno-unused-function -Wno-unused-local-typedefs
  • CGAL version: CGAL @a0a9d4
  • Boost version: 1.74
  • Other libraries versions if used (Eigen, TBB, etc.): Eigen: 3.4.0

Thanks!

— Reply to this email directly, view it on GitHub https://github.com/CGAL/cgal/issues/8125, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVBNOEDTVZUKQRLXJHNVVTY4DJI5AVCNFSM6AAAAABF3ARJZCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGIZDSNJWHA2DGNA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

KraftOreo commented 3 months ago

Thanks! It worked!!