Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:39

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 // This file is manually converted from PROJ4
0003 
0004 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
0005 
0006 // This file was modified by Oracle on 2018.
0007 // Modifications copyright (c) 2018, Oracle and/or its affiliates.
0008 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0009 
0010 // Use, modification and distribution is subject to the Boost Software License,
0011 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0012 // http://www.boost.org/LICENSE_1_0.txt)
0013 
0014 // This file is converted from PROJ4, http://trac.osgeo.org/proj
0015 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
0016 // PROJ4 is maintained by Frank Warmerdam
0017 // PROJ4 is converted to Geometry Library by Barend Gehrels (Geodan, Amsterdam)
0018 
0019 // Original copyright notice:
0020 
0021 // Permission is hereby granted, free of charge, to any person obtaining a
0022 // copy of this software and associated documentation files (the "Software"),
0023 // to deal in the Software without restriction, including without limitation
0024 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
0025 // and/or sell copies of the Software, and to permit persons to whom the
0026 // Software is furnished to do so, subject to the following conditions:
0027 
0028 // The above copyright notice and this permission notice shall be included
0029 // in all copies or substantial portions of the Software.
0030 
0031 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0032 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0033 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0034 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0035 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0036 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0037 // DEALINGS IN THE SOFTWARE.
0038 
0039 #ifndef BOOST_GEOMETRY_PROJECTIONS_PROJ_MDIST_HPP
0040 #define BOOST_GEOMETRY_PROJECTIONS_PROJ_MDIST_HPP
0041 
0042 
0043 #include <boost/geometry/srs/projections/exception.hpp>
0044 #include <boost/geometry/srs/projections/impl/pj_strerrno.hpp>
0045 #include <boost/geometry/util/math.hpp>
0046 
0047 
0048 namespace boost { namespace geometry { namespace projections
0049 {
0050 namespace detail
0051 {
0052     template <typename T>
0053     struct mdist
0054     {
0055         static const int static_size = 20;
0056 
0057         T es;
0058         T E;
0059         T b[static_size];
0060         int nb;
0061     };
0062 
0063     template <typename T>
0064     inline bool proj_mdist_ini(T const& es, mdist<T>& b)
0065     {
0066         T numf, numfi, twon1, denf, denfi, ens, t, twon;
0067         T den, El, Es;
0068         T E[mdist<T>::static_size];
0069         int i, j;
0070 
0071         /* generate E(e^2) and its terms E[] */
0072         ens = es;
0073         numf = twon1 = denfi = 1.;
0074         denf = 1.;
0075         twon = 4.;
0076         Es = El = E[0] = 1.;
0077         for (i = 1; i < mdist<T>::static_size ; ++i)
0078         {
0079             numf *= (twon1 * twon1);
0080             den = twon * denf * denf * twon1;
0081             t = numf/den;
0082             E[i] = t * ens;
0083             Es -= E[i];
0084             ens *= es;
0085             twon *= 4.;
0086             denf *= ++denfi;
0087             twon1 += 2.;
0088             if (Es == El) /* jump out if no change */
0089                 break;
0090             El = Es;
0091         }
0092         b.nb = i - 1;
0093         b.es = es;
0094         b.E = Es;
0095         /* generate b_n coefficients--note: collapse with prefix ratios */
0096         b.b[0] = Es = 1. - Es;
0097         numf = denf = 1.;
0098         numfi = 2.;
0099         denfi = 3.;
0100         for (j = 1; j < i; ++j)
0101         {
0102             Es -= E[j];
0103             numf *= numfi;
0104             denf *= denfi;
0105             b.b[j] = Es * numf / denf;
0106             numfi += 2.;
0107             denfi += 2.;
0108         }
0109         return true;
0110     }
0111 
0112     template <typename T>
0113     inline T proj_mdist(T const& phi, T const& sphi, T const& cphi, mdist<T> const& b)
0114     {
0115         T sc, sum, sphi2, D;
0116         int i;
0117 
0118         sc = sphi * cphi;
0119         sphi2 = sphi * sphi;
0120         D = phi * b.E - b.es * sc / sqrt(1. - b.es * sphi2);
0121         sum = b.b[i = b.nb];
0122         while (i) sum = b.b[--i] + sphi2 * sum;
0123         return(D + sc * sum);
0124     }
0125 
0126     template <typename T>
0127     inline T proj_inv_mdist(T const& dist, mdist<T> const& b)
0128     {
0129         static const T TOL = 1e-14;
0130         T s, t, phi, k;
0131         int i;
0132 
0133         k = 1./(1.- b.es);
0134         i = mdist<T>::static_size;
0135         phi = dist;
0136         while ( i-- ) {
0137             s = sin(phi);
0138             t = 1. - b.es * s * s;
0139             phi -= t = (proj_mdist(phi, s, cos(phi), b) - dist) *
0140                 (t * sqrt(t)) * k;
0141             if (geometry::math::abs(t) < TOL) /* that is no change */
0142                 return phi;
0143         }
0144             /* convergence failed */
0145         BOOST_THROW_EXCEPTION( projection_exception(error_non_conv_inv_meri_dist) );
0146     }
0147 } // namespace detail
0148 
0149 }}} // namespace boost::geometry::projections
0150 
0151 #endif