Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:43

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/select_calculation_type.hpp>
0021 
0022 
0023 namespace boost { namespace geometry
0024 {
0025 
0026 namespace strategy { namespace line_interpolate
0027 {
0028 
0029 
0030 /*!
0031 \brief Interpolate point on a cartesian segment.
0032 \ingroup strategies
0033 \tparam CalculationType \tparam_calculation
0034 \tparam DistanceStrategy The underlying point-point distance strategy
0035 
0036 \qbk{
0037 [heading See also]
0038 \* [link geometry.reference.algorithms.line_interpolate.line_interpolate_4_with_strategy line_interpolate (with strategy)]
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         //segment convex combination: p0*fraction + p1*(1-fraction)
0064         Fraction const one_minus_fraction = 1-fraction;
0065         geometry::detail::for_each_dimension<Point>([&](auto dimension)
0066         {
0067             // NOTE: numeric_cast is a leftover from convert, it could probably be ommited.
0068             // NOTE: the order of points is different than in the formula above
0069             //       this is also a leftover from the previous implementation
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 } // namespace services
0091 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0092 
0093 
0094 }} // namespace strategy::line_interpolate
0095 
0096 
0097 }} // namespace boost::geometry
0098 
0099 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_LINE_INTERPOLATE_HPP