2013-07-16 15:13:01 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Slic3r::XS;
|
2014-06-15 23:49:49 +00:00
|
|
|
use Test::More tests => 39;
|
2014-05-02 11:26:59 +00:00
|
|
|
|
|
|
|
use constant PI => 4 * atan2(1, 1);
|
|
|
|
use constant EPSILON => 1E-4;
|
2013-07-16 15:13:01 +00:00
|
|
|
|
|
|
|
my $points = [
|
|
|
|
[100, 100],
|
|
|
|
[200, 100],
|
|
|
|
];
|
|
|
|
|
|
|
|
my $line = Slic3r::Line->new(@$points);
|
|
|
|
is_deeply $line->pp, $points, 'line roundtrip';
|
|
|
|
|
|
|
|
is ref($line->arrayref), 'ARRAY', 'line arrayref is unblessed';
|
2013-09-02 18:22:20 +00:00
|
|
|
isa_ok $line->[0], 'Slic3r::Point::Ref', 'line point is blessed';
|
2013-07-16 15:13:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
my $clone = $line->clone;
|
|
|
|
$clone->reverse;
|
|
|
|
is_deeply $clone->pp, [ reverse @$points ], 'reverse';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my $line2 = Slic3r::Line->new($line->a->clone, $line->b->clone);
|
|
|
|
is_deeply $line2->pp, $points, 'line roundtrip with cloned points';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my $clone = $line->clone;
|
|
|
|
$clone->translate(10, -5);
|
|
|
|
is_deeply $clone->pp, [
|
|
|
|
[110, 95],
|
|
|
|
[210, 95],
|
|
|
|
], 'translate';
|
|
|
|
}
|
|
|
|
|
2014-06-15 23:49:49 +00:00
|
|
|
{
|
|
|
|
ok +Slic3r::Line->new([0,0],[200,0])->parallel_to_line(Slic3r::Line->new([200,200],[0,200])), 'parallel_to';
|
|
|
|
}
|
|
|
|
|
2014-05-02 11:26:59 +00:00
|
|
|
foreach my $base_angle (0, PI/4, PI/2, PI) {
|
|
|
|
my $line = Slic3r::Line->new([0,0], [100,0]);
|
|
|
|
$line->rotate($base_angle, [0,0]);
|
2014-06-15 23:49:49 +00:00
|
|
|
my $clone = $line->clone;
|
|
|
|
ok $line->parallel_to_line($clone), 'line is parallel to self';
|
|
|
|
$clone->reverse;
|
|
|
|
ok $line->parallel_to_line($clone), 'line is parallel to self + PI';
|
2014-05-02 11:26:59 +00:00
|
|
|
ok $line->parallel_to($line->direction), 'line is parallel to its direction';
|
|
|
|
ok $line->parallel_to($line->direction + PI), 'line is parallel to its direction + PI';
|
|
|
|
ok $line->parallel_to($line->direction - PI), 'line is parallel to its direction - PI';
|
|
|
|
{
|
|
|
|
my $line2 = $line->clone;
|
|
|
|
$line2->reverse;
|
|
|
|
ok $line->parallel_to_line($line2), 'line is parallel to its opposite';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
my $line2 = $line->clone;
|
2014-05-02 16:46:22 +00:00
|
|
|
$line2->rotate(+(EPSILON)/2, [0,0]);
|
2014-05-02 11:26:59 +00:00
|
|
|
ok $line->parallel_to_line($line2), 'line is parallel within epsilon';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
my $line2 = $line->clone;
|
2014-05-02 16:46:22 +00:00
|
|
|
$line2->rotate(-(EPSILON)/2, [0,0]);
|
2014-05-02 11:26:59 +00:00
|
|
|
ok $line->parallel_to_line($line2), 'line is parallel within epsilon';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-16 15:13:01 +00:00
|
|
|
__END__
|