flattening.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Boost.Geometry
  2. // Copyright (c) 2014-2016 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  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. #ifndef BOOST_GEOMETRY_FORMULAS_FLATTENING_HPP
  8. #define BOOST_GEOMETRY_FORMULAS_FLATTENING_HPP
  9. #include <boost/geometry/core/radius.hpp>
  10. #include <boost/geometry/core/tag.hpp>
  11. #include <boost/geometry/core/tags.hpp>
  12. #include <boost/geometry/algorithms/not_implemented.hpp>
  13. namespace boost { namespace geometry
  14. {
  15. #ifndef DOXYGEN_NO_DISPATCH
  16. namespace formula_dispatch
  17. {
  18. template <typename ResultType, typename Geometry, typename Tag = typename tag<Geometry>::type>
  19. struct flattening
  20. : not_implemented<Tag>
  21. {};
  22. template <typename ResultType, typename Geometry>
  23. struct flattening<ResultType, Geometry, srs_sphere_tag>
  24. {
  25. static inline ResultType apply(Geometry const& /*geometry*/)
  26. {
  27. return ResultType(0);
  28. }
  29. };
  30. template <typename ResultType, typename Geometry>
  31. struct flattening<ResultType, Geometry, srs_spheroid_tag>
  32. {
  33. static inline ResultType apply(Geometry const& geometry)
  34. {
  35. // (a - b) / a
  36. return ResultType(get_radius<0>(geometry) - get_radius<2>(geometry))
  37. / ResultType(get_radius<0>(geometry));
  38. }
  39. };
  40. } // namespace formula_dispatch
  41. #endif // DOXYGEN_NO_DISPATCH
  42. #ifndef DOXYGEN_NO_DETAIL
  43. namespace formula
  44. {
  45. template <typename ResultType, typename Geometry>
  46. ResultType flattening(Geometry const& geometry)
  47. {
  48. return formula_dispatch::flattening<ResultType, Geometry>::apply(geometry);
  49. }
  50. } // namespace formula
  51. #endif // DOXYGEN_NO_DETAIL
  52. }} // namespace boost::geometry
  53. #endif // BOOST_GEOMETRY_FORMULAS_FLATTENING_HPP