interval_data.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Boost.Polygon library interval_data.hpp header file
  2. // Copyright (c) Intel Corporation 2008.
  3. // Copyright (c) 2008-2012 Simonson Lucanus.
  4. // Copyright (c) 2012-2012 Andrii Sydorchuk.
  5. // See http://www.boost.org for updates, documentation, and revision history.
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_POLYGON_INTERVAL_DATA_HPP
  10. #define BOOST_POLYGON_INTERVAL_DATA_HPP
  11. #include "isotropy.hpp"
  12. #include "interval_concept.hpp"
  13. namespace boost {
  14. namespace polygon {
  15. template <typename T>
  16. class interval_data {
  17. public:
  18. typedef T coordinate_type;
  19. interval_data()
  20. #ifndef BOOST_POLYGON_MSVC
  21. : coords_()
  22. #endif
  23. {}
  24. interval_data(coordinate_type low, coordinate_type high) {
  25. coords_[LOW] = low;
  26. coords_[HIGH] = high;
  27. }
  28. interval_data(const interval_data& that) {
  29. coords_[0] = that.coords_[0];
  30. coords_[1] = that.coords_[1];
  31. }
  32. interval_data& operator=(const interval_data& that) {
  33. coords_[0] = that.coords_[0];
  34. coords_[1] = that.coords_[1];
  35. return *this;
  36. }
  37. template <typename IntervalType>
  38. interval_data& operator=(const IntervalType& that) {
  39. assign(*this, that);
  40. return *this;
  41. }
  42. coordinate_type get(direction_1d dir) const {
  43. return coords_[dir.to_int()];
  44. }
  45. void set(direction_1d dir, coordinate_type value) {
  46. coords_[dir.to_int()] = value;
  47. }
  48. coordinate_type low() const {
  49. return coords_[0];
  50. }
  51. interval_data& low(coordinate_type value) {
  52. coords_[LOW] = value;
  53. return *this;
  54. }
  55. coordinate_type high() const {
  56. return coords_[1];
  57. }
  58. interval_data& high(coordinate_type value) {
  59. coords_[HIGH] = value;
  60. return *this;
  61. }
  62. bool operator==(const interval_data& that) const {
  63. return low() == that.low() && high() == that.high();
  64. }
  65. bool operator!=(const interval_data& that) const {
  66. return low() != that.low() || high() != that.high();
  67. }
  68. bool operator<(const interval_data& that) const {
  69. if (coords_[0] != that.coords_[0]) {
  70. return coords_[0] < that.coords_[0];
  71. }
  72. return coords_[1] < that.coords_[1];
  73. }
  74. bool operator<=(const interval_data& that) const {
  75. return !(that < *this);
  76. }
  77. bool operator>(const interval_data& that) const {
  78. return that < *this;
  79. }
  80. bool operator>=(const interval_data& that) const {
  81. return !((*this) < that);
  82. }
  83. private:
  84. coordinate_type coords_[2];
  85. };
  86. template <typename CType>
  87. struct geometry_concept< interval_data<CType> > {
  88. typedef interval_concept type;
  89. };
  90. } // polygon
  91. } // boost
  92. #endif // BOOST_POLYGON_INTERVAL_DATA_HPP