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.
8// Modifications copyright (c) 2014, Oracle and/or its affiliates.
9
10// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
11
12// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
15// Use, modification and distribution is subject to the Boost Software License,
16// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17// http://www.boost.org/LICENSE_1_0.txt)
18
19#ifndef BOOST_GEOMETRY_CORE_CS_HPP
20#define BOOST_GEOMETRY_CORE_CS_HPP
21
22#include <cstddef>
23
24#include <boost/mpl/assert.hpp>
25#include <boost/type_traits/integral_constant.hpp>
26
27#include <boost/geometry/core/coordinate_system.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 coordinate_system_units
60{
61 BOOST_MPL_ASSERT_MSG
62 ((false),
63 COORDINATE_SYSTEM_UNITS_MUST_BE_DEGREES_OR_RADIANS,
64 (types<DegreeOrRadian>));
65};
66
67template <>
68struct coordinate_system_units<geometry::degree>
69{
70 typedef geometry::degree units;
71};
72
73template <>
74struct coordinate_system_units<geometry::radian>
75{
76 typedef geometry::radian units;
77};
78
79} // namespace core_detail
80#endif // DOXYGEN_NO_DETAIL
81
82
83namespace 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)
90dimensions and usually (but not always) known as x,y,z
91\see http://en.wikipedia.org/wiki/Cartesian_coordinate_system
92\ingroup cs
93*/
94struct 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
103known 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*/
108template<typename DegreeOrRadian>
109struct geographic
110{
111 typedef typename core_detail::coordinate_system_units
112 <
113 DegreeOrRadian
114 >::units units;
115};
116
117
118
119/*!
120\brief Spherical (polar) coordinate system, in degree or in radian
121\details Defines the spherical coordinate system where points are
122 defined in two angles
123 and an optional radius usually known as r, theta, phi
124\par Coordinates:
125- coordinate 0:
126 0 <= phi < 2pi is the angle between the positive x-axis and the
127 line from the origin to the P projected onto the xy-plane.
128- coordinate 1:
129 0 <= theta <= pi is the angle between the positive z-axis and the
130 line formed between the origin and P.
131- coordinate 2 (if specified):
132 r >= 0 is the distance from the origin to a given point P.
133
134\see http://en.wikipedia.org/wiki/Spherical_coordinates
135\ingroup cs
136*/
137template<typename DegreeOrRadian>
138struct spherical
139{
140 typedef typename core_detail::coordinate_system_units
141 <
142 DegreeOrRadian
143 >::units units;
144};
145
146
147/*!
148\brief Spherical equatorial coordinate system, in degree or in radian
149\details This one resembles the geographic coordinate system, and has latitude
150 up from zero at the equator, to 90 at the pole
151 (opposite to the spherical(polar) coordinate system).
152 Used in astronomy and in GIS (but there is also the geographic)
153
154\see http://en.wikipedia.org/wiki/Spherical_coordinates
155\ingroup cs
156*/
157template<typename DegreeOrRadian>
158struct spherical_equatorial
159{
160 typedef typename core_detail::coordinate_system_units
161 <
162 DegreeOrRadian
163 >::units units;
164};
165
166
167
168/*!
169\brief Polar coordinate system
170\details Defines the polar coordinate system "in which each point
171 on a plane is determined by an angle and a distance"
172\see http://en.wikipedia.org/wiki/Polar_coordinates
173\ingroup cs
174*/
175template<typename DegreeOrRadian>
176struct polar
177{
178 typedef typename core_detail::coordinate_system_units
179 <
180 DegreeOrRadian
181 >::units units;
182};
183
184
185} // namespace cs
186
187
188namespace traits
189{
190
191/*!
192\brief Traits class defining coordinate system tag, bound to coordinate system
193\ingroup traits
194\tparam CoordinateSystem coordinate system
195*/
196template <typename CoordinateSystem>
197struct cs_tag
198{
199};
200
201
202#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
203
204template<typename DegreeOrRadian>
205struct cs_tag<cs::geographic<DegreeOrRadian> >
206{
207 typedef geographic_tag type;
208};
209
210template<typename DegreeOrRadian>
211struct cs_tag<cs::spherical<DegreeOrRadian> >
212{
213 typedef spherical_polar_tag type;
214};
215
216template<typename DegreeOrRadian>
217struct cs_tag<cs::spherical_equatorial<DegreeOrRadian> >
218{
219 typedef spherical_equatorial_tag type;
220};
221
222
223template<>
224struct cs_tag<cs::cartesian>
225{
226 typedef cartesian_tag type;
227};
228
229
230#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
231} // namespace traits
232
233/*!
234\brief Meta-function returning coordinate system tag (cs family) of any geometry
235\tparam Geometry \tparam_geometry
236\ingroup core
237*/
238template <typename Geometry>
239struct cs_tag
240{
241 typedef typename traits::cs_tag
242 <
243 typename geometry::coordinate_system<Geometry>::type
244 >::type type;
245};
246
247
248/*!
249\brief Meta-function to verify if a coordinate system is radian
250\tparam CoordinateSystem Any coordinate system.
251\ingroup core
252*/
253template <typename CoordinateSystem>
254struct is_radian : boost::true_type {};
255
256
257#ifndef DOXYGEN_NO_SPECIALIZATIONS
258
259// Specialization for any degree coordinate systems
260template <template<typename> class CoordinateSystem>
261struct is_radian< CoordinateSystem<degree> > : boost::false_type
262{
263};
264
265#endif // DOXYGEN_NO_SPECIALIZATIONS
266
267}} // namespace boost::geometry
268
269#endif // BOOST_GEOMETRY_CORE_CS_HPP
270