summaryrefslogtreecommitdiff
path: root/pcbnew/router/range.h
blob: 5b47c74f1d9972abf0d958566a761e30d6869025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * KiRouter - a push-and-(sometimes-)shove PCB router
 *
 * Copyright (C) 2013-2014 CERN
 * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __RANGE_H
#define __RANGE_H

template<class T>
class RANGE
{
public:
    RANGE( T aMin, T aMax ) :
        m_min( aMin ),
        m_max( aMax ),
        m_defined( true ) {}

    RANGE():
        m_defined( false ) {}

    T MinV() const
    {
        return m_min;
    }

    T MaxV() const
    {
        return m_max;
    }

    void Set( T aMin, T aMax ) const
    {
        m_max = aMax;
        m_min = aMin;
    }

    void Grow( T aValue )
    {
        if( !m_defined )
        {
            m_min = aValue;
            m_max = aValue;
            m_defined = true;
        }
        else
        {
            m_min = std::min( m_min, aValue );
            m_max = std::max( m_max, aValue );
        }
    }

    bool Inside( const T& aValue ) const
    {
        if( !m_defined )
            return true;

        return aValue >= m_min && aValue <= m_max;
    }

    bool Overlaps ( const RANGE<T>& aOther ) const
    {
        if( !m_defined || !aOther.m_defined )
            return true;

        return m_max >= aOther.m_min && m_min <= aOther.m_max;
    }

    bool Defined() const
    {
        return m_defined;
    }

private:
    T m_min, m_max;
    bool m_defined;
};

#endif