Added ability to divide a number over a vector.

Example: `local s = 1/scale`
This commit is contained in:
Landon Manning 2015-09-09 23:14:33 -03:00
parent 2ffad16f80
commit 449bf861d4
2 changed files with 16 additions and 4 deletions

View File

@ -78,8 +78,14 @@ function vector.__mul(a,b)
end end
function vector.__div(a,b) function vector.__div(a,b)
assert(isvector(a) and type(b) == "number", "wrong argument types (expected <vector> / <number>)") if type(a) == "number" then
return new(a.x / b, a.y / b) return new(a/b.x, a/b.y)
elseif type(b) == "number" then
return new(b/a.x, b/a.y)
else
assert(isvector(a) and isvector(b), "Div: wrong argument types (<vector> or <number> expected)")
return new(a.x/b.x, a.y/b.y)
end
end end
function vector.__eq(a,b) function vector.__eq(a,b)

View File

@ -88,8 +88,14 @@ function vector.__mul(a,b)
end end
function vector.__div(a,b) function vector.__div(a,b)
assert(isvector(a) and type(b) == "number", "wrong argument types (expected <vector> / <number>)") if type(a) == "number" then
return new(a.x / b, a.y / b, a.z / b) return new(a / b.x, a / b.y, a / b.z)
elseif type(b) == "number" then
return new(a.x / b, a.y / b, a.z / b)
else
assert(isvector(a) and isvector(b), "Div: wrong argument types (<vector> or <number> expected)")
return new(a.x/b.x, a.y/b.y, a.z/b.z)
end
end end
function vector.__eq(a,b) function vector.__eq(a,b)