]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/srs/projections/proj/gnom.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / geometry / srs / projections / proj / gnom.hpp
1 #ifndef BOOST_GEOMETRY_PROJECTIONS_GNOM_HPP
2 #define BOOST_GEOMETRY_PROJECTIONS_GNOM_HPP
3
4 // Boost.Geometry - extensions-gis-projections (based on PROJ4)
5 // This file is automatically generated. DO NOT EDIT.
6
7 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
8
9 // This file was modified by Oracle on 2017, 2018.
10 // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
12
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
16
17 // This file is converted from PROJ4, http://trac.osgeo.org/proj
18 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
19 // PROJ4 is maintained by Frank Warmerdam
20 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
21
22 // Last updated version of proj: 4.9.1
23
24 // Original copyright notice:
25
26 // Permission is hereby granted, free of charge, to any person obtaining a
27 // copy of this software and associated documentation files (the "Software"),
28 // to deal in the Software without restriction, including without limitation
29 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
30 // and/or sell copies of the Software, and to permit persons to whom the
31 // Software is furnished to do so, subject to the following conditions:
32
33 // The above copyright notice and this permission notice shall be included
34 // in all copies or substantial portions of the Software.
35
36 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
37 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
41 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
42 // DEALINGS IN THE SOFTWARE.
43
44 #include <boost/config.hpp>
45 #include <boost/geometry/util/math.hpp>
46 #include <boost/math/special_functions/hypot.hpp>
47
48 #include <boost/geometry/srs/projections/impl/base_static.hpp>
49 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
50 #include <boost/geometry/srs/projections/impl/projects.hpp>
51 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
52
53 namespace boost { namespace geometry
54 {
55
56 namespace srs { namespace par4
57 {
58 struct gnom {};
59
60 }} //namespace srs::par4
61
62 namespace projections
63 {
64 #ifndef DOXYGEN_NO_DETAIL
65 namespace detail { namespace gnom
66 {
67
68 static const double EPS10 = 1.e-10;
69 static const int N_POLE = 0;
70 static const int S_POLE = 1;
71 static const int EQUIT = 2;
72 static const int OBLIQ = 3;
73
74 template <typename T>
75 struct par_gnom
76 {
77 T sinph0;
78 T cosph0;
79 int mode;
80 };
81
82 // template class, using CRTP to implement forward/inverse
83 template <typename CalculationType, typename Parameters>
84 struct base_gnom_spheroid : public base_t_fi<base_gnom_spheroid<CalculationType, Parameters>,
85 CalculationType, Parameters>
86 {
87
88 typedef CalculationType geographic_type;
89 typedef CalculationType cartesian_type;
90
91 par_gnom<CalculationType> m_proj_parm;
92
93 inline base_gnom_spheroid(const Parameters& par)
94 : base_t_fi<base_gnom_spheroid<CalculationType, Parameters>,
95 CalculationType, Parameters>(*this, par) {}
96
97 // FORWARD(s_forward) spheroid
98 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
99 inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
100 {
101 CalculationType coslam, cosphi, sinphi;
102
103 sinphi = sin(lp_lat);
104 cosphi = cos(lp_lat);
105 coslam = cos(lp_lon);
106 switch (this->m_proj_parm.mode) {
107 case EQUIT:
108 xy_y = cosphi * coslam;
109 break;
110 case OBLIQ:
111 xy_y = this->m_proj_parm.sinph0 * sinphi + this->m_proj_parm.cosph0 * cosphi * coslam;
112 break;
113 case S_POLE:
114 xy_y = - sinphi;
115 break;
116 case N_POLE:
117 xy_y = sinphi;
118 break;
119 }
120 if (xy_y <= EPS10)
121 BOOST_THROW_EXCEPTION( projection_exception(-20) );
122 xy_x = (xy_y = 1. / xy_y) * cosphi * sin(lp_lon);
123 switch (this->m_proj_parm.mode) {
124 case EQUIT:
125 xy_y *= sinphi;
126 break;
127 case OBLIQ:
128 xy_y *= this->m_proj_parm.cosph0 * sinphi - this->m_proj_parm.sinph0 * cosphi * coslam;
129 break;
130 case N_POLE:
131 coslam = - coslam;
132 BOOST_FALLTHROUGH;
133 case S_POLE:
134 xy_y *= cosphi * coslam;
135 break;
136 }
137 }
138
139 // INVERSE(s_inverse) spheroid
140 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
141 inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
142 {
143 static const CalculationType HALFPI = detail::HALFPI<CalculationType>();
144
145 CalculationType rh, cosz, sinz;
146
147 rh = boost::math::hypot(xy_x, xy_y);
148 sinz = sin(lp_lat = atan(rh));
149 cosz = sqrt(1. - sinz * sinz);
150 if (fabs(rh) <= EPS10) {
151 lp_lat = this->m_par.phi0;
152 lp_lon = 0.;
153 } else {
154 switch (this->m_proj_parm.mode) {
155 case OBLIQ:
156 lp_lat = cosz * this->m_proj_parm.sinph0 + xy_y * sinz * this->m_proj_parm.cosph0 / rh;
157 if (fabs(lp_lat) >= 1.)
158 lp_lat = lp_lat > 0. ? HALFPI : -HALFPI;
159 else
160 lp_lat = asin(lp_lat);
161 xy_y = (cosz - this->m_proj_parm.sinph0 * sin(lp_lat)) * rh;
162 xy_x *= sinz * this->m_proj_parm.cosph0;
163 break;
164 case EQUIT:
165 lp_lat = xy_y * sinz / rh;
166 if (fabs(lp_lat) >= 1.)
167 lp_lat = lp_lat > 0. ? HALFPI : -HALFPI;
168 else
169 lp_lat = asin(lp_lat);
170 xy_y = cosz * rh;
171 xy_x *= sinz;
172 break;
173 case S_POLE:
174 lp_lat -= HALFPI;
175 break;
176 case N_POLE:
177 lp_lat = HALFPI - lp_lat;
178 xy_y = -xy_y;
179 break;
180 }
181 lp_lon = atan2(xy_x, xy_y);
182 }
183 }
184
185 static inline std::string get_name()
186 {
187 return "gnom_spheroid";
188 }
189
190 };
191
192 // Gnomonic
193 template <typename Parameters, typename T>
194 inline void setup_gnom(Parameters& par, par_gnom<T>& proj_parm)
195 {
196 static const T HALFPI = detail::HALFPI<T>();
197
198 if (fabs(fabs(par.phi0) - HALFPI) < EPS10)
199 proj_parm.mode = par.phi0 < 0. ? S_POLE : N_POLE;
200 else if (fabs(par.phi0) < EPS10)
201 proj_parm.mode = EQUIT;
202 else {
203 proj_parm.mode = OBLIQ;
204 proj_parm.sinph0 = sin(par.phi0);
205 proj_parm.cosph0 = cos(par.phi0);
206 }
207 par.es = 0.;
208 }
209
210 }} // namespace detail::gnom
211 #endif // doxygen
212
213 /*!
214 \brief Gnomonic projection
215 \ingroup projections
216 \tparam Geographic latlong point type
217 \tparam Cartesian xy point type
218 \tparam Parameters parameter type
219 \par Projection characteristics
220 - Azimuthal
221 - Spheroid
222 \par Example
223 \image html ex_gnom.gif
224 */
225 template <typename CalculationType, typename Parameters>
226 struct gnom_spheroid : public detail::gnom::base_gnom_spheroid<CalculationType, Parameters>
227 {
228 inline gnom_spheroid(const Parameters& par) : detail::gnom::base_gnom_spheroid<CalculationType, Parameters>(par)
229 {
230 detail::gnom::setup_gnom(this->m_par, this->m_proj_parm);
231 }
232 };
233
234 #ifndef DOXYGEN_NO_DETAIL
235 namespace detail
236 {
237
238 // Static projection
239 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::gnom, gnom_spheroid, gnom_spheroid)
240
241 // Factory entry(s)
242 template <typename CalculationType, typename Parameters>
243 class gnom_entry : public detail::factory_entry<CalculationType, Parameters>
244 {
245 public :
246 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
247 {
248 return new base_v_fi<gnom_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
249 }
250 };
251
252 template <typename CalculationType, typename Parameters>
253 inline void gnom_init(detail::base_factory<CalculationType, Parameters>& factory)
254 {
255 factory.add_to_factory("gnom", new gnom_entry<CalculationType, Parameters>);
256 }
257
258 } // namespace detail
259 #endif // doxygen
260
261 } // namespace projections
262
263 }} // namespace boost::geometry
264
265 #endif // BOOST_GEOMETRY_PROJECTIONS_GNOM_HPP
266