bugfix: checking if a point is on a manhattan line
This commit is contained in:
parent
26033f40f1
commit
1552efd76d
20
geom.lua
20
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
|
||||
|
|
Loading…
Reference in New Issue