KiCad PCB EDA Suite
Loading...
Searching...
No Matches
range.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 * Author: Tomasz Wlostowski <[email protected]>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef __RANGE_H
22#define __RANGE_H
23
24template<class T>
25class RANGE
26{
27public:
28 RANGE( T aMin, T aMax ) :
29 m_min( aMin ),
30 m_max( aMax ),
31 m_defined( true ) {}
32
34 m_defined( false ) {}
35
36 T MinV() const
37 {
38 return m_min;
39 }
40
41 T MaxV() const
42 {
43 return m_max;
44 }
45
46 void Set( T aMin, T aMax ) const
47 {
48 m_max = aMax;
49 m_min = aMin;
50 }
51
52 void Grow( T aValue )
53 {
54 if( !m_defined )
55 {
56 m_min = aValue;
57 m_max = aValue;
58 m_defined = true;
59 }
60 else
61 {
62 m_min = std::min( m_min, aValue );
63 m_max = std::max( m_max, aValue );
64 }
65 }
66
67 bool Inside( const T& aValue ) const
68 {
69 if( !m_defined )
70 return true;
71
72 return aValue >= m_min && aValue <= m_max;
73 }
74
75 bool Overlaps ( const RANGE<T>& aOther ) const
76 {
77 if( !m_defined || !aOther.m_defined )
78 return true;
79
80 return m_max >= aOther.m_min && m_min <= aOther.m_max;
81 }
82
83 bool Defined() const
84 {
85 return m_defined;
86 }
87
88private:
91};
92
93#endif
Definition: range.h:26
void Grow(T aValue)
Definition: range.h:52
RANGE()
Definition: range.h:33
T m_min
Definition: range.h:89
bool Defined() const
Definition: range.h:83
bool m_defined
Definition: range.h:90
T MinV() const
Definition: range.h:36
void Set(T aMin, T aMax) const
Definition: range.h:46
bool Inside(const T &aValue) const
Definition: range.h:67
RANGE(T aMin, T aMax)
Definition: range.h:28
T MaxV() const
Definition: range.h:41
bool Overlaps(const RANGE< T > &aOther) const
Definition: range.h:75
T m_max
Definition: range.h:89