]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/srs/projections/proj/airy.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / geometry / srs / projections / proj / airy.hpp
1 #ifndef BOOST_GEOMETRY_PROJECTIONS_AIRY_HPP
2 #define BOOST_GEOMETRY_PROJECTIONS_AIRY_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.
10 // Modifications copyright (c) 2017, 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 // Purpose: Implementation of the airy (Airy) projection.
27 // Author: Gerald Evenden
28 // Copyright (c) 1995, Gerald Evenden
29
30 // Permission is hereby granted, free of charge, to any person obtaining a
31 // copy of this software and associated documentation files (the "Software"),
32 // to deal in the Software without restriction, including without limitation
33 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 // and/or sell copies of the Software, and to permit persons to whom the
35 // Software is furnished to do so, subject to the following conditions:
36
37 // The above copyright notice and this permission notice shall be included
38 // in all copies or substantial portions of the Software.
39
40 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
41 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
43 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
46 // DEALINGS IN THE SOFTWARE.
47
48 #include <boost/geometry/util/math.hpp>
49
50 #include <boost/geometry/srs/projections/impl/base_static.hpp>
51 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
52 #include <boost/geometry/srs/projections/impl/projects.hpp>
53 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
54
55 #include <boost/geometry/srs/projections/par4.hpp> // airy tag
56
57 namespace boost { namespace geometry
58 {
59
60 namespace srs { namespace par4
61 {
62 // already defined in par4.hpp as ellps name
63 //struct airy {};
64
65 }} //namespace srs::par4
66
67 namespace projections
68 {
69 #ifndef DOXYGEN_NO_DETAIL
70 namespace detail { namespace airy
71 {
72
73 static const double EPS = 1.e-10;
74 static const int N_POLE = 0;
75 static const int S_POLE = 1;
76 static const int EQUIT = 2;
77 static const int OBLIQ = 3;
78
79 template <typename T>
80 struct par_airy
81 {
82 T p_halfpi;
83 T sinph0;
84 T cosph0;
85 T Cb;
86 int mode;
87 int no_cut; /* do not cut at hemisphere limit */
88 };
89
90 // template class, using CRTP to implement forward/inverse
91 template <typename CalculationType, typename Parameters>
92 struct base_airy_spheroid : public base_t_f<base_airy_spheroid<CalculationType, Parameters>,
93 CalculationType, Parameters>
94 {
95
96 typedef CalculationType geographic_type;
97 typedef CalculationType cartesian_type;
98
99 par_airy<CalculationType> m_proj_parm;
100
101 inline base_airy_spheroid(const Parameters& par)
102 : base_t_f<base_airy_spheroid<CalculationType, Parameters>,
103 CalculationType, Parameters>(*this, par) {}
104
105 // FORWARD(s_forward) spheroid
106 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
107 inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
108 {
109 static const CalculationType HALFPI = detail::HALFPI<CalculationType>();
110
111 CalculationType sinlam, coslam, cosphi, sinphi, t, s, Krho, cosz;
112
113 sinlam = sin(lp_lon);
114 coslam = cos(lp_lon);
115 switch (this->m_proj_parm.mode) {
116 case EQUIT:
117 case OBLIQ:
118 sinphi = sin(lp_lat);
119 cosphi = cos(lp_lat);
120 cosz = cosphi * coslam;
121 if (this->m_proj_parm.mode == OBLIQ)
122 cosz = this->m_proj_parm.sinph0 * sinphi + this->m_proj_parm.cosph0 * cosz;
123 if (!this->m_proj_parm.no_cut && cosz < -EPS)
124 BOOST_THROW_EXCEPTION( projection_exception(-20) );
125 if (fabs(s = 1. - cosz) > EPS) {
126 t = 0.5 * (1. + cosz);
127 Krho = -log(t)/s - this->m_proj_parm.Cb / t;
128 } else
129 Krho = 0.5 - this->m_proj_parm.Cb;
130 xy_x = Krho * cosphi * sinlam;
131 if (this->m_proj_parm.mode == OBLIQ)
132 xy_y = Krho * (this->m_proj_parm.cosph0 * sinphi -
133 this->m_proj_parm.sinph0 * cosphi * coslam);
134 else
135 xy_y = Krho * sinphi;
136 break;
137 case S_POLE:
138 case N_POLE:
139 lp_lat = fabs(this->m_proj_parm.p_halfpi - lp_lat);
140 if (!this->m_proj_parm.no_cut && (lp_lat - EPS) > HALFPI)
141 BOOST_THROW_EXCEPTION( projection_exception(-20) );
142 if ((lp_lat *= 0.5) > EPS) {
143 t = tan(lp_lat);
144 Krho = -2.*(log(cos(lp_lat)) / t + t * this->m_proj_parm.Cb);
145 xy_x = Krho * sinlam;
146 xy_y = Krho * coslam;
147 if (this->m_proj_parm.mode == N_POLE)
148 xy_y = -xy_y;
149 } else
150 xy_x = xy_y = 0.;
151 }
152 }
153
154 static inline std::string get_name()
155 {
156 return "airy_spheroid";
157 }
158
159 };
160
161 // Airy
162 template <typename Parameters, typename T>
163 inline void setup_airy(Parameters& par, par_airy<T>& proj_parm)
164 {
165 static const T HALFPI = detail::HALFPI<T>();
166
167 T beta;
168
169 proj_parm.no_cut = pj_param(par.params, "bno_cut").i;
170 beta = 0.5 * (HALFPI - pj_param(par.params, "rlat_b").f);
171 if (fabs(beta) < EPS)
172 proj_parm.Cb = -0.5;
173 else {
174 proj_parm.Cb = 1./tan(beta);
175 proj_parm.Cb *= proj_parm.Cb * log(cos(beta));
176 }
177 if (fabs(fabs(par.phi0) - HALFPI) < EPS)
178 if (par.phi0 < 0.) {
179 proj_parm.p_halfpi = -HALFPI;
180 proj_parm.mode = S_POLE;
181 } else {
182 proj_parm.p_halfpi = HALFPI;
183 proj_parm.mode = N_POLE;
184 }
185 else {
186 if (fabs(par.phi0) < EPS)
187 proj_parm.mode = EQUIT;
188 else {
189 proj_parm.mode = OBLIQ;
190 proj_parm.sinph0 = sin(par.phi0);
191 proj_parm.cosph0 = cos(par.phi0);
192 }
193 }
194 par.es = 0.;
195 }
196
197 }} // namespace detail::airy
198 #endif // doxygen
199
200 /*!
201 \brief Airy projection
202 \ingroup projections
203 \tparam Geographic latlong point type
204 \tparam Cartesian xy point type
205 \tparam Parameters parameter type
206 \par Projection characteristics
207 - Miscellaneous
208 - Spheroid
209 - no inverse
210 \par Projection parameters
211 - no_cut: Do not cut at hemisphere limit (boolean)
212 - lat_b (degrees)
213 \par Example
214 \image html ex_airy.gif
215 */
216 template <typename CalculationType, typename Parameters>
217 struct airy_spheroid : public detail::airy::base_airy_spheroid<CalculationType, Parameters>
218 {
219 inline airy_spheroid(const Parameters& par) : detail::airy::base_airy_spheroid<CalculationType, Parameters>(par)
220 {
221 detail::airy::setup_airy(this->m_par, this->m_proj_parm);
222 }
223 };
224
225 #ifndef DOXYGEN_NO_DETAIL
226 namespace detail
227 {
228
229 // Static projection
230 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::airy, airy_spheroid, airy_spheroid)
231
232 // Factory entry(s)
233 template <typename CalculationType, typename Parameters>
234 class airy_entry : public detail::factory_entry<CalculationType, Parameters>
235 {
236 public :
237 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
238 {
239 return new base_v_f<airy_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
240 }
241 };
242
243 template <typename CalculationType, typename Parameters>
244 inline void airy_init(detail::base_factory<CalculationType, Parameters>& factory)
245 {
246 factory.add_to_factory("airy", new airy_entry<CalculationType, Parameters>);
247 }
248
249 } // namespace detail
250 #endif // doxygen
251
252 } // namespace projections
253
254 }} // namespace boost::geometry
255
256 #endif // BOOST_GEOMETRY_PROJECTIONS_AIRY_HPP
257