cs.hpp 7.7 KB

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