NumberUtils
Kind of class: | public class |
---|---|
Package: | |
Inherits from: |
|
Classpath: | org.asaplibrary.util.NumberUtils |
File last modified: | Wednesday, 11 May 2011, 19:06:53 |
Summary
Class methods
-
randomInRange
(inStartRange:Number, inEndRange:Number) : Number
- Creates a random number within a given range.
-
roundFloat
(inNumber:Number, inDigitCount:int) : Number
- Rounds a floating point number to a given number of digits.
-
xPosOnSinus
(inYPosOnCurve:Number, inCurveBottom:Number, inCurveTop:Number) : Number
- Finds the x value of a point on a sine curve of which only the y value is known.
-
normalizedValue
(inValueToNormalize:Number, inMinValue:Number, inMaxValue:Number) : Number
- Finds the relative position of a number in a range between min and max, and returns its normalized value between 0 and 1.
-
angle
(inDx:Number, inDy:Number) : Number
- Calculates the angle of a vector.
-
percentageValue
(inStart:Number, inEnd:Number, inPercentage:Number) : Number
- Calculates the value of a continuum between start and end given a percentage position.
Class methods
angle
static function angle(inDx:Number,
inDy:Number) : Number
Calculates the angle of a vector.
Parameters
inDx:the x component of the vector
inDy:the y component of the vector
Returns
- The the angle of the passed vector in degrees.
normalizedValue
static function normalizedValue(inValueToNormalize:Number,
inMinValue:Number,
inMaxValue:Number) : Number
Finds the relative position of a number in a range between min and max, and returns its normalized value between 0 and 1.
Parameters
inValueToNormalize:value to normalize
inMinValue :lowest range value
inMaxValue :highest range value
Example
-
NumberUtils.normalizedValue(25, 0, 100); // 0.25 NumberUtils.normalizedValue(0, -1, 1); // 0.5
Returns
- The normalized value between 0 and 1.
percentageValue
static function percentageValue(inStart:Number,
inEnd:Number,
inPercentage:Number) : Number
Calculates the value of a continuum between start and end given a percentage position.
Parameters
inStart :start value
inEnd :end value
inPercentage:current percentage (from 0.0 to 1.0)
Example
-
var v:Number = NumberUtils.percentageValue(0, 100, .1); // 10
protected function performMoveToActualPosition (inPercentage:Number) : void { clip.x = NumberUtils.percentageValue( startX, endX, inPercentage ); clip.y = NumberUtils.percentageValue( startY, endY, inPercentage ); }
randomInRange
static function randomInRange(inStartRange:Number,
inEndRange:Number) : Number
Creates a random number within a given range.
Parameters
inStartRange:lowest number of the range
inEndRange :highest number of the range
Example
-
This example creates a random number between 10 and 20:
var scale:Number = NumberUtils.randomInRange(10, 20);
Returns
- A new random number.
roundFloat
static function roundFloat(inNumber:Number,
inDigitCount:int) : Number
Rounds a floating point number to a given number of digits.
Parameters
inNumber :the number to truncate
inDigitCount:the number of digits to keep after truncating
Example
-
var pi:Number = 3.14159265; pi = NumberUtils.roundFloat(pi, 2); // 3.14
Returns
- A new number with truncated floating point digits.
xPosOnSinus
static function xPosOnSinus(inYPosOnCurve:Number,
inCurveBottom:Number,
inCurveTop:Number) : Number
Finds the x value of a point on a sine curve of which only the y value is known. The closest x value is returned, ranging between -1 pi and 1 pi.
Parameters
inYPosOnCurve:y value of point to find on the sine curve
inCurveBottom:min y value (bottom) of the sine curve
inCurveTop :max y value (top) of the sine curve
Example
-
This code returns the x position of a normal sine curve - running from -1 to 1 - at x position 1 (when the curve is at its highest):
NumberUtils.xPosOnSinus(1, -1, 1); // 1.5707963267949 ( = 0.5 * Math.PI )
Implementation note
- Calls normalizedValue.
Returns
- The offset value as multiplier of pi.