Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-07-05 04:30:00 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-07-05 04:30:00 +0400
commita02d256f5effdeec890cd90d96b6132845daf3ce (patch)
treeedd58c45fff025820a3d97a659523f592c207be6 /source/blender/blenlib
parent32e917be8d2d7b7a0649428cb4ff9f86e3ff785a (diff)
fix [#35987] bevel gives nan vertices
The line intersection function bevel uses could give nan intersections.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/math_geom.c24
1 files changed, 17 insertions, 7 deletions
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)