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 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
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 __RANGE_H
23#define __RANGE_H
24
25template<class T>
26class RANGE
27{
28public:
29 RANGE( T aMin, T aMax ) :
30 m_min( aMin ),
31 m_max( aMax ),
32 m_defined( true ) {}
33
35 m_defined( false ) {}
36
37 T MinV() const
38 {
39 return m_min;
40 }
41
42 T MaxV() const
43 {
44 return m_max;
45 }
46
47 void Set( T aMin, T aMax ) const
48 {
49 m_max = aMax;
50 m_min = aMin;
51 }
52
53 void Grow( T aValue )
54 {
55 if( !m_defined )
56 {
57 m_min = aValue;
58 m_max = aValue;
59 m_defined = true;
60 }
61 else
62 {
63 m_min = std::min( m_min, aValue );
64 m_max = std::max( m_max, aValue );
65 }
66 }
67
68 bool Inside( const T& aValue ) const
69 {
70 if( !m_defined )
71 return true;
72
73 return aValue >= m_min && aValue <= m_max;
74 }
75
76 bool Overlaps ( const RANGE<T>& aOther ) const
77 {
78 if( !m_defined || !aOther.m_defined )
79 return true;
80
81 return m_max >= aOther.m_min && m_min <= aOther.m_max;
82 }
83
84 bool Defined() const
85 {
86 return m_defined;
87 }
88
89private:
92};
93
94#endif
Definition: range.h:27
void Grow(T aValue)
Definition: range.h:53
RANGE()
Definition: range.h:34
T m_min
Definition: range.h:90
bool Defined() const
Definition: range.h:84
bool m_defined
Definition: range.h:91
T MinV() const
Definition: range.h:37
void Set(T aMin, T aMax) const
Definition: range.h:47
bool Inside(const T &aValue) const
Definition: range.h:68
RANGE(T aMin, T aMax)
Definition: range.h:29
T MaxV() const
Definition: range.h:42
bool Overlaps(const RANGE< T > &aOther) const
Definition: range.h:76
T m_max
Definition: range.h:90