File indexing completed on 2025-07-12 08:14:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_POINTS_HPP
0015 #define BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_POINTS_HPP
0016
0017
0018 #include <algorithm>
0019 #include <string>
0020
0021 #include <boost/geometry/algorithms/assign.hpp>
0022 #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
0023 #include <boost/geometry/core/access.hpp>
0024 #include <boost/geometry/core/assert.hpp>
0025 #include <boost/geometry/strategies/side_info.hpp>
0026
0027 namespace boost { namespace geometry
0028 {
0029
0030 namespace policies { namespace relate
0031 {
0032
0033
0034
0035
0036
0037 template
0038 <
0039 typename ReturnType
0040 >
0041 struct segments_intersection_points
0042 {
0043 typedef ReturnType return_type;
0044
0045 template
0046 <
0047 typename Segment1,
0048 typename Segment2,
0049 typename SegmentIntersectionInfo
0050 >
0051 static inline return_type segments_crosses(side_info const&,
0052 SegmentIntersectionInfo const& sinfo,
0053 Segment1 const& s1, Segment2 const& s2)
0054 {
0055 return_type result;
0056 result.count = 1;
0057 sinfo.calculate(result.intersections[0], s1, s2);
0058
0059
0060 result.fractions[0].assign(sinfo);
0061
0062 return result;
0063 }
0064
0065 template<typename SegmentIntersectionInfo, typename Point>
0066 static inline return_type
0067 segments_share_common_point(side_info const&, SegmentIntersectionInfo const& sinfo,
0068 Point const& p)
0069 {
0070 return_type result;
0071 result.count = 1;
0072 boost::geometry::assign(result.intersections[0], p);
0073
0074
0075 result.fractions[0].assign(sinfo);
0076
0077 return result;
0078 }
0079
0080 template <typename Segment1, typename Segment2, typename Ratio>
0081 static inline return_type segments_collinear(
0082 Segment1 const& a, Segment2 const& b, bool ,
0083 int a1_wrt_b, int a2_wrt_b, int b1_wrt_a, int b2_wrt_a,
0084 Ratio const& ra_from_wrt_b, Ratio const& ra_to_wrt_b,
0085 Ratio const& rb_from_wrt_a, Ratio const& rb_to_wrt_a)
0086 {
0087 return_type result;
0088 unsigned int index = 0;
0089 Ratio on_a[2];
0090
0091
0092
0093
0094
0095 if (a1_wrt_b >= 1 && a1_wrt_b <= 3
0096 && index < 2)
0097 {
0098
0099
0100
0101
0102
0103 detail::assign_point_from_index<0>(a, result.intersections[index]);
0104 result.fractions[index].assign(Ratio::zero(), ra_from_wrt_b);
0105 on_a[index] = Ratio::zero();
0106 index++;
0107 }
0108 if (b1_wrt_a == 2
0109 && index < 2)
0110 {
0111
0112
0113
0114
0115
0116
0117
0118 detail::assign_point_from_index<0>(b, result.intersections[index]);
0119 result.fractions[index].assign(rb_from_wrt_a, Ratio::zero());
0120 on_a[index] = rb_from_wrt_a;
0121 index++;
0122 }
0123
0124 if (a2_wrt_b >= 1 && a2_wrt_b <= 3
0125 && index < 2)
0126 {
0127
0128
0129
0130 detail::assign_point_from_index<1>(a, result.intersections[index]);
0131 result.fractions[index].assign(Ratio::one(), ra_to_wrt_b);
0132 on_a[index] = Ratio::one();
0133 index++;
0134 }
0135 if (b2_wrt_a == 2
0136 && index < 2)
0137 {
0138 detail::assign_point_from_index<1>(b, result.intersections[index]);
0139 result.fractions[index].assign(rb_to_wrt_a, Ratio::one());
0140 on_a[index] = rb_to_wrt_a;
0141 index++;
0142 }
0143
0144
0145
0146
0147
0148 if (index == 2 && on_a[1] < on_a[0])
0149 {
0150 std::swap(result.fractions[0], result.fractions[1]);
0151 std::swap(result.intersections[0], result.intersections[1]);
0152 }
0153
0154 result.count = index;
0155
0156 return result;
0157 }
0158
0159 static inline return_type disjoint()
0160 {
0161 return return_type();
0162 }
0163 static inline return_type error(std::string const&)
0164 {
0165 return return_type();
0166 }
0167
0168
0169 template <typename Segment>
0170 static inline return_type degenerate(Segment const& segment, bool)
0171 {
0172 return_type result;
0173 result.count = 1;
0174 set<0>(result.intersections[0], get<0, 0>(segment));
0175 set<1>(result.intersections[0], get<0, 1>(segment));
0176 return result;
0177 }
0178
0179
0180 template <typename Segment, typename Ratio>
0181 static inline return_type one_degenerate(Segment const& degenerate_segment,
0182 Ratio const& ratio, bool a_degenerate)
0183 {
0184 return_type result;
0185 result.count = 1;
0186 set<0>(result.intersections[0], get<0, 0>(degenerate_segment));
0187 set<1>(result.intersections[0], get<0, 1>(degenerate_segment));
0188 if (a_degenerate)
0189 {
0190
0191 result.fractions[0].assign(Ratio::zero(), ratio);
0192 }
0193 else
0194 {
0195 result.fractions[0].assign(ratio, Ratio::zero());
0196 }
0197 return result;
0198 }
0199 };
0200
0201
0202 }}
0203
0204 }}
0205
0206 #endif