get_max_size.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2014 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2018.
  7. // Modifications copyright (c) 2018, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Use, modification and distribution is subject to the Boost Software License,
  10. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_GET_MAX_SIZE_HPP
  13. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_GET_MAX_SIZE_HPP
  14. #include <cstddef>
  15. #include <boost/geometry/core/access.hpp>
  16. #include <boost/geometry/core/coordinate_dimension.hpp>
  17. #include <boost/geometry/util/math.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. #ifndef DOXYGEN_NO_DETAIL
  21. namespace detail
  22. {
  23. template <typename Box, std::size_t Dimension>
  24. struct get_max_size_box
  25. {
  26. static inline typename coordinate_type<Box>::type apply(Box const& box)
  27. {
  28. typename coordinate_type<Box>::type s
  29. = geometry::math::abs(geometry::get<1, Dimension>(box) - geometry::get<0, Dimension>(box));
  30. return (std::max)(s, get_max_size_box<Box, Dimension - 1>::apply(box));
  31. }
  32. };
  33. template <typename Box>
  34. struct get_max_size_box<Box, 0>
  35. {
  36. static inline typename coordinate_type<Box>::type apply(Box const& box)
  37. {
  38. return geometry::math::abs(geometry::get<1, 0>(box) - geometry::get<0, 0>(box));
  39. }
  40. };
  41. // This might be implemented later on for other geometries too.
  42. // Not dispatched yet.
  43. template <typename Box>
  44. inline typename coordinate_type<Box>::type get_max_size(Box const& box)
  45. {
  46. return get_max_size_box<Box, dimension<Box>::value - 1>::apply(box);
  47. }
  48. } // namespace detail
  49. #endif // DOXYGEN_NO_DETAIL
  50. }} // namespace boost::geometry
  51. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_GET_MAX_SIZE_HPP