[Bf-blender-cvs] [f66e9ce5aed] soc-2021-curves: Cleanup

Dilith Jayakody noreply at git.blender.org
Sat Feb 5 13:28:31 CET 2022


Commit: f66e9ce5aedf1fe3709c3a3ba46e315ba94049c8
Author: Dilith Jayakody
Date:   Sat Feb 5 09:46:28 2022 +0530
Branches: soc-2021-curves
https://developer.blender.org/rBf66e9ce5aedf1fe3709c3a3ba46e315ba94049c8

Cleanup

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

M	source/blender/editors/curve/editcurve_pen.c

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

diff --git a/source/blender/editors/curve/editcurve_pen.c b/source/blender/editors/curve/editcurve_pen.c
index 4fe237487cc..f8ffef23ff9 100644
--- a/source/blender/editors/curve/editcurve_pen.c
+++ b/source/blender/editors/curve/editcurve_pen.c
@@ -234,19 +234,19 @@ static bool worldspace_to_screenspace(const float pos_3d[3],
          V3D_PROJ_RET_OK;
 }
 
-static void move_bezt_by_change(BezTriple *bezt, const float change[3])
+static void move_bezt_by_displacement(BezTriple *bezt, const float disp_3d[3])
 {
-  add_v3_v3(bezt->vec[0], change);
-  add_v3_v3(bezt->vec[1], change);
-  add_v3_v3(bezt->vec[2], change);
+  add_v3_v3(bezt->vec[0], disp_3d);
+  add_v3_v3(bezt->vec[1], disp_3d);
+  add_v3_v3(bezt->vec[2], disp_3d);
 }
 
 /* Move entire control point to given worldspace location. */
 static void move_bezt_to_location(BezTriple *bezt, const float location[3])
 {
-  float change[3];
-  sub_v3_v3v3(change, location, bezt->vec[1]);
-  move_bezt_by_change(bezt, change);
+  float disp_3d[3];
+  sub_v3_v3v3(disp_3d, location, bezt->vec[1]);
+  move_bezt_by_displacement(bezt, disp_3d);
 }
 
 /* Alter handle types to allow free movement (Set handles to #FREE or #ALIGN). */
