mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-11-16 09:43:56 +00:00
feat(math): math.clamp (#468)
This commit is contained in:
1 parent
fdbf0ac114
commit
5d5a0cc511
1 file changed
+10
@@ -114,4 +114,14 @@ function math.groupdigits(number, seperator) -- credit http://richard.warburton.
|
||||
return left..(num:reverse():gsub('(%d%d%d)','%1' .. (seperator or ',')):reverse())..right
|
||||
end
|
||||
|
||||
---Clamp a number between 2 other numbers
|
||||
---@param val number
|
||||
---@param lower number
|
||||
---@param upper number
|
||||
---@return number
|
||||
function math.clamp(val, lower, upper) -- credit https://love2d.org/forums/viewtopic.php?t=1856
|
||||
if lower > upper then lower, upper = upper, lower end -- swap if boundaries supplied the wrong way
|
||||
return math.max(lower, math.min(upper, val))
|
||||
end
|
||||
|
||||
return lib.math
|
||||
Reference in new issue
Block a user