Merge pull request #2864 from Elv13/rect_equal
Add a way to compare rectangle to gears.geometry
This commit is contained in:
commit
754461b8f1
|
@ -151,6 +151,20 @@ function gears.geometry.rectangle.get_in_direction(dir, recttbl, cur)
|
||||||
return target
|
return target
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Return true if the area are exactly identical.
|
||||||
|
--
|
||||||
|
-- The areas are table with a `x`, `y`, `width` and `height` keys.
|
||||||
|
--
|
||||||
|
-- @tparam table a The area.
|
||||||
|
-- @tparam table b The other area.
|
||||||
|
-- @treturn boolean If the areas are identical.
|
||||||
|
function gears.geometry.rectangle.are_equal(a, b)
|
||||||
|
for _, v in ipairs {"x", "y", "width", "height"} do
|
||||||
|
if a[v] ~= b[v] then return false end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
--- Check if an area intersect another area.
|
--- Check if an area intersect another area.
|
||||||
-- @param a The area.
|
-- @param a The area.
|
||||||
-- @param b The other area.
|
-- @param b The other area.
|
||||||
|
|
|
@ -121,6 +121,30 @@ describe("gears.geometry", function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe("rectangle.are_equal", function()
|
||||||
|
|
||||||
|
it("with equality", function()
|
||||||
|
assert.are_equal(true, geo.rectangle.are_equal(
|
||||||
|
{x=0, y=0, width=10, height=10},
|
||||||
|
{x=0, y=0, width=10, height=10}
|
||||||
|
))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("without equality", function()
|
||||||
|
assert.are_equal(false, geo.rectangle.are_equal(
|
||||||
|
{x=0, y=0, width=1, height=1},
|
||||||
|
{x=2, y=2, width=1, height=1}
|
||||||
|
))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("with intersection", function()
|
||||||
|
assert.are_equal(false, geo.rectangle.are_equal(
|
||||||
|
{x=0, y=0, width=1, height=1},
|
||||||
|
{x=0, y=0, width=2, height=2}
|
||||||
|
))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe("rectangle.area_remove", function()
|
describe("rectangle.area_remove", function()
|
||||||
-- TODO perhaps it would be better to compare against a cairo.region
|
-- TODO perhaps it would be better to compare against a cairo.region
|
||||||
-- than to have this overly specific tests?
|
-- than to have this overly specific tests?
|
||||||
|
|
Loading…
Reference in New Issue