Open lcrombez opened 4 years ago
I think I found the issue.
partition_opt_cvx_best_so_far
detroys the stack of pivot_vertex
.
I'm pretty sure that the stack should be preserved for future calls from partition_opt_cvx_load
I tried the lazy and dirty fix consisting of saving and the stack and restoring it after the call to partition_opt_cvx_best_so_far
in partition_opt_cvx_load
and I do get the correct result by doing that.
I think it's safe to assume that partition_opt_cvx_best_so_far
is supposed to iterate through the stack instead of poping it.
Issue Details
In some "simple" cases (No three points are aligned) optimal_convex_partition_2 does not return the optimal convex partition.
The source code below shows a 10 points polygon that can be partitioned in 3 convex polygons. optimal_convex_partition_2 returns 4 polygons. The second part of the code shows the same 10 points polygon but the first points listed is changed. This time optimal_convex_partition_2 returns the correct answer, which is a partition of 3 convex polygons.
Source Code
Environment
My rough understanding of the origin of the issue
Note: I do not have access to Greene's paper which describes the algorithm implemented, so my understanding of the algorithm is at least partially flawed.
The starting edge (9 0) sees three points: 3,5 and 7 (which are not consecutive in the input polygon) The optimal partition uses the edges (0 3) and (3 9). Which the algorithm correctly sees both as only "requiring 1 convex polygon to partition the section of the input polygon that lies right to those edges". It looks like to me that the issue comes eeither from partition_opt_cvx_load and/or partition_opt_cvx_best_so_far (However, the intended behavior of this part of the algorithm is still blurry to me). I think that the fact that the optimal solution requires the polygon aounrd (9 0) not to use one of the extremum of the seen points from the edge (9 0) (so not using neither 3 nor 7 in this case) induces the bug.