diff options
author | Hans Goudey <h.goudey@me.com> | 2022-04-18 20:36:37 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-04-18 20:36:37 +0300 |
commit | 98fc998c70c172b70557e69eb3b832661d23bf1a (patch) | |
tree | 2b28b7c15d6747614761a985510fe7dbfb25a088 /source/blender/blenkernel/intern | |
parent | fc58368263ce5be7771cc06498ea360fadfc75cf (diff) |
Cleanup: Clang tidy
- Inconsistent parameter names
- Else after return
- Braces around statements
- Qualified auto
- Also (not clang tidy): Pass StringRef by value, unused parameter
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/gpencil_geom.cc | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc index e1a79986719..041696fa8d3 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.cc +++ b/source/blender/blenkernel/intern/gpencil_geom.cc @@ -981,7 +981,7 @@ bool BKE_gpencil_stroke_shrink(bGPDstroke *gps, const float dist, const short mo * \{ */ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps, - int i, + int point_index, float influence, int iterations, const bool smooth_caps, @@ -995,7 +995,7 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps, /* Overview of the algorithm here and in the following smooth functions: * The smooth functions return the new attribute in question for a single point. - * The result is stored in r_gps->points[i], while the data is read from gps. + * The result is stored in r_gps->points[point_index], while the data is read from gps. * To get a correct result, duplicate the stroke point data and read from the copy, * while writing to the real stroke. Not doing that will result in acceptable, but * asymmetric results. @@ -1004,16 +1004,16 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps, * the parameter "iterations" set to 1 or 2. (2 matches the old algorithm). */ - const bGPDspoint *pt = &gps->points[i]; + const bGPDspoint *pt = &gps->points[point_index]; const bool is_cyclic = (gps->flag & GP_STROKE_CYCLIC) != 0; /* If smooth_caps is false, the caps will not be translated by smoothing. */ - if (!smooth_caps && !is_cyclic && ELEM(i, 0, gps->totpoints - 1)) { - copy_v3_v3(&r_gps->points[i].x, &pt->x); + if (!smooth_caps && !is_cyclic && ELEM(point_index, 0, gps->totpoints - 1)) { + copy_v3_v3(&r_gps->points[point_index].x, &pt->x); return true; } /* This function uses a binomial kernel, which is the discrete version of gaussian blur. - * The weight for a vertex at the relative index i is + * The weight for a vertex at the relative index point_index is * w = nCr(n, j + n/2) / 2^n = (n/1 * (n-1)/2 * ... * (n-j-n/2)/(j+n/2)) / 2^n * All weights together sum up to 1 * This is equivalent to doing multiple iterations of averaging neighbors, @@ -1044,8 +1044,8 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps, 0.0; double total_w = 0.0; for (int step = iterations; step > 0; step--) { - int before = i - step; - int after = i + step; + int before = point_index - step; + int after = point_index + step; float w_before = (float)(w - w2); float w_after = (float)(w - w2); @@ -1056,13 +1056,13 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps, else { if (before < 0) { if (!smooth_caps) { - w_before *= -before / (float)i; + w_before *= -before / (float)point_index; } before = 0; } if (after > gps->totpoints - 1) { if (!smooth_caps) { - w_after *= (after - (gps->totpoints - 1)) / (float)(gps->totpoints - 1 - i); + w_after *= (after - (gps->totpoints - 1)) / (float)(gps->totpoints - 1 - point_index); } after = gps->totpoints - 1; } @@ -1089,7 +1089,7 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps, add_v3_v3(sco, &pt->x); /* Based on influence factor, blend between original and optimal smoothed coordinate. */ - interp_v3_v3v3(&r_gps->points[i].x, &pt->x, sco, influence); + interp_v3_v3v3(&r_gps->points[point_index].x, &pt->x, sco, influence); return true; } @@ -1101,7 +1101,7 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps, * \{ */ bool BKE_gpencil_stroke_smooth_strength( - bGPDstroke *gps, int i, float influence, int iterations, bGPDstroke *r_gps) + bGPDstroke *gps, int point_index, float influence, int iterations, bGPDstroke *r_gps) { /* If nothing to do, return early */ if (gps->totpoints <= 2 || iterations <= 0) { @@ -1110,15 +1110,15 @@ bool BKE_gpencil_stroke_smooth_strength( /* See BKE_gpencil_stroke_smooth_point for details on the algorithm. */ - const bGPDspoint *pt = &gps->points[i]; + const bGPDspoint *pt = &gps->points[point_index]; const bool is_cyclic = (gps->flag & GP_STROKE_CYCLIC) != 0; float strength = 0.0f; const int n_half = (iterations * iterations) / 4 + iterations; double w = 1.0; double total_w = 0.0; for (int step = iterations; step > 0; step--) { - int before = i - step; - int after = i + step; + int before = point_index - step; + int after = point_index + step; float w_before = (float)w; float w_after = (float)w; @@ -1147,7 +1147,7 @@ bool BKE_gpencil_stroke_smooth_strength( strength /= total_w; /* Based on influence factor, blend between original and optimal smoothed value. */ - r_gps->points[i].strength = pt->strength + strength * influence; + r_gps->points[point_index].strength = pt->strength + strength * influence; return true; } @@ -1159,7 +1159,7 @@ bool BKE_gpencil_stroke_smooth_strength( * \{ */ bool BKE_gpencil_stroke_smooth_thickness( - bGPDstroke *gps, int i, float influence, int iterations, bGPDstroke *r_gps) + bGPDstroke *gps, int point_index, float influence, int iterations, bGPDstroke *r_gps) { /* If nothing to do, return early */ if (gps->totpoints <= 2 || iterations <= 0) { @@ -1168,15 +1168,15 @@ bool BKE_gpencil_stroke_smooth_thickness( /* See BKE_gpencil_stroke_smooth_point for details on the algorithm. */ - const bGPDspoint *pt = &gps->points[i]; + const bGPDspoint *pt = &gps->points[point_index]; const bool is_cyclic = (gps->flag & GP_STROKE_CYCLIC) != 0; float pressure = 0.0f; const int n_half = (iterations * iterations) / 4 + iterations; double w = 1.0; double total_w = 0.0; for (int step = iterations; step > 0; step--) { - int before = i - step; - int after = i + step; + int before = point_index - step; + int after = point_index + step; float w_before = (float)w; float w_after = (float)w; @@ -1205,7 +1205,7 @@ bool BKE_gpencil_stroke_smooth_thickness( pressure /= total_w; /* Based on influence factor, blend between original and optimal smoothed value. */ - r_gps->points[i].pressure = pt->pressure + pressure * influence; + r_gps->points[point_index].pressure = pt->pressure + pressure * influence; return true; } @@ -1216,8 +1216,11 @@ bool BKE_gpencil_stroke_smooth_thickness( /** \name Stroke Smooth UV * \{ */ -bool BKE_gpencil_stroke_smooth_uv( - struct bGPDstroke *gps, int i, float influence, int iterations, struct bGPDstroke *r_gps) +bool BKE_gpencil_stroke_smooth_uv(struct bGPDstroke *gps, + int point_index, + float influence, + int iterations, + struct bGPDstroke *r_gps) { /* If nothing to do, return early */ if (gps->totpoints <= 2 || iterations <= 0) { @@ -1226,13 +1229,13 @@ bool BKE_gpencil_stroke_smooth_uv( /* See BKE_gpencil_stroke_smooth_point for details on the algorithm. */ - const bGPDspoint *pt = &gps->points[i]; + const bGPDspoint *pt = &gps->points[point_index]; const bool is_cyclic = (gps->flag & GP_STROKE_CYCLIC) != 0; /* If don't change the caps. */ - if (!is_cyclic && ELEM(i, 0, gps->totpoints - 1)) { - r_gps->points[i].uv_rot = pt->uv_rot; - r_gps->points[i].uv_fac = pt->uv_fac; + if (!is_cyclic && ELEM(point_index, 0, gps->totpoints - 1)) { + r_gps->points[point_index].uv_rot = pt->uv_rot; + r_gps->points[point_index].uv_fac = pt->uv_fac; return true; } @@ -1242,8 +1245,8 @@ bool BKE_gpencil_stroke_smooth_uv( double w = 1.0; double total_w = 0.0; for (int step = iterations; step > 0; step--) { - int before = i - step; - int after = i + step; + int before = point_index - step; + int after = point_index + step; float w_before = (float)w; float w_after = (float)w; @@ -1253,11 +1256,11 @@ bool BKE_gpencil_stroke_smooth_uv( } else { if (before < 0) { - w_before *= -before / (float)i; + w_before *= -before / (float)point_index; before = 0; } if (after > gps->totpoints - 1) { - w_after *= (after - (gps->totpoints - 1)) / (float)(gps->totpoints - 1 - i); + w_after *= (after - (gps->totpoints - 1)) / (float)(gps->totpoints - 1 - point_index); after = gps->totpoints - 1; } } @@ -1281,8 +1284,8 @@ bool BKE_gpencil_stroke_smooth_uv( uv_fac /= total_w; /* Based on influence factor, blend between original and optimal smoothed value. */ - r_gps->points[i].uv_rot = pt->uv_rot + uv_rot * influence; - r_gps->points[i].uv_fac = pt->uv_fac + uv_fac * influence; + r_gps->points[point_index].uv_rot = pt->uv_rot + uv_rot * influence; + r_gps->points[point_index].uv_fac = pt->uv_fac + uv_fac * influence; return true; } |