summaryrefslogtreecommitdiff
path: root/city/geometry.lua
diff options
context:
space:
mode:
Diffstat (limited to 'city/geometry.lua')
-rw-r--r--city/geometry.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/city/geometry.lua b/city/geometry.lua
new file mode 100644
index 0000000..47e6a78
--- /dev/null
+++ b/city/geometry.lua
@@ -0,0 +1,28 @@
+local geom = {}
+
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+--
+-- point
+--
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+local point = {
+ __call = function(_, x, y)
+ local pt = {}
+ pt.x = x
+ pt.y = y
+ setmetatable(pt, {__index=_})
+ return pt
+ end,
+
+ distance_to = function(self, pt)
+ local d_x = self.x - pt.x
+ local d_y = self.y - pt.y
+ return math.sqrt(d_x*d_x + d_y*d_y)
+ end,
+}
+setmetatable(point, point)
+geom.point = point
+
+
+return geom