mean_radius.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Boost.Geometry
  2. // Copyright (c) 2017 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_MEAN_RADIUS_HPP
  8. #define BOOST_GEOMETRY_FORMULAS_MEAN_RADIUS_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 mean_radius
  20. : not_implemented<Tag>
  21. {};
  22. template <typename ResultType, typename Geometry>
  23. struct mean_radius<ResultType, Geometry, srs_sphere_tag>
  24. {
  25. static inline ResultType apply(Geometry const& geometry)
  26. {
  27. return ResultType(get_radius<0>(geometry));
  28. }
  29. };
  30. template <typename ResultType, typename Geometry>
  31. struct mean_radius<ResultType, Geometry, srs_spheroid_tag>
  32. {
  33. static inline ResultType apply(Geometry const& geometry)
  34. {
  35. // (2*a + b) / 3
  36. return (ResultType(2) * ResultType(get_radius<0>(geometry))
  37. + ResultType(get_radius<2>(geometry)))
  38. / ResultType(3);
  39. }
  40. };
  41. } // namespace formula_dispatch
  42. #endif // DOXYGEN_NO_DISPATCH
  43. #ifndef DOXYGEN_NO_DETAIL
  44. namespace formula
  45. {
  46. template <typename ResultType, typename Geometry>
  47. inline ResultType mean_radius(Geometry const& geometry)
  48. {
  49. return formula_dispatch::mean_radius<ResultType, Geometry>::apply(geometry);
  50. }
  51. } // namespace formula
  52. #endif // DOXYGEN_NO_DETAIL
  53. }} // namespace boost::geometry
  54. #endif // BOOST_GEOMETRY_FORMULAS_MEAN_RADIUS_HPP