point_xy.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_GEOMETRIES_POINT_XY_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_POINT_XY_HPP
  12. #include <cstddef>
  13. #include <boost/config.hpp>
  14. #include <boost/mpl/int.hpp>
  15. #include <boost/geometry/core/cs.hpp>
  16. #include <boost/geometry/geometries/point.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace model { namespace d2
  20. {
  21. /*!
  22. \brief 2D point in Cartesian coordinate system
  23. \tparam CoordinateType numeric type, for example, double, float, int
  24. \tparam CoordinateSystem coordinate system, defaults to cs::cartesian
  25. \qbk{[include reference/geometries/point_xy.qbk]}
  26. \qbk{before.synopsis,
  27. [heading Model of]
  28. [link geometry.reference.concepts.concept_point Point Concept]
  29. }
  30. \qbk{[include reference/geometries/point_assign_warning.qbk]}
  31. */
  32. template<typename CoordinateType, typename CoordinateSystem = cs::cartesian>
  33. class point_xy : public model::point<CoordinateType, 2, CoordinateSystem>
  34. {
  35. public:
  36. #ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
  37. /// \constructor_default_no_init
  38. point_xy() = default;
  39. #else
  40. /// \constructor_default_no_init
  41. inline point_xy()
  42. {}
  43. #endif
  44. /// Constructor with x/y values
  45. inline point_xy(CoordinateType const& x, CoordinateType const& y)
  46. : model::point<CoordinateType, 2, CoordinateSystem>(x, y)
  47. {}
  48. /// Get x-value
  49. inline CoordinateType const& x() const
  50. { return this->template get<0>(); }
  51. /// Get y-value
  52. inline CoordinateType const& y() const
  53. { return this->template get<1>(); }
  54. /// Set x-value
  55. inline void x(CoordinateType const& v)
  56. { this->template set<0>(v); }
  57. /// Set y-value
  58. inline void y(CoordinateType const& v)
  59. { this->template set<1>(v); }
  60. };
  61. }} // namespace model::d2
  62. // Adapt the point_xy to the concept
  63. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  64. namespace traits
  65. {
  66. template <typename CoordinateType, typename CoordinateSystem>
  67. struct tag<model::d2::point_xy<CoordinateType, CoordinateSystem> >
  68. {
  69. typedef point_tag type;
  70. };
  71. template<typename CoordinateType, typename CoordinateSystem>
  72. struct coordinate_type<model::d2::point_xy<CoordinateType, CoordinateSystem> >
  73. {
  74. typedef CoordinateType type;
  75. };
  76. template<typename CoordinateType, typename CoordinateSystem>
  77. struct coordinate_system<model::d2::point_xy<CoordinateType, CoordinateSystem> >
  78. {
  79. typedef CoordinateSystem type;
  80. };
  81. template<typename CoordinateType, typename CoordinateSystem>
  82. struct dimension<model::d2::point_xy<CoordinateType, CoordinateSystem> >
  83. : boost::mpl::int_<2>
  84. {};
  85. template<typename CoordinateType, typename CoordinateSystem, std::size_t Dimension>
  86. struct access<model::d2::point_xy<CoordinateType, CoordinateSystem>, Dimension >
  87. {
  88. static inline CoordinateType get(
  89. model::d2::point_xy<CoordinateType, CoordinateSystem> const& p)
  90. {
  91. return p.template get<Dimension>();
  92. }
  93. static inline void set(model::d2::point_xy<CoordinateType, CoordinateSystem>& p,
  94. CoordinateType const& value)
  95. {
  96. p.template set<Dimension>(value);
  97. }
  98. };
  99. } // namespace traits
  100. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  101. }} // namespace boost::geometry
  102. #endif // BOOST_GEOMETRY_GEOMETRIES_POINT_XY_HPP