about summary refs log tree commit diff stats
path: root/geom.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-30 15:27:03 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-30 15:27:03 -0700
commit1552efd76d3b815883d5eeafd5cf681d91de0bce (patch)
tree0f1de4054a8aa7762ad9448c8da50c52c2766381 /geom.lua
parent26033f40f1a33793b90c3b20805d5672fb4e1bef (diff)
downloadtext.love-1552efd76d3b815883d5eeafd5cf681d91de0bce.tar.gz
bugfix: checking if a point is on a manhattan line
Diffstat (limited to 'geom.lua')
-rw-r--r--geom.lua20
1 files changed, 19 insertions, 1 deletions
diff --git a/geom.lua b/geom.lua
index 7dd6628..3efe4ec 100644
--- a/geom.lua
+++ b/geom.lua
@@ -6,7 +6,25 @@ function geom.on_shape(x,y, drawing, shape)
   elseif shape.mode == 'line' then
     return geom.on_line(x,y, drawing, shape)
   elseif shape.mode == 'manhattan' then
-    return x == drawing.points[shape.p1].x or y == drawing.points[shape.p1].y
+    local p1 = drawing.points[shape.p1]
+    local p2 = drawing.points[shape.p2]
+    if p1.x == p2.x then
+      if x ~= p1.x then return false end
+      local y1,y2 = p1.y, p2.y
+      if y1 > y2 then
+        y1,y2 = y2,y1
+      end
+      return y >= y1*0.95 and y <= y2*1.05
+    elseif p1.y == p2.y then
+      if y ~= p1.y then return false end
+      local x1,x2 = p1.x, p2.x
+      if x1 > x2 then
+        x1,x2 = x2,x1
+      end
+      return x >= x1*0.95 and x <= x2*1.05
+    else
+      assert(false)
+    end
   elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
     return geom.on_polygon(x,y, drawing, shape)
   elseif shape.mode == 'circle' then