Skip to content

Commit

Permalink
change GeometricOpticsRuler constructor signature, #263
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Dec 7, 2021
1 parent b75aaeb commit cdd7376
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
18 changes: 10 additions & 8 deletions js/common/model/GeometricOpticsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,17 @@ class GeometricOpticsModel {
options.barrier
);

this.horizontalRuler = new GeometricOpticsRuler( 'horizontal',
GeometricOpticsConstants.HORIZONTAL_RULER_INITIAL_POSITION,
GeometricOpticsConstants.HORIZONTAL_RULER_LENGTH
);
this.horizontalRuler = new GeometricOpticsRuler( {
orientation: 'horizontal',
position: GeometricOpticsConstants.HORIZONTAL_RULER_INITIAL_POSITION,
length: GeometricOpticsConstants.HORIZONTAL_RULER_LENGTH
} );

this.verticalRuler = new GeometricOpticsRuler( 'vertical',
GeometricOpticsConstants.VERTICAL_RULER_INITIAL_POSITION,
GeometricOpticsConstants.VERTICAL_RULER_LENGTH
);
this.verticalRuler = new GeometricOpticsRuler( {
orientation: 'vertical',
position: GeometricOpticsConstants.VERTICAL_RULER_INITIAL_POSITION,
length: GeometricOpticsConstants.VERTICAL_RULER_LENGTH
} );
}

public reset(): void {
Expand Down
23 changes: 14 additions & 9 deletions js/common/model/GeometricOpticsRuler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import Property from '../../../../axon/js/Property.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import Vector2Property from '../../../../dot/js/Vector2Property.js';
import merge from '../../../../phet-core/js/merge.js';
import geometricOptics from '../../geometricOptics.js';

type RulerOrientation = 'horizontal' | 'vertical';
Expand All @@ -34,21 +35,25 @@ class GeometricOpticsRuler {
readonly visibleProperty: BooleanProperty;

/**
* @param orientation
* @param position - position of the ruler in VIEW Coordinates
* @param length - length of the ruler in cm
* @param options
*/
constructor( orientation: RulerOrientation, position: Vector2, length: number ) {
constructor( options?: any ) {

assert && assert( isFinite( length ) && length > 0 );
options = merge( {
orientation: 'horizontal',
position: Vector2.ZERO,
length: 100
}, options );

this.orientation = orientation;
assert && assert( isFinite( options.length ) && options.length > 0 );

this.orientation = options.orientation;
this.isVertical = ( this.orientation === 'vertical' );

this.positionProperty = new Vector2Property( position );
this.positionProperty = new Vector2Property( options.position );

this.length = length;
this.nominalLength = length;
this.length = options.length;
this.nominalLength = options.length;

this.visibleProperty = new BooleanProperty( false );
}
Expand Down

0 comments on commit cdd7376

Please sign in to comment.