1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2014 Bruno Lalande, Paris, France.
5 // Copyright (c) 2014 Mateusz Loskot, London, UK.
6 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // 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
17 #include <boost/type_traits.hpp>
19 #include <boost/geometry/policies/robustness/segment_ratio.hpp>
20 #include <boost/geometry/policies/robustness/segment_ratio_type.hpp>
21 #include <boost/geometry/policies/robustness/robust_point_type.hpp>
23 namespace boost { namespace geometry
26 #ifndef DOXYGEN_NO_DETAIL
30 template <typename FpPoint, typename IntPoint, typename CalculationType>
33 static bool const enabled = true;
35 typedef typename geometry::coordinate_type<IntPoint>::type output_ct;
37 robust_policy(FpPoint const& fp_min, IntPoint const& int_min, CalculationType const& the_factor)
40 , m_multiplier(the_factor)
44 template <std::size_t Dimension, typename Value>
45 inline output_ct apply(Value const& value) const
48 CalculationType const a = static_cast<CalculationType>(get<Dimension>(m_int_min));
49 CalculationType const b = static_cast<CalculationType>(get<Dimension>(m_fp_min));
50 CalculationType const result = a + (value - b) * m_multiplier;
51 return static_cast<output_ct>(result);
56 CalculationType m_multiplier;
63 // Implement meta-functions for this policy
65 // Define the IntPoint as a robust-point type
66 template <typename Point, typename FpPoint, typename IntPoint, typename CalculationType>
67 struct robust_point_type<Point, detail::robust_policy<FpPoint, IntPoint, CalculationType> >
69 typedef IntPoint type;
72 // Meta function for rescaling, if rescaling is done segment_ratio is based on long long
73 template <typename Point, typename FpPoint, typename IntPoint, typename CalculationType>
74 struct segment_ratio_type<Point, detail::robust_policy<FpPoint, IntPoint, CalculationType> >
76 typedef segment_ratio<boost::long_long_type> type;
80 }} // namespace boost::geometry
83 #endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP