]> git.lizzy.rs Git - hydra-dragonfire.git/commitdiff
Add length operator to vector
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 30 May 2022 19:44:24 +0000 (21:44 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 30 May 2022 19:44:24 +0000 (21:44 +0200)
builtin/vector.lua

index 4991c1ef02d92d606878d957d2b7fb7b36416fd5..eed368f328ea2c9315e6b83d5a903f3c75b14c18 100644 (file)
@@ -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