Skip to content

Commit

Permalink
Revert "Use mutable form of Vector2.add() instead of Vector2.plus() (…
Browse files Browse the repository at this point in the history
…memory optimization) #115"

This reverts commit 55b2dd8.
  • Loading branch information
Denz1994 committed Mar 9, 2020
1 parent 55b2dd8 commit 607bb07
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions js/common/model/Atom2.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class Atom2 extends Atom {
}

translatePositionAndDestination( delta ) {
this.positionProperty.value = this.positionProperty.value.add( delta );
this.destinationProperty.value.add( delta );
this.positionProperty.value = this.positionProperty.value.plus( delta );
this.destinationProperty.value = this.destinationProperty.value.plus( delta );
}

setPositionAndDestination( point ) {
Expand Down
8 changes: 4 additions & 4 deletions js/common/model/Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ class Kit {
foundOverlap = true;

// get perturbed centers. this is so that if two molecules have the exact same centers, we will push them away
const aCenter = aBounds.center.add( new Vector2( phet.joist.random.nextDouble() - 0.5, phet.joist.random.nextDouble() - 0.5 ) );
const bCenter = bBounds.center.add( new Vector2( phet.joist.random.nextDouble() - 0.5, phet.joist.random.nextDouble() - 0.5 ) );
const aCenter = aBounds.center.plus( new Vector2( phet.joist.random.nextDouble() - 0.5, phet.joist.random.nextDouble() - 0.5 ) );
const bCenter = bBounds.center.plus( new Vector2( phet.joist.random.nextDouble() - 0.5, phet.joist.random.nextDouble() - 0.5 ) );

// delta from center of A to center of B, scaled to half of our push amount.
const delta = bCenter.minus( aCenter ).normalized().times( pushAmount );
Expand Down Expand Up @@ -648,7 +648,7 @@ class Kit {
// cause all atoms in the molecule to move to that location
const delta = bestLocation.idealLocation.minus( bestLocation.b.positionProperty.value );
this.getMolecule( bestLocation.b ).atoms.forEach( atomInMolecule => {
atomInMolecule.setPositionAndDestination( atomInMolecule.positionProperty.value.add( delta ) );
atomInMolecule.setPositionAndDestination( atomInMolecule.positionProperty.value.plus( delta ) );
} );

// we now will bond the atom
Expand Down Expand Up @@ -695,7 +695,7 @@ class BondingOption {
this.b = b;

// The location the atom should be placed
this.idealLocation = a.positionProperty.value.add( direction.vector.times( a.covalentRadius + b.covalentRadius ) );
this.idealLocation = a.positionProperty.value.plus( direction.vector.times( a.covalentRadius + b.covalentRadius ) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion js/common/model/LewisDotModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class LewisDotModel {

// if this atom isn't excluded
if ( otherDot.atom !== excludedAtom ) {
success = this.mapMolecule( coordinates.add( direction.vector ), otherDot.atom, atom, coordinateMap );
success = this.mapMolecule( coordinates.plus( direction.vector ), otherDot.atom, atom, coordinateMap );

// if we had a failure mapping that one, bail out
if ( !success ) {
Expand Down
3 changes: 2 additions & 1 deletion js/common/model/Molecule.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ class Molecule extends MoleculeStructure {
*/
shiftDestination( delta ) {
this.atoms.forEach( atom => {
// TODO: memory: consider alternate mutable form atom.destination.add( delta )
atom.isSeparatingProperty.value = true;
atom.destinationProperty.value.add( delta );
atom.destinationProperty.value = atom.destinationProperty.value.plus( delta );
} );
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/MoleculeBondNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MoleculeBondNode extends Node {
if ( orientation.magnitude > 0 ) {
orientation.normalize();
}
const location = orientation.times( this.a.covalentRadius ).add( this.a.positionProperty.value );
const location = orientation.times( this.a.covalentRadius ).plus( this.a.positionProperty.value );
this.setTranslation( BAMConstants.MODEL_VIEW_TRANSFORM.modelToViewPosition( location ) );
};
this.a.positionProperty.link( this.positionListener );
Expand Down

0 comments on commit 607bb07

Please sign in to comment.