[Bf-blender-cvs] [a80c1fc0117] master: Cleanup: simplify lasso transform from 17cb2a6da0c88

Campbell Barton noreply at git.blender.org
Wed Oct 21 04:04:12 CEST 2020


Commit: a80c1fc011795f4e8461210535e4fd0526b39044
Author: Campbell Barton
Date:   Wed Oct 21 12:57:50 2020 +1100
Branches: master
https://developer.blender.org/rBa80c1fc011795f4e8461210535e4fd0526b39044

Cleanup: simplify lasso transform from 17cb2a6da0c88

Access as 2D array, loop forwards over the pointer since it's
more common and simpler to read.

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

M	source/blender/windowmanager/intern/wm_gesture_ops.c

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

diff --git a/source/blender/windowmanager/intern/wm_gesture_ops.c b/source/blender/windowmanager/intern/wm_gesture_ops.c
index 72657ca83e2..8357d4c2331 100644
--- a/source/blender/windowmanager/intern/wm_gesture_ops.c
+++ b/source/blender/windowmanager/intern/wm_gesture_ops.c
@@ -690,26 +690,23 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
         }
 
         {
-          int x, y;
-          short *lasso = gesture->customdata;
+          short(*lasso)[2] = gesture->customdata;
 
-          lasso += (2 * gesture->points - 2);
-          x = (event->x - gesture->winrct.xmin - lasso[0]);
-          y = (event->y - gesture->winrct.ymin - lasso[1]);
+          const int x = ((event->x - gesture->winrct.xmin) - lasso[gesture->points - 1][0]);
+          const int y = ((event->y - gesture->winrct.ymin) - lasso[gesture->points - 1][1]);
 
           /* move the lasso */
           if (gesture->move) {
             for (int i = 0; i < gesture->points; i++) {
-              lasso[0 - (i * 2)] += x;
-              lasso[1 - (i * 2)] += y;
+              lasso[i][0] += x;
+              lasso[i][1] += y;
             }
           }
-          /* make a simple distance check to get a smoother lasso
-           * add only when at least 2 pixels between this and previous location */
+          /* Make a simple distance check to get a smoother lasso
+           * add only when at least 2 pixels between this and previous location. */
           else if ((x * x + y * y) > pow2f(2.0f * UI_DPI_FAC)) {
-            lasso += 2;
-            lasso[0] = event->x - gesture->winrct.xmin;
-            lasso[1] = event->y - gesture->winrct.ymin;
+            lasso[gesture->points][0] = event->x - gesture->winrct.xmin;
+            lasso[gesture->points][1] = event->y - gesture->winrct.ymin;
             gesture->points++;
           }
         }



More information about the Bf-blender-cvs mailing list