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
18namespace boost {
19namespace polygon {
20
21template <typename T>
22class point_data {
23 public:
24 typedef T coordinate_type;
25
26 point_data()
27#ifndef BOOST_POLYGON_MSVC
28 : coords_()
29#endif
30 {}
31
32 point_data(coordinate_type x, coordinate_type y) {
33 coords_[HORIZONTAL] = x;
34 coords_[VERTICAL] = y;
35 }
36
37 explicit point_data(const point_data& that) {
38 coords_[0] = that.coords_[0];
39 coords_[1] = that.coords_[1];
40 }
41
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>
51 explicit point_data(const PointType& that) {
52 *this = that;
53 }
54#else // __GNUC__ < 6
55 template <typename PointType>
56 point_data(const PointType& that) {
57 *this = that;
58 }
59#endif // __GNUC__ < 6
60
61 template <typename PointType>
62 point_data& operator=(const PointType& that) {
63 assign(*this, that);
64 return *this;
65 }
66
67 // TODO(asydorchuk): Deprecated.
68 template <typename CT>
69 point_data(const point_data<CT>& that) {
70 coords_[HORIZONTAL] = (coordinate_type)that.x();
71 coords_[VERTICAL] = (coordinate_type)that.y();
72 }
73
74 coordinate_type get(orientation_2d orient) const {
75 return coords_[orient.to_int()];
76 }
77
78 void set(orientation_2d orient, coordinate_type value) {
79 coords_[orient.to_int()] = value;
80 }
81
82 coordinate_type x() const {
83 return coords_[HORIZONTAL];
84 }
85
86 point_data& x(coordinate_type value) {
87 coords_[HORIZONTAL] = value;
88 return *this;
89 }
90
91 coordinate_type y() const {
92 return coords_[VERTICAL];
93 }
94
95 point_data& y(coordinate_type value) {
96 coords_[VERTICAL] = value;
97 return *this;
98 }
99
100 bool operator==(const point_data& that) const {
101 return (coords_[0] == that.coords_[0]) &&
102 (coords_[1] == that.coords_[1]);
103 }
104
105 bool operator!=(const point_data& that) const {
106 return !(*this == that);
107 }
108
109 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
115 bool operator<=(const point_data& that) const {
116 return !(that < *this);
117 }
118
119 bool operator>(const point_data& that) const {
120 return that < *this;
121 }
122
123 bool operator>=(const point_data& that) const {
124 return !(*this < that);
125 }
126
127 private:
128 coordinate_type coords_[2];
129};
130
131template <typename CType>
132struct geometry_concept< point_data<CType> > {
133 typedef point_concept type;
134};
135} // polygon
136} // boost
137
138#endif // BOOST_POLYGON_POINT_DATA_HPP
139

source code of boost/boost/polygon/point_data.hpp