about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-03 18:40:07 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-03 18:40:07 -0700
commit65879591caaeadaa884a8223a255835bbef0f394 (patch)
tree1634ca53bfcb9beb184f6f11469ea499e99eee73
parentf72185ab19878e271962392a29f0b8be080349c5 (diff)
downloadview.love-65879591caaeadaa884a8223a255835bbef0f394.tar.gz
bugfix: imprecision in drawing
scenario:
  slowly press down mouse button and drag to draw a line
  release mouse button

Before this commit the point would jump just a little bit on release,
and points would go slightly to the left of where I expect.

Yet another thing it's hard to write an automated test for.
-rw-r--r--Manual_tests.md1
-rw-r--r--drawing.lua3
2 files changed, 4 insertions, 0 deletions
diff --git a/Manual_tests.md b/Manual_tests.md
index 8d121d9..e258940 100644
--- a/Manual_tests.md
+++ b/Manual_tests.md
@@ -12,6 +12,7 @@ record those here.
 * How the screen looks. Our tests use a level of indirection to check text and
   graphics printed to screen, but not the precise pixels they translate to.
     - where exactly the cursor is drawn to highlight a given character
+    - analogously, how a shape precisely looks as you draw it
 
 ### Other compromises
 
diff --git a/drawing.lua b/drawing.lua
index 33bdbc0..8263dd9 100644
--- a/drawing.lua
+++ b/drawing.lua
@@ -126,6 +126,9 @@ function Drawing.draw_pending_shape(drawing, top, left,right)
   local function py(y) return Drawing.pixels(y, width)+top end
   local mx = Drawing.coord(pmx-left, width)
   local my = Drawing.coord(pmy-top, width)
+  -- recreate pixels from coords to precisely mimic how the drawing will look
+  -- after mouse_released
+  pmx,pmy = px(mx), py(my)
   local shape = drawing.pending
   if shape.mode == nil then
     -- nothing pending