Small enhancement to 'decompose_convex' with the goal to avoid thin slivers

This commit is contained in:
Matthias Koefferlein 2023-05-14 18:33:53 +02:00
parent 7169910607
commit 8f25c3470d
1 changed files with 9 additions and 2 deletions

View File

@ -2300,9 +2300,11 @@ static void decompose_convex_helper (int depth, PreferredOrientation po, const d
db::Box bbox = sp.box ();
db::coord_traits<db::Coord>::area_type atot = 0;
db::coord_traits<db::Coord>::distance_type min_edge = std::numeric_limits<db::coord_traits<db::Coord>::distance_type>::max ();
for (size_t i = 0; i < n; ++i) {
db::Edge ep (sp.hull ()[(i + n - 1) % n], sp.hull ()[i]);
atot += db::vprod (ep.p2 () - db::Point (), ep.p1 () - db::Point ());
min_edge = std::min (min_edge, ep.length ());
}
std::set<db::Point> skipped;
@ -2449,9 +2451,14 @@ static void decompose_convex_helper (int depth, PreferredOrientation po, const d
int cr = 0;
if (x.second == efc.p1 ()) {
if (db::vprod (efc, efp) < 0) {
cr = 2; // cut terminates at another concave corner
cr = 3; // cut terminates at another concave corner
} else {
cr = 1; // cut terminates at a convex corner
cr = 2; // cut terminates at a convex corner
}
} else {
db::coord_traits<db::Coord>::distance_type el = std::min (x.second.distance (efc.p1 ()), x.second.distance (efc.p2 ()));
if (el >= min_edge) {
cr = 1; // does not induce shorter edge than we have so far
}
}