Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / geometry / policies / robustness / rescale_policy.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
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.
7
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)
11
12 #ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
13 #define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
14
15 #include <cstddef>
16
17 #include <boost/type_traits.hpp>
18
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>
22
23 namespace boost { namespace geometry
24 {
25
26 #ifndef DOXYGEN_NO_DETAIL
27 namespace detail
28 {
29
30 template <typename FpPoint, typename IntPoint, typename CalculationType>
31 struct robust_policy
32 {
33     static bool const enabled = true;
34
35     typedef typename geometry::coordinate_type<IntPoint>::type output_ct;
36
37     robust_policy(FpPoint const& fp_min, IntPoint const& int_min, CalculationType const& the_factor)
38         : m_fp_min(fp_min)
39         , m_int_min(int_min)
40         , m_multiplier(the_factor)
41     {
42     }
43
44     template <std::size_t Dimension, typename Value>
45     inline output_ct apply(Value const& value) const
46     {
47         // a + (v-b)*f
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);
52     }
53
54     FpPoint m_fp_min;
55     IntPoint m_int_min;
56     CalculationType m_multiplier;
57 };
58
59 } // namespace detail
60 #endif
61
62
63 // Implement meta-functions for this policy
64
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> >
68 {
69     typedef IntPoint type;
70 };
71
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> >
75 {
76     typedef segment_ratio<boost::long_long_type> type;
77 };
78
79
80 }} // namespace boost::geometry
81
82
83 #endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP