2011-09-01 19:06:28 +00:00
|
|
|
package Slic3r::Line;
|
2011-10-12 14:27:40 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2013-04-27 13:02:13 +00:00
|
|
|
# a line is a two-points line
|
|
|
|
use parent 'Slic3r::Polyline';
|
|
|
|
|
2011-11-11 21:01:27 +00:00
|
|
|
use Slic3r::Geometry qw(A B X Y);
|
2011-10-20 16:11:59 +00:00
|
|
|
|
2011-10-12 14:27:40 +00:00
|
|
|
sub new {
|
2011-09-18 17:28:12 +00:00
|
|
|
my $class = shift;
|
2011-10-12 14:27:40 +00:00
|
|
|
my $self;
|
2012-02-25 21:15:34 +00:00
|
|
|
$self = [ @_ ];
|
2011-10-12 14:27:40 +00:00
|
|
|
bless $self, $class;
|
2011-11-13 17:14:02 +00:00
|
|
|
bless $_, 'Slic3r::Point' for @$self;
|
2011-10-12 14:27:40 +00:00
|
|
|
return $self;
|
2011-09-01 19:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub coincides_with {
|
|
|
|
my $self = shift;
|
|
|
|
my ($line) = @_;
|
|
|
|
|
|
|
|
return ($self->a->coincides_with($line->a) && $self->b->coincides_with($line->b))
|
|
|
|
|| ($self->a->coincides_with($line->b) && $self->b->coincides_with($line->a));
|
|
|
|
}
|
|
|
|
|
2012-11-17 11:08:19 +00:00
|
|
|
sub vector {
|
|
|
|
my $self = shift;
|
|
|
|
return (ref $self)->new([0,0], [map $self->[B][$_] - $self->[A][$_], X,Y]);
|
|
|
|
}
|
|
|
|
|
2011-10-20 16:11:59 +00:00
|
|
|
sub atan {
|
|
|
|
my $self = shift;
|
|
|
|
return Slic3r::Geometry::line_atan($self);
|
|
|
|
}
|
|
|
|
|
2011-12-02 22:35:39 +00:00
|
|
|
sub direction {
|
|
|
|
my $self = shift;
|
|
|
|
return Slic3r::Geometry::line_direction($self);
|
|
|
|
}
|
|
|
|
|
2011-10-20 16:11:59 +00:00
|
|
|
sub intersection {
|
|
|
|
my $self = shift;
|
|
|
|
my ($line, $require_crossing) = @_;
|
|
|
|
return Slic3r::Geometry::line_intersection($self, $line, $require_crossing);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub point_on_left {
|
|
|
|
my $self = shift;
|
|
|
|
my ($point) = @_;
|
|
|
|
return Slic3r::Geometry::point_is_on_left_of_segment($point, $self);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub midpoint {
|
|
|
|
my $self = shift;
|
|
|
|
return Slic3r::Point->new(
|
|
|
|
($self->[A][X] + $self->[B][X]) / 2,
|
|
|
|
($self->[A][Y] + $self->[B][Y]) / 2,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
1;
|