Skip to content

optimal_convex_partition_2 fails with very simple polygon #8828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mmertama opened this issue Apr 4, 2025 · 10 comments
Open

optimal_convex_partition_2 fails with very simple polygon #8828

mmertama opened this issue Apr 4, 2025 · 10 comments

Comments

@mmertama
Copy link

mmertama commented Apr 4, 2025

Issue Details

CGAL error: precondition violation!
Expression : is_simple_2(first, last, traits)
File : /opt/homebrew/include/CGAL/Polygon_2/Polygon_2_algorithms_impl.h
Line : 542
Explanation:
Refer to the bug-reporting instructions at https://www.cgal.org/bug_report.html
libc++abi: terminating due to uncaught exception of type CGAL::Precondition_exception: CGAL ERROR: precondition violation!
Expr: is_simple_2(first, last, traits)
File: /opt/homebrew/include/CGAL/Polygon_2/Polygon_2_algorithms_impl.h
Line: 542

Source Code

void test(){

using Kern = CGAL::Exact_predicates_inexact_constructions_kernel;
using Tra = CGAL::Partition_traits_2<Kern>;
Tra::Polygon_2  polygon;
std::list<Tra::Polygon_2>   partition_polys;

const std::vector<double> vec = {-640,-160,-640,-384,-448,-384,-448,-448,-320,-448,-320,-384,
-128,-384,-128,-152,-128,-128,-128,0,-128,24,-128,256,-320,256,-448,64,-320,64,-320,-192,-448,-192,-512,-192,-512,-160
};

for (unsigned i = 0; i < vec.size(); i += 2) {
    polygon.push_back(Tra::Point_2{vec[i], vec[i + 1]});
}
   
assert(polygon.orientation() == CGAL::Orientation::COUNTERCLOCKWISE);
assert(polygon.is_simple());

CGAL::optimal_convex_partition_2(polygon.vertices_begin(),
                                polygon.vertices_end(),
                                std::back_inserter(partition_polys));

assert(CGAL::partition_is_valid_2(polygon.vertices_begin(),
                                 polygon.vertices_end(),
                                 partition_polys.begin(),
                                 partition_polys.end()));

}

Environment

  • OS: Mac 16.3
  • Compiler: Clang (system default C++)
  • Release or debug mode: Debug
  • Specific flags used (if any):
  • CGAL version: 6.0.1
  • Boost version: 1.87.0_1
  • Other libraries versions if used (Eigen, TBB, etc.):
@mmertama
Copy link
Author

mmertama commented Apr 4, 2025

TBC if duplicate of #2575

@mmertama
Copy link
Author

mmertama commented Apr 4, 2025

I tried greene_approx_convex_partition_2, and it worked with that paricular data, but failed with: std::vector vec2 = {256, 3072, 129.41, 3009.41, 448, 3008, 496, 3136, 496, 3160, 496, 3304, 496, 3328,
448, 3456, 129.41, 3454.59, 67.21, 3391.47, 129.85, 3266.89, 160.18, 3268, 256, 3392, 320, 3392, 320,
3328, 256, 3328, 192.25, 3267.99, 224.25, 3267.99, 256.13, 3266, 288, 3264, 320, 3264, 320, 3200, 288,
3200, 256.13, 3198, 224.25, 3196.01, 192.25, 3196.01, 160.18, 3196, 256, 3136, 320, 3136, 320, 3072}; ... that is also simple set.

@mmertama
Copy link
Author

mmertama commented Apr 4, 2025

This time the failure is
CGAL error: postcondition violation! Expression : convex_partition_is_valid_2(polygon.vertices_begin(), polygon.vertices_end(), res.output_so_far_begin(), res.output_so_far_end(), traits) File : /opt/homebrew/include/CGAL/Partition_2/partition_greene_approx_convex_2.h Line : 829 Explanation:

@mmertama
Copy link
Author

mmertama commented Apr 4, 2025

There is CGAL_PARTITION_NO_POSTCONDITIONS, but when set, code wont compile - whole CGAL::Partition is fundamentally broken and should not be used?

@Abhishek-Atole

This comment has been minimized.

@sloriot
Copy link
Member

sloriot commented Apr 7, 2025

-384,-448,-384,-448 is a duplicated point making the is_simple precondition failing.

@sloriot sloriot closed this as completed Apr 7, 2025
@mmertama
Copy link
Author

mmertama commented Apr 7, 2025

Sorry where do you see duplicate points? How much I try I cannot spot them:
-640,-160
-640,-384
-448,-384
-448,-448
-320,-448
-320,-384
-128,-384
-128,-152
-128,-128
-128,0
-128,24
-128,256
-320,256
-448,64
-320,64
-320,-192
-448,-192
-512,-192
-512,-160

@sloriot
Copy link
Member

sloriot commented Apr 7, 2025

My bad. But there is a missing comma after -384 on the first line of points.

@sloriot
Copy link
Member

sloriot commented Apr 7, 2025

I still have the assertion after adding the missing comma. Sorry for the fast closing.

@mmertama
Copy link
Author

mmertama commented Apr 7, 2025

My example code had a missing comma after -384, <-- It was lost when edited here, sorry. Now the example should show the fail condition correctly. @sloriot, Im sorry about confusion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants