Skip to content

Commit

Permalink
Convert LinearFunction to a class with an evaluate method, see phetsi…
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Nov 2, 2021
1 parent cc3aa67 commit 6aa6242
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion js/common/model/MassesAndSpringsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class MassesAndSpringsModel {
mass.springProperty.get().naturalRestingLengthProperty.get() );

// Max Y value in model coordinates
const modelMaxY = UPPER_CONSTRAINT( maxY );
const modelMaxY = UPPER_CONSTRAINT.evaluate( maxY );

// Update only the spring's length if we are lower than the max Y
if ( mass.positionProperty.get().y > modelMaxY ) {
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/OscillatingSpringNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import massesAndSprings from '../../massesAndSprings.js';

// constants
const LINEAR_LOOP_MAPPING = new LinearFunction( 0.1, 0.5, 2, 12 );
const MAP_NUMBER_OF_LOOPS = springLength => Utils.roundSymmetric( LINEAR_LOOP_MAPPING( springLength ) );
const MAP_NUMBER_OF_LOOPS = springLength => Utils.roundSymmetric( LINEAR_LOOP_MAPPING.evaluate( springLength ) );

class OscillatingSpringNode extends ParametricSpringNode {

Expand Down
4 changes: 2 additions & 2 deletions js/common/view/ReferenceLineNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ReferenceLineNode extends Line {
// Helper function to derive the length as if the mass wasn't attached.
const lengthFunction = new LinearFunction( 0.1, 0.5, 1.37, 0.97 );

let yPos = modelViewTransform2.modelToViewY( lengthFunction( spring.naturalRestingLengthProperty.value ) );
let yPos = modelViewTransform2.modelToViewY( lengthFunction.evaluate( spring.naturalRestingLengthProperty.value ) );

// @private (read-write) - position of line in screen coordinates.
this.positionProperty = new Vector2Property( new Vector2( xPos, yPos ) );
Expand All @@ -69,7 +69,7 @@ class ReferenceLineNode extends Line {
if ( options.fixedPosition || !mass ) {

// Y position of line in screen coordinates as if a mass isn't attached
yPos = modelViewTransform2.modelToViewY( lengthFunction( restingLength ) );
yPos = modelViewTransform2.modelToViewY( lengthFunction.evaluate( restingLength ) );
}
else {

Expand Down

0 comments on commit 6aa6242

Please sign in to comment.