point_concept.hpp 5.4 KB

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