Don't extrude acute angles

This commit is contained in:
Alessandro Ranellucci 2011-10-01 14:26:54 +02:00
parent 25ea8a0204
commit ea88cad8e3
4 changed files with 52 additions and 5 deletions

View file

@ -3,6 +3,8 @@ use Moo;
extends 'Slic3r::Polyline';
use constant PI => 4 * atan2(1, 1);
sub clip_end {
my $self = shift;
my ($distance) = @_;
@ -34,4 +36,36 @@ sub reverse {
@{$self->points} = reverse @{$self->points};
}
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
push @paths, __PACKAGE__->cast([@p]);
@p = ($p3);
push @p, grep $_, shift @points or last;
} else {
push @p, $p3;
}
}
push @paths, __PACKAGE__->cast([@p]) if @p > 1;
return @paths;
}
1;