1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2014-2015 Bruno Lalande, Paris, France.
5 // Copyright (c) 2014-2015 Mateusz Loskot, London, UK.
6 // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
8 // This file was modified by Oracle on 2015, 2018.
9 // Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 #ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
18 #define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
22 #include <boost/geometry/core/coordinate_type.hpp>
24 #include <boost/geometry/policies/robustness/segment_ratio.hpp>
25 #include <boost/geometry/policies/robustness/robust_point_type.hpp>
27 #include <boost/geometry/util/math.hpp>
29 namespace boost { namespace geometry
32 #ifndef DOXYGEN_NO_DETAIL
36 template <typename FpPoint, typename IntPoint, typename CalculationType>
39 static bool const enabled = true;
41 typedef typename geometry::coordinate_type<IntPoint>::type output_ct;
43 robust_policy(FpPoint const& fp_min, IntPoint const& int_min, CalculationType const& the_factor)
46 , m_multiplier(the_factor)
50 template <std::size_t Dimension, typename Value>
51 inline output_ct apply(Value const& value) const
54 CalculationType const a = static_cast<CalculationType>(get<Dimension>(m_int_min));
55 CalculationType const b = static_cast<CalculationType>(get<Dimension>(m_fp_min));
56 CalculationType const result = a + (value - b) * m_multiplier;
58 return geometry::math::rounding_cast<output_ct>(result);
63 CalculationType m_multiplier;
70 // Implement meta-functions for this policy
72 // Define the IntPoint as a robust-point type
73 template <typename Point, typename FpPoint, typename IntPoint, typename CalculationType>
74 struct robust_point_type<Point, detail::robust_policy<FpPoint, IntPoint, CalculationType> >
76 typedef IntPoint type;
80 }} // namespace boost::geometry
83 #endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP