1 // Boost.Geometry 2 3 // Copyright (c) 2018, Oracle and/or its affiliates. 4 5 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle 6 7 // Licensed under the Boost Software License version 1.0. 8 // http://www.boost.org/users/license.html 9 10 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP 11 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP 12 13 #include <boost/geometry/core/assert.hpp> 14 #include <boost/geometry/core/coordinate_dimension.hpp> 15 #include <boost/geometry/core/coordinate_type.hpp> 16 #include <boost/geometry/strategies/line_interpolate.hpp> 17 #include <boost/geometry/strategies/cartesian/distance_pythagoras.hpp> 18 #include <boost/geometry/util/select_calculation_type.hpp> 19 20 21 namespace boost { namespace geometry 22 { 23 24 namespace strategy { namespace line_interpolate 25 { 26 27 28 /*! 29 \brief Interpolate point on a cartesian segment. 30 \ingroup strategies 31 \tparam CalculationType \tparam_calculation 32 \tparam DistanceStrategy The underlying point-point distance strategy 33 34 \qbk{ 35 [heading See also] 36 \* [link geometry.reference.algorithms.line_interpolate.line_interpolate_4_with_strategy line_interpolate (with strategy)] 37 } 38 39 */ 40 template 41 < 42 typename CalculationType = void, 43 typename DistanceStrategy = distance::pythagoras<CalculationType> 44 > 45 class cartesian 46 { 47 public: 48 49 // point-point strategy getters 50 struct distance_pp_strategy 51 { 52 typedef DistanceStrategy type; 53 }; 54 get_distance_pp_strategy() const55 inline typename distance_pp_strategy::type get_distance_pp_strategy() const 56 { 57 typedef typename distance_pp_strategy::type distance_type; 58 return distance_type(); 59 } 60 61 template <typename Point, typename Fraction, typename Distance> apply(Point const & p0,Point const & p1,Fraction const & fraction,Point & p,Distance const &) const62 inline void apply(Point const& p0, 63 Point const& p1, 64 Fraction const& fraction, 65 Point & p, 66 Distance const&) const 67 { 68 typedef typename select_calculation_type_alt 69 < 70 CalculationType, 71 Point 72 >::type calc_t; 73 74 typedef model::point 75 < 76 calc_t, 77 geometry::dimension<Point>::value, 78 cs::cartesian 79 > calc_point_t; 80 81 calc_point_t cp0, cp1; 82 geometry::detail::conversion::convert_point_to_point(p0, cp0); 83 geometry::detail::conversion::convert_point_to_point(p1, cp1); 84 85 //segment convex combination: p0*fraction + p1*(1-fraction) 86 Fraction const one_minus_fraction = 1-fraction; 87 for_each_coordinate(cp1, detail::value_operation 88 < 89 Fraction, 90 std::multiplies 91 >(fraction)); 92 for_each_coordinate(cp0, detail::value_operation 93 < 94 Fraction, 95 std::multiplies 96 >(one_minus_fraction)); 97 for_each_coordinate(cp1, detail::point_operation 98 < 99 calc_point_t, 100 std::plus 101 >(cp0)); 102 103 assert_dimension_equal<calc_point_t, Point>(); 104 geometry::detail::conversion::convert_point_to_point(cp1, p); 105 } 106 }; 107 108 109 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS 110 namespace services 111 { 112 113 template <> 114 struct default_strategy<cartesian_tag> 115 { 116 typedef strategy::line_interpolate::cartesian<> type; 117 }; 118 119 120 } // namespace services 121 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS 122 123 124 }} // namespace strategy::line_interpolate 125 126 127 }} // namespace boost::geometry 128 129 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP 130