From: Elias Fleckenstein Date: Mon, 30 May 2022 19:44:24 +0000 (+0200) Subject: Add length operator to vector X-Git-Tag: v0.1.1~1 X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=99ddbf595cd82382f665118d942c775d61e97f2a;p=hydra-dragonfire.git Add length operator to vector --- 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