adjlon.hpp 2.6 KB

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