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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef PCBNEW_CONNECTIVITY_RTREE_H_
25#define PCBNEW_CONNECTIVITY_RTREE_H_
26
27#include <layer_ids.h>
28#include <math/box2.h>
29#include <router/pns_layerset.h>
30
32
33
39template< class T >
41{
42public:
43
44 CN_RTREE() = default;
45 ~CN_RTREE() = default;
46
47 CN_RTREE( CN_RTREE&& aOther ) noexcept = default;
48 CN_RTREE& operator=( CN_RTREE&& aOther ) noexcept = default;
49
50 CN_RTREE( const CN_RTREE& ) = delete;
51 CN_RTREE& operator=( const CN_RTREE& ) = delete;
52
57 void Insert( T aItem )
58 {
59 const BOX2I& bbox = aItem->BBox();
60
61 const int mmin[3] = { aItem->StartLayer(), bbox.GetX(), bbox.GetY() };
62 const int mmax[3] = { aItem->EndLayer(), bbox.GetRight(), bbox.GetBottom() };
63
64 m_tree.Insert( mmin, mmax, aItem );
65 }
66
72 void Remove( T aItem )
73 {
74 const BOX2I& bbox = aItem->BBox();
75
76 const int mmin[3] = { aItem->StartLayer(), bbox.GetX(), bbox.GetY() };
77 const int mmax[3] = { aItem->EndLayer(), bbox.GetRight(), bbox.GetBottom() };
78
79 // DYNAMIC_RTREE::Remove tries the provided bbox first, then falls back
80 // to full-tree search if the item has moved since insertion.
81 m_tree.Remove( mmin, mmax, aItem );
82 }
83
88 void RemoveAll()
89 {
90 m_tree.RemoveAll();
91 }
92
98 template <class Visitor>
99 void Query( const BOX2I& aBounds, int aStartLayer, int aEndLayer, Visitor& aVisitor ) const
100 {
101 int start_layer = aStartLayer == B_Cu ? INT_MAX : aStartLayer;
102 int end_layer = aEndLayer == B_Cu ? INT_MAX : aEndLayer;
103
104 const int mmin[3] = { start_layer, aBounds.GetX(), aBounds.GetY() };
105 const int mmax[3] = { end_layer, aBounds.GetRight(), aBounds.GetBottom() };
106
107 m_tree.Search( mmin, mmax, aVisitor );
108 }
109
110private:
112};
113
114
115#endif /* PCBNEW_CONNECTIVITY_RTREE_H_ */
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr coord_type GetY() const
Definition box2.h:208
constexpr coord_type GetX() const
Definition box2.h:207
constexpr coord_type GetRight() const
Definition box2.h:217
constexpr coord_type GetBottom() const
Definition box2.h:222
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:65