]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/srs/projections/proj/lagrng.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / geometry / srs / projections / proj / lagrng.hpp
1 #ifndef BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP
2 #define BOOST_GEOMETRY_PROJECTIONS_LAGRNG_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 // 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/geometry/util/math.hpp>
45
46 #include <boost/geometry/srs/projections/impl/base_static.hpp>
47 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
48 #include <boost/geometry/srs/projections/impl/projects.hpp>
49 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
50
51 namespace boost { namespace geometry
52 {
53
54 namespace srs { namespace par4
55 {
56 struct lagrng {};
57
58 }} //namespace srs::par4
59
60 namespace projections
61 {
62 #ifndef DOXYGEN_NO_DETAIL
63 namespace detail { namespace lagrng
64 {
65
66 static const double TOL = 1e-10;
67
68 template <typename T>
69 struct par_lagrng
70 {
71 T hrw;
72 T rw;
73 T a1;
74 };
75
76 // template class, using CRTP to implement forward/inverse
77 template <typename CalculationType, typename Parameters>
78 struct base_lagrng_spheroid : public base_t_f<base_lagrng_spheroid<CalculationType, Parameters>,
79 CalculationType, Parameters>
80 {
81
82 typedef CalculationType geographic_type;
83 typedef CalculationType cartesian_type;
84
85 par_lagrng<CalculationType> m_proj_parm;
86
87 inline base_lagrng_spheroid(const Parameters& par)
88 : base_t_f<base_lagrng_spheroid<CalculationType, Parameters>,
89 CalculationType, Parameters>(*this, par) {}
90
91 // FORWARD(s_forward) spheroid
92 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
93 inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
94 {
95 static const CalculationType HALFPI = detail::HALFPI<CalculationType>();
96
97 CalculationType v, c;
98
99 if (fabs(fabs(lp_lat) - HALFPI) < TOL) {
100 xy_x = 0;
101 xy_y = lp_lat < 0 ? -2. : 2.;
102 } else {
103 lp_lat = sin(lp_lat);
104 v = this->m_proj_parm.a1 * pow((1. + lp_lat)/(1. - lp_lat), this->m_proj_parm.hrw);
105 if ((c = 0.5 * (v + 1./v) + cos(lp_lon *= this->m_proj_parm.rw)) < TOL)
106 BOOST_THROW_EXCEPTION( projection_exception(-20) );
107 xy_x = 2. * sin(lp_lon) / c;
108 xy_y = (v - 1./v) / c;
109 }
110 }
111
112 static inline std::string get_name()
113 {
114 return "lagrng_spheroid";
115 }
116
117 };
118
119 // Lagrange
120 template <typename Parameters, typename T>
121 inline void setup_lagrng(Parameters& par, par_lagrng<T>& proj_parm)
122 {
123 T phi1;
124
125 if ((proj_parm.rw = pj_param(par.params, "dW").f) <= 0)
126 BOOST_THROW_EXCEPTION( projection_exception(-27) );
127 proj_parm.hrw = 0.5 * (proj_parm.rw = 1. / proj_parm.rw);
128 phi1 = pj_param(par.params, "rlat_1").f;
129 if (fabs(fabs(phi1 = sin(phi1)) - 1.) < TOL)
130 BOOST_THROW_EXCEPTION( projection_exception(-22) );
131 proj_parm.a1 = pow((1. - phi1)/(1. + phi1), proj_parm.hrw);
132 par.es = 0.;
133 }
134
135 }} // namespace detail::lagrng
136 #endif // doxygen
137
138 /*!
139 \brief Lagrange projection
140 \ingroup projections
141 \tparam Geographic latlong point type
142 \tparam Cartesian xy point type
143 \tparam Parameters parameter type
144 \par Projection characteristics
145 - Miscellaneous
146 - Spheroid
147 - no inverse
148 \par Projection parameters
149 - W (real)
150 - lat_1: Latitude of first standard parallel (degrees)
151 \par Example
152 \image html ex_lagrng.gif
153 */
154 template <typename CalculationType, typename Parameters>
155 struct lagrng_spheroid : public detail::lagrng::base_lagrng_spheroid<CalculationType, Parameters>
156 {
157 inline lagrng_spheroid(const Parameters& par) : detail::lagrng::base_lagrng_spheroid<CalculationType, Parameters>(par)
158 {
159 detail::lagrng::setup_lagrng(this->m_par, this->m_proj_parm);
160 }
161 };
162
163 #ifndef DOXYGEN_NO_DETAIL
164 namespace detail
165 {
166
167 // Static projection
168 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::lagrng, lagrng_spheroid, lagrng_spheroid)
169
170 // Factory entry(s)
171 template <typename CalculationType, typename Parameters>
172 class lagrng_entry : public detail::factory_entry<CalculationType, Parameters>
173 {
174 public :
175 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
176 {
177 return new base_v_f<lagrng_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
178 }
179 };
180
181 template <typename CalculationType, typename Parameters>
182 inline void lagrng_init(detail::base_factory<CalculationType, Parameters>& factory)
183 {
184 factory.add_to_factory("lagrng", new lagrng_entry<CalculationType, Parameters>);
185 }
186
187 } // namespace detail
188 #endif // doxygen
189
190 } // namespace projections
191
192 }} // namespace boost::geometry
193
194 #endif // BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP
195