1
package Slic3r::Polygon;
5
# a polygon is a closed polyline.
6
use parent 'Slic3r::Polyline';
8
use Slic3r::Geometry qw(
9
polygon_segment_having_point
10
PI X1 X2 Y1 Y2 epsilon);
11
use Slic3r::Geometry::Clipper qw(intersection_pl);
15
return sprintf "POLYGON((%s))", join ',', map "$_->[0] $_->[1]", @$self;
20
return sprintf "[%s]", join ',', map "[$_->[0],$_->[1]]", @$self;
25
return $self->split_at_first_point->grow(@_);
28
# this method subdivides the polygon segments to that no one of them
29
# is longer than the length provided
32
my ($max_length) = @_;
35
push @points, $points[0]; # append first point as this is a polygon
36
my @new_points = shift @points;
38
while ($new_points[-1]->distance_to($points[0]) > $max_length) {
39
push @new_points, map Slic3r::Point->new(@$_),
40
Slic3r::Geometry::point_along_segment($new_points[-1], $points[0], $max_length);
42
push @new_points, shift @points;
44
pop @new_points; # remove last point as it coincides with first one
45
return Slic3r::Polygon->new(@new_points);
49
my ($self, $angle) = @_;
53
# input angle threshold is checked on the internal side of the polygon
54
# but angle3points measures CCW angle, so we calculate the complementary angle
55
my $ccw_angle = 2*PI-$angle;
58
my @points_pp = @{$self->pp};
61
for my $i (-1 .. ($#points-1)) {
62
next if $points[$i-1]->coincides_with($points[$i]);
63
# angle is measured in ccw orientation
64
my $vertex_angle = Slic3r::Geometry::angle3points(@points_pp[$i, $i-1, $i+1]);
65
if ($vertex_angle <= $ccw_angle) {
66
push @concave, $points[$i];
73
my ($self, $angle) = @_;
77
# input angle threshold is checked on the internal side of the polygon
78
# but angle3points measures CCW angle, so we calculate the complementary angle
79
my $ccw_angle = 2*PI-$angle;
82
my @points_pp = @{$self->pp};
85
for my $i (-1 .. ($#points-1)) {
86
next if $points[$i-1]->coincides_with($points[$i]);
87
# angle is measured in ccw orientation
88
my $vertex_angle = Slic3r::Geometry::angle3points(@points_pp[$i, $i-1, $i+1]);
89
if ($vertex_angle >= $ccw_angle) {
90
push @convex, $points[$i];
b'\\ No newline at end of file'