From a995e796ff3bf4d248c8cb71f9f0721ab12b1c52 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 14 May 2022 16:10:41 -0700 Subject: [PATCH] snap lines to nearby points --- main.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.lua b/main.lua index 8b8f90b..a09e580 100644 --- a/main.lua +++ b/main.lua @@ -171,8 +171,10 @@ 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 - if point.x == x and point.y == y then + local cx,cy = pixels(point.x), pixels(point.y) + if (cx-px)*(cx-px) + (cy-py)*(cy-py) < 16 then return i end end