[Bf-blender-cvs] [23c1e48e19d] master: Cleanup: naming for edit-mesh nearest distance values

Campbell Barton noreply at git.blender.org
Wed Mar 31 15:03:50 CEST 2021


Commit: 23c1e48e19dd4281516723e1a6dcc80e752b1bf7
Author: Campbell Barton
Date:   Wed Mar 31 23:53:07 2021 +1100
Branches: master
https://developer.blender.org/rB23c1e48e19dd4281516723e1a6dcc80e752b1bf7

Cleanup: naming for edit-mesh nearest distance values

- Don't use `r_` prefix for an argument that's also read from
  (this is meant for return only arguments).
- Rename variables to make it clear the distance is pixels,
  using manhattan length measurement.

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

M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/mesh/editmesh_select.c

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

diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 7d16720bb5d..b8e9f6e8871 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -164,16 +164,16 @@ void EDBM_select_mirrored(struct BMEditMesh *em,
                           int *r_totfail);
 
 struct BMVert *EDBM_vert_find_nearest_ex(struct ViewContext *vc,
-                                         float *r_dist,
+                                         float *dist_px_manhattan_p,
                                          const bool use_select_bias,
                                          bool use_cycle,
                                          struct Base **bases,
                                          uint bases_len,
                                          uint *r_base_index);
-struct BMVert *EDBM_vert_find_nearest(struct ViewContext *vc, float *r_dist);
+struct BMVert *EDBM_vert_find_nearest(struct ViewContext *vc, float *dist_px_manhattan_p);
 
 struct BMEdge *EDBM_edge_find_nearest_ex(struct ViewContext *vc,
-                                         float *r_dist,
+                                         float *dist_px_manhattan,
                                          float *r_dist_center,
                                          const bool use_select_bias,
                                          bool use_cycle,
@@ -181,10 +181,10 @@ struct BMEdge *EDBM_edge_find_nearest_ex(struct ViewContext *vc,
                                          struct Base **bases,
                                          uint bases_len,
                                          uint *r_base_index);
-struct BMEdge *EDBM_edge_find_nearest(struct ViewContext *vc, float *r_dist);
+struct BMEdge *EDBM_edge_find_nearest(struct ViewContext *vc, float *dist_px_manhattan_p);
 
 struct BMFace *EDBM_face_find_nearest_ex(struct ViewContext *vc,
-                                         float *r_dist,
+                                         float *dist_px_manhattan,
                                          float *r_dist_center,
                                          const bool use_zbuf_single_px,
                                          const bool use_select_bias,
@@ -193,7 +193,7 @@ struct BMFace *EDBM_face_find_nearest_ex(struct ViewContext *vc,
                                          struct Base **bases,
                                          uint bases_len,
                                          uint *r_base_index);
-struct BMFace *EDBM_face_find_nearest(struct ViewContext *vc, float *r_dist);
+struct BMFace *EDBM_face_find_nearest(struct ViewContext *vc, float *dist_px_manhattan_p);
 
 bool EDBM_unified_findnearest(struct ViewContext *vc,
                               struct Base **bases,
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index 3bdc28b0d29..4864c7de123 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -268,7 +268,8 @@ static void findnearestvert__doClosest(void *userData,
 /**
  * Nearest vertex under the cursor.
  *
- * \param r_dist: (in/out), minimal distance to the nearest and at the end, actual distance
+ * \param dist_px_manhattan_p: (in/out), minimal distance to the nearest and at the end,
+ * actual distance.
  * \param use_select_bias:
  * - When true, selected vertices are given a 5 pixel bias
  *   to make them further than unselect verts.
@@ -276,7 +277,7 @@ static void findnearestvert__doClosest(void *userData,
  * \param use_cycle: Cycle over elements within #FIND_NEAR_CYCLE_THRESHOLD_MIN in order of index.
  */
 BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
-                                  float *r_dist,
+                                  float *dist_px_manhattan_p,
                                   const bool use_select_bias,
                                   bool use_cycle,
                                   Base **bases,
@@ -286,7 +287,8 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
   uint base_index = 0;
 
   if (!XRAY_FLAG_ENABLED(vc->v3d)) {
-    uint dist_px = (uint)ED_view3d_backbuf_sample_size_clamp(vc->region, *r_dist);
+    uint dist_px_manhattan_test = (uint)ED_view3d_backbuf_sample_size_clamp(vc->region,
+                                                                            *dist_px_manhattan_p);
     uint index;
     BMVert *eve;
 
@@ -295,7 +297,7 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
       DRW_select_buffer_context_create(bases, bases_len, SCE_SELECT_VERTEX);
 
       index = DRW_select_buffer_find_nearest_to_point(
-          vc->depsgraph, vc->region, vc->v3d, vc->mval, 1, UINT_MAX, &dist_px);
+          vc->depsgraph, vc->region, vc->v3d, vc->mval, 1, UINT_MAX, &dist_px_manhattan_test);
 
       if (index) {
         eve = (BMVert *)edbm_select_id_bm_elem_get(bases, index, &base_index);
@@ -306,11 +308,11 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
     }
 
     if (eve) {
-      if (dist_px < *r_dist) {
+      if (dist_px_manhattan_test < *dist_px_manhattan_p) {
         if (r_base_index) {
           *r_base_index = base_index;
         }
-        *r_dist = dist_px;
+        *dist_px_manhattan_p = dist_px_manhattan_test;
         return eve;
       }
     }
@@ -348,18 +350,19 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
       data.cycle_index_prev = 0;
     }
 
-    data.hit.dist = data.hit_cycle.dist = data.hit.dist_bias = data.hit_cycle.dist_bias = *r_dist;
+    data.hit.dist = data.hit_cycle.dist = data.hit.dist_bias = data.hit_cycle.dist_bias =
+        *dist_px_manhattan_p;
 
     ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
     mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, clip_flag);
 
     hit = (data.use_cycle && data.hit_cycle.vert) ? &data.hit_cycle : &data.hit;
 
-    if (hit->dist < *r_dist) {
+    if (hit->dist < *dist_px_manhattan_p) {
       if (r_base_index) {
         *r_base_index = base_index;
       }
-      *r_dist = hit->dist;
+      *dist_px_manhattan_p = hit->dist;
       prev_select_bm = vc->em->bm;
     }
   }
@@ -375,10 +378,10 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
   return hit->vert;
 }
 
-BMVert *EDBM_vert_find_nearest(ViewContext *vc, float *r_dist)
+BMVert *EDBM_vert_find_nearest(ViewContext *vc, float *dist_px_manhattan_p)
 {
   Base *base = BKE_view_layer_base_find(vc->view_layer, vc->obact);
-  return EDBM_vert_find_nearest_ex(vc, r_dist, false, false, &base, 1, NULL);
+  return EDBM_vert_find_nearest_ex(vc, dist_px_manhattan_p, false, false, &base, 1, NULL);
 }
 
 /* find the distance to the edge we already have */
@@ -417,7 +420,7 @@ struct NearestEdgeUserData_Hit {
 
   /* edges only, un-biased manhattan distance to which ever edge we pick
    * (not used for choosing) */
-  float dist_center;
+  float dist_center_px_manhattan;
 };
 
 struct NearestEdgeUserData {
@@ -477,7 +480,7 @@ static void find_nearest_edge__doClosest(
     data->hit.edge = eed;
 
     mid_v2_v2v2(screen_co_mid, screen_co_a, screen_co_b);
-    data->hit.dist_center = len_manhattan_v2v2(data->mval_fl, screen_co_mid);
+    data->hit.dist_center_px_manhattan = len_manhattan_v2v2(data->mval_fl, screen_co_mid);
   }
 
   if (data->use_cycle) {
@@ -491,14 +494,14 @@ static void find_nearest_edge__doClosest(
       data->hit_cycle.edge = eed;
 
       mid_v2_v2v2(screen_co_mid, screen_co_a, screen_co_b);
-      data->hit_cycle.dist_center = len_manhattan_v2v2(data->mval_fl, screen_co_mid);
+      data->hit_cycle.dist_center_px_manhattan = len_manhattan_v2v2(data->mval_fl, screen_co_mid);
     }
   }
 }
 
 BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
-                                  float *r_dist,
-                                  float *r_dist_center,
+                                  float *dist_px_manhattan_p,
+                                  float *r_dist_center_px_manhattan,
                                   const bool use_select_bias,
                                   bool use_cycle,
                                   BMEdge **r_eed_zbuf,
@@ -509,7 +512,8 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
   uint base_index = 0;
 
   if (!XRAY_FLAG_ENABLED(vc->v3d)) {
-    uint dist_px = (uint)ED_view3d_backbuf_sample_size_clamp(vc->region, *r_dist);
+    uint dist_px_manhattan_test = (uint)ED_view3d_backbuf_sample_size_clamp(vc->region,
+                                                                            *dist_px_manhattan_p);
     uint index;
     BMEdge *eed;
 
@@ -518,7 +522,7 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
       DRW_select_buffer_context_create(bases, bases_len, SCE_SELECT_EDGE);
 
       index = DRW_select_buffer_find_nearest_to_point(
-          vc->depsgraph, vc->region, vc->v3d, vc->mval, 1, UINT_MAX, &dist_px);
+          vc->depsgraph, vc->region, vc->v3d, vc->mval, 1, UINT_MAX, &dist_px_manhattan_test);
 
       if (index) {
         eed = (BMEdge *)edbm_select_id_bm_elem_get(bases, index, &base_index);
@@ -533,7 +537,7 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
     }
 
     /* exception for faces (verts don't need this) */
-    if (r_dist_center && eed) {
+    if (r_dist_center_px_manhattan && eed) {
       struct NearestEdgeUserData_ZBuf data;
 
       data.mval_fl[0] = vc->mval[0];
@@ -546,16 +550,16 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
       mesh_foreachScreenEdge(
           vc, find_nearest_edge_center__doZBuf, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
 
-      *r_dist_center = data.dist;
+      *r_dist_center_px_manhattan = data.dist;
     }
     /* end exception */
 
     if (eed) {
-      if (dist_px < *r_dist) {
+      if (dist_px_manhattan_test < *dist_px_manhattan_p) {
         if (r_base_index) {
           *r_base_index = base_index;
         }
-        *r_dist = dist_px;
+        *dist_px_manhattan_p = dist_px_manhattan_test;
         return eed;
       }
     }
@@ -593,18 +597,19 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
       data.cycle_index_prev = 0;
     }
 
-    data.hit.dist = data.hit_cycle.dist = data.hit.dist_bias = data.hit_cycle.dist_bias = *r_dist;
+    data.hit.dist = data.hit_cycle.dist 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list