Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / srs / projections / proj / eck3.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_ECK3_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_ECK3_HPP
42
43 #include <boost/core/ignore_unused.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 #include <boost/geometry/srs/projections/impl/aasincos.hpp>
50
51 namespace boost { namespace geometry
52 {
53
54 namespace projections
55 {
56     #ifndef DOXYGEN_NO_DETAIL
57     namespace detail { namespace eck3
58     {
59
60             template <typename T>
61             struct par_eck3
62             {
63                 T C_x, C_y, A, B;
64             };
65
66             template <typename T, typename Parameters>
67             struct base_eck3_spheroid
68             {
69                 par_eck3<T> m_proj_parm;
70
71                 // FORWARD(s_forward)  spheroid
72                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
73                 inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
74                 {
75                     xy_y = this->m_proj_parm.C_y * lp_lat;
76                     xy_x = this->m_proj_parm.C_x * lp_lon * (this->m_proj_parm.A + asqrt(1. - this->m_proj_parm.B * lp_lat * lp_lat));
77                 }
78
79                 // INVERSE(s_inverse)  spheroid
80                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
81                 inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
82                 {
83                     T denominator;
84                     lp_lat = xy_y / this->m_proj_parm.C_y;
85                     denominator = (this->m_proj_parm.C_x * (this->m_proj_parm.A + asqrt(1. - this->m_proj_parm.B * lp_lat * lp_lat)));
86                     if ( denominator == 0.0) {
87                         lp_lon = HUGE_VAL;
88                         lp_lat = HUGE_VAL;
89                     } else
90                         lp_lon = xy_x / denominator;
91                 }
92
93                 static inline std::string get_name()
94                 {
95                     return "eck3_spheroid";
96                 }
97
98             };
99
100             template <typename Parameters>
101             inline void setup(Parameters& par)
102             {
103                 par.es = 0.;
104             }
105
106
107             // Eckert III
108             template <typename Parameters, typename T>
109             inline void setup_eck3(Parameters& par, par_eck3<T>& proj_parm)
110             {
111                 proj_parm.C_x = 0.42223820031577120149;
112                 proj_parm.C_y = 0.84447640063154240298;
113                 proj_parm.A = 1.0;
114                 proj_parm.B = 0.4052847345693510857755;
115
116                 setup(par);
117             }
118
119             // Putnins P1
120             template <typename Parameters, typename T>
121             inline void setup_putp1(Parameters& par, par_eck3<T>& proj_parm)
122             {
123                 proj_parm.C_x = 1.89490;
124                 proj_parm.C_y = 0.94745;
125                 proj_parm.A = -0.5;
126                 proj_parm.B = 0.30396355092701331433;
127
128                 setup(par);
129             }
130
131             // Wagner VI
132             template <typename Parameters, typename T>
133             inline void setup_wag6(Parameters& par, par_eck3<T>& proj_parm)
134             {
135                 proj_parm.C_x = proj_parm.C_y = 0.94745;
136                 proj_parm.A = 0.0;
137                 proj_parm.B = 0.30396355092701331433;
138
139                 setup(par);
140             }
141
142             // Kavraisky VII
143             template <typename Parameters, typename T>
144             inline void setup_kav7(Parameters& par, par_eck3<T>& proj_parm)
145             {
146                 /* Defined twice in original code - Using 0.866...,
147                  * but leaving the other one here as a safety measure.
148                  * proj_parm.C_x = 0.2632401569273184856851; */
149                 proj_parm.C_x = 0.8660254037844;
150                 proj_parm.C_y = 1.0;
151                 proj_parm.A = 0.0;
152                 proj_parm.B = 0.30396355092701331433;
153
154                 setup(par);
155             }
156
157     }} // namespace detail::eck3
158     #endif // doxygen
159
160     /*!
161         \brief Eckert III projection
162         \ingroup projections
163         \tparam Geographic latlong point type
164         \tparam Cartesian xy point type
165         \tparam Parameters parameter type
166         \par Projection characteristics
167          - Pseudocylindrical
168          - Spheroid
169         \par Example
170         \image html ex_eck3.gif
171     */
172     template <typename T, typename Parameters>
173     struct eck3_spheroid : public detail::eck3::base_eck3_spheroid<T, Parameters>
174     {
175         template <typename Params>
176         inline eck3_spheroid(Params const& , Parameters & par)
177         {
178             detail::eck3::setup_eck3(par, this->m_proj_parm);
179         }
180     };
181
182     /*!
183         \brief Putnins P1 projection
184         \ingroup projections
185         \tparam Geographic latlong point type
186         \tparam Cartesian xy point type
187         \tparam Parameters parameter type
188         \par Projection characteristics
189          - Pseudocylindrical
190          - Spheroid
191         \par Example
192         \image html ex_putp1.gif
193     */
194     template <typename T, typename Parameters>
195     struct putp1_spheroid : public detail::eck3::base_eck3_spheroid<T, Parameters>
196     {
197         template <typename Params>
198         inline putp1_spheroid(Params const& , Parameters & par)
199         {
200             detail::eck3::setup_putp1(par, this->m_proj_parm);
201         }
202     };
203
204     /*!
205         \brief Wagner VI projection
206         \ingroup projections
207         \tparam Geographic latlong point type
208         \tparam Cartesian xy point type
209         \tparam Parameters parameter type
210         \par Projection characteristics
211          - Pseudocylindrical
212          - Spheroid
213         \par Example
214         \image html ex_wag6.gif
215     */
216     template <typename T, typename Parameters>
217     struct wag6_spheroid : public detail::eck3::base_eck3_spheroid<T, Parameters>
218     {
219         template <typename Params>
220         inline wag6_spheroid(Params const& , Parameters & par)
221         {
222             detail::eck3::setup_wag6(par, this->m_proj_parm);
223         }
224     };
225
226     /*!
227         \brief Kavraisky VII projection
228         \ingroup projections
229         \tparam Geographic latlong point type
230         \tparam Cartesian xy point type
231         \tparam Parameters parameter type
232         \par Projection characteristics
233          - Pseudocylindrical
234          - Spheroid
235         \par Example
236         \image html ex_kav7.gif
237     */
238     template <typename T, typename Parameters>
239     struct kav7_spheroid : public detail::eck3::base_eck3_spheroid<T, Parameters>
240     {
241         template <typename Params>
242         inline kav7_spheroid(Params const& , Parameters & par)
243         {
244             detail::eck3::setup_kav7(par, this->m_proj_parm);
245         }
246     };
247
248     #ifndef DOXYGEN_NO_DETAIL
249     namespace detail
250     {
251
252         // Static projection
253         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_eck3, eck3_spheroid)
254         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_putp1, putp1_spheroid)
255         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_wag6, wag6_spheroid)
256         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_kav7, kav7_spheroid)
257
258         // Factory entry(s)
259         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(eck3_entry, eck3_spheroid)
260         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(putp1_entry, putp1_spheroid)
261         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(wag6_entry, wag6_spheroid)
262         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(kav7_entry, kav7_spheroid)
263         
264         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(eck3_init)
265         {
266             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(eck3, eck3_entry);
267             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(putp1, putp1_entry);
268             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(wag6, wag6_entry);
269             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(kav7, kav7_entry);
270         }
271
272     } // namespace detail
273     #endif // doxygen
274
275 } // namespace projections
276
277 }} // namespace boost::geometry
278
279 #endif // BOOST_GEOMETRY_PROJECTIONS_ECK3_HPP
280