point_xy.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/mpl/int.hpp>
  14. #include <boost/geometry/core/cs.hpp>
  15. #include <boost/geometry/geometries/point.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. namespace model { namespace d2
  19. {
  20. /*!
  21. \brief 2D point in Cartesian coordinate system
  22. \tparam CoordinateType numeric type, for example, double, float, int
  23. \tparam CoordinateSystem coordinate system, defaults to cs::cartesian
  24. \qbk{before.synopsis,
  25. [heading Model of]
  26. [link geometry.reference.concepts.concept_point Point Concept]
  27. }
  28. \qbk{[include reference/geometries/point_assign_warning.qbk]}
  29. */
  30. template<typename CoordinateType, typename CoordinateSystem = cs::cartesian>
  31. class point_xy : public model::point<CoordinateType, 2, CoordinateSystem>
  32. {
  33. public:
  34. /// Default constructor, does not initialize anything
  35. inline point_xy()
  36. : model::point<CoordinateType, 2, CoordinateSystem>()
  37. {}
  38. /// Constructor with x/y values
  39. inline point_xy(CoordinateType const& x, CoordinateType const& y)
  40. : model::point<CoordinateType, 2, CoordinateSystem>(x, y)
  41. {}
  42. /// Get x-value
  43. inline CoordinateType const& x() const
  44. { return this->template get<0>(); }
  45. /// Get y-value
  46. inline CoordinateType const& y() const
  47. { return this->template get<1>(); }
  48. /// Set x-value
  49. inline void x(CoordinateType const& v)
  50. { this->template set<0>(v); }
  51. /// Set y-value
  52. inline void y(CoordinateType const& v)
  53. { this->template set<1>(v); }
  54. };
  55. }} // namespace model::d2
  56. // Adapt the point_xy to the concept
  57. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  58. namespace traits
  59. {
  60. template <typename CoordinateType, typename CoordinateSystem>
  61. struct tag<model::d2::point_xy<CoordinateType, CoordinateSystem> >
  62. {
  63. typedef point_tag type;
  64. };
  65. template<typename CoordinateType, typename CoordinateSystem>
  66. struct coordinate_type<model::d2::point_xy<CoordinateType, CoordinateSystem> >
  67. {
  68. typedef CoordinateType type;
  69. };
  70. template<typename CoordinateType, typename CoordinateSystem>
  71. struct coordinate_system<model::d2::point_xy<CoordinateType, CoordinateSystem> >
  72. {
  73. typedef CoordinateSystem type;
  74. };
  75. template<typename CoordinateType, typename CoordinateSystem>
  76. struct dimension<model::d2::point_xy<CoordinateType, CoordinateSystem> >
  77. : boost::mpl::int_<2>
  78. {};
  79. template<typename CoordinateType, typename CoordinateSystem, std::size_t Dimension>
  80. struct access<model::d2::point_xy<CoordinateType, CoordinateSystem>, Dimension >
  81. {
  82. static inline CoordinateType get(
  83. model::d2::point_xy<CoordinateType, CoordinateSystem> const& p)
  84. {
  85. return p.template get<Dimension>();
  86. }
  87. static inline void set(model::d2::point_xy<CoordinateType, CoordinateSystem>& p,
  88. CoordinateType const& value)
  89. {
  90. p.template set<Dimension>(value);
  91. }
  92. };
  93. } // namespace traits
  94. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  95. }} // namespace boost::geometry
  96. #endif // BOOST_GEOMETRY_GEOMETRIES_POINT_XY_HPP