Packageorg.as3utils
Classpublic class MathUtil
InheritanceMathUtil Inheritance Object

A utility class for working with mathematical operations.



Public Methods
 MethodDefined By
  
MathUtil is a static class and shouldn't be instantiated.
MathUtil
  
degreesToRadians(degrees:Number, decimalPlaces:int = 18):Number
[static] Converts degrees to radians.
MathUtil
  
millisecondsToSeconds(milliseconds:Number, decimalPlaces:int = 0):Number
[static] Converts milliseconds to seconds.
MathUtil
  
percentToRange(percent:Number, min:Number, max:Number, rounding:NumericRounding = null):Number
[static] Returns the number that corresponds to the percentage in a given range.
MathUtil
  
radiansToDegrees(radians:Number, decimalPlaces:int = 18):Number
[static] Converts radians to degrees.
MathUtil
  
rangeToPercent(num:Number, min:Number, max:Number, rounding:NumericRounding = null):Number
[static] Returns the percentage corresponding to the number in a given range.
MathUtil
Constructor Detail
MathUtil()Constructor
public function MathUtil()

MathUtil is a static class and shouldn't be instantiated.


Throws
IllegalOperationError — MathUtil is a static class and shouldn't be instantiated.
Method Detail
degreesToRadians()method
public static function degreesToRadians(degrees:Number, decimalPlaces:int = 18):Number

Converts degrees to radians.

Parameters

degrees:Number — the number of degrees to be converted.
 
decimalPlaces:int (default = 18) — the number of decimal places.

Returns
Number — the number of degrees converted to radians.

Example
         import org.as3coreaddendum.utils.MathUtil;
         
         MathUtil.degreesToRadians(null)    // 0
         MathUtil.degreesToRadians(0)       // 0
         MathUtil.degreesToRadians(1)       // 0.017453292519943295
         MathUtil.degreesToRadians(1, 0)    // 0
         MathUtil.degreesToRadians(1, 1)    // 0
         MathUtil.degreesToRadians(1, 2)    // 0.02
         MathUtil.degreesToRadians(1, 3)    // 0.017
         MathUtil.degreesToRadians(1.5)     // 0.02617993877991494
         MathUtil.degreesToRadians(30)      // 0.5235987755982988
         MathUtil.degreesToRadians(-8)      // -0.13962634015954636
         
millisecondsToSeconds()method 
public static function millisecondsToSeconds(milliseconds:Number, decimalPlaces:int = 0):Number

Converts milliseconds to seconds.

Parameters

milliseconds:Number — the number of milliseconds to be converted.
 
decimalPlaces:int (default = 0) — the number of decimal places.

Returns
Number — the number of milliseconds converted to seconds.

Example
         import org.as3coreaddendum.utils.MathUtil;
         
         MathUtil.millisecondsToSeconds(null)        // 0
         MathUtil.millisecondsToSeconds(0)           // 0
         MathUtil.millisecondsToSeconds(1)           // 0
         MathUtil.millisecondsToSeconds(300)         // 0
         MathUtil.millisecondsToSeconds(300, 1)      // 0.3
         MathUtil.millisecondsToSeconds(500)         // 1
         MathUtil.millisecondsToSeconds(500, 1)      // 0.5
         MathUtil.millisecondsToSeconds(1000)        // 1
         MathUtil.millisecondsToSeconds(1000, 1)     // 1
         MathUtil.millisecondsToSeconds(1500)        // 2
         MathUtil.millisecondsToSeconds(1500, 1)     // 1.5
         MathUtil.millisecondsToSeconds(1500, 2)     // 1.5
         MathUtil.millisecondsToSeconds(2123)        // 2
         MathUtil.millisecondsToSeconds(2123, 1)     // 2.1
         MathUtil.millisecondsToSeconds(2123, 2)     // 2.12
         MathUtil.millisecondsToSeconds(-2123)       // -2
         MathUtil.millisecondsToSeconds(-2123, 1)    // -2.1
         
percentToRange()method 
public static function percentToRange(percent:Number, min:Number, max:Number, rounding:NumericRounding = null):Number

Returns the number that corresponds to the percentage in a given range.

Parameters

percent:Number — the percent to be used in the range.
 
min:Number — the begin of the range.
 
max:Number — the end of the range.
 
rounding:NumericRounding (default = null) — determines whether the number should be rounded.

Returns
Number — the number that corresponds to the percentage in the range.

Example
         import org.as3coreaddendum.utils.MathUtil;
         
         MathUtil.percentToRange(50, 0, 100)                           // 50
         MathUtil.percentToRange(50, 100, 200)                         // 150
         MathUtil.percentToRange(1, 26, 77)                            // 26.51
         MathUtil.percentToRange(33, 26, 77)                           // 42.83
         MathUtil.percentToRange(33, 26, 77, NumericRounding.FLOOR)    // 42
         
radiansToDegrees()method 
public static function radiansToDegrees(radians:Number, decimalPlaces:int = 18):Number

Converts radians to degrees.

Parameters

radians:Number — the number of degrees to be converted.
 
decimalPlaces:int (default = 18) — the number of decimal places.

Returns
Number — the number of radians converted to degrees.

Example
         import org.as3coreaddendum.utils.MathUtil;
         
         MathUtil.radiansToDegrees(null)    // 0
         MathUtil.radiansToDegrees(0)       // 0
         MathUtil.radiansToDegrees(1)       // 57.29577951308232
         MathUtil.radiansToDegrees(1, 0)    // 57
         MathUtil.radiansToDegrees(1, 1)    // 57.3
         MathUtil.radiansToDegrees(1, 2)    // 57.3
         MathUtil.radiansToDegrees(1, 3)    // 57.296
         MathUtil.radiansToDegrees(1.5)     // 85.94366926962348
         MathUtil.radiansToDegrees(30)      // 1718.8733853924698
         MathUtil.radiansToDegrees(-8)      // -458.3662361046586
         
rangeToPercent()method 
public static function rangeToPercent(num:Number, min:Number, max:Number, rounding:NumericRounding = null):Number

Returns the percentage corresponding to the number in a given range.

Parameters

num:Number — the number to be used in the range.
 
min:Number — the begin of the range.
 
max:Number — the end of the range.
 
rounding:NumericRounding (default = null) — determines whether the number should be rounded.

Returns
Number — the percentage that corresponds to the number in the range.

Example
         import org.as3coreaddendum.utils.MathUtil;
         
         MathUtil.rangeToPercent(50, 0, 100)                           // 50
         MathUtil.rangeToPercent(50, 100, 200)                         // -50
         MathUtil.rangeToPercent(150, 100, 200)                        // 50
         MathUtil.rangeToPercent(27, 26, 77)                           // 1.9607843137254901
         MathUtil.rangeToPercent(33, 26, 77)                           // 13.725490196078432
         MathUtil.rangeToPercent(33, 26, 77, NumericRounding.FLOOR)    // 13
         MathUtil.rangeToPercent(51.5, 26, 77)                         // 50