-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathshape_test.cpp
More file actions
131 lines (114 loc) · 4.97 KB
/
shape_test.cpp
File metadata and controls
131 lines (114 loc) · 4.97 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
#include "packingsolver/irregular/shape.hpp"
#include <gtest/gtest.h>
using namespace packingsolver;
using namespace packingsolver::irregular;
struct ShapeElementLengthTestParams
{
ShapeElement element;
LengthDbl expected_length;
};
class IrregularShapeElementLengthTest: public testing::TestWithParam<ShapeElementLengthTestParams> { };
TEST_P(IrregularShapeElementLengthTest, ShapeElementLength)
{
ShapeElementLengthTestParams test_params = GetParam();
EXPECT_TRUE(equal(test_params.element.length(), test_params.expected_length));
}
INSTANTIATE_TEST_SUITE_P(
Irregular,
IrregularShapeElementLengthTest,
testing::ValuesIn(std::vector<ShapeElementLengthTestParams>{
{build_shape({{0, 0}, {0, 1}}, true).elements.front(), 1 },
{build_shape({{1, 0}, {0, 0, 1}, {0, 1}}, true).elements.front(), M_PI / 2 },
{build_shape({{1, 0}, {0, 0, -1}, {0, -1}}, true).elements.front(), M_PI / 2 },
}));
struct CleanShapeTestParams
{
Shape shape;
Shape expected_shape;
};
class IrregularCleanShapeTest: public testing::TestWithParam<CleanShapeTestParams> { };
TEST_P(IrregularCleanShapeTest, CleanShape)
{
CleanShapeTestParams test_params = GetParam();
Shape cleaned_shape = clean_shape(test_params.shape);
std::cout << cleaned_shape.to_string(0) << std::endl;
EXPECT_EQ(test_params.expected_shape, cleaned_shape);
}
INSTANTIATE_TEST_SUITE_P(
Irregular,
IrregularCleanShapeTest,
testing::ValuesIn(std::vector<CleanShapeTestParams>{
{
build_shape({{0, 0}, {0, 0}, {100, 0}, {100, 100}}),
build_shape({{0, 0}, {100, 0}, {100, 100}})
}, {
build_shape({{50, 50}, {0, 0}, {100, 0}, {100, 100}}),
build_shape({{0, 0}, {100, 0}, {100, 100}})
}, {
build_shape({{0, 0}, {100, 0}, {100, 100}, {50, 50}}),
build_shape({{0, 0}, {100, 0}, {100, 100}})
}}));
struct ApproximateCircularArcByLineSegmentsTestParams
{
ShapeElement circular_arc;
ElementPos number_of_line_segments;
bool outer;
std::vector<ShapeElement> expected_line_segments;
};
class IrregularApproximateCircularArcByLineSegmentsTest: public testing::TestWithParam<ApproximateCircularArcByLineSegmentsTestParams> { };
TEST_P(IrregularApproximateCircularArcByLineSegmentsTest, ApproximateCircularArcByLineSegments)
{
ApproximateCircularArcByLineSegmentsTestParams test_params = GetParam();
std::cout << "circular_arc" << std::endl;
std::cout << test_params.circular_arc.to_string() << std::endl;
std::cout << "expected_line_segments" << std::endl;
for (const ShapeElement& line_segment: test_params.expected_line_segments)
std::cout << line_segment.to_string() << std::endl;
std::vector<ShapeElement> line_segments = approximate_circular_arc_by_line_segments(
test_params.circular_arc,
test_params.number_of_line_segments,
test_params.outer);
std::cout << "line_segments" << std::endl;
for (const ShapeElement& line_segment: line_segments)
std::cout << line_segment.to_string() << std::endl;
ASSERT_EQ(line_segments.size(), test_params.number_of_line_segments);
for (ElementPos pos = 0; pos < test_params.number_of_line_segments; ++pos) {
//std::cout << std::setprecision (15) << line_segments[pos].start.x << std::endl;
EXPECT_TRUE(equal(line_segments[pos], test_params.expected_line_segments[pos]));
}
}
INSTANTIATE_TEST_SUITE_P(
Irregular,
IrregularApproximateCircularArcByLineSegmentsTest,
testing::ValuesIn(std::vector<ApproximateCircularArcByLineSegmentsTestParams>{
{
build_shape({{1, 0}, {0, 0, 1}, {0, 1}}, true).elements.front(),
1,
false,
build_shape({{1, 0}, {0, 1}}, true).elements
}, {
build_shape({{1, 0}, {1, 1, -1}, {0, 1}}, true).elements.front(),
1,
true,
build_shape({{1, 0}, {0, 1}}, true).elements
}, {
build_shape({{1, 0}, {0, 0, 1}, {0, 1}}, true).elements.front(),
2,
true,
build_shape({{1, 0}, {1, 1}, {0, 1}}, true).elements
}, {
build_shape({{1, 0}, {1, 1, -1}, {0, 1}}, true).elements.front(),
2,
false,
build_shape({{1, 0}, {0, 0}, {0, 1}}, true).elements
}, {
build_shape({{1, 0}, {0, 0, 1}, {0, 1}}, true).elements.front(),
3,
true,
build_shape({{1, 0}, {1, 0.414213562373095}, {0.414213562373095, 1}, {0, 1}}, true).elements
}, {
build_shape({{1, 0}, {1, 1, -1}, {0, 1}}, true).elements.front(),
3,
false,
build_shape({{1, 0}, {0.585786437626905, 0}, {0, 0.585786437626905}, {0, 1}}, true).elements
}}));