• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
6 
7 // This file was modified by Oracle on 2014, 2018.
8 // Modifications copyright (c) 2014-2018, Oracle and/or its affiliates.
9 
10 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 
16 // Use, modification and distribution is subject to the Boost Software License,
17 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
19 
20 #ifndef BOOST_GEOMETRY_CORE_CS_HPP
21 #define BOOST_GEOMETRY_CORE_CS_HPP
22 
23 #include <cstddef>
24 
25 #include <boost/mpl/assert.hpp>
26 
27 #include <boost/geometry/core/coordinate_system.hpp>
28 #include <boost/geometry/core/tags.hpp>
29 
30 
31 namespace boost { namespace geometry
32 {
33 
34 /*!
35 \brief Unit of plane angle: Degrees
36 \details Tag defining the unit of plane angle for spherical coordinate systems.
37     This tag specifies that coordinates are defined in degrees (-180 .. 180).
38     It has to be specified for some coordinate systems.
39 \qbk{[include reference/core/degree_radian.qbk]}
40 */
41 struct degree {};
42 
43 
44 /*!
45 \brief Unit of plane angle: Radians
46 \details Tag defining the unit of plane angle for spherical coordinate systems.
47     This tag specifies that coordinates are defined in radians (-PI .. PI).
48     It has to be specified for some coordinate systems.
49 \qbk{[include reference/core/degree_radian.qbk]}
50 */
51 struct radian {};
52 
53 
54 #ifndef DOXYGEN_NO_DETAIL
55 namespace core_detail
56 {
57 
58 template <typename DegreeOrRadian>
59 struct define_angular_units
60 {
61     BOOST_MPL_ASSERT_MSG
62         ((false),
63          COORDINATE_SYSTEM_UNITS_MUST_BE_DEGREES_OR_RADIANS,
64          (types<DegreeOrRadian>));
65 };
66 
67 template <>
68 struct define_angular_units<geometry::degree>
69 {
70     typedef geometry::degree units;
71 };
72 
73 template <>
74 struct define_angular_units<geometry::radian>
75 {
76     typedef geometry::radian units;
77 };
78 
79 } // namespace core_detail
80 #endif // DOXYGEN_NO_DETAIL
81 
82 
83 namespace cs
84 {
85 
86 /*!
87 \brief Cartesian coordinate system
88 \details Defines the Cartesian or rectangular coordinate system
89     where points are defined in 2 or 3 (or more)
90 dimensions and usually (but not always) known as x,y,z
91 \see http://en.wikipedia.org/wiki/Cartesian_coordinate_system
92 \ingroup cs
93 */
94 struct cartesian {};
95 
96 
97 
98 
99 /*!
100 \brief Geographic coordinate system, in degree or in radian
101 \details Defines the geographic coordinate system where points
102     are defined in two angles and usually
103 known as lat,long or lo,la or phi,lambda
104 \see http://en.wikipedia.org/wiki/Geographic_coordinate_system
105 \ingroup cs
106 \note might be moved to extensions/gis/geographic
107 */
108 template<typename DegreeOrRadian>
109 struct geographic
110     : core_detail::define_angular_units<DegreeOrRadian>
111 {};
112 
113 
114 
115 /*!
116 \brief Spherical (polar) coordinate system, in degree or in radian
117 \details Defines the spherical coordinate system where points are
118     defined in two angles
119     and an optional radius usually known as r, theta, phi
120 \par Coordinates:
121 - coordinate 0:
122     0 <= phi < 2pi is the angle between the positive x-axis and the
123         line from the origin to the P projected onto the xy-plane.
124 - coordinate 1:
125     0 <= theta <= pi is the angle between the positive z-axis and the
126         line formed between the origin and P.
127 - coordinate 2 (if specified):
128     r >= 0 is the distance from the origin to a given point P.
129 
130 \see http://en.wikipedia.org/wiki/Spherical_coordinates
131 \ingroup cs
132 */
133 template<typename DegreeOrRadian>
134 struct spherical
135     : core_detail::define_angular_units<DegreeOrRadian>
136 {};
137 
138 
139 /*!
140 \brief Spherical equatorial coordinate system, in degree or in radian
141 \details This one resembles the geographic coordinate system, and has latitude
142     up from zero at the equator, to 90 at the pole
143     (opposite to the spherical(polar) coordinate system).
144     Used in astronomy and in GIS (but there is also the geographic)
145 
146 \see http://en.wikipedia.org/wiki/Spherical_coordinates
147 \ingroup cs
148 */
149 template<typename DegreeOrRadian>
150 struct spherical_equatorial
151     : core_detail::define_angular_units<DegreeOrRadian>
152 {};
153 
154 
155 
156 /*!
157 \brief Polar coordinate system
158 \details Defines the polar coordinate system "in which each point
159     on a plane is determined by an angle and a distance"
160 \see http://en.wikipedia.org/wiki/Polar_coordinates
161 \ingroup cs
162 */
163 template<typename DegreeOrRadian>
164 struct polar
165     : core_detail::define_angular_units<DegreeOrRadian>
166 {};
167 
168 
169 /*!
170 \brief Undefined coordinate system
171 \ingroup cs
172 */
173 struct undefined {};
174 
175 
176 } // namespace cs
177 
178 
179 namespace traits
180 {
181 
182 /*!
183 \brief Traits class defining coordinate system tag, bound to coordinate system
184 \ingroup traits
185 \tparam CoordinateSystem coordinate system
186 */
187 template <typename CoordinateSystem>
188 struct cs_tag
189 {
190 };
191 
192 
193 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
194 
195 template<typename DegreeOrRadian>
196 struct cs_tag<cs::geographic<DegreeOrRadian> >
197 {
198     typedef geographic_tag type;
199 };
200 
201 template<typename DegreeOrRadian>
202 struct cs_tag<cs::spherical<DegreeOrRadian> >
203 {
204     typedef spherical_polar_tag type;
205 };
206 
207 template<typename DegreeOrRadian>
208 struct cs_tag<cs::spherical_equatorial<DegreeOrRadian> >
209 {
210     typedef spherical_equatorial_tag type;
211 };
212 
213 
214 template<>
215 struct cs_tag<cs::cartesian>
216 {
217     typedef cartesian_tag type;
218 };
219 
220 
221 template <>
222 struct cs_tag<cs::undefined>
223 {
224     typedef cs_undefined_tag type;
225 };
226 
227 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
228 
229 
230 } // namespace traits
231 
232 
233 /*!
234 \brief Meta-function returning coordinate system tag (cs family) of any geometry
235 \tparam Geometry \tparam_geometry
236 \ingroup core
237 */
238 template <typename Geometry>
239 struct cs_tag
240 {
241     typedef typename traits::cs_tag
242         <
243             typename geometry::coordinate_system<Geometry>::type
244         >::type type;
245 };
246 
247 
248 namespace traits
249 {
250 
251 // cartesian or undefined
252 template <typename CoordinateSystem>
253 struct cs_angular_units
254 {
255     typedef geometry::radian type;
256 };
257 
258 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
259 
260 template<typename DegreeOrRadian>
261 struct cs_angular_units<cs::geographic<DegreeOrRadian> >
262 {
263     typedef DegreeOrRadian type;
264 };
265 
266 template<typename DegreeOrRadian>
267 struct cs_angular_units<cs::spherical<DegreeOrRadian> >
268 {
269     typedef DegreeOrRadian type;
270 };
271 
272 template<typename DegreeOrRadian>
273 struct cs_angular_units<cs::spherical_equatorial<DegreeOrRadian> >
274 {
275     typedef DegreeOrRadian type;
276 };
277 
278 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
279 
280 
281 } // namespace traits
282 
283 
284 #ifndef DOXYGEN_NO_DETAIL
285 namespace detail
286 {
287 
288 template <typename Geometry>
289 struct cs_angular_units
290 {
291     typedef typename traits::cs_angular_units
292         <
293             typename geometry::coordinate_system<Geometry>::type
294         >::type type;
295 };
296 
297 
298 template <typename Units, typename CsTag>
299 struct cs_tag_to_coordinate_system
300 {
301     BOOST_MPL_ASSERT_MSG((false),
302                          NOT_IMPLEMENTED_FOR_THIS_COORDINATE_SYSTEM,
303                          (types<CsTag>));
304 };
305 
306 template <typename Units>
307 struct cs_tag_to_coordinate_system<Units, cs_undefined_tag>
308 {
309     typedef cs::undefined type;
310 };
311 
312 template <typename Units>
313 struct cs_tag_to_coordinate_system<Units, cartesian_tag>
314 {
315     typedef cs::cartesian type;
316 };
317 
318 template <typename Units>
319 struct cs_tag_to_coordinate_system<Units, spherical_equatorial_tag>
320 {
321     typedef cs::spherical_equatorial<Units> type;
322 };
323 
324 template <typename Units>
325 struct cs_tag_to_coordinate_system<Units, spherical_polar_tag>
326 {
327     typedef cs::spherical<Units> type;
328 };
329 
330 template <typename Units>
331 struct cs_tag_to_coordinate_system<Units, geographic_tag>
332 {
333     typedef cs::geographic<Units> type;
334 };
335 
336 } // namespace detail
337 #endif // DOXYGEN_NO_DETAIL
338 
339 
340 }} // namespace boost::geometry
341 
342 #endif // BOOST_GEOMETRY_CORE_CS_HPP
343