Skip to content

Commit

Permalink
#77 review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Malley <cmalley@pixelzoom.com>
  • Loading branch information
pixelzoom committed Oct 4, 2018
1 parent e42277b commit 7b63a08
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
26 changes: 13 additions & 13 deletions js/Range.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013-2015, University of Colorado Boulder
// Copyright 2013-2018, University of Colorado Boulder

/**
* A numeric range.
Expand All @@ -19,13 +19,13 @@ define( function( require ) {
*/
function Range( min, max ) {

// @public (read-only) - the minimum value of the range
assert && assert( min <= max, 'max must be >= min. min: ' + min + ', max: ' + max );

// @private the minimum value of the range
this._min = min;

// @public (read-only) - the maximum value of the range
// @private the maximum value of the range
this._max = max;

assert && assert( min <= max, 'max must be greater than or equal to min. min: ' + min + ', max: ' + max );
}

dot.register( 'Range', Range );
Expand All @@ -52,7 +52,7 @@ define( function( require ) {
* @param {number} min
*/
setMin: function( min ) {
assert && assert( min <= this._max, 'min must be less than or equal to max: ' + min );
assert && assert( min <= this._max, 'min must be <= max: ' + min );
this._min = min;
},
set min( min ) {
Expand All @@ -77,7 +77,7 @@ define( function( require ) {
* @param {number} max
*/
setMax: function( max ) {
assert && assert( this._min <= max, 'max must be greater than or equal to min: ' + max );
assert && assert( this._min <= max, 'max must be >= to min: ' + max );
this._max = max;
},
set max( max ) {
Expand All @@ -91,7 +91,7 @@ define( function( require ) {
* @param {number} max
*/
setMinMax: function( min, max ) {
assert && assert( min <= max, 'max must be greater than or equal to min. min: ' + min + ', max: ' + max );
assert && assert( min <= max, 'max must be >= to min. min: ' + min + ', max: ' + max );
this._min = min;
this._max = max;
},
Expand Down Expand Up @@ -140,7 +140,7 @@ define( function( require ) {
* @returns {boolean}
*/
containsRange: function( range ) {
return this._min <= range.min && this._max >= range.max;
return ( this._min <= range.min ) && ( this._max >= range.max );
},

/**
Expand Down Expand Up @@ -184,13 +184,13 @@ define( function( require ) {
},

/**
* Determines if this range is equal to other range.
* Determines if this Range is equal to some object.
* @public
* @param {Range} other
* @param {*} object
* @returns {boolean}
*/
equals: function( other ) {
return this._min === other.min && this._max === other.max;
equals: function( object ) {
return ( object instanceof Range ) && ( this._min === object.min ) && ( this._max === object.max );
}
};

Expand Down
33 changes: 14 additions & 19 deletions js/RangeWithValue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013-2015, University of Colorado Boulder
// Copyright 2013-2018, University of Colorado Boulder

/**
* A numeric range with an optional default value.
Expand All @@ -19,17 +19,15 @@ define( function( require ) {
* @param {number} [defaultValue] - default value inside the range
* @constructor
*/

function RangeWithValue( min, max, defaultValue ) {

Range.call( this, min, max );
defaultValue = ( defaultValue === undefined ) ? min : defaultValue;
assert && assert( defaultValue >= min && defaultValue <= max, 'defaultValue out of range: ' + defaultValue );

// @private - the default value of the range
this._defaultValue = ( defaultValue === undefined ) ? min : defaultValue;
Range.call( this, min, max );

assert && assert( this._defaultValue >= min && this._defaultValue <= max,
'Default value must be less than or equal to max and greater than or equal to min: ' + this._defaultValue
);
// @private
this._defaultValue = defaultValue;
}

dot.register( 'RangeWithValue', RangeWithValue );
Expand All @@ -38,7 +36,6 @@ define( function( require ) {

/**
* Getter for defaultValue
*
* @returns {number}
* @public
*/
Expand All @@ -56,7 +53,7 @@ define( function( require ) {
* @override
*/
setMin: function( min ) {
assert && assert( this._defaultValue >= min, 'min must be less than or equal to default value: ' + min );
assert && assert( this._defaultValue >= min, 'min must be <= defaultValue: ' + min );
Range.prototype.setMin.call( this, min );
},

Expand All @@ -67,7 +64,7 @@ define( function( require ) {
* @override
*/
setMax: function( max ) {
assert && assert( this._defaultValue <= max, 'max must be greater than or equal to default value: ' + max );
assert && assert( this._defaultValue <= max, 'max must be >= defaultValue: ' + max );
Range.prototype.setMax.call( this, max );
},

Expand All @@ -82,18 +79,16 @@ define( function( require ) {
},

/**
* Determines if this range is equal to other range.
* Note the default values must match as well.
* Determines if this RangeWithValue is equal to some object.
* @public
* @param {Range} other
* @param {*} object
* @returns {boolean}
* @override
*/
equals: function( other ) {
return other instanceof RangeWithValue &&
this.min === other.min &&
this.max === other.max &&
this._defaultValue === other.defaultValue;
equals: function( object ) {
return ( object instanceof RangeWithValue ) &&
( this._defaultValue === object.defaultValue ) &&
Range.prototype.equals.call( this, object );
}
} );
} );
Expand Down

0 comments on commit 7b63a08

Please sign in to comment.