point_data.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #if defined(__GNUC__) && __GNUC__ < 6
  38. // "explicit" to work around a bug in GCC < 6: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63356
  39. template <typename PointType>
  40. explicit point_data(const PointType& that) {
  41. *this = that;
  42. }
  43. #else // __GNUC__ < 6
  44. template <typename PointType>
  45. point_data(const PointType& that) {
  46. *this = that;
  47. }
  48. #endif // __GNUC__ < 6
  49. template <typename PointType>
  50. point_data& operator=(const PointType& that) {
  51. assign(*this, that);
  52. return *this;
  53. }
  54. // TODO(asydorchuk): Deprecated.
  55. template <typename CT>
  56. point_data(const point_data<CT>& that) {
  57. coords_[HORIZONTAL] = (coordinate_type)that.x();
  58. coords_[VERTICAL] = (coordinate_type)that.y();
  59. }
  60. coordinate_type get(orientation_2d orient) const {
  61. return coords_[orient.to_int()];
  62. }
  63. void set(orientation_2d orient, coordinate_type value) {
  64. coords_[orient.to_int()] = value;
  65. }
  66. coordinate_type x() const {
  67. return coords_[HORIZONTAL];
  68. }
  69. point_data& x(coordinate_type value) {
  70. coords_[HORIZONTAL] = value;
  71. return *this;
  72. }
  73. coordinate_type y() const {
  74. return coords_[VERTICAL];
  75. }
  76. point_data& y(coordinate_type value) {
  77. coords_[VERTICAL] = value;
  78. return *this;
  79. }
  80. bool operator==(const point_data& that) const {
  81. return (coords_[0] == that.coords_[0]) &&
  82. (coords_[1] == that.coords_[1]);
  83. }
  84. bool operator!=(const point_data& that) const {
  85. return !(*this == that);
  86. }
  87. bool operator<(const point_data& that) const {
  88. return (coords_[0] < that.coords_[0]) ||
  89. ((coords_[0] == that.coords_[0]) &&
  90. (coords_[1] < that.coords_[1]));
  91. }
  92. bool operator<=(const point_data& that) const {
  93. return !(that < *this);
  94. }
  95. bool operator>(const point_data& that) const {
  96. return that < *this;
  97. }
  98. bool operator>=(const point_data& that) const {
  99. return !(*this < that);
  100. }
  101. private:
  102. coordinate_type coords_[2];
  103. };
  104. template <typename CType>
  105. struct geometry_concept< point_data<CType> > {
  106. typedef point_concept type;
  107. };
  108. } // polygon
  109. } // boost
  110. #endif // BOOST_POLYGON_POINT_DATA_HPP