about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-20 17:06:16 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-20 17:08:00 -0700
commit1937379da31f4c2f4d2635ea3ad9c4cda074e1fe (patch)
tree4ea5d724eeedb2d0a2bed318517382ca67afbbf8
parentd61b5dfdeba5a35f1840a4a949c40a7d68bff0bf (diff)
downloadview.love-1937379da31f4c2f4d2635ea3ad9c4cda074e1fe.tar.gz
move drawing.starty into line cache
-rw-r--r--drawing.lua103
-rw-r--r--drawing_tests.lua20
-rw-r--r--edit.lua8
3 files changed, 71 insertions, 60 deletions
diff --git a/drawing.lua b/drawing.lua
index 587c24c..8d94bdd 100644
--- a/drawing.lua
+++ b/drawing.lua
@@ -4,15 +4,18 @@ require 'drawing_tests'
 
 -- All drawings span 100% of some conceptual 'page width' and divide it up
 -- into 256 parts.
-function Drawing.draw(State, line)
+function Drawing.draw(State, line_index, y)
+  local line = State.lines[line_index]
+  local line_cache = State.line_cache[line_index]
+  line_cache.starty = y
   local pmx,pmy = App.mouse_x(), App.mouse_y()
-  if pmx < State.right and pmy > line.y and pmy < line.y+Drawing.pixels(line.h, State.width) then
+  if pmx < State.right and pmy > line_cache.starty and pmy < line_cache.starty+Drawing.pixels(line.h, State.width) then
     App.color(Icon_color)
-    love.graphics.rectangle('line', State.left,line.y, State.width,Drawing.pixels(line.h, State.width))
+    love.graphics.rectangle('line', State.left,line_cache.starty, State.width,Drawing.pixels(line.h, State.width))
     if icon[State.current_drawing_mode] then
-      icon[State.current_drawing_mode](State.right-22, line.y+4)
+      icon[State.current_drawing_mode](State.right-22, line_cache.starty+4)
     else
-      icon[State.previous_drawing_mode](State.right-22, line.y+4)
+      icon[State.previous_drawing_mode](State.right-22, line_cache.starty+4)
     end
 
     if App.mouse_down(1) and love.keyboard.isDown('h') then
@@ -27,7 +30,7 @@ function Drawing.draw(State, line)
   end
 
   local mx = Drawing.coord(pmx-State.left, State.width)
-  local my = Drawing.coord(pmy-line.y, State.width)
+  local my = Drawing.coord(pmy-line_cache.starty, State.width)
 
   for _,shape in ipairs(line.shapes) do
     assert(shape)
@@ -36,11 +39,11 @@ function Drawing.draw(State, line)
     else
       App.color(Stroke_color)
     end
-    Drawing.draw_shape(line, shape, line.y, State.left,State.right)
+    Drawing.draw_shape(line, shape, line_cache.starty, State.left,State.right)
   end
 
   local function px(x) return Drawing.pixels(x, State.width)+State.left end
-  local function py(y) return Drawing.pixels(y, State.width)+line.y end
+  local function py(y) return Drawing.pixels(y, State.width)+line_cache.starty end
   for i,p in ipairs(line.points) do
     if p.deleted == nil then
       if Drawing.near(p, mx,my, State.width) then
@@ -70,7 +73,7 @@ function Drawing.draw(State, line)
     end
   end
   App.color(Current_stroke_color)
-  Drawing.draw_pending_shape(line, line.y, State.left,State.right)
+  Drawing.draw_pending_shape(line, line_cache.starty, State.left,State.right)
 end
 
 function Drawing.draw_shape(drawing, shape, top, left,right)
@@ -206,15 +209,17 @@ function Drawing.draw_pending_shape(drawing, top, left,right)
   end
 end
 
-function Drawing.in_drawing(drawing, x,y, left,right)
-  if drawing.y == nil then return false end  -- outside current page
+function Drawing.in_drawing(drawing, line_cache, x,y, left,right)
+  if line_cache.starty == nil then return false end  -- outside current page
   local width = right-left
-  return y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h, width) and x >= left and x < right
+  return y >= line_cache.starty and y < line_cache.starty + Drawing.pixels(drawing.h, width) and x >= left and x < right
 end
 
-function Drawing.mouse_pressed(State, drawing, x,y, button)
+function Drawing.mouse_pressed(State, drawing_index, x,y, button)
+  local drawing = State.lines[drawing_index]
+  local line_cache = State.line_cache[drawing_index]
   local cx = Drawing.coord(x-State.left, State.width)
