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