Skip to content

Commit 6c61dcf

Browse files
committed
feat: 📦 added scm load
1 parent 0f190bf commit 6c61dcf

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ jobs:
2828
2929
- name: test
3030
run: |
31-
busted .
31+
busted vector
3232
# further tests here

scm.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- This simulates the files requried from the SCM module
2+
local scm = {}
3+
4+
function scm:load(name)
5+
return require(name)
6+
end
7+
8+
9+
return scm

vector/tests/test_spec.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,20 @@ describe('Vector', function()
101101
end)
102102
it('should transform a vector to the right', function()
103103
local v1 = vector.new(1, 0, 0)
104-
local v2 = v1:transformRight()
104+
local v2 = v1:rotate(90)
105105
assert.are.same("v=-0,0,1", "v="..tostring(v2))
106-
local v3 = v2:transformRight()
106+
local v3 = v2:rotate(90)
107107
assert.are.same("v=-1,0,-0", "v="..tostring(v3))
108-
local v4 = v3:transformRight()
108+
local v4 = v3:rotate(90)
109109
assert.are.same("v=0,0,-1", "v="..tostring(v4))
110110
end)
111111
it('should transform a vector to the left', function()
112112
local v1 = vector.new(1, 0, 0)
113-
local v2 = v1:transformLeft()
113+
local v2 = v1:rotate(270)
114114
assert.are.same("v=0,0,-1", "v="..tostring(v2))
115-
local v3 = v2:transformLeft()
115+
local v3 = v2:rotate(270)
116116
assert.are.same("v=-1,0,-0", "v="..tostring(v3))
117-
local v4 = v3:transformLeft()
117+
local v4 = v3:rotate(270)
118118
assert.are.same("v=-0,0,1", "v="..tostring(v4))
119119
end)
120120
end)

vector/vector.lua

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,24 @@ function Vector:equals(other)
141141
return self.x == other.x and self.y == other.y and self.z == other.z
142142
end
143143

144-
function Vector:transformRight()
145-
local v = Vector.new(self.x, self.y, self.z)
146-
v.x = self.z * -1
147-
v.z = self.x
148-
return v
149-
end
150-
151-
function Vector:transformLeft()
152-
local v = Vector.new(self.x, self.y, self.z)
153-
v.z = self.x * -1
154-
v.x = self.z
155-
return v
144+
---Rotate the vector by a given angle (90, 180, 270 degrees) around the Z-axis
145+
---@param angle number @The angle to rotate (90, 180, or 270)
146+
---@return Vector
147+
function Vector:rotate(angle)
148+
local newX, newZ
149+
if angle == 90 then
150+
newX = -self.z
151+
newZ = self.x
152+
elseif angle == 180 then
153+
newX = -self.x
154+
newZ = -self.z
155+
elseif angle == 270 then
156+
newX = self.z
157+
newZ = -self.x
158+
else
159+
error("Invalid angle. Only 90, 180, and 270 degrees are supported.")
160+
end
161+
return Vector.new(newX,self.y, newZ)
156162
end
157163

158164

0 commit comments

Comments
 (0)