Packagecom.zehfernando.utils
Classpublic class MathUtils



Public Methods
 MethodDefined by
  
clamp(__value:Number, __min:Number = 0, __max:Number = 1):Number
[static] Clamps a number to a range, by restricting it to a minimum and maximum values: if the passed value is lower than the minimum value, it's replaced by the minimum; if it's higher than the maximum value, it's replaced by the maximum; if not, it's unchanged.
MathUtils
  
map(__value:Number, __oldMin:Number, __oldMax:Number, __newMin:Number = 0, __newMax:Number = 1, __clamp:Boolean = false):Number
[static] Maps a value from a range, determined by old minimum and maximum values, to a new range, determined by new minimum and maximum values.
MathUtils
  
rangeMod(__value:Number, __min:Number, __max:Number):Number
[static] Clamps a value to a range, by restricting it to a minimum and maximum values but folding the value to the range instead of simply resetting to the minimum and maximum.
MathUtils
Method detail
clamp()method
public static function clamp(__value:Number, __min:Number = 0, __max:Number = 1):Number

Clamps a number to a range, by restricting it to a minimum and maximum values: if the passed value is lower than the minimum value, it's replaced by the minimum; if it's higher than the maximum value, it's replaced by the maximum; if not, it's unchanged.

Parameters
__value:Number — The value to be clamped.
 
__min:Number (default = 0) — Minimum value allowed.
 
__max:Number (default = 1) — Maximum value allowed.

Returns
Number — The newly clamped value.
map()method 
public static function map(__value:Number, __oldMin:Number, __oldMax:Number, __newMin:Number = 0, __newMax:Number = 1, __clamp:Boolean = false):Number

Maps a value from a range, determined by old minimum and maximum values, to a new range, determined by new minimum and maximum values. These minimum and maximum values are referential; the new value is not clamped by them.

Parameters
__value:Number — The value to be re-mapped.
 
__oldMin:Number — The previous minimum value.
 
__oldMax:Number — The previous maximum value.
 
__newMin:Number (default = 0) — The new minimum value.
 
__newMax:Number (default = 1) — The new maximum value.
 
__clamp:Boolean (default = false)

Returns
Number — The new value, mapped to the new range.
rangeMod()method 
public static function rangeMod(__value:Number, __min:Number, __max:Number):Number

Clamps a value to a range, by restricting it to a minimum and maximum values but folding the value to the range instead of simply resetting to the minimum and maximum. It works like a more powerful Modulo function.

Parameters
__value:Number — The value to be clamped.
 
__min:Number — Minimum value allowed.
 
__max:Number — Maximum value allowed.

Returns
Number — The newly clamped value.

Example
Some examples:
    trace(MathUtils.roundClamp(14, 0, 10));
    // Result: 4
    
    trace(MathUtils.roundClamp(360, 0, 360));
    // Result: 0
    
    trace(MathUtils.roundClamp(360, -180, 180));
    // Result: 0
    
    trace(MathUtils.roundClamp(21, 0, 10));
    // Result: 1
    
    trace(MathUtils.roundClamp(-98, 0, 100));
    // Result: 2