diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index 8ba9d6a31..35eb0f12a 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -356,7 +356,7 @@ sub extrude_path { } } $gcode .= ";_BRIDGE_FAN_END\n" if $path->is_bridge; - $self->last_pos($path->last_point->clone); + $self->last_pos($path->last_point); if ($self->config->cooling) { my $path_time = $path_length / $F * 60; diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index fc85ff911..a54d190f3 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -252,7 +252,7 @@ sub make_perimeters { # use a nearest neighbor search to order these children # TODO: supply second argument to chained_path_items() too? my @nodes = @{Slic3r::Geometry::chained_path_items( - [ map [ ($_->{outer} // $_->{hole})->first_point->clone, $_ ], @$polynodes ], + [ map [ ($_->{outer} // $_->{hole})->first_point, $_ ], @$polynodes ], )}; my @loops = (); diff --git a/xs/src/ExtrusionEntity.cpp b/xs/src/ExtrusionEntity.cpp index 7e8b48fc9..eb3507df0 100644 --- a/xs/src/ExtrusionEntity.cpp +++ b/xs/src/ExtrusionEntity.cpp @@ -15,15 +15,15 @@ ExtrusionPath::reverse() } Point* -ExtrusionPath::first_point() +ExtrusionPath::first_point() const { - return &(this->polyline.points.front()); + return new Point(this->polyline.points.front()); } Point* -ExtrusionPath::last_point() +ExtrusionPath::last_point() const { - return &(this->polyline.points.back()); + return new Point(this->polyline.points.back()); } ExtrusionLoop* @@ -66,15 +66,15 @@ ExtrusionLoop::reverse() } Point* -ExtrusionLoop::first_point() +ExtrusionLoop::first_point() const { - return &(this->polygon.points.front()); + return new Point(this->polygon.points.front()); } Point* -ExtrusionLoop::last_point() +ExtrusionLoop::last_point() const { - return &(this->polygon.points.front()); // in polygons, first == last + return new Point(this->polygon.points.front()); // in polygons, first == last } } diff --git a/xs/src/ExtrusionEntity.hpp b/xs/src/ExtrusionEntity.hpp index 0ce0f790a..129115460 100644 --- a/xs/src/ExtrusionEntity.hpp +++ b/xs/src/ExtrusionEntity.hpp @@ -31,8 +31,8 @@ class ExtrusionEntity double height; // vertical thickness of the extrusion expressed in mm double flow_spacing; virtual void reverse() = 0; - virtual Point* first_point() = 0; - virtual Point* last_point() = 0; + virtual Point* first_point() const = 0; + virtual Point* last_point() const = 0; }; typedef std::vector ExtrusionEntitiesPtr; @@ -43,8 +43,8 @@ class ExtrusionPath : public ExtrusionEntity ExtrusionPath* clone() const; Polyline polyline; void reverse(); - Point* first_point(); - Point* last_point(); + Point* first_point() const; + Point* last_point() const; }; class ExtrusionLoop : public ExtrusionEntity @@ -56,8 +56,8 @@ class ExtrusionLoop : public ExtrusionEntity ExtrusionPath* split_at_first_point(); bool make_counter_clockwise(); void reverse(); - Point* first_point(); - Point* last_point(); + Point* first_point() const; + Point* last_point() const; }; } diff --git a/xs/src/ExtrusionEntityCollection.cpp b/xs/src/ExtrusionEntityCollection.cpp index c5bc809c9..67f9adaf9 100644 --- a/xs/src/ExtrusionEntityCollection.cpp +++ b/xs/src/ExtrusionEntityCollection.cpp @@ -22,13 +22,13 @@ ExtrusionEntityCollection::reverse() } Point* -ExtrusionEntityCollection::first_point() +ExtrusionEntityCollection::first_point() const { return this->entities.front()->first_point(); } Point* -ExtrusionEntityCollection::last_point() +ExtrusionEntityCollection::last_point() const { return this->entities.back()->last_point(); } diff --git a/xs/src/ExtrusionEntityCollection.hpp b/xs/src/ExtrusionEntityCollection.hpp index a7ea8bef0..901265c94 100644 --- a/xs/src/ExtrusionEntityCollection.hpp +++ b/xs/src/ExtrusionEntityCollection.hpp @@ -16,8 +16,8 @@ class ExtrusionEntityCollection : public ExtrusionEntity ExtrusionEntityCollection* chained_path(bool no_reverse) const; ExtrusionEntityCollection* chained_path_from(Point* start_near, bool no_reverse) const; void reverse(); - Point* first_point(); - Point* last_point(); + Point* first_point() const; + Point* last_point() const; }; } diff --git a/xs/src/MultiPoint.cpp b/xs/src/MultiPoint.cpp index 83fcb6a89..c851b57f9 100644 --- a/xs/src/MultiPoint.cpp +++ b/xs/src/MultiPoint.cpp @@ -33,15 +33,9 @@ MultiPoint::reverse() } Point* -MultiPoint::first_point() -{ - return &(this->points.front()); -} - -const Point* MultiPoint::first_point() const { - return &(this->points.front()); + return new Point(this->points.front()); } void diff --git a/xs/src/MultiPoint.hpp b/xs/src/MultiPoint.hpp index 255cc2d58..da19a54d8 100644 --- a/xs/src/MultiPoint.hpp +++ b/xs/src/MultiPoint.hpp @@ -19,9 +19,8 @@ class MultiPoint void translate(double x, double y); void rotate(double angle, Point* center); void reverse(); - Point* first_point(); - const Point* first_point() const; - virtual Point* last_point() = 0; + Point* first_point() const; + virtual Point* last_point() const = 0; }; } diff --git a/xs/src/Polygon.cpp b/xs/src/Polygon.cpp index b5391582d..c2e9ffadd 100644 --- a/xs/src/Polygon.cpp +++ b/xs/src/Polygon.cpp @@ -6,9 +6,9 @@ namespace Slic3r { Point* -Polygon::last_point() +Polygon::last_point() const { - return &(this->points.front()); // last point == first point for polygons + return new Point(this->points.front()); // last point == first point for polygons } SV* diff --git a/xs/src/Polygon.hpp b/xs/src/Polygon.hpp index 9c00bd8e8..77ca81147 100644 --- a/xs/src/Polygon.hpp +++ b/xs/src/Polygon.hpp @@ -11,7 +11,7 @@ namespace Slic3r { class Polygon : public MultiPoint { public: - Point* last_point(); + Point* last_point() const; SV* to_SV_ref() const; SV* to_SV_clone_ref() const; Lines lines(); diff --git a/xs/src/Polyline.cpp b/xs/src/Polyline.cpp index e01276f08..8fa714376 100644 --- a/xs/src/Polyline.cpp +++ b/xs/src/Polyline.cpp @@ -3,15 +3,9 @@ namespace Slic3r { Point* -Polyline::last_point() -{ - return &(this->points.back()); -} - -const Point* Polyline::last_point() const { - return &(this->points.back()); + return new Point(this->points.back()); } Lines diff --git a/xs/src/Polyline.hpp b/xs/src/Polyline.hpp index ca8e1583b..631f2e604 100644 --- a/xs/src/Polyline.hpp +++ b/xs/src/Polyline.hpp @@ -8,8 +8,7 @@ namespace Slic3r { class Polyline : public MultiPoint { public: - Point* last_point(); - const Point* last_point() const; + Point* last_point() const; Lines lines(); SV* to_SV_ref() const; SV* to_SV_clone_ref() const;