fix(math): torgba types and alpha value

This commit is contained in:
Linden
2024-05-14 19:21:47 +10:00
parent 0b13a56071
commit 8b0359071b

View File

@@ -32,7 +32,7 @@ function math.toscalars(input, min, max, round)
local i = 0
for s in string.gmatch(input:gsub('[%w]+%w?%(', ''), '(-?[%w.%w]+)') do
local n = parseNumber(s, min, max, round)
local n = parseNumber(s, min, max, round and (round == true or i < round))
i += 1
arr[i] = n
@@ -45,7 +45,7 @@ end
---@param input string | table
---@param min? number
---@param max? number
---@param round? boolean
---@param round? boolean | number If round is a number, only round n values.
---@return number | vector2 | vector3 | vector4
function math.tovector(input, min, max, round)
local inputType = type(input)
@@ -89,11 +89,14 @@ function math.normaltorotation(input)
error(('cannot convert type %s to a rotation vector'):format(inputType), 2)
end
---Tries to convert its argument to a vector.
---Tries to convert its argument to a vector4.
---@param input string | table
---@return number | vector2 | vector3 | vector4
---@return vector4
function math.torgba(input)
return math.tovector(input, 0, 255, true)
local res = math.tovector(input, 0, 255, 3)
assert(type(res) == 'vector4', 'cannot convert input to rgba')
parseNumber(res.a, 0, 1)
return res
end
---Takes a hexidecimal string and returns three integers.