Ported concave_points() and convex_points() to XS

This commit is contained in:
Alessandro Ranellucci 2014-11-30 21:48:50 +01:00
parent 076d82d8d6
commit 1fda9e3d50
4 changed files with 62 additions and 47 deletions

View file

@ -37,51 +37,4 @@ sub subdivide {
return Slic3r::Polygon->new(@new_points);
}
sub concave_points {
my ($self, $angle) = @_;
$angle //= PI;
# input angle threshold is checked on the internal side of the polygon
# but angle3points measures CCW angle, so we calculate the complementary angle
my $ccw_angle = 2*PI-$angle;
my @concave = ();
my @points = @$self;
my @points_pp = @{$self->pp};
for my $i (-1 .. ($#points-1)) {
# angle is measured in ccw orientation
my $vertex_angle = Slic3r::Geometry::angle3points(@points_pp[$i, $i-1, $i+1]);
if ($vertex_angle <= $ccw_angle) {
push @concave, $points[$i];
}
}
return [@concave];
}
sub convex_points {
my ($self, $angle) = @_;
$angle //= PI;
# input angle threshold is checked on the internal side of the polygon
# but angle3points measures CCW angle, so we calculate the complementary angle
my $ccw_angle = 2*PI-$angle;
my @convex = ();
my @points = @$self;
my @points_pp = @{$self->pp};
for my $i (-1 .. ($#points-1)) {
# angle is measured in ccw orientation
my $vertex_angle = Slic3r::Geometry::angle3points(@points_pp[$i, $i-1, $i+1]);
if ($vertex_angle >= $ccw_angle) {
push @convex, $points[$i];
}
}
return [@convex];
}
1;