2011-09-01 19:06:28 +00:00
|
|
|
package Slic3r::Line;
|
2011-09-06 09:50:43 +00:00
|
|
|
use Moo;
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
# arrayref of points
|
|
|
|
has 'points' => (
|
2011-09-01 19:06:28 +00:00
|
|
|
is => 'rw',
|
2011-09-18 17:28:12 +00:00
|
|
|
default => sub { [] },
|
|
|
|
required => 1,
|
2011-09-02 19:10:20 +00:00
|
|
|
);
|
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
sub cast {
|
|
|
|
my $class = shift;
|
|
|
|
my ($line) = @_;
|
|
|
|
if (ref $line eq 'ARRAY') {
|
|
|
|
@$line == 2 or die "Line needs two points!";
|
|
|
|
return Slic3r::Line->new(points => [ map Slic3r::Point->cast($_), @$line ]);
|
|
|
|
} else {
|
|
|
|
return $line;
|
2011-09-01 19:06:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
sub a { return $_[0]->points->[0] }
|
|
|
|
sub b { return $_[0]->points->[1] }
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
sub id {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->a->id . "-" . $self->b->id;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:21:27 +00:00
|
|
|
sub coordinates {
|
|
|
|
my $self = shift;
|
|
|
|
return ($self->a->coordinates, $self->b->coordinates);
|
|
|
|
}
|
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
sub p {
|
|
|
|
my $self = shift;
|
|
|
|
return [ $self->a->p, $self->b->p ];
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2011-09-02 19:10:20 +00:00
|
|
|
sub has_endpoint {
|
|
|
|
my $self = shift;
|
2011-09-05 10:21:27 +00:00
|
|
|
my ($point) = @_;
|
2011-09-02 19:10:20 +00:00
|
|
|
return $point->coincides_with($self->a) || $point->coincides_with($self->b);
|
|
|
|
}
|
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
sub parallel_to {
|
2011-09-01 19:06:28 +00:00
|
|
|
my $self = shift;
|
2011-09-18 17:28:12 +00:00
|
|
|
my ($line) = @_;
|
|
|
|
return Slic3r::Geometry::lines_parallel($self->p, $line->p);
|
2011-09-01 19:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|