2011-09-04 10:04:01 +00:00
|
|
|
package Slic3r::ExtrusionPath;
|
2011-09-06 09:50:43 +00:00
|
|
|
use Moo;
|
2011-09-04 10:04:01 +00:00
|
|
|
|
|
|
|
extends 'Slic3r::Polyline';
|
|
|
|
|
2011-10-01 12:26:54 +00:00
|
|
|
use constant PI => 4 * atan2(1, 1);
|
|
|
|
|
2011-09-25 21:15:45 +00:00
|
|
|
sub clip_end {
|
|
|
|
my $self = shift;
|
|
|
|
my ($distance) = @_;
|
|
|
|
|
|
|
|
while ($distance > 0) {
|
|
|
|
my $last_point = pop @{$self->points};
|
|
|
|
|
|
|
|
my $last_segment_length = $last_point->distance_to($self->points->[-1]);
|
|
|
|
if ($last_segment_length <= $distance) {
|
|
|
|
$distance -= $last_segment_length;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2011-10-12 12:54:49 +00:00
|
|
|
my $new_point = Slic3r::Geometry::point_along_segment($last_point, $self->points->[-1], $distance);
|
|
|
|
push @{$self->points}, Slic3r::Point->new($new_point);
|
2011-09-25 21:15:45 +00:00
|
|
|
$distance = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-26 08:52:58 +00:00
|
|
|
sub endpoints {
|
|
|
|
my $self = shift;
|
2011-10-12 12:54:49 +00:00
|
|
|
return ($self->points->[0], $self->points->[-1]);
|
2011-09-26 08:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub reverse {
|
|
|
|
my $self = shift;
|
|
|
|
@{$self->points} = reverse @{$self->points};
|
|
|
|
}
|
|
|
|
|
2011-10-01 12:26:54 +00:00
|
|
|
sub split_at_acute_angles {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# calculate angle limit
|
|
|
|
my $angle_limit = abs(Slic3r::Geometry::deg2rad(40));
|
|
|
|
my @points = @{$self->p};
|
|
|
|
|
|
|
|
my @paths = ();
|
|
|
|
|
|
|
|
# take first two points
|
|
|
|
my @p = splice @points, 0, 2;
|
|
|
|
|
|
|
|
# loop until we have one spare point
|
|
|
|
while (my $p3 = shift @points) {
|
|
|
|
my $angle = abs(Slic3r::Geometry::angle3points($p[-1], $p[-2], $p3));
|
|
|
|
$angle = 2*PI - $angle if $angle > PI;
|
|
|
|
|
|
|
|
if ($angle < $angle_limit) {
|
|
|
|
# if the angle between $p[-2], $p[-1], $p3 is too acute
|
|
|
|
# then consider $p3 only as a starting point of a new
|
|
|
|
# path and stop the current one as it is
|
2011-10-15 09:36:05 +00:00
|
|
|
push @paths, (ref $self)->cast([@p]);
|
2011-10-01 12:26:54 +00:00
|
|
|
@p = ($p3);
|
|
|
|
push @p, grep $_, shift @points or last;
|
|
|
|
} else {
|
|
|
|
push @p, $p3;
|
|
|
|
}
|
|
|
|
}
|
2011-10-15 09:36:05 +00:00
|
|
|
push @paths, (ref $self)->cast([@p]) if @p > 1;
|
2011-10-01 12:26:54 +00:00
|
|
|
return @paths;
|
|
|
|
}
|
|
|
|
|
2011-09-04 10:04:01 +00:00
|
|
|
1;
|