point_xyz.hpp 3.6 KB

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