changeset 146:bb1602f371d4

Add helper function chopv() and use it.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 14 Aug 2018 13:34:54 +0300
parents 5af8b5ddf349
children 9ad847dcd8e3
files draw_outputs.pde
diffstat 1 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/draw_outputs.pde	Tue Aug 14 13:12:43 2018 +0300
+++ b/draw_outputs.pde	Tue Aug 14 13:34:54 2018 +0300
@@ -11,6 +11,10 @@
   return int(v / 8) * 8;
 }
 
+int chopv(int v, int qv)
+{
+  return int(v / qv) * qv;
+}
 
 
 void createpoint(int x, int y, int mo)
@@ -115,8 +119,8 @@
         if (g_data[int('c')] == 1 || g_shift == true) {
             if (g_data[int('q')] == 1) {
                 // XXX is this g_gridx an error?
-                midy = int(midy / g_gridx) * g_gridx;
-                midx = int(midx / g_gridx) * g_gridx;
+                midy = chopv(midy, g_gridx);
+                midx = chopv(midx, g_gridx);
             }
         }
         int orient;
@@ -998,19 +1002,15 @@
     g_storedcoordx = x;
     g_storedcoordy = y;
 
-    int midx = 0;
-    int midy = 0;
     //brush handle mid point
     //some tools are exempted
     if (g_btype == 9 && tool() != 4 && tool() != 0 && mbut != 255) {
-        midx = int((g_bsourcex2 - g_bsourcex) / 2);
-        midy = int((g_bsourcey2 - g_bsourcey) / 2);
-        x = x - midx;
-        y = y - midy;
+        x -= int((g_bsourcex2 - g_bsourcex) / 2);
+        y -= int((g_bsourcey2 - g_bsourcey) / 2);
     }
     if (g_data[int('c')] == 1 || g_shift) {
-        x = int(x / g_gridx) * g_gridx;
-        y = int(y / g_gridy) * g_gridy;
+        x = chopv(x, g_gridx);
+        y = chopv(y, g_gridy);
     }
 
     if (g_pixelw == 2) {
@@ -1026,8 +1026,8 @@
         g_data[int('q')] = 0;
         g_data[int('z')] = 0;
 
-        x = int(ox / g_gridx) * g_gridx;
-        y = int(oy / g_gridy) * g_gridy;
+        x = chopv(ox, g_gridx);
+        y = chopv(oy, g_gridy);
 
         g_bsourcex = x;
         g_bsourcey = y;