cs.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_CORE_CS_HPP
  11. #define BOOST_GEOMETRY_CORE_CS_HPP
  12. #include <cstddef>
  13. #include <boost/type_traits.hpp>
  14. #include <boost/geometry/core/coordinate_system.hpp>
  15. #include <boost/geometry/core/tags.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. /*!
  19. \brief Unit of plane angle: Degrees
  20. \details Tag defining the unit of plane angle for spherical coordinate systems.
  21. This tag specifies that coordinates are defined in degrees (-180 .. 180).
  22. It has to be specified for some coordinate systems.
  23. \qbk{[include reference/core/degree_radian.qbk]}
  24. */
  25. struct degree {};
  26. /*!
  27. \brief Unit of plane angle: Radians
  28. \details Tag defining the unit of plane angle for spherical coordinate systems.
  29. This tag specifies that coordinates are defined in radians (-PI .. PI).
  30. It has to be specified for some coordinate systems.
  31. \qbk{[include reference/core/degree_radian.qbk]}
  32. */
  33. struct radian {};
  34. namespace cs
  35. {
  36. /*!
  37. \brief Cartesian coordinate system
  38. \details Defines the Cartesian or rectangular coordinate system
  39. where points are defined in 2 or 3 (or more)
  40. dimensions and usually (but not always) known as x,y,z
  41. \see http://en.wikipedia.org/wiki/Cartesian_coordinate_system
  42. \ingroup cs
  43. */
  44. struct cartesian {};
  45. /*!
  46. \brief Geographic coordinate system, in degree or in radian
  47. \details Defines the geographic coordinate system where points
  48. are defined in two angles and usually
  49. known as lat,long or lo,la or phi,lambda
  50. \see http://en.wikipedia.org/wiki/Geographic_coordinate_system
  51. \ingroup cs
  52. \note might be moved to extensions/gis/geographic
  53. */
  54. template<typename DegreeOrRadian>
  55. struct geographic
  56. {
  57. typedef DegreeOrRadian units;
  58. };
  59. /*!
  60. \brief Spherical (polar) coordinate system, in degree or in radian
  61. \details Defines the spherical coordinate system where points are
  62. defined in two angles
  63. and an optional radius usually known as r, theta, phi
  64. \par Coordinates:
  65. - coordinate 0:
  66. 0 <= phi < 2pi is the angle between the positive x-axis and the
  67. line from the origin to the P projected onto the xy-plane.
  68. - coordinate 1:
  69. 0 <= theta <= pi is the angle between the positive z-axis and the
  70. line formed between the origin and P.
  71. - coordinate 2 (if specified):
  72. r >= 0 is the distance from the origin to a given point P.
  73. \see http://en.wikipedia.org/wiki/Spherical_coordinates
  74. \ingroup cs
  75. */
  76. template<typename DegreeOrRadian>
  77. struct spherical
  78. {
  79. typedef DegreeOrRadian units;
  80. };
  81. /*!
  82. \brief Spherical equatorial coordinate system, in degree or in radian
  83. \details This one resembles the geographic coordinate system, and has latitude
  84. up from zero at the equator, to 90 at the pole
  85. (opposite to the spherical(polar) coordinate system).
  86. Used in astronomy and in GIS (but there is also the geographic)
  87. \see http://en.wikipedia.org/wiki/Spherical_coordinates
  88. \ingroup cs
  89. */
  90. template<typename DegreeOrRadian>
  91. struct spherical_equatorial
  92. {
  93. typedef DegreeOrRadian units;
  94. };
  95. /*!
  96. \brief Polar coordinate system
  97. \details Defines the polar coordinate system "in which each point
  98. on a plane is determined by an angle and a distance"
  99. \see http://en.wikipedia.org/wiki/Polar_coordinates
  100. \ingroup cs
  101. */
  102. template<typename DegreeOrRadian>
  103. struct polar
  104. {
  105. typedef DegreeOrRadian units;
  106. };
  107. } // namespace cs
  108. namespace traits
  109. {
  110. /*!
  111. \brief Traits class defining coordinate system tag, bound to coordinate system
  112. \ingroup traits
  113. \tparam CoordinateSystem coordinate system
  114. */
  115. template <typename CoordinateSystem>
  116. struct cs_tag
  117. {
  118. };
  119. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  120. template<typename DegreeOrRadian>
  121. struct cs_tag<cs::geographic<DegreeOrRadian> >
  122. {
  123. typedef geographic_tag type;
  124. };
  125. template<typename DegreeOrRadian>
  126. struct cs_tag<cs::spherical<DegreeOrRadian> >
  127. {
  128. typedef spherical_polar_tag type;
  129. };
  130. template<typename DegreeOrRadian>
  131. struct cs_tag<cs::spherical_equatorial<DegreeOrRadian> >
  132. {
  133. typedef spherical_equatorial_tag type;
  134. };
  135. template<>
  136. struct cs_tag<cs::cartesian>
  137. {
  138. typedef cartesian_tag type;
  139. };
  140. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  141. } // namespace traits
  142. /*!
  143. \brief Meta-function returning coordinate system tag (cs family) of any geometry
  144. \ingroup core
  145. */
  146. template <typename G>
  147. struct cs_tag
  148. {
  149. typedef typename traits::cs_tag
  150. <
  151. typename geometry::coordinate_system<G>::type
  152. >::type type;
  153. };
  154. /*!
  155. \brief Meta-function to verify if a coordinate system is radian
  156. \ingroup core
  157. */
  158. template <typename CoordinateSystem>
  159. struct is_radian : boost::true_type {};
  160. #ifndef DOXYGEN_NO_SPECIALIZATIONS
  161. // Specialization for any degree coordinate systems
  162. template <template<typename> class CoordinateSystem>
  163. struct is_radian< CoordinateSystem<degree> > : boost::false_type
  164. {
  165. };
  166. #endif // DOXYGEN_NO_SPECIALIZATIONS
  167. }} // namespace boost::geometry
  168. #endif // BOOST_GEOMETRY_CORE_CS_HPP