cgal icon indicating copy to clipboard operation
cgal copied to clipboard

polygon disjoint problem with Polygon_Set_2

Open mptangtang opened this issue 2 years ago • 1 comments

Create a Polygon_Set_2 Failed!

Issue Details

When I tried to construct a polygon set using the following code, it failed

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Polygon_set_2.h>
#include <CGAL/draw_polygon_2.h>
#include <CGAL/draw_polygon_set_2.h>
#include <list>


typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2                                   Point_2;
typedef CGAL::Polygon_2<Kernel>                           Polygon_2;
typedef CGAL::Polygon_with_holes_2<Kernel>                Polygon_with_holes_2;
typedef CGAL::Polygon_set_2<Kernel>                       Polygon_set_2;

Polygon_set_2 result_polygon_set;

Polygon_2 polygon_middle;
polygon_middle.push_back(Point_2(7, 5));
polygon_middle.push_back(Point_2(5, 8));
polygon_middle.push_back(Point_2(3, 4));
polygon_middle.push_back(Point_2(6, 2));

Polygon_2 polygon_right;
polygon_right.push_back(Point_2(7, 5));
polygon_right.push_back(Point_2(8, 4));
polygon_right.push_back(Point_2(10, 5));
polygon_right.push_back(Point_2(9, 9));

result_polygon_set.insert(polygon_middle);
result_polygon_set.insert(polygon_right);

The program have a runtime error as follows:

CGAL error: assertion violation!
Expression : CGAL::assign(const_f, obj_f) && !const_f->contained()
File       : E:\PreBuild\vs_indep\CGAL5.5\include\CGAL/Boolean_set_operations_2/Gps_on_surface_base_2_impl.h
Line       : 353
Explanation:
Refer to the bug-reporting instructions at https://www.cgal.org/bug_report.html

if I change the first point of polygon_right by

polygon_right.push_back(Point_2(7.001, 5));

Everything is fine. This means that the problem is introduced by inserting two polygons with shared vertex. However, the document of CGAL tell us

 (ii) the boundaries of two sets intersect but their interiors are disjoint; namely they have a finite number of common points or even share a boundary curve (still in this case P∩Q=∅;)
In addition, a polygon-set object can be constructed from a single polygon object or from a polygon-with-holes object. Once constructed, it is possible to insert new polygons (or polygons with holes) into the set using the [insert()](https://github.com/CGAL/cgal/Arrangement_on_surface_2/group__PkgArrangementOnSurface2Insert.html#gab9fcd6cd172ef1c36d36f4693f2ec128) method, as long as the inserted polygons and the existing polygons in the set are disjoint.

How could we handle polygons with same vertices or same edges that still disjoint in this case?

Thank you very much!

mptangtang avatar Jul 31 '22 11:07 mptangtang

The polygons are not disjoint' Therefore, you cannot use the operation .insert(). See the precondition under https://doc.cgal.org/latest/Boolean_set_operations_2/classCGAL_1_1General__polygon__set__2.html#a9d41f55871a2b65d1b421f19f155e6d4 . If you replace the second call with join() it works fine.


/_____/) o /_________ __ // (____ ( ( ( (/ (/-(-'_(/ _/

On Sun, 31 Jul 2022 at 14:49, mptangtang @.***> wrote:

Create a Polygon_Set_2 Failed! Issue Details

When I tried to construct a polygon set using the following code, it failed

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>

#include <CGAL/Polygon_2.h>

#include <CGAL/Polygon_with_holes_2.h>

#include <CGAL/Polygon_set_2.h>

#include <CGAL/draw_polygon_2.h>

#include <CGAL/draw_polygon_set_2.h>

#include

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;

typedef Kernel::Point_2 Point_2;

typedef CGAL::Polygon_2<Kernel> Polygon_2;

typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes_2;

typedef CGAL::Polygon_set_2<Kernel> Polygon_set_2;

Polygon_set_2 result_polygon_set;

Polygon_2 polygon_middle;

polygon_middle.push_back(Point_2(7, 5));

polygon_middle.push_back(Point_2(5, 8));

polygon_middle.push_back(Point_2(3, 4));

polygon_middle.push_back(Point_2(6, 2));

Polygon_2 polygon_right;

polygon_right.push_back(Point_2(7, 5));

polygon_right.push_back(Point_2(8, 4));

polygon_right.push_back(Point_2(10, 5));

polygon_right.push_back(Point_2(9, 9));

result_polygon_set.insert(polygon_middle);

result_polygon_set.insert(polygon_right);

The program have a runtime error as follows:

CGAL error: assertion violation!

Expression : CGAL::assign(const_f, obj_f) && !const_f->contained()

File : E:\PreBuild\vs_indep\CGAL5.5\include\CGAL/Boolean_set_operations_2/Gps_on_surface_base_2_impl.h

Line : 353

Explanation:

Refer to the bug-reporting instructions at https://www.cgal.org/bug_report.html

if I change the first point of polygon_right by

polygon_right.push_back(Point_2(7.001, 5));

Everything is fine. This means that the problem is introduced by inserting two polygons with shared vertex. However, the document of CGAL tell us

(ii) the boundaries of two sets intersect but their interiors are disjoint; namely they have a finite number of common points or even share a boundary curve (still in this case P∩Q=∅;)

In addition, a polygon-set object can be constructed from a single polygon object or from a polygon-with-holes object. Once constructed, it is possible to insert new polygons (or polygons with holes) into the set using the insert() method, as long as the inserted polygons and the existing polygons in the set are disjoint.

How could we handle polygons with same vertices or same edges that still disjoint in this case?

Thank you very much!

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

efifogel avatar Aug 10 '22 14:08 efifogel