about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-15 00:03:31 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-15 00:03:31 -0700
commit87a3753796bec4818aca390c215ed0a2821cff1c (patch)
treed625675c5109135d8eae82af1dfb4d9490f22576
parent3cb9dc3e0bf11f0834e4eeefe67c51492d904a24 (diff)
downloadlines.love-87a3753796bec4818aca390c215ed0a2821cff1c.tar.gz
more intuitive point delete from polygons
-rw-r--r--main.lua20
1 files changed, 18 insertions, 2 deletions
diff --git a/main.lua b/main.lua
index 56d309e..61a2777 100644
--- a/main.lua
+++ b/main.lua
@@ -566,7 +566,16 @@ function keychord_pressed(chord)
     if drawing then
       for _,shape in ipairs(drawing.shapes) do
         if contains_point(shape, i) then
-          shape.mode = 'deleted'
+          if shape.mode == 'polygon' then
+            local idx = table.find(shape.vertices, i)
+            assert(idx)
+            table.remove(shape.vertices, idx)
+            if #shape.vertices < 3 then
+              shape.mode = 'deleted'
+            end
+          else
+            shape.mode = 'deleted'
+          end
         end
       end
       drawing.points[i].deleted = true
@@ -651,7 +660,6 @@ function contains_point(shape, p)
   if shape.mode == 'freehand' then
     -- not supported
   elseif shape.mode == 'line' then
-    print(p, shape.p1, shape.p2)
     return shape.p1 == p or shape.p2 == p
   elseif shape.mode == 'polygon' then
     return table.find(shape.vertices, p)
@@ -710,6 +718,14 @@ end
 function love.keyreleased(key, scancode)
 end
 
+function table.find(h, x)
+  for k,v in pairs(h) do
+    if v == x then
+      return k
+    end
+  end
+end
+
 function angle_with_hint(x1, y1, x2, y2, hint)
   local result = math.angle(x1,y1, x2,y2)
   if hint then