From 8b0359071bd71258eba96a0b68dba867fca51953 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Tue, 14 May 2024 19:21:47 +1000 Subject: [PATCH] fix(math): torgba types and alpha value --- imports/math/shared.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/imports/math/shared.lua b/imports/math/shared.lua index 32b1ef9..b1f3de9 100644 --- a/imports/math/shared.lua +++ b/imports/math/shared.lua @@ -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.