@@ -274,20 +274,21 @@ static void remove_handle_movement_constraints(BezTriple *bezt, const bool f1, c
 
 static void move_bezt_handle_or_vertex_to_location(BezTriple *bezt,
                                                    const float mval[2],
-                                                   const short cp_index,
+                                                   const short bezt_idx,
                                                    const ViewContext *vc)
 {
   float location[3];
-  screenspace_to_worldspace(mval, bezt->vec[cp_index], vc, location);
-  if (cp_index == 1) {
+  screenspace_to_worldspace(mval, bezt->vec[bezt_idx], vc, location);
+  if (bezt_idx == 1) {
     move_bezt_to_location(bezt, location);
   }
   else {
-    copy_v3_v3(bezt->vec[cp_index], location);
+    copy_v3_v3(bezt->vec[bezt_idx], location);
     if (bezt->h1 == HD_ALIGN && bezt->h2 == HD_ALIGN) {
+      /* Move the handle on the opposite side. */
       float handle_vec[3];
       sub_v3_v3v3(handle_vec, bezt->vec[1], location);
-      const short other_handle = cp_index == 2 ? 0 : 2;
+      const short other_handle = bezt_idx == 2 ? 0 : 2;
       normalize_v3_length(handle_vec, len_v3v3(bezt->vec[1], bezt->vec[other_handle]));
       add_v3_v3v3(bezt->vec[other_handle], bezt->vec[1], handle_vec);
     }
@@ -302,6 +303,9 @@ static void move_bp_to_location(BPoint *bp, const float mval[2], const ViewConte
   copy_v3_v3(bp->vec, location);
 }
 
+/* Get the average position of selected points.
+ * `mid_only`: Use only the middle point of the three points on a BezTriple.
+ * `bezt_only`: Use only points of Bezier splines. */
 static bool get_selected_center(const ListBase *nurbs,
                                 float r_center[3],
                                 const bool mid_only,
@@ -359,28 +363,30 @@ static void move_all_selected_points(ListBase *nurbs,
                                      const wmEvent *event,
                                      const ViewContext *vc)
 {
-  float center[3] = {0.0f, 0.0f, 0.0f};
-  float change[2], center_2d[2];
+  float center[3], center_2d[2];
   get_selected_center(nurbs, center, false, bezt_only);
   worldspace_to_screenspace(center, vc, center_2d);
-  float mval[2] = {UNPACK2(event->xy)};
-  sub_v2_v2v2(change, mval, center_2d);
+
+  const float mval[2] = {UNPACK2(event->xy)};
+  float disp_2d[2];
+  sub_v2_v2v2(disp_2d, mval, center_2d);
+
   if (!cpd->offset_calc) {
-    float prev_mval[2] = {UNPACK2(event->prev_xy)};
+    const float prev_mval[2] = {UNPACK2(event->prev_xy)};
     sub_v2_v2v2(cpd->move_offset, center_2d, prev_mval);
     cpd->offset_calc = true;
   }
-  add_v2_v2(change, cpd->move_offset);
+  add_v2_v2(disp_2d, cpd->move_offset);
 
   const bool link_handles = cpd->link_handles && !cpd->free_toggle;
   const bool lock_angle = cpd->lock_angle;
 
-  float change_len = 0.0f;
+  float distance = 0.0f;
   if (lock_angle) {
     float mval_3d[3], center_mid[3];
     get_selected_center(nurbs, center_mid, true, true);
     screenspace_to_worldspace_int(event->mval, center_mid, vc, mval_3d);
-    change_len = len_v3v3(center_mid, mval_3d);
+    distance = len_v3v3(center_mid, mval_3d);
   }
 
   LISTBASE_FOREACH (Nurb *, nu, nurbs) {
@@ -390,7 +396,7 @@ static void move_all_selected_points(ListBase *nurbs,
         if (BEZT_ISSEL_IDX(bezt, 1) || (move_entire && BEZT_ISSEL_ANY(bezt))) {
           float pos[2], dst[2];
           worldspace_to_screenspace(bezt->vec[1], vc, pos);
-          add_v2_v2v2(dst, pos, change);
+          add_v2_v2v2(dst, pos, disp_2d);
           move_bezt_handle_or_vertex_to_location(bezt, dst, 1, vc);
         }
         else {
@@ -398,15 +404,15 @@ static void move_all_selected_points(ListBase *nurbs,
               bezt, BEZT_ISSEL_IDX(bezt, 0), BEZT_ISSEL_IDX(bezt, 2));
           if (BEZT_ISSEL_IDX(bezt, 0)) {
             if (lock_angle) {
-              float change_3d[3];
-              sub_v3_v3v3(change_3d, bezt->vec[0], bezt->vec[1]);
-              normalize_v3_length(change_3d, change_len);
-              add_v3_v3v3(bezt->vec[0], bezt->vec[1], change_3d);
+              float disp_3d[3];
+              sub_v3_v3v3(disp_3d, bezt->vec[0], bezt->vec[1]);
+              normalize_v3_length(disp_3d, distance);
+              add_v3_v3v3(bezt->vec[0], bezt->vec[1], disp_3d);
             }
             else {
               float pos[2], dst[2];
               worldspace_to_screenspace(bezt->vec[0], vc, pos);
-              add_v2_v2v2(dst, pos, change);
+              add_v2_v2v2(dst, pos, disp_2d);
               move_bezt_handle_or_vertex_to_location(bezt, dst, 0, vc);
               if (link_handles) {
                 float handle[3];
@@ -417,15 +423,15 @@ static void move_all_selected_points(ListBase *nurbs,
           }
           else if (BEZT_ISSEL_IDX(bezt, 2)) {
             if (lock_angle) {
-              float change_3d[3];
-              sub_v3_v3v3(change_3d, bezt->vec[2], bezt->vec[1]);
-              normalize_v3_length(change_3d, change_len);
-              add_v3_v3v3(bezt->vec[2], bezt->vec[1], change_3d);
+              float disp_3d[3];
+              sub_v3_v3v3(disp_3d, bezt->vec[2], bezt->vec[1]);
+              normalize_v3_length(disp_3d, distance);
+              add_v3_v3v3(bezt->vec[2], bezt->vec[1], disp_3d);
             }
             else {
               float pos[2], dst[2];
               worldspace_to_screenspace(bezt->vec[2], vc, pos);
-              add_v2_v2v2(dst, pos, change);
+              add_v2_v2v2(dst, pos, disp_2d);
               move_bezt_handle_or_vertex_to_location(bezt, dst, 2, vc);
               if (link_handles) {
                 float handle[3];
@@ -444,7 +450,7 @@ static void move_all_selected_points(ListBase *nurbs,
         if (bp->f1 & SELECT) {
           float pos[2], dst[2];
           worldspace_to_screenspace(bp->vec, vc, pos);
-          add_v2_v2v2(dst, pos, change);
+          add_v2_v2v2(dst, pos, disp_2d);
           move_bp_to_location(bp, dst, vc);
         }
       }
@@ -468,13 +474,13 @@ static int get_nurb_index(const ListBase *nurbs, const Nurb *nurb)
 static void delete_nurb(Curve *cu, Nurb *nu)
 {
   EditNurb *editnurb = cu->editnurb;
-  ListBase *nubase = &editnurb->nurbs;
-  const int nuindex = get_nurb_index(nubase, nu);
-  if (cu->actnu == nuindex) {
+  ListBase *nurbs = &editnurb->nurbs;
+  const int nu_index = get_nurb_index(nurbs, nu);
+  if (cu->actnu == nu_index) {
     cu->actnu = CU_ACT_NONE;
   }
 
-  BLI_remlink(nubase, nu);
+  BLI_remlink(nurbs, nu);
   BKE_nurb_free(nu);
   nu = NULL;
 }
@@ -524,7 +530,7 @@ static bool get_closest_point_on_edge(float r_point[3],
   opposite to each other. If they're the same, that indicates that there is a
   perpendicular line from the mouse to the line.*/
   if ((dot1 > 0) == (dot2 > 0)) {
-    float len_vec3_sq = len_squared_v2(vec3);
+    const float len_vec3_sq = len_squared_v2(vec3);
     *r_fraction = 1 - dot2 / len_vec3_sq;
 
     float pos_dif[3];
@@ -558,8 +564,8 @@ static bool get_closest_vertex_to_point_in_nurbs(const ListBase *nurbs,
   *r_bezt = NULL;
   *r_bp = NULL;
 
-  float min_distance_bezt = FLT_MAX;
-  float min_distance_bp = FLT_MAX;
+  float min_dist_bezt = FLT_MAX;
+  float min_dist_bp = FLT_MAX;
 
   BezTriple *closest_bezt = NULL;
   short closest_handle = 0;
@@ -580,9 +586,9 @@ static bool get_closest_vertex_to_point_in_nurbs(const ListBase *nurbs,
         }
         for (short j = start; j < end; j++) {
           if (worldspace_to_screenspace(bezt->vec[j], vc, bezt_vec)) {
-            const float distance = len_manhattan_v2v2(bezt_vec, point);
-            if (distance < min_distance_bezt) {
-              min_distance_bezt = distance;
+            const float dist = len_manhattan_v2v2(bezt_vec, point);
+            if (dist < min_dist_bezt) {
+              min_dist_bezt = dist;
               closest_bezt = bezt;
               closest_bezt_nu = nu;
               closest_handle = j;
@@ -596,9 +602,9 @@ static bool get_closest_vertex_to_point_in_nurbs(const ListBase *nurbs,
         BPoint *bp = &nu->bp[i];
         float bp_vec[2];
         if (worldspace_to_screenspace(bp->vec, vc, bp_vec)) {
-          const float distance = len_manhattan_v2v2(bp_vec, point);
-          if (distance < min_distance_bp) {
-            min_distance_bp = distance;
+          const float dist = len_manhattan_v2v2(bp_vec, point);
+          if (dist < min_dist_bp) {
+            min_dist_bp = dist;
             closest_bp = bp;
             closest_bp_nu = nu;
           }
@@ -607,9 +613,9 @@ static bool get_closest_vertex_to_point_in_nurbs(const ListBase *nurbs,
     }
   }
 
-  const float threshold_distance = ED_view3d_select_dist_px() * sel_dist_mul;
-  if (min_distance_bezt < threshold_distance || min_distance_bp < threshold_distance) {
-    if (min_distance_bp < min_distance_bezt) {
+  const float threshold_dist = ED_view3d_select_dist_px() * sel_dist_mul;
+  if (min_dist_bezt < threshold_dist || min_dist_bp < threshold_dist) {
+    if (min_dist_bp < mi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list