Imported Upstream version 1.72.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-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.
7
8 // This file was modified by Oracle on 2015, 2018.
9 // Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
10
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12
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)
16
17 #ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
18 #define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
19
20 #include <cstddef>
21
22 #include <boost/geometry/core/coordinate_type.hpp>
23
24 #include <boost/geometry/policies/robustness/segment_ratio.hpp>
25 #include <boost/geometry/policies/robustness/robust_point_type.hpp>
26
27 #include <boost/geometry/util/math.hpp>
28
29 namespace boost { namespace geometry
30 {
31
32 #ifndef DOXYGEN_NO_DETAIL
33 namespace detail
34 {
35
36 template <typename FpPoint, typename IntPoint, typename CalculationType>
37 struct robust_policy
38 {
39     static bool const enabled = true;
40
41     typedef typename geometry::coordinate_type<IntPoint>::type output_ct;
42
43     robust_policy(FpPoint const& fp_min, IntPoint const& int_min, CalculationType const& the_factor)
44         : m_fp_min(fp_min)
45         , m_int_min(int_min)
46         , m_multiplier(the_factor)
47     {
48     }
49
50     template <std::size_t Dimension, typename Value>
51     inline output_ct apply(Value const& value) const
52     {
53         // a + (v-b)*f
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;
57
58         return geometry::math::rounding_cast<output_ct>(result);
59     }
60
61     FpPoint m_fp_min;
62     IntPoint m_int_min;
63     CalculationType m_multiplier;
64 };
65
66 } // namespace detail
67 #endif
68
69
70 // Implement meta-functions for this policy
71
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> >
75 {
76     typedef IntPoint type;
77 };
78
79
80 }} // namespace boost::geometry
81
82
83 #endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP