helper_geometry.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2015, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_GEOMETRIES_HELPER_GEOMETRY_HPP
  7. #define BOOST_GEOMETRY_GEOMETRIES_HELPER_GEOMETRY_HPP
  8. #include <boost/geometry/core/cs.hpp>
  9. #include <boost/geometry/core/coordinate_dimension.hpp>
  10. #include <boost/geometry/core/coordinate_type.hpp>
  11. #include <boost/geometry/core/point_type.hpp>
  12. #include <boost/geometry/core/tag.hpp>
  13. #include <boost/geometry/core/tags.hpp>
  14. #include <boost/geometry/geometries/box.hpp>
  15. #include <boost/geometry/geometries/point.hpp>
  16. #include <boost/geometry/algorithms/not_implemented.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace detail { namespace helper_geometries
  20. {
  21. template <typename Geometry, typename CS_Tag = typename cs_tag<Geometry>::type>
  22. struct default_units
  23. {
  24. typedef typename coordinate_system<Geometry>::type::units type;
  25. };
  26. // The Cartesian coordinate system does not define the type units.
  27. // For that reason the generic implementation for default_units cannot be used
  28. // and specialization needs to be defined.
  29. // Moreover, it makes sense to define the units for the Cartesian
  30. // coordinate system to be radians, as this way a Cartesian point can
  31. // potentially be used in algorithms taking non-Cartesian strategies
  32. // and work as if it was as point in the non-Cartesian coordinate
  33. // system with radian units.
  34. template <typename Geometry>
  35. struct default_units<Geometry, cartesian_tag>
  36. {
  37. typedef radian type;
  38. };
  39. template <typename Units, typename CS_Tag>
  40. struct cs_tag_to_coordinate_system
  41. {
  42. typedef cs::cartesian type;
  43. };
  44. template <typename Units>
  45. struct cs_tag_to_coordinate_system<Units, spherical_equatorial_tag>
  46. {
  47. typedef cs::spherical_equatorial<Units> type;
  48. };
  49. template <typename Units>
  50. struct cs_tag_to_coordinate_system<Units, spherical_tag>
  51. {
  52. typedef cs::spherical<Units> type;
  53. };
  54. template <typename Units>
  55. struct cs_tag_to_coordinate_system<Units, geographic_tag>
  56. {
  57. typedef cs::geographic<Units> type;
  58. };
  59. template
  60. <
  61. typename Point,
  62. typename NewCoordinateType,
  63. typename NewUnits,
  64. typename CS_Tag = typename cs_tag<Point>::type
  65. >
  66. struct helper_point
  67. {
  68. typedef model::point
  69. <
  70. NewCoordinateType,
  71. dimension<Point>::value,
  72. typename cs_tag_to_coordinate_system<NewUnits, CS_Tag>::type
  73. > type;
  74. };
  75. }} // detail::helper_geometries
  76. namespace detail_dispatch
  77. {
  78. template
  79. <
  80. typename Geometry,
  81. typename NewCoordinateType,
  82. typename NewUnits,
  83. typename Tag = typename tag<Geometry>::type>
  84. struct helper_geometry : not_implemented<Geometry>
  85. {};
  86. template <typename Point, typename NewCoordinateType, typename NewUnits>
  87. struct helper_geometry<Point, NewCoordinateType, NewUnits, point_tag>
  88. {
  89. typedef typename detail::helper_geometries::helper_point
  90. <
  91. Point, NewCoordinateType, NewUnits
  92. >::type type;
  93. };
  94. template <typename Box, typename NewCoordinateType, typename NewUnits>
  95. struct helper_geometry<Box, NewCoordinateType, NewUnits, box_tag>
  96. {
  97. typedef model::box
  98. <
  99. typename helper_geometry
  100. <
  101. typename point_type<Box>::type, NewCoordinateType, NewUnits
  102. >::type
  103. > type;
  104. };
  105. } // detail_dispatch
  106. // Meta-function that provides a new helper geometry of the same kind as
  107. // the input geometry and the same coordinate system type,
  108. // but with a possibly different coordinate type and coordinate system units
  109. template
  110. <
  111. typename Geometry,
  112. typename NewCoordinateType = typename coordinate_type<Geometry>::type,
  113. typename NewUnits = typename detail::helper_geometries::default_units
  114. <
  115. Geometry
  116. >::type
  117. >
  118. struct helper_geometry
  119. {
  120. typedef typename detail_dispatch::helper_geometry
  121. <
  122. Geometry, NewCoordinateType, NewUnits
  123. >::type type;
  124. };
  125. }} // namespace boost::geometry
  126. #endif // BOOST_GEOMETRY_GEOMETRIES_HELPER_GEOMETRY_HPP