forked from pcb2gcode/pcb2gcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_finding_tests.cpp
More file actions
133 lines (117 loc) · 4.63 KB
/
Copy pathpath_finding_tests.cpp
File metadata and controls
133 lines (117 loc) · 4.63 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#define BOOST_TEST_MODULE path finding tests
#include <boost/test/unit_test.hpp>
#include <ostream>
#include "geometry.hpp"
#include "bg_operators.hpp"
#include "bg_helpers.hpp"
#include <boost/optional.hpp>
using boost::make_optional;
#include <boost/optional/optional_io.hpp>
#include "path_finding.hpp"
using namespace std;
using namespace path_finding;
BOOST_AUTO_TEST_SUITE(path_finding_tests)
BOOST_AUTO_TEST_CASE(simple) {
box_type_fp bounding_box = bg::return_envelope<box_type_fp>(point_type_fp(-100, -100));
bg::expand(bounding_box, point_type_fp(100, 100));
multi_polygon_type_fp keep_in;
bg::convert(bounding_box, keep_in);
auto surface = create_path_finding_surface(keep_in, multi_polygon_type_fp(), 0.1);
auto ret = find_path(surface, point_type_fp(0,0), point_type_fp(1,1), nullptr);
linestring_type_fp expected;
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(1, 1));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
}
BOOST_AUTO_TEST_CASE(box) {
ring_type_fp box;
box.push_back(point_type_fp(3,3));
box.push_back(point_type_fp(3,7));
box.push_back(point_type_fp(7,7));
box.push_back(point_type_fp(8,3));
box.push_back(point_type_fp(3,3));
polygon_type_fp poly;
poly.outer() = box;
multi_polygon_type_fp keep_out;
keep_out.push_back(poly);
box_type_fp bounding_box = bg::return_envelope<box_type_fp>(point_type_fp(-100, -100));
bg::expand(bounding_box, point_type_fp(100, 100));
multi_polygon_type_fp keep_in;
bg::convert(bounding_box, keep_in);
auto surface = create_path_finding_surface(keep_in, keep_out, 0.1);
auto ret = find_path(surface, point_type_fp(0,0), point_type_fp(10,10), nullptr);
linestring_type_fp expected;
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(3, 7));
expected.push_back(point_type_fp(10, 10));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
}
BOOST_AUTO_TEST_CASE(unreachable_box) {
ring_type_fp box;
box.push_back(point_type_fp(3,3));
box.push_back(point_type_fp(3,7));
box.push_back(point_type_fp(7,7));
box.push_back(point_type_fp(8,3));
box.push_back(point_type_fp(3,3));
polygon_type_fp poly;
poly.outer() = box;
multi_polygon_type_fp keep_out;
keep_out.push_back(poly);
box_type_fp bounding_box = bg::return_envelope<box_type_fp>(point_type_fp(-100, -100));
bg::expand(bounding_box, point_type_fp(100, 100));
multi_polygon_type_fp keep_in;
bg::convert(bounding_box, keep_in);
auto surface = create_path_finding_surface(keep_in, keep_out, 0.1);
auto ret = find_path(surface, point_type_fp(0,0), point_type_fp(5,5), nullptr);
BOOST_CHECK_EQUAL(ret, boost::none);
}
BOOST_AUTO_TEST_CASE(reuse_surface) {
ring_type_fp box;
box.push_back(point_type_fp(3,3));
box.push_back(point_type_fp(3,7));
box.push_back(point_type_fp(7,7));
box.push_back(point_type_fp(8,3));
box.push_back(point_type_fp(3,3));
polygon_type_fp poly;
poly.outer() = box;
multi_polygon_type_fp keep_out;
keep_out.push_back(poly);
box_type_fp bounding_box = bg::return_envelope<box_type_fp>(point_type_fp(-100, -100));
bg::expand(bounding_box, point_type_fp(100, 100));
multi_polygon_type_fp keep_in;
bg::convert(bounding_box, keep_in);
auto surface = create_path_finding_surface(keep_in, keep_out, 0.1);
auto ret = find_path(surface, point_type_fp(0,0), point_type_fp(5,5), nullptr);
BOOST_CHECK_EQUAL(ret, boost::none);
ret = find_path(surface, point_type_fp(0,0), point_type_fp(10,10), nullptr);
linestring_type_fp expected;
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(3, 7));
expected.push_back(point_type_fp(10, 10));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
}
BOOST_AUTO_TEST_CASE(u_shape) {
ring_type_fp u_shape;
u_shape.push_back(point_type_fp( 0, 10));
u_shape.push_back(point_type_fp( 3, 10));
u_shape.push_back(point_type_fp( 3, 3));
u_shape.push_back(point_type_fp( 7, 3));
u_shape.push_back(point_type_fp( 7, 10));
u_shape.push_back(point_type_fp(10, 10));
u_shape.push_back(point_type_fp(10, 0));
u_shape.push_back(point_type_fp( 0, 0));
u_shape.push_back(point_type_fp( 0, 10));
polygon_type_fp poly;
poly.outer() = u_shape;
multi_polygon_type_fp keep_in;
keep_in.push_back(poly);
auto surface = create_path_finding_surface(keep_in, multi_polygon_type_fp(), 0.1);
auto ret = find_path(surface, point_type_fp(1,9), point_type_fp(9,9), nullptr);
linestring_type_fp expected;
expected.push_back(point_type_fp(1, 9));
expected.push_back(point_type_fp(3, 3));
expected.push_back(point_type_fp(7, 3));
expected.push_back(point_type_fp(9, 9));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
}
BOOST_AUTO_TEST_SUITE_END()