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-2020.
8// Modifications copyright (c) 2014-2020, 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
24#include <cstddef>
25
26#include <boost/geometry/core/coordinate_system.hpp>
27#include <boost/geometry/core/static_assert.hpp>
28#include <boost/geometry/core/tags.hpp>
29
30
31namespace 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*/
41struct 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*/
51struct radian {};
52
53
54#ifndef DOXYGEN_NO_DETAIL
55namespace core_detail
56{
57
58template <typename DegreeOrRadian>
59struct define_angular_units
60{
61 BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
62 "Coordinate system unit must be degree or radian.",
63 DegreeOrRadian);
64};
65
66template <>
67struct define_angular_units<geometry::degree>
68{
69 typedef geometry::degree units;
70};
71
72template <>
73struct define_angular_units<geometry::radian>
74{
75 typedef geometry::radian units;
76};
77
78} // namespace core_detail
79#endif // DOXYGEN_NO_DETAIL
80
81
82namespace cs
83{
84
85/*!
86\brief Cartesian coordinate system
87\details Defines the Cartesian or rectangular coordinate system
88 where points are defined in 2 or 3 (or more)
89dimensions and usually (but not always) known as x,y,z
90\see http://en.wikipedia.org/wiki/Cartesian_coordinate_system
91\ingroup cs
92*/
93struct cartesian {};
94
95
96
97
98/*!
99\brief Geographic coordinate system, in degree or in radian
100\details Defines the geographic coordinate system where points
101 are defined in two angles and usually
102known as lat,long or lo,la or phi,lambda
103\see http://en.wikipedia.org/wiki/Geographic_coordinate_system
104\ingroup cs
105\note might be moved to extensions/gis/geographic
106*/
107template<typename DegreeOrRadian>
108struct geographic
109 : core_detail::define_angular_units<DegreeOrRadian>
110{};
111
112
113
114/*!
115\brief Spherical (polar) coordinate system, in degree or in radian
116\details Defines the spherical coordinate system where points are
117 defined in two angles
118 and an optional radius usually known as r, theta, phi
119\par Coordinates:
120- coordinate 0:
121 0 <= phi < 2pi is the angle between the positive x-axis and the
122 line from the origin to the P projected onto the xy-plane.
123- coordinate 1:
124 0 <= theta <= pi is the angle between the positive z-axis and the
125 line formed between the origin and P.
126- coordinate 2 (if specified):
127 r >= 0 is the distance from the origin to a given point P.
128
129\see http://en.wikipedia.org/wiki/Spherical_coordinates
130\ingroup cs
131*/
132template<typename DegreeOrRadian>
133struct spherical
134 : core_detail::define_angular_units<DegreeOrRadian>
135{};
136
137
138/*!
139\brief Spherical equatorial coordinate system, in degree or in radian
140\details This one resembles the geographic coordinate system, and has latitude
141 up from zero at the equator, to 90 at the pole
142 (opposite to the spherical(polar) coordinate system).
143 Used in astronomy and in GIS (but there is also the geographic)
144
145\see http://en.wikipedia.org/wiki/Spherical_coordinates
146\ingroup cs
147*/
148template<typename DegreeOrRadian>
149struct spherical_equatorial
150 : core_detail::define_angular_units<DegreeOrRadian>
151{};
152
153
154
155/*!
156\brief Polar coordinate system
157\details Defines the polar coordinate system "in which each point
158 on a plane is determined by an angle and a distance"
159\see http://en.wikipedia.org/wiki/Polar_coordinates
160\ingroup cs
161*/
162template<typename DegreeOrRadian>
163struct polar
164 : core_detail::define_angular_units<DegreeOrRadian>
165{};
166
167
168/*!
169\brief Undefined coordinate system
170\ingroup cs
171*/
172struct undefined {};
173
174
175} // namespace cs
176
177
178namespace traits
179{
180
181/*!
182\brief Traits class defining coordinate system tag, bound to coordinate system
183\ingroup traits
184\tparam CoordinateSystem coordinate system
185*/
186template <typename CoordinateSystem>
187struct cs_tag
188{
189};
190
191
192#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
193
194template<typename DegreeOrRadian>
195struct cs_tag<cs::geographic<DegreeOrRadian> >
196{
197 typedef geographic_tag type;
198};
199
200template<typename DegreeOrRadian>
201struct cs_tag<cs::spherical<DegreeOrRadian> >
202{
203 typedef spherical_polar_tag type;
204};
205
206template<typename DegreeOrRadian>
207struct cs_tag<cs::spherical_equatorial<DegreeOrRadian> >
208{
209 typedef spherical_equatorial_tag type;
210};
211
212
213template<>
214struct cs_tag<cs::cartesian>
215{
216 typedef cartesian_tag type;
217};
218
219
220template <>
221struct cs_tag<cs::undefined>
222{
223 typedef cs_undefined_tag type;
224};
225
226#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
227
228
229} // namespace traits
230
231
232/*!
233\brief Meta-function returning coordinate system tag (cs family) of any geometry
234\tparam Geometry \tparam_geometry
235\ingroup core
236*/
237template <typename Geometry>
238struct cs_tag
239{
240 typedef typename traits::cs_tag
241 <
242 typename geometry::coordinate_system<Geometry>::type
243 >::type type;
244};
245
246
247namespace traits
248{
249
250// cartesian or undefined
251template <typename CoordinateSystem>
252struct cs_angular_units
253{
254 typedef geometry::radian type;
255};
256
257#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
258
259template<typename DegreeOrRadian>
260struct cs_angular_units<cs::geographic<DegreeOrRadian> >
261{
262 typedef DegreeOrRadian type;
263};
264
265template<typename DegreeOrRadian>
266struct cs_angular_units<cs::spherical<DegreeOrRadian> >
267{
268 typedef DegreeOrRadian type;
269};
270
271template<typename DegreeOrRadian>
272struct cs_angular_units<cs::spherical_equatorial<DegreeOrRadian> >
273{
274 typedef DegreeOrRadian type;
275};
276
277#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
278
279
280} // namespace traits
281
282
283#ifndef DOXYGEN_NO_DETAIL
284namespace detail
285{
286
287template <typename Geometry>
288struct cs_angular_units
289{
290 typedef typename traits::cs_angular_units
291 <
292 typename geometry::coordinate_system<Geometry>::type
293 >::type type;
294};
295
296
297template <typename Units, typename CsTag>
298struct cs_tag_to_coordinate_system
299{
300 BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
301 "Not implemented for this coordinate system.",
302 Units, CsTag);
303};
304
305template <typename Units>
306struct cs_tag_to_coordinate_system<Units, cs_undefined_tag>
307{
308 typedef cs::undefined type;
309};
310
311template <typename Units>
312struct cs_tag_to_coordinate_system<Units, cartesian_tag>
313{
314 typedef cs::cartesian type;
315};
316
317template <typename Units>
318struct cs_tag_to_coordinate_system<Units, spherical_equatorial_tag>
319{
320 typedef cs::spherical_equatorial<Units> type;
321};
322
323template <typename Units>
324struct cs_tag_to_coordinate_system<Units, spherical_polar_tag>
325{
326 typedef cs::spherical<Units> type;
327};
328
329template <typename Units>
330struct cs_tag_to_coordinate_system<Units, geographic_tag>
331{
332 typedef cs::geographic<Units> type;
333};
334
335} // namespace detail
336#endif // DOXYGEN_NO_DETAIL
337
338
339}} // namespace boost::geometry
340
341#endif // BOOST_GEOMETRY_CORE_CS_HPP
342

source code of boost/libs/geometry/include/boost/geometry/core/cs.hpp