~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to lib/Slic3r/Polyline.pm

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

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