point_data.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Boost.Polygon library point_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_POINT_DATA_HPP
  10. #define BOOST_POLYGON_POINT_DATA_HPP
  11. #include "isotropy.hpp"
  12. #include "point_concept.hpp"
  13. namespace boost {
  14. namespace polygon {
  15. template <typename T>
  16. class point_data {
  17. public:
  18. typedef T coordinate_type;
  19. point_data()
  20. #ifndef BOOST_POLYGON_MSVC
  21. : coords_()
  22. #endif
  23. {}
  24. point_data(coordinate_type x, coordinate_type y) {
  25. coords_[HORIZONTAL] = x;
  26. coords_[VERTICAL] = y;
  27. }
  28. explicit point_data(const point_data& that) {
  29. coords_[0] = that.coords_[0];
  30. coords_[1] = that.coords_[1];
  31. }
  32. point_data& operator=(const point_data& that) {
  33. coords_[0] = that.coords_[0];
  34. coords_[1] = that.coords_[1];
  35. return *this;
  36. }
  37. template <typename PointType>
  38. explicit point_data(const PointType& that) {
  39. *this = that;
  40. }
  41. template <typename PointType>
  42. point_data& operator=(const PointType& that) {
  43. assign(*this, that);
  44. return *this;
  45. }
  46. // TODO(asydorchuk): Deprecated.
  47. template <typename CT>
  48. point_data(const point_data<CT>& that) {
  49. coords_[HORIZONTAL] = (coordinate_type)that.x();
  50. coords_[VERTICAL] = (coordinate_type)that.y();
  51. }
  52. coordinate_type get(orientation_2d orient) const {
  53. return coords_[orient.to_int()];
  54. }
  55. void set(orientation_2d orient, coordinate_type value) {
  56. coords_[orient.to_int()] = value;
  57. }
  58. coordinate_type x() const {
  59. return coords_[HORIZONTAL];
  60. }
  61. point_data& x(coordinate_type value) {
  62. coords_[HORIZONTAL] = value;
  63. return *this;
  64. }
  65. coordinate_type y() const {
  66. return coords_[VERTICAL];
  67. }
  68. point_data& y(coordinate_type value) {
  69. coords_[VERTICAL] = value;
  70. return *this;
  71. }
  72. bool operator==(const point_data& that) const {
  73. return (coords_[0] == that.coords_[0]) &&
  74. (coords_[1] == that.coords_[1]);
  75. }
  76. bool operator!=(const point_data& that) const {
  77. return !(*this == that);
  78. }
  79. bool operator<(const point_data& that) const {
  80. return (coords_[0] < that.coords_[0]) ||
  81. ((coords_[0] == that.coords_[0]) &&
  82. (coords_[1] < that.coords_[1]));
  83. }
  84. bool operator<=(const point_data& that) const {
  85. return !(that < *this);
  86. }
  87. bool operator>(const point_data& that) const {
  88. return that < *this;
  89. }
  90. bool operator>=(const point_data& that) const {
  91. return !(*this < that);
  92. }
  93. private:
  94. coordinate_type coords_[2];
  95. };
  96. template <typename CType>
  97. struct geometry_concept< point_data<CType> > {
  98. typedef point_concept type;
  99. };
  100. } // polygon
  101. } // boost
  102. #endif // BOOST_POLYGON_POINT_DATA_HPP