diff options
author | sanine <sanine.not@pm.me> | 2022-02-25 10:03:47 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-02-25 10:03:47 -0600 |
commit | b10141db0f63429111f6c82c85ccb921723b5b82 (patch) | |
tree | 1cbbfb54690acb1d4f053b55764ef611cec6b9e3 /city/geometry-test.lua | |
parent | c167a029faf0d381c546f90abc9ed2a3bc96f94d (diff) |
add square:divide() function
Diffstat (limited to 'city/geometry-test.lua')
-rw-r--r-- | city/geometry-test.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/city/geometry-test.lua b/city/geometry-test.lua index f85bec0..74ddb3a 100644 --- a/city/geometry-test.lua +++ b/city/geometry-test.lua @@ -93,3 +93,40 @@ test( end end ) + +test( + 'subdivide a square', + function() + local center = geom.point(2, 2) + local square = geom.square(center, 4) + + local children = square:divide() + assert( + #children == 4, + string.format( + 'incorrect number of children: %d', + #children + ) + ) + + local aa = children[1] + assert(aa.center.x == 1) + assert(aa.center.y == 1) + assert(aa.span == 2) + + local ba = children[2] + assert(ba.center.x == 3) + assert(ba.center.y == 1) + assert(ba.span == 2) + + local ab = children[3] + assert(ab.center.x == 1) + assert(ab.center.y == 3) + assert(ab.span == 2) + + local bb = children[4] + assert(bb.center.x == 3) + assert(bb.center.y == 3) + assert(bb.span == 2) + end +) |