KiCad PCB EDA Suite
test_sch_rtree.cpp File Reference

Test suite for SCH_SHEET. More...

Go to the source code of this file.

Classes

class  TEST_SCH_RTREE_FIXTURE
 

Functions

 BOOST_AUTO_TEST_CASE (Default)
 Declare the test suite. More...
 
 BOOST_AUTO_TEST_CASE (Junctions)
 
 BOOST_AUTO_TEST_CASE (MixedElements)
 
 BOOST_AUTO_TEST_CASE (SingleElementTree)
 

Detailed Description

Test suite for SCH_SHEET.

Definition in file test_sch_rtree.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( Default  )

Declare the test suite.

Check default iterators

Definition at line 62 of file test_sch_rtree.cpp.

63{
64 BOOST_CHECK_EQUAL( m_tree.empty(), true );
65
66 int count = 0;
67 for( auto item : m_tree )
68 {
69 ignore_unused( item );
70 count++;
71 }
72
73 BOOST_CHECK_EQUAL( count, 0 );
74
75 for( int type = 0; type <= MAX_STRUCT_TYPE_ID; type++ )
76 {
77 count = 0;
78 for( auto item : m_tree.OfType( KICAD_T( type ) ) )
79 {
80 ignore_unused( item );
81 count++;
82 }
83
84 BOOST_CHECK_EQUAL( count, 0 );
85 }
86
87 EDA_RECT bbox;
88
89 for( int type = 0; type <= MAX_STRUCT_TYPE_ID; type++ )
90 {
91 count = 0;
92 for( auto item : m_tree.Overlapping( SCH_JUNCTION_T, bbox ) )
93 {
94 ignore_unused( item );
95 count++;
96 }
97
98 BOOST_CHECK_EQUAL( count, 0 );
99 }
100}
Handle the component boundary box.
Definition: eda_rect.h:44
void ignore_unused(const T &)
Definition: ignore.h:24
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ MAX_STRUCT_TYPE_ID
Definition: typeinfo.h:233
@ SCH_JUNCTION_T
Definition: typeinfo.h:133

References ignore_unused(), MAX_STRUCT_TYPE_ID, and SCH_JUNCTION_T.

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( Junctions  )

Definition at line 102 of file test_sch_rtree.cpp.

103{
104 for( int i = 0; i < 100; i++ )
105 {
106 SCH_JUNCTION* junction =
107 new SCH_JUNCTION( VECTOR2I( Mils2iu( 100 ) * i, Mils2iu( 100 ) * i ) );
108 m_tree.insert( junction );
109 }
110
111 int count = 0;
112
113 for( auto item : m_tree.OfType( SCH_JUNCTION_T ) )
114 {
115 ignore_unused( item );
116 count++;
117 }
118
119 BOOST_CHECK_EQUAL( count, 100 );
120
121 count = 0;
122 for( auto item : m_tree.OfType( SCH_NO_CONNECT_T ) )
123 {
124 ignore_unused( item );
125 count++;
126 }
127
128 BOOST_CHECK_EQUAL( count, 0 );
129
130 EDA_RECT small_bbox( VECTOR2I( -1, -1 ), VECTOR2I( Mils2iu( 2 ), Mils2iu( 2 ) ) );
131 EDA_RECT med_bbox( VECTOR2I( 0, 0 ), VECTOR2I( Mils2iu( 100 ), Mils2iu( 100 ) ) );
132 EDA_RECT big_bbox( VECTOR2I( 0, 0 ), VECTOR2I( Mils2iu( 5000 ), Mils2iu( 5000 ) ) );
133
134 count = 0;
135 for( auto item : m_tree.Overlapping( small_bbox ) )
136 {
137 BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
138 count++;
139 }
140
141 BOOST_CHECK_EQUAL( count, 1 );
142
143 count = 0;
144 for( auto item : m_tree.Overlapping( SCH_JUNCTION_T, small_bbox ) )
145 {
146 BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
147 count++;
148 }
149
150 BOOST_CHECK_EQUAL( count, 1 );
151
152 count = 0;
153 for( auto item : m_tree.Overlapping( SCH_NO_CONNECT_T, small_bbox ) )
154 {
155 BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
156 count++;
157 }
158
159 BOOST_CHECK_EQUAL( count, 0 );
160
161 count = 0;
162 for( auto item : m_tree.Overlapping( med_bbox ) )
163 {
164 BOOST_CHECK( med_bbox.Intersects( item->GetBoundingBox() ) );
165 count++;
166 }
167
168 BOOST_CHECK_EQUAL( count, 2 );
169
170 count = 0;
171 for( auto item : m_tree.Overlapping( big_bbox ) )
172 {
173 BOOST_CHECK( big_bbox.Intersects( item->GetBoundingBox() ) );
174 count++;
175 }
176
177 BOOST_CHECK_EQUAL( count, 51 );
178
179 for( SCH_ITEM* item : m_tree )
180 delete item;
181}
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:145
BOOST_CHECK(v2.Cross(v1)==1)
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:134
VECTOR2< int > VECTOR2I
Definition: vector2d.h:607

