From 1552efd76d3b815883d5eeafd5cf681d91de0bce Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 30 May 2022 15:27:03 -0700 Subject: [PATCH] bugfix: checking if a point is on a manhattan line --- geom.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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