Polyline.pm 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package Slic3r::Polyline;
  2. use strict;
  3. use warnings;
  4. use List::Util qw(first);
  5. use Slic3r::Geometry qw(X Y PI epsilon);
  6. use Slic3r::Geometry::Clipper qw(JT_SQUARE);
  7. sub new_scale {
  8. my $class = shift;
  9. my @points = map { ref($_) eq 'Slic3r::Point' ? $_->pp : $_ } @_;
  10. return $class->new(map [ Slic3r::Geometry::scale($_->[X]), Slic3r::Geometry::scale($_->[Y]) ], @points);
  11. }
  12. sub wkt {
  13. my $self = shift;
  14. return sprintf "LINESTRING((%s))", join ',', map "$_->[0] $_->[1]", @$self;
  15. }
  16. sub bounding_box {
  17. my $self = shift;
  18. return Slic3r::Geometry::BoundingBox->new_from_points([ @$self ]);
  19. }
  20. sub size {
  21. my $self = shift;
  22. return [ Slic3r::Geometry::size_2D($self) ];
  23. }
  24. sub is_straight {
  25. my ($self) = @_;
  26. # Check that each segment's direction is equal to the line connecting
  27. # first point and last point. (Checking each line against the previous
  28. # one would have caused the error to accumulate.)
  29. my $dir = Slic3r::Line->new($self->first_point, $self->last_point)->direction;
  30. return !defined first { !$_->parallel_to($dir) } @{$self->lines};
  31. }
  32. 1;