]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/srs/projections/impl/pj_mlfn.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / geometry / srs / projections / impl / pj_mlfn.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // This file is manually converted from PROJ4
3
4 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // This file was modified by Oracle on 2017, 2018.
7 // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14 // This file is converted from PROJ4, http://trac.osgeo.org/proj
15 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
16 // PROJ4 is maintained by Frank Warmerdam
17 // PROJ4 is converted to Geometry Library by Barend Gehrels (Geodan, Amsterdam)
18
19 // Original copyright notice:
20
21 // Permission is hereby granted, free of charge, to any person obtaining a
22 // copy of this software and associated documentation files (the "Software"),
23 // to deal in the Software without restriction, including without limitation
24 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
25 // and/or sell copies of the Software, and to permit persons to whom the
26 // Software is furnished to do so, subject to the following conditions:
27
28 // The above copyright notice and this permission notice shall be included
29 // in all copies or substantial portions of the Software.
30
31 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
32 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
36 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37 // DEALINGS IN THE SOFTWARE.
38
39 /* meridional distance for ellipsoid and inverse
40 ** 8th degree - accurate to < 1e-5 meters when used in conjunction
41 ** with typical major axis values.
42 ** Inverse determines phi to EPS (1e-11) radians, about 1e-6 seconds.
43 */
44
45 #ifndef BOOST_GEOMETRY_PROJECTIONS_PJ_MLFN_HPP
46 #define BOOST_GEOMETRY_PROJECTIONS_PJ_MLFN_HPP
47
48
49 #include <cstdlib>
50
51 #include <boost/geometry/srs/projections/exception.hpp>
52 #include <boost/geometry/srs/projections/impl/pj_strerrno.hpp>
53 #include <boost/geometry/util/math.hpp>
54
55
56 namespace boost { namespace geometry { namespace projections {
57
58 namespace detail {
59
60 template <typename T>
61 struct en
62 {
63 static const std::size_t size = 5;
64
65 T const& operator[](size_t i) const { return data[i]; }
66 T & operator[](size_t i) { return data[i]; }
67
68 private:
69 T data[5];
70 };
71
72 template <typename T>
73 inline en<T> pj_enfn(T const& es)
74 {
75 static const T C00 = 1.;
76 static const T C02 = .25;
77 static const T C04 = .046875;
78 static const T C06 = .01953125;
79 static const T C08 = .01068115234375;
80 static const T C22 = .75;
81 static const T C44 = .46875;
82 static const T C46 = .01302083333333333333;
83 static const T C48 = .00712076822916666666;
84 static const T C66 = .36458333333333333333;
85 static const T C68 = .00569661458333333333;
86 static const T C88 = .3076171875;
87
88 T t;
89 detail::en<T> en;
90
91 {
92 en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
93 en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
94 en[2] = (t = es * es) * (C44 - es * (C46 + es * C48));
95 en[3] = (t *= es) * (C66 - es * C68);
96 en[4] = t * es * C88;
97 }
98
99 return en;
100 }
101
102 template <typename T>
103 inline T pj_mlfn(T const& phi, T sphi, T cphi, detail::en<T> const& en)
104 {
105 cphi *= sphi;
106 sphi *= sphi;
107 return(en[0] * phi - cphi * (en[1] + sphi*(en[2]
108 + sphi*(en[3] + sphi*en[4]))));
109 }
110
111 template <typename T>
112 inline T pj_inv_mlfn(T const& arg, T const& es, detail::en<T> const& en)
113 {
114 static const T EPS = 1e-11;
115 static const int MAX_ITER = 10;
116
117 T s, t, phi, k = 1./(1.-es);
118 int i;
119
120 phi = arg;
121 for (i = MAX_ITER; i ; --i) { /* rarely goes over 2 iterations */
122 s = sin(phi);
123 t = 1. - es * s * s;
124 phi -= t = (pj_mlfn(phi, s, cos(phi), en) - arg) * (t * sqrt(t)) * k;
125 if (geometry::math::abs(t) < EPS)
126 return phi;
127 }
128 BOOST_THROW_EXCEPTION( projection_exception(error_non_conv_inv_meri_dist) );
129 return phi;
130 }
131
132 } // namespace detail
133 }}} // namespace boost::geometry::projections
134
135 #endif