ExPolygon.pm 1022 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package Slic3r::ExPolygon;
  2. use strict;
  3. use warnings;
  4. # an ExPolygon is a polygon with holes
  5. use List::Util qw(first);
  6. use Slic3r::Geometry qw(X Y A B point_in_polygon epsilon scaled_epsilon);
  7. use Slic3r::Geometry::Clipper qw(union_ex diff_pl);
  8. sub wkt {
  9. my $self = shift;
  10. return sprintf "POLYGON(%s)",
  11. join ',', map "($_)", map { join ',', map "$_->[0] $_->[1]", @$_ } @$self;
  12. }
  13. sub dump_perl {
  14. my $self = shift;
  15. return sprintf "[%s]",
  16. join ',', map "[$_]", map { join ',', map "[$_->[0],$_->[1]]", @$_ } @$self;
  17. }
  18. sub offset {
  19. my $self = shift;
  20. return Slic3r::Geometry::Clipper::offset(\@$self, @_);
  21. }
  22. sub offset_ex {
  23. my $self = shift;
  24. return Slic3r::Geometry::Clipper::offset_ex(\@$self, @_);
  25. }
  26. sub bounding_box {
  27. my $self = shift;
  28. return $self->contour->bounding_box;
  29. }
  30. package Slic3r::ExPolygon::Collection;
  31. use Slic3r::Geometry qw(X1 Y1);
  32. sub size {
  33. my $self = shift;
  34. return [ Slic3r::Geometry::size_2D([ map @$_, map @$_, @$self ]) ];
  35. }
  36. 1;