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