KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_oval.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <geometry/oval.h>
23
24#include "geom_test_utils.h"
25
36template <typename T>
38
39 for( const auto& p : expected )
40 {
41 BOOST_CHECK_MESSAGE( std::find( actual.begin(), actual.end(), p ) != actual.end(),
42 "Expected item not found: " << p );
43 }
44
45 for( const auto& p : actual )
46 {
47 BOOST_CHECK_MESSAGE( std::find( expected.begin(), expected.end(), p ) != expected.end(),
48 "Unexpected item: " << p );
49 }
50
51 BOOST_CHECK_EQUAL( expected.size(), actual.size() );
52}
53
55
57{
59 std::vector<TYPED_POINT2I> m_expected_points;
60};
61
63{
64 const auto sort_vectors_x_then_y = []( const VECTOR2I& a, const VECTOR2I& b ) {
66 };
67
68 std::vector<TYPED_POINT2I> expected_points = testcase.m_expected_points;
69
70 std::vector<TYPED_POINT2I> actual_points =
72
73 CHECK_COLLECTIONS_SAME_UNORDERED( expected_points, actual_points );
74}
75
76BOOST_AUTO_TEST_CASE( SimpleOvalVertical )
77{
78 const OVAL_POINTS_TEST_CASE testcase
79 {
80 {
81 SEG{ { 0, -1000 }, { 0, 1000 } },
82 1000,
83 },
84 {
85 { { 0, 0 }, PT_CENTER },
86 // Main points
87 { { 0, 1500 }, PT_QUADRANT },
88 { { 0, -1500 }, PT_QUADRANT },
89 { { 500, 0 }, PT_MID },
90 { { -500, 0 }, PT_MID },
91 // Cap centres
92 { { 0, 1000 }, PT_CENTER },
93 { { 0, -1000 }, PT_CENTER },
94 // Side segment ends
95 { { 500, 1000 }, PT_END },
96 { { 500, -1000 }, PT_END },
97 { { -500, 1000 }, PT_END },
98 { { -500, -1000 }, PT_END },
99 // No quadrants
100 },
101 };
102
103 DoOvalPointTestChecks( testcase );
104}
105
106BOOST_AUTO_TEST_CASE( SimpleOvalHorizontal )
107{
108 const OVAL_POINTS_TEST_CASE testcase
109 {
110 {
111 SEG{ { -1000, 0 }, { 1000, 0 } },
112 1000,
113 },
114 {
115 { { 0, 0 }, PT_CENTER },
116 // Main points
117 { { 0, 500 }, PT_MID },
118 { { 0, -500 }, PT_MID },
119 { { 1500, 0 }, PT_QUADRANT },
120 { { -1500, 0 }, PT_QUADRANT },
121 // Cap centres
122 { { 1000, 0 }, PT_CENTER },
123 { { -1000, 0 }, PT_CENTER },
124 // Side segment ends
125 { { 1000, 500 }, PT_END },
126 { { 1000, -500 }, PT_END },
127 { { -1000, 500 }, PT_END },
128 { { -1000, -500 }, PT_END },
129 // No quadrants
130 },
131 };
132
133 DoOvalPointTestChecks( testcase );
134}
135
136BOOST_AUTO_TEST_CASE( SimpleOval45Degrees )
137{
138 // In this case, it's useful to keep in mind the hypotenuse of
139 // isoceles right-angled triangles is sqrt(2) times the length of the sides
140 // 500 / sqrt(2) = 354
141 // 1000 / sqrt(2) = 707
142 // 1500 / sqrt(2) = 1061
143 // 2000 / sqrt(2) = 1414
144
145 const OVAL_POINTS_TEST_CASE testcase
146 {
147 {
148 SEG{ GetRotated( { -1500, 0 }, ANGLE_45 ), GetRotated( { 1500, 0 }, ANGLE_45 ) },
149 1000,
150 },
151 {
152 { { 0, 0 }, PT_CENTER },
153 // Main points
154 { { 1414, -1414 }, PT_END },
155 { { -1414, 1414 }, PT_END },
156 { { 354, 354 }, PT_MID },
157 { { -354, -354 }, PT_MID },
158 // Side segment ends
159 { { -1414, 707 }, PT_END },
160 { { 1414, -707 }, PT_END },
161 { { -707, 1414 }, PT_END },
162 { { 707, -1414 }, PT_END },
163 // Cap centres
164 { { 1061, -1061 }, PT_CENTER },
165 { { -1061, 1061 }, PT_CENTER },
166 // Extremum points (always one of NSEW of a cap centre because 45 degrees)
167 { { -1061 - 500, 1061 }, PT_QUADRANT },
168 { { -1061, 1061 + 500 }, PT_QUADRANT },
169 { { 1061 + 500, -1061 }, PT_QUADRANT },
170 { { 1061, -1061 - 500 }, PT_QUADRANT },
171 },
172 };
173
174 DoOvalPointTestChecks( testcase );
175}
176
Definition seg.h:38
static constexpr EDA_ANGLE ANGLE_45
Definition eda_angle.h:412
std::vector< TYPED_POINT2I > GetOvalKeyPoints(const SHAPE_SEGMENT &aOval, OVAL_KEY_POINT_FLAGS aFlags)
Get a list of interesting points on an oval (rectangle with semicircular end caps)
Definition oval.cpp:46
@ OVAL_ALL_KEY_POINTS
Definition oval.h:50
@ PT_CENTER
The point is the center of something.
Definition point_types.h:42
@ PT_QUADRANT
The point is on a quadrant of a circle (N, E, S, W points).
Definition point_types.h:54
@ PT_END
The point is at the end of a segment, arc, etc.
Definition point_types.h:46
@ PT_MID
The point is at the middle of a segment, arc, etc.
Definition point_types.h:50
std::vector< TYPED_POINT2I > m_expected_points
Definition test_oval.cpp:59
SHAPE_SEGMENT m_oval
Definition test_oval.cpp:58
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
void CHECK_COLLECTIONS_SAME_UNORDERED(const T &expected, const T &actual)
Check that two collections contain the same elements, ignoring order.
Definition test_oval.cpp:37
BOOST_AUTO_TEST_CASE(SimpleOvalVertical)
Definition test_oval.cpp:76
void DoOvalPointTestChecks(const OVAL_POINTS_TEST_CASE &testcase)
Definition test_oval.cpp:62
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
int actual
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2I GetRotated(const VECTOR2I &aVector, const EDA_ANGLE &aAngle)
Return a new VECTOR2I that is the result of rotating aVector by aAngle.
Definition trigo.h:73
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
constexpr int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition vector2d.h:632