]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/srs/projections/proj/bacon.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / geometry / srs / projections / proj / bacon.hpp
1 // Boost.Geometry - gis-projections (based on PROJ4)
2
3 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2017, 2018, 2019.
6 // Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
8
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12
13 // This file is converted from PROJ4, http://trac.osgeo.org/proj
14 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
15 // PROJ4 is maintained by Frank Warmerdam
16 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
17
18 // Last updated version of proj: 5.0.0
19
20 // Original copyright notice:
21
22 // Permission is hereby granted, free of charge, to any person obtaining a
23 // copy of this software and associated documentation files (the "Software"),
24 // to deal in the Software without restriction, including without limitation
25 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
26 // and/or sell copies of the Software, and to permit persons to whom the
27 // Software is furnished to do so, subject to the following conditions:
28
29 // The above copyright notice and this permission notice shall be included
30 // in all copies or substantial portions of the Software.
31
32 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
33 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
35 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
38 // DEALINGS IN THE SOFTWARE.
39
40 #ifndef BOOST_GEOMETRY_PROJECTIONS_BACON_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_BACON_HPP
42
43 #include <boost/geometry/util/math.hpp>
44
45 #include <boost/geometry/srs/projections/impl/base_static.hpp>
46 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
47 #include <boost/geometry/srs/projections/impl/projects.hpp>
48 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
49
50 namespace boost { namespace geometry
51 {
52
53 namespace projections
54 {
55 #ifndef DOXYGEN_NO_DETAIL
56 namespace detail { namespace bacon
57 {
58
59 //static const double half_pi_sqr = 2.46740110027233965467;
60 static const double epsilon = 1e-10;
61
62 struct par_bacon
63 {
64 bool bacn;
65 bool ortl;
66 };
67
68 template <typename T, typename Parameters>
69 struct base_bacon_spheroid
70 {
71 par_bacon m_proj_parm;
72
73 // FORWARD(s_forward) spheroid
74 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
75 inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
76 {
77 static const T half_pi = detail::half_pi<T>();
78 static const T half_pi_sqr = detail::half_pi_sqr<T>();
79
80 T ax, f;
81
82 xy_y = this->m_proj_parm.bacn ? half_pi * sin(lp_lat) : lp_lat;
83 if ((ax = fabs(lp_lon)) >= epsilon) {
84 if (this->m_proj_parm.ortl && ax >= half_pi)
85 xy_x = sqrt(half_pi_sqr - lp_lat * lp_lat + epsilon) + ax - half_pi;
86 else {
87 f = 0.5 * (half_pi_sqr / ax + ax);
88 xy_x = ax - f + sqrt(f * f - xy_y * xy_y);
89 }
90 if (lp_lon < 0.) xy_x = - xy_x;
91 } else
92 xy_x = 0.;
93 }
94
95 static inline std::string get_name()
96 {
97 return "bacon_spheroid";
98 }
99
100 };
101
102 // Apian Globular I
103 template <typename Parameters>
104 inline void setup_apian(Parameters& par, par_bacon& proj_parm)
105 {
106 proj_parm.bacn = proj_parm.ortl = false;
107 par.es = 0.;
108 }
109
110 // Ortelius Oval
111 template <typename Parameters>
112 inline void setup_ortel(Parameters& par, par_bacon& proj_parm)
113 {
114 proj_parm.bacn = false;
115 proj_parm.ortl = true;
116 par.es = 0.;
117 }
118
119 // Bacon Globular
120 template <typename Parameters>
121 inline void setup_bacon(Parameters& par, par_bacon& proj_parm)
122 {
123 proj_parm.bacn = true;
124 proj_parm.ortl = false;
125 par.es = 0.;
126 }
127
128 }} // namespace detail::bacon
129 #endif // doxygen
130
131 /*!
132 \brief Apian Globular I projection
133 \ingroup projections
134 \tparam Geographic latlong point type
135 \tparam Cartesian xy point type
136 \tparam Parameters parameter type
137 \par Projection characteristics
138 - Miscellaneous
139 - Spheroid
140 - no inverse
141 \par Example
142 \image html ex_apian.gif
143 */
144 template <typename T, typename Parameters>
145 struct apian_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
146 {
147 template <typename Params>
148 inline apian_spheroid(Params const& , Parameters & par)
149 {
150 detail::bacon::setup_apian(par, this->m_proj_parm);
151 }
152 };
153
154 /*!
155 \brief Ortelius Oval projection
156 \ingroup projections
157 \tparam Geographic latlong point type
158 \tparam Cartesian xy point type
159 \tparam Parameters parameter type
160 \par Projection characteristics
161 - Miscellaneous
162 - Spheroid
163 - no inverse
164 \par Example
165 \image html ex_ortel.gif
166 */
167 template <typename T, typename Parameters>
168 struct ortel_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
169 {
170 template <typename Params>
171 inline ortel_spheroid(Params const& , Parameters & par)
172 {
173 detail::bacon::setup_ortel(par, this->m_proj_parm);
174 }
175 };
176
177 /*!
178 \brief Bacon Globular projection
179 \ingroup projections
180 \tparam Geographic latlong point type
181 \tparam Cartesian xy point type
182 \tparam Parameters parameter type
183 \par Projection characteristics
184 - Miscellaneous
185 - Spheroid
186 - no inverse
187 \par Example
188 \image html ex_bacon.gif
189 */
190 template <typename T, typename Parameters>
191 struct bacon_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
192 {
193 template <typename Params>
194 inline bacon_spheroid(Params const& , Parameters & par)
195 {
196 detail::bacon::setup_bacon(par, this->m_proj_parm);
197 }
198 };
199
200 #ifndef DOXYGEN_NO_DETAIL
201 namespace detail
202 {
203
204 // Static projection
205 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_apian, apian_spheroid)
206 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_bacon, bacon_spheroid)
207 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_ortel, ortel_spheroid)
208
209 // Factory entry(s)
210 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(apian_entry, apian_spheroid)
211 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(ortel_entry, ortel_spheroid)
212 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(bacon_entry, bacon_spheroid)
213
214 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(bacon_init)
215 {
216 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(apian, apian_entry)
217 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(ortel, ortel_entry)
218 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(bacon, bacon_entry)
219 }
220
221 } // namespace detail
222 #endif // doxygen
223
224 } // namespace projections
225
226 }} // namespace boost::geometry
227
228 #endif // BOOST_GEOMETRY_PROJECTIONS_BACON_HPP
229