Skip to content

Commit

Permalink
Fix in splitting the loop at a new point.
Browse files Browse the repository at this point in the history
  • Loading branch information
bubnikv committed Sep 13, 2016
1 parent f518e06 commit c443f49
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions xs/src/libslic3r/ExtrusionEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ ExtrusionLoop::split_at_vertex(const Point &point)
} else {
// new paths list starts with the second half of current path
ExtrusionPaths new_paths;
new_paths.reserve(this->paths.size() + 1);
{
ExtrusionPath p = *path;
p.polyline.points.erase(p.polyline.points.begin(), p.polyline.points.begin() + idx);
Expand All @@ -212,7 +213,7 @@ ExtrusionLoop::split_at_vertex(const Point &point)
if (p.polyline.is_valid()) new_paths.push_back(p);
}
// we can now override the old path list with the new one and stop looping
this->paths = new_paths;
std::swap(this->paths, new_paths);
}
return true;
}
Expand Down Expand Up @@ -240,14 +241,24 @@ ExtrusionLoop::split_at(const Point &point)
}

// now split path_idx in two parts
ExtrusionPath p1 = this->paths[path_idx];
ExtrusionPath p2 = p1;
ExtrusionPath p1(this->paths[path_idx].role), p2(this->paths[path_idx].role);

This comment has been minimized.

Copy link
@lordofhyphens

lordofhyphens Sep 13, 2016

Contributor

So, what was the problem with using the (default) copy constructor here?

This comment has been minimized.

Copy link
@bubnikv

bubnikv via email Sep 13, 2016

Author Collaborator

This comment has been minimized.

Copy link
@lordofhyphens

lordofhyphens via email Sep 13, 2016

Contributor
this->paths[path_idx].polyline.split_at(p, &p1.polyline, &p2.polyline);

// install the two paths
this->paths.erase(this->paths.begin() + path_idx);
if (p2.polyline.is_valid()) this->paths.insert(this->paths.begin() + path_idx, p2);
if (p1.polyline.is_valid()) this->paths.insert(this->paths.begin() + path_idx, p1);
if (this->paths.size() == 1) {

This comment has been minimized.

Copy link
@lordofhyphens

lordofhyphens Sep 13, 2016

Contributor

So this catches an edge case where a path that is fixable after a split isn't dropped?

if (! p1.polyline.is_valid())
std::swap(this->paths.front().polyline.points, p2.polyline.points);
else if (! p2.polyline.is_valid())
std::swap(this->paths.front().polyline.points, p1.polyline.points);
else {
p2.polyline.points.insert(p2.polyline.points.end(), p1.polyline.points.begin() + 1, p1.polyline.points.end());
std::swap(this->paths.front().polyline.points, p2.polyline.points);
}
} else {
// install the two paths
this->paths.erase(this->paths.begin() + path_idx);
if (p2.polyline.is_valid()) this->paths.insert(this->paths.begin() + path_idx, p2);
if (p1.polyline.is_valid()) this->paths.insert(this->paths.begin() + path_idx, p1);
}

// split at the new vertex
this->split_at_vertex(p);
Expand Down

0 comments on commit c443f49

Please sign in to comment.