File indexing completed on 2025-01-18 09:36:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP
0012 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP
0013
0014 #include <boost/geometry/core/assert.hpp>
0015 #include <boost/geometry/core/coordinate_dimension.hpp>
0016 #include <boost/geometry/core/coordinate_type.hpp>
0017 #include <boost/geometry/strategies/line_interpolate.hpp>
0018 #include <boost/geometry/strategies/cartesian/distance_pythagoras.hpp>
0019 #include <boost/geometry/util/algorithm.hpp>
0020 #include <boost/geometry/util/select_calculation_type.hpp>
0021
0022
0023 namespace boost { namespace geometry
0024 {
0025
0026 namespace strategy { namespace line_interpolate
0027 {
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 template
0043 <
0044 typename CalculationType = void,
0045 typename DistanceStrategy = distance::pythagoras<CalculationType>
0046 >
0047 class cartesian
0048 {
0049 public:
0050 template <typename Point, typename Fraction, typename Distance>
0051 inline void apply(Point const& p0,
0052 Point const& p1,
0053 Fraction const& fraction,
0054 Point & p,
0055 Distance const&) const
0056 {
0057 typedef typename select_calculation_type_alt
0058 <
0059 CalculationType, Point
0060 >::type calc_t;
0061 typedef typename coordinate_type<Point>::type coord_t;
0062
0063
0064 Fraction const one_minus_fraction = 1-fraction;
0065 geometry::detail::for_each_dimension<Point>([&](auto dimension)
0066 {
0067
0068
0069
0070 calc_t coord0 = boost::numeric_cast<calc_t>(get<dimension>(p0));
0071 calc_t coord1 = boost::numeric_cast<calc_t>(get<dimension>(p1));
0072 calc_t result = calc_t(coord1 * fraction) + calc_t(coord0 * one_minus_fraction);
0073 set<dimension>(p, boost::numeric_cast<coord_t>(result));
0074 });
0075 }
0076 };
0077
0078
0079 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0080 namespace services
0081 {
0082
0083 template <>
0084 struct default_strategy<cartesian_tag>
0085 {
0086 typedef strategy::line_interpolate::cartesian<> type;
0087 };
0088
0089
0090 }
0091 #endif
0092
0093
0094 }}
0095
0096
0097 }}
0098
0099 #endif