mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-07 14:04:11 -06:00
Ported point_along_segment(), Polyline::length(), Polyline::clip_end() to XS
This commit is contained in:
parent
26a18a2a52
commit
29b83517cb
12 changed files with 64 additions and 57 deletions
|
@ -264,8 +264,7 @@ sub extrude_loop {
|
|||
# the rotation of the second segment so we might cross the object boundary
|
||||
my $first_segment = Slic3r::Line->new(@{$extrusion_path->polyline}[0,1]);
|
||||
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);
|
||||
my $point = $first_segment->point_at($distance);
|
||||
$point->rotate($angle, $extrusion_path->first_point);
|
||||
|
||||
# generate the travel move
|
||||
|
@ -474,8 +473,8 @@ sub retract {
|
|||
my $wipe_path;
|
||||
if ($self->extruder->wipe && $self->wipe_path) {
|
||||
my @points = @{$self->wipe_path};
|
||||
$wipe_path = Slic3r::Polyline->new($self->last_pos, @{$self->wipe_path}[1..$#{$self->wipe_path}])
|
||||
->clip_start($self->extruder->scaled_wipe_distance);
|
||||
$wipe_path = Slic3r::Polyline->new($self->last_pos, @{$self->wipe_path}[1..$#{$self->wipe_path}]);
|
||||
$wipe_path->clip_end($wipe_path->length - $self->extruder->scaled_wipe_distance);
|
||||
}
|
||||
|
||||
# prepare moves
|
||||
|
|
|
@ -35,11 +35,6 @@ sub simplify {
|
|||
return __PACKAGE__->new(@$simplified);
|
||||
}
|
||||
|
||||
sub length {
|
||||
my $self = shift;
|
||||
return Boost::Geometry::Utils::linestring_length($self->pp);
|
||||
}
|
||||
|
||||
sub grow {
|
||||
my $self = shift;
|
||||
my ($distance, $scale, $joinType, $miterLimit) = @_;
|
||||
|
@ -85,53 +80,6 @@ sub align_to_origin {
|
|||
return $self->translate(-$bb->x_min, -$bb->y_min);
|
||||
}
|
||||
|
||||
# removes the given distance from the end of the polyline
|
||||
sub clip_end {
|
||||
my $self = shift;
|
||||
my ($distance) = @_;
|
||||
|
||||
while ($distance > 0) {
|
||||
my $last_point = $self->last_point->clone;
|
||||
$self->pop_back;
|
||||
last if @$self == 0;
|
||||
|
||||
my $last_segment_length = $last_point->distance_to($self->last_point);
|
||||
if ($last_segment_length <= $distance) {
|
||||
$distance -= $last_segment_length;
|
||||
next;
|
||||
}
|
||||
|
||||
my $new_point = Slic3r::Geometry::point_along_segment($last_point, $self->last_point, $distance);
|
||||
$self->append($new_point);
|
||||
$distance = 0;
|
||||
}
|
||||
}
|
||||
|
||||
# only keeps the given distance at the beginning of the polyline
|
||||
sub clip_start {
|
||||
my $self = shift;
|
||||
my ($distance) = @_;
|
||||
|
||||
my @my_points = @$self;
|
||||
my $points = [ $my_points[0]->clone ];
|
||||
|
||||
for (my $i = 1; $distance > 0 && $i <= $#my_points; $i++) {
|
||||
my $point = $my_points[$i];
|
||||
my $segment_length = $point->distance_to($my_points[$i-1]);
|
||||
if ($segment_length <= $distance) {
|
||||
$distance -= $segment_length;
|
||||
push @$points, $point;
|
||||
next;
|
||||
}
|
||||
|
||||
my $new_point = Slic3r::Geometry::point_along_segment($my_points[$i-1], $point, $distance);
|
||||
push @$points, Slic3r::Point->new(@$new_point);
|
||||
$distance = 0;
|
||||
}
|
||||
|
||||
return __PACKAGE__->new(@$points);
|
||||
}
|
||||
|
||||
# this method returns a collection of points picked on the polygon contour
|
||||
# so that they are evenly spaced according to the input distance
|
||||
# (find a better name!)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue