Skip to content

Commit

Permalink
Renamed crytpic variables, see #358
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 6, 2016
1 parent 58f84f3 commit 6fd756b
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 169 deletions.
120 changes: 60 additions & 60 deletions js/energy-skate-park-basics/model/EnergySkateParkBasicsModel.js

Large diffs are not rendered by default.

68 changes: 28 additions & 40 deletions js/energy-skate-park-basics/model/Skater.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,25 @@ define( function( require ) {
phetioValueType: TTrack
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
// Parameter along the parametric spline, unitless since it is in parametric space
u: {
parametricPosition: {
value: 0,
tandem: tandem.createTandem( 'skaterParametricDistanceAlongTrackProperty' ),
tandem: tandem.createTandem( 'parametricPositionProperty' ),
phetioValueType: TNumber()
},

// Speed along the parametric spline dimension, formally 'u dot', indicating speed and direction (+/-) along the
// track spline in meters per second. Not technically the derivative of 'u' since it is the euclidean speed.
uD: {
parametricSpeed: {
value: 0,
tandem: tandem.createTandem( 'uDProperty' ),
tandem: tandem.createTandem( 'parametricSpeedProperty' ),
phetioValueType: TNumber()
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
// True if the skater is pointing up on the track, false if attached to underside of track
up: {
onTopSideOfTrack: {
value: true,
tandem: tandem.createTandem( 'skaterUpsideUpOnTrackProperty' ),
tandem: tandem.createTandem( 'onTopSideOfTrackProperty' ),
phetioValueType: TBoolean
},

Expand All @@ -83,79 +81,69 @@ define( function( require ) {
phetioValueType: TNumber( { units: 'meters/second/second' } )
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
position: {
value: new Vector2( 3.5, 0 ),
tandem: tandem.createTandem( 'skaterPositionProperty' ),
tandem: tandem.createTandem( 'positionProperty' ),
phetioValueType: TVector2
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
// Start in the middle of the MassControlPanel range
mass: {
value: Constants.DEFAULT_MASS,
tandem: tandem.createTandem( 'skaterMassProperty' ),
tandem: tandem.createTandem( 'massProperty' ),
phetioValueType: TNumber( { units: 'kilograms' } )
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
// Which way the skater is facing, right or left. Coded as strings instead of boolean in case we add other states
// later like 'forward'
direction: {
value: 'left',
tandem: tandem.createTandem( 'skaterDirectionProperty' ),
tandem: tandem.createTandem( 'directionProperty' ),
phetioValueType: TString
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
velocity: {
value: new Vector2( 0, 0 ),
tandem: tandem.createTandem( 'skaterVelocityProperty' ),
tandem: tandem.createTandem( 'velocityProperty' ),
phetioValueType: TVector2
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
// True if the user is dragging the skater with a pointer
dragging: {
value: false,
tandem: tandem.createTandem( 'skaterDraggingProperty' ),
tandem: tandem.createTandem( 'draggingProperty' ),
phetioValueType: TBoolean
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
// Energies are in Joules
kineticEnergy: {
value: 0,
tandem: tandem.createTandem( 'skaterKineticEnergyProperty' ),
tandem: tandem.createTandem( 'kineticEnergyProperty' ),
phetioValueType: TNumber( { units: 'joules' } )
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
potentialEnergy: {
value: 0,
tandem: tandem.createTandem( 'skaterPotentialEnergyProperty' ),
tandem: tandem.createTandem( 'potentialEnergyProperty' ),
phetioValueType: TNumber( { units: 'joules' } )
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
thermalEnergy: {
value: 0,
tandem: tandem.createTandem( 'skaterThermalEnergyProperty' ),
tandem: tandem.createTandem( 'thermalEnergyProperty' ),
phetioValueType: TNumber( { units: 'joules' } )
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
totalEnergy: {
value: 0,
tandem: tandem.createTandem( 'skaterTotalEnergyProperty' ),
tandem: tandem.createTandem( 'totalEnergyProperty' ),
phetioValueType: TNumber( { units: 'joules' } )
},

//TODO tandem name does not match Property name, see https://github.com/phetsims/energy-skate-park-basics/issues/358
// The skater's angle (about the pivot point at the bottom center), in radians
angle: {
value: 0,
tandem: tandem.createTandem( 'skaterAngleProperty' ),
tandem: tandem.createTandem( 'angleProperty' ),
phetioValueType: TNumber( { units: 'radians' } )
},

Expand Down Expand Up @@ -211,17 +199,17 @@ define( function( require ) {
}
} );

this.link( 'uD', function( uD ) {
this.parametricSpeedProperty.link( function( parametricSpeed ) {

// Require the skater to overcome a speed threshold so he won't toggle back and forth rapidly at the bottom of a
// well with friction, see #51
var speedThreshold = 0.01;

if ( uD > speedThreshold ) {
self.direction = self.up ? 'right' : 'left';
if ( parametricSpeed > speedThreshold ) {
self.direction = self.onTopSideOfTrack ? 'right' : 'left';
}
else if ( uD < -speedThreshold ) {
self.direction = self.up ? 'left' : 'right';
else if ( parametricSpeed < -speedThreshold ) {
self.direction = self.onTopSideOfTrack ? 'left' : 'right';
}
else {
// Keep the same direction
Expand Down Expand Up @@ -317,10 +305,10 @@ define( function( require ) {
// If the user is on the same track as where he began (and the track hasn't changed), remain on the track,
// see #143 and #144
if ( this.startingTrack && this.track === this.startingTrack && arrayEquals( this.track.copyControlPointSources(), this.startingTrackControlPointSources ) ) {
this.u = this.startingU;
this.parametricPosition = this.startingU;
this.angle = this.startingAngle;
this.up = this.startingUp;
this.uD = 0;
this.onTopSideOfTrack = this.startingUp;
this.parametricSpeed = 0;
}
else {
this.track = null;
Expand Down Expand Up @@ -371,15 +359,15 @@ define( function( require ) {
released: function( targetTrack, targetU ) {
this.dragging = false;
this.velocity = new Vector2( 0, 0 );
this.uD = 0;
this.parametricSpeed = 0;
this.track = targetTrack;
this.u = targetU;
this.parametricPosition = targetU;
if ( targetTrack ) {
this.position = targetTrack.getPoint( this.u );
this.position = targetTrack.getPoint( this.parametricPosition );
}
this.startingPosition = this.position.copy();
this.startingU = targetU;
this.startingUp = this.up;
this.startingUp = this.onTopSideOfTrack;
this.startingTrack = targetTrack;

// Record the starting track control points to make sure the track hasn't changed during return this.
Expand Down
54 changes: 27 additions & 27 deletions js/energy-skate-park-basics/model/SkaterState.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ define( function( require ) {
// Special handling for values that can be null, false or zero
this.track = 'track' in overrides ? overrides.track : source.track;
this.angle = 'angle' in overrides ? overrides.angle : source.angle;
this.up = 'up' in overrides ? overrides.up : source.up;
this.u = 'u' in overrides ? overrides.u : source.u;
this.uD = 'uD' in overrides ? overrides.uD : source.uD;
this.onTopSideOfTrack = 'onTopSideOfTrack' in overrides ? overrides.onTopSideOfTrack : source.onTopSideOfTrack;
this.parametricPosition = 'parametricPosition' in overrides ? overrides.parametricPosition : source.parametricPosition;
this.parametricSpeed = 'parametricSpeed' in overrides ? overrides.parametricSpeed : source.parametricSpeed;
this.dragging = 'dragging' in overrides ? overrides.dragging : source.dragging;
this.thermalEnergy = 'thermalEnergy' in overrides ? overrides.thermalEnergy : source.thermalEnergy;

// Some sanity tests
assert && assert( isFinite( this.thermalEnergy ) );
assert && assert( isFinite( this.velocityX ) );
assert && assert( isFinite( this.velocityY ) );
assert && assert( isFinite( this.uD ) );
assert && assert( isFinite( this.parametricSpeed ) );

assert && assert( this.thermalEnergy >= 0 );

Expand All @@ -105,7 +105,7 @@ define( function( require ) {

// Get the curvature at the skater's point on the track, by setting it to the pass-by-reference argument
getCurvature: function( curvature ) {
this.track.getCurvature( this.u, curvature );
this.track.getCurvature( this.parametricPosition, curvature );
},

// Only set values that have changed
Expand All @@ -121,40 +121,40 @@ define( function( require ) {
skater.velocity.y = this.velocityY;
skater.velocityProperty.notifyObserversStatic();

skater.u = this.u;
skater.uD = this.uD;
skater.parametricPosition = this.parametricPosition;
skater.parametricSpeed = this.parametricSpeed;
skater.thermalEnergy = this.thermalEnergy;
skater.up = this.up;
skater.angle = skater.track ? skater.track.getViewAngleAt( this.u ) + (this.up ? 0 : Math.PI) : this.angle;
skater.onTopSideOfTrack = this.onTopSideOfTrack;
skater.angle = skater.track ? skater.track.getViewAngleAt( this.parametricPosition ) + (this.onTopSideOfTrack ? 0 : Math.PI) : this.angle;
skater.updateEnergy();
},

// Create a new SkaterState with the new values. Provided as a convenience to avoid allocating options argument
// (as in update)
updateTrackUD: function( track, uD ) {
updateTrackUD: function( track, parametricSpeed ) {
var state = new SkaterState( this, EMPTY_OBJECT );
state.track = track;
state.uD = uD;
state.parametricSpeed = parametricSpeed;
return state;
},

// Create a new SkaterState with the new values. Provided as a convenience to avoid allocating options argument
// (as in update)
updateUUDVelocityPosition: function( u, uD, velocityX, velocityY, positionX, positionY ) {
updateUUDVelocityPosition: function( parametricPosition, parametricSpeed, velocityX, velocityY, positionX, positionY ) {
var state = new SkaterState( this, EMPTY_OBJECT );
state.u = u;
state.uD = uD;
state.parametricPosition = parametricPosition;
state.parametricSpeed = parametricSpeed;
state.velocityX = velocityX;
state.velocityY = velocityY;
state.positionX = positionX;
state.positionY = positionY;
return state;
},

updatePositionAngleUpVelocity: function( positionX, positionY, angle, up, velocityX, velocityY ) {
updatePositionAngleUpVelocity: function( positionX, positionY, angle, onTopSideOfTrack, velocityX, velocityY ) {
var state = new SkaterState( this, EMPTY_OBJECT );
state.angle = angle;
state.up = up;
state.onTopSideOfTrack = onTopSideOfTrack;
state.velocityX = velocityX;
state.velocityY = velocityY;
state.positionX = positionX;
Expand All @@ -170,9 +170,9 @@ define( function( require ) {
return state;
},

updateUPosition: function( u, positionX, positionY ) {
updateUPosition: function( parametricPosition, positionX, positionY ) {
var state = new SkaterState( this, EMPTY_OBJECT );
state.u = u;
state.parametricPosition = parametricPosition;
state.positionX = positionX;
state.positionY = positionY;
return state;
Expand All @@ -184,7 +184,7 @@ define( function( require ) {
var state = new SkaterState( this, EMPTY_OBJECT );
state.thermalEnergy = thermalEnergy;
state.track = null;
state.up = true;
state.onTopSideOfTrack = true;
state.angle = 0;
state.velocityX = velocityX;
state.velocityY = velocityY;
Expand All @@ -203,7 +203,7 @@ define( function( require ) {
state.velocityX = 0;
state.velocityY = 0;
state.angle = 0;
state.up = true;
state.onTopSideOfTrack = true;
return state;
},

Expand All @@ -213,7 +213,7 @@ define( function( require ) {

leaveTrack: function() {
var state = new SkaterState( this, EMPTY_OBJECT );
state.uD = 0;
state.parametricSpeed = 0;
state.track = null;
return state;
},
Expand All @@ -225,9 +225,9 @@ define( function( require ) {
return state;
},

updateUDVelocity: function( uD, velocityX, velocityY ) {
updateUDVelocity: function( parametricSpeed, velocityX, velocityY ) {
var state = new SkaterState( this, EMPTY_OBJECT );
state.uD = uD;
state.parametricSpeed = parametricSpeed;
state.velocityX = velocityX;
state.velocityY = velocityY;
return state;
Expand All @@ -242,15 +242,15 @@ define( function( require ) {
return state;
},

attachToTrack: function( thermalEnergy, track, up, u, uD, velocityX, velocityY, positionX, positionY ) {
attachToTrack: function( thermalEnergy, track, onTopSideOfTrack, parametricPosition, parametricSpeed, velocityX, velocityY, positionX, positionY ) {
assert && assert( thermalEnergy >= 0 );

var state = new SkaterState( this, EMPTY_OBJECT );
state.thermalEnergy = thermalEnergy;
state.track = track;
state.up = up;
state.u = u;
state.uD = uD;
state.onTopSideOfTrack = onTopSideOfTrack;
state.parametricPosition = parametricPosition;
state.parametricSpeed = parametricSpeed;
state.velocityX = velocityX;
state.velocityY = velocityY;
state.positionX = positionX;
Expand Down
Loading

0 comments on commit 6fd756b

Please sign in to comment.