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>2015-08-22 14:03:12 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-08-22 14:12:46 +0300
commitc1c07b68b82e221db6dd9855a6c2c4162c1d8e02 (patch)
tree1a68569343f70cd41b0f0d6bfbd2784716a1e632
parent6c8db9fd5feb1871890da1b9c6b33b429fb68c8f (diff)
Use epsilon for line-intersect collinear test
Also remove 2x vector normalize since other parts of the code already check this. Fixes T45849
-rw-r--r--source/blender/blenlib/intern/math_geom.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 60b1c038616..0d02ff3c181 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -1969,27 +1969,19 @@ int isect_line_line_epsilon_v3(
const float v3[3], const float v4[3], float i1[3], float i2[3],
const float epsilon)
{
- float a[3], b[3], c[3], ab[3], cb[3], dir1[3], dir2[3];
+ float a[3], b[3], c[3], ab[3], cb[3];
float d, div;
sub_v3_v3v3(c, v3, v1);
sub_v3_v3v3(a, v2, v1);
sub_v3_v3v3(b, v4, v3);
- normalize_v3_v3(dir1, a);
- normalize_v3_v3(dir2, b);
- d = dot_v3v3(dir1, dir2);
- if (d == 1.0f || d == -1.0f) {
- /* colinear */
- return 0;
- }
-
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)) {
+ if (UNLIKELY(div <= epsilon)) {
return 0;
}
/* test if the two lines are coplanar */
@@ -2049,31 +2041,26 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3],
float vi[3], float *r_lambda)
{
const float epsilon = 0.000001f;
- float a[3], b[3], c[3], ab[3], cb[3], ca[3], dir1[3], dir2[3];
+ float a[3], b[3], c[3], ab[3], cb[3], ca[3];
float d, div;
sub_v3_v3v3(c, v3, v1);
sub_v3_v3v3(a, v2, v1);
sub_v3_v3v3(b, v4, v3);
- normalize_v3_v3(dir1, a);
- normalize_v3_v3(dir2, b);
- d = dot_v3v3(dir1, dir2);
- if (d == 1.0f || d == -1.0f || d == 0) {
- /* colinear or one vector is zero-length*/
- return false;
- }
-
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)) {
+ if (UNLIKELY(div <= epsilon)) {
return false;
}
/* test if the two lines are coplanar */
- else if (d > -epsilon && d < epsilon) {
+ else if (UNLIKELY(fabsf(d) < epsilon)) {
+ return false;
+ }
+ else {
float f1, f2;
cross_v3_v3v3(cb, c, b);
cross_v3_v3v3(ca, c, a);
@@ -2095,9 +2082,6 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3],
return false;
}
}
- else {
- return false;
- }
}
bool isect_aabb_aabb_v3(const float min1[3], const float max1[3], const float min2[3], const float max2[3])