References BOOST_CHECK(), ignore_unused(), EDA_RECT::Intersects(), SCH_JUNCTION_T, and SCH_NO_CONNECT_T.

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( MixedElements  )

Definition at line 183 of file test_sch_rtree.cpp.

184{
185 for( int i = 0; i < 100; i++ )
186 {
187 int x_sign = ( i % 2 == 0 ) ? -1 : 1;
188 int y_sign = ( i % 3 == 0 ) ? -1 : 1;
189
190 SCH_JUNCTION* junction = new SCH_JUNCTION(
191 VECTOR2I( Mils2iu( 100 ) * i * x_sign, Mils2iu( 100 ) * i * y_sign ) );
192 m_tree.insert( junction );
193
195 VECTOR2I( Mils2iu( 150 ) * i * y_sign, Mils2iu( 150 ) * i * x_sign ) );
196 m_tree.insert( nc );
197 }
198
199 int count = 0;
200
201 for( auto item : m_tree.OfType( SCH_JUNCTION_T ) )
202 {
203 ignore_unused( item );
204 count++;
205 }
206
207 BOOST_CHECK_EQUAL( count, 100 );
208
209 count = 0;
210 for( auto item : m_tree.OfType( SCH_NO_CONNECT_T ) )
211 {
212 ignore_unused( item );
213 count++;
214 }
215
216 BOOST_CHECK_EQUAL( count, 100 );
217
218 EDA_RECT small_bbox( VECTOR2I( -1, -1 ), VECTOR2I( Mils2iu( 2 ), Mils2iu( 2 ) ) );
219
220 count = 0;
221 for( auto item : m_tree.Overlapping( small_bbox ) )
222 {
223 BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
224 count++;
225 }
226
227 BOOST_CHECK_EQUAL( count, 2 );
228
229 count = 0;
230 for( auto item : m_tree.Overlapping( SCH_JUNCTION_T, small_bbox ) )
231 {
232 BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
233 count++;
234 }
235
236 BOOST_CHECK_EQUAL( count, 1 );
237
238 count = 0;
239 for( auto item : m_tree.Overlapping( SCH_NO_CONNECT_T, small_bbox ) )
240 {
241 BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
242 count++;
243 }
244
245 BOOST_CHECK_EQUAL( count, 1 );
246
247 for( SCH_ITEM* item : m_tree )
248 delete item;
249}

References BOOST_CHECK(), ignore_unused(), EDA_RECT::Intersects(), SCH_JUNCTION_T, and SCH_NO_CONNECT_T.

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( SingleElementTree  )

Definition at line 253 of file test_sch_rtree.cpp.

254{
255 SCH_JUNCTION* junction = new SCH_JUNCTION( VECTOR2I( Mils2iu( 100 ), Mils2iu( 100 ) ) );
256 m_tree.insert( junction );
257
258 SCH_NO_CONNECT* nc = new SCH_NO_CONNECT( VECTOR2I( Mils2iu( 150 ), Mils2iu( 150 ) ) );
259 m_tree.insert( nc );
260
261 int count = 0;
262
263 for( auto item : m_tree.OfType( SCH_JUNCTION_T ) )
264 {
265 ignore_unused( item );
266 count++;
267 }
268
269 BOOST_CHECK_EQUAL( count, 1 );
270
271 count = 0;
272 for( auto item : m_tree.OfType( SCH_NO_CONNECT_T ) )
273 {
274 ignore_unused( item );
275 count++;
276 }
277
278 BOOST_CHECK_EQUAL( count, 1 );
279
280 for( SCH_ITEM* item : m_tree )
281 delete item;
282}

References ignore_unused(), SCH_JUNCTION_T, and SCH_NO_CONNECT_T.