summaryrefslogtreecommitdiff
path: root/city/geometry.lua
diff options
context:
space:
mode:
Diffstat (limited to 'city/geometry.lua')
-rw-r--r--city/geometry.lua33
1 files changed, 28 insertions, 5 deletions
diff --git a/city/geometry.lua b/city/geometry.lua
index 47e6a78..a775213 100644
--- a/city/geometry.lua
+++ b/city/geometry.lua
@@ -1,17 +1,22 @@
local geom = {}
+local function class(tbl)
+ setmetatable(tbl, tbl)
+ return tbl
+end
+
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- point
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-local point = {
- __call = function(_, x, y)
+geom.point = class{
+ __call = function(this, x, y)
local pt = {}
pt.x = x
pt.y = y
- setmetatable(pt, {__index=_})
+ setmetatable(pt, {__index=this})
return pt
end,
@@ -21,8 +26,26 @@ local point = {
return math.sqrt(d_x*d_x + d_y*d_y)
end,
}
-setmetatable(point, point)
-geom.point = point
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+--
+-- square
+--
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+geom.square = class{
+ __call = function(this, center, span)
+ local square = {}
+ square.center = center
+ square.span = span
+ square.x = this.axis_range(center.x, span/2)
+ square.y = this.axis_range(center.y, span/2)
+ setmetatable(square, {__index=this})
+ return square
+ end,
+
+ axis_range = function(c, r) return {min=c-r, max=c+r} end,
+}
+
return geom