[MOD] inside function to accept either tuples or args

This commit is contained in:
Eduardo Cueto Mendoza 2020-05-09 10:48:32 -06:00
parent 0e22d64ad5
commit f635c452e6
1 changed files with 10 additions and 6 deletions

View File

@ -65,15 +65,17 @@ end
"Check if point at `(x,y)` is inside rectangle" "Check if point at `(x,y)` is inside rectangle"
function inside(r::Rectangle,x::Tuple) function inside(r::Rectangle,x::Tuple)
r.x <= x <= r.r + r.width && r.t1[1] <= x[1] <= r.t2[1] &&
r.y <= y <= r.y + r.height r.t1[2] <= x[2] <= r.t2[2]
end end
"Check if point at `(x,y)` is inside one of the shapes in the group" "Check if point at `(x,y)` is inside one of the shapes in the group"
function inside(g::ShapeGroup,x,y) function inside(g::ShapeGroup,x,y)
for m in g.members for m in g.members
if inside(m,x,y) if string(typeof(m)) == "Rectangle"
return true println(inside(m,(x,y)))
elseif string(typeof(m)) == "Circle"
println(inside(m,x,y))
end end
end end
end end
@ -81,8 +83,10 @@ end
"Check if point at `(x,y)` defined as a tuple is inside one of the shapes in the group" "Check if point at `(x,y)` defined as a tuple is inside one of the shapes in the group"
function inside(g::ShapeGroup,x::Tuple) function inside(g::ShapeGroup,x::Tuple)
for m in g.members for m in g.members
if inside(m,x) if string(typeof(m)) == "Rectangle"
return true println(inside(m,x))
elseif string(typeof(m)) == "Circle"
println(inside(m,x...))
end end
end end
end end