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, see <https://www.gnu.org/licenses/>.
19
*/
20
21
#include <
qa_utils/wx_utils/unit_test_utils.h
>
22
23
#include <
geometry/shape_line_chain.h
>
24
#include <
geometry/shape_poly_set.h
>
25
26
#include "
fixtures_geometry.h
"
27
31
struct
IteratorFixture
32
{
33
// Structure to store the common data.
34
struct
KI_TEST::CommonTestData
common
;
35
36
// Polygons to test whether the RemoveNullSegments method works
37
SHAPE_POLY_SET
lastNullSegmentPolySet
;
38
SHAPE_POLY_SET
firstNullSegmentPolySet
;
39
SHAPE_POLY_SET
insideNullSegmentPolySet
;
40
41
// Null segments points
42
std::vector<VECTOR2I>
nullPoints
;
43
44
IteratorFixture
()
45
{
46
nullPoints
.emplace_back( 100, 100 );
47
nullPoints
.emplace_back( 0, 100 );
48
nullPoints
.emplace_back( 0, 0 );
49
50
// Create a polygon with its last segment null
51
SHAPE_LINE_CHAIN
polyLine;
52
polyLine.
Append
(
nullPoints
[0] );
53
polyLine.
Append
(
nullPoints
[1] );
54
polyLine.
Append
(
nullPoints
[2] );
55
polyLine.
Append
(
nullPoints
[2],
true
);
56
polyLine.
SetClosed
(
true
);
57
58
lastNullSegmentPolySet
.AddOutline( polyLine );
59
60
// Create a polygon with its first segment null
61
polyLine.
Clear
();
62
polyLine.
Append
(
nullPoints
[0] );
63
polyLine.
Append
(
nullPoints
[0],
true
);
64
polyLine.
Append
(
nullPoints
[1] );
65
polyLine.
Append
(
nullPoints
[2] );
66
polyLine.
SetClosed
(
true
);
67
68
firstNullSegmentPolySet
.AddOutline( polyLine );
69
70
// Create a polygon with an inside segment null
71
polyLine.
Clear
();
72
polyLine.
Append
(
nullPoints
[0] );
73
polyLine.
Append
(
nullPoints
[1] );
74
polyLine.
Append
(
nullPoints
[1],
true
);
75
polyLine.
Append
(
nullPoints
[2] );
76
polyLine.
SetClosed
(
true
);
77
78
insideNullSegmentPolySet
.AddOutline( polyLine );
79
}
80
81
~IteratorFixture
()
82
{
83
}
84
};
85
89
BOOST_FIXTURE_TEST_SUITE( PolygonIterator,
IteratorFixture
)
90
91
94
BOOST_AUTO_TEST_CASE
( VertexIterator )
95
{
96
SHAPE_POLY_SET::ITERATOR
iterator;
97
int
vertexIndex = 0;
98
99
for
( iterator = common.holeyPolySet.IterateWithHoles(); iterator; iterator++ )
100
{
101
BOOST_CHECK_EQUAL( common.holeyPoints[vertexIndex], *iterator );
102
vertexIndex++;
103
}
104
}
105
109
BOOST_AUTO_TEST_CASE
( SegmentIterator )
110
{
111
SHAPE_POLY_SET::SEGMENT_ITERATOR
iterator;
112
int
segmentIndex = 0;
113
114
for
( iterator = common.holeyPolySet.IterateSegmentsWithHoles(); iterator; iterator++ )
115
{
116
SEG
segment = *iterator;
117
118
BOOST_CHECK_EQUAL
( common.holeySegments[segmentIndex].A, segment.
A
);
119
BOOST_CHECK_EQUAL
( common.holeySegments[segmentIndex].B, segment.
B
);
120
121
segmentIndex++;
122
}
123
}
124
128
BOOST_AUTO_TEST_CASE
( EmptyPolygon )
129
{
130
SHAPE_POLY_SET::SEGMENT_ITERATOR
iterator;
131
132
for
( iterator = common.emptyPolySet.IterateSegmentsWithHoles(); iterator; iterator++ )
133
{
134
BOOST_FAIL(
"Empty set is being iterated!"
);
135
}
136
}
137
141
BOOST_AUTO_TEST_CASE
( UniqueVertex )
142
{
143
SHAPE_POLY_SET::SEGMENT_ITERATOR
iterator;
144
iterator = common.uniqueVertexPolySet.IterateSegmentsWithHoles();
145
146
SEG
segment = *iterator;
147
BOOST_CHECK_EQUAL
( segment.
A
, common.uniquePoints[0] );
148
BOOST_CHECK_EQUAL
( segment.
B
, common.uniquePoints[0] );
149
150
iterator++;
151
152
BOOST_CHECK( !iterator );
153
}
154
158
BOOST_AUTO_TEST_CASE
( TotalVertices )
159
{
160
BOOST_CHECK_EQUAL
( common.emptyPolySet.TotalVertices(), 0 );
161
BOOST_CHECK_EQUAL
( common.uniqueVertexPolySet.TotalVertices(), 1 );
162
BOOST_CHECK_EQUAL
( common.solidPolySet.TotalVertices(), 0 );
163
BOOST_CHECK_EQUAL
( common.holeyPolySet.TotalVertices(), 12 );
164
}
165
169
BOOST_AUTO_TEST_CASE
( RemoveNullSegments )
170
{
171
SHAPE_POLY_SET
polygonSets[3] = { lastNullSegmentPolySet, firstNullSegmentPolySet,
172
insideNullSegmentPolySet };
173
174
for
(
SHAPE_POLY_SET
polygonSet : polygonSets )
175
{
176
BOOST_CHECK_EQUAL
( polygonSet.TotalVertices(), 4 );
177
BOOST_CHECK_EQUAL
( polygonSet.RemoveNullSegments(), 1 );
178
BOOST_CHECK_EQUAL
( polygonSet.TotalVertices(), 3 );
179
180
BOOST_CHECK_EQUAL
( polygonSet.CVertex( 0 ), nullPoints[0] );
181
BOOST_CHECK_EQUAL
( polygonSet.CVertex( 1 ), nullPoints[1] );
182
BOOST_CHECK_EQUAL
( polygonSet.CVertex( 2 ), nullPoints[2] );
183
}
184
}
185
186
187
BOOST_AUTO_TEST_SUITE_END
()
SEG
Definition
seg.h:38
SEG::A
VECTOR2I A
Definition
seg.h:45
SEG::B
VECTOR2I B
Definition
seg.h:46
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:78
SHAPE_LINE_CHAIN::SetClosed
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
Definition
shape_line_chain.h:288
SHAPE_LINE_CHAIN::Clear
void Clear()
Remove all points from the line chain.
Definition
shape_line_chain.h:274
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:520
SHAPE_POLY_SET
Represent a set of closed polygons.
Definition
shape_poly_set.h:65
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:32
IteratorFixture::insideNullSegmentPolySet
SHAPE_POLY_SET insideNullSegmentPolySet
Definition
test_shape_poly_set_iterator.cpp:39
IteratorFixture::nullPoints
std::vector< VECTOR2I > nullPoints
Definition
test_shape_poly_set_iterator.cpp:42
IteratorFixture::lastNullSegmentPolySet
SHAPE_POLY_SET lastNullSegmentPolySet
Definition
test_shape_poly_set_iterator.cpp:37
IteratorFixture::~IteratorFixture
~IteratorFixture()
Definition
test_shape_poly_set_iterator.cpp:81
IteratorFixture::IteratorFixture
IteratorFixture()
Definition
test_shape_poly_set_iterator.cpp:44
IteratorFixture::firstNullSegmentPolySet
SHAPE_POLY_SET firstNullSegmentPolySet
Definition
test_shape_poly_set_iterator.cpp:38
IteratorFixture::common
struct KI_TEST::CommonTestData common
Definition
test_shape_poly_set_iterator.cpp:34
KI_TEST::CommonTestData
Common data for some of the SHAPE_POLY_SET tests:
Definition
fixtures_geometry.h:39
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
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:94
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 Fri Jun 26 2026 00:05:44 for KiCad PCB EDA Suite by
1.13.2