From 9fb14f2119aa85144494554d38e2ea38c37c3e37 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 26 Aug 2013 23:42:00 +0200 Subject: [PATCH] Ported (and used) ExtrusionPath->first_point --- lib/Slic3r/ExtrusionPath.pm | 5 ----- lib/Slic3r/GCode.pm | 7 ++++--- xs/src/ExtrusionEntity.cpp | 6 ++++++ xs/src/ExtrusionEntity.hpp | 1 + xs/t/07_extrusionpath.t | 4 +++- xs/xsp/ExtrusionPath.xsp | 2 ++ 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/Slic3r/ExtrusionPath.pm b/lib/Slic3r/ExtrusionPath.pm index 5446736f6..0bcd3b78a 100644 --- a/lib/Slic3r/ExtrusionPath.pm +++ b/lib/Slic3r/ExtrusionPath.pm @@ -65,11 +65,6 @@ sub points { return $self->polyline; } -sub first_point { - my $self = shift; - return $self->polyline->[0]; -} - sub is_perimeter { my $self = shift; return $self->role == EXTR_ROLE_PERIMETER diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index d8ba29a98..9f653e2e2 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -268,7 +268,7 @@ sub extrude_loop { my $distance = min(scale $extrusion_path->flow_spacing, $first_segment->length); my $point = Slic3r::Geometry::point_along_segment(@$first_segment, $distance); $point = Slic3r::Point->new(@$point); - $point->rotate($angle, $extrusion_path->polyline->[0]); + $point->rotate($angle, $extrusion_path->first_point); # generate the travel move $gcode .= $self->travel_to($point, $loop->role, "move inwards before travel"); @@ -294,8 +294,9 @@ sub extrude_path { # go to first point of extrusion path my $gcode = ""; - $gcode .= $self->travel_to($path->points->[0], $path->role, "move to first $description point") - if !defined $self->last_pos || !$self->last_pos->coincides_with($path->points->[0]); + my $first_point = $path->first_point; + $gcode .= $self->travel_to($first_point, $path->role, "move to first $description point") + if !defined $self->last_pos || !$self->last_pos->coincides_with($first_point); # compensate retraction $gcode .= $self->unretract; diff --git a/xs/src/ExtrusionEntity.cpp b/xs/src/ExtrusionEntity.cpp index 463bc75e9..e8b586446 100644 --- a/xs/src/ExtrusionEntity.cpp +++ b/xs/src/ExtrusionEntity.cpp @@ -8,6 +8,12 @@ ExtrusionPath::reverse() this->polyline.reverse(); } +const Point* +ExtrusionPath::first_point() const +{ + return &(this->polyline.points.front()); +} + ExtrusionPath* ExtrusionLoop::split_at_index(int index) { diff --git a/xs/src/ExtrusionEntity.hpp b/xs/src/ExtrusionEntity.hpp index 5cf37cc24..c85293be6 100644 --- a/xs/src/ExtrusionEntity.hpp +++ b/xs/src/ExtrusionEntity.hpp @@ -38,6 +38,7 @@ class ExtrusionPath : public ExtrusionEntity public: Polyline polyline; void reverse(); + const Point* first_point() const; }; class ExtrusionLoop : public ExtrusionEntity diff --git a/xs/t/07_extrusionpath.t b/xs/t/07_extrusionpath.t index b84631dd8..835f25a21 100644 --- a/xs/t/07_extrusionpath.t +++ b/xs/t/07_extrusionpath.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 7; +use Test::More tests => 8; my $points = [ [100, 100], @@ -28,6 +28,8 @@ is scalar(@$path), 4, 'append to path'; $path->pop_back; is scalar(@$path), 3, 'pop_back from path'; +ok $path->first_point->coincides_with($path->polyline->[0]), 'first_point'; + $path = $path->clone; is $path->role, Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER, 'role'; diff --git a/xs/xsp/ExtrusionPath.xsp b/xs/xsp/ExtrusionPath.xsp index 3d139d53b..b4e03c199 100644 --- a/xs/xsp/ExtrusionPath.xsp +++ b/xs/xsp/ExtrusionPath.xsp @@ -16,6 +16,8 @@ void reverse(); Lines lines() %code{% RETVAL = THIS->polyline.lines(); %}; + Point* first_point() + %code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->first_point())); %}; %{ ExtrusionPath*