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.
6 // Modifications copyright (c) 2017-2018, 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                 int bacn;
65                 int ortl;
66             };
67 
68             // template class, using CRTP to implement forward/inverse
69             template <typename T, typename Parameters>
70             struct base_bacon_spheroid
71                 : public base_t_f<base_bacon_spheroid<T, Parameters>, T, Parameters>
72             {
73                 par_bacon m_proj_parm;
74 
base_bacon_spheroidboost::geometry::projections::detail::bacon::base_bacon_spheroid75                 inline base_bacon_spheroid(const Parameters& par)
76                     : base_t_f<base_bacon_spheroid<T, Parameters>, T, Parameters>(*this, par)
77                 {}
78 
79                 // FORWARD(s_forward)  spheroid
80                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
fwdboost::geometry::projections::detail::bacon::base_bacon_spheroid81                 inline void fwd(T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
82                 {
83                     static const T half_pi = detail::half_pi<T>();
84                     static const T half_pi_sqr = detail::half_pi_sqr<T>();
85 
86                     T ax, f;
87 
88                     xy_y = this->m_proj_parm.bacn ? half_pi * sin(lp_lat) : lp_lat;
89                     if ((ax = fabs(lp_lon)) >= epsilon) {
90                         if (this->m_proj_parm.ortl && ax >= half_pi)
91                             xy_x = sqrt(half_pi_sqr - lp_lat * lp_lat + epsilon) + ax - half_pi;
92                         else {
93                             f = 0.5 * (half_pi_sqr / ax + ax);
94                             xy_x = ax - f + sqrt(f * f - xy_y * xy_y);
95                         }
96                         if (lp_lon < 0.) xy_x = - xy_x;
97                     } else
98                         xy_x = 0.;
99                 }
100 
get_nameboost::geometry::projections::detail::bacon::base_bacon_spheroid101                 static inline std::string get_name()
102                 {
103                     return "bacon_spheroid";
104                 }
105 
106             };
107 
108             // Apian Globular I
109             template <typename Parameters>
setup_apian(Parameters & par,par_bacon & proj_parm)110             inline void setup_apian(Parameters& par, par_bacon& proj_parm)
111             {
112                 proj_parm.bacn = proj_parm.ortl = 0;
113                 par.es = 0.;
114             }
115 
116             // Ortelius Oval
117             template <typename Parameters>
setup_ortel(Parameters & par,par_bacon & proj_parm)118             inline void setup_ortel(Parameters& par, par_bacon& proj_parm)
119             {
120                 proj_parm.bacn = 0;
121                 proj_parm.ortl = 1;
122                 par.es = 0.;
123             }
124 
125             // Bacon Globular
126             template <typename Parameters>
setup_bacon(Parameters & par,par_bacon & proj_parm)127             inline void setup_bacon(Parameters& par, par_bacon& proj_parm)
128             {
129                 proj_parm.bacn = 1;
130                 proj_parm.ortl = 0;
131                 par.es = 0.;
132             }
133 
134     }} // namespace detail::bacon
135     #endif // doxygen
136 
137     /*!
138         \brief Apian Globular I projection
139         \ingroup projections
140         \tparam Geographic latlong point type
141         \tparam Cartesian xy point type
142         \tparam Parameters parameter type
143         \par Projection characteristics
144          - Miscellaneous
145          - Spheroid
146          - no inverse
147         \par Example
148         \image html ex_apian.gif
149     */
150     template <typename T, typename Parameters>
151     struct apian_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
152     {
153         template <typename Params>
apian_spheroidboost::geometry::projections::apian_spheroid154         inline apian_spheroid(Params const& , Parameters const& par)
155             : detail::bacon::base_bacon_spheroid<T, Parameters>(par)
156         {
157             detail::bacon::setup_apian(this->m_par, this->m_proj_parm);
158         }
159     };
160 
161     /*!
162         \brief Ortelius Oval projection
163         \ingroup projections
164         \tparam Geographic latlong point type
165         \tparam Cartesian xy point type
166         \tparam Parameters parameter type
167         \par Projection characteristics
168          - Miscellaneous
169          - Spheroid
170          - no inverse
171         \par Example
172         \image html ex_ortel.gif
173     */
174     template <typename T, typename Parameters>
175     struct ortel_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
176     {
177         template <typename Params>
ortel_spheroidboost::geometry::projections::ortel_spheroid178         inline ortel_spheroid(Params const& , Parameters const& par)
179             : detail::bacon::base_bacon_spheroid<T, Parameters>(par)
180         {
181             detail::bacon::setup_ortel(this->m_par, this->m_proj_parm);
182         }
183     };
184 
185     /*!
186         \brief Bacon Globular projection
187         \ingroup projections
188         \tparam Geographic latlong point type
189         \tparam Cartesian xy point type
190         \tparam Parameters parameter type
191         \par Projection characteristics
192          - Miscellaneous
193          - Spheroid
194          - no inverse
195         \par Example
196         \image html ex_bacon.gif
197     */
198     template <typename T, typename Parameters>
199     struct bacon_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
200     {
201         template <typename Params>
bacon_spheroidboost::geometry::projections::bacon_spheroid202         inline bacon_spheroid(Params const& , Parameters const& par)
203             : detail::bacon::base_bacon_spheroid<T, Parameters>(par)
204         {
205             detail::bacon::setup_bacon(this->m_par, this->m_proj_parm);
206         }
207     };
208 
209     #ifndef DOXYGEN_NO_DETAIL
210     namespace detail
211     {
212 
213         // Static projection
BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::spar::proj_apian,apian_spheroid,apian_spheroid)214         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::spar::proj_apian, apian_spheroid, apian_spheroid)
215         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::spar::proj_bacon, bacon_spheroid, bacon_spheroid)
216         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::spar::proj_ortel, ortel_spheroid, ortel_spheroid)
217 
218         // Factory entry(s)
219         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(apian_entry, apian_spheroid)
220         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(ortel_entry, ortel_spheroid)
221         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(bacon_entry, bacon_spheroid)
222 
223         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(bacon_init)
224         {
225             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(apian, apian_entry)
226             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(ortel, ortel_entry)
227             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(bacon, bacon_entry)
228         }
229 
230     } // namespace detail
231     #endif // doxygen
232 
233 } // namespace projections
234 
235 }} // namespace boost::geometry
236 
237 #endif // BOOST_GEOMETRY_PROJECTIONS_BACON_HPP
238 
239