]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | // Copyright (c) 2015, Oracle and/or its affiliates. | |
9 | ||
10 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
11 | ||
12 | // Use, modification and distribution is subject to the Boost Software License, | |
13 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
14 | // http://www.boost.org/LICENSE_1_0.txt) | |
15 | ||
16 | #ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP | |
17 | #define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP | |
18 | ||
19 | #include <cstddef> | |
20 | ||
21 | #include <boost/geometry/policies/robustness/segment_ratio.hpp> | |
22 | #include <boost/geometry/policies/robustness/segment_ratio_type.hpp> | |
23 | #include <boost/geometry/policies/robustness/robust_point_type.hpp> | |
24 | ||
25 | #include <boost/geometry/util/math.hpp> | |
26 | ||
27 | namespace boost { namespace geometry | |
28 | { | |
29 | ||
30 | #ifndef DOXYGEN_NO_DETAIL | |
31 | namespace detail | |
32 | { | |
33 | ||
34 | template <typename FpPoint, typename IntPoint, typename CalculationType> | |
35 | struct robust_policy | |
36 | { | |
37 | static bool const enabled = true; | |
38 | ||
39 | typedef typename geometry::coordinate_type<IntPoint>::type output_ct; | |
40 | ||
41 | robust_policy(FpPoint const& fp_min, IntPoint const& int_min, CalculationType const& the_factor) | |
42 | : m_fp_min(fp_min) | |
43 | , m_int_min(int_min) | |
44 | , m_multiplier(the_factor) | |
45 | { | |
46 | } | |
47 | ||
48 | template <std::size_t Dimension, typename Value> | |
49 | inline output_ct apply(Value const& value) const | |
50 | { | |
51 | // a + (v-b)*f | |
52 | CalculationType const a = static_cast<CalculationType>(get<Dimension>(m_int_min)); | |
53 | CalculationType const b = static_cast<CalculationType>(get<Dimension>(m_fp_min)); | |
54 | CalculationType const result = a + (value - b) * m_multiplier; | |
55 | ||
56 | return geometry::math::rounding_cast<output_ct>(result); | |
57 | } | |
58 | ||
59 | FpPoint m_fp_min; | |
60 | IntPoint m_int_min; | |
61 | CalculationType m_multiplier; | |
62 | }; | |
63 | ||
64 | } // namespace detail | |
65 | #endif | |
66 | ||
67 | ||
68 | // Implement meta-functions for this policy | |
69 | ||
70 | // Define the IntPoint as a robust-point type | |
71 | template <typename Point, typename FpPoint, typename IntPoint, typename CalculationType> | |
72 | struct robust_point_type<Point, detail::robust_policy<FpPoint, IntPoint, CalculationType> > | |
73 | { | |
74 | typedef IntPoint type; | |
75 | }; | |
76 | ||
77 | // Meta function for rescaling, if rescaling is done segment_ratio is based on long long | |
78 | template <typename Point, typename FpPoint, typename IntPoint, typename CalculationType> | |
79 | struct segment_ratio_type<Point, detail::robust_policy<FpPoint, IntPoint, CalculationType> > | |
80 | { | |
81 | typedef segment_ratio<boost::long_long_type> type; | |
82 | }; | |
83 | ||
84 | ||
85 | }} // namespace boost::geometry | |
86 | ||
87 | ||
88 | #endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP |