-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
feature requestA feature requested by the communityA feature requested by the community
Description
Is your feature request related to a problem? Please describe.
The common math function "Clamp" is missing in the squirrel ::Math table.
Currently we need to implement clamping by writing something like this:
return ::Math.max(0, ::Math.min(100, _foo));
Right now, especially after you've worked with such lines a bunch of times, you will easily identify it.
But as the line grows larger, because the arguments come from different places, it becomes harder to parse at a glance.
Describe the solution you'd like
Add a new ::MSU.Math.Clamp function.
It could look something like this:
// Clamps an integer or float _value to be within [_min, _max] range
// throw InvalidValue exception when _min is greater than _max
::MSU.Math.clamp <- function( _value, _min, _max )
{
if (_min > _max)
{
::logError("_min must be less than or equal to _max");
throw ::MSU.Exception.InvalidValue(_min);
}
return _value < _min ? _min : (_value > _max ? _max : _value);
}
Additional context
Here is a now closed PR with some thoughts from the MSU guys about this: #461
Metadata
Metadata
Assignees
Labels
feature requestA feature requested by the communityA feature requested by the community