You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.0 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /*
  2. * KiRouter - a push-and-(sometimes-)shove PCB router
  3. *
  4. * Copyright (C) 2013-2014 CERN
  5. * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  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. #ifndef __RANGE_H
  21. #define __RANGE_H
  22. template<class T>
  23. class RANGE
  24. {
  25. public:
  26. RANGE( T aMin, T aMax ) :
  27. m_min( aMin ),
  28. m_max( aMax ),
  29. m_defined( true ) {}
  30. RANGE():
  31. m_defined( false ) {}
  32. T MinV() const
  33. {
  34. return m_min;
  35. }
  36. T MaxV() const
  37. {
  38. return m_max;
  39. }
  40. void Set( T aMin, T aMax ) const
  41. {
  42. m_max = aMax;
  43. m_min = aMin;
  44. }
  45. void Grow( T aValue )
  46. {
  47. if( !m_defined )
  48. {
  49. m_min = aValue;
  50. m_max = aValue;
  51. m_defined = true;
  52. }
  53. else
  54. {
  55. m_min = std::min( m_min, aValue );
  56. m_max = std::max( m_max, aValue );
  57. }
  58. }
  59. bool Inside( const T& aValue ) const
  60. {
  61. if( !m_defined )
  62. return true;
  63. return aValue >= m_min && aValue <= m_max;
  64. }
  65. bool Overlaps ( const RANGE<T>& aOther ) const
  66. {
  67. if( !m_defined || !aOther.m_defined )
  68. return true;
  69. return m_max >= aOther.m_min && m_min <= aOther.m_max;
  70. }
  71. bool Defined() const
  72. {
  73. return m_defined;
  74. }
  75. private:
  76. T m_min, m_max;
  77. bool m_defined;
  78. };
  79. #endif