cs.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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, 2018.
  6. // Modifications copyright (c) 2014-2018, 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/mpl/assert.hpp>
  18. #include <boost/geometry/core/coordinate_system.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_MPL_ASSERT_MSG
  45. ((false),
  46. COORDINATE_SYSTEM_UNITS_MUST_BE_DEGREES_OR_RADIANS,
  47. (types<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. typedef geographic_tag type;
  152. };
  153. template<typename DegreeOrRadian>
  154. struct cs_tag<cs::spherical<DegreeOrRadian> >
  155. {
  156. typedef spherical_polar_tag type;
  157. };
  158. template<typename DegreeOrRadian>
  159. struct cs_tag<cs::spherical_equatorial<DegreeOrRadian> >
  160. {
  161. typedef spherical_equatorial_tag type;
  162. };
  163. template<>
  164. struct cs_tag<cs::cartesian>
  165. {
  166. typedef cartesian_tag type;
  167. };
  168. template <>
  169. struct cs_tag<cs::undefined>
  170. {
  171. typedef cs_undefined_tag type;
  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. typedef typename traits::cs_tag
  184. <
  185. typename geometry::coordinate_system<Geometry>::type
  186. >::type type;
  187. };
  188. namespace traits
  189. {
  190. // cartesian or undefined
  191. template <typename CoordinateSystem>
  192. struct cs_angular_units
  193. {
  194. typedef geometry::radian type;
  195. };
  196. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  197. template<typename DegreeOrRadian>
  198. struct cs_angular_units<cs::geographic<DegreeOrRadian> >
  199. {
  200. typedef DegreeOrRadian type;
  201. };
  202. template<typename DegreeOrRadian>
  203. struct cs_angular_units<cs::spherical<DegreeOrRadian> >
  204. {
  205. typedef DegreeOrRadian type;
  206. };
  207. template<typename DegreeOrRadian>
  208. struct cs_angular_units<cs::spherical_equatorial<DegreeOrRadian> >
  209. {
  210. typedef DegreeOrRadian type;
  211. };
  212. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  213. } // namespace traits
  214. #ifndef DOXYGEN_NO_DETAIL
  215. namespace detail
  216. {
  217. template <typename Geometry>
  218. struct cs_angular_units
  219. {
  220. typedef typename traits::cs_angular_units
  221. <
  222. typename geometry::coordinate_system<Geometry>::type
  223. >::type type;
  224. };
  225. template <typename Units, typename CsTag>
  226. struct cs_tag_to_coordinate_system
  227. {
  228. BOOST_MPL_ASSERT_MSG((false),
  229. NOT_IMPLEMENTED_FOR_THIS_COORDINATE_SYSTEM,
  230. (types<CsTag>));
  231. };
  232. template <typename Units>
  233. struct cs_tag_to_coordinate_system<Units, cs_undefined_tag>
  234. {
  235. typedef cs::undefined type;
  236. };
  237. template <typename Units>
  238. struct cs_tag_to_coordinate_system<Units, cartesian_tag>
  239. {
  240. typedef cs::cartesian type;
  241. };
  242. template <typename Units>
  243. struct cs_tag_to_coordinate_system<Units, spherical_equatorial_tag>
  244. {
  245. typedef cs::spherical_equatorial<Units> type;
  246. };
  247. template <typename Units>
  248. struct cs_tag_to_coordinate_system<Units, spherical_polar_tag>
  249. {
  250. typedef cs::spherical<Units> type;
  251. };
  252. template <typename Units>
  253. struct cs_tag_to_coordinate_system<Units, geographic_tag>
  254. {
  255. typedef cs::geographic<Units> type;
  256. };
  257. } // namespace detail
  258. #endif // DOXYGEN_NO_DETAIL
  259. }} // namespace boost::geometry
  260. #endif // BOOST_GEOMETRY_CORE_CS_HPP