]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/include/boost/geometry/core/radian_access.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / core / radian_access.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
3// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
5// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
6
7// This file was modified by Oracle on 2015.
8// Modifications copyright (c) 2015, 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
20#ifndef BOOST_GEOMETRY_CORE_RADIAN_ACCESS_HPP
21#define BOOST_GEOMETRY_CORE_RADIAN_ACCESS_HPP
22
23
24#include <cstddef>
25
26#include <boost/numeric/conversion/cast.hpp>
27
28#include <boost/geometry/core/access.hpp>
29#include <boost/geometry/core/cs.hpp>
30#include <boost/geometry/core/coordinate_type.hpp>
31
32
33#include <boost/geometry/util/math.hpp>
34
35
36
37namespace boost { namespace geometry
38{
39
40
41#ifndef DOXYGEN_NO_DETAIL
42namespace detail
43{
44
45template<std::size_t Dimension, typename Geometry>
46struct degree_radian_converter
47{
48 typedef typename fp_coordinate_type<Geometry>::type coordinate_type;
49
50 static inline coordinate_type get(Geometry const& geometry)
51 {
52 return boost::numeric_cast
53 <
54 coordinate_type
55 >(geometry::get<Dimension>(geometry)
56 * math::d2r<coordinate_type>());
57 }
58
59 static inline void set(Geometry& geometry, coordinate_type const& radians)
60 {
61 geometry::set<Dimension>(geometry, boost::numeric_cast
62 <
63 coordinate_type
64 >(radians * math::r2d<coordinate_type>()));
65 }
66
67};
68
69
70// Default, radian (or any other coordinate system) just works like "get"
71template <std::size_t Dimension, typename Geometry, typename DegreeOrRadian>
72struct radian_access
73{
74 typedef typename fp_coordinate_type<Geometry>::type coordinate_type;
75
76 static inline coordinate_type get(Geometry const& geometry)
77 {
78 return geometry::get<Dimension>(geometry);
79 }
80
81 static inline void set(Geometry& geometry, coordinate_type const& radians)
82 {
83 geometry::set<Dimension>(geometry, radians);
84 }
85};
86
87// Specialize, any "degree" coordinate system will be converted to radian
88// but only for dimension 0,1 (so: dimension 2 and heigher are untouched)
89
90template
91<
92 typename Geometry,
93 template<typename> class CoordinateSystem
94>
95struct radian_access<0, Geometry, CoordinateSystem<degree> >
96 : degree_radian_converter<0, Geometry>
97{};
98
99
100template
101<
102 typename Geometry,
103 template<typename> class CoordinateSystem
104>
105struct radian_access<1, Geometry, CoordinateSystem<degree> >
106 : degree_radian_converter<1, Geometry>
107{};
108
109
110} // namespace detail
111#endif // DOXYGEN_NO_DETAIL
112
113
114/*!
115\brief get coordinate value of a point, result is in Radian
116\details Result is in Radian, even if source coordinate system
117 is in Degrees
118\return coordinate value
119\ingroup get
120\tparam Dimension dimension
121\tparam Geometry geometry
122\param geometry geometry to get coordinate value from
123\note Only applicable to coordinate systems templatized by units,
124 e.g. spherical or geographic coordinate systems
125*/
126template <std::size_t Dimension, typename Geometry>
127inline typename fp_coordinate_type<Geometry>::type get_as_radian(Geometry const& geometry)
128{
129 return detail::radian_access<Dimension, Geometry,
130 typename coordinate_system<Geometry>::type>::get(geometry);
131}
132
133
134/*!
135\brief set coordinate value (in radian) to a point
136\details Coordinate value will be set correctly, if coordinate system of
137 point is in Degree, Radian value will be converted to Degree
138\ingroup set
139\tparam Dimension dimension
140\tparam Geometry geometry
141\param geometry geometry to assign coordinate to
142\param radians coordinate value to assign
143\note Only applicable to coordinate systems templatized by units,
144 e.g. spherical or geographic coordinate systems
145*/
146template <std::size_t Dimension, typename Geometry>
147inline void set_from_radian(Geometry& geometry,
148 typename fp_coordinate_type<Geometry>::type const& radians)
149{
150 detail::radian_access<Dimension, Geometry,
151 typename coordinate_system<Geometry>::type>::set(geometry, radians);
152}
153
154
155}} // namespace boost::geometry
156
157
158#endif // BOOST_GEOMETRY_CORE_RADIAN_ACCESS_HPP