From 70fb381ecf8c794902d07d3b5f26768120ec9ffc Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 23 Jul 2014 16:32:31 +0200 Subject: [PATCH] Bugfix: some extra spots were added in medial axis --- xs/src/ExPolygon.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xs/src/ExPolygon.cpp b/xs/src/ExPolygon.cpp index 78a658bd6..7edecf46b 100644 --- a/xs/src/ExPolygon.cpp +++ b/xs/src/ExPolygon.cpp @@ -154,15 +154,20 @@ ExPolygon::medial_axis(double max_width, double min_width, Polylines* polylines) // compute the Voronoi diagram ma.build(polylines); + // clip segments to our expolygon area + // (do this before extending endpoints as external segments coule be extended into + // expolygon, this leaving wrong things inside) + intersection(*polylines, *this, *polylines); + // extend initial and final segments of each polyline (they will be clipped) // unless they represent closed loops for (Polylines::iterator polyline = polylines->begin(); polyline != polylines->end(); ++polyline) { - if (polyline->points.front().coincides_with(polyline->points.back())) continue; + if (polyline->points.front().distance_to(polyline->points.back()) < min_width) continue; polyline->extend_start(max_width); polyline->extend_end(max_width); } - // clip segments to our expolygon area + // clip again after extending endpoints to prevent them from exceeding the expolygon boundaries intersection(*polylines, *this, *polylines); }