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 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_POLY_FRANKLIN_HPP
0020 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_POLY_FRANKLIN_HPP
0021
0022
0023 #include <boost/geometry/core/access.hpp>
0024 #include <boost/geometry/core/coordinate_type.hpp>
0025 #include <boost/geometry/util/select_calculation_type.hpp>
0026
0027
0028 namespace boost { namespace geometry
0029 {
0030
0031 namespace strategy { namespace within
0032 {
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 template
0053 <
0054 typename Point_,
0055 typename PointOfSegment_ = Point_,
0056 typename CalculationType = void
0057 >
0058 class franklin
0059 {
0060 template <typename Point, typename PointOfSegment>
0061 struct calculation_type
0062 : select_calculation_type
0063 <
0064 Point,
0065 PointOfSegment,
0066 CalculationType
0067 >
0068 {};
0069
0070
0071 class crossings
0072 {
0073 bool crosses;
0074
0075 public :
0076
0077 friend class franklin;
0078 inline crossings()
0079 : crosses(false)
0080 {}
0081 };
0082
0083 public :
0084
0085 typedef crossings state_type;
0086
0087 template <typename Point, typename PointOfSegment>
0088 static inline bool apply(Point const& point,
0089 PointOfSegment const& seg1, PointOfSegment const& seg2,
0090 crossings& state)
0091 {
0092 typedef typename calculation_type<Point, PointOfSegment>::type calc_t;
0093
0094 calc_t const& px = get<0>(point);
0095 calc_t const& py = get<1>(point);
0096 calc_t const& x1 = get<0>(seg1);
0097 calc_t const& y1 = get<1>(seg1);
0098 calc_t const& x2 = get<0>(seg2);
0099 calc_t const& y2 = get<1>(seg2);
0100
0101 if (
0102 ( (y2 <= py && py < y1) || (y1 <= py && py < y2) )
0103 && (px < (x1 - x2) * (py - y2) / (y1 - y2) + x2)
0104 )
0105 {
0106 state.crosses = ! state.crosses;
0107 }
0108 return true;
0109 }
0110
0111 static inline int result(crossings const& state)
0112 {
0113 return state.crosses ? 1 : -1;
0114 }
0115 };
0116
0117
0118
0119 }}
0120
0121
0122
0123
0124
0125 }}
0126
0127
0128 #endif