ExPolygon.pm 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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::Clipper qw(union_ex diff_pl);
  7. sub wkt {
  8. my $self = shift;
  9. return sprintf "POLYGON(%s)",
  10. join ',', map "($_)", map { join ',', map "$_->[0] $_->[1]", @$_ } @$self;
  11. }
  12. sub dump_perl {
  13. my $self = shift;
  14. return sprintf "[%s]",
  15. join ',', map "[$_]", map { join ',', map "[$_->[0],$_->[1]]", @$_ } @$self;
  16. }
  17. sub offset {
  18. my $self = shift;
  19. return Slic3r::Geometry::Clipper::offset(\@$self, @_);
  20. }
  21. sub offset_ex {
  22. my $self = shift;
  23. return Slic3r::Geometry::Clipper::offset_ex(\@$self, @_);
  24. }
  25. sub noncollapsing_offset_ex {
  26. my $self = shift;
  27. my ($distance, @params) = @_;
  28. return $self->offset_ex($distance + 1, @params);
  29. }
  30. sub bounding_box {
  31. my $self = shift;
  32. return $self->contour->bounding_box;
  33. }
  34. package Slic3r::ExPolygon::Collection;
  35. sub size {
  36. my $self = shift;
  37. return [ Slic3r::Geometry::size_2D([ map @$_, map @$_, @$self ]) ];
  38. }
  39. 1;