From 53ec177b7f0d20865355468fda9a626176808635 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 26 Dec 2014 08:44:23 +1100 Subject: optimize interp_weights_poly_v2, v3 use line_point_factor instead of length between vertices. --- source/blender/blenlib/intern/math_geom.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 148495c736c..3a0187584ff 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -2714,11 +2714,10 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[ w[i_curr] = 1.0f; } else { - float len_curr = len_v3v3(co, v_curr); - float len_next = len_v3v3(co, v_next); - float edge_len = len_curr + len_next; - w[i_curr] = len_next / edge_len; - w[(i_curr + 1) % n] = len_curr / edge_len; + float fac = line_point_factor_v3(co, v_curr, v_next); + CLAMP(fac, 0.0f, 1.0f); + w[i_curr] = 1.0f - fac; + w[(i_curr + 1) % n] = fac; } } else { @@ -2787,11 +2786,10 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[ w[i_curr] = 1.0f; } else { - float len_curr = len_v2v2(co, v_curr); - float len_next = len_v2v2(co, v_next); - float edge_len = len_curr + len_next; - w[i_curr] = len_next / edge_len; - w[(i_curr + 1) % n] = len_curr / edge_len; + float fac = line_point_factor_v2(co, v_curr, v_next); + CLAMP(fac, 0.0f, 1.0f); + w[i_curr] = 1.0f - fac; + w[(i_curr + 1) % n] = fac; } } else { -- cgit v1.2.3