From 99ddbf595cd82382f665118d942c775d61e97f2a Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 30 May 2022 21:44:24 +0200 Subject: [PATCH] Add length operator to vector --- builtin/vector.lua | 8 ++++++++ 1 file changed, 8 insertions(+) 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 -- 2.44.0