From 26db1722ae7b37f9720795d1714b4bd4ac1634a0 Mon Sep 17 00:00:00 2001 From: supermerill Date: Tue, 22 Oct 2019 18:02:25 +0200 Subject: [PATCH] optimisation for remove_point_too_near, using only distance_to_square instead of distance_to #106 --- src/libslic3r/ExPolygon.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/ExPolygon.cpp b/src/libslic3r/ExPolygon.cpp index c2ec08b8a..63f617fc1 100644 --- a/src/libslic3r/ExPolygon.cpp +++ b/src/libslic3r/ExPolygon.cpp @@ -199,22 +199,23 @@ ExPolygon::simplify(double tolerance, ExPolygons* expolygons) const //simplier than simplify void ExPolygon::remove_point_too_near(const coord_t tolerance) { + const double tolerance_sq = tolerance * (double)tolerance; size_t id = 1; while (id < this->contour.points.size() - 1) { - coord_t newdist = (coord_t)std::min(this->contour.points[id].distance_to(this->contour.points[id - 1]) - , this->contour.points[id].distance_to(this->contour.points[id + 1])); - if (newdist < tolerance) { + coord_t newdist = (coord_t)std::min(this->contour.points[id].distance_to_square(this->contour.points[id - 1]) + , this->contour.points[id].distance_to_square(this->contour.points[id + 1])); + if (newdist < tolerance_sq) { this->contour.points.erase(this->contour.points.begin() + id); - newdist = (coord_t)this->contour.points[id].distance_to(this->contour.points[id - 1]); + newdist = (coord_t)this->contour.points[id].distance_to_square(this->contour.points[id - 1]); } //go to next one //if you removed a point, it check if the next one isn't too near from the previous one. // if not, it byepass it. - if (newdist > tolerance) { + if (newdist > tolerance_sq) { ++id; } } - if (this->contour.points.front().distance_to(this->contour.points.back()) < tolerance) { + if (this->contour.points.front().distance_to_square(this->contour.points.back()) < tolerance_sq) { this->contour.points.erase(this->contour.points.end() -1); } }