cs.hpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2024 Adam Wulkiewicz, Lodz, Poland.
  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_CORE_CS_HPP
  16. #define BOOST_GEOMETRY_CORE_CS_HPP
  17. #include <cstddef>
  18. #include <boost/geometry/core/coordinate_system.hpp>
  19. #include <boost/geometry/core/static_assert.hpp>
  20. #include <boost/geometry/core/tags.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. /*!
  24. \brief Unit of plane angle: Degrees
  25. \details Tag defining the unit of plane angle for spherical coordinate systems.
  26. This tag specifies that coordinates are defined in degrees (-180 .. 180).
  27. It has to be specified for some coordinate systems.
  28. \qbk{[include reference/core/degree_radian.qbk]}
  29. */
  30. struct degree {};
  31. /*!
  32. \brief Unit of plane angle: Radians
  33. \details Tag defining the unit of plane angle for spherical coordinate systems.
  34. This tag specifies that coordinates are defined in radians (-PI .. PI).
  35. It has to be specified for some coordinate systems.
  36. \qbk{[include reference/core/degree_radian.qbk]}
  37. */
  38. struct radian {};
  39. #ifndef DOXYGEN_NO_DETAIL
  40. namespace core_detail
  41. {
  42. template <typename DegreeOrRadian>
  43. struct define_angular_units
  44. {
  45. BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
  46. "Coordinate system unit must be degree or radian.",
  47. DegreeOrRadian);
  48. };
  49. template <>
  50. struct define_angular_units<geometry::degree>
  51. {
  52. typedef geometry::degree units;
  53. };
  54. template <>
  55. struct define_angular_units<geometry::radian>
  56. {
  57. typedef geometry::radian units;
  58. };
  59. } // namespace core_detail
  60. #endif // DOXYGEN_NO_DETAIL
  61. namespace cs
  62. {
  63. /*!
  64. \brief Cartesian coordinate system
  65. \details Defines the Cartesian or rectangular coordinate system
  66. where points are defined in 2 or 3 (or more)
  67. dimensions and usually (but not always) known as x,y,z
  68. \see http://en.wikipedia.org/wiki/Cartesian_coordinate_system
  69. \ingroup cs
  70. */
  71. struct cartesian {};
  72. /*!
  73. \brief Geographic coordinate system, in degree or in radian
  74. \details Defines the geographic coordinate system where points
  75. are defined in two angles and usually
  76. known as lat,long or lo,la or phi,lambda
  77. \see http://en.wikipedia.org/wiki/Geographic_coordinate_system
  78. \ingroup cs
  79. \note might be moved to extensions/gis/geographic
  80. */
  81. template<typename DegreeOrRadian>
  82. struct geographic
  83. : core_detail::define_angular_units<DegreeOrRadian>
  84. {};
  85. /*!
  86. \brief Spherical (polar) coordinate system, in degree or in radian
  87. \details Defines the spherical coordinate system where points are
  88. defined in two angles
  89. and an optional radius usually known as r, theta, phi
  90. \par Coordinates:
  91. - coordinate 0:
  92. 0 <= phi < 2pi is the angle between the positive x-axis and the
  93. line from the origin to the P projected onto the xy-plane.
  94. - coordinate 1:
  95. 0 <= theta <= pi is the angle between the positive z-axis and the
  96. line formed between the origin and P.
  97. - coordinate 2 (if specified):
  98. r >= 0 is the distance from the origin to a given point P.
  99. \see http://en.wikipedia.org/wiki/Spherical_coordinates
  100. \ingroup cs
  101. */
  102. template<typename DegreeOrRadian>
  103. struct spherical
  104. : core_detail::define_angular_units<DegreeOrRadian>
  105. {};
  106. /*!
  107. \brief Spherical equatorial coordinate system, in degree or in radian
  108. \details This one resembles the geographic coordinate system, and has latitude
  109. up from zero at the equator, to 90 at the pole
  110. (opposite to the spherical (polar) coordinate system).
  111. Used in astronomy and in GIS (but there is also the geographic)
  112. \see http://en.wikipedia.org/wiki/Spherical_coordinates
  113. \ingroup cs
  114. */
  115. template<typename DegreeOrRadian>
  116. struct spherical_equatorial
  117. : core_detail::define_angular_units<DegreeOrRadian>
  118. {};
  119. /*!
  120. \brief Polar coordinate system
  121. \details Defines the polar coordinate system "in which each point
  122. on a plane is determined by an angle and a distance"
  123. \see http://en.wikipedia.org/wiki/Polar_coordinates
  124. \ingroup cs
  125. */
  126. template<typename DegreeOrRadian>
  127. struct polar
  128. : core_detail::define_angular_units<DegreeOrRadian>
  129. {};
  130. /*!
  131. \brief Undefined coordinate system
  132. \ingroup cs
  133. */
  134. struct undefined {};
  135. } // namespace cs
  136. namespace traits
  137. {
  138. /*!
  139. \brief Traits class defining coordinate system tag, bound to coordinate system
  140. \ingroup traits
  141. \tparam CoordinateSystem coordinate system
  142. */
  143. template <typename CoordinateSystem>
  144. struct cs_tag
  145. {
  146. };
  147. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  148. template<typename DegreeOrRadian>
  149. struct cs_tag<cs::geographic<DegreeOrRadian> >
  150. {
  151. using type = geographic_tag;
  152. };
  153. template<typename DegreeOrRadian>
  154. struct cs_tag<cs::spherical<DegreeOrRadian> >
  155. {
  156. using type = spherical_polar_tag;
  157. };
  158. template<typename DegreeOrRadian>
  159. struct cs_tag<cs::spherical_equatorial<DegreeOrRadian> >
  160. {
  161. using type = spherical_equatorial_tag;
  162. };
  163. template<>
  164. struct cs_tag<cs::cartesian>
  165. {
  166. using type = cartesian_tag;
  167. };
  168. template <>
  169. struct cs_tag<cs::undefined>
  170. {
  171. using type = cs_undefined_tag;
  172. };
  173. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  174. } // namespace traits
  175. /*!
  176. \brief Meta-function returning coordinate system tag (cs family) of any geometry
  177. \tparam Geometry \tparam_geometry
  178. \ingroup core
  179. */
  180. template <typename Geometry>
  181. struct cs_tag
  182. {
  183. using type = typename traits::cs_tag
  184. <
  185. geometry::coordinate_system_t<Geometry>
  186. >::type;
  187. };
  188. template <typename Geometry>
  189. using cs_tag_t = typename cs_tag<Geometry>::type;
  190. namespace traits
  191. {
  192. // cartesian or undefined
  193. template <typename CoordinateSystem>
  194. struct cs_angular_units
  195. {
  196. using type = geometry::radian;
  197. };
  198. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  199. template<typename DegreeOrRadian>
  200. struct cs_angular_units<cs::geographic<DegreeOrRadian> >
  201. {
  202. using type = DegreeOrRadian;
  203. };
  204. template<typename DegreeOrRadian>
  205. struct cs_angular_units<cs::spherical<DegreeOrRadian> >
  206. {
  207. using type = DegreeOrRadian;
  208. };
  209. template<typename DegreeOrRadian>
  210. struct cs_angular_units<cs::spherical_equatorial<DegreeOrRadian> >
  211. {
  212. using type = DegreeOrRadian;
  213. };
  214. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  215. } // namespace traits
  216. #ifndef DOXYGEN_NO_DETAIL
  217. namespace detail
  218. {
  219. template <typename Geometry>
  220. struct cs_angular_units
  221. {
  222. using type = typename traits::cs_angular_units
  223. <
  224. geometry::coordinate_system_t<Geometry>
  225. >::type;
  226. };
  227. template <typename Geometry>
  228. using cs_angular_units_t = typename cs_angular_units<Geometry>::type;
  229. template <typename Units, typename CsTag>
  230. struct cs_tag_to_coordinate_system
  231. {
  232. BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
  233. "Not implemented for this coordinate system.",
  234. Units, CsTag);
  235. };
  236. template <typename Units>
  237. struct cs_tag_to_coordinate_system<Units, cs_undefined_tag>
  238. {
  239. using type = cs::undefined;
  240. };
  241. template <typename Units>
  242. struct cs_tag_to_coordinate_system<Units, cartesian_tag>
  243. {
  244. using type = cs::cartesian;
  245. };
  246. template <typename Units>
  247. struct cs_tag_to_coordinate_system<Units, spherical_equatorial_tag>
  248. {
  249. using type = cs::spherical_equatorial<Units>;
  250. };
  251. template <typename Units>
  252. struct cs_tag_to_coordinate_system<Units, spherical_polar_tag>
  253. {
  254. using type = cs::spherical<Units>;
  255. };
  256. template <typename Units>
  257. struct cs_tag_to_coordinate_system<Units, geographic_tag>
  258. {
  259. using type = cs::geographic<Units>;
  260. };
  261. template <typename Units, typename CsTag>
  262. using cs_tag_to_coordinate_system_t = typename cs_tag_to_coordinate_system<Units, CsTag>::type;
  263. } // namespace detail
  264. #endif // DOXYGEN_NO_DETAIL
  265. }} // namespace boost::geometry
  266. #endif // BOOST_GEOMETRY_CORE_CS_HPP