eccentricity_sqr.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Boost.Geometry
  2. // Copyright (c) 2016, 2018 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_ECCENCRICITY_SQR_HPP
  8. #define BOOST_GEOMETRY_FORMULAS_ECCENCRICITY_SQR_HPP
  9. #include <boost/geometry/algorithms/not_implemented.hpp>
  10. #include <boost/geometry/core/radius.hpp>
  11. #include <boost/geometry/core/tag.hpp>
  12. #include <boost/geometry/core/tags.hpp>
  13. #include <boost/geometry/util/math.hpp>
  14. namespace boost { namespace geometry
  15. {
  16. #ifndef DOXYGEN_NO_DISPATCH
  17. namespace formula_dispatch
  18. {
  19. template <typename ResultType, typename Geometry, typename Tag = typename tag<Geometry>::type>
  20. struct eccentricity_sqr
  21. : not_implemented<Tag>
  22. {};
  23. template <typename ResultType, typename Geometry>
  24. struct eccentricity_sqr<ResultType, Geometry, srs_sphere_tag>
  25. {
  26. static inline ResultType apply(Geometry const& /*geometry*/)
  27. {
  28. return ResultType(0);
  29. }
  30. };
  31. template <typename ResultType, typename Geometry>
  32. struct eccentricity_sqr<ResultType, Geometry, srs_spheroid_tag>
  33. {
  34. static inline ResultType apply(Geometry const& geometry)
  35. {
  36. // 1 - (b / a)^2
  37. return ResultType(1) - math::sqr(ResultType(get_radius<2>(geometry))
  38. / ResultType(get_radius<0>(geometry)));
  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. ResultType eccentricity_sqr(Geometry const& geometry)
  48. {
  49. return formula_dispatch::eccentricity_sqr<ResultType, Geometry>::apply(geometry);
  50. }
  51. } // namespace formula
  52. #endif // DOXYGEN_NO_DETAIL
  53. }} // namespace boost::geometry
  54. #endif // BOOST_GEOMETRY_FORMULAS_ECCENCRICITY_SQR_HPP