KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_shape_poly_set_iterator.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 (C) 2017 CERN
5
* @author Alejandro GarcĂa Montoro <
[email protected]
>
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, you may find one here:
19
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20
* or you may search the http://www.gnu.org website for the version 2 license,
21
* or you may write to the Free Software Foundation, Inc.,
22
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23
*/
24
25
#include <
qa_utils/wx_utils/unit_test_utils.h
>
26
27
#include <
geometry/shape_line_chain.h
>
28
#include <
geometry/shape_poly_set.h
>
29
30
#include "
fixtures_geometry.h
"
31
35
struct
IteratorFixture
36
{
37
// Structure to store the common data.
38
struct
KI_TEST::CommonTestData
common
;
39
40
// Polygons to test whether the RemoveNullSegments method works
41
SHAPE_POLY_SET
lastNullSegmentPolySet
;
42
SHAPE_POLY_SET
firstNullSegmentPolySet
;
43
SHAPE_POLY_SET
insideNullSegmentPolySet
;
44
45
// Null segments points
46
std::vector<VECTOR2I>
nullPoints
;
47
48
IteratorFixture
()
49
{
50
nullPoints
.emplace_back( 100, 100 );
51
nullPoints
.emplace_back( 0, 100 );
52
nullPoints
.emplace_back( 0, 0 );
53
54
// Create a polygon with its last segment null
55
SHAPE_LINE_CHAIN
polyLine;
56
polyLine.
Append
(
nullPoints
[0] );
57
polyLine.
Append
(
nullPoints
[1] );
58
polyLine.
Append
(
nullPoints
[2] );
59
polyLine.
Append
(
nullPoints
[2],
true
);
60
polyLine.
SetClosed
(
true
);
61
62
lastNullSegmentPolySet
.AddOutline( polyLine );
63
64
// Create a polygon with its first segment null
65
polyLine.
Clear
();
66
polyLine.
Append
(
nullPoints
[0] );
67
polyLine.
Append
(
nullPoints
[0],
true
);
68
polyLine.
Append
(
nullPoints
[1] );
69
polyLine.
Append
(
nullPoints
[2] );
70
polyLine.
SetClosed
(
true
);
71
72
firstNullSegmentPolySet
.AddOutline( polyLine );
73
74
// Create a polygon with an inside segment null
75
polyLine.
Clear
();
76
polyLine.
Append
(
nullPoints
[0] );
77
polyLine.
Append
(
nullPoints
[1] );
78
polyLine.
Append
(
nullPoints
[1],
true
);
79
polyLine.
Append
(
nullPoints
[2] );
80
polyLine.
SetClosed
(
true
);
81
82
insideNullSegmentPolySet
.AddOutline( polyLine );
83
}
84
85
~IteratorFixture
()
86
{
87
}
88
};
89
93
BOOST_FIXTURE_TEST_SUITE( PolygonIterator,
IteratorFixture
)
94
95
98
BOOST_AUTO_TEST_CASE
( VertexIterator )
99
{
100
SHAPE_POLY_SET::ITERATOR
iterator;
101
int
vertexIndex = 0;
102
103
for
( iterator = common.holeyPolySet.IterateWithHoles(); iterator; iterator++ )
104
{
105
BOOST_CHECK_EQUAL( common.holeyPoints[vertexIndex], *iterator );
106
vertexIndex++;
107
}
108
}
109
113
BOOST_AUTO_TEST_CASE
( SegmentIterator )
114
{
115
SHAPE_POLY_SET::SEGMENT_ITERATOR
iterator;
116
int
segmentIndex = 0;
117
118
for
( iterator = common.holeyPolySet.IterateSegmentsWithHoles(); iterator; iterator++ )
119
{
120
SEG
segment = *iterator;
121
122
BOOST_CHECK_EQUAL
( common.holeySegments[segmentIndex].A, segment.
A
);
123
BOOST_CHECK_EQUAL
( common.holeySegments[segmentIndex].B, segment.
B
);
124
125
segmentIndex++;
126
}
127
}
128
132
BOOST_AUTO_TEST_CASE
( EmptyPolygon )
133
{
134
SHAPE_POLY_SET::SEGMENT_ITERATOR
iterator;
135
136
for
( iterator = common.emptyPolySet.IterateSegmentsWithHoles(); iterator; iterator++ )
137
{
138
BOOST_FAIL(
"Empty set is being iterated!"
);
139
}
140
}
141
145
BOOST_AUTO_TEST_CASE
( UniqueVertex )
146
{
147
SHAPE_POLY_SET::SEGMENT_ITERATOR
iterator;
148
iterator = common.uniqueVertexPolySet.IterateSegmentsWithHoles();
149
150
SEG
segment = *iterator;
151
BOOST_CHECK_EQUAL
( segment.
A
, common.uniquePoints[0] );
152
BOOST_CHECK_EQUAL
( segment.
B
, common.uniquePoints[0] );
153
154
iterator++;
155
156
BOOST_CHECK( !iterator );
157
}
158
162
BOOST_AUTO_TEST_CASE
( TotalVertices )
163
{
164
BOOST_CHECK_EQUAL
( common.emptyPolySet.TotalVertices(), 0 );
165
BOOST_CHECK_EQUAL
( common.uniqueVertexPolySet.TotalVertices(), 1 );
166
BOOST_CHECK_EQUAL
( common.solidPolySet.TotalVertices(), 0 );
167
BOOST_CHECK_EQUAL
( common.holeyPolySet.TotalVertices(), 12 );
168
}
169
173
BOOST_AUTO_TEST_CASE
( RemoveNullSegments )
174
{
175
SHAPE_POLY_SET
polygonSets[3] = { lastNullSegmentPolySet, firstNullSegmentPolySet,
176
insideNullSegmentPolySet };
177
178
for
(
SHAPE_POLY_SET
polygonSet : polygonSets )
179
{
180
BOOST_CHECK_EQUAL
( polygonSet.TotalVertices(), 4 );
181
BOOST_CHECK_EQUAL
( polygonSet.RemoveNullSegments(), 1 );
182
BOOST_CHECK_EQUAL
( polygonSet.TotalVertices(), 3 );
183
184
BOOST_CHECK_EQUAL
( polygonSet.CVertex( 0 ), nullPoints[0] );
185
BOOST_CHECK_EQUAL
( polygonSet.CVertex( 1 ), nullPoints[1] );
186
BOOST_CHECK_EQUAL
( polygonSet.CVertex( 2 ), nullPoints[2] );
187
}
188
}
189
190
191
BOOST_AUTO_TEST_SUITE_END
()
SEG
Definition
seg.h:42
SEG::A
VECTOR2I A
Definition
seg.h:49
SEG::B
VECTOR2I B
Definition
seg.h:50
SHAPE_LINE_CHAIN
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Definition
shape_line_chain.h:82
SHAPE_LINE_CHAIN::SetClosed
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
Definition
shape_line_chain.h:292
SHAPE_LINE_CHAIN::Clear
void Clear()
Remove all points from the line chain.
Definition
shape_line_chain.h:278
SHAPE_LINE_CHAIN::Append
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Definition
shape_line_chain.h:524
SHAPE_POLY_SET
Represent a set of closed polygons.
Definition
shape_poly_set.h:68
SHAPE_POLY_SET::ITERATOR
ITERATOR_TEMPLATE< VECTOR2I > ITERATOR
Definition
shape_poly_set.h:515
SHAPE_POLY_SET::SEGMENT_ITERATOR
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
Definition
shape_poly_set.h:519
fixtures_geometry.h
shape_line_chain.h
shape_poly_set.h
IteratorFixture
Fixture for the Iterator test suite.
Definition
test_shape_poly_set_iterator.cpp:36
IteratorFixture::insideNullSegmentPolySet
SHAPE_POLY_SET insideNullSegmentPolySet
Definition
test_shape_poly_set_iterator.cpp:43
IteratorFixture::nullPoints
std::vector< VECTOR2I > nullPoints
Definition
test_shape_poly_set_iterator.cpp:46
IteratorFixture::lastNullSegmentPolySet
SHAPE_POLY_SET lastNullSegmentPolySet
Definition
test_shape_poly_set_iterator.cpp:41
IteratorFixture::~IteratorFixture
~IteratorFixture()
Definition
test_shape_poly_set_iterator.cpp:85
IteratorFixture::IteratorFixture
IteratorFixture()
Definition
test_shape_poly_set_iterator.cpp:48
IteratorFixture::firstNullSegmentPolySet
SHAPE_POLY_SET firstNullSegmentPolySet
Definition
test_shape_poly_set_iterator.cpp:42
IteratorFixture::common
struct KI_TEST::CommonTestData common
Definition
test_shape_poly_set_iterator.cpp:38
KI_TEST::CommonTestData
Common data for some of the SHAPE_POLY_SET tests:
Definition
fixtures_geometry.h:43
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:134
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(VertexIterator)
Declares the IteratorFixture as the boost test suite fixture.
Definition
test_shape_poly_set_iterator.cpp:98
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
libs
kimath
geometry
test_shape_poly_set_iterator.cpp
Generated on Sun Sep 21 2025 01:05:32 for KiCad PCB EDA Suite by
1.13.2