segment_data.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Boost.Polygon library segment_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_SEGMENT_DATA_HPP
  10. #define BOOST_POLYGON_SEGMENT_DATA_HPP
  11. #include "isotropy.hpp"
  12. #include "segment_concept.hpp"
  13. namespace boost {
  14. namespace polygon {
  15. template <typename T>
  16. class segment_data {
  17. public:
  18. typedef T coordinate_type;
  19. typedef point_data<T> point_type;
  20. segment_data()
  21. #ifndef BOOST_POLYGON_MSVC
  22. : points_()
  23. #endif
  24. {}
  25. segment_data(const point_type& low, const point_type& high) {
  26. points_[LOW] = low;
  27. points_[HIGH] = high;
  28. }
  29. segment_data(const segment_data& that) {
  30. points_[0] = that.points_[0];
  31. points_[1] = that.points_[1];
  32. }
  33. segment_data& operator=(const segment_data& that) {
  34. points_[0] = that.points_[0];
  35. points_[1] = that.points_[1];
  36. return *this;
  37. }
  38. template <typename SegmentType>
  39. segment_data& operator=(const SegmentType& that) {
  40. assign(*this, that);
  41. return *this;
  42. }
  43. point_type get(direction_1d dir) const {
  44. return points_[dir.to_int()];
  45. }
  46. void set(direction_1d dir, const point_type& point) {
  47. points_[dir.to_int()] = point;
  48. }
  49. point_type low() const {
  50. return points_[LOW];
  51. }
  52. segment_data& low(const point_type& point) {
  53. points_[LOW] = point;
  54. return *this;
  55. }
  56. point_type high() const {
  57. return points_[HIGH];
  58. }
  59. segment_data& high(const point_type& point) {
  60. points_[HIGH] = point;
  61. return *this;
  62. }
  63. bool operator==(const segment_data& that) const {
  64. return (points_[0] == that.points_[0]) &&
  65. (points_[1] == that.points_[1]);
  66. }
  67. bool operator!=(const segment_data& that) const {
  68. return (points_[0] != that.points_[0]) ||
  69. (points_[1] != that.points_[1]);
  70. }
  71. bool operator<(const segment_data& that) const {
  72. if (points_[0] != that.points_[0]) {
  73. return points_[0] < that.points_[0];
  74. }
  75. return points_[1] < that.points_[1];
  76. }
  77. bool operator<=(const segment_data& that) const {
  78. return !(that < *this);
  79. }
  80. bool operator>(const segment_data& that) const {
  81. return that < *this;
  82. }
  83. bool operator>=(const segment_data& that) const {
  84. return !((*this) < that);
  85. }
  86. private:
  87. point_type points_[2];
  88. };
  89. template <typename CType>
  90. struct geometry_concept<segment_data<CType> > {
  91. typedef segment_concept type;
  92. };
  93. } // polygon
  94. } // boost
  95. #endif // BOOST_POLYGON_SEGMENT_DATA_HPP