1 // Boost.Polygon library point_data.hpp header file
2 
3 // Copyright (c) Intel Corporation 2008.
4 // Copyright (c) 2008-2012 Simonson Lucanus.
5 // Copyright (c) 2012-2012 Andrii Sydorchuk.
6 
7 // See http://www.boost.org for updates, documentation, and revision history.
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 
12 #ifndef BOOST_POLYGON_POINT_DATA_HPP
13 #define BOOST_POLYGON_POINT_DATA_HPP
14 
15 #include "isotropy.hpp"
16 #include "point_concept.hpp"
17 
18 namespace boost {
19 namespace polygon {
20 
21 template <typename T>
22 class point_data {
23  public:
24   typedef T coordinate_type;
25 
point_data()26   point_data()
27 #ifndef BOOST_POLYGON_MSVC
28     : coords_()
29 #endif
30   {}
31 
point_data(coordinate_type x,coordinate_type y)32   point_data(coordinate_type x, coordinate_type y) {
33     coords_[HORIZONTAL] = x;
34     coords_[VERTICAL] = y;
35   }
36 
point_data(const point_data & that)37   explicit point_data(const point_data& that) {
38     coords_[0] = that.coords_[0];
39     coords_[1] = that.coords_[1];
40   }
41 
operator =(const point_data & that)42   point_data& operator=(const point_data& that) {
43     coords_[0] = that.coords_[0];
44     coords_[1] = that.coords_[1];
45     return *this;
46   }
47 
48 #if defined(__GNUC__) && __GNUC__ < 6
49   // "explicit" to work around a bug in GCC < 6: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63356
50   template <typename PointType>
point_data(const PointType & that)51   explicit point_data(const PointType& that) {
52     *this = that;
53   }
54 #else // __GNUC__ < 6
55   template <typename PointType>
point_data(const PointType & that)56   point_data(const PointType& that) {
57     *this = that;
58   }
59 #endif // __GNUC__ < 6
60 
61   template <typename PointType>
operator =(const PointType & that)62   point_data& operator=(const PointType& that) {
63     assign(*this, that);
64     return *this;
65   }
66 
67   // TODO(asydorchuk): Deprecated.
68   template <typename CT>
point_data(const point_data<CT> & that)69   point_data(const point_data<CT>& that) {
70     coords_[HORIZONTAL] = (coordinate_type)that.x();
71     coords_[VERTICAL] = (coordinate_type)that.y();
72   }
73 
get(orientation_2d orient) const74   coordinate_type get(orientation_2d orient) const {
75     return coords_[orient.to_int()];
76   }
77 
set(orientation_2d orient,coordinate_type value)78   void set(orientation_2d orient, coordinate_type value) {
79     coords_[orient.to_int()] = value;
80   }
81 
x() const82   coordinate_type x() const {
83     return coords_[HORIZONTAL];
84   }
85 
x(coordinate_type value)86   point_data& x(coordinate_type value) {
87     coords_[HORIZONTAL] = value;
88     return *this;
89   }
90 
y() const91   coordinate_type y() const {
92     return coords_[VERTICAL];
93   }
94 
y(coordinate_type value)95   point_data& y(coordinate_type value) {
96     coords_[VERTICAL] = value;
97     return *this;
98   }
99 
operator ==(const point_data & that) const100   bool operator==(const point_data& that) const {
101     return (coords_[0] == that.coords_[0]) &&
102       (coords_[1] == that.coords_[1]);
103   }
104 
operator !=(const point_data & that) const105   bool operator!=(const point_data& that) const {
106     return !(*this == that);
107   }
108 
operator <(const point_data & that) const109   bool operator<(const point_data& that) const {
110     return (coords_[0] < that.coords_[0]) ||
111       ((coords_[0] == that.coords_[0]) &&
112        (coords_[1] < that.coords_[1]));
113   }
114 
operator <=(const point_data & that) const115   bool operator<=(const point_data& that) const {
116     return !(that < *this);
117   }
118 
operator >(const point_data & that) const119   bool operator>(const point_data& that) const {
120     return that < *this;
121   }
122 
operator >=(const point_data & that) const123   bool operator>=(const point_data& that) const {
124     return !(*this < that);
125   }
126 
127  private:
128   coordinate_type coords_[2];
129 };
130 
131 template <typename CType>
132 struct geometry_concept< point_data<CType> > {
133   typedef point_concept type;
134 };
135 }  // polygon
136 }  // boost
137 
138 #endif  // BOOST_POLYGON_POINT_DATA_HPP
139