-  local cy = Drawing.coord(y-drawing.y, State.width)
+  local cy = Drawing.coord(y-line_cache.starty, State.width)
   if State.current_drawing_mode == 'freehand' then
     drawing.pending = {mode=State.current_drawing_mode, points={{x=cx, y=cy}}}
   elseif State.current_drawing_mode == 'line' or State.current_drawing_mode == 'manhattan' then
@@ -240,12 +245,13 @@ end
 function Drawing.update(State)
   if State.lines.current_drawing == nil then return end
   local drawing = State.lines.current_drawing
+  local line_cache = State.line_cache[State.lines.current_drawing_index]
   assert(drawing.mode == 'drawing')
   local pmx, pmy = App.mouse_x(), App.mouse_y()
   local mx = Drawing.coord(pmx-State.left, State.width)
-  local my = Drawing.coord(pmy-drawing.y, State.width)
+  local my = Drawing.coord(pmy-line_cache.starty, State.width)
   if App.mouse_down(1) then
-    if Drawing.in_drawing(drawing, pmx,pmy, State.left,State.right) then
+    if Drawing.in_drawing(drawing, line_cache, pmx,pmy, State.left,State.right) then
       if drawing.pending.mode == 'freehand' then
         table.insert(drawing.pending.points, {x=mx, y=my})
       elseif drawing.pending.mode == 'move' then
@@ -255,7 +261,7 @@ function Drawing.update(State)
       end
     end
   elseif State.current_drawing_mode == 'move' then
-    if Drawing.in_drawing(drawing, pmx, pmy, State.left,State.right) then
+    if Drawing.in_drawing(drawing, line_cache, pmx, pmy, State.left,State.right) then
       drawing.pending.target_point.x = mx
       drawing.pending.target_point.y = my
       Drawing.relax_constraints(drawing, drawing.pending.target_point_index)
@@ -293,6 +299,7 @@ function Drawing.mouse_released(State, x,y, button)
     end
   elseif State.lines.current_drawing then
     local drawing = State.lines.current_drawing
+    local line_cache = State.line_cache[State.lines.current_drawing_index]
     if drawing.pending then
       if drawing.pending.mode == nil then
         -- nothing pending
@@ -301,14 +308,14 @@ function Drawing.mouse_released(State, x,y, button)
         Drawing.smoothen(drawing.pending)
         table.insert(drawing.shapes, drawing.pending)
       elseif drawing.pending.mode == 'line' then
-        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
+        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           drawing.pending.p2 = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)
           table.insert(drawing.shapes, drawing.pending)
         end
       elseif drawing.pending.mode == 'manhattan' then
         local p1 = drawing.points[drawing.pending.p1]
-        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
+        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           if math.abs(mx-p1.x) > math.abs(my-p1.y) then
             drawing.pending.p2 = Drawing.find_or_insert_point(drawing.points, mx, p1.y, State.width)
@@ -316,11 +323,11 @@ function Drawing.mouse_released(State, x,y, button)
             drawing.pending.p2 = Drawing.find_or_insert_point(drawing.points, p1.x, my, State.width)
           end
           local p2 = drawing.points[drawing.pending.p2]
-          App.mouse_move(State.left+Drawing.pixels(p2.x, State.width), drawing.y+Drawing.pixels(p2.y, State.width))
+          App.mouse_move(State.left+Drawing.pixels(p2.x, State.width), line_cache.starty+Drawing.pixels(p2.y, State.width))
           table.insert(drawing.shapes, drawing.pending)
         end
       elseif drawing.pending.mode == 'polygon' then
-        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
+        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           table.insert(drawing.pending.vertices, Drawing.find_or_insert_point(drawing.points, mx,my, State.width))
           table.insert(drawing.shapes, drawing.pending)
@@ -328,7 +335,7 @@ function Drawing.mouse_released(State, x,y, button)
       elseif drawing.pending.mode == 'rectangle' then
         assert(#drawing.pending.vertices <= 2)
         if #drawing.pending.vertices == 2 then
-          local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
+          local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)
           if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
             local first = drawing.points[drawing.pending.vertices[1]]
             local second = drawing.points[drawing.pending.vertices[2]]
@@ -343,7 +350,7 @@ function Drawing.mouse_released(State, x,y, button)
       elseif drawing.pending.mode == 'square' then
         assert(#drawing.pending.vertices <= 2)
         if #drawing.pending.vertices == 2 then
-          local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
+          local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)
           if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
             local first = drawing.points[drawing.pending.vertices[1]]
             local second = drawing.points[drawing.pending.vertices[2]]
@@ -354,14 +361,14 @@ function Drawing.mouse_released(State, x,y, button)
           end
         end
       elseif drawing.pending.mode == 'circle' then
-        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
+        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           local center = drawing.points[drawing.pending.center]
           drawing.pending.radius = geom.dist(center.x,center.y, mx,my)
           table.insert(drawing.shapes, drawing.pending)
         end
       elseif drawing.pending.mode == 'arc' then
-        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
+        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           local center = drawing.points[drawing.pending.center]
           drawing.pending.end_angle = geom.angle_with_hint(center.x,center.y, mx,my, drawing.pending.end_angle)
@@ -466,13 +473,13 @@ function Drawing.keychord_pressed(State, chord)
     end
     drawing.pending.mode = 'square'
   elseif App.mouse_down(1) and chord == 'p' and State.current_drawing_mode == 'polygon' then
-    local _,drawing = Drawing.current_drawing(State)
-    local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-drawing.y, State.width)
+    local _,drawing,line_cache = Drawing.current_drawing(State)
+    local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-line_cache.starty, State.width)
     local j = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)
     table.insert(drawing.pending.vertices, j)
   elseif App.mouse_down(1) and chord == 'p' and (State.current_drawing_mode == 'rectangle' or State.current_drawing_mode == 'square') then
-    local _,drawing = Drawing.current_drawing(State)
-    local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-drawing.y, State.width)
+    local _,drawing,line_cache = Drawing.current_drawing(State)
+    local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-line_cache.starty, State.width)
     local j = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)
     while #drawing.pending.vertices >= 2 do
       table.remove(drawing.pending.vertices)
@@ -481,9 +488,9 @@ function Drawing.keychord_pressed(State, chord)
   elseif chord == 'C-o' and not App.mouse_down(1) then
     State.current_drawing_mode = 'circle'
   elseif App.mouse_down(1) and chord == 'a' and State.current_drawing_mode == 'circle' then
-    local _,drawing = Drawing.current_drawing(State)
+    local _,drawing,line_cache = Drawing.current_drawing(State)
     drawing.pending.mode = 'arc'
-    local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-drawing.y, State.width)
+    local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-line_cache.starty, State.width)
     local center = drawing.points[drawing.pending.center]
     drawing.pending.radius = geom.dist(center.x,center.y, mx,my)
     drawing.pending.start_angle = geom.angle(center.x,center.y, mx,my)
@@ -499,7 +506,7 @@ function Drawing.keychord_pressed(State, chord)
     end
     drawing.pending.mode = 'circle'
   elseif chord == 'C-u' and not App.mouse_down(1) then
-    local drawing_index,drawing,i,p = Drawing.select_point_at_mouse(State)
+    local drawing_index,drawing,line_cache,i,p = Drawing.select_point_at_mouse(State)
     if drawing then
       if State.previous_drawing_mode == nil then
         State.previous_drawing_mode = State.current_drawing_mode
@@ -510,7 +517,7 @@ function Drawing.keychord_pressed(State, chord)
       State.lines.current_drawing = drawing
     end
   elseif chord == 'C-n' and not App.mouse_down(1) then
-    local drawing_index,drawing,point_index,p = Drawing.select_point_at_mouse(State)
+    local drawing_index,drawing,line_cache,point_index,p = Drawing.select_point_at_mouse(State)
     if drawing then
       if State.previous_drawing_mode == nil then
         -- don't clobber
@@ -523,7 +530,7 @@ function Drawing.keychord_pressed(State, chord)
       State.lines.current_drawing = drawing
     end
   elseif chord == 'C-d' and not App.mouse_down(1) then
-    local _,drawing,i,p = Drawing.select_point_at_mouse(State)
+    local _,drawing,_,i,p = Drawing.select_point_at_mouse(State)
     if drawing then
       for _,shape in ipairs(drawing.shapes) do
         if Drawing.contains_point(shape, i) then
@@ -541,7 +548,7 @@ function Drawing.keychord_pressed(State, chord)
       end
       drawing.points[i].deleted = true
     end
-    local drawing,_,shape = Drawing.select_shape_at_mouse(State)
+    local drawing,_,_,shape = Drawing.select_shape_at_mouse(State)
     if drawing then
       shape.mode = 'deleted'
     end
@@ -608,8 +615,9 @@ function Drawing.current_drawing(State)
   local x, y = App.mouse_x(), App.mouse_y()
   for drawing_index,drawing in ipairs(State.lines) do
     if drawing.mode == 'drawing' then
-      if Drawing.in_drawing(drawing, x,y, State.left,State.right) then
-        return drawing_index,drawing
+      local line_cache = State.line_cache[drawing_index]
+      if Drawing.in_drawing(drawing, line_cache, x,y, State.left,State.right) then
+        return drawing_index,drawing,line_cache
       end
     end
   end
@@ -617,15 +625,16 @@ function Drawing.current_drawing(State)
 end
 
 function Drawing.select_shape_at_mouse(State)
-  for _,drawing in ipairs(State.lines) do
+  for drawing_index,drawing in ipairs(State.lines) do
     if drawing.mode == 'drawing' then
       local x, y = App.mouse_x(), App.mouse_y()
-      if Drawing.in_drawing(drawing, x,y, State.left,State.right) then
-        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
+      local line_cache = State.line_cache[drawing_index]
+      if Drawing.in_drawing(drawing, line_cache, x,y, State.left,State.right) then
+        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)
         for i,shape in ipairs(drawing.shapes) do
           assert(shape)
           if geom.on_shape(mx,my, drawing, shape) then
-            return drawing,i,shape
+            return drawing,line_cache,i,shape
           end
         end
       end
@@ -637,12 +646,13 @@ function Drawing.select_point_at_mouse(State)
   for drawing_index,drawing in ipairs(State.lines) do
     if drawing.mode == 'drawing' then
       local x, y = App.mouse_x(), App.mouse_y()
-      if Drawing.in_drawing(drawing, x,y, State.left,State.right) then
-        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
+      local line_cache = State.line_cache[drawing_index]
+      if Drawing.in_drawing(drawing, line_cache, x,y, State.left,State.right) then
+        local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)
         for i,point in ipairs(drawing.points) do
           assert(point)
           if Drawing.near(point, mx,my, State.width) then
-            return drawing_index,drawing,i,point
+            return drawing_index,drawing,line_cache,i,point
           end
         end
       end
@@ -651,10 +661,11 @@ function Drawing.select_point_at_mouse(State)
 end
 
 function Drawing.select_drawing_at_mouse(State)
-  for _,drawing in ipairs(State.lines) do
+  for drawing_index,drawing in ipairs(State.lines) do
     if drawing.mode == 'drawing' then
       local x, y = App.mouse_x(), App.mouse_y()
-      if Drawing.in_drawing(drawing, x,y, State.left,State.right) then
+      local line_cache = State.line_cache[drawing_index]
+      if Drawing.in_drawing(drawing, line_cache, x,y, State.left,State.right) then
         return drawing
       end
     end
diff --git a/drawing_tests.lua b/drawing_tests.lua
index 4488fa9..5301318 100644
--- a/drawing_tests.lua
+++ b/drawing_tests.lua
@@ -34,7 +34,7 @@ function test_draw_line()
   edit.draw(Editor_state)
   check_eq(#Editor_state.lines, 2, 'F - test_draw_line/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_line/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_draw_line/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_line/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_line/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_line/baseline/#shapes')
   -- draw a line
@@ -80,7 +80,7 @@ function test_draw_horizontal_line()
   edit.draw(Editor_state)
   check_eq(#Editor_state.lines, 2, 'F - test_draw_horizontal_line/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_horizontal_line/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_draw_horizontal_line/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_horizontal_line/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_horizontal_line/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_horizontal_line/baseline/#shapes')
   -- draw a line that is more horizontal than vertical
@@ -109,7 +109,7 @@ function test_draw_circle()
   edit.draw(Editor_state)
   check_eq(#Editor_state.lines, 2, 'F - test_draw_circle/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_circle/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_draw_circle/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_circle/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_circle/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_circle/baseline/#shapes')
   -- draw a circle
@@ -139,7 +139,7 @@ function test_cancel_stroke()
   edit.draw(Editor_state)
   check_eq(#Editor_state.lines, 2, 'F - test_cancel_stroke/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_cancel_stroke/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_cancel_stroke/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_cancel_stroke/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_cancel_stroke/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_cancel_stroke/baseline/#shapes')
   -- start drawing a line
@@ -179,7 +179,7 @@ function test_draw_circle_mid_stroke()
   edit.draw(Editor_state)
   check_eq(#Editor_state.lines, 2, 'F - test_draw_circle_mid_stroke/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_circle_mid_stroke/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_draw_circle_mid_stroke/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_circle_mid_stroke/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_circle_mid_stroke/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_circle_mid_stroke/baseline/#shapes')
   -- draw a circle
@@ -208,7 +208,7 @@ function test_draw_arc()
   edit.draw(Editor_state)
   check_eq(#Editor_state.lines, 2, 'F - test_draw_arc/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_arc/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_draw_arc/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_arc/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_arc/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_arc/baseline/#shapes')
   -- draw an arc
@@ -240,7 +240,7 @@ function test_draw_polygon()
   check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_draw_polygon/baseline/drawing_mode')
   check_eq(#Editor_state.lines, 2, 'F - test_draw_polygon/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_polygon/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_draw_polygon/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_polygon/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_polygon/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_polygon/baseline/#shapes')
   -- first point
@@ -279,7 +279,7 @@ function test_draw_rectangle()
   check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_draw_rectangle/baseline/drawing_mode')
   check_eq(#Editor_state.lines, 2, 'F - test_draw_rectangle/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_rectangle/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_draw_rectangle/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_rectangle/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_rectangle/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle/baseline/#shapes')
   -- first point
@@ -324,7 +324,7 @@ function test_draw_rectangle_intermediate()
   check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_draw_rectangle_intermediate/baseline/drawing_mode')
   check_eq(#Editor_state.lines, 2, 'F - test_draw_rectangle_intermediate/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_rectangle_intermediate/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_draw_rectangle_intermediate/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_rectangle_intermediate/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_rectangle_intermediate/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle_intermediate/baseline/#shapes')
   -- first point
@@ -361,7 +361,7 @@ function test_draw_square()
   check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_draw_square/baseline/drawing_mode')
   check_eq(#Editor_state.lines, 2, 'F - test_draw_square/baseline/#lines')
   check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_square/baseline/mode')
-  check_eq(Editor_state.lines[1].y, Editor_state.top+Drawing_padding_top, 'F - test_draw_square/baseline/y')
+  check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_square/baseline/y')
   check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_square/baseline/y')
   check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_square/baseline/#shapes')
   -- first point
diff --git a/edit.lua b/edit.lua
index 011e975..b1a315d 100644
--- a/edit.lua
+++ b/edit.lua
@@ -158,8 +158,7 @@ function edit.draw(State)
 --?       print('=> y', y)
     elseif line.mode == 'drawing' then
       y = y+Drawing_padding_top
-      line.y = y
-      Drawing.draw(State, line)
+      Drawing.draw(State, line_index, y)
       y = y + Drawing.pixels(line.h, State.width) + Drawing_padding_bottom
     else
       print(line.mode)
@@ -224,11 +223,12 @@ function edit.mouse_pressed(State, x,y, mouse_button)
         break
       end
     elseif line.mode == 'drawing' then
-      if Drawing.in_drawing(line, x, y, State.left,State.right) then
+      local line_cache = State.line_cache[line_index]
+      if Drawing.in_drawing(line, line_cache, x, y, State.left,State.right) then
         State.lines.current_drawing_index = line_index
         State.lines.current_drawing = line
         Drawing.before = snapshot(State, line_index)
-        Drawing.mouse_pressed(State, line, x,y, mouse_button)
+        Drawing.mouse_pressed(State, line_index, x,y, mouse_button)
         break
       end
     end
ranged getproto' href='/acidbong/suckless/dwm/commit/main.c?id=0ff80653d3c85715966de3c1fe76a8927ed8133d'>0ff8065 ^
352e1b4 ^

3399650 ^
0ff8065 ^


352e1b4 ^
3399650 ^
0ff8065 ^
c09bf8d ^
080a38d ^
352e1b4 ^
3399650 ^



ca65478 ^
3399650 ^








e6cbe9c ^
3399650 ^

adaa28a ^
ca65478 ^
727449d ^
1076f2b

6651dd7 ^
bf35794 ^
b597fa4 ^
dba2306 ^

ca65478 ^
dba2306 ^
dc5d967 ^




1d7674b ^

dba2306 ^

dc5d967 ^
b597fa4 ^
4641aa2 ^

1076f2b
ca65478 ^
61a1910 ^
b5159df ^
dc5d967 ^
1076f2b
4970ef9 ^


1076f2b
4970ef9 ^

1076f2b

86d1224 ^
e571de8 ^
1076f2b

dba2306 ^

86d1224 ^
1076f2b
f60c597 ^
dba2306 ^

1076f2b
b6ad663 ^
f60c597 ^
dba2306 ^
2ffdc19 ^
b5159df ^
c0705ee ^
dba2306 ^
1076f2b
4e2c5b5 ^
0680c76 ^
b6ad663 ^
727449d ^
e3fd306 ^
0e5c819 ^
95e8d12 ^

e571de8 ^
478f6f9 ^


61a1910 ^
478f6f9 ^

61a1910 ^
478f6f9 ^
61a1910 ^
35e96b8 ^
478f6f9 ^


35e96b8 ^
478f6f9 ^


2210ea7 ^

61a1910 ^

0e5c819 ^
478f6f9 ^
0e5c819 ^
478f6f9 ^

439e15d ^
1076f2b

1076f2b

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301