diff options
author | Pablo Dobarro <pablodp606@gmail.com> | 2020-08-11 03:08:22 +0300 |
---|---|---|
committer | Pablo Dobarro <pablodp606@gmail.com> | 2020-08-12 18:49:55 +0300 |
commit | 697c4495782887f0c2faa045fa0ab8235664afbb (patch) | |
tree | e2606bc2b6bf15ae0142bd30776e92f7ac9633c7 | |
parent | 2476b31c710a1d47c7c0857c4303f6955e6374fc (diff) |
Cleanup: Use clamp_f instead of CLAMP in sculpt code
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D8528
4 files changed, 25 insertions, 37 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index d91de6245ba..3421bb2cce5 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1921,8 +1921,7 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, if (use_area_cos && area_test_r) { /* Weight the coordinates towards the center. */ float p = 1.0f - (sqrtf(area_test.dist) / area_test.radius); - float afactor = 3.0f * p * p - 2.0f * p * p * p; - CLAMP(afactor, 0.0f, 1.0f); + const float afactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f); float disp[3]; sub_v3_v3v3(disp, co, area_test.location); @@ -1935,8 +1934,7 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, if (use_area_nos && normal_test_r) { /* Weight the normals towards the center. */ float p = 1.0f - (sqrtf(normal_test.dist) / normal_test.radius); - float nfactor = 3.0f * p * p - 2.0f * p * p * p; - CLAMP(nfactor, 0.0f, 1.0f); + const float nfactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f); mul_v3_fl(no, nfactor); add_v3_v3(anctd->area_nos[flip_index], no); @@ -1997,8 +1995,7 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, if (use_area_cos && area_test_r) { /* Weight the coordinates towards the center. */ float p = 1.0f - (sqrtf(area_test.dist) / area_test.radius); - float afactor = 3.0f * p * p - 2.0f * p * p * p; - CLAMP(afactor, 0.0f, 1.0f); + const float afactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f); float disp[3]; sub_v3_v3v3(disp, co, area_test.location); @@ -2011,8 +2008,7 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, if (use_area_nos && normal_test_r) { /* Weight the normals towards the center. */ float p = 1.0f - (sqrtf(normal_test.dist) / normal_test.radius); - float nfactor = 3.0f * p * p - 2.0f * p * p * p; - CLAMP(nfactor, 0.0f, 1.0f); + const float nfactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f); mul_v3_fl(no, nfactor); add_v3_v3(anctd->area_nos[flip_index], no); @@ -2778,8 +2774,7 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata, return; } - float bstrength = data->strength; - CLAMP(bstrength, 0.0f, 1.0f); + const float bstrength = clamp_f(data->strength, 0.0f, 1.0f); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( @@ -2818,14 +2813,14 @@ static void bmesh_topology_rake( Sculpt *sd, Object *ob, PBVHNode **nodes, const int totnode, float bstrength) { Brush *brush = BKE_paint_brush(&sd->paint); - CLAMP(bstrength, 0.0f, 1.0f); + const float strength = clamp_f(bstrength, 0.0f, 1.0f); /* Interactions increase both strength and quality. */ const int iterations = 3; int iteration; - const int count = iterations * bstrength + 1; - const float factor = iterations * bstrength / count; + const int count = iterations * strength + 1; + const float factor = iterations * strength / count; for (iteration = 0; iteration <= count; iteration++) { @@ -2871,7 +2866,7 @@ static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata, else { (*vd.mask) += fade * bstrength * (*vd.mask); } - CLAMP(*vd.mask, 0.0f, 1.0f); + *vd.mask = clamp_f(*vd.mask, 0.0f, 1.0f); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; @@ -4335,10 +4330,10 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata, } if (vd.mask) { const float clamp_mask = 1.0f - *vd.mask; - CLAMP(*disp_factor, -clamp_mask, clamp_mask); + *disp_factor = clamp_f(*disp_factor, -clamp_mask, clamp_mask); } else { - CLAMP(*disp_factor, -1.0f, 1.0f); + *disp_factor = clamp_f(*disp_factor, -1.0f, 1.0f); } float final_co[3]; @@ -5229,7 +5224,7 @@ static void do_clay_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to * stroke. */ if (SCULPT_stroke_is_main_symmetry_pass(ss->cache)) { ss->cache->clay_thumb_front_angle += 0.8f; - CLAMP(ss->cache->clay_thumb_front_angle, 0.0f, 60.0f); + ss->cache->clay_thumb_front_angle = clamp_f(ss->cache->clay_thumb_front_angle, 0.0f, 60.0f); } if (is_zero_v3(ss->cache->grab_delta_symmetry)) { diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_color.c b/source/blender/editors/sculpt_paint/sculpt_filter_color.c index 8648b786008..576536cac03 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_color.c +++ b/source/blender/editors/sculpt_paint/sculpt_filter_color.c @@ -127,7 +127,7 @@ static void color_filter_task_cb(void *__restrict userdata, float fill_color_rgba[4]; copy_v3_v3(fill_color_rgba, data->filter_fill_color); fill_color_rgba[3] = 1.0f; - CLAMP(fade, 0.0f, 1.0f); + fade = clamp_f(fade, 0.0f, 1.0f); mul_v4_fl(fill_color_rgba, fade); blend_color_mix_float(final_color, orig_data.col, fill_color_rgba); break; @@ -140,33 +140,28 @@ static void color_filter_task_cb(void *__restrict userdata, break; case COLOR_FILTER_SATURATION: rgb_to_hsv_v(orig_color, hsv_color); - hsv_color[1] = hsv_color[1] + fade; - CLAMP(hsv_color[1], 0.0f, 1.0f); + hsv_color[1] = clamp_f(hsv_color[1] + fade, 0.0f, 1.0f); hsv_to_rgb_v(hsv_color, final_color); break; case COLOR_FILTER_VALUE: rgb_to_hsv_v(orig_color, hsv_color); - hsv_color[2] = hsv_color[2] + fade; - CLAMP(hsv_color[2], 0.0f, 1.0f); + hsv_color[2] = clamp_f(hsv_color[2] + fade, 0.0f, 1.0f); hsv_to_rgb_v(hsv_color, final_color); break; case COLOR_FILTER_RED: - orig_color[0] = orig_color[0] + fade; - CLAMP(orig_color[0], 0.0f, 1.0f); + orig_color[0] = clamp_f(orig_color[0] + fade, 0.0f, 1.0f); copy_v3_v3(final_color, orig_color); break; case COLOR_FILTER_GREEN: - orig_color[1] = orig_color[1] + fade; - CLAMP(orig_color[1], 0.0f, 1.0f); + orig_color[1] = clamp_f(orig_color[1] + fade, 0.0f, 1.0f); copy_v3_v3(final_color, orig_color); break; case COLOR_FILTER_BLUE: - orig_color[2] = orig_color[2] + fade; - CLAMP(orig_color[2], 0.0f, 1.0f); + orig_color[2] = clamp_f(orig_color[2] + fade, 0.0f, 1.0f); copy_v3_v3(final_color, orig_color); break; case COLOR_FILTER_BRIGHTNESS: - CLAMP(fade, -1.0f, 1.0f); + fade = clamp_f(fade, -1.0f, 1.0f); brightness = fade; contrast = 0; delta = contrast / 2.0f; @@ -174,12 +169,11 @@ static void color_filter_task_cb(void *__restrict userdata, delta *= -1; offset = gain * (brightness + delta); for (int i = 0; i < 3; i++) { - final_color[i] = gain * orig_color[i] + offset; - CLAMP(final_color[i], 0.0f, 1.0f); + final_color[i] = clamp_f(gain * orig_color[i] + offset, 0.0f, 1.0f); } break; case COLOR_FILTER_CONTRAST: - CLAMP(fade, -1.0f, 1.0f); + fade = clamp_f(fade, -1.0f, 1.0f); brightness = 0; contrast = fade; delta = contrast / 2.0f; @@ -193,12 +187,11 @@ static void color_filter_task_cb(void *__restrict userdata, offset = gain * (brightness + delta); } for (int i = 0; i < 3; i++) { - final_color[i] = gain * orig_color[i] + offset; - CLAMP(final_color[i], 0.0f, 1.0f); + final_color[i] = clamp_f(gain * orig_color[i] + offset, 0.0f, 1.0f); } break; case COLOR_FILTER_SMOOTH: { - CLAMP(fade, -1.0f, 1.0f); + fade = clamp_f(fade, -1.0f, 1.0f); float smooth_color[4]; SCULPT_neighbor_color_average(ss, smooth_color, vd.index); blend_color_interpolate_float(final_color, vd.col, smooth_color, fade); diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mask.c b/source/blender/editors/sculpt_paint/sculpt_filter_mask.c index 83145f5600f..37ffaed6ec7 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mask.c +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mask.c @@ -175,7 +175,7 @@ static void mask_filter_task_cb(void *__restrict userdata, *vd.mask = gain * (*vd.mask) + offset; break; } - CLAMP(*vd.mask, 0.0f, 1.0f); + *vd.mask = clamp_f(*vd.mask, 0.0f, 1.0f); if (*vd.mask != prev_val) { update = true; } diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c index 5b6b20fb15b..ed9f1c22ec5 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c @@ -261,7 +261,7 @@ static void mesh_filter_task_cb(void *__restrict userdata, switch (filter_type) { case MESH_FILTER_SMOOTH: - CLAMP(fade, -1.0f, 1.0f); + fade = clamp_f(fade, -1.0f, 1.0f); SCULPT_neighbor_coords_average_interior(ss, avg, vd.index); sub_v3_v3v3(val, avg, orig_co); madd_v3_v3v3fl(val, orig_co, val, fade); |