diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-06-23 13:37:53 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-06-23 14:01:12 +0300 |
commit | 72e812de7c0f9a7221b2b7d180edf02fbbde3530 (patch) | |
tree | aaea08da6a7dedaf70deb678216192c3a0c61e64 /source/blender/blenlib/intern/math_geom.c | |
parent | ec8e0336a99b5affc68ec38c65bbfb176a54ddbe (diff) |
Fix T45123: 2D line intersection fails
Co-linear lines could detect as intersecting even if they weren't overlapping.
Diffstat (limited to 'source/blender/blenlib/intern/math_geom.c')
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 8754ad1a2ba..2c7c83822e7 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -719,8 +719,26 @@ int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[ (v >= -eps && v <= 1.0f + eps)) { /* intersection */ - madd_v2_v2v2fl(r_vi, v0, s10, u); - return 1; + float vi_test[2]; + float s_vi_v2[2]; + + madd_v2_v2v2fl(vi_test, v0, s10, u); + + /* When 'd' approaches zero, float precision lets non-overlapping co-linear segments + * detect as an intersection. So re-calculate 'v' to ensure the point overlaps both. + * see T45123 */ + + /* inline since we have most vars already */ +#if 0 + v = line_point_factor_v2(ix_test, v2, v3); +#else + sub_v2_v2v2(s_vi_v2, vi_test, v2); + v = (dot_v2v2(s32, s_vi_v2) / dot_v2v2(s32, s32)); +#endif + if (v >= -eps && v <= 1.0f + eps) { + copy_v2_v2(r_vi, vi_test); + return 1; + } } /* out of segment intersection */ |