cs.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.
  6. // Modifications copyright (c) 2014, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_CORE_CS_HPP
  14. #define BOOST_GEOMETRY_CORE_CS_HPP
  15. #include <cstddef>
  16. #include <boost/mpl/assert.hpp>
  17. #include <boost/type_traits/integral_constant.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 coordinate_system_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 coordinate_system_units<geometry::degree>
  51. {
  52. typedef geometry::degree units;
  53. };
  54. template <>
  55. struct coordinate_system_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. {
  84. typedef typename core_detail::coordinate_system_units
  85. <
  86. DegreeOrRadian
  87. >::units units;
  88. };
  89. /*!
  90. \brief Spherical (polar) coordinate system, in degree or in radian
  91. \details Defines the spherical coordinate system where points are
  92. defined in two angles
  93. and an optional radius usually known as r, theta, phi
  94. \par Coordinates:
  95. - coordinate 0:
  96. 0 <= phi < 2pi is the angle between the positive x-axis and the
  97. line from the origin to the P projected onto the xy-plane.
  98. - coordinate 1:
  99. 0 <= theta <= pi is the angle between the positive z-axis and the
  100. line formed between the origin and P.
  101. - coordinate 2 (if specified):
  102. r >= 0 is the distance from the origin to a given point P.
  103. \see http://en.wikipedia.org/wiki/Spherical_coordinates
  104. \ingroup cs
  105. */
  106. template<typename DegreeOrRadian>
  107. struct spherical
  108. {
  109. typedef typename core_detail::coordinate_system_units
  110. <
  111. DegreeOrRadian
  112. >::units units;
  113. };
  114. /*!
  115. \brief Spherical equatorial coordinate system, in degree or in radian
  116. \details This one resembles the geographic coordinate system, and has latitude
  117. up from zero at the equator, to 90 at the pole
  118. (opposite to the spherical(polar) coordinate system).
  119. Used in astronomy and in GIS (but there is also the geographic)
  120. \see http://en.wikipedia.org/wiki/Spherical_coordinates
  121. \ingroup cs
  122. */
  123. template<typename DegreeOrRadian>
  124. struct spherical_equatorial
  125. {
  126. typedef typename core_detail::coordinate_system_units
  127. <
  128. DegreeOrRadian
  129. >::units units;
  130. };
  131. /*!
  132. \brief Polar coordinate system
  133. \details Defines the polar coordinate system "in which each point
  134. on a plane is determined by an angle and a distance"
  135. \see http://en.wikipedia.org/wiki/Polar_coordinates
  136. \ingroup cs
  137. */
  138. template<typename DegreeOrRadian>
  139. struct polar
  140. {
  141. typedef typename core_detail::coordinate_system_units
  142. <
  143. DegreeOrRadian
  144. >::units units;
  145. };
  146. } // namespace cs
  147. namespace traits
  148. {
  149. /*!
  150. \brief Traits class defining coordinate system tag, bound to coordinate system
  151. \ingroup traits
  152. \tparam CoordinateSystem coordinate system
  153. */
  154. template <typename CoordinateSystem>
  155. struct cs_tag
  156. {
  157. };
  158. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  159. template<typename DegreeOrRadian>
  160. struct cs_tag<cs::geographic<DegreeOrRadian> >
  161. {
  162. typedef geographic_tag type;
  163. };
  164. template<typename DegreeOrRadian>
  165. struct cs_tag<cs::spherical<DegreeOrRadian> >
  166. {
  167. typedef spherical_polar_tag type;
  168. };
  169. template<typename DegreeOrRadian>
  170. struct cs_tag<cs::spherical_equatorial<DegreeOrRadian> >
  171. {
  172. typedef spherical_equatorial_tag type;
  173. };
  174. template<>
  175. struct cs_tag<cs::cartesian>
  176. {
  177. typedef cartesian_tag type;
  178. };
  179. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  180. } // namespace traits
  181. /*!
  182. \brief Meta-function returning coordinate system tag (cs family) of any geometry
  183. \tparam Geometry \tparam_geometry
  184. \ingroup core
  185. */
  186. template <typename Geometry>
  187. struct cs_tag
  188. {
  189. typedef typename traits::cs_tag
  190. <
  191. typename geometry::coordinate_system<Geometry>::type
  192. >::type type;
  193. };
  194. /*!
  195. \brief Meta-function to verify if a coordinate system is radian
  196. \tparam CoordinateSystem Any coordinate system.
  197. \ingroup core
  198. */
  199. template <typename CoordinateSystem>
  200. struct is_radian : boost::true_type {};
  201. #ifndef DOXYGEN_NO_SPECIALIZATIONS
  202. // Specialization for any degree coordinate systems
  203. template <template<typename> class CoordinateSystem>
  204. struct is_radian< CoordinateSystem<degree> > : boost::false_type
  205. {
  206. };
  207. #endif // DOXYGEN_NO_SPECIALIZATIONS
  208. }} // namespace boost::geometry
  209. #endif // BOOST_GEOMETRY_CORE_CS_HPP