diff options
author | Ghostkeeper <rubend@tutanota.com> | 2022-01-24 18:11:41 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2022-01-24 18:11:50 +0300 |
commit | ebb53015413c568ccf20c050ef0d68c3072da9f9 (patch) | |
tree | 95da9b414b7b1dd21fa9afb9e9f4d4044b51b72a | |
parent | c64a4c68999bf67192b7812a95744abacdcd2866 (diff) |
And then make them refer to the same function again.
This is a rather elaborate way to avoid the boolean trap.
Contributes to issue CURA-8903.
-rw-r--r-- | src/slicer.cpp | 3 | ||||
-rw-r--r-- | src/utils/polygon.cpp | 11 | ||||
-rw-r--r-- | src/utils/polygon.h | 24 |
3 files changed, 34 insertions, 4 deletions
diff --git a/src/slicer.cpp b/src/slicer.cpp index 5bfc94a27..4f9501869 100644 --- a/src/slicer.cpp +++ b/src/slicer.cpp @@ -789,8 +789,7 @@ void SlicerLayer::makePolygons(const Mesh* mesh) it = std::remove_if(openPolylines.begin(), openPolylines.end(), [snap_distance](PolygonRef poly) { return poly.shorterThan(snap_distance); }); openPolylines.erase(it, openPolylines.end()); - constexpr bool for_polylines = true; - openPolylines.removeDegenerateVerts(for_polylines); + openPolylines.removeDegenerateVertsPolyline(); } Slicer::Slicer(Mesh* i_mesh, const coord_t thickness, const size_t slice_layer_count, diff --git a/src/utils/polygon.cpp b/src/utils/polygon.cpp index e9445e1f2..bb6797cb7 100644 --- a/src/utils/polygon.cpp +++ b/src/utils/polygon.cpp @@ -585,8 +585,17 @@ void Polygons::removeSmallAreas(const double min_area_size, const bool remove_ho paths.resize(new_end-paths.begin()); } +void Polygons::removeDegenerateVerts() +{ + _removeDegenerateVerts(false); +} + +void Polygons::removeDegenerateVertsPolyline() +{ + _removeDegenerateVerts(true); +} -void Polygons::removeDegenerateVerts(const bool for_polyline) +void Polygons::_removeDegenerateVerts(const bool for_polyline) { Polygons& thiss = *this; for(size_t poly_idx = 0; poly_idx < size(); poly_idx++) diff --git a/src/utils/polygon.h b/src/utils/polygon.h index ec5a09ba4..7496637b1 100644 --- a/src/utils/polygon.h +++ b/src/utils/polygon.h @@ -1025,13 +1025,35 @@ public: /*! * Removes overlapping consecutive line segments which don't delimit a * positive area. + * + * This function is meant to work on polygons, not polylines. When misused + * on polylines, it may cause too many vertices to be removed. + * See \ref removeDegenerateVertsPolyline for a version that works on + * polylines. + */ + void removeDegenerateVerts(); + + /*! + * Removes overlapping consecutive line segments which don't delimit a + * positive area. + * + * This version is meant to work on polylines, not polygons. It leaves the + * endpoints of the polyline untouched. When misused on polygons, it may + * leave some degenerate vertices in. + * See \ref removeDegenerateVerts for a version that works on polygons. + */ + void removeDegenerateVertsPolyline(); + + /*! + * Removes overlapping consecutive line segments which don't delimit a + * positive area. * \param for_polyline Indicate that we're removing degenerate vertices from * a polyline, causing the endpoints of the polyline to be left untouched. * When removing vertices from a polygon, the start and end can be * considered for removal too, but when processing a polyline, removing * those would cause the polyline to become shorter. */ - void removeDegenerateVerts(const bool for_polyline = false); + void _removeDegenerateVerts(const bool for_polyline = false); /*! * Removes the same polygons from this set (and also empty polygons). |