aboutsummaryrefslogtreecommitdiff
path: root/builtin/vector.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-05-30 21:44:24 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-05-30 21:44:24 +0200
commit99ddbf595cd82382f665118d942c775d61e97f2a (patch)
tree4a4dd53fa0794a70d6f4b22b6f69b931ae13fb6f /builtin/vector.lua
parent58943a2fb9eff643eb93c6733b75150614868d7c (diff)
downloadhydra-dragonfire-99ddbf595cd82382f665118d942c775d61e97f2a.tar.xz
Add length operator to vector
Diffstat (limited to 'builtin/vector.lua')
-rw-r--r--builtin/vector.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/builtin/vector.lua b/builtin/vector.lua
index 4991c1e..eed368f 100644
--- a/builtin/vector.lua
+++ b/builtin/vector.lua
@@ -30,6 +30,10 @@ function mt_vec2:__neg()
return vec2(-self.x, -self.y)
end
+function mt_vec2:__len()
+ return math.sqrt(self.x ^ 2 + self.y ^ 2)
+end
+
function mt_vec2:__tostring()
return "(" .. self.x .. ", " .. self.y .. ")"
end
@@ -73,6 +77,10 @@ function mt_vec3:__neg()
return vec3(-self.x, -self.y, -self.z)
end
+function mt_vec3:__len()
+ return math.sqrt(self.x ^ 2 + self.y ^ 2 + self.z ^ 2)
+end
+
function mt_vec3:__tostring()
return "(" .. self.x .. ", " .. self.y .. ", " .. self.z .. ")"
end