PrusaSlicer-NonPlainar/lib/Slic3r/Point.pm

52 lines
947 B
Perl
Raw Normal View History

2011-09-01 19:06:28 +00:00
package Slic3r::Point;
use Moo;
2011-09-01 19:06:28 +00:00
has 'x' => (
is => 'ro',
required => 1,
#coerce => sub { sprintf '%.0f', $_[0] },
2011-09-01 19:06:28 +00:00
);
has 'y' => (
is => 'ro',
required => 1,
#coerce => sub { sprintf '%.0f', $_[0] },
2011-09-01 19:06:28 +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); #))
}
sub p {
my $self = shift;
return [ $self->coordinates ];
}
2011-09-01 19:06:28 +00:00
sub coincides_with {
my $self = shift;
my ($point) = @_;
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) = @_;
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;