PrusaSlicer-NonPlainar/xs/t/03_point.t
Vojtech Bubnik f1c0c61895 Refactored Point / MultiPoint / Polyline / Polygon:
1) Removed virtual methods. There was not really need for them.
2) Some of the virtual methods were using conversion to Lines, which
   was unnecessary and expensive.
3) Removed some nearest element search methods from Point.
2022-11-14 19:01:17 +01:00

63 lines
2.0 KiB
Perl

#!/usr/bin/perl
use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 16;
my $point = Slic3r::Point->new(10, 15);
my $point2 = $point->clone;
$point2->scale(2);
is_deeply [ @$point2 ], [20, 30], 'scale';
$point2->translate(10, -15);
is_deeply [ @$point2 ], [30, 15], 'translate';
{
my $point3 = Slic3r::Point->new(4300000, -9880845);
is $point->[0], $point->x, 'x accessor';
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';
}
{
my $line = Slic3r::Line->new([0,0], [100,0]);
is +Slic3r::Point->new(0,0) ->distance_to_line($line), 0, 'distance_to_line()';
is +Slic3r::Point->new(100,0)->distance_to_line($line), 0, 'distance_to_line()';
is +Slic3r::Point->new(50,0) ->distance_to_line($line), 0, 'distance_to_line()';
is +Slic3r::Point->new(150,0)->distance_to_line($line), 50, 'distance_to_line()';
is +Slic3r::Point->new(0,50) ->distance_to_line($line), 50, 'distance_to_line()';
is +Slic3r::Point->new(50,50)->distance_to_line($line), 50, 'distance_to_line()';
is +Slic3r::Point->new(50,50) ->perp_distance_to_line($line), 50, 'perp_distance_to_line()';
is +Slic3r::Point->new(150,50)->perp_distance_to_line($line), 50, 'perp_distance_to_line()';
}
{
my $line = Slic3r::Line->new([50,50], [125,-25]);
cmp_ok(abs(Slic3r::Point->new(100,0)->distance_to_line($line)), '<=', 4e-15, 'distance_to_line()');
}
{
my $line = Slic3r::Line->new(
[18335846,18335845],
[18335846,1664160],
);
$point = Slic3r::Point->new(1664161,18335848);
is $point->perp_distance_to_line($line), 16671685, 'perp_distance_to_line() does not overflow';
}
{
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';
}
__END__