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 if ( m_start < 0 || m_end < 0 || aOther.m_start < 0 || aOther.m_end < 0 )
70 return false;
71 return m_end >= aOther.m_start && m_start <= aOther.m_end;
72 }
73
74 bool Overlaps( const int aLayer ) const
75 {
76 if ( m_start < 0 || m_end < 0 || aLayer < 0 )
77 return false;
78 return aLayer >= m_start && aLayer <= m_end;
79 }
80
81 bool IsMultilayer() const
82 {
83 return m_start != m_end;
84 }
85
86 int Start() const
87 {
88 return m_start;
89 }
90
91 int End() const
92 {
93 return m_end;
94 }
95
96 void Merge( const PNS_LAYER_RANGE& aOther )
97 {
98 if( m_start < 0 || m_end < 0 )
99 {
100 m_start = aOther.m_start;
101 m_end = aOther.m_end;
102 return;
103 }
104
105 if( aOther.m_start < m_start )
106 m_start = aOther.m_start;
107
108 if( aOther.m_end > m_end )
109 m_end = aOther.m_end;
110 }
111
113 {
114 PNS_LAYER_RANGE overlap;
115
116 overlap.m_start = std::max( m_start, aOther.m_start );
117
118 if( m_end < 0 )
119 overlap.m_end = aOther.m_end;
120 else if( aOther.m_end < 0 )
121 overlap.m_end = m_end;
122 else
123 overlap.m_end = std::min( m_end, aOther.m_end );
124
125 return overlap;
126 }
127
130 {
131 return PNS_LAYER_RANGE( 0, 256 ); // fixme: use layer IDs header
132 }
133
134 bool operator==( const PNS_LAYER_RANGE& aOther ) const
135 {
136 return ( m_start == aOther.m_start ) && ( m_end == aOther.m_end );
137 }
138
139 bool operator!=( const PNS_LAYER_RANGE& aOther ) const
140 {
141 return ( m_start != aOther.m_start ) || ( m_end != aOther.m_end );
142 }
143
144private:
146 int m_end;
147};
148
149#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:86
bool Overlaps(const int aLayer) const
Definition: pns_layerset.h:74
bool Overlaps(const PNS_LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
void Merge(const PNS_LAYER_RANGE &aOther)
Definition: pns_layerset.h:96
static PNS_LAYER_RANGE All()
Definition: pns_layerset.h:129
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:139
int End() const
Definition: pns_layerset.h:91
PNS_LAYER_RANGE Intersection(const PNS_LAYER_RANGE &aOther) const
Shortcut for comparisons/overlap tests.
Definition: pns_layerset.h:112
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:134
PNS_LAYER_RANGE(int aStart, int aEnd)
Definition: pns_layerset.h:39
bool IsMultilayer() const
Definition: pns_layerset.h:81