Skip to content

Commit

Permalink
change isVertical from method to field, #263
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Dec 7, 2021
1 parent eb6a696 commit d8f3563
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions js/common/model/Ruler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Ruler {

// orientation of the ruler
private readonly orientation: RulerOrientation;
readonly isVertical: boolean;

// position of the ruler, in view coordinates
//TODO change this to model coordinates
Expand All @@ -42,9 +43,13 @@ class Ruler {
assert && assert( isFinite( length ) && length > 0 );

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

this.positionProperty = new Vector2Property( position );

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

this.visibleProperty = new BooleanProperty( false );
}

Expand All @@ -61,13 +66,6 @@ class Ruler {
assert && assert( isFinite( zoomScale ) && zoomScale > 0 );
this.length = this.nominalLength / zoomScale;
}

/**
* Is the ruler vertical?
*/
public isVertical(): boolean {
return ( this.orientation === 'vertical' );
}
}

geometricOptics.register( 'Ruler', Ruler );
Expand Down
8 changes: 4 additions & 4 deletions js/common/view/GeometricOpticsRulerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class GeometricOpticsRulerNode extends Node {
assert && assert( !options.children, 'this Node calls removeAllChildren' );

assert && assert( options.rulerOptions.tickMarksOnBottom === undefined );
options.tickMarksOnBottom = ruler.isVertical();
options.tickMarksOnBottom = ruler.isVertical;

assert && assert( options.rotation === undefined );
options.rotation = ruler.isVertical() ? -Math.PI / 2 : 0;
options.rotation = ruler.isVertical ? -Math.PI / 2 : 0;

assert && assert( !options.visibleProperty );
options.visibleProperty = ruler.visibleProperty;
Expand All @@ -85,7 +85,7 @@ class GeometricOpticsRulerNode extends Node {
} );

ruler.positionProperty.link( position => {
if ( this.ruler.isVertical() ) {
if ( this.ruler.isVertical ) {
this.leftBottom = position;
}
else {
Expand All @@ -97,7 +97,7 @@ class GeometricOpticsRulerNode extends Node {
const rulerDragBoundsProperty = new DerivedProperty<Bounds2>(
[ visibleBoundsProperty ],
( visibleBounds: Bounds2 ) => {
if ( ruler.isVertical() ) {
if ( ruler.isVertical ) {

// if vertical the left and right bounds of the ruler stay within visible bounds
// minimum visible length of the ruler is always showing inside top and bottom visible bounds.
Expand Down

0 comments on commit d8f3563

Please sign in to comment.