Welcome to mirror list, hosted at ThFree Co, Russian Federation.

collinear.t « t - github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b28a3602c5966b859871c68372215209da988dad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use Test::More;
use strict;
use warnings;

plan tests => 11;

BEGIN {
    use FindBin;
    use lib "$FindBin::Bin/../lib";
    use local::lib "$FindBin::Bin/../local-lib";
}

use Slic3r;
use Slic3r::Geometry qw(collinear);

#==========================================================

{
    my @lines = (
        Slic3r::Line->new([0,4], [4,2]),
        Slic3r::Line->new([2,3], [8,0]),
        Slic3r::Line->new([6,1], [8,0]),
    );
    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 = (
        Slic3r::Line->new([0,1], [5,1]),
        Slic3r::Line->new([2,1], [8,1]),
    );
    is collinear($lines[0], $lines[1]), 1, 'collinear';
}

#==========================================================

{
    # vertical
    my @lines = (
        Slic3r::Line->new([1,0], [1,5]),
        Slic3r::Line->new([1,2], [1,8]),
    );
    is collinear($lines[0], $lines[1]), 1, 'collinear';
}

#==========================================================

{
    # non overlapping
    my @lines = (
        Slic3r::Line->new([0,1], [5,1]),
        Slic3r::Line->new([7,1], [10,1]),
    );
    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 = (
        Slic3r::Line->new([0,4], [4,2]),
        Slic3r::Line->new([4,2], [8,0]),
    );
    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 = (
        Slic3r::Line->new([290000000,690525600], [285163380,684761540]),
        Slic3r::Line->new([285163380,684761540], [193267599,575244400]),
    );
    is collinear($lines[0], $lines[1], 0), 0, 'not collinear';
    is collinear($lines[0], $lines[1], 1), 0, 'not collinear';
}

#==========================================================