point_xyz.hpp 4.2 KB

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