Skip to content

Commit

Permalink
rename location to position, phetsims/phet-info#126
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jan 7, 2020
1 parent 78f4106 commit 58caf37
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 82 deletions.
12 changes: 6 additions & 6 deletions js/common/model/Beaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ define( require => {

/**
* Constructor
* @param {Vector2} location bottom center
* @param {Vector2} position bottom center
* @param {Dimension2} size
* @param {Object} [options]
* @constructor
*/
function Beaker( location, size, options ) {
function Beaker( position, size, options ) {

options = merge( {
volume: 1.2 // L
}, options );

// @Public
this.location = location;
this.position = position;
this.size = size;
this.volume = options.volume;

// @public convenience properties
this.left = location.x - ( size.width / 2 );
this.right = location.x + ( size.width / 2 );
this.bounds = new Bounds2( this.left, location.y - size.height, this.right, location.y );
this.left = position.x - ( size.width / 2 );
this.right = position.x + ( size.width / 2 );
this.bounds = new Bounds2( this.left, position.y - size.height, this.right, position.y );
}

phScale.register( 'Beaker', Beaker );
Expand Down
6 changes: 3 additions & 3 deletions js/common/model/Dropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ define( require => {

/**
* @param {Solute} solute
* @param {Vector2} location
* @param {Vector2} position
* @param {Bounds2} dragBounds
* @param {Object} [options]
* @constructor
*/
function Dropper( solute, location, dragBounds, options ) {
function Dropper( solute, position, dragBounds, options ) {

options = merge( {
maxFlowRate: 0.05, // L/sec
Expand All @@ -36,7 +36,7 @@ define( require => {
}, options );

const self = this;
Movable.call( this, location, dragBounds );
Movable.call( this, position, dragBounds );

// @public
this.soluteProperty = new Property( solute );
Expand Down
6 changes: 3 additions & 3 deletions js/common/model/Faucet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ define( require => {
const phScale = require( 'PH_SCALE/phScale' );

/**
* @param {Vector2} location center of output pipe
* @param {Vector2} position center of output pipe
* @param {number} pipeMinX x-coordinate of where the pipe starts
* @param {Object} [options]
* @constructor
*/
function Faucet( location, pipeMinX, options ) {
function Faucet( position, pipeMinX, options ) {

options = merge( {
spoutWidth: 45, // pixels
Expand All @@ -32,7 +32,7 @@ define( require => {
}, options );

// @public
this.location = location;
this.position = position;
this.pipeMinX = pipeMinX;
this.spoutWidth = options.spoutWidth;
this.maxFlowRate = options.maxFlowRate;
Expand Down
8 changes: 4 additions & 4 deletions js/common/model/Movable.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ define( require => {
const Property = require( 'AXON/Property' );

/**
* @param {Vector2} location
* @param {Vector2} position
* @param {Bounds2} dragBounds optional, undefined if not provided
* @constructor
*/
function Movable( location, dragBounds ) {
function Movable( position, dragBounds ) {

// @public
this.locationProperty = new Property( location );
this.positionProperty = new Property( position );
this.dragBounds = dragBounds;
}

Expand All @@ -32,7 +32,7 @@ define( require => {

// @public
reset: function() {
this.locationProperty.reset();
this.positionProperty.reset();
}
} );
} );
2 changes: 1 addition & 1 deletion js/common/view/BeakerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ define( require => {
}
}

this.translation = modelViewTransform.modelToViewPosition( beaker.location );
this.translation = modelViewTransform.modelToViewPosition( beaker.position );
}

phScale.register( 'BeakerNode', BeakerNode );
Expand Down
4 changes: 2 additions & 2 deletions js/common/view/DrainFaucetNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define( require => {

const scale = 0.6;

const horizontalPipeLength = Math.abs( modelViewTransform.modelToViewX( faucet.location.x - faucet.pipeMinX ) ) / scale;
const horizontalPipeLength = Math.abs( modelViewTransform.modelToViewX( faucet.position.x - faucet.pipeMinX ) ) / scale;
FaucetNode.call( this, faucet.maxFlowRate, faucet.flowRateProperty, faucet.enabledProperty, {
horizontalPipeLength: horizontalPipeLength,
verticalPipeLength: 5,
Expand All @@ -34,7 +34,7 @@ define( require => {
touchAreaYDilation: 60
}
} );
this.translation = modelViewTransform.modelToViewPosition( faucet.location );
this.translation = modelViewTransform.modelToViewPosition( faucet.position );
this.setScaleMagnitude( -scale, scale ); // reflect horizontally
}

Expand Down
14 changes: 7 additions & 7 deletions js/common/view/DropperFluidNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ define( require => {
const self = this;
Rectangle.call( this, 0, 0, 0, 0, { lineWidth: 1 } );

// shape and location
const updateShapeAndLocation = function() {
// shape and position
const updateShapeAndPosition = function() {
// path
if ( dropper.flowRateProperty.get() > 0 ) {
self.setRect( -tipWidth / 2, 0, tipWidth, beaker.location.y - dropper.locationProperty.get().y );
self.setRect( -tipWidth / 2, 0, tipWidth, beaker.position.y - dropper.positionProperty.get().y );
}
else {
self.setRect( 0, 0, 0, 0 );
}
// move this node to the dropper's location
self.translation = modelViewTransform.modelToViewPosition( dropper.locationProperty.get() );
// move this node to the dropper's position
self.translation = modelViewTransform.modelToViewPosition( dropper.positionProperty.get() );
};
dropper.locationProperty.link( updateShapeAndLocation );
dropper.flowRateProperty.link( updateShapeAndLocation );
dropper.positionProperty.link( updateShapeAndPosition );
dropper.flowRateProperty.link( updateShapeAndPosition );

// set color to match solute
dropper.soluteProperty.link( function( solute ) {
Expand Down
6 changes: 3 additions & 3 deletions js/common/view/FaucetFluidNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ define( require => {
* Set the width of the shape to match the flow rate.
* @param {number} flowRate
*/
const viewLocation = modelViewTransform.modelToViewPosition( faucet.location );
const viewPosition = modelViewTransform.modelToViewPosition( faucet.position );
const viewHeight = modelViewTransform.modelToViewDeltaY( height );
faucet.flowRateProperty.link( function( flowRate ) {
if ( flowRate === 0 ) {
self.setRect( -1, -1, 0, 0 ); // empty rectangle, at a location where we won't intersect with it
self.setRect( -1, -1, 0, 0 ); // empty rectangle, at a position where we won't intersect with it
}
else {
const viewWidth = modelViewTransform.modelToViewDeltaX( faucet.spoutWidth * flowRate / faucet.maxFlowRate );
self.setRect( viewLocation.x - (viewWidth / 2), viewLocation.y, viewWidth, viewHeight );
self.setRect( viewPosition.x - (viewWidth / 2), viewPosition.y, viewWidth, viewHeight );
}
} );
}
Expand Down
8 changes: 4 additions & 4 deletions js/common/view/PHDropperNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ define( require => {
emptyProperty: dropper.emptyProperty
}, options ) );

// location
dropper.locationProperty.link( function( location ) {
self.translation = modelViewTransform.modelToViewPosition( location );
// position
dropper.positionProperty.link( function( position ) {
self.translation = modelViewTransform.modelToViewPosition( position );
} );

// visibility
Expand All @@ -53,7 +53,7 @@ define( require => {
this.touchArea = this.localBounds.dilatedX( 0.25 * this.width );

// move the dropper
this.addInputListener( new MovableDragHandler( dropper.locationProperty, {
this.addInputListener( new MovableDragHandler( dropper.positionProperty, {
dragBounds: dropper.dragBounds,
modelViewTransform: modelViewTransform
} ) );
Expand Down
4 changes: 2 additions & 2 deletions js/common/view/SolutionNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define( require => {
* Updates the amount of stuff in the beaker, based on solution volume.
* @param {number} volume
*/
const viewLocation = modelViewTransform.modelToViewPosition( beaker.location );
const viewPosition = modelViewTransform.modelToViewPosition( beaker.position );
const viewWidth = modelViewTransform.modelToViewDeltaX( beaker.size.width );
solution.volumeProperty.link( function( volume ) {
assert && assert( volume >= 0 );
Expand All @@ -58,7 +58,7 @@ define( require => {
const viewHeight = modelViewTransform.modelToViewDeltaY( solutionHeight );

// shape
self.setRect( viewLocation.x - (viewWidth / 2), viewLocation.y - viewHeight, viewWidth, viewHeight );
self.setRect( viewPosition.x - (viewWidth / 2), viewPosition.y - viewHeight, viewWidth, viewHeight );
} );
}

Expand Down
8 changes: 5 additions & 3 deletions js/common/view/VolumeIndicatorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@ define( require => {
this.addChild( valueNode );
this.addChild( arrowHead );

// x location
// x position
this.left = modelViewTransform.modelToViewX( beaker.right ) + 3;

// update when the volume changes
const self = this;
volumeProperty.link( function( volume ) {

// text
valueNode.text = StringUtils.format( pattern0Value1UnitsString, Utils.toFixed( volume, PHScaleConstants.VOLUME_DECIMAL_PLACES ), unitsLitersString );
valueNode.centerY = arrowHead.centerY;
// y-location

// y position
const solutionHeight = Utils.linear( 0, beaker.volume, 0, beaker.size.height, volume ); // volume -> height, model coordinates
self.y = modelViewTransform.modelToViewY( beaker.location.y - solutionHeight );
self.y = modelViewTransform.modelToViewY( beaker.position.y - solutionHeight );
} );
}

Expand Down
4 changes: 2 additions & 2 deletions js/common/view/WaterFaucetNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define( require => {

const scale = 0.6;

const horizontalPipeLength = Math.abs( modelViewTransform.modelToViewX( faucet.location.x - faucet.pipeMinX ) ) / scale;
const horizontalPipeLength = Math.abs( modelViewTransform.modelToViewX( faucet.position.x - faucet.pipeMinX ) ) / scale;
const faucetNode = new FaucetNode( faucet.maxFlowRate, faucet.flowRateProperty, faucet.enabledProperty, {
horizontalPipeLength: horizontalPipeLength,
verticalPipeLength: 20,
Expand All @@ -40,7 +40,7 @@ define( require => {
touchAreaYDilation: 60
}
} );
faucetNode.translation = modelViewTransform.modelToViewPosition( faucet.location );
faucetNode.translation = modelViewTransform.modelToViewPosition( faucet.position );
faucetNode.setScaleMagnitude( -scale, scale ); // reflect horizontally
this.addChild( faucetNode );

Expand Down
24 changes: 12 additions & 12 deletions js/common/view/graph/GraphIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* The indicator that points to a value on a graph's vertical scale.
* Origin is at the indicator's pointer, and the pointer can be attached to any corner of the indicator (see options.pointerLocation).
* Origin is at the indicator's pointer, and the pointer can be attached to any corner of the indicator (see options.pointerPosition).
* Interactive indicators are decorated with a double-headed arrow, indicating the direction of dragging.
*
* @author Chris Malley (PixelZoom, Inc.)
Expand Down Expand Up @@ -44,7 +44,7 @@ define( require => {

options = merge( {
scale: 0.75, // specified by design team
pointerLocation: 'topRight', // values: topLeft, topRight, bottomLeft, bottomRight
pointerPosition: 'topRight', // values: topLeft, topRight, bottomLeft, bottomRight
backgroundFill: 'white',
backgroundWidth: 160,
backgroundHeight: 80,
Expand All @@ -68,20 +68,20 @@ define( require => {

// Transform shapes to support various orientations of pointer.
let shapeMatrix;
if ( options.pointerLocation === 'topRight' ) {
if ( options.pointerPosition === 'topRight' ) {
shapeMatrix = Matrix3.identity(); // background shape will be drawn with pointer at top-right
}
else if ( options.pointerLocation === 'topLeft' ) {
else if ( options.pointerPosition === 'topLeft' ) {
shapeMatrix = Matrix3.scaling( -1, 1 );
}
else if ( options.pointerLocation === 'bottomRight' ) {
else if ( options.pointerPosition === 'bottomRight' ) {
shapeMatrix = Matrix3.scaling( 1, -1 );
}
else if ( options.pointerLocation === 'bottomLeft' ) {
else if ( options.pointerPosition === 'bottomLeft' ) {
shapeMatrix = Matrix3.scaling( -1, -1 );
}
else {
throw new Error( 'unsupported options.pointerLocation: ' + options.pointerLocation );
throw new Error( 'unsupported options.pointerPosition: ' + options.pointerPosition );
}

// Background with the pointer at top-right. Proceed clockwise from the tip of the pointer.
Expand Down Expand Up @@ -134,7 +134,7 @@ define( require => {
this.addChild( moleculeAndFormula );

// layout, relative to backgroundNode
if ( options.pointerLocation === 'topRight' || options.pointerLocation === 'bottomRight' ) {
if ( options.pointerPosition === 'topRight' || options.pointerPosition === 'bottomRight' ) {
valueBackgroundNode.left = backgroundNode.left + options.backgroundXMargin;
}
else {
Expand All @@ -160,7 +160,7 @@ define( require => {
this.addChild( arrowNode );

// put the arrow on opposite side of the indicator's pointer
if ( options.pointerLocation === 'topRight' || options.pointerLocation === 'bottomRight' ) {
if ( options.pointerPosition === 'topRight' || options.pointerPosition === 'bottomRight' ) {
arrowNode.right = backgroundNode.left - options.arrowXSpacing;
}
else {
Expand Down Expand Up @@ -216,7 +216,7 @@ define( require => {
new RichText( PHScaleConstants.H3O_FORMULA, { font: new PhetFont( 28 ), fill: 'white' } ),
merge( {
backgroundFill: PHScaleColors.ACIDIC,
pointerLocation: 'topRight'
pointerPosition: 'topRight'
}, options ) );
},

Expand All @@ -233,7 +233,7 @@ define( require => {
new RichText( PHScaleConstants.OH_FORMULA, { font: new PhetFont( 28 ), fill: 'white', supXSpacing: 2 } ),
merge( {
backgroundFill: PHScaleColors.BASIC,
pointerLocation: 'topLeft'
pointerPosition: 'topLeft'
}, options ) );
},

Expand All @@ -250,7 +250,7 @@ define( require => {
new RichText( PHScaleConstants.H2O_FORMULA, { font: new PhetFont( 28 ), fill: 'white' } ),
merge( {
backgroundFill: PHScaleColors.H2O_BACKGROUND,
pointerLocation: 'bottomLeft',
pointerPosition: 'bottomLeft',
mantissaDecimalPlaces: 0,
exponent: 0
}, options ) );
Expand Down
12 changes: 6 additions & 6 deletions js/macro/model/MacroModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,27 @@ define( require => {
this.beaker = new Beaker( new Vector2( 750, 580 ), new Dimension2( 450, 300 ) );

// Dropper above the beaker
const yDropper = this.beaker.location.y - this.beaker.size.height - 15;
const yDropper = this.beaker.position.y - this.beaker.size.height - 15;
// @public
this.dropper = new Dropper( Solute.WATER,
new Vector2( this.beaker.location.x - 50, yDropper ),
new Vector2( this.beaker.position.x - 50, yDropper ),
new Bounds2( this.beaker.left + 40, yDropper, this.beaker.right - 200, yDropper ) );

// @public Solution in the beaker
this.solution = new Solution( this.dropper.soluteProperty, 0, 0, this.beaker.volume );

// @public Water faucet at the beaker's top-right
this.waterFaucet = new Faucet( new Vector2( this.beaker.right - 50, this.beaker.location.y - this.beaker.size.height - 45 ),
this.waterFaucet = new Faucet( new Vector2( this.beaker.right - 50, this.beaker.position.y - this.beaker.size.height - 45 ),
this.beaker.right + 400,
{ enabled: this.solution.volumeProperty.get() < this.beaker.volume } );

// @public Drain faucet at the beaker's bottom-left.
this.drainFaucet = new Faucet( new Vector2( this.beaker.left - 75, this.beaker.location.y + 43 ), this.beaker.left,
this.drainFaucet = new Faucet( new Vector2( this.beaker.left - 75, this.beaker.position.y + 43 ), this.beaker.left,
{ enabled: this.solution.volumeProperty.get() > 0 } );

// pH meter to the left of the drain faucet
const pHMeterLocation = new Vector2( this.drainFaucet.location.x - 300, 75 );
this.pHMeter = new PHMeter( pHMeterLocation, new Vector2( pHMeterLocation.x + 150, this.beaker.location.y ),
const pHMeterPosition = new Vector2( this.drainFaucet.position.x - 300, 75 );
this.pHMeter = new PHMeter( pHMeterPosition, new Vector2( pHMeterPosition.x + 150, this.beaker.position.y ),
PHScaleConstants.SCREEN_VIEW_OPTIONS.layoutBounds );

// auto-fill when the solute changes
Expand Down
Loading

0 comments on commit 58caf37

Please sign in to comment.