KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_layerset.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef __PNS_LAYERSET_H
24#define __PNS_LAYERSET_H
25
26#include <algorithm>
27
32{
33public:
35 m_start( -1 ),
36 m_end( -1 )
37 {};
38
39 PNS_LAYER_RANGE( int aStart, int aEnd )
40 {
41 if( aStart > aEnd )
42 std::swap( aStart, aEnd );
43
44 m_start = aStart;
45 m_end = aEnd;
46 }
47
48 PNS_LAYER_RANGE( int aLayer )
49 {
50 m_start = m_end = aLayer;
51 }
52
54 m_start( aB.m_start ),
55 m_end( aB.m_end )
56 {}
57
59
61 {
62 m_start = aB.m_start;
63 m_end = aB.m_end;
64 return *this;
65 }
66
67 bool Overlaps( const PNS_LAYER_RANGE& aOther ) const
68 {
69 return m_end >= aOther.m_start && m_start <= aOther.m_end;
70 }
71
72 bool Overlaps( const int aLayer ) const
73 {
74 return aLayer >= m_start && aLayer <= m_end;
75 }
76
77 bool IsMultilayer() const
78 {
79 return m_start != m_end;
80 }
81
82 int Start() const
83 {
84 return m_start;
85 }
86
87 int End() const
88 {
89 return m_end;
90 }
91
92 void Merge( const PNS_LAYER_RANGE& aOther )
93 {
94 if( m_start < 0 || m_end < 0 )
95 {
96 m_start = aOther.m_start;
97 m_end = aOther.m_end;
98 return;
99 }
100
101 if( aOther.m_start < m_start )
102 m_start = aOther.m_start;
103
104 if( aOther.m_end > m_end )
105 m_end = aOther.m_end;
106 }
107
109 {
110 PNS_LAYER_RANGE overlap;
111
112 overlap.m_start = std::max( m_start, aOther.m_start );
113
114 if( m_end < 0 )
115 overlap.m_end = aOther.m_end;
116 else if( aOther.m_end < 0 )
117 overlap.m_end = m_end;
118 else
119 overlap.m_end = std::min( m_end, aOther.m_end );
120
121 return overlap;
122 }
123
126 {
127 return PNS_LAYER_RANGE( 0, 256 ); // fixme: use layer IDs header
128 }
129
130 bool operator==( const PNS_LAYER_RANGE& aOther ) const
131 {
132 return ( m_start == aOther.m_start ) && ( m_end == aOther.m_end );
133 }
134
135 bool operator!=( const PNS_LAYER_RANGE& aOther ) const
136 {
137 return ( m_start != aOther.m_start ) || ( m_end != aOther.m_end );
138 }
139
140private:
142 int m_end;
143};
144
145#endif // __PNS_LAYERSET_H
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
PNS_LAYER_RANGE(int aLayer)
Definition: pns_layerset.h:48
int Start() const
Definition: pns_layerset.h:82
bool Overlaps(const int aLayer) const
Definition: pns_layerset.h:72
bool Overlaps(const PNS_LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
void Merge(const PNS_LAYER_RANGE &aOther)
Definition: pns_layerset.h:92
static PNS_LAYER_RANGE All()
Definition: pns_layerset.h:125
PNS_LAYER_RANGE(const PNS_LAYER_RANGE &aB)
Definition: pns_layerset.h:53
bool operator!=(const PNS_LAYER_RANGE &aOther) const
Definition: pns_layerset.h:135
int End() const
Definition: pns_layerset.h:87
PNS_LAYER_RANGE Intersection(const PNS_LAYER_RANGE &aOther) const
Shortcut for comparisons/overlap tests.
Definition: pns_layerset.h:108
PNS_LAYER_RANGE & operator=(const PNS_LAYER_RANGE &aB)
Definition: pns_layerset.h:60
bool operator==(const PNS_LAYER_RANGE &aOther) const
Definition: pns_layerset.h:130
PNS_LAYER_RANGE(int aStart, int aEnd)
Definition: pns_layerset.h:39
bool IsMultilayer() const
Definition: pns_layerset.h:77