rescale_policy.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2014-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2014-2015 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2015, 2023.
  7. // Modifications copyright (c) 2015-2023, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
  14. #define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
  15. #include <cstddef>
  16. #include <boost/geometry/core/access.hpp>
  17. #include <boost/geometry/core/coordinate_type.hpp>
  18. #include <boost/geometry/policies/robustness/segment_ratio.hpp>
  19. #include <boost/geometry/policies/robustness/robust_point_type.hpp>
  20. #include <boost/geometry/util/math.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. #ifndef DOXYGEN_NO_DETAIL
  24. namespace detail
  25. {
  26. template <typename FpPoint, typename IntPoint, typename CalculationType>
  27. struct robust_policy
  28. {
  29. static bool const enabled = true;
  30. typedef typename geometry::coordinate_type<IntPoint>::type output_ct;
  31. robust_policy(FpPoint const& fp_min, IntPoint const& int_min, CalculationType const& the_factor)
  32. : m_fp_min(fp_min)
  33. , m_int_min(int_min)
  34. , m_multiplier(the_factor)
  35. {
  36. }
  37. template <std::size_t Dimension, typename Value>
  38. inline output_ct apply(Value const& value) const
  39. {
  40. // a + (v-b)*f
  41. CalculationType const a = static_cast<CalculationType>(get<Dimension>(m_int_min));
  42. CalculationType const b = static_cast<CalculationType>(get<Dimension>(m_fp_min));
  43. CalculationType const result = a + (value - b) * m_multiplier;
  44. return geometry::math::rounding_cast<output_ct>(result);
  45. }
  46. FpPoint m_fp_min;
  47. IntPoint m_int_min;
  48. CalculationType m_multiplier;
  49. };
  50. } // namespace detail
  51. #endif
  52. // Implement meta-functions for this policy
  53. // Define the IntPoint as a robust-point type
  54. template <typename Point, typename FpPoint, typename IntPoint, typename CalculationType>
  55. struct robust_point_type<Point, detail::robust_policy<FpPoint, IntPoint, CalculationType> >
  56. {
  57. typedef IntPoint type;
  58. };
  59. }} // namespace boost::geometry
  60. #endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP