Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 08:12:18

0001 // Boost.Geometry
0002 
0003 // Copyright (c) 2018-2021, Oracle and/or its affiliates.
0004 
0005 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
0006 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0007 
0008 // Licensed under the Boost Software License version 1.0.
0009 // http://www.boost.org/users/license.html
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/numeric_cast.hpp>
0021 #include <boost/geometry/util/select_calculation_type.hpp>
0022 
0023 
0024 namespace boost { namespace geometry
0025 {
0026 
0027 namespace strategy { namespace line_interpolate
0028 {
0029 
0030 
0031 /*!
0032 \brief Interpolate point on a cartesian segment.
0033 \ingroup strategies
0034 \tparam CalculationType \tparam_calculation
0035 \tparam DistanceStrategy The underlying point-point distance strategy
0036 
0037 \qbk{
0038 [heading See also]
0039 \* [link geometry.reference.algorithms.line_interpolate.line_interpolate_4_with_strategy line_interpolate (with strategy)]
0040 }
0041 
0042 */
0043 template
0044 <
0045     typename CalculationType = void,
0046     typename DistanceStrategy = distance::pythagoras<CalculationType>
0047 >
0048 class cartesian
0049 {
0050 public:
0051     template <typename Point, typename Fraction, typename Distance>
0052     inline void apply(Point const& p0,
0053                       Point const& p1,
0054                       Fraction const& fraction,
0055                       Point & p,
0056                       Distance const&) const
0057     {
0058         typedef typename select_calculation_type_alt
0059             <
0060                 CalculationType, Point
0061             >::type calc_t;
0062         typedef typename coordinate_type<Point>::type coord_t;
0063 
0064         //segment convex combination: p0*fraction + p1*(1-fraction)
0065         Fraction const one_minus_fraction = 1-fraction;
0066         geometry::detail::for_each_dimension<Point>([&](auto dimension)
0067         {
0068             // NOTE: numeric_cast is a leftover from convert, it could probably be ommited.
0069             // NOTE: the order of points is different than in the formula above
0070             //       this is also a leftover from the previous implementation
0071             calc_t coord0 = util::numeric_cast<calc_t>(get<dimension>(p0));
0072             calc_t coord1 = util::numeric_cast<calc_t>(get<dimension>(p1));
0073             calc_t result = calc_t(coord1 * fraction) + calc_t(coord0 * one_minus_fraction);
0074             set<dimension>(p, util::numeric_cast<coord_t>(result));
0075         });
0076     }
0077 };
0078 
0079 
0080 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0081 namespace services
0082 {
0083 
0084 template <>
0085 struct default_strategy<cartesian_tag>
0086 {
0087     typedef strategy::line_interpolate::cartesian<> type;
0088 };
0089 
0090 
0091 } // namespace services
0092 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0093 
0094 
0095 }} // namespace strategy::line_interpolate
0096 
0097 
0098 }} // namespace boost::geometry
0099 
0100 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP