PrusaSlicer-NonPlainar/lib/Slic3r/Point.pm

63 lines
1.1 KiB
Perl
Raw Normal View History

2011-09-01 19:06:28 +00:00
package Slic3r::Point;
use strict;
use warnings;
2011-09-01 19:06:28 +00:00
sub new {
my $class = shift;
my $self;
if (@_ == 2) {
$self = [@_];
} elsif ((ref $_[0]) =~ 'ARRAY' || (ref $_[0]) =~ /Slic3r::Point/) {
$self = [@{$_[0]}];
} elsif ($_[0]->isa(__PACKAGE__)) {
return $_[0];
} else {
2011-10-12 14:27:40 +00:00
use XXX;
ZZZ \@_;
die "Invalid arguments for ${class}->new";
}
bless $self, $class;
return $self;
}
2011-09-01 19:06:28 +00:00
2011-12-30 16:17:37 +00:00
sub clone {
my $self = shift;
return (ref $self)->new(@$self);
}
sub cast {
my $class = shift;
if (ref $_[0] eq 'Slic3r::Point') {
return $_[0];
} else {
return $class->new(@_);
}
}
2011-09-01 19:06:28 +00:00
sub id {
my $self = shift;
return join ',', @$self;
2011-09-01 19:06:28 +00:00
}
2011-09-05 10:21:27 +00:00
sub coordinates {
my $self = shift;
return @$self;
}
2011-09-01 19:06:28 +00:00
sub coincides_with {
my $self = shift;
my ($point) = @_;
return Slic3r::Geometry::points_coincide($self, $point);
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, $point);
2011-09-03 18:47:38 +00:00
}
sub x { $_[0]->[0] }
sub y { $_[0]->[1] }
2011-09-01 19:06:28 +00:00
1;