diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-03 09:57:33 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-03 09:57:33 +0400 |
commit | 2a78a1436934590d4762e79c50e85be466d3914f (patch) | |
tree | 420d0181bd375069300e608ad42b9f439afbe9cc /source/blender/blenlib | |
parent | a5d6820b6d96b2f379e3f5e118b80cfc486b425d (diff) |
knife sort_by_frac_along was re-calculating the reference factor for every test, change to only calculate once and use line_point_factor_v3().
also add zero division check for line_point_factor_v3() since the 2d version already checked for this.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 56921797659..c8de9108fc3 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -1654,9 +1654,16 @@ float closest_to_line_v2(float cp[2], const float p[2], const float l1[2], const float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3]) { float h[3], u[3]; + float dot; sub_v3_v3v3(u, l2, l1); sub_v3_v3v3(h, p, l1); +#if 0 return (dot_v3v3(u, h) / dot_v3v3(u, u)); +#else + /* better check for zero */ + dot = dot_v3v3(u, u); + return (dot != 0.0f) ? (dot_v3v3(u, h) / dot) : 0.0f; +#endif } float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2]) |