diff --git a/include/geometry/shape.h b/include/geometry/shape.h index a236b04dc0..a853b1cf77 100644 --- a/include/geometry/shape.h +++ b/include/geometry/shape.h @@ -30,7 +30,7 @@ class Shape : public LinesSet Shape(Shape&& other) = default; - Shape(const std::initializer_list& initializer); + Shape(const std::vector& polygons); explicit Shape(ClipperLib::Paths&& paths, bool explicitely_closed = clipper_explicitely_closed_); @@ -68,6 +68,11 @@ class Shape : public LinesSet Shape intersection(const Shape& other) const; + /*! @brief Overridden definition of offset() + * @note The behavior of this method is exactly the same, but it just exists because it allows + * for a performance optimization */ + Shape offset(coord_t distance, ClipperLib::JoinType join_type = ClipperLib::jtMiter, double miter_limit = 1.2) const; + /*! * Intersect polylines with the area covered by the shape. * diff --git a/include/geometry/single_shape.h b/include/geometry/single_shape.h index 472302d01f..08a9e421d9 100644 --- a/include/geometry/single_shape.h +++ b/include/geometry/single_shape.h @@ -25,7 +25,7 @@ class SingleShape : public Shape /*! * Tests whether the given point is inside this polygon part. - * \param p The point to test whether it is inside. + * \param p The point to test whether it is insisinglehde. * \param border_result If the point is exactly on the border, this will be * returned instead. */ @@ -34,4 +34,4 @@ class SingleShape : public Shape } // namespace cura -#endif // GEOMETRY_MONO_SHAPE_H +#endif // GEOMETRY_SINGLE_SHAPE_H diff --git a/src/WallsComputation.cpp b/src/WallsComputation.cpp index 1d0b1380b9..4f02bedc91 100644 --- a/src/WallsComputation.cpp +++ b/src/WallsComputation.cpp @@ -84,7 +84,8 @@ void WallsComputation::generateWalls(SliceLayerPart* part, SectionType section_t part->wall_toolpaths = wall_tool_paths.getToolPaths(); part->inner_area = wall_tool_paths.getInnerContour(); } - part->outline = SingleShape{ Simplify(settings_).polygon(part->outline) }; + + part->outline = SingleShape({ Simplify(settings_).polygon(part->outline) }); part->print_outline = part->outline; } diff --git a/src/geometry/lines_set.cpp b/src/geometry/lines_set.cpp index c1edb9c4d0..5d1fa1d61c 100644 --- a/src/geometry/lines_set.cpp +++ b/src/geometry/lines_set.cpp @@ -162,13 +162,11 @@ Shape LinesSet::offset(coord_t distance, ClipperLib::JoinType join_type { if (distance == 0) { - Shape result; - result.push_back(getLines()); - return result; + return Shape(getLines()); } ClipperLib::Paths ret; ClipperLib::ClipperOffset clipper(miter_limit, 10.0); - addPaths(clipper, join_type, ClipperLib::etClosedPolygon); + Shape(getLines()).unionPolygons().addPaths(clipper, join_type, ClipperLib::etClosedPolygon); clipper.MiterLimit = miter_limit; clipper.Execute(ret, static_cast(distance)); return Shape(std::move(ret)); @@ -203,71 +201,6 @@ Shape LinesSet::offset(coord_t distance, ClipperLib::JoinType join return result; } -#if 0 -template<> -Shape LinesSet::offset(coord_t distance, ClipperLib::JoinType joinType, double miter_limit) const -{ -#error Implement me if required - Shape result; - - if (distance != 0) - { - Shape polygons; - ClipperLib::ClipperOffset clipper(miter_limit, 10.0); - - for (const LineType& line : lines_) - { - if (const Polygon* polygon = dynamic_cast(&line)) - { - // Union all polygons first and add them later - polygons.push_back(*polygon); - - /*temp = Shape(asRawVector()).unionPolygons(); - actual_polygons = &temp.asRawVector(); - end_type = ClipperLib::etClosedPolygon;*/ - } - else - { - ClipperLib::EndType end_type; - - if (line.addClosingSegment()) - { - end_type = ClipperLib::etClosedLine; - } - else if (joinType == ClipperLib::jtMiter) - { - end_type = ClipperLib::etOpenSquare; - } - else - { - end_type = ClipperLib::etOpenRound; - } - - clipper.AddPath(line.getPoints(), joinType, end_type); - } - } - - if (! polygons.empty()) - { - polygons = polygons.unionPolygons(); - - for (const Polygon& polygon : polygons) - { - clipper.AddPath(polygon.getPoints(), joinType, ClipperLib::etClosedPolygon); - } - } - - clipper.MiterLimit = miter_limit; - - ClipperLib::Paths result; - clipper.Execute(result, static_cast(distance)); - return Shape(std::move(result)); - } - - return result; -} -#endif - template void LinesSet::removeDegenerateVerts() { @@ -372,6 +305,7 @@ template coord_t LinesSet::length() const; template Shape LinesSet::tubeShape(const coord_t inner_offset, const coord_t outer_offset) const; template void LinesSet::removeDegenerateVerts(); template void LinesSet::addPaths(ClipperLib::Clipper& clipper, ClipperLib::PolyType PolyTyp) const; +template void LinesSet::addPaths(ClipperLib::ClipperOffset& clipper, ClipperLib::JoinType jointType, ClipperLib::EndType endType) const; template void LinesSet::push_back(const OpenPolyline& line, bool checkNonEmpty); template void LinesSet::push_back(OpenPolyline&& line, bool checkNonEmpty); template void LinesSet::push_back(LinesSet&& lines_set); @@ -384,6 +318,7 @@ template coord_t LinesSet::length() const; template Shape LinesSet::tubeShape(const coord_t inner_offset, const coord_t outer_offset) const; template void LinesSet::removeDegenerateVerts(); template void LinesSet::addPaths(ClipperLib::Clipper& clipper, ClipperLib::PolyType PolyTyp) const; +template void LinesSet::addPaths(ClipperLib::ClipperOffset& clipper, ClipperLib::JoinType jointType, ClipperLib::EndType endType) const; template void LinesSet::push_back(const ClosedPolyline& line, bool checkNonEmpty); template void LinesSet::push_back(ClosedPolyline&& line, bool checkNonEmpty); template void LinesSet::push_back(LinesSet&& lines_set); @@ -397,6 +332,7 @@ template coord_t LinesSet::length() const; template Shape LinesSet::tubeShape(const coord_t inner_offset, const coord_t outer_offset) const; template void LinesSet::removeDegenerateVerts(); template void LinesSet::addPaths(ClipperLib::Clipper& clipper, ClipperLib::PolyType PolyTyp) const; +template void LinesSet::addPaths(ClipperLib::ClipperOffset& clipper, ClipperLib::JoinType jointType, ClipperLib::EndType endType) const; template void LinesSet::push_back(const Polygon& line, bool checkNonEmpty); template void LinesSet::push_back(Polygon&& line, bool checkNonEmpty); template void LinesSet::push_back(LinesSet&& lines_set); diff --git a/src/geometry/shape.cpp b/src/geometry/shape.cpp index a50ec4f7b1..ef6565f8d3 100644 --- a/src/geometry/shape.cpp +++ b/src/geometry/shape.cpp @@ -39,8 +39,8 @@ Shape::Shape(ClipperLib::Paths&& paths, bool explicitely_closed) emplace_back(std::move(paths), explicitely_closed); } -Shape::Shape(const std::initializer_list& initializer) - : LinesSet(initializer) +Shape::Shape(const std::vector& polygons) + : LinesSet(polygons) { } @@ -173,6 +173,20 @@ Shape Shape::intersection(const Shape& other) const return Shape(std::move(ret)); } +Shape Shape::offset(coord_t distance, ClipperLib::JoinType join_type, double miter_limit) const +{ + if (distance == 0) + { + return Shape(getLines()); + } + ClipperLib::Paths ret; + ClipperLib::ClipperOffset clipper(miter_limit, 10.0); + unionPolygons().addPaths(clipper, join_type, ClipperLib::etClosedPolygon); + clipper.MiterLimit = miter_limit; + clipper.Execute(ret, static_cast(distance)); + return Shape(std::move(ret)); +} + bool Shape::inside(const Point2LL& p, bool border_result) const { int poly_count_inside = 0;