2011-09-01 19:06:28 +00:00
|
|
|
package Slic3r::Point;
|
2011-10-12 12:54:49 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2011-10-12 12:54:49 +00:00
|
|
|
sub new {
|
2011-09-18 17:28:12 +00:00
|
|
|
my $class = shift;
|
2011-11-11 09:21:48 +00:00
|
|
|
my $self;
|
2011-10-12 12:54:49 +00:00
|
|
|
if (@_ == 2) {
|
|
|
|
$self = [@_];
|
2011-11-11 09:21:48 +00:00
|
|
|
} elsif ((ref $_[0]) =~ 'ARRAY' || (ref $_[0]) =~ /Slic3r::Point/) {
|
2011-10-12 12:54:49 +00:00
|
|
|
$self = [@{$_[0]}];
|
|
|
|
} elsif ($_[0]->isa(__PACKAGE__)) {
|
|
|
|
return $_[0];
|
|
|
|
} else {
|
|
|
|
die "Invalid arguments for ${class}->new";
|
|
|
|
}
|
|
|
|
bless $self, $class;
|
|
|
|
return $self;
|
2011-09-18 17:28:12 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
sub coincides_with {
|
|
|
|
my $self = shift;
|
|
|
|
my ($point) = @_;
|
2011-10-12 12:54:49 +00:00
|
|
|
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) = @_;
|
2011-10-12 12:54:49 +00:00
|
|
|
return Slic3r::Geometry::distance_between_points($self, $point);
|
2011-09-03 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 21:16:02 +00:00
|
|
|
sub scale {
|
|
|
|
my $self = shift;
|
|
|
|
my ($factor) = @_;
|
|
|
|
$_ *= $factor for @$self;
|
|
|
|
$self;
|
|
|
|
}
|
|
|
|
|
2012-04-16 09:55:14 +00:00
|
|
|
sub rotate {
|
|
|
|
my $self = shift;
|
|
|
|
my ($angle, $center) = @_;
|
|
|
|
@$self = @{ +(Slic3r::Geometry::rotate_points($angle, $center, $self))[0] };
|
2012-08-23 13:42:58 +00:00
|
|
|
$self;
|
2012-04-16 09:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub translate {
|
|
|
|
my $self = shift;
|
|
|
|
my ($x, $y) = @_;
|
|
|
|
@$self = @{ +(Slic3r::Geometry::move_points([$x, $y], $self))[0] };
|
2012-08-23 13:42:58 +00:00
|
|
|
$self;
|
2012-04-16 09:55:14 +00:00
|
|
|
}
|
|
|
|
|
2011-10-12 12:54:49 +00:00
|
|
|
sub x { $_[0]->[0] }
|
|
|
|
sub y { $_[0]->[1] }
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
1;
|