Class: Range

system.numeric. Range


new Range( [min] [, max] [, writable])

Represents a range of numeric values. This range can be immutable.

Represents a range of numeric values. This range can be immutable.

Parameters:
Name Type Argument Default Description
min number <optional>
NaN

The minimum range value.

max number <optional>
NaN

The maximum range value.

writable boolean <optional>
true

Indicates if the min and max values must be freezed. Prevents existing min and max properties from being removed or their enumerability, configurability, or writability, from being changed.

Implements:
Example
var Range = system.numeric.Range ;

var r1 = new Range(10, 120) ;
var r2 = new Range(100, 150) ;

trace ("r1 : " + r1) ; // r1 : [Range min:10 max:120]
trace ("r2 : " + r2) ; // r2 : [Range min:100 max:150]

trace ("r1 contains 50    : " + r1.contains(50)) ; // r1 contains 50 : true
trace ("r1 isOutOfRange 5 : " + r1.isOutOfRange(5)) ; // r1 isOutOfRange 5 : true
trace ("r1 overlap r2     : " + r1.overlap(r2)) ; // r1 overlap r2 : true
trace ("r1 clamp 5        : " + r1.clamp(5)) ; // r1 clamp 5 : 10
trace ("r1 clamp 121      : " + r1.clamp(121)) ; // r1 clamp 121 : 120

Members


<static> COLOR :system.numeric.Range

Range between -255 and 255.

Type:

<static> DEGREE :system.numeric.Range

Range between 0 and 360.

Type:

<static> PERCENT :system.numeric.Range

Range between 0 and 100.

Type:

<static> RADIAN :system.numeric.Range

Range between 0 and Math.PI*2.

Type:

<static> UNITY :system.numeric.Range

Range between 0 and 1.

Type:

max :number

The maximum range value.

Type:
  • number

min :number

The minimum range value.

Type:
  • number

Methods


clamp(value)

Clamps a specific value in the current range.

Parameters:
Name Type Description
value number

The number to clamp between the minimum and maximum value of the current range.

Returns:

The clamped value.

Type
number
Example
var range = new Range(2,8) ;
trace( range.clamp(1) ) ; // 2
trace( range.clamp(2) ) ; // 2
trace( range.clamp(5) ) ; // 5
trace( range.clamp(8) ) ; // 8
trace( range.clamp(9) ) ; // 8

clone()

Returns a shallow copy of the object.

Returns:

a shallow copy of the object.


combine( [range])

Creates a new range by combining two existing ranges.

Parameters:
Name Type Argument Default Description
range system.numeric.Range <optional>
null

The range to combine, null permitted to create a clone of the current range.

Returns:

The new range combined between the curred and passed-in range.

Type
system.numeric.Range
Example
var range1 = new Range(2,8) ;
var range2 = new Range(1,8) ;
var range3 = new Range(5,10) ;

trace( range1.combine( range2 ) ) ; // [Range min:1 max:8]
trace( range1.combine( range3 ) ) ; // [Range min:2 max:10]

contains(value)

Returns true if the Range instance contains the value passed in argument.

Parameters:
Name Type Description
value number

The value to check.

Returns:

true if the Range instance contains the value passed in argument.

Type
boolean
Example
var range = new Range(2,8) ;
trace( range.contains(2) ) ; // true
trace( range.contains(5) ) ; // true
trace( range.contains(8) ) ; // true
trace( range.contains(0) ) ; // false
trace( range.contains(9) ) ; // false

equals(object)

Indicates whether some other object is equal to this one.

Parameters:
Name Type Description
object *

The object to evaluates.

Returns:

true if the the specified object is equal to this one.

Type
boolean
Example
var range1 = new Range(2,8) ;
var range2 = new Range(2,8) ;
var range3 = new Range(5,10) ;

trace( range1.equals(range2) ) ; // true
trace( range1.equals(range3) ) ; // false

expand( [lowerMargin] [, upperMargin])

Creates a new range by adding margins to an existing range.

Parameters:
Name Type Argument Default Description
lowerMargin number <optional>
0

The lower margin expressed as a normalized value of the range length (between 0 and 1).

upperMargin number <optional>
0

The upper margin expressed as a normalized value of the range length (between 0 and 1).

Returns:

The new expanded range.

Type
system.numeric.Range
Example
var range = new Range(4,8) ;
trace( range.expand( 0.5 , 0.5 ) ) ; // [Range min:2 max:12]

getCentralValue()

Indicates the central value for the range.

Returns:

The central value of the current range.

Type
number
Example
var range = new Range(4,8) ;
trace( range.getCentralValue() ) ; //  6

getRandomFloat()

Returns a random floating-point number between two numbers.

Returns:

A random floating-point number between two numbers.

Type
number
Example
var range = new Range(2,8) ;
trace( range.getRandomFloat() ) ; // a float between 2 and 8

getRandomInteger()

Returns a random integer integet between two numbers.

Returns:

A random integer number between two numbers.

Type
number
Example
var range = new Range(2,8) ;
trace( range.getRandomInteger() ) ; // an integer between 2 and 8

isOutOfRange(value)

Indicates true if the specified value is out of the range.

Parameters:
Name Type Description
value number

The numeric value to evaluates.

Returns:

true if the value is out of the range.

Type
boolean
Example
var range = new Range(2,8) ;
trace( range.isOutOfRange(1) ) ; // true
trace( range.isOutOfRange(9) ) ; // true
trace( range.isOutOfRange(2) ) ; // false
trace( range.isOutOfRange(5) ) ; // false
trace( range.isOutOfRange(8) ) ; // false

overlap(range)

Returns true if the range in argument overlap the current range.

Parameters:
Name Type Description
range system.numeric.Range

The range to evaluates.

Returns:

true if the range in argument overlap the current range.

Type
boolean
Example
var range = new Range(2,8) ;
trace( range.overlap(new Range(1,2)) ) ; // true
trace( range.overlap(new Range(3,5)) ) ; // true
trace( range.overlap(new Range(5,9)) ) ; // true
trace( range.overlap(new Range(8,9)) ) ; // true
trace( range.overlap(new Range(0,1)) ) ; // false
trace( range.overlap(new Range(9,10)) ) ; // false

size()

Returns the length of the range.

Returns:

the length of the range.

Type
number
Example
var range = new Range(2,8) ;
trace( range.size() ) ; // 6

toString()

Returns the string representation of this instance.

Returns:

the string representation of this instance.

Type
string
Example
var range = new Range(4,8) ;
trace( range ) ; [Range min:4 max:8]