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:
40
42 using BULK_ENTRY = typename TREE::BULK_ENTRY;
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
99 void BulkLoad( std::vector<BULK_ENTRY>& aEntries )
100 {
101 m_tree.BulkLoad( aEntries );
102 }
103
109 template <class Visitor>
110 void Query( const BOX2I& aBounds, int aStartLayer, int aEndLayer, Visitor& aVisitor ) const
111 {
112 // The layer bounds are copper layer ordinals, the same as Insert() stores.
113 const int mmin[3] = { aStartLayer, aBounds.GetX(), aBounds.GetY() };
114 const int mmax[3] = { aEndLayer, aBounds.GetRight(), aBounds.GetBottom() };
115
116 m_tree.Search( mmin, mmax, aVisitor );
117 }
118
119private:
121};
122
123
124#endif /* PCBNEW_CONNECTIVITY_RTREE_H_ */
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
constexpr coord_type GetY() const
Definition box2.h:205
constexpr coord_type GetX() const
Definition box2.h:204
constexpr coord_type GetRight() const
Definition box2.h:214
constexpr coord_type GetBottom() const
Definition box2.h:219
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
typename TREE::BULK_ENTRY BULK_ENTRY
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
KIRTREE::DYNAMIC_RTREE< T, int, 3 > TREE
Entry type accepted by BulkLoad().
void BulkLoad(std::vector< BULK_ENTRY > &aEntries)
Function BulkLoad() Replaces the tree contents with aEntries, packed bottom-up.
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.