]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/strategies/cartesian/line_interpolate.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / strategies / cartesian / line_interpolate.hpp
1 // Boost.Geometry
2
3 // Copyright (c) 2018-2021, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
10
11 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP
12 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP
13
14 #include <boost/geometry/core/assert.hpp>
15 #include <boost/geometry/core/coordinate_dimension.hpp>
16 #include <boost/geometry/core/coordinate_type.hpp>
17 #include <boost/geometry/strategies/line_interpolate.hpp>
18 #include <boost/geometry/strategies/cartesian/distance_pythagoras.hpp>
19 #include <boost/geometry/util/algorithm.hpp>
20 #include <boost/geometry/util/select_calculation_type.hpp>
21
22
23 namespace boost { namespace geometry
24 {
25
26 namespace strategy { namespace line_interpolate
27 {
28
29
30 /*!
31 \brief Interpolate point on a cartesian segment.
32 \ingroup strategies
33 \tparam CalculationType \tparam_calculation
34 \tparam DistanceStrategy The underlying point-point distance strategy
35
36 \qbk{
37 [heading See also]
38 \* [link geometry.reference.algorithms.line_interpolate.line_interpolate_4_with_strategy line_interpolate (with strategy)]
39 }
40
41 */
42 template
43 <
44 typename CalculationType = void,
45 typename DistanceStrategy = distance::pythagoras<CalculationType>
46 >
47 class cartesian
48 {
49 public:
50 template <typename Point, typename Fraction, typename Distance>
51 inline void apply(Point const& p0,
52 Point const& p1,
53 Fraction const& fraction,
54 Point & p,
55 Distance const&) const
56 {
57 typedef typename select_calculation_type_alt
58 <
59 CalculationType, Point
60 >::type calc_t;
61 typedef typename coordinate_type<Point>::type coord_t;
62
63 //segment convex combination: p0*fraction + p1*(1-fraction)
64 Fraction const one_minus_fraction = 1-fraction;
65 geometry::detail::for_each_dimension<Point>([&](auto dimension)
66 {
67 // NOTE: numeric_cast is a leftover from convert, it could probably be ommited.
68 // NOTE: the order of points is different than in the formula above
69 // this is also a leftover from the previous implementation
70 calc_t coord0 = boost::numeric_cast<calc_t>(get<dimension>(p0));
71 calc_t coord1 = boost::numeric_cast<calc_t>(get<dimension>(p1));
72 calc_t result = calc_t(coord1 * fraction) + calc_t(coord0 * one_minus_fraction);
73 set<dimension>(p, boost::numeric_cast<coord_t>(result));
74 });
75 }
76 };
77
78
79 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
80 namespace services
81 {
82
83 template <>
84 struct default_strategy<cartesian_tag>
85 {
86 typedef strategy::line_interpolate::cartesian<> type;
87 };
88
89
90 } // namespace services
91 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
92
93
94 }} // namespace strategy::line_interpolate
95
96
97 }} // namespace boost::geometry
98
99 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP