var my_bound = new Limit(low, high) // when installed onto the window
var my_bound = new Elements.Limit(low, high)
This is one way to make a new "bound", simply put the lower and upper bounds into the constructor and use the functions on it, as you can see below. You can also use the functions out-of-the-box as it were, and those examples are put first.
Elements.Limit.clamp(number, low, high)
Limit.clamp(number, low, high)
my_bound.clamp(number)
The clamp()
function returns the number but restricted between low
and high
Elements.Limit.wrap(number, low, high)
Limit.wrap(number, low, high)
my_bound.wrap(number)
The wrap()
function is a modified version of the modulo (%) operator - but with one key difference:
-1 % 10 // gives -1
Limit.wrap(-1, 0, 10) // gives 9 - properly between 0 and 10
I'm thinking of doing an alternate version that swaps the upper and lower bounds, something like:
Limit.wrap(0, 0, 10) // gives 0, but
Limit.awrap(0, 0, 10) // would give 10
Elements.Limit.fold(number, low, high)
Limit.fold(number, low, high)
my_bound.fold(number)
The fold()
function is like wrap()
, but is more continuous, and actually probably the least useful
Elements.Limit.sigmoid(number, low, high)
Limit.sigmoid(number, low, high)
my_bound.sigmoid(number)
The sigmoid()
function is a modified version of a relatively well known mathematical function, widely used as an activator function in the field of AI, I haven't actually used it yet, but I thought it'd be a bit cool to play around with it in a future project