diff_abs.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Boost.Geometry Index
  2. //
  3. // Abs of difference
  4. //
  5. // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2020-2023.
  8. // Modifications copyright (c) 2020-2023, Oracle and/or its affiliates.
  9. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  10. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  11. //
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_DIFF_ABS_HPP
  16. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_DIFF_ABS_HPP
  17. #include <cmath>
  18. #include <type_traits>
  19. namespace boost { namespace geometry { namespace index { namespace detail
  20. {
  21. template
  22. <
  23. typename T,
  24. std::enable_if_t<std::is_integral<T>::value, int> = 0
  25. >
  26. inline T diff_abs(T const& v1, T const& v2)
  27. {
  28. return v1 < v2 ? v2 - v1 : v1 - v2;
  29. }
  30. template
  31. <
  32. typename T,
  33. std::enable_if_t<! std::is_integral<T>::value, int> = 0
  34. >
  35. inline T diff_abs(T const& v1, T const& v2)
  36. {
  37. return ::fabs(v1 - v2);
  38. }
  39. }}}} // namespace boost::geometry::index::detail
  40. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_DIFF_ABS_HPP