summaryrefslogtreecommitdiff
path: root/city/geometry-test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'city/geometry-test.lua')
-rw-r--r--city/geometry-test.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/city/geometry-test.lua b/city/geometry-test.lua
index 758ce95..d48abbc 100644
--- a/city/geometry-test.lua
+++ b/city/geometry-test.lua
@@ -132,6 +132,43 @@ test(
end
)
+test(
+ 'intersect various squares',
+ function()
+ local center = geom.point(0, 0)
+ local square = geom.square(center, 2)
+
+ -- overlap x/y
+ assert(square:intersects(
+ geom.square(geom.point(1, 1), 2)))
+
+ -- nest inside
+ assert(square:intersects(
+ geom.square(geom.point(0, 0), 1)))
+
+ -- nest outside
+ assert(square:intersects(
+ geom.square(geom.point(0, 0), 5)))
+
+ -------- non-intersections --------
+
+ -- share x on left
+ assert(not square:intersects(
+ geom.square(geom.point(-2, 0), 2)))
+
+ -- share x on right
+ assert(not square:intersects(
+ geom.square(geom.point(2, 0), 2)))
+
+ -- share y on top
+ assert(not square:intersects(
+ geom.square(geom.point(0, -2), 2)))
+
+ -- share y on bottom
+ assert(not square:intersects(
+ geom.square(geom.point(0, 2), 2)))
+ end
+)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--