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 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 // This file is converted from PROJ4, http://trac.osgeo.org/proj
11 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
12 // PROJ4 is maintained by Frank Warmerdam
13 // PROJ4 is converted to Geometry Library by Barend Gehrels (Geodan, Amsterdam)
14
15 // Original copyright notice:
16
17 // Permission is hereby granted, free of charge, to any person obtaining a
18 // copy of this software and associated documentation files (the "Software"),
19 // to deal in the Software without restriction, including without limitation
20 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
21 // and/or sell copies of the Software, and to permit persons to whom the
22 // Software is furnished to do so, subject to the following conditions:
23
24 // The above copyright notice and this permission notice shall be included
25 // in all copies or substantial portions of the Software.
26
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
28 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33 // DEALINGS IN THE SOFTWARE.
34
35 #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_ADJLON_HPP
36 #define BOOST_GEOMETRY_PROJECTIONS_IMPL_ADJLON_HPP
37
38 #include <boost/math/constants/constants.hpp>
39 #include <boost/geometry/util/math.hpp>
40
41 namespace boost { namespace geometry { namespace projections
42 {
43
44 namespace detail
45 {
46
47 /* reduce argument to range +/- PI */
48 template <typename T>
adjlon(T lon)49 inline T adjlon (T lon)
50 {
51 if (geometry::math::abs(lon) <= boost::math::constants::pi<T>())
52 {
53 return lon;
54 }
55
56 /* adjust to 0..2pi rad */
57 lon += boost::math::constants::pi<T>();
58 /* remove integral # of 'revolutions'*/
59 lon -= boost::math::constants::two_pi<T>() *
60 std::floor(lon / boost::math::constants::two_pi<T>());
61 /* adjust back to -pi..pi rad */
62 lon -= boost::math::constants::pi<T>();
63
64 return lon;
65 }
66
67 } // namespace detail
68 }}} // namespace boost::geometry::projections
69
70 #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_ADJLON_HPP
71