2011-09-01 19:06:28 +00:00
|
|
|
package Slic3r::Point;
|
2011-09-06 09:50:43 +00:00
|
|
|
use Moo;
|
2011-09-01 19:06:28 +00:00
|
|
|
|
|
|
|
has 'x' => (
|
|
|
|
is => 'ro',
|
|
|
|
required => 1,
|
2011-09-06 09:50:43 +00:00
|
|
|
coerce => sub { sprintf '%.0f', $_[0] },
|
2011-09-01 19:06:28 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
has 'y' => (
|
|
|
|
is => 'ro',
|
|
|
|
required => 1,
|
2011-09-06 09:50:43 +00:00
|
|
|
coerce => sub { sprintf '%.0f', $_[0] },
|
2011-09-01 19:06:28 +00:00
|
|
|
);
|
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
sub cast {
|
|
|
|
my $class = shift;
|
|
|
|
my ($point) = @_;
|
|
|
|
return ref $point eq 'ARRAY'
|
|
|
|
? Slic3r::Point->new(x => $point->[0], y => $point->[1]) # ==
|
|
|
|
: $point;
|
|
|
|
}
|
2011-09-01 19:06:28 +00:00
|
|
|
|
|
|
|
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-18 17:28:12 +00:00
|
|
|
sub p {
|
|
|
|
my $self = shift;
|
|
|
|
return [ $self->coordinates ];
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
sub coincides_with {
|
|
|
|
my $self = shift;
|
|
|
|
my ($point) = @_;
|
2011-09-18 17:28:12 +00:00
|
|
|
return Slic3r::Geometry::points_coincide($self->p, $point->p);
|
2011-09-01 19:06:28 +00:00
|
|
|
}
|
|
|
|
|
2011-09-03 18:47:38 +00:00
|
|
|
sub distance_to {
|
|
|
|
my $self = shift;
|
|
|
|
my ($point) = @_;
|
2011-09-18 17:28:12 +00:00
|
|
|
return Slic3r::Geometry::distance_between_points($self->p, $point->p);
|
2011-09-03 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
1;
|