Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit cf4f1c3

Browse files
committed
feat(vectors): vec2 implementation
1 parent 85dc572 commit cf4f1c3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

scripts/serverCore.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ require("color")
1717
require("config")
1818
require("time")
1919

20-
vec3 = require("vectors")
20+
local vec = require("vectors")
21+
22+
vec2, vec3 = vec.vec2, vec.vec3
2123
customEventHooks = require("customEventHooks")
2224
customCommandHooks = require("customCommandHooks")
2325
logicHandler = require("logicHandler")

scripts/vectors.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function vec3:__call(x, y, z)
77
return setmetatable({x=x or 0,y=y or 0,z=z or 0}, getmetatable(self))
88
end
99

10+
--- Get the magnitude of a vector
11+
---@return number
1012
function vec3:length()
1113
return math.sqrt(self.x^2 + self.y^2 + self.z^2)
1214
end
@@ -45,4 +47,17 @@ function vec3.__tostring(a)
4547
return "vec3(" .. a.x .. ", " .. a.y .. ', ' .. a.z .. ")"
4648
end
4749

48-
return setmetatable(vec3, vec3)
50+
---@class vec2
51+
local vec2 = {}
52+
53+
vec2.__index = vec3
54+
55+
function vec2:__call(x, z)
56+
return setmetatable(vec3(x, 0, z), vec2)
57+
end
58+
59+
function vec2.__tostring(a)
60+
return "vec2(" .. a.x .. ", " .. a.z .. ")"
61+
end
62+
63+
return {vec3 = setmetatable(vec3, vec3), vec2 = setmetatable(vec2, vec2)}

0 commit comments

Comments
 (0)