Class sandy.util.NumberUtil

Description

NumberUtil

Field Index

HALF_PI, PI, TO_DEGREE, TO_RADIAN, TOL, TWO_PI

Method Index

areEqual(), constrain(), isZero(), roundTo(), toDegree(), toRadian()

Field Detail

TWO_PI

static public TWO_PI:Number [Read Only]
Constant used pretty much everywhere. Trick of final const keywords use.

PI

static public PI:Number [Read Only]
Constant used pretty much everywhere. Trick of final const keywords use.

HALF_PI

static public HALF_PI:Number [Read Only]
Constant used pretty much everywhere. Trick of final const keywords use.

TO_DEGREE

static public TO_DEGREE:Number [Read Only]
Constant used to convert angle from radians to degress

TO_RADIAN

static public TO_RADIAN:Number [Read Only]
Constant used to convert degress to radians.

TOL

static public TOL:Number
Value used to compare a number and another one. Basically it's used to say if a number is zero or not.

Method Detail

isZero

static public function isZero(n:Number):Boolean

Say if a Number is close enought to zero to ba able to say it's zero. Adjust TOL property depending on the precision of your Application

Parameters

nNumber The number to compare with zero

Return

Boolean true if the Number is comparable to zero, false otherwise.

areEqual

static public function areEqual(n:Number, m:Number):Boolean

Say if a Number is close enought to another to ba able to say they are equal. Adjust TOL property depending on the precision of your Application

Parameters

nNumber The number to compare m
mNumber The number you want to compare with n

Return

Boolean true if the numbers are comparable to zero, false otherwise.

toDegree

static public function toDegree(n:Number):Number

Convert an angle from Radians to Degrees unit

Parameters

nNumber Number representing the angle in radian

Return

Number The angle in degrees unit

toRadian

static public function toRadian(n:Number):Number

Convert an angle from Degrees to Radians unit

Parameters

nNumber Number representing the angle in dregrees

Return

Number The angle in radian unit

constrain

static public function constrain(n:Number, min:Number, max:Number):Number

Add a constrain to the number which must be between min and max values. Usually name clamp ?

Parameters

nNumber The number to constrain
minNumber The minimal valid value
maxNumber The maximal valid value

Return

Number The number constrained

roundTo

static public function roundTo(n:Number, roundToInterval:Number):Number

Round a number to specified accuracy

Parameters

nNumber The number to round
roundToIntervalNumber The accuracy to which to round (i.e., set roundInterval to 0.01 to round 2 to decimal places)

Return

Number The rounded number