point_concept.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. //
  3. // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2008-2014 Barend Gehrels, Amsterdam, the Netherlands.
  5. // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
  6. // This file was modified by Oracle on 2014-2020.
  7. // Modifications copyright (c) 2014-2020, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP
  16. #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP
  17. #include <cstddef>
  18. #include <boost/concept_check.hpp>
  19. #include <boost/core/ignore_unused.hpp>
  20. #include <boost/geometry/core/access.hpp>
  21. #include <boost/geometry/core/coordinate_dimension.hpp>
  22. #include <boost/geometry/core/coordinate_system.hpp>
  23. namespace boost { namespace geometry { namespace concepts
  24. {
  25. /*!
  26. \brief Point concept.
  27. \ingroup concepts
  28. \par Formal definition:
  29. The point concept is defined as following:
  30. - there must be a specialization of traits::tag defining point_tag as type
  31. - there must be a specialization of traits::coordinate_type defining the type
  32. of its coordinates
  33. - there must be a specialization of traits::coordinate_system defining its
  34. coordinate system (cartesian, spherical, etc)
  35. - there must be a specialization of traits::dimension defining its number
  36. of dimensions (2, 3, ...) (derive it conveniently
  37. from std::integral_constant&lt;std::size_t, X&gt; for X-D)
  38. - there must be a specialization of traits::access, per dimension,
  39. with two functions:
  40. - \b get to get a coordinate value
  41. - \b set to set a coordinate value (this one is not checked for ConstPoint)
  42. - for non-Cartesian coordinate systems, the coordinate system's units
  43. must either be boost::geometry::degree or boost::geometry::radian
  44. \par Example:
  45. A legacy point, defining the necessary specializations to fulfil to the concept.
  46. Suppose that the following point is defined:
  47. \dontinclude doxygen_5.cpp
  48. \skip legacy_point1
  49. \until };
  50. It can then be adapted to the concept as following:
  51. \dontinclude doxygen_5.cpp
  52. \skip adapt legacy_point1
  53. \until }}
  54. Note that it is done like above to show the system. Users will normally use the registration macro.
  55. \par Example:
  56. A read-only legacy point, using a macro to fulfil to the ConstPoint concept.
  57. It cannot be modified by the library but can be used in all algorithms where
  58. points are not modified.
  59. The point looks like the following:
  60. \dontinclude doxygen_5.cpp
  61. \skip legacy_point2
  62. \until };
  63. It uses the macro as following:
  64. \dontinclude doxygen_5.cpp
  65. \skip adapt legacy_point2
  66. \until end adaptation
  67. */
  68. template <typename Geometry>
  69. class Point
  70. {
  71. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  72. typedef typename coordinate_type<Geometry>::type ctype;
  73. typedef typename coordinate_system<Geometry>::type csystem;
  74. // The following enum is used to fully instantiate the coordinate
  75. // system class; this is needed in order to check the units passed
  76. // to it for non-Cartesian coordinate systems.
  77. enum { cs_check = sizeof(csystem) };
  78. enum { ccount = dimension<Geometry>::value };
  79. template <typename P, std::size_t Dimension, std::size_t DimensionCount>
  80. struct dimension_checker
  81. {
  82. static void apply()
  83. {
  84. P* p = 0;
  85. geometry::set<Dimension>(*p, geometry::get<Dimension>(*p));
  86. dimension_checker<P, Dimension+1, DimensionCount>::apply();
  87. }
  88. };
  89. template <typename P, std::size_t DimensionCount>
  90. struct dimension_checker<P, DimensionCount, DimensionCount>
  91. {
  92. static void apply() {}
  93. };
  94. public:
  95. /// BCCL macro to apply the Point concept
  96. BOOST_CONCEPT_USAGE(Point)
  97. {
  98. dimension_checker<Geometry, 0, ccount>::apply();
  99. }
  100. #endif
  101. };
  102. /*!
  103. \brief point concept (const version).
  104. \ingroup const_concepts
  105. \details The ConstPoint concept apply the same as the Point concept,
  106. but does not apply write access.
  107. */
  108. template <typename Geometry>
  109. class ConstPoint
  110. {
  111. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  112. typedef typename coordinate_type<Geometry>::type ctype;
  113. typedef typename coordinate_system<Geometry>::type csystem;
  114. // The following enum is used to fully instantiate the coordinate
  115. // system class; this is needed in order to check the units passed
  116. // to it for non-Cartesian coordinate systems.
  117. enum { cs_check = sizeof(csystem) };
  118. enum { ccount = dimension<Geometry>::value };
  119. template <typename P, std::size_t Dimension, std::size_t DimensionCount>
  120. struct dimension_checker
  121. {
  122. static void apply()
  123. {
  124. const P* p = 0;
  125. ctype coord(geometry::get<Dimension>(*p));
  126. boost::ignore_unused(p, coord);
  127. dimension_checker<P, Dimension+1, DimensionCount>::apply();
  128. }
  129. };
  130. template <typename P, std::size_t DimensionCount>
  131. struct dimension_checker<P, DimensionCount, DimensionCount>
  132. {
  133. static void apply() {}
  134. };
  135. public:
  136. /// BCCL macro to apply the ConstPoint concept
  137. BOOST_CONCEPT_USAGE(ConstPoint)
  138. {
  139. dimension_checker<Geometry, 0, ccount>::apply();
  140. }
  141. #endif
  142. };
  143. }}} // namespace boost::geometry::concepts
  144. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP