2014-05-14 13:53:54 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
template<class T>
|
|
|
|
class RANGE
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
public:
|
2014-05-16 11:37:31 +00:00
|
|
|
RANGE( T aMin, T aMax ) :
|
|
|
|
m_min( aMin ),
|
|
|
|
m_max( aMax ),
|
|
|
|
m_defined( true ) {}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
RANGE():
|
|
|
|
m_defined( false ) {}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
T MinV() const
|
|
|
|
{
|
|
|
|
return m_min;
|
|
|
|
}
|
|
|
|
|
|
|
|
T MaxV() const
|
|
|
|
{
|
|
|
|
return m_max;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void Set( T aMin, T aMax ) const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_max = aMax;
|
|
|
|
m_min = aMin;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void Grow( T aValue )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !m_defined )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
m_min = aValue;
|
|
|
|
m_max = aValue;
|
2014-05-14 13:53:54 +00:00
|
|
|
m_defined = true;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_min = std::min( m_min, aValue );
|
|
|
|
m_max = std::max( m_max, aValue );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
bool Inside( const T& aValue ) const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !m_defined )
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
return aValue >= m_min && aValue <= m_max;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
bool Overlaps ( const RANGE<T>& aOther ) const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !m_defined || !aOther.m_defined )
|
2014-05-14 13:53:54 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
#endif
|