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 02f079b commit 59482fe
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 82 deletions.
6 changes: 3 additions & 3 deletions js/common/model/Atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ define( require => {
options = merge( {
diameter: MPConstants.ATOM_DIAMETER, // {number} the atom's diameter
color: 'white', // {Color|string} base color of the atom
location: new Vector2( 0, 0 ), // initial location
position: new Vector2( 0, 0 ), // initial position
electronegativity: MPConstants.ELECTRONEGATIVITY_RANGE.min // {number}
}, options );

Expand All @@ -38,7 +38,7 @@ define( require => {
this.name = name;
this.diameter = options.diameter;
this.color = options.color;
this.locationProperty = new Property( options.location );
this.positionProperty = new Property( options.position );
this.electronegativityProperty = new NumberProperty( options.electronegativity );
this.partialChargeProperty = new NumberProperty( 0 ); // partial charge is zero until this atom participates in a bond
}
Expand All @@ -51,7 +51,7 @@ define( require => {
reset: function() {
this.electronegativityProperty.reset();

// Do not reset location and partial charge, they will be reset by their parent molecule.
// Do not reset position and partial charge, they will be reset by their parent molecule.
}
} );
} );
12 changes: 6 additions & 6 deletions js/common/model/Bond.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ define( require => {

// @public dispose not needed, exists for the lifetime of the sim
this.dipoleProperty = new DerivedProperty( [
atom1.locationProperty, atom2.locationProperty,
atom1.positionProperty, atom2.positionProperty,
atom1.electronegativityProperty, atom2.electronegativityProperty,
MPConstants.GLOBAL_OPTIONS.dipoleDirectionProperty
],
function( location1, location2, electronegativity1, electronegativity2, dipoleDirection ) {
function( position1, position2, electronegativity1, electronegativity2, dipoleDirection ) {

const deltaEN = electronegativity2 - electronegativity1;

Expand Down Expand Up @@ -65,12 +65,12 @@ define( require => {
return inherit( Object, Bond, {

/**
* Gets the center of the bond, the midpoint between the 2 atom locations.
* Gets the center of the bond, the midpoint between the 2 atom positions.
* @returns {Vector2}
* @public
*/
getCenter: function() {
return this.atom1.locationProperty.get().average( this.atom2.locationProperty.get() );
return this.atom1.positionProperty.get().average( this.atom2.positionProperty.get() );
},

/**
Expand All @@ -80,7 +80,7 @@ define( require => {
*/
getAngle: function() {
const center = this.getCenter();
return Math.atan2( this.atom2.locationProperty.get().y - center.y, this.atom2.locationProperty.get().x - center.x );
return Math.atan2( this.atom2.positionProperty.get().y - center.y, this.atom2.positionProperty.get().x - center.x );
},

/**
Expand All @@ -89,7 +89,7 @@ define( require => {
* @public
*/
getLength: function() {
return this.atom1.locationProperty.get().distance( this.atom2.locationProperty.get() );
return this.atom1.positionProperty.get().distance( this.atom2.positionProperty.get() );
}
} );
} );
20 changes: 10 additions & 10 deletions js/common/model/Molecule.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ define( require => {
/**
* @param {Atom[]} atoms - atoms that make up the molecule
* @param {Bond[]} bonds - bonds between the atoms
* @param {function} updateAtomLocations - repositions the atoms (no arguments, no return value)
* @param {function} updateAtomPositions - repositions the atoms (no arguments, no return value)
* @param {function} updatePartialCharges - updates the partial charges (no arguments, no return value)
* @param {Object} [options]
* @constructor
* @abstract
*/
function Molecule( atoms, bonds, updateAtomLocations, updatePartialCharges, options ) {
function Molecule( atoms, bonds, updateAtomPositions, updatePartialCharges, options ) {

options = merge( {
location: new Vector2( 0, 0 ), // the point about which the molecule rotates, in global model coordinate frame
angle: 0 // angle of rotation of the entire molecule about the location, in radians
position: new Vector2( 0, 0 ), // the point about which the molecule rotates, in global model coordinate frame
angle: 0 // angle of rotation of the entire molecule about the position, in radians
}, options );

const self = this;

// @public (read-only)
this.location = options.location; // the point about which the molecule rotates, in global model coordinate frame
this.position = options.position; // the point about which the molecule rotates, in global model coordinate frame
this.atoms = atoms;
this.bonds = bonds;

// @public
this.angleProperty = new NumberProperty( options.angle ); // angle of rotation about the location, in radians
this.angleProperty = new NumberProperty( options.angle ); // angle of rotation about the position, in radians
this.dragging = false; // true when the user is dragging the molecule

// update atom locations when molecule is rotated
this.angleProperty.link( updateAtomLocations.bind( this ) ); // unlink not needed
// update atom positions when molecule is rotated
this.angleProperty.link( updateAtomPositions.bind( this ) ); // unlink not needed

// bond dipoles, for deriving molecular dipole
const bondDipoleProperties = [];
Expand Down Expand Up @@ -79,12 +79,12 @@ define( require => {
},

/**
* Creates a transform that accounts for the molecule's location and orientation.
* Creates a transform that accounts for the molecule's position and orientation.
* @returns {Matrix3}
* @public
*/
createTransformMatrix: function() {
return Matrix3.translationFromVector( this.location ).timesMatrix( Matrix3.rotation2( this.angleProperty.get() ) );
return Matrix3.translationFromVector( this.position ).timesMatrix( Matrix3.rotation2( this.angleProperty.get() ) );
}
} );
} );
4 changes: 2 additions & 2 deletions js/common/view/AtomNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ define( require => {
children: [ sphereNode, textNode ]
} );

// sync location with model, unlink not needed
atom.locationProperty.linkAttribute( this, 'translation' );
// sync position with model, unlink not needed
atom.positionProperty.linkAttribute( this, 'translation' );
}

moleculePolarity.register( 'AtomNode', AtomNode );
Expand Down
6 changes: 3 additions & 3 deletions js/common/view/BondDipoleNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ define( require => {
const isInPhase = Math.abs( bondAngle - dipole.angle ) < ( Math.PI / 4 );
const dipoleViewLength = dipole.magnitude * ( self.referenceLength / self.referenceMagnitude );

// location of tail in polar coordinates, relative to center of bond
// position of tail in polar coordinates, relative to center of bond
const offsetX = isInPhase ? ( dipoleViewLength / 2 ) : -( dipoleViewLength / 2 );
const offsetAngle = Math.atan( offsetX / PERPENDICULAR_OFFSET );
const tailDistance = PERPENDICULAR_OFFSET / Math.cos( offsetAngle );
const tailAngle = bondAngle - ( Math.PI / 2 ) - offsetAngle;

// location of tail in Cartesian coordinates, relative to center of bond
// position of tail in Cartesian coordinates, relative to center of bond
const tailX = tailDistance * Math.cos( tailAngle );
const tailY = tailDistance * Math.sin( tailAngle );

// location of tail in global coordinate frame
// position of tail in global coordinate frame
self.translation = bond.getCenter().plusXY( tailX, tailY );
} );
}
Expand Down
8 changes: 4 additions & 4 deletions js/common/view/BondNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Visual representation of a bond between 2 atoms.
* Intended to be rendered before the 2 atoms, so that the atoms cover the portion of the bond that overlaps the atoms.
* Shapes are created in global coordinates, so this node's location should be (0,0).
* Shapes are created in global coordinates, so this node's position should be (0,0).
* Clients should not attempt to position this node.
*
* @author Chris Malley (PixelZoom, Inc.)
Expand All @@ -25,15 +25,15 @@ define( require => {

const self = this;

Line.call( this, bond.atom1.locationProperty.get(), bond.atom2.locationProperty.get(), {
Line.call( this, bond.atom1.positionProperty.get(), bond.atom2.positionProperty.get(), {
stroke: MPColors.BOND,
lineWidth: 12,
strokePickable: true // include stroke in hit-testing
} );

// adjust the bond when its endpoints change, unlinks not needed
bond.atom1.locationProperty.link( function( location ) { self.setPoint1( location ); } );
bond.atom2.locationProperty.link( function( location ) { self.setPoint2( location ); } );
bond.atom1.positionProperty.link( function( position ) { self.setPoint1( position ); } );
bond.atom2.positionProperty.link( function( position ) { self.setPoint2( position ); } );
}

moleculePolarity.register( 'BondNode', BondNode );
Expand Down
6 changes: 3 additions & 3 deletions js/common/view/MolecularDipoleNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ define( require => {

DipoleNode.call( this, molecule.dipoleProperty, MPColors.MOLECULAR_DIPOLE );

// position the dipole with some radial offset from the molecule's location, unlink not needed
// position the dipole with some radial offset from the molecule's position, unlink not needed
const self = this;
molecule.dipoleProperty.link( function( dipole ) {

// offset vector relative to molecule location
// offset vector relative to molecule position
const v = Vector2.createPolar( OFFSET, dipole.angle );

// offset in global coordinate frame
self.translation = molecule.location.plus( v );
self.translation = molecule.position.plus( v );
} );
}

Expand Down
2 changes: 1 addition & 1 deletion js/common/view/MoleculeAngleDragHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define( require => {
*/
const getAngle = function( event ) {
const point = relativeNode.globalToParentPoint( event.pointer.point );
return new Vector2( point.x - molecule.location.x, point.y - molecule.location.y ).angle;
return new Vector2( point.x - molecule.position.x, point.y - molecule.position.y ).angle;
};

SimpleDragHandler.call( this, {
Expand Down
8 changes: 4 additions & 4 deletions js/common/view/PartialChargeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ define( require => {
// Compute the amount to move the partial charge node
const multiplier = ( atom.diameter / 2 ) + ( Math.max( self.width, self.height ) / 2 ) + 3;
const relativeOffset = unitVector.timesScalar( multiplier );
self.translation = atom.locationProperty.get().plus( relativeOffset );
self.translation = atom.positionProperty.get().plus( relativeOffset );
}
};

atom.partialChargeProperty.link( this.update.bind( this ) ); // unlink not needed
atom.locationProperty.link( this.update.bind( this ) ); // unlink not needed
atom.positionProperty.link( this.update.bind( this ) ); // unlink not needed
}

moleculePolarity.register( 'PartialChargeNode', PartialChargeNode );
Expand Down Expand Up @@ -109,10 +109,10 @@ define( require => {
return new PartialChargeNode( atom, function() {

// along the bond axis, in the direction of the atom
let v = atom.locationProperty.get().minus( bond.getCenter() );
let v = atom.positionProperty.get().minus( bond.getCenter() );

/*
* Avoid the case where pressing Reset All causes the atoms to swap locations, temporarily resulting
* Avoid the case where pressing Reset All causes the atoms to swap positions, temporarily resulting
* in a zero-magnitude vector when the first atom has moved but the second atom hasn't moved yet.
* This sorts itself out when both atoms have moved.
*/
Expand Down
10 changes: 5 additions & 5 deletions js/common/view/TranslateArrowsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* A pair of arrows that are placed around an atom to indicate that the atom can be translated.
* Shapes are created in global coordinates, so this node's location should be (0,0).
* Shapes are created in global coordinates, so this node's position should be (0,0).
*
* @author Chris Malley (PixelZoom, Inc.)
*/
Expand Down Expand Up @@ -45,12 +45,12 @@ define( require => {
options.children = [ leftArrowNode, rightArrowNode ];

// unlink not needed
atom.locationProperty.link( function() {
atom.positionProperty.link( function() {

// transform the arrow shapes to account for atom location and relationship to molecule location
const v = molecule.location.minus( atom.locationProperty.get() );
// transform the arrow shapes to account for atom position and relationship to molecule position
const v = molecule.position.minus( atom.positionProperty.get() );
const angle = v.angle - ( Math.PI / 2 );
const transform = new Transform3( Matrix3.translationFromVector( atom.locationProperty.get() ).timesMatrix( Matrix3.rotation2( angle ) ) );
const transform = new Transform3( Matrix3.translationFromVector( atom.positionProperty.get() ).timesMatrix( Matrix3.rotation2( angle ) ) );
leftArrowNode.shape = transform.transformShape( leftArrow );
rightArrowNode.shape = transform.transformShape( rightArrow );
} );
Expand Down
2 changes: 1 addition & 1 deletion js/threeatoms/model/ThreeAtomsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define( require => {
* @constructor
*/
function ThreeAtomsModel() {
MPModel.call( this, new TriatomicMolecule( { location: new Vector2( 400, 280 ) } ) );
MPModel.call( this, new TriatomicMolecule( { position: new Vector2( 400, 280 ) } ) );
}

moleculePolarity.register( 'ThreeAtomsModel', ThreeAtomsModel );
Expand Down
24 changes: 12 additions & 12 deletions js/threeatoms/model/TriatomicMolecule.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ define( require => {
Molecule.call( this,
[ this.atomA, this.atomB, this.atomC ],
[ this.bondAB, this.bondBC ],
this.updateAtomLocations,
this.updateAtomPositions,
this.updatePartialCharges,
options );

// unlinks not needed
this.bondAngleAProperty.link( this.updateAtomLocations.bind( this ) );
this.bondAngleCProperty.link( this.updateAtomLocations.bind( this ) );
this.bondAngleAProperty.link( this.updateAtomPositions.bind( this ) );
this.bondAngleCProperty.link( this.updateAtomPositions.bind( this ) );
}

moleculePolarity.register( 'TriatomicMolecule', TriatomicMolecule );
Expand All @@ -72,14 +72,14 @@ define( require => {
*
* @param {Atom} atom the atom to reposition
* @param {number} bondAngle the angle of the bond that the atom participates in
* @param {Vector2 location location of the molecule
* @param {Vector2 position position of the molecule
* @param {number} angle orientation of the molecule
*/
const updateAtomLocation = function( atom, bondAngle, location, angle ) {
const updateAtomPosition = function( atom, bondAngle, position, angle ) {
const thetaA = angle + bondAngle;
const xA = ( MPConstants.BOND_LENGTH * Math.cos( thetaA ) ) + location.x;
const yA = ( MPConstants.BOND_LENGTH * Math.sin( thetaA ) ) + location.y;
atom.locationProperty.set( new Vector2( xA, yA ) );
const xA = ( MPConstants.BOND_LENGTH * Math.cos( thetaA ) ) + position.x;
const yA = ( MPConstants.BOND_LENGTH * Math.sin( thetaA ) ) + position.y;
atom.positionProperty.set( new Vector2( xA, yA ) );
};

return inherit( Molecule, TriatomicMolecule, {
Expand All @@ -98,10 +98,10 @@ define( require => {
* Repositions the atoms.
* @private
*/
updateAtomLocations: function() {
this.atomB.locationProperty.set( this.location ); // atom B remains at the molecule's location
updateAtomLocation( this.atomA, this.bondAngleAProperty.get(), this.location, this.angleProperty.get() );
updateAtomLocation( this.atomC, this.bondAngleCProperty.get(), this.location, this.angleProperty.get() );
updateAtomPositions: function() {
this.atomB.positionProperty.set( this.position ); // atom B remains at the molecule's position
updateAtomPosition( this.atomA, this.bondAngleAProperty.get(), this.position, this.angleProperty.get() );
updateAtomPosition( this.atomC, this.bondAngleCProperty.get(), this.position, this.angleProperty.get() );
},

/**
Expand Down
4 changes: 2 additions & 2 deletions js/threeatoms/view/BondAngleDragHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ define( require => {
let previousAngle = 0;

/**
* Finds the angle about the molecule's location.
* Finds the angle about the molecule's position.
* @param {SceneryEvent} event
* @returns {number} angle in radians
*/
const getAngle = function( event ) {
const point = event.currentTarget.getParent().globalToLocalPoint( event.pointer.point );
return new Vector2( point.x - molecule.location.x, point.y - molecule.location.y ).angle;
return new Vector2( point.x - molecule.position.x, point.y - molecule.position.y ).angle;
};

SimpleDragHandler.call( this, {
Expand Down
8 changes: 4 additions & 4 deletions js/threeatoms/view/RotateArrowsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* A pair of arrows used to indicate that an arrow can be rotated.
* Shapes are created in global coordinates, so this node's location should be (0,0).
* Shapes are created in global coordinates, so this node's position should be (0,0).
*
* @author Chris Malley (PixelZoom, Inc.)
*/
Expand Down Expand Up @@ -37,14 +37,14 @@ define( require => {
]
} );

// Align with atom location and molecular dipole
// Align with atom position and molecular dipole
const updateTransform = function() {
this.matrix = Matrix3
.translationFromVector( atom.locationProperty.get() )
.translationFromVector( atom.positionProperty.get() )
.timesMatrix( Matrix3.rotation2( molecule.dipoleProperty.get().angle + Math.PI / 2 ) );
};
molecule.dipoleProperty.link( updateTransform.bind( this ) ); // unlink not needed
atom.locationProperty.link( updateTransform.bind( this ) ); // unlink not needed
atom.positionProperty.link( updateTransform.bind( this ) ); // unlink not needed
}

moleculePolarity.register( 'RotateArrowsNode', RotateArrowsNode );
Expand Down
6 changes: 3 additions & 3 deletions js/threeatoms/view/ThreeAtomsScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ define( require => {
} );
this.addChild( rootNode );

// layout, based on molecule location ---------------------------------
// layout, based on molecule position ---------------------------------

const moleculeX = model.molecule.location.x;
const moleculeY = model.molecule.location.y;
const moleculeX = model.molecule.position.x;
const moleculeY = model.molecule.position.y;

// to left of molecule, vertically centered
negativePlateNode.right = moleculeX - PLATE_X_OFFSET;
Expand Down
Loading

0 comments on commit 59482fe

Please sign in to comment.