2011-09-01 19:06:28 +00:00
|
|
|
package Slic3r::Point;
|
|
|
|
use Moose;
|
|
|
|
use Moose::Util::TypeConstraints;
|
|
|
|
|
|
|
|
subtype 'Slic3r::Point::Coordinate', as 'Int';
|
|
|
|
coerce 'Slic3r::Point::Coordinate', from 'Num', via { sprintf '%.0f', $_ };
|
|
|
|
|
|
|
|
has 'x' => (
|
|
|
|
is => 'ro',
|
|
|
|
isa => 'Slic3r::Point::Coordinate',
|
|
|
|
required => 1,
|
|
|
|
coerce => 1,
|
|
|
|
);
|
|
|
|
|
|
|
|
has 'y' => (
|
|
|
|
is => 'ro',
|
|
|
|
isa => 'Slic3r::Point::Coordinate',
|
|
|
|
required => 1,
|
|
|
|
coerce => 1,
|
|
|
|
);
|
|
|
|
|
|
|
|
# this array contains weak references, so it can contain undef's as well
|
|
|
|
has 'lines' => (
|
|
|
|
is => 'rw',
|
|
|
|
isa => 'ArrayRef[Slic3r::Line]',
|
|
|
|
default => sub { [] },
|
|
|
|
);
|
|
|
|
|
|
|
|
sub id {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->x . "," . $self->y; #;;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:21:27 +00:00
|
|
|
sub coordinates {
|
|
|
|
my $self = shift;
|
|
|
|
return ($self->x, $self->y); #))
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
sub coincides_with {
|
|
|
|
my $self = shift;
|
|
|
|
my ($point) = @_;
|
|
|
|
|
2011-09-02 19:10:20 +00:00
|
|
|
$point = Slic3r::Point->new(x => $point->[0], y => $point->[1]) #==
|
|
|
|
if ref $point eq 'ARRAY';
|
2011-09-01 19:06:28 +00:00
|
|
|
return $self->x == $point->x && $self->y == $point->y; #=
|
|
|
|
}
|
|
|
|
|
2011-09-03 18:47:38 +00:00
|
|
|
sub distance_to {
|
|
|
|
my $self = shift;
|
|
|
|
my ($point) = @_;
|
|
|
|
|
|
|
|
return sqrt(($point->x - $self->x)**2 + ($point->y - $self->y)**2); #-
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
1;
|