From a02d256f5effdeec890cd90d96b6132845daf3ce Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Jul 2013 00:30:00 +0000 Subject: fix [#35987] bevel gives nan vertices The line intersection function bevel uses could give nan intersections. --- source/blender/blenlib/intern/math_geom.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index ddf1c598a1c..78b1f50c2e8 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -1452,7 +1452,7 @@ bool isect_axial_line_tri_v3(const int axis, const float p1[3], const float p2[3 int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float i1[3], float i2[3]) { float a[3], b[3], c[3], ab[3], cb[3], dir1[3], dir2[3]; - float d; + float d, div; sub_v3_v3v3(c, v3, v1); sub_v3_v3v3(a, v2, v1); @@ -1468,12 +1468,17 @@ int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3], cross_v3_v3v3(ab, a, b); d = dot_v3v3(c, ab); + div = dot_v3v3(ab, ab); + /* test zero length line */ + if (UNLIKELY(div == 0.0f)) { + return 0; + } /* test if the two lines are coplanar */ - if (d > -0.000001f && d < 0.000001f) { + else if (d > -0.000001f && d < 0.000001f) { cross_v3_v3v3(cb, c, b); - mul_v3_fl(a, dot_v3v3(cb, ab) / dot_v3v3(ab, ab)); + mul_v3_fl(a, dot_v3v3(cb, ab) / div); add_v3_v3v3(i1, v1, a); copy_v3_v3(i2, i1); @@ -1518,7 +1523,7 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3], float vi[3], float *r_lambda) { float a[3], b[3], c[3], ab[3], cb[3], ca[3], dir1[3], dir2[3]; - float d; + float d, div; sub_v3_v3v3(c, v3, v1); sub_v3_v3v3(a, v2, v1); @@ -1534,15 +1539,20 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3], cross_v3_v3v3(ab, a, b); d = dot_v3v3(c, ab); + div = dot_v3v3(ab, ab); + /* test zero length line */ + if (UNLIKELY(div == 0.0f)) { + return 0; + } /* test if the two lines are coplanar */ - if (d > -0.000001f && d < 0.000001f) { + else if (d > -0.000001f && d < 0.000001f) { float f1, f2; cross_v3_v3v3(cb, c, b); cross_v3_v3v3(ca, c, a); - f1 = dot_v3v3(cb, ab) / dot_v3v3(ab, ab); - f2 = dot_v3v3(ca, ab) / dot_v3v3(ab, ab); + f1 = dot_v3v3(cb, ab) / div; + f2 = dot_v3v3(ca, ab) / div; if (f1 >= 0 && f1 <= 1 && f2 >= 0 && f2 <= 1) -- cgit v1.2.3