2013-07-06 13:26:32 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Slic3r::XS;
|
2014-05-22 10:28:12 +00:00
|
|
|
use Test::More tests => 15;
|
2013-07-06 13:26:32 +00:00
|
|
|
|
2013-07-15 18:31:43 +00:00
|
|
|
my $point = Slic3r::Point->new(10, 15);
|
2013-07-06 13:26:32 +00:00
|
|
|
is_deeply [ @$point ], [10, 15], 'point roundtrip';
|
|
|
|
|
2013-07-15 14:04:49 +00:00
|
|
|
my $point2 = $point->clone;
|
|
|
|
$point2->scale(2);
|
|
|
|
is_deeply [ @$point2 ], [20, 30], 'scale';
|
|
|
|
|
|
|
|
$point2->translate(10, -15);
|
|
|
|
is_deeply [ @$point2 ], [30, 15], 'translate';
|
|
|
|
|
|
|
|
ok $point->coincides_with($point->clone), 'coincides_with';
|
|
|
|
ok !$point->coincides_with($point2), 'coincides_with';
|
|
|
|
|
2013-07-16 15:13:01 +00:00
|
|
|
{
|
|
|
|
my $point3 = Slic3r::Point->new(4300000, -9880845);
|
|
|
|
is $point->[0], $point->x, 'x accessor';
|
2013-08-26 22:52:20 +00:00
|
|
|
is $point->[1], $point->y, 'y accessor'; #,,
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my $nearest = $point->nearest_point([ $point2, Slic3r::Point->new(100, 200) ]);
|
|
|
|
ok $nearest->coincides_with($point2), 'nearest_point';
|
2013-07-16 15:13:01 +00:00
|
|
|
}
|
|
|
|
|
2014-01-17 13:22:37 +00:00
|
|
|
{
|
|
|
|
my $line = Slic3r::Line->new(
|
|
|
|
[18335846,18335845],
|
|
|
|
[18335846,1664160],
|
|
|
|
);
|
|
|
|
$point = Slic3r::Point->new(1664161,18335848);
|
|
|
|
is $point->distance_to_line($line), 16671685, 'distance_to_line() does not overflow';
|
|
|
|
}
|
|
|
|
|
2014-01-17 13:49:51 +00:00
|
|
|
{
|
|
|
|
my $p0 = Slic3r::Point->new(76975850,89989996);
|
|
|
|
my $p1 = Slic3r::Point->new(76989990,109989991);
|
|
|
|
my $p2 = Slic3r::Point->new(76989987,89989994);
|
|
|
|
ok $p0->ccw($p1, $p2) < 0, 'ccw() does not overflow';
|
|
|
|
}
|
|
|
|
|
2014-05-21 18:08:21 +00:00
|
|
|
{
|
|
|
|
my $point = Slic3r::Point->new(15,15);
|
|
|
|
my $line = Slic3r::Line->new([10,10], [20,10]);
|
|
|
|
is_deeply $point->projection_onto_line($line)->pp, [15,10], 'project_onto_line';
|
|
|
|
|
|
|
|
$point = Slic3r::Point->new(0, 15);
|
|
|
|
is_deeply $point->projection_onto_line($line)->pp, [10,10], 'project_onto_line';
|
|
|
|
|
|
|
|
$point = Slic3r::Point->new(25, 15);
|
|
|
|
is_deeply $point->projection_onto_line($line)->pp, [20,10], 'project_onto_line';
|
2014-05-22 10:28:12 +00:00
|
|
|
|
|
|
|
$point = Slic3r::Point->new(10,10);
|
|
|
|
is_deeply $point->projection_onto_line($line)->pp, [10,10], 'project_onto_line';
|
|
|
|
|
|
|
|
$point = Slic3r::Point->new(12, 10);
|
|
|
|
is_deeply $point->projection_onto_line($line)->pp, [12,10], 'project_onto_line';
|
2014-05-21 18:08:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-06 13:26:32 +00:00
|
|
|
__END__
|