point_xy.hpp 4.1 KB

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