mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 09:17:52 -06:00
Optimize remove_duplicate_points.
This commit is contained in:
parent
42d9db04f2
commit
79c5e0a52d
2 changed files with 27 additions and 6 deletions
|
@ -102,15 +102,33 @@ MultiPoint::bounding_box() const
|
|||
return BoundingBox(this->points);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
MultiPoint::has_duplicate_points() const
|
||||
{
|
||||
for (size_t i = 1; i < points.size(); ++i)
|
||||
if (points[i-1].coincides_with(points[i]))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
MultiPoint::remove_duplicate_points()
|
||||
{
|
||||
for (size_t i = 1; i < this->points.size(); ++i) {
|
||||
if (this->points.at(i).coincides_with(this->points.at(i-1))) {
|
||||
this->points.erase(this->points.begin() + i);
|
||||
--i;
|
||||
size_t j = 0;
|
||||
for (size_t i = 1; i < points.size(); ++i) {
|
||||
if (points[j].coincides_with(points[i])) {
|
||||
// Just increase index i.
|
||||
} else {
|
||||
++ j;
|
||||
if (j < i)
|
||||
points[j] = points[i];
|
||||
}
|
||||
}
|
||||
if (++ j < points.size()) {
|
||||
points.erase(points.begin() + j, points.end());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue