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-23 10:07:35 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-08-23 10:07:35 +0300
commit0cb23fafe7c93f4cbf010a3f2fdd1db96d2d4e1d (patch)
tree6d19e9b88b6d2bb6ac5d04bb886bd5a40248f6bd
parent58c9a0b11a0e705f68d741107faba51d9d17000e (diff)
Math Lib: minor optimization interp_weights_poly
-rw-r--r--source/blender/blenlib/intern/math_geom.c70
1 files changed, 36 insertions, 34 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index d6029c96f91..6e54d4b5865 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -3065,18 +3065,22 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[
const float *v_curr, *v_next;
float ht_prev, ht; /* half tangents */
float totweight = 0.0f;
- int i = 0;
+ int i_curr, i_next;
char ix_flag = 0;
struct Float3_Len d_curr, d_next;
- v_curr = v[0];
- v_next = v[1];
+ /* loop over 'i_next' */
+ i_curr = n - 1;
+ i_next = 0;
- DIR_V3_SET(&d_curr, v[n - 1], co);
- DIR_V3_SET(&d_next, v_curr, co);
+ v_curr = v[i_curr];
+ v_next = v[i_next];
+
+ DIR_V3_SET(&d_curr, v_curr - 3 /* v[n - 2] */, co);
+ DIR_V3_SET(&d_next, v_curr /* v[n - 1] */, co);
ht_prev = mean_value_half_tan_v3(&d_curr, &d_next);
- while (i < n) {
+ while (i_next < n) {
/* Mark Mayer et al algorithm that is used here does not operate well if vertex is close
* to borders of face. In that case, do simple linear interpolation between the two edge vertices */
@@ -3093,22 +3097,19 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[
d_curr = d_next;
DIR_V3_SET(&d_next, v_next, co);
ht = mean_value_half_tan_v3(&d_curr, &d_next);
- w[i] = (ht_prev + ht) / d_curr.len;
- totweight += w[i];
+ w[i_curr] = (ht_prev + ht) / d_curr.len;
+ totweight += w[i_curr];
/* step */
- i++;
+ i_curr = i_next++;
v_curr = v_next;
- v_next = v[(i + 1) % n];
+ v_next = v[i_next];
ht_prev = ht;
}
if (ix_flag) {
- const int i_curr = i;
- for (i = 0; i < n; i++) {
- w[i] = 0.0f;
- }
+ memset(w, 0, sizeof(*w) * (size_t)n);
if (ix_flag & IS_POINT_IX) {
w[i_curr] = 1.0f;
@@ -3117,13 +3118,13 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[
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;
+ w[i_next] = fac;
}
}
else {
if (totweight != 0.0f) {
- for (i = 0; i < n; i++) {
- w[i] /= totweight;
+ for (i_curr = 0; i_curr < n; i_curr++) {
+ w[i_curr] /= totweight;
}
}
}
@@ -3137,18 +3138,22 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[
const float *v_curr, *v_next;
float ht_prev, ht; /* half tangents */
float totweight = 0.0f;
- int i = 0;
+ int i_curr, i_next;
char ix_flag = 0;
struct Float2_Len d_curr, d_next;
- v_curr = v[0];
- v_next = v[1];
+ /* loop over 'i_next' */
+ i_curr = n - 1;
+ i_next = 0;
- DIR_V2_SET(&d_curr, v[n - 1], co);
- DIR_V2_SET(&d_next, v_curr, co);
+ v_curr = v[i_curr];
+ v_next = v[i_next];
+
+ DIR_V2_SET(&d_curr, v_curr - 2 /* v[n - 2] */, co);
+ DIR_V2_SET(&d_next, v_curr /* v[n - 1] */, co);
ht_prev = mean_value_half_tan_v2(&d_curr, &d_next);
- while (i < n) {
+ while (i_next < n) {
/* Mark Mayer et al algorithm that is used here does not operate well if vertex is close
* to borders of face. In that case, do simple linear interpolation between the two edge vertices */
@@ -3165,22 +3170,19 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[
d_curr = d_next;
DIR_V2_SET(&d_next, v_next, co);
ht = mean_value_half_tan_v2(&d_curr, &d_next);
- w[i] = (ht_prev + ht) / d_curr.len;
- totweight += w[i];
+ w[i_curr] = (ht_prev + ht) / d_curr.len;
+ totweight += w[i_curr];
/* step */
- i++;
+ i_curr = i_next++;
v_curr = v_next;
- v_next = v[(i + 1) % n];
+ v_next = v[i_next];
ht_prev = ht;
}
if (ix_flag) {
- const int i_curr = i;
- for (i = 0; i < n; i++) {
- w[i] = 0.0f;
- }
+ memset(w, 0, sizeof(*w) * (size_t)n);
if (ix_flag & IS_POINT_IX) {
w[i_curr] = 1.0f;
@@ -3189,13 +3191,13 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[
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;
+ w[i_next] = fac;
}
}
else {
if (totweight != 0.0f) {
- for (i = 0; i < n; i++) {
- w[i] /= totweight;
+ for (i_curr = 0; i_curr < n; i_curr++) {
+ w[i_curr] /= totweight;
}
}
}