[Bf-blender-cvs] [9ae39a1] master: Math Lib: use vector funcs for isect_line_line_v2_point

Campbell Barton noreply at git.blender.org
Tue Jul 21 13:55:10 CEST 2015


Commit: 9ae39a1312ed69b77d3af17842710e931a8f6b83
Author: Campbell Barton
Date:   Tue Jul 21 21:33:57 2015 +1000
Branches: master
https://developer.blender.org/rB9ae39a1312ed69b77d3af17842710e931a8f6b83

Math Lib: use vector funcs for isect_line_line_v2_point

===================================================================

M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 5734d01..8820b88 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -143,7 +143,7 @@ void limit_dist_v3(float v1[3], float v2[3], const float dist);
 #define ISECT_LINE_LINE_EXACT        1
 #define ISECT_LINE_LINE_CROSS        2
 
-int isect_line_line_v2_point(const float v1[2], const float v2[2], const float v3[2], const float v4[2], float vi[2]);
+int isect_line_line_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2]);
 int isect_line_line_v2(const float a1[2], const float a2[2], const float b1[2], const float b2[2]);
 int isect_line_line_v2_int(const int a1[2], const int a2[2], const int b1[2], const int b2[2]);
 int isect_line_sphere_v3(const float l1[3], const float l2[3], const float sp[3], const float r, float r_p1[3], float r_p2[3]);
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 4662762..3fb6de4 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -693,19 +693,28 @@ int isect_line_line_v2_int(const int v1[2], const int v2[2], const int v3[2], co
 }
 
 /* intersect Line-Line, floats - gives intersection point */
-int isect_line_line_v2_point(const float v1[2], const float v2[2], const float v3[2], const float v4[2], float vi[2])
+int isect_line_line_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2])
 {
+	float s10[2], s32[2];
 	float div;
 
-	div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]);
-	if (div == 0.0f) return ISECT_LINE_LINE_COLINEAR;
+	sub_v2_v2v2(s10, v1, v0);
+	sub_v2_v2v2(s32, v3, v2);
 
-	vi[0] = ((v3[0] - v4[0]) * (v1[0] * v2[1] - v1[1] * v2[0]) - (v1[0] - v2[0]) * (v3[0] * v4[1] - v3[1] * v4[0])) / div;
-	vi[1] = ((v3[1] - v4[1]) * (v1[0] * v2[1] - v1[1] * v2[0]) - (v1[1] - v2[1]) * (v3[0] * v4[1] - v3[1] * v4[0])) / div;
+	div = cross_v2v2(s10, s32);
+	if (div != 0.0f) {
+		const float u = cross_v2v2(v1, v0);
+		const float v = cross_v2v2(v3, v2);
 
-	return ISECT_LINE_LINE_CROSS;
-}
+		r_vi[0] = ((s32[0] * u) - (s10[0] * v)) / div;
+		r_vi[1] = ((s32[1] * u) - (s10[1] * v)) / div;
 
+		return ISECT_LINE_LINE_CROSS;
+	}
+	else {
+		return ISECT_LINE_LINE_COLINEAR;
+	}
+}
 
 /* intersect Line-Line, floats */
 int isect_line_line_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])




More information about the Bf-blender-cvs mailing list