Range¶
Overview¶
A numeric range.
@author Chris Malley (PixelZoom, Inc.) @author Andrew Adare @author Chris Klusendorf (PhET Interactive Simulations)
Class Range¶
Constructor¶
new Range( min : number, max : number )¶
Instance Methods¶
getMin() : number¶
Getter for min
setMin( min : number )¶
TODO: Allow chaining, https://github.com/phetsims/dot/issues/122 Setter for min
getMax() : number¶
Getter for max
setMax( max : number )¶
Setter for max
setMinMax( min : number, max : number ) : this¶
Sets the minimum and maximum value of the range
set( range : Range ) : this¶
Sets the minimum and maximum value of this range from the provided Range.
addValue( n : number )¶
withValue( n : number ) : Range¶
copy() : Range¶
Makes a copy of this range
getLength() : number¶
Gets the length of this range, that is the difference between the maximum and minimum value of this range
getCenter() : number¶
Gets the center of this range, that is the average value of the maximum and minimum value of this range
contains( value : number ) : boolean¶
Determines if this range contains the value
containsRange( range : Range ) : boolean¶
Does this range contain the specified range?
intersects( range : Range ) : boolean¶
Determine if this range overlaps (intersects) with another range
intersectsExclusive( range : Range ) : boolean¶
Do the two ranges overlap with one another? Note that this assumes that This is a open interval.
union( range : Range ) : Range¶
REVIEW: The naming is not helping me understand that this function is just the immutable version of includeRange().
The smallest range that contains both this range and the input range, returned as a copy.
The method below is the immutable form of the function includeRange(). The method will return a new range, and will not modify this range.
intersection( range : Range ) : Range¶
REVIEW: The naming is not helping me understand that this function is just the immutable version of constrainRange().
The smallest range that is contained by both this range and the input range, returned as a copy.
The method below the immutable form of the function constrainRange(). The method below will return a new range, and will not modify this range.
includeRange( range : Range ) : Range¶
Modifies this range so that it contains both its original range and the input range.
This is the mutable form of the function union(). This will mutate (change) this range, in addition to returning this range itself.
constrainRange( range : Range ) : Range¶
Modifies this range so that it is the largest range contained both in its original range and in the input range.
This is the mutable form of the function intersection(). This will mutate (change) this range, in addition to returning this range itself.
shifted( n : number ) : Range¶
REVIEW: do we also need a mutable form of shifted?
Returns a new range that is the same as this range, but shifted by the specified amount.
toString() : string¶
Converts the attributes of this range to a string
constrainValue( value : number ) : number¶
Constrains a value to the range.
times( value : number ) : Range¶
Multiply the min and max by the provided value, immutable
multiply( value : number ) : this¶
Multiply the min and max by the provided value, mutable
equals( object : IntentionalAny ) : boolean¶
Determines if this Range is equal to some object.
equalsEpsilon( object : IntentionalAny, epsilon : number ) : boolean¶
Determines if this Range is approximately equal to some object.
getNormalizedValue( value : number ) : number¶
Given a value, normalize it to this Range's length, returning a value between 0 and 1 for values contained in the Range. If the value is not contained in Range, then the return value will not be between 0 and 1.
expandNormalizedValue( normalizedValue : number ) : number¶
Compute the opposite of a normalized value. Given a normalized value (between 0 and 1). Worked with any number though, (even outside of the range). It is the client's responsibility to clamp if that is important to the usage.
toStateObject() : RangeStateObject¶
clampDelta( value : number, delta : number ) : number¶
Given a value and a delta to change that value, clamp the delta to make sure the value stays within range.
Static Methods¶
fromStateObject( stateObject : RangeStateObject ) : Range¶
Static Properties¶
RangeIO : IOType¶
EVERYTHING : Range¶
(readonly)
NOTHING : Range¶
(readonly)
Type RangeStateObject¶
StateObject<typeof STATE_SCHEMA>
Type TRange¶
- min: number
- max: number