Skip to content

Commit

Permalink
Addressed REVIEW: Coupled two multiLink functions. phetsims/masses-an…
Browse files Browse the repository at this point in the history
  • Loading branch information
Denz1994 committed Jan 30, 2019
1 parent f791200 commit 0727c4a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions js/common/model/Spring.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,19 @@ define( function( require ) {
this.naturalRestingLengthProperty
],
function( springConstant, gravity, mass, naturalRestingLength ) {
// REVIEW: Is it possible to combine this with the multilink that sets massEquilibriumYPositionProperty?
// REVIEW: The springExtensionValue is computed in both.
if ( mass ) {
var springExtensionValue =
( mass.massProperty.value * self.gravityProperty.value ) / self.springConstantProperty.value;

// springExtension = mg/k
var springExtension = ( mass.massProperty.value * self.gravityProperty.value ) / self.springConstantProperty.value;

//Set equilibrium y position
self.equilibriumYPositionProperty.set(
self.positionProperty.get().y - naturalRestingLength - springExtensionValue );
self.positionProperty.get().y - naturalRestingLength - springExtension );

// Set mass equilibrium y position
self.massEquilibriumYPositionProperty.set(
self.positionProperty.get().y - naturalRestingLength - springExtension - mass.heightProperty.value / 2
);
}
} );

Expand Down

0 comments on commit 0727c4a

Please sign in to comment.