KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_rtree.h
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 * Copyright (C) 2020 CERN
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 3
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#ifndef DRC_RTREE_H_
22#define DRC_RTREE_H_
23
24#include <board_item.h>
25#include <pcb_field.h>
26#include <algorithm>
27#include <memory>
28#include <unordered_set>
29#include <set>
30#include <vector>
31
33#include <geometry/shape.h>
35#include <math/vector2d.h>
36#include "geometry/shape_null.h"
37#include "board.h"
38
39#define ATOMIC_TABLES true
40
46{
47public:
49 {
50 ITEM_WITH_SHAPE( BOARD_ITEM *aParent, const SHAPE* aShape,
51 std::shared_ptr<SHAPE> aParentShape ) :
52 parent( aParent ),
53 shape( aShape ),
54 shapeStorage( nullptr ),
55 parentShape( std::move( aParentShape ) )
56 {};
57
58 ITEM_WITH_SHAPE( BOARD_ITEM *aParent, const std::shared_ptr<SHAPE>& aShape,
59 std::shared_ptr<SHAPE> aParentShape ) :
60 parent( aParent ),
61 shape( aShape.get() ),
62 shapeStorage( aShape ),
63 parentShape( std::move( aParentShape ) )
64 {};
65
67 const SHAPE* shape;
68 std::shared_ptr<SHAPE> shapeStorage;
69
71 std::shared_ptr<SHAPE> parentShape;
72 };
73
74private:
76 using drc_rtree_builder = typename drc_rtree::Builder;
77
78public:
80 {
81 m_count = 0;
82 }
83
85 {
86 for( ITEM_WITH_SHAPE* p : m_owned )
87 delete p;
88 }
89
94 void Insert( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, DRC_CONSTRAINT_T aConstraintType,
95 int aWorstClearance = 0, bool aAtomicTables = false )
96 {
97 Insert( aItem, aLayer, aLayer, aConstraintType, aWorstClearance, aAtomicTables );
98 }
99
104 void Insert( BOARD_ITEM* aItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer,
105 DRC_CONSTRAINT_T aConstraintType, int aWorstClearance, bool aAtomicTables = false )
106 {
107 wxCHECK( aTargetLayer != UNDEFINED_LAYER, /* void */ );
108 wxCHECK_MSG( !m_tree.count( aTargetLayer ), /* void */, wxT( "Insert after Build() is silently wrong" ) );
109
110 if( aItem->Type() == PCB_FIELD_T && !static_cast<PCB_FIELD*>( aItem )->IsVisible() )
111 return;
112
113 BOARD_ITEM* parent = aItem;
114
115 if( aAtomicTables && aItem->Type() == PCB_TABLECELL_T )
116 parent = aItem->GetParent();
117
118 std::vector<const SHAPE*> subshapes;
119 std::shared_ptr<SHAPE> shape = aItem->GetEffectiveShape( aRefLayer, FLASHING::DEFAULT, aConstraintType );
120
121 wxCHECK2_MSG( shape, return, wxT( "Item does not have a valid shape for this layer" ) );
122
123 if( shape->HasIndexableSubshapes() )
124 shape->GetIndexableSubshapes( subshapes );
125 else
126 subshapes.push_back( shape.get() );
127
128 for( const SHAPE* subshape : subshapes )
129 {
130 if( dynamic_cast<const SHAPE_NULL*>( subshape ) )
131 continue;
132
133 BOX2I bbox = subshape->BBox();
134
135 bbox.Inflate( aWorstClearance );
136
137 const int mmin[2] = { bbox.GetX(), bbox.GetY() };
138 const int mmax[2] = { bbox.GetRight(), bbox.GetBottom() };
139 ITEM_WITH_SHAPE* itemShape = new ITEM_WITH_SHAPE( parent, subshape, shape );
140
141 m_owned.push_back( itemShape );
142 m_builders[aTargetLayer].Add( mmin, mmax, itemShape );
143 recordPadding( aTargetLayer, aWorstClearance );
144 m_count++;
145 }
146
147 if( aItem->Type() == PCB_PAD_T && aItem->HasHole() )
148 {
149 std::shared_ptr<SHAPE_SEGMENT> hole = aItem->GetEffectiveHoleShape();
150 BOX2I bbox = hole->BBox();
151
152 bbox.Inflate( aWorstClearance );
153
154 const int mmin[2] = { bbox.GetX(), bbox.GetY() };
155 const int mmax[2] = { bbox.GetRight(), bbox.GetBottom() };
156 ITEM_WITH_SHAPE* itemShape = new ITEM_WITH_SHAPE( parent, hole, shape );
157
158 m_owned.push_back( itemShape );
159 m_builders[aTargetLayer].Add( mmin, mmax, itemShape );
160 recordPadding( aTargetLayer, aWorstClearance );
161 m_count++;
162 }
163 }
164
169 void Build()
170 {
171 for( auto& [layer, builder] : m_builders )
172 m_tree[layer] = builder.Build();
173
174 m_builders.clear();
175 }
176
180 void clear()
181 {
182 for( ITEM_WITH_SHAPE* p : m_owned )
183 delete p;
184
185 m_owned.clear();
186 m_tree.clear();
187 m_builders.clear();
188 m_minPadding.clear();
189 m_count = 0;
190 }
191
192 bool CheckColliding( SHAPE* aRefShape, PCB_LAYER_ID aTargetLayer, int aClearance = 0,
193 std::function<bool( BOARD_ITEM*)> aFilter = nullptr ) const
194 {
195 BOX2I box = aRefShape->BBox();
196 box.Inflate( aClearance );
197
198 int min[2] = { box.GetX(), box.GetY() };
199 int max[2] = { box.GetRight(), box.GetBottom() };
200
201 int count = 0;
202
203 auto visit =
204 [&] ( ITEM_WITH_SHAPE* aItem ) -> bool
205 {
206 if( !aFilter || aFilter( aItem->parent ) )
207 {
208 int actual;
209
210 if( aRefShape->Collide( aItem->shape, aClearance, &actual ) )
211 {
212 count++;
213 return false;
214 }
215 }
216
217 return true;
218 };
219
220 if( auto it = m_tree.find( aTargetLayer ); it != m_tree.end() )
221 it->second.Search( min, max, visit );
222
223 return count > 0;
224 }
225
231 int QueryColliding( BOARD_ITEM* aRefItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer,
232 std::function<bool( BOARD_ITEM* )> aFilter = nullptr,
233 std::function<bool( BOARD_ITEM* )> aVisitor = nullptr,
234 int aClearance = 0 ) const
235 {
236 // keep track of BOARD_ITEMs that have already been found to collide (some items might
237 // be built of COMPOUND/triangulated shapes and a single subshape collision means we have
238 // a hit)
239 std::unordered_set<BOARD_ITEM*> collidingCompounds;
240
241 // keep track of results of client filter so we don't ask more than once for compound
242 // shapes
243 std::unordered_map<BOARD_ITEM*, bool> filterResults;
244
245 std::shared_ptr<SHAPE> refShape = aRefItem->GetEffectiveShape( aRefLayer );
246
247 // A mask aperture reaches past the item's copper bounding box, so cover both
248 BOX2I box = aRefItem->GetBoundingBox();
249 box.Merge( refShape->BBox() );
250 box.Inflate( aClearance );
251
252 int min[2] = { box.GetX(), box.GetY() };
253 int max[2] = { box.GetRight(), box.GetBottom() };
254
255 int count = 0;
256
257 auto visit =
258 [&]( ITEM_WITH_SHAPE* aItem ) -> bool
259 {
260 if( aItem->parent == aRefItem )
261 return true;
262
263 if( collidingCompounds.find( aItem->parent ) != collidingCompounds.end() )
264 return true;
265
266 bool filtered;
267 auto it = filterResults.find( aItem->parent );
268
269 if( it == filterResults.end() )
270 {
271 filtered = aFilter && !aFilter( aItem->parent );
272 filterResults[ aItem->parent ] = filtered;
273 }
274 else
275 {
276 filtered = it->second;
277 }
278
279 if( filtered )
280 return true;
281
282 wxCHECK( aItem->shape, false );
283
284 if( refShape->Collide( aItem->shape, aClearance ) )
285 {
286 collidingCompounds.insert( aItem->parent );
287 count++;
288
289 if( aVisitor )
290 return aVisitor( aItem->parent );
291 }
292
293 return true;
294 };
295
296 if( auto it = m_tree.find( aTargetLayer ); it != m_tree.end() )
297 it->second.Search( min, max, visit );
298
299 return count;
300 }
301
313 BOARD_ITEM* aRefItem, const std::shared_ptr<SHAPE>& aRefShape,
314 PCB_LAYER_ID aTargetLayer, std::function<bool( BOARD_ITEM* )> aFilter,
315 std::function<bool( BOARD_ITEM*, const std::shared_ptr<SHAPE>& )> aVisitor,
316 int aClearance = 0, bool aUsePaddingCredit = false ) const
317 {
318 // PAD::GetEffectiveShape() returns null when a layer has no cached shape
319 wxCHECK( aRefShape, 0 );
320
321 std::unordered_set<BOARD_ITEM*> collidingCompounds;
322 std::unordered_map<BOARD_ITEM*, bool> filterResults;
323 BOX2I box = aRefItem->GetBoundingBox();
324 int inflation = aClearance;
325
326 if( aUsePaddingCredit && aClearance >= 0 )
327 {
328 // Checked before the box grows, because the credit can leave inflation at 0. A
329 // reference whose bounds do not contain its own shape would shrink the query past a
330 // real candidate and silently drop a clearance violation, so it pays full inflation
331 // instead of getting a wrong answer in a release build
332 bool contained = box.Contains( aRefShape->BBox() );
333
334 wxASSERT_MSG( contained, wxT( "Padding credit needs the item bbox to contain its own shape" ) );
335
336 auto paddingIt = m_minPadding.find( aTargetLayer );
337
338 if( contained && paddingIt != m_minPadding.end() && paddingIt->second >= 0 )
339 inflation = std::max( 0, aClearance - paddingIt->second );
340 }
341
342 box.Inflate( inflation );
343
344 int min[2] = { box.GetX(), box.GetY() };
345 int max[2] = { box.GetRight(), box.GetBottom() };
346 int count = 0;
347
348 auto visit =
349 [&]( ITEM_WITH_SHAPE* aItem ) -> bool
350 {
351 if( aItem->parent == aRefItem
352 || collidingCompounds.find( aItem->parent ) != collidingCompounds.end() )
353 {
354 return true;
355 }
356
357 auto [filterIt, inserted] = filterResults.emplace( aItem->parent, false );
358
359 if( inserted )
360 filterIt->second = aFilter && !aFilter( aItem->parent );
361
362 if( filterIt->second )
363 return true;
364
365 wxCHECK( aItem->shape, false );
366
367 if( aRefShape->Collide( aItem->shape, aClearance ) )
368 {
369 collidingCompounds.insert( aItem->parent );
370 count++;
371
372 if( aVisitor )
373 return aVisitor( aItem->parent, aItem->parentShape );
374 }
375
376 return true;
377 };
378
379 if( auto it = m_tree.find( aTargetLayer ); it != m_tree.end() )
380 it->second.Search( min, max, visit );
381
382 return count;
383 }
384
391 bool QueryColliding( const BOX2I& aBox, SHAPE* aRefShape, PCB_LAYER_ID aLayer, int aClearance,
392 int* aActual, VECTOR2I* aPos ) const
393 {
394 BOX2I bbox = aBox;
395 bbox.Inflate( aClearance );
396
397 int min[2] = { bbox.GetX(), bbox.GetY() };
398 int max[2] = { bbox.GetRight(), bbox.GetBottom() };
399
400 bool collision = false;
401 int actual = INT_MAX;
402 VECTOR2I pos;
403
404 auto visit =
405 [&]( ITEM_WITH_SHAPE* aItem ) -> bool
406 {
407 int curActual;
408 VECTOR2I curPos;
409
410 if( aRefShape->Collide( aItem->shape, aClearance, &curActual, &curPos ) )
411 {
412 collision = true;
413
414 if( curActual < actual )
415 {
416 actual = curActual;
417 pos = curPos;
418 }
419
420 // Stop looking after we have a true collision
421 if( actual <= 0 )
422 return false;
423 }
424
425 return true;
426 };
427
428 if( auto it = m_tree.find( aLayer ); it != m_tree.end() )
429 it->second.Search( min, max, visit );
430
431 if( collision )
432 {
433 if( aActual )
434 *aActual = std::max( 0, actual );
435
436 if( aPos )
437 *aPos = pos;
438
439 return true;
440 }
441
442 return false;
443 }
444
448 bool QueryColliding( const BOX2I& aBox, SHAPE* aRefShape, PCB_LAYER_ID aLayer ) const
449 {
450 SHAPE_POLY_SET* poly = dynamic_cast<SHAPE_POLY_SET*>( aRefShape );
451
452 int min[2] = { aBox.GetX(), aBox.GetY() };
453 int max[2] = { aBox.GetRight(), aBox.GetBottom() };
454 bool collision = false;
455
456 // Special case the polygon case. Otherwise we'll call its Collide() method which will
457 // triangulate it as well and then do triangle/triangle collisions. This ends up being
458 // *much* slower than 3 segment Collide()s and a PointInside().
459 auto polyVisitor =
460 [&]( ITEM_WITH_SHAPE* aItem ) -> bool
461 {
462 const SHAPE* shape = aItem->shape;
463
464 // There are certain degenerate cases that result in empty zone fills, which
465 // will be represented in the rtree with only a root (and no triangles).
466 // https://gitlab.com/kicad/code/kicad/-/issues/18600
467 if( shape->Type() != SH_POLY_SET_TRIANGLE )
468 return true;
469
470 auto tri = static_cast<const SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI*>( shape );
471
472 const SHAPE_LINE_CHAIN& outline = poly->Outline( 0 );
473
474 for( int ii = 0; ii < (int) tri->GetSegmentCount(); ++ii )
475 {
476 if( outline.Collide( tri->GetSegment( ii ) ) )
477 {
478 collision = true;
479 return false;
480 }
481 }
482
483 // Also must check for poly being completely inside the triangle
484 if( tri->PointInside( outline.CPoint( 0 ) ) )
485 {
486 collision = true;
487 return false;
488 }
489
490 return true;
491 };
492
493 auto visitor =
494 [&]( ITEM_WITH_SHAPE* aItem ) -> bool
495 {
496 if( aRefShape->Collide( aItem->shape, 0 ) )
497 {
498 collision = true;
499 return false;
500 }
501
502 return true;
503 };
504
505 auto it = m_tree.find( aLayer );
506
507 if( it == m_tree.end() )
508 return false;
509
510 if( poly && poly->OutlineCount() == 1 && poly->HoleCount( 0 ) == 0 )
511 it->second.Search( min, max, polyVisitor );
512 else
513 it->second.Search( min, max, visitor );
514
515 return collision;
516 }
517
526 std::unordered_set<BOARD_ITEM*> GetObjectsAt( const VECTOR2I& aPt, PCB_LAYER_ID aLayer,
527 int aClearance = 0 )
528 {
529 std::unordered_set<BOARD_ITEM*> retval;
530 int min[2] = { aPt.x - aClearance, aPt.y - aClearance };
531 int max[2] = { aPt.x + aClearance, aPt.y + aClearance };
532
533 auto visitor =
534 [&]( ITEM_WITH_SHAPE* aItem ) -> bool
535 {
536 retval.insert( aItem->parent );
537 return true;
538 };
539
540 auto it = m_tree.find( aLayer );
541
542 if( it != m_tree.end() )
543 it->second.Search( min, max, visitor );
544
545 return retval;
546 }
547
548 typedef std::pair<PCB_LAYER_ID, PCB_LAYER_ID> LAYER_PAIR;
549
551 {
553 layerPair( aPair ),
554 refItem( aRef ),
555 testItem( aTest )
556 { };
557
561 };
562
563 int QueryCollidingPairs( DRC_RTREE* aRefTree, std::vector<LAYER_PAIR> aLayerPairs,
564 std::function<bool( const LAYER_PAIR&, ITEM_WITH_SHAPE*,
565 ITEM_WITH_SHAPE*, bool* aCollision )> aVisitor,
566 int aMaxClearance,
567 std::function<bool(int, int )> aProgressReporter ) const
568 {
569 std::vector<PAIR_INFO> pairsToVisit;
570
571 for( LAYER_PAIR& layerPair : aLayerPairs )
572 {
573 const PCB_LAYER_ID refLayer = layerPair.first;
574 const PCB_LAYER_ID targetLayer = layerPair.second;
575
576 for( ITEM_WITH_SHAPE* refItem : aRefTree->OnLayer( refLayer ) )
577 {
578 BOX2I box = refItem->shape->BBox();
579 box.Inflate( aMaxClearance );
580
581 int min[2] = { box.GetX(), box.GetY() };
582 int max[2] = { box.GetRight(), box.GetBottom() };
583
584 auto visit =
585 [&]( ITEM_WITH_SHAPE* aItemToTest ) -> bool
586 {
587 // don't collide items against themselves
588 if( aItemToTest->parent == refItem->parent )
589 return true;
590
591 pairsToVisit.emplace_back( layerPair, refItem, aItemToTest );
592 return true;
593 };
594
595 auto it = m_tree.find( targetLayer );
596
597 if( it != m_tree.end() )
598 it->second.Search( min, max, visit );
599 };
600 }
601
602 // keep track of BOARD_ITEMs pairs that have been already found to collide (some items
603 // might be build of COMPOUND/triangulated shapes and a single subshape collision
604 // means we have a hit)
605 std::unordered_map<PTR_PTR_CACHE_KEY, int> collidingCompounds;
606
607 int progress = 0;
608 int count = pairsToVisit.size();
609
610 for( const PAIR_INFO& pair : pairsToVisit )
611 {
612 if( !aProgressReporter( progress++, count ) )
613 break;
614
615 BOARD_ITEM* a = pair.refItem->parent;
616 BOARD_ITEM* b = pair.testItem->parent;
617
618 // store canonical order so we don't collide in both directions (a:b and b:a)
619 if( static_cast<void*>( a ) > static_cast<void*>( b ) )
620 std::swap( a, b );
621
622 // don't report multiple collisions for compound or triangulated shapes
623 if( collidingCompounds.count( { a, b } ) )
624 continue;
625
626 bool collisionDetected = false;
627
628 if( !aVisitor( pair.layerPair, pair.refItem, pair.testItem, &collisionDetected ) )
629 break;
630
631 if( collisionDetected )
632 collidingCompounds[ { a, b } ] = 1;
633 }
634
635 return 0;
636 }
637
643 size_t size() const
644 {
645 return m_count;
646 }
647
648 bool empty() const
649 {
650 return m_count == 0;
651 }
652
662 {
663 DRC_LAYER() = default;
664
665 DRC_LAYER( const drc_rtree& aTree )
666 {
667 for( ITEM_WITH_SHAPE* item : aTree )
668 m_items.push_back( item );
669 }
670
671 DRC_LAYER( const drc_rtree& aTree, const BOX2I& aRect )
672 {
673 int min[2] = { aRect.GetX(), aRect.GetY() };
674 int max[2] = { aRect.GetRight(), aRect.GetBottom() };
675
676 auto collector = [this]( ITEM_WITH_SHAPE* aItem ) -> bool
677 {
678 m_items.push_back( aItem );
679 return true;
680 };
681
682 aTree.Search( min, max, collector );
683 }
684
685 std::vector<ITEM_WITH_SHAPE*> m_items;
686
687 std::vector<ITEM_WITH_SHAPE*>::iterator begin() { return m_items.begin(); }
688 std::vector<ITEM_WITH_SHAPE*>::iterator end() { return m_items.end(); }
689 };
690
692 {
693 auto it = m_tree.find( aLayer );
694 return it == m_tree.end() ? DRC_LAYER() : DRC_LAYER( it->second );
695 }
696
697 DRC_LAYER Overlapping( PCB_LAYER_ID aLayer, const VECTOR2I& aPoint, int aAccuracy = 0 ) const
698 {
699 BOX2I rect( aPoint, VECTOR2I( 0, 0 ) );
700 rect.Inflate( aAccuracy );
701 auto it = m_tree.find( aLayer );
702 return it == m_tree.end() ? DRC_LAYER() : DRC_LAYER( it->second, rect );
703 }
704
705 DRC_LAYER Overlapping( PCB_LAYER_ID aLayer, const BOX2I& aRect ) const
706 {
707 auto it = m_tree.find( aLayer );
708 return it == m_tree.end() ? DRC_LAYER() : DRC_LAYER( it->second, aRect );
709 }
710
711
712private:
713 void recordPadding( PCB_LAYER_ID aLayer, int aPadding )
714 {
715 auto [it, inserted] = m_minPadding.emplace( aLayer, aPadding );
716
717 if( !inserted )
718 it->second = std::min( it->second, aPadding );
719 }
720
721 std::map<int, drc_rtree> m_tree;
722 std::map<int, drc_rtree_builder> m_builders;
723 std::map<int, int> m_minPadding;
724 std::vector<ITEM_WITH_SHAPE*> m_owned;
725 size_t m_count = 0;
726};
727
728
729#endif /* DRC_RTREE_H_ */
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:267
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
virtual bool HasHole() const
Definition board_item.h:208
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:553
constexpr coord_type GetY() const
Definition box2.h:205
constexpr coord_type GetX() const
Definition box2.h:204
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:594
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:165
constexpr coord_type GetRight() const
Definition box2.h:214
constexpr coord_type GetBottom() const
Definition box2.h:219
std::map< int, int > m_minPadding
Definition drc_rtree.h:723
DRC_LAYER OnLayer(PCB_LAYER_ID aLayer) const
Definition drc_rtree.h:691
void Insert(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer, DRC_CONSTRAINT_T aConstraintType, int aWorstClearance=0, bool aAtomicTables=false)
Insert an item into the tree on a particular layer with an optional worst clearance.
Definition drc_rtree.h:94
void recordPadding(PCB_LAYER_ID aLayer, int aPadding)
Definition drc_rtree.h:713
size_t size() const
Return the number of items in the tree.
Definition drc_rtree.h:643
bool empty() const
Definition drc_rtree.h:648
int QueryColliding(BOARD_ITEM *aRefItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer, std::function< bool(BOARD_ITEM *)> aFilter=nullptr, std::function< bool(BOARD_ITEM *)> aVisitor=nullptr, int aClearance=0) const
This is a fast test which essentially does bounding-box overlap given a worst-case clearance.
Definition drc_rtree.h:231
typename drc_rtree::Builder drc_rtree_builder
Definition drc_rtree.h:76
bool CheckColliding(SHAPE *aRefShape, PCB_LAYER_ID aTargetLayer, int aClearance=0, std::function< bool(BOARD_ITEM *)> aFilter=nullptr) const
Definition drc_rtree.h:192
DRC_LAYER Overlapping(PCB_LAYER_ID aLayer, const BOX2I &aRect) const
Definition drc_rtree.h:705
KIRTREE::PACKED_RTREE< ITEM_WITH_SHAPE *, int, 2 > drc_rtree
Definition drc_rtree.h:75
std::unordered_set< BOARD_ITEM * > GetObjectsAt(const VECTOR2I &aPt, PCB_LAYER_ID aLayer, int aClearance=0)
Get the BOARD_ITEM objects that overlap the specified point/layer.
Definition drc_rtree.h:526
bool QueryColliding(const BOX2I &aBox, SHAPE *aRefShape, PCB_LAYER_ID aLayer) const
Quicker version of above that just reports a raw yes/no.
Definition drc_rtree.h:448
int QueryCollidingPreparedCopper(BOARD_ITEM *aRefItem, const std::shared_ptr< SHAPE > &aRefShape, PCB_LAYER_ID aTargetLayer, std::function< bool(BOARD_ITEM *)> aFilter, std::function< bool(BOARD_ITEM *, const std::shared_ptr< SHAPE > &)> aVisitor, int aClearance=0, bool aUsePaddingCredit=false) const
Same broad phase as QueryColliding(), but the caller supplies the reference shape and the visitor als...
Definition drc_rtree.h:312
void clear()
Remove all items from the RTree.
Definition drc_rtree.h:180
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > LAYER_PAIR
Definition drc_rtree.h:548
size_t m_count
Definition drc_rtree.h:725
std::map< int, drc_rtree_builder > m_builders
Definition drc_rtree.h:722
DRC_LAYER Overlapping(PCB_LAYER_ID aLayer, const VECTOR2I &aPoint, int aAccuracy=0) const
Definition drc_rtree.h:697
int QueryCollidingPairs(DRC_RTREE *aRefTree, std::vector< LAYER_PAIR > aLayerPairs, std::function< bool(const LAYER_PAIR &, ITEM_WITH_SHAPE *, ITEM_WITH_SHAPE *, bool *aCollision)> aVisitor, int aMaxClearance, std::function< bool(int, int)> aProgressReporter) const
Definition drc_rtree.h:563
std::vector< ITEM_WITH_SHAPE * > m_owned
Definition drc_rtree.h:724
void Build()
Finalize all pending inserts by bulk-building packed R-trees from the staged items.
Definition drc_rtree.h:169
bool QueryColliding(const BOX2I &aBox, SHAPE *aRefShape, PCB_LAYER_ID aLayer, int aClearance, int *aActual, VECTOR2I *aPos) const
This one is for tessellated items.
Definition drc_rtree.h:391
void Insert(BOARD_ITEM *aItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer, DRC_CONSTRAINT_T aConstraintType, int aWorstClearance, bool aAtomicTables=false)
Insert an item into the tree on a particular layer with a worst clearance.
Definition drc_rtree.h:104
std::map< int, drc_rtree > m_tree
Definition drc_rtree.h:721
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:270
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual bool IsVisible() const
Definition eda_text.h:226
Static (immutable) packed R-tree built via Hilbert-curve bulk loading.
int Search(const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], VISITOR &aVisitor) const
Search for all items whose bounding boxes overlap the query rectangle.
SHAPE_TYPE Type() const
Return the type of the shape.
Definition shape.h:96
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if point aP lies closer to us than aClearance.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
An abstract shape on 2D plane.
Definition shape.h:124
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition shape.h:181
virtual const BOX2I BBox(int aClearance=0) const =0
Compute a bounding box of the shape, with a margin of aClearance a collision.
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:181
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
STL namespace.
@ SH_POLY_SET_TRIANGLE
a single triangle belonging to a POLY_SET triangulation
Definition shape.h:52
The DRC_LAYER struct provides a layer-specific auto-range iterator to the RTree.
Definition drc_rtree.h:662
DRC_LAYER(const drc_rtree &aTree, const BOX2I &aRect)
Definition drc_rtree.h:671
DRC_LAYER(const drc_rtree &aTree)
Definition drc_rtree.h:665
std::vector< ITEM_WITH_SHAPE * >::iterator begin()
Definition drc_rtree.h:687
std::vector< ITEM_WITH_SHAPE * > m_items
Definition drc_rtree.h:685
std::vector< ITEM_WITH_SHAPE * >::iterator end()
Definition drc_rtree.h:688
std::shared_ptr< SHAPE > parentShape
Never null; Insert() only builds these from a shape wxCHECK2_MSG has already validated.
Definition drc_rtree.h:71
ITEM_WITH_SHAPE(BOARD_ITEM *aParent, const std::shared_ptr< SHAPE > &aShape, std::shared_ptr< SHAPE > aParentShape)
Definition drc_rtree.h:58
ITEM_WITH_SHAPE(BOARD_ITEM *aParent, const SHAPE *aShape, std::shared_ptr< SHAPE > aParentShape)
Definition drc_rtree.h:50
std::shared_ptr< SHAPE > shapeStorage
Definition drc_rtree.h:68
ITEM_WITH_SHAPE * refItem
Definition drc_rtree.h:559
PAIR_INFO(LAYER_PAIR aPair, ITEM_WITH_SHAPE *aRef, ITEM_WITH_SHAPE *aTest)
Definition drc_rtree.h:552
ITEM_WITH_SHAPE * testItem
Definition drc_rtree.h:560
LAYER_PAIR layerPair
Definition drc_rtree.h:558
int actual
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:87
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708