From bd521ec45f9f4472aa1a039e61e4d167231be617 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 14 Nov 2018 16:53:24 -0300 Subject: [PATCH] Test Rectangle:contains/union/intersect(s) functions --- scripts/rectangle.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/rectangle.lua b/scripts/rectangle.lua index c25e9a5ce..e8b35bf4b 100644 --- a/scripts/rectangle.lua +++ b/scripts/rectangle.lua @@ -37,3 +37,25 @@ assert(rc.x == 2) assert(rc.y == 3) assert(rc.width == 4) assert(rc.height == 5) + +-- Rectangle:contains + +local a = Rectangle{x=2, y=3, width=4, height=5} +local b = Rectangle{x=3, y=4, width=1, height=1} +assert(a:contains(b)) +assert(not b:contains(a)) + +-- Rectangle:intersect + +assert(a:intersects(b)) +assert(b == a:intersect(b)) + +a = Rectangle{x=2, y=3, width=4, height=5} +b = Rectangle{x=3, y=4, width=4, height=5} +c = Rectangle{x=3, y=4, width=3, height=4} +assert(c == a:intersect(b)) +assert(c == b:intersect(a)) + +-- Rectangle:union + +assert(Rectangle{x=2, y=3, width=5, height=6} == a:union(b))