File indexing completed on 2025-09-13 08:36:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DISTANCE_PROJECTED_POINT_AX_HPP
0021 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DISTANCE_PROJECTED_POINT_AX_HPP
0022
0023 #include <boost/config/pragma_message.hpp>
0024 BOOST_PRAGMA_MESSAGE("This include file is deprecated and will be removed in Boost 1.88")
0025
0026 #include <algorithm>
0027
0028 #include <boost/concept_check.hpp>
0029 #include <boost/core/ignore_unused.hpp>
0030
0031 #include <boost/geometry/core/access.hpp>
0032 #include <boost/geometry/core/point_type.hpp>
0033
0034 #include <boost/geometry/algorithms/convert.hpp>
0035 #include <boost/geometry/arithmetic/arithmetic.hpp>
0036 #include <boost/geometry/arithmetic/dot_product.hpp>
0037
0038 #include <boost/geometry/strategies/tags.hpp>
0039 #include <boost/geometry/strategies/distance.hpp>
0040 #include <boost/geometry/strategies/default_distance_result.hpp>
0041 #include <boost/geometry/strategies/cartesian/distance_pythagoras.hpp>
0042 #include <boost/geometry/strategies/cartesian/distance_projected_point.hpp>
0043
0044 #include <boost/geometry/util/select_coordinate_type.hpp>
0045
0046
0047 #include <boost/geometry/geometries/point.hpp>
0048
0049
0050 namespace boost { namespace geometry
0051 {
0052
0053
0054 namespace strategy { namespace distance
0055 {
0056
0057
0058 #ifndef DOXYGEN_NO_DETAIL
0059 namespace detail
0060 {
0061
0062 template <typename T>
0063 struct projected_point_ax_result
0064 {
0065 typedef T value_type;
0066
0067 projected_point_ax_result(T const& c = T(0))
0068 : atd(c), xtd(c)
0069 {}
0070
0071 projected_point_ax_result(T const& a, T const& x)
0072 : atd(a), xtd(x)
0073 {}
0074
0075 friend inline bool operator<(projected_point_ax_result const& left,
0076 projected_point_ax_result const& right)
0077 {
0078 return left.xtd < right.xtd || left.atd < right.atd;
0079 }
0080
0081 T atd, xtd;
0082 };
0083
0084
0085
0086
0087
0088 template <typename Distance>
0089 class projected_point_ax_less
0090 {
0091 public:
0092 projected_point_ax_less(Distance const& max_distance)
0093 : m_max_distance(max_distance)
0094 {}
0095
0096 inline bool operator()(Distance const& left, Distance const& right) const
0097 {
0098
0099
0100 typedef typename Distance::value_type value_type;
0101
0102 value_type const lx = left.xtd > m_max_distance.xtd ? left.xtd - m_max_distance.xtd : 0;
0103 value_type const rx = right.xtd > m_max_distance.xtd ? right.xtd - m_max_distance.xtd : 0;
0104 value_type const la = left.atd > m_max_distance.atd ? left.atd - m_max_distance.atd : 0;
0105 value_type const ra = right.atd > m_max_distance.atd ? right.atd - m_max_distance.atd : 0;
0106
0107 value_type const l = (std::max)(lx, la);
0108 value_type const r = (std::max)(rx, ra);
0109
0110 return l < r;
0111 }
0112 private:
0113 Distance const& m_max_distance;
0114 };
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 template
0135 <
0136 typename CalculationType = void,
0137 typename Strategy = pythagoras<CalculationType>
0138 >
0139 class projected_point_ax
0140 {
0141 public :
0142 template <typename Point, typename PointOfSegment>
0143 struct calculation_type
0144 : public projected_point<CalculationType, Strategy>
0145 ::template calculation_type<Point, PointOfSegment>
0146 {};
0147
0148 template <typename Point, typename PointOfSegment>
0149 struct result_type
0150 {
0151 typedef projected_point_ax_result
0152 <
0153 typename calculation_type<Point, PointOfSegment>::type
0154 > type;
0155 };
0156
0157 public :
0158
0159 template <typename Point, typename PointOfSegment>
0160 inline typename result_type<Point, PointOfSegment>::type
0161 apply(Point const& p, PointOfSegment const& p1, PointOfSegment const& p2) const
0162 {
0163 assert_dimension_equal<Point, PointOfSegment>();
0164
0165 typedef typename calculation_type<Point, PointOfSegment>::type calculation_type;
0166
0167
0168
0169 typedef model::point
0170 <
0171 calculation_type,
0172 dimension<PointOfSegment>::value,
0173 coordinate_system_t<PointOfSegment>
0174 > fp_point_type;
0175
0176
0177 typedef fp_point_type fp_vector_type;
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 fp_vector_type v, w, projected;
0192
0193 geometry::convert(p2, v);
0194 geometry::convert(p, w);
0195 geometry::convert(p1, projected);
0196 subtract_point(v, projected);
0197 subtract_point(w, projected);
0198
0199 Strategy strategy;
0200 boost::ignore_unused(strategy);
0201
0202 typename result_type<Point, PointOfSegment>::type result;
0203
0204 calculation_type const zero = calculation_type();
0205 calculation_type const c2 = dot_product(v, v);
0206 if ( math::equals(c2, zero) )
0207 {
0208 result.xtd = strategy.apply(p, projected);
0209
0210 result.atd = 0;
0211 return result;
0212 }
0213
0214 calculation_type const c1 = dot_product(w, v);
0215 calculation_type const b = c1 / c2;
0216 multiply_value(v, b);
0217 add_point(projected, v);
0218
0219 result.xtd = strategy.apply(p, projected);
0220
0221 if (c1 <= zero)
0222 {
0223 result.atd = strategy.apply(p1, projected);
0224 }
0225 else if (c2 <= c1)
0226 {
0227 result.atd = strategy.apply(p2, projected);
0228 }
0229 else
0230 {
0231 result.atd = 0;
0232 }
0233
0234 return result;
0235 }
0236 };
0237
0238 }
0239 #endif
0240
0241 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0242 namespace services
0243 {
0244
0245
0246 template <typename CalculationType, typename Strategy>
0247 struct tag<detail::projected_point_ax<CalculationType, Strategy> >
0248 {
0249 typedef strategy_tag_distance_point_segment type;
0250 };
0251
0252
0253 template <typename CalculationType, typename Strategy, typename P, typename PS>
0254 struct return_type<detail::projected_point_ax<CalculationType, Strategy>, P, PS>
0255 {
0256 typedef typename detail::projected_point_ax<CalculationType, Strategy>
0257 ::template result_type<P, PS>::type type;
0258 };
0259
0260
0261 template <typename CalculationType, typename Strategy>
0262 struct comparable_type<detail::projected_point_ax<CalculationType, Strategy> >
0263 {
0264
0265
0266 typedef detail::projected_point_ax
0267 <
0268 CalculationType,
0269 typename comparable_type<Strategy>::type
0270 > type;
0271 };
0272
0273
0274 template <typename CalculationType, typename Strategy>
0275 struct get_comparable<detail::projected_point_ax<CalculationType, Strategy> >
0276 {
0277 typedef typename comparable_type
0278 <
0279 detail::projected_point_ax<CalculationType, Strategy>
0280 >::type comparable_type;
0281 public :
0282 static inline comparable_type apply(detail::projected_point_ax<CalculationType, Strategy> const& )
0283 {
0284 return comparable_type();
0285 }
0286 };
0287
0288
0289 template <typename CalculationType, typename Strategy, typename P, typename PS>
0290 struct result_from_distance<detail::projected_point_ax<CalculationType, Strategy>, P, PS>
0291 {
0292 private :
0293 typedef typename return_type<detail::projected_point_ax<CalculationType, Strategy>, P, PS>::type return_type;
0294 public :
0295 template <typename T>
0296 static inline return_type apply(detail::projected_point_ax<CalculationType, Strategy> const& , T const& value)
0297 {
0298 Strategy s;
0299 return_type ret;
0300 ret.atd = result_from_distance<Strategy, P, PS>::apply(s, value.atd);
0301 ret.xtd = result_from_distance<Strategy, P, PS>::apply(s, value.xtd);
0302 return ret;
0303 }
0304 };
0305
0306
0307 }
0308 #endif
0309
0310
0311 }}
0312
0313
0314 }}
0315
0316 #endif