Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:55:21

0001 // Boost.Polygon library point_data.hpp header file
0002 
0003 // Copyright (c) Intel Corporation 2008.
0004 // Copyright (c) 2008-2012 Simonson Lucanus.
0005 // Copyright (c) 2012-2012 Andrii Sydorchuk.
0006 
0007 // See http://www.boost.org for updates, documentation, and revision history.
0008 // Use, modification and distribution is subject to the Boost Software License,
0009 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0010 // http://www.boost.org/LICENSE_1_0.txt)
0011 
0012 #ifndef BOOST_POLYGON_POINT_DATA_HPP
0013 #define BOOST_POLYGON_POINT_DATA_HPP
0014 
0015 #include "isotropy.hpp"
0016 #include "point_concept.hpp"
0017 
0018 namespace boost {
0019 namespace polygon {
0020 
0021 template <typename T>
0022 class point_data {
0023  public:
0024   typedef T coordinate_type;
0025 
0026   point_data()
0027 #ifndef BOOST_POLYGON_MSVC
0028     : coords_()
0029 #endif
0030   {}
0031 
0032   point_data(coordinate_type x, coordinate_type y) {
0033     coords_[HORIZONTAL] = x;
0034     coords_[VERTICAL] = y;
0035   }
0036 
0037   explicit point_data(const point_data& that) {
0038     coords_[0] = that.coords_[0];
0039     coords_[1] = that.coords_[1];
0040   }
0041 
0042   point_data& operator=(const point_data& that) {
0043     coords_[0] = that.coords_[0];
0044     coords_[1] = that.coords_[1];
0045     return *this;
0046   }
0047 
0048 #if defined(__GNUC__) && __GNUC__ < 6
0049   // "explicit" to work around a bug in GCC < 6: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63356
0050   template <typename PointType>
0051   explicit point_data(const PointType& that) {
0052     *this = that;
0053   }
0054 #else // __GNUC__ < 6
0055   template <typename PointType>
0056   point_data(const PointType& that) {
0057     *this = that;
0058   }
0059 #endif // __GNUC__ < 6
0060 
0061   template <typename PointType>
0062   point_data& operator=(const PointType& that) {
0063     assign(*this, that);
0064     return *this;
0065   }
0066 
0067   // TODO(asydorchuk): Deprecated.
0068   template <typename CT>
0069   point_data(const point_data<CT>& that) {
0070     coords_[HORIZONTAL] = (coordinate_type)that.x();
0071     coords_[VERTICAL] = (coordinate_type)that.y();
0072   }
0073 
0074   coordinate_type get(orientation_2d orient) const {
0075     return coords_[orient.to_int()];
0076   }
0077 
0078   void set(orientation_2d orient, coordinate_type value) {
0079     coords_[orient.to_int()] = value;
0080   }
0081 
0082   coordinate_type x() const {
0083     return coords_[HORIZONTAL];
0084   }
0085 
0086   point_data& x(coordinate_type value) {
0087     coords_[HORIZONTAL] = value;
0088     return *this;
0089   }
0090 
0091   coordinate_type y() const {
0092     return coords_[VERTICAL];
0093   }
0094 
0095   point_data& y(coordinate_type value) {
0096     coords_[VERTICAL] = value;
0097     return *this;
0098   }
0099 
0100   bool operator==(const point_data& that) const {
0101     return (coords_[0] == that.coords_[0]) &&
0102       (coords_[1] == that.coords_[1]);
0103   }
0104 
0105   bool operator!=(const point_data& that) const {
0106     return !(*this == that);
0107   }
0108 
0109   bool operator<(const point_data& that) const {
0110     return (coords_[0] < that.coords_[0]) ||
0111       ((coords_[0] == that.coords_[0]) &&
0112        (coords_[1] < that.coords_[1]));
0113   }
0114 
0115   bool operator<=(const point_data& that) const {
0116     return !(that < *this);
0117   }
0118 
0119   bool operator>(const point_data& that) const {
0120     return that < *this;
0121   }
0122 
0123   bool operator>=(const point_data& that) const {
0124     return !(*this < that);
0125   }
0126 
0127  private:
0128   coordinate_type coords_[2];
0129 };
0130 
0131 template <typename CType>
0132 struct geometry_concept< point_data<CType> > {
0133   typedef point_concept type;
0134 };
0135 }  // polygon
0136 }  // boost
0137 
0138 #endif  // BOOST_POLYGON_POINT_DATA_HPP