KiCad PCB EDA Suite
Loading...
Searching...
No Matches
connectivity_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 *
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
20#ifndef PCBNEW_CONNECTIVITY_RTREE_H_
21#define PCBNEW_CONNECTIVITY_RTREE_H_
22
23#include <layer_ids.h>
24#include <math/box2.h>
25#include <router/pns_layerset.h>
26
28
29
35template< class T >
37{
38public:
39
40 CN_RTREE() = default;
41 ~CN_RTREE() = default;
42
43 CN_RTREE( CN_RTREE&& aOther ) noexcept = default;
44 CN_RTREE& operator=( CN_RTREE&& aOther ) noexcept = default;
45
46 CN_RTREE( const CN_RTREE& ) = delete;
47 CN_RTREE& operator=( const CN_RTREE& ) = delete;
48
53 void Insert( T aItem )
54 {
55 const BOX2I& bbox = aItem->BBox();
56
57 const int mmin[3] = { aItem->StartLayer(), bbox.GetX(), bbox.GetY() };
58 const int mmax[3] = { aItem->EndLayer(), bbox.GetRight(), bbox.GetBottom() };
59
60 m_tree.Insert( mmin, mmax, aItem );
61 }
62
68 void Remove( T aItem )
69 {
70 const BOX2I& bbox = aItem->BBox();
71
72 const int mmin[3] = { aItem->StartLayer(), bbox.GetX(), bbox.GetY() };
73 const int mmax[3] = { aItem->EndLayer(), bbox.GetRight(), bbox.GetBottom() };
74
75 // DYNAMIC_RTREE::Remove tries the provided bbox first, then falls back
76 // to full-tree search if the item has moved since insertion.
77 m_tree.Remove( mmin, mmax, aItem );
78 }
79
84 void RemoveAll()
85 {
86 m_tree.RemoveAll();
87 }
88
94 template <class Visitor>
95 void Query( const BOX2I& aBounds, int aStartLayer, int aEndLayer, Visitor& aVisitor ) const
96 {
97 int start_layer = aStartLayer == B_Cu ? INT_MAX : aStartLayer;
98 int end_layer = aEndLayer == B_Cu ? INT_MAX : aEndLayer;
99
100 const int mmin[3] = { start_layer, aBounds.GetX(), aBounds.GetY() };
101 const int mmax[3] = { end_layer, aBounds.GetRight(), aBounds.GetBottom() };
102
103 m_tree.Search( mmin, mmax, aVisitor );
104 }
105
106private:
108};
109
110
111#endif /* PCBNEW_CONNECTIVITY_RTREE_H_ */
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr coord_type GetY() const
Definition box2.h:204
constexpr coord_type GetX() const
Definition box2.h:203
constexpr coord_type GetRight() const
Definition box2.h:213
constexpr coord_type GetBottom() const
Definition box2.h:218
void Insert(T aItem)
Function Insert() Inserts an item into the tree.
CN_RTREE(CN_RTREE &&aOther) noexcept=default
CN_RTREE & operator=(const CN_RTREE &)=delete
CN_RTREE & operator=(CN_RTREE &&aOther) noexcept=default
KIRTREE::DYNAMIC_RTREE< T, int, 3 > m_tree
CN_RTREE()=default
void RemoveAll()
Function RemoveAll() Removes all items from the RTree.
void Remove(T aItem)
Function Remove() Removes an item from the tree.
~CN_RTREE()=default
void Query(const BOX2I &aBounds, int aStartLayer, int aEndLayer, Visitor &aVisitor) const
Function Query() Executes a function object aVisitor for each item whose bounding box intersects with...
CN_RTREE(const CN_RTREE &)=delete
Dynamic R*-tree with SoA node layout and stored insertion bounding boxes.
@ B_Cu
Definition layer_ids.h:61