summaryrefslogtreecommitdiff
path: root/boost/geometry/policies/relate/direction.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/geometry/policies/relate/direction.hpp')
-rw-r--r--boost/geometry/policies/relate/direction.hpp55
1 files changed, 42 insertions, 13 deletions
diff --git a/boost/geometry/policies/relate/direction.hpp b/boost/geometry/policies/relate/direction.hpp
index 02fed94..2c903bd 100644
--- a/boost/geometry/policies/relate/direction.hpp
+++ b/boost/geometry/policies/relate/direction.hpp
@@ -206,22 +206,51 @@ struct segments_direction
}
}
+ static inline int arrival_from_position_value(int /*v_from*/, int v_to)
+ {
+ return v_to == 2 ? 1
+ : v_to == 1 || v_to == 3 ? 0
+ //: v_from >= 1 && v_from <= 3 ? -1
+ : -1;
+
+ // NOTE: this should be an equivalent of the above for the other order
+ /* (v_from < 3 && v_to > 3) || (v_from > 3 && v_to < 3) ? 1
+ : v_from == 3 || v_to == 3 ? 0
+ : -1;*/
+ }
+
+ static inline void analyse_position_value(int pos_val,
+ int & in_segment_count,
+ int & on_end_count,
+ int & outside_segment_count)
+ {
+ if ( pos_val == 1 || pos_val == 3 )
+ {
+ on_end_count++;
+ }
+ else if ( pos_val == 2 )
+ {
+ in_segment_count++;
+ }
+ else
+ {
+ outside_segment_count++;
+ }
+ }
+
template <typename Segment1, typename Segment2, typename Ratio>
static inline return_type segments_collinear(
- Segment1 const& , Segment2 const&,
- Ratio const& ra_from_wrt_b, Ratio const& ra_to_wrt_b,
- Ratio const& rb_from_wrt_a, Ratio const& rb_to_wrt_a)
+ Segment1 const& , Segment2 const& , bool opposite,
+ int a1_wrt_b, int a2_wrt_b, int b1_wrt_a, int b2_wrt_a,
+ Ratio const& /*ra_from_wrt_b*/, Ratio const& /*ra_to_wrt_b*/,
+ Ratio const& /*rb_from_wrt_a*/, Ratio const& /*rb_to_wrt_a*/)
{
- // If segments are opposite, the ratio of the FROM w.r.t. the other
- // is larger than the ratio of the TO w.r.t. the other
- bool const opposite = ra_to_wrt_b < ra_from_wrt_b;
-
return_type r('c', opposite);
// IMPORTANT: the order of conditions is different as in intersection_points.hpp
// We assign A in 0 and B in 1
- r.arrival[0] = arrival_value(ra_from_wrt_b, ra_to_wrt_b);
- r.arrival[1] = arrival_value(rb_from_wrt_a, rb_to_wrt_a);
+ r.arrival[0] = arrival_from_position_value(a1_wrt_b, a2_wrt_b);
+ r.arrival[1] = arrival_from_position_value(b1_wrt_a, b2_wrt_a);
// Analyse them
int a_in_segment_count = 0;
@@ -230,13 +259,13 @@ struct segments_direction
int b_in_segment_count = 0;
int b_on_end_count = 0;
int b_outside_segment_count = 0;
- analyze(ra_from_wrt_b,
+ analyse_position_value(a1_wrt_b,
a_in_segment_count, a_on_end_count, a_outside_segment_count);
- analyze(ra_to_wrt_b,
+ analyse_position_value(a2_wrt_b,
a_in_segment_count, a_on_end_count, a_outside_segment_count);
- analyze(rb_from_wrt_a,
+ analyse_position_value(b1_wrt_a,
b_in_segment_count, b_on_end_count, b_outside_segment_count);
- analyze(rb_to_wrt_a,
+ analyse_position_value(b2_wrt_a,
b_in_segment_count, b_on_end_count, b_outside_segment_count);
if (a_on_end_count == 1