diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-07-21 14:33:57 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-07-21 14:49:29 +0300 |
commit | 9ae39a1312ed69b77d3af17842710e931a8f6b83 (patch) | |
tree | 27beb877491f6b3fae3ec1c446d3c1d1b8af620c | |
parent | ff3d535bc2a63092357533acbe7289556af956a0 (diff) |
Math Lib: use vector funcs for isect_line_line_v2_point
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 23 |
2 files changed, 17 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 5734d0125c7..8820b88b9ac 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 4662762ad21..3fb6de47f5f 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]) |