Skip to content

Commit

Permalink
optimisation for remove_point_too_near, using only distance_to_square…
Browse files Browse the repository at this point in the history
… instead of distance_to

prusa3d#106
  • Loading branch information
supermerill committed Oct 22, 2019
1 parent 8aaaeaf commit 26db172
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/libslic3r/ExPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 26db172

Please sign in to comment.