2011-11-11 21:01:27 +00:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
plan tests => 11;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/../lib";
|
2017-08-18 07:58:50 +00:00
|
|
|
use local::lib "$FindBin::Bin/../local-lib";
|
2011-11-11 21:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
use Slic3r;
|
|
|
|
use Slic3r::Geometry qw(collinear);
|
|
|
|
|
|
|
|
#==========================================================
|
|
|
|
|
|
|
|
{
|
|
|
|
my @lines = (
|
2013-08-26 23:26:44 +00:00
|
|
|
Slic3r::Line->new([0,4], [4,2]),
|
|
|
|
Slic3r::Line->new([2,3], [8,0]),
|
|
|
|
Slic3r::Line->new([6,1], [8,0]),
|
2011-11-11 21:01:27 +00:00
|
|
|
);
|
|
|
|
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
|
|
|
is collinear($lines[1], $lines[2]), 1, 'collinear';
|
|
|
|
is collinear($lines[0], $lines[2]), 1, 'collinear';
|
|
|
|
}
|
|
|
|
|
|
|
|
#==========================================================
|
|
|
|
|
|
|
|
{
|
|
|
|
# horizontal
|
|
|
|
my @lines = (
|
2013-08-26 23:26:44 +00:00
|
|
|
Slic3r::Line->new([0,1], [5,1]),
|
|
|
|
Slic3r::Line->new([2,1], [8,1]),
|
2011-11-11 21:01:27 +00:00
|
|
|
);
|
|
|
|
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
|
|
|
}
|
|
|
|
|
|
|
|
#==========================================================
|
|
|
|
|
|
|
|
{
|
|
|
|
# vertical
|
|
|
|
my @lines = (
|
2013-08-26 23:26:44 +00:00
|
|
|
Slic3r::Line->new([1,0], [1,5]),
|
|
|
|
Slic3r::Line->new([1,2], [1,8]),
|
2011-11-11 21:01:27 +00:00
|
|
|
);
|
|
|
|
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
|
|
|
}
|
|
|
|
|
|
|
|
#==========================================================
|
|
|
|
|
|
|
|
{
|
|
|
|
# non overlapping
|
|
|
|
my @lines = (
|
2013-08-26 23:26:44 +00:00
|
|
|
Slic3r::Line->new([0,1], [5,1]),
|
|
|
|
Slic3r::Line->new([7,1], [10,1]),
|
2011-11-11 21:01:27 +00:00
|
|
|
);
|
|
|
|
is collinear($lines[0], $lines[1], 1), 0, 'non overlapping';
|
|
|
|
is collinear($lines[0], $lines[1], 0), 1, 'overlapping';
|
|
|
|
}
|
|
|
|
|
|
|
|
#==========================================================
|
|
|
|
|
|
|
|
{
|
|
|
|
# with one common point
|
|
|
|
my @lines = (
|
2013-08-26 23:26:44 +00:00
|
|
|
Slic3r::Line->new([0,4], [4,2]),
|
|
|
|
Slic3r::Line->new([4,2], [8,0]),
|
2011-11-11 21:01:27 +00:00
|
|
|
);
|
|
|
|
is collinear($lines[0], $lines[1], 1), 1, 'one common point';
|
|
|
|
is collinear($lines[0], $lines[1], 0), 1, 'one common point';
|
|
|
|
}
|
|
|
|
|
|
|
|
#==========================================================
|
|
|
|
|
|
|
|
{
|
|
|
|
# not collinear
|
|
|
|
my @lines = (
|
2013-08-26 23:26:44 +00:00
|
|
|
Slic3r::Line->new([290000000,690525600], [285163380,684761540]),
|
|
|
|
Slic3r::Line->new([285163380,684761540], [193267599,575244400]),
|
2011-11-11 21:01:27 +00:00
|
|
|
);
|
|
|
|
is collinear($lines[0], $lines[1], 0), 0, 'not collinear';
|
|
|
|
is collinear($lines[0], $lines[1], 1), 0, 'not collinear';
|
|
|
|
}
|
|
|
|
|
|
|
|
#==========================================================
|