cgal icon indicating copy to clipboard operation
cgal copied to clipboard

Inconsistent behavior of CGAL::join overload methods

Open Alison-97 opened this issue 3 years ago • 3 comments

Issue Details

In using the CGAL::join method to get the union of two polygon_with_holes, the input polygons must have an outer boundary with counter clockwise orientation as stated as one of its valid conditions. In the following code, polygon Q has a clockwise orientation which is supposed to trigger a precondition violation error. I'm using two different join overload methods (1) polygon with holes as input and (2) iterator as input. Only the former triggers the violation assertion but not the latter. Shouldn’t both trigger the violation assertion?

Source Code

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_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 std::list<Polygon_with_holes_2>                   Pwh_list_2;

void InvalidOrientationTest()
{
    Polygon_with_holes_2 P;
    P.outer_boundary().push_back(Point_2(0, 0));
    P.outer_boundary().push_back(Point_2(10, 0));
    P.outer_boundary().push_back(Point_2(10, 10));
    P.outer_boundary().push_back(Point_2(0, 10));

    Polygon_with_holes_2 Q;     // Q has a wrong orientation
    Q.outer_boundary().push_back(Point_2(0, 10));
    Q.outer_boundary().push_back(Point_2(10, 10));
    Q.outer_boundary().push_back(Point_2(10, 5));
    Q.outer_boundary().push_back(Point_2(0, 5));

    // (1) Polygon as input: precondition error triggered
    Polygon_with_holes_2 unionR;
    CGAL::join(P, Q, unionR);

    // (2) Iterator as input: precondition error not triggered
    std::list<Polygon_with_holes_2> input;
    input.push_back(P);
    input.push_back(Q);
    std::list<Polygon_with_holes_2> unionRList;
    CGAL::join(input.begin(), input.end(), std::back_inserter(unionRList));
}

Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits): Windows 11 version 21H2, 64 bits
  • Compiler: Visual Studio 2022
  • Release or debug mode: Debug
  • CGAL version: 5.5
  • Boost version: 1_65_1

Alison-97 avatar Sep 09 '22 06:09 Alison-97

I confirm that the behavior is indeed inconsistent. In case of aggregate operations (intersection, union, do_intersect, difference, and symmetric_difference) many polygons might be passed as arguments. The validity test can become quite expensive in these cases. I guess a good solution is to use CGAL_expensive_assertion in these cases, so that validity can be tested if the user insists.


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

On Fri, 9 Sept 2022 at 09:46, Alison-97 @.***> wrote:

Issue Details

In using the CGAL::join method to get the union of two polygon_with_holes, the input polygons must have an outer boundary with counter clockwise orientation as stated as one of its valid conditions https://doc.cgal.org/latest/Boolean_set_operations_2/index.html#title3. In the following code, polygon Q has a clockwise orientation which is supposed to trigger a precondition violation error. I'm using two different join overload methods (1) polygon with holes as input https://doc.cgal.org/latest/Boolean_set_operations_2/group__boolean__join.html#ga66229d7a99f1f61c52b5f65615067ae2 and (2) iterator as input https://doc.cgal.org/latest/Boolean_set_operations_2/group__boolean__join.html#ga7a04e91d075a1ed5bdc1593ed15291f9. Only the former triggers the violation assertion but not the latter. Shouldn’t both trigger the violation assertion? Source Code

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>

#include <CGAL/Boolean_set_operations_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 std::list<Polygon_with_holes_2> Pwh_list_2;

void InvalidOrientationTest()

{

Polygon_with_holes_2 P;

P.outer_boundary().push_back(Point_2(0, 0));

P.outer_boundary().push_back(Point_2(10, 0));

P.outer_boundary().push_back(Point_2(10, 10));

P.outer_boundary().push_back(Point_2(0, 10));



Polygon_with_holes_2 Q;     // Q has a wrong orientation

Q.outer_boundary().push_back(Point_2(0, 10));

Q.outer_boundary().push_back(Point_2(10, 10));

Q.outer_boundary().push_back(Point_2(10, 5));

Q.outer_boundary().push_back(Point_2(0, 5));



// (1) Polygon as input: precondition error triggered

Polygon_with_holes_2 unionR;

CGAL::join(P, Q, unionR);



// (2) Iterator as input: precondition error not triggered

std::list<Polygon_with_holes_2> input;

input.push_back(P);

input.push_back(Q);

std::list<Polygon_with_holes_2> unionRList;

CGAL::join(input.begin(), input.end(), std::back_inserter(unionRList));

}

Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits): Windows 11 version 21H2, 64 bits
  • Compiler: Visual Studio 2022
  • Release or debug mode: Debug
  • CGAL version: 5.5
  • Boost version: 1_65_1

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

efifogel avatar Sep 18 '22 09:09 efifogel

@efifogel Has this been improved in recent versions of CGAL?

lrineau avatar Apr 29 '24 14:04 lrineau

I don't think so. I'll handle it.


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

On Mon, 29 Apr 2024 at 17:35, Laurent Rineau @.***> wrote:

@efifogel https://github.com/efifogel Has this been improved in recent versions of CGAL?

— Reply to this email directly, view it on GitHub https://github.com/CGAL/cgal/issues/6840#issuecomment-2082918155, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVBNOAGB2CAFSQNXZ4DSLTY7ZLEVAVCNFSM6AAAAAAQIMOX7CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBSHEYTQMJVGU . You are receiving this because you were mentioned.Message ID: @.***>

efifogel avatar Apr 29 '24 20:04 efifogel