From 4ce54e98aa0d1292f532be18f5a3ed37b881ba1f Mon Sep 17 00:00:00 2001 From: greenya Date: Sun, 19 Nov 2017 15:44:57 +0200 Subject: [PATCH] api: clamp function --- api/api.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api/api.lua b/api/api.lua index 48d57bab..26e17a58 100644 --- a/api/api.lua +++ b/api/api.lua @@ -85,6 +85,20 @@ function pfUI.api.round(input, places) end end +-- [ clamp ] +-- Clamps a number between given range. +-- 'x' [number] the number that should be clamped. +-- 'min' [number] minimum value. +-- 'max' [number] maximum value. +-- returns: [number] clamped value: 'x', 'min' or 'max' value itself. +function pfUI.api.clamp(x, min, max) + if type(x) == "number" and type(min) == "number" and type(max) == "number" then + return x < min and min or x > max and max or x + else + return x + end +end + -- [ SanitizePattern ] -- Sanitizes and convert patterns into gfind compatible ones. -- 'pattern' [string] unformatted pattern