[Bf-blender-cvs] [4818ed1c76c] master: Cleanup: Unindent if statements in sculpt tools code

Pablo Dobarro noreply at git.blender.org
Wed Feb 10 18:07:47 CET 2021


Commit: 4818ed1c76cad447b59a36056b170282732dde0d
Author: Pablo Dobarro
Date:   Wed Feb 10 01:38:28 2021 +0100
Branches: master
https://developer.blender.org/rB4818ed1c76cad447b59a36056b170282732dde0d

Cleanup: Unindent if statements in sculpt tools code

This removes indentations from if statements by converting them to early
returns and continue.
Most of the code of brushes and tools has loops with a full indented
body inside of an if, which was also copied into some of the new tools.

Reviewed By: JacquesLucke

Differential Revision: https://developer.blender.org/D10333

===================================================================

M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_automasking.c
M	source/blender/editors/sculpt_paint/sculpt_boundary.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.c
M	source/blender/editors/sculpt_paint/sculpt_face_set.c
M	source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/editors/sculpt_paint/sculpt_pose.c
M	source/blender/editors/sculpt_paint/sculpt_smooth.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 42dece9ddd5..d1028e5f542 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -391,13 +391,14 @@ void SCULPT_face_set_visibility_set(SculptSession *ss, int face_set, bool visibl
     case PBVH_FACES:
     case PBVH_GRIDS:
       for (int i = 0; i < ss->totfaces; i++) {
-        if (abs(ss->face_sets[i]) == face_set) {
-          if (visible) {
-            ss->face_sets[i] = abs(ss->face_sets[i]);
-          }
-          else {
-            ss->face_sets[i] = -abs(ss->face_sets[i]);
-          }
+        if (abs(ss->face_sets[i]) != face_set) {
+          continue;
+        }
+        if (visible) {
+          ss->face_sets[i] = abs(ss->face_sets[i]);
+        }
+        else {
+          ss->face_sets[i] = -abs(ss->face_sets[i]);
         }
       }
       break;
@@ -1057,12 +1058,13 @@ bool SCULPT_is_vertex_inside_brush_radius_symm(const float vertex[3],
                                                char symm)
 {
   for (char i = 0; i <= symm; ++i) {
-    if (SCULPT_is_symmetry_iteration_valid(i, symm)) {
-      float location[3];
-      flip_v3_v3(location, br_co, (char)i);
-      if (len_squared_v3v3(location, vertex) < radius * radius) {
-        return true;
-      }
+    if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
+      continue;
+    }
+    float location[3];
+    flip_v3_v3(location, br_co, (char)i);
+    if (len_squared_v3v3(location, vertex) < radius * radius) {
+      return true;
     }
   }
   return false;
@@ -1107,20 +1109,22 @@ void SCULPT_floodfill_add_initial_with_symmetry(
   /* Add active vertex and symmetric vertices to the queue. */
   const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
   for (char i = 0; i <= symm; ++i) {
-    if (SCULPT_is_symmetry_iteration_valid(i, symm)) {
-      int v = -1;
-      if (i == 0) {
-        v = index;
-      }
-      else if (radius > 0.0f) {
-        float radius_squared = (radius == FLT_MAX) ? FLT_MAX : radius * radius;
-        float location[3];
-        flip_v3_v3(location, SCULPT_vertex_co_get(ss, index), i);
-        v = SCULPT_nearest_vertex_get(sd, ob, location, radius_squared, false);
-      }
-      if (v != -1) {
-        SCULPT_floodfill_add_initial(flood, v);
-      }
+    if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
+      continue;
+    }
+    int v = -1;
+    if (i == 0) {
+      v = index;
+    }
+    else if (radius > 0.0f) {
+      float radius_squared = (radius == FLT_MAX) ? FLT_MAX : radius * radius;
+      float location[3];
+      flip_v3_v3(location, SCULPT_vertex_co_get(ss, index), i);
+      v = SCULPT_nearest_vertex_get(sd, ob, location, radius_squared, false);
+    }
+
+    if (v != -1) {
+      SCULPT_floodfill_add_initial(flood, v);
     }
   }
 }
@@ -1131,20 +1135,22 @@ void SCULPT_floodfill_add_active(
   /* Add active vertex and symmetric vertices to the queue. */
   const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
   for (char i = 0; i <= symm; ++i) {
-    if (SCULPT_is_symmetry_iteration_valid(i, symm)) {
-      int v = -1;
-      if (i == 0) {
-        v = SCULPT_active_vertex_get(ss);
-      }
-      else if (radius > 0.0f) {
-        float radius_squared = (radius == FLT_MAX) ? FLT_MAX : radius * radius;
-        float location[3];
-        flip_v3_v3(location, SCULPT_active_vertex_co_get(ss), i);
-        v = SCULPT_nearest_vertex_get(sd, ob, location, radius_squared, false);
-      }
-      if (v != -1) {
-        SCULPT_floodfill_add_initial(flood, v);
-      }
+    if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
+      continue;
+    }
+    int v = -1;
+    if (i == 0) {
+      v = SCULPT_active_vertex_get(ss);
+    }
+    else if (radius > 0.0f) {
+      float radius_squared = (radius == FLT_MAX) ? FLT_MAX : radius * radius;
+      float location[3];
+      flip_v3_v3(location, SCULPT_active_vertex_co_get(ss), i);
+      v = SCULPT_nearest_vertex_get(sd, ob, location, radius_squared, false);
+    }
+
+    if (v != -1) {
+      SCULPT_floodfill_add_initial(flood, v);
     }
   }
 }
@@ -1161,12 +1167,19 @@ void SCULPT_floodfill_execute(
     SculptVertexNeighborIter ni;
     SCULPT_VERTEX_DUPLICATES_AND_NEIGHBORS_ITER_BEGIN (ss, from_v, ni) {
       const int to_v = ni.index;
-      if (!BLI_BITMAP_TEST(flood->visited_vertices, to_v) && SCULPT_vertex_visible_get(ss, to_v)) {
-        BLI_BITMAP_ENABLE(flood->visited_vertices, to_v);
 
-        if (func(ss, from_v, to_v, ni.is_duplicate, userdata)) {
-          BLI_gsqueue_push(flood->queue, &to_v);
-        }
+      if (BLI_BITMAP_TEST(flood->visited_vertices, to_v)) {
+        continue;
+      }
+
+      if (!SCULPT_vertex_visible_get(ss, to_v)) {
+        continue;
+      }
+
+      BLI_BITMAP_ENABLE(flood->visited_vertices, to_v);
+
+      if (func(ss, from_v, to_v, ni.is_duplicate, userdata)) {
+        BLI_gsqueue_push(flood->queue, &to_v);
       }
     }
     SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
@@ -1466,40 +1479,42 @@ static void paint_mesh_restore_co_task_cb(void *__restrict userdata,
     unode = SCULPT_undo_get_node(data->nodes[n]);
   }
 
-  if (unode) {
-    PBVHVertexIter vd;
-    SculptOrigVertData orig_data;
+  if (!unode) {
+    return;
+  }
 
-    SCULPT_orig_vert_data_unode_init(&orig_data, data->ob, unode);
+  PBVHVertexIter vd;
+  SculptOrigVertData orig_data;
 
-    BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
-    {
-      SCULPT_orig_vert_data_update(&orig_data, &vd);
+  SCULPT_orig_vert_data_unode_init(&orig_data, data->ob, unode);
 
-      if (orig_data.unode->type == SCULPT_UNDO_COORDS) {
-        copy_v3_v3(vd.co, orig_data.co);
-        if (vd.no) {
-          copy_v3_v3_short(vd.no, orig_data.no);
-        }
-        else {
-          normal_short_to_float_v3(vd.fno, orig_data.no);
-        }
-      }
-      else if (orig_data.unode->type == SCULPT_UNDO_MASK) {
-        *vd.mask = orig_data.mask;
-      }
-      else if (orig_data.unode->type == SCULPT_UNDO_COLOR) {
-        copy_v4_v4(vd.col, orig_data.col);
-      }
+  BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
+  {
+    SCULPT_orig_vert_data_update(&orig_data, &vd);
 
-      if (vd.mvert) {
-        vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+    if (orig_data.unode->type == SCULPT_UNDO_COORDS) {
+      copy_v3_v3(vd.co, orig_data.co);
+      if (vd.no) {
+        copy_v3_v3_short(vd.no, orig_data.no);
+      }
+      else {
+        normal_short_to_float_v3(vd.fno, orig_data.no);
       }
     }
-    BKE_pbvh_vertex_iter_end;
+    else if (orig_data.unode->type == SCULPT_UNDO_MASK) {
+      *vd.mask = orig_data.mask;
+    }
+    else if (orig_data.unode->type == SCULPT_UNDO_COLOR) {
+      copy_v4_v4(vd.col, orig_data.col);
+    }
 
-    BKE_pbvh_node_mark_update(data->nodes[n]);
+    if (vd.mvert) {
+      vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+    }
   }
+  BKE_pbvh_vertex_iter_end;
+
+  BKE_pbvh_node_mark_update(data->nodes[n]);
 }
 
 static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
@@ -1545,11 +1560,15 @@ static void sculpt_extend_redraw_rect_previous(Object *ob, rcti *rect)
    * mesh parts could disappear from screen (sergey). */
   SculptSession *ss = ob->sculpt;
 
-  if (ss->cache) {
-    if (!BLI_rcti_is_empty(&ss->cache->previous_r)) {
-      BLI_rcti_union(rect, &ss->cache->previous_r);
-    }
+  if (!ss->cache) {
+    return;
+  }
+
+  if (BLI_rcti_is_empty(&ss->cache->previous_r)) {
+    return;
   }
+
+  BLI_rcti_union(rect, &ss->cache->previous_r);
 }
 
 /* Get a screen-space rectangle of the modified area. */
@@ -1651,28 +1670,30 @@ bool SCULPT_brush_test_sphere(SculptBrushTest *test, const float co[3])
 {
   float distsq = len_squared_v3v3(co, test->location);
 
-  if (distsq <= test->radius_squared) {
-    if (sculpt_brush_test_clipping(test, co)) {
-      return false;
-    }
-    test->dist = sqrtf(distsq);
-    return true;
+  if (distsq > test->radius_squared) {
+    return false;
   }
-  return false;
+
+  if (sculpt_brush_test_clipping(test, co)) {
+    return false;
+  }
+
+  test->dist = sqrtf(distsq);
+  return true;
 }
 
 bool SCULPT_brush_test_sphere_sq(SculptBrushTest *test, const float co[3])
 {
   float distsq = len_squared_v3v3(co, test->location);
 
-  if (distsq <= test->radius_squared) {
-    if (sculpt_brush_test_clipping(test, co)) {
-      return false;
-    }
-    test->dist = distsq;
-    return true;
+  if (distsq > test->radius_squared) {
+    return false;
   }
-  return false;
+  if (sculpt_brush_test_clipping(test, co)) {
+    return false;
+  }
+  test->dist = distsq;
+  return true;
 }
 
 bool SCULPT_brush_test_sphere_fast(const SculptBrushTest *test, const float co[3])
@@ -1689,14 +1710,16 @@ bool SCULPT_brush_test_circle_sq(SculptBrushTest *test, const float co[3])
   closest_to_plane_normalized_v3(co_proj, test->plane_view, co);
   float distsq = len_squared_v3v3(co_proj, test->location);
 
-  if (distsq <= test->radius_squared) {
-    if (sculpt_brush_test_clipping(test, co)) {
-      return false;
-    }
-    test->dist = distsq;
-    return true;
+  if (distsq > test->radius_squared) {
+    return false;
   }
-  return false;
+
+  if (sculpt_brush_test_clipping(test, co)) {
+    return false;
+  }
+
+  test->dist = distsq;
+  return true;
 }
 
 bool SCULPT_brush_test_cube(SculptBrushTest *test,
@@ -1724,25 +1747,26 @@ bool SCULPT_brush_test_cube(SculptBrushTest *test,
   const float constant_side = hardness * side;
   const float falloff_side = roundness * side;
 
-  if (local_co[0] <= side && local_co[1] <= side && local_co[2] <= side) {
+  if (!(local_co[0] <= side && local_co[1] <= side && local_co[2] <= side)) {
+    /* Outside the square. */
+    return false;
+  }
+  if (min_ff(local_co[0], local_co[1]) > constant_side) {
     /* Corner, distance to the center of the corner circle. */
-    if (min_ff(local_co[0], local_co[1]) > constant_side) {
-      float r_point[3];
-      copy_v3_fl(r_point, constant_side);
-      test->dist = len_v2v2(r_point, local_co) / falloff_side;
-      return true;
-    }
+    float r_point[3];
+    copy_v3_fl(r_point, constant_side);
+    test->dist = len_v2v2(r_p

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list