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

18_motionplanner.t « t « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dfcfec67f791a1deed1c3201fb0d093568c7572b (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
88
89
90
91
92
#!/usr/bin/perl

use strict;
use warnings;

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

use Slic3r::XS;
use Test::More tests => 20;

my $square = Slic3r::Polygon->new(  # ccw
    [100, 100],
    [200, 100],
    [200, 200],
    [100, 200],
);
my $hole_in_square = Slic3r::Polygon->new(  # cw
    [140, 140],
    [140, 160],
    [160, 160],
    [160, 140],
);
$_->scale(1/0.000001) for $square, $hole_in_square;

my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);

{
    my $mp = Slic3r::MotionPlanner->new([ $expolygon ]);
    isa_ok $mp, 'Slic3r::MotionPlanner';
    
    my $from = Slic3r::Point->new(120, 120);
    my $to = Slic3r::Point->new(180,180);
    $_->scale(1/0.000001) for $from, $to;
    my $path = $mp->shortest_path($from, $to);
    ok $path->is_valid(), 'return path is valid';
    ok $path->length > Slic3r::Line->new($from, $to)->length, 'path length is greater than straight line';
    ok $path->first_point->coincides_with($from), 'first path point coincides with initial point';
    ok $path->last_point->coincides_with($to), 'last path point coincides with destination point';
    ok $expolygon->contains_polyline($path), 'path is fully contained in expolygon';
}

{
    my $mp = Slic3r::MotionPlanner->new([ $expolygon ]);
    isa_ok $mp, 'Slic3r::MotionPlanner';
    
    my $from = Slic3r::Point->new(80, 100);
    my $to = Slic3r::Point->new(220,200);
    $_->scale(1/0.000001) for $from, $to;
    
    my $path = $mp->shortest_path($from, $to);
    ok $path->is_valid(), 'return path is valid';
    ok $path->length > Slic3r::Line->new($from, $to)->length, 'path length is greater than straight line';
    ok $path->first_point->coincides_with($from), 'first path point coincides with initial point';
    ok $path->last_point->coincides_with($to), 'last path point coincides with destination point';
    is scalar(@{ Slic3r::Geometry::Clipper::intersection_pl([$path], [@$expolygon]) }), 0, 'path has no intersection with expolygon';
}

{
    my $expolygon2 = $expolygon->clone;
    $expolygon2->translate(300/0.000001, 0);
    my $mp = Slic3r::MotionPlanner->new([ $expolygon, $expolygon2 ]);
    isa_ok $mp, 'Slic3r::MotionPlanner';
    
    my $from = Slic3r::Point->new(120, 120);
    my $to = Slic3r::Point->new(120 + 300, 120);
    $_->scale(1/0.000001) for $from, $to;
    ok $expolygon->contains_point($from), 'start point is contained in first expolygon';
    ok $expolygon2->contains_point($to), 'end point is contained in second expolygon';
    my $path = $mp->shortest_path($from, $to);
    ok $path->is_valid(), 'return path is valid';
}

{
    my $expolygons = [
        Slic3r::ExPolygon->new([[123800962,89330311],[123959159,89699438],[124000004,89898430],[124000012,110116427],[123946510,110343065],[123767391,110701303],[123284087,111000001],[102585791,111000009],[102000004,110414223],[102000004,89585787],[102585790,89000000],[123300022,88999993]]),
        Slic3r::ExPolygon->new([[97800954,89330311],[97959151,89699438],[97999996,89898430],[98000004,110116427],[97946502,110343065],[97767383,110701303],[97284079,111000001],[76585783,111000009],[75999996,110414223],[75999996,89585787],[76585782,89000000],[97300014,88999993]]),
    ];
    my $mp = Slic3r::MotionPlanner->new($expolygons);
    isa_ok $mp, 'Slic3r::MotionPlanner';
    
    my $from = Slic3r::Point->new(79120520, 107839491);
    my $to = Slic3r::Point->new(104664164, 108335852);
    ok $expolygons->[1]->contains_point($from), 'start point is contained in second expolygon';
    ok $expolygons->[0]->contains_point($to), 'end point is contained in first expolygon';
    my $path = $mp->shortest_path($from, $to);
    ok $path->is_valid(), 'return path is valid';
}

__END__