Skip to content

Commit

Permalink
fix(math): torgba types and alpha value
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed May 14, 2024
1 parent 0b13a56 commit 8b03590
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions imports/math/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8b03590

Please sign in to comment.