about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-14 16:15:50 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-14 16:15:50 -0700
commit89b6eda6b98df75c8ce5cea49cc2d578f65c98ad (patch)
treee44aca75a43064143254cc9f81fbe0de6fa1400d
parent7d6eeed194584777c45baddc3a1f5df71b8883ee (diff)
downloadtext.love-89b6eda6b98df75c8ce5cea49cc2d578f65c98ad.tar.gz
make points easier to acquire
-rw-r--r--main.lua12
1 files changed, 8 insertions, 4 deletions
diff --git a/main.lua b/main.lua
index d6a3abf..adcd948 100644
--- a/main.lua
+++ b/main.lua
@@ -95,7 +95,7 @@ function love.draw()
         draw_shape(16,line.y, line, shape)
       end
       for _,p in ipairs(line.points) do
-        if p.x == mx and p.y == my then
+        if near(p, mx,my) then
           love.graphics.setColor(1,0,0)
           love.graphics.circle('line', pixels(p.x)+16,pixels(p.y)+line.y, 4)
         else
@@ -173,10 +173,8 @@ function propagate_to_drawings(x,y, button)
 end
 
 function insert_point(points, x,y)
-  local px,py = pixels(x),pixels(y)
   for i,point in ipairs(points) do
-    local cx,cy = pixels(point.x), pixels(point.y)
-    if (cx-px)*(cx-px) + (cy-py)*(cy-py) < 16 then
+    if near(point, x,y) then
       return i
     end
   end
@@ -184,6 +182,12 @@ function insert_point(points, x,y)
   return #points
 end
 
+function near(point, x,y)
+  local px,py = pixels(x),pixels(y)
+  local cx,cy = pixels(point.x), pixels(point.y)
+  return (cx-px)*(cx-px) + (cy-py)*(cy-py) < 16
+end
+
 function draw_shape(left,top, drawing, shape)
   if shape.mode == 'freehand' then
     local prev = nil