rescale_policy.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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, 2018.
  7. // Modifications copyright (c) 2015-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_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
  13. #define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
  14. #include <cstddef>
  15. #include <boost/geometry/core/coordinate_type.hpp>
  16. #include <boost/geometry/policies/robustness/segment_ratio.hpp>
  17. #include <boost/geometry/policies/robustness/robust_point_type.hpp>
  18. #include <boost/geometry/util/math.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. #ifndef DOXYGEN_NO_DETAIL
  22. namespace detail
  23. {
  24. template <typename FpPoint, typename IntPoint, typename CalculationType>
  25. struct robust_policy
  26. {
  27. static bool const enabled = true;
  28. typedef typename geometry::coordinate_type<IntPoint>::type output_ct;
  29. robust_policy(FpPoint const& fp_min, IntPoint const& int_min, CalculationType const& the_factor)
  30. : m_fp_min(fp_min)
  31. , m_int_min(int_min)
  32. , m_multiplier(the_factor)
  33. {
  34. }
  35. template <std::size_t Dimension, typename Value>
  36. inline output_ct apply(Value const& value) const
  37. {
  38. // a + (v-b)*f
  39. CalculationType const a = static_cast<CalculationType>(get<Dimension>(m_int_min));
  40. CalculationType const b = static_cast<CalculationType>(get<Dimension>(m_fp_min));
  41. CalculationType const result = a + (value - b) * m_multiplier;
  42. return geometry::math::rounding_cast<output_ct>(result);
  43. }
  44. FpPoint m_fp_min;
  45. IntPoint m_int_min;
  46. CalculationType m_multiplier;
  47. };
  48. } // namespace detail
  49. #endif
  50. // Implement meta-functions for this policy
  51. // Define the IntPoint as a robust-point type
  52. template <typename Point, typename FpPoint, typename IntPoint, typename CalculationType>
  53. struct robust_point_type<Point, detail::robust_policy<FpPoint, IntPoint, CalculationType> >
  54. {
  55. typedef IntPoint type;
  56. };
  57. }} // namespace boost::geometry
  58. #endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP