Skip to content

Commit cef8ddf

Browse files
authored
Merge pull request #679 from almul8ab/patch-2
Fix CVectors.lua
2 parents 3fc2711 + f764978 commit cef8ddf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
function newVector3D(posX, posY, posZ)
22
local newVector = {x = posX or 0.0, y = posY or 0.0, z = posZ or 0.0}
3-
43
return newVector
54
end
65

76
function moduleVector3D(vector3D)
7+
if not vector3D or type(vector3D.x) ~= "number" then
8+
return 0
9+
end
810
return math.sqrt(vector3D.x * vector3D.x + vector3D.y * vector3D.y + vector3D.z * vector3D.z)
911
end
1012

1113
function normalizeVector3D(vector3D)
14+
if not vector3D or type(vector3D.x) ~= "number" then
15+
return newVector3D(0, 0, 0)
16+
end
1217
local mod = moduleVector3D(vector3D)
13-
1418
if mod ~= 0 then
1519
vector3D.x = vector3D.x / mod
1620
vector3D.y = vector3D.y / mod
1721
vector3D.z = vector3D.z / mod
1822
end
19-
2023
return vector3D
2124
end
2225

2326
function mulVector3D(vector3D, n)
27+
if not vector3D or type(vector3D.x) ~= "number" or type(n) ~= "number" then
28+
return newVector3D(0, 0, 0)
29+
end
2430
return newVector3D(vector3D.x * n, vector3D.y * n, vector3D.z * n)
25-
end
31+
end

0 commit comments

Comments
 (0)