Polygon.pm 976 B

1234567891011121314151617181920212223242526272829303132333435
  1. package Slic3r::Polygon;
  2. use strict;
  3. use warnings;
  4. # a polygon is a closed polyline.
  5. use parent 'Slic3r::Polyline';
  6. use Slic3r::Geometry qw(PI);
  7. sub grow {
  8. my $self = shift;
  9. return $self->split_at_first_point->grow(@_);
  10. }
  11. # this method subdivides the polygon segments to that no one of them
  12. # is longer than the length provided
  13. sub subdivide {
  14. my $self = shift;
  15. my ($max_length) = @_;
  16. my @points = @$self;
  17. push @points, $points[0]; # append first point as this is a polygon
  18. my @new_points = shift @points;
  19. while (@points) {
  20. while ($new_points[-1]->distance_to($points[0]) > $max_length) {
  21. push @new_points, map Slic3r::Point->new(@$_),
  22. Slic3r::Geometry::point_along_segment($new_points[-1], $points[0], $max_length);
  23. }
  24. push @new_points, shift @points;
  25. }
  26. pop @new_points; # remove last point as it coincides with first one
  27. return Slic3r::Polygon->new(@new_points);
  28. }
  29. 1;