Skip to content

Commit

Permalink
Apply PhET formatting to assist in ES6 module migration, see phetsims…
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Feb 21, 2020
1 parent b849d29 commit 7d1fa72
Show file tree
Hide file tree
Showing 24 changed files with 122 additions and 68 deletions.
14 changes: 7 additions & 7 deletions js/energy-skate-park/common/SplineEvaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ define( require => {
const yr = spline.yr;
const kl = spline.kl;
const kr = spline.kr;
const a = (kl[ p ] * (x[ p + 1 ] - x[ p ])) - (yr[ p + 1 ] - yl[ p ]);
const b = kr[ p + 1 ] * (x[ p ] - x[ p + 1 ]) + yr[ p + 1 ] - yl[ p ];
const t = (x1 - x[ p ]) / (x[ p + 1 ] - x[ p ]);
const s = t * (1 - t);
return ((1 - t) * yl[ p ] + t * yr[ p + 1 ] +
a * s * (1 - t) ) +
const a = ( kl[ p ] * ( x[ p + 1 ] - x[ p ] ) ) - ( yr[ p + 1 ] - yl[ p ] );
const b = kr[ p + 1 ] * ( x[ p ] - x[ p + 1 ] ) + yr[ p + 1 ] - yl[ p ];
const t = ( x1 - x[ p ] ) / ( x[ p + 1 ] - x[ p ] );
const s = t * ( 1 - t );
return ( ( 1 - t ) * yl[ p ] + t * yr[ p + 1 ] +
a * s * ( 1 - t ) ) +
b * s * t;
};

Expand All @@ -43,7 +43,7 @@ define( require => {
p = 0;
q = n - 1;
while ( q - p > 1 ) {
mid = floor( (p + q) / 2 );
mid = floor( ( p + q ) / 2 );
if ( x[ mid ] <= x0 ) {
p = mid;
}
Expand Down
24 changes: 12 additions & 12 deletions js/energy-skate-park/common/model/DebugTracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ define( require => {
* @param {Tandem} trackGroupTandem
*/
static init( model, controlPointGroupTandem, trackGroupTandem ) {
// Tracks to help demonstrate issues
// Tracks to help demonstrate issues

const createControlPoint = ( x, y ) => {
return new ControlPoint( x, y, { tandem: controlPointGroupTandem.createNextTandem() } );
Expand Down Expand Up @@ -278,22 +278,22 @@ define( require => {
model.frictionProperty.value = 0;

const controlPoints = [
createControlPoint(-0.29564715581203593,5.349320898598515),
createControlPoint(0.5844187963726313,5.266814715581202),
createControlPoint(1.5469909315746087,4.771777617477328),
createControlPoint(2.0145259686727126,3.1629070486397355),
createControlPoint(1.2307172300082456,1.7878039983511949),
createControlPoint(-1.2994723825226702,1.7740529678483092),
createControlPoint(-2.1382852431986805,3.575437963726298),
createControlPoint(-1.0382028029678487,5.280565746084088),
createControlPoint(0.6944270403957145,6.806930131904369),
createControlPoint(-0.9831986809563062,7.962016694146743)
createControlPoint( -0.29564715581203593, 5.349320898598515 ),
createControlPoint( 0.5844187963726313, 5.266814715581202 ),
createControlPoint( 1.5469909315746087, 4.771777617477328 ),
createControlPoint( 2.0145259686727126, 3.1629070486397355 ),
createControlPoint( 1.2307172300082456, 1.7878039983511949 ),
createControlPoint( -1.2994723825226702, 1.7740529678483092 ),
createControlPoint( -2.1382852431986805, 3.575437963726298 ),
createControlPoint( -1.0382028029678487, 5.280565746084088 ),
createControlPoint( 0.6944270403957145, 6.806930131904369 ),
createControlPoint( -0.9831986809563062, 7.962016694146743 )
];

const track16 = new Track( model, model.tracks, controlPoints, null, model.availableModelBoundsProperty, {
tandem: trackGroupTandem.createNextTandem(),
configurable: true
} );
} );
track16.physicalProperty.value = true;
model.tracks.add( track16 );
}
Expand Down
49 changes: 39 additions & 10 deletions js/energy-skate-park/common/model/PremadeTracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ define( require => {
p1Draggable: true,
p2Draggable: true,
p3Draggable: true
},CREATOR_OPTIONS, options );
}, CREATOR_OPTIONS, options );

const p1 = new Vector2( -options.trackWidth / 2, options.trackHeight );
const p2 = new Vector2( 0, 0 );
Expand Down Expand Up @@ -148,9 +148,21 @@ define( require => {
const p3Bounds = createRelativeSpaceBounds( p3, 0.5, 2.5, 3, 0 );

return [
new ControlPoint( p1.x, p1.y, { limitBounds: p1Bounds, tandem: groupTandem.createNextTandem(), phetioState: false } ),
new ControlPoint( p2.x, p2.y, { limitBounds: p2Bounds, tandem: groupTandem.createNextTandem(), phetioState: false } ),
new ControlPoint( p3.x, p3.y, { limitBounds: p3Bounds, tandem: groupTandem.createNextTandem(), phetioState: false } )
new ControlPoint( p1.x, p1.y, {
limitBounds: p1Bounds,
tandem: groupTandem.createNextTandem(),
phetioState: false
} ),
new ControlPoint( p2.x, p2.y, {
limitBounds: p2Bounds,
tandem: groupTandem.createNextTandem(),
phetioState: false
} ),
new ControlPoint( p3.x, p3.y, {
limitBounds: p3Bounds,
tandem: groupTandem.createNextTandem(),
phetioState: false
} )
];
},

Expand Down Expand Up @@ -257,7 +269,7 @@ define( require => {

const p1 = new Vector2( -loopWidth / 2, trackTop );
const p2 = new Vector2( -innerLoopWidth / 2, trackBottom );
const p3 = new Vector2( innerLoopWidth/ 2, innerLoopHeight );
const p3 = new Vector2( innerLoopWidth / 2, innerLoopHeight );
const p4 = new Vector2( 0, loopTop );
const p5 = new Vector2( -innerLoopWidth / 2, innerLoopHeight );
const p6 = new Vector2( innerLoopWidth / 2, trackBottom );
Expand All @@ -272,7 +284,11 @@ define( require => {
const p7Bounds = createRelativeSpaceBounds( p7, 1, 1, 2, 3 );

return [
new ControlPoint( p1.x, p1.y, { limitBounds: p1Bounds, tandem: groupTandem.createNextTandem(), phetioState: false } ),
new ControlPoint( p1.x, p1.y, {
limitBounds: p1Bounds,
tandem: groupTandem.createNextTandem(),
phetioState: false
} ),
new ControlPoint( p2.x, p2.y, {
limitBounds: p2Bounds,
tandem: groupTandem.createNextTandem(),
Expand All @@ -283,13 +299,26 @@ define( require => {
tandem: groupTandem.createNextTandem(),
phetioState: false
} ),
new ControlPoint( p4.x, p4.y, { limitBounds: p4Bounds, tandem: groupTandem.createNextTandem(), phetioState: false } ),
new ControlPoint( p5.x, p5.y, { limitBounds: p5Bounds,
new ControlPoint( p4.x, p4.y, {
limitBounds: p4Bounds,
tandem: groupTandem.createNextTandem(),
phetioState: false
} ),
new ControlPoint( p6.x, p6.y, { limitBounds: p6Bounds, tandem: groupTandem.createNextTandem(), phetioState: false } ),
new ControlPoint( p7.x, p7.y, { limitBounds: p7Bounds, tandem: groupTandem.createNextTandem(), phetioState: false } )
new ControlPoint( p5.x, p5.y, {
limitBounds: p5Bounds,
tandem: groupTandem.createNextTandem(),
phetioState: false
} ),
new ControlPoint( p6.x, p6.y, {
limitBounds: p6Bounds,
tandem: groupTandem.createNextTandem(),
phetioState: false
} ),
new ControlPoint( p7.x, p7.y, {
limitBounds: p7Bounds,
tandem: groupTandem.createNextTandem(),
phetioState: false
} )
];
},

Expand Down
2 changes: 1 addition & 1 deletion js/energy-skate-park/common/model/SkaterSample.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ define( require => {
}
}

return energySkatePark.register( 'SkaterSample', SkaterSample );
return energySkatePark.register( 'SkaterSample', SkaterSample );
} );
6 changes: 3 additions & 3 deletions js/energy-skate-park/common/model/SkaterState.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ define( require => {
* @returns {number}
*/
getTotalEnergy() {
return 0.5 * this.mass * (this.velocityX * this.velocityX + this.velocityY * this.velocityY) - this.mass * this.gravity * ( this.positionY - this.referenceHeight ) + this.thermalEnergy;
return 0.5 * this.mass * ( this.velocityX * this.velocityX + this.velocityY * this.velocityY ) - this.mass * this.gravity * ( this.positionY - this.referenceHeight ) + this.thermalEnergy;
}

/**
Expand All @@ -100,7 +100,7 @@ define( require => {
* @returns {number}
*/
getKineticEnergy() {
return 0.5 * this.mass * (this.velocityX * this.velocityX + this.velocityY * this.velocityY);
return 0.5 * this.mass * ( this.velocityX * this.velocityX + this.velocityY * this.velocityY );
}

/**
Expand Down Expand Up @@ -155,7 +155,7 @@ define( require => {
skater.onTopSideOfTrackProperty.value = this.onTopSideOfTrack;

// only an angle to restore if skater is attached to a track and skater is not being dragged
skater.angleProperty.value = ( skater.trackProperty.value && !this.dragging ) ? skater.trackProperty.value.getViewAngleAt( this.parametricPosition ) + (this.onTopSideOfTrack ? 0 : Math.PI) : this.angle;
skater.angleProperty.value = ( skater.trackProperty.value && !this.dragging ) ? skater.trackProperty.value.getViewAngleAt( this.parametricPosition ) + ( this.onTopSideOfTrack ? 0 : Math.PI ) : this.angle;
skater.updateEnergy();
}

Expand Down
2 changes: 2 additions & 0 deletions js/energy-skate-park/common/model/Track.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ define( require => {
this._slopeToGround = slopeToGround;
this._restoreSlopeToGroundOnReset = true;
}

set slopeToGround( slopeToGround ) { this.setSlopeToGround( slopeToGround ); }

/**
Expand All @@ -393,6 +394,7 @@ define( require => {
getSlopeToGround() {
return this._slopeToGround;
}

get slopeToGround() { return this.getSlopeToGround(); }

/**
Expand Down
24 changes: 20 additions & 4 deletions js/energy-skate-park/common/view/EnergyBarGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,26 @@ define( require => {
scale: 0.7
} );

const kineticEntry = { property: skater.kineticEnergyProperty, color: EnergySkateParkColorScheme.kineticEnergy, modifyBarHeight: hideSmallValues };
const potentialEntry = { property: skater.potentialEnergyProperty, color: EnergySkateParkColorScheme.potentialEnergy, modifyBarHeight: hideSmallValues };
const thermalEntry = { property: skater.thermalEnergyProperty, color: EnergySkateParkColorScheme.thermalEnergy, modifyBarHeight: showSmallValues };
const totalEntry = { property: skater.totalEnergyProperty, color: EnergySkateParkColorScheme.totalEnergy, modifyBarHeight: showSmallValues };
const kineticEntry = {
property: skater.kineticEnergyProperty,
color: EnergySkateParkColorScheme.kineticEnergy,
modifyBarHeight: hideSmallValues
};
const potentialEntry = {
property: skater.potentialEnergyProperty,
color: EnergySkateParkColorScheme.potentialEnergy,
modifyBarHeight: hideSmallValues
};
const thermalEntry = {
property: skater.thermalEnergyProperty,
color: EnergySkateParkColorScheme.thermalEnergy,
modifyBarHeight: showSmallValues
};
const totalEntry = {
property: skater.totalEnergyProperty,
color: EnergySkateParkColorScheme.totalEnergy,
modifyBarHeight: showSmallValues
};

this.barChartNode = new BarChartNode( [
{ entries: [ kineticEntry ], labelString: energyKineticString },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ define( require => {
children: [ checkbox, icon ],
spacing: 10
} );

}

/**
Expand Down Expand Up @@ -149,7 +149,7 @@ define( require => {

/**
* An icon for the reference height control.
* @param {Tandem} tandem
* @param {Tandem} tandem
* @returns {Node}
*/
static createReferenceHeightIcon( tandem ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ define( require => {
roadLine: 'black',

// colors for the reference height line
referenceLineFill:'rgb(74,133,208)',
referenceLineFill: 'rgb(74,133,208)',
referenceLineStroke: 'black',

// color for the reference line arrow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ define( require => {
6, {
fill: 'white',
stroke: 'black'
} );
} );
this.bottomLayer.addChild( this.trackCreationPanel );

model.tracks.addItemAddedListener( this.addTrackNode.bind( this ) );
Expand Down
2 changes: 1 addition & 1 deletion js/energy-skate-park/common/view/GridNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define( require => {
const Path = require( 'SCENERY/nodes/Path' );
const PhetFont = require( 'SCENERY_PHET/PhetFont' );
const Shape = require( 'KITE/Shape' );
const TextPanel= require( 'ENERGY_SKATE_PARK/energy-skate-park/common/view/TextPanel' );
const TextPanel = require( 'ENERGY_SKATE_PARK/energy-skate-park/common/view/TextPanel' );

// strings
const zeroMetersString = require( 'string!ENERGY_SKATE_PARK/zeroMeters' );
Expand Down
9 changes: 5 additions & 4 deletions js/energy-skate-park/common/view/PhysicalSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ define( require => {
sliderOnly: true,

sliderOptions: merge( {}, Constants.SLIDER_OPTIONS, {
majorTicks: [
createTickEntry( valueRange.min, options.minLabel, tandem, 'minLabel' ),
createTickEntry( valueRange.max, options.maxLabel, tandem, 'maxLabel' )
] }
majorTicks: [
createTickEntry( valueRange.min, options.minLabel, tandem, 'minLabel' ),
createTickEntry( valueRange.max, options.maxLabel, tandem, 'maxLabel' )
]
}
)
} );
}
Expand Down
2 changes: 1 addition & 1 deletion js/energy-skate-park/common/view/PieChartLegend.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define( require => {
const energyThermalString = require( 'string!ENERGY_SKATE_PARK/energy.thermal' );
const energyTotalString = require( 'string!ENERGY_SKATE_PARK/energy.total' );

class PieChartLegend extends Panel{
class PieChartLegend extends Panel {

/**
* @param {Skater} skater the model for the skater
Expand Down
8 changes: 4 additions & 4 deletions js/energy-skate-park/common/view/PieChartNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ define( require => {

// if only one component of pie chart, then show as a circle so there are no seams
const numberComponents = ( skater.potentialEnergyProperty.value > THRESHOLD ? 1 : 0 ) +
( skater.kineticEnergyProperty.value > THRESHOLD ? 1 : 0 ) +
( skater.thermalEnergyProperty.value > THRESHOLD ? 1 : 0 );
( skater.kineticEnergyProperty.value > THRESHOLD ? 1 : 0 ) +
( skater.thermalEnergyProperty.value > THRESHOLD ? 1 : 0 );

// Don't show the pie chart if energies are zero, or if potential energy is negative (underground skater), see #189
const energyNegative = skater.potentialEnergyProperty.value < 0;
Expand All @@ -142,8 +142,8 @@ define( require => {
}
else if ( numberComponents === 1 ) {
const selectedSlice = skater.potentialEnergyProperty.value > THRESHOLD ? potentialEnergySlice :
skater.kineticEnergyProperty.value > THRESHOLD ? kineticEnergySlice :
thermalEnergySlice;
skater.kineticEnergyProperty.value > THRESHOLD ? kineticEnergySlice :
thermalEnergySlice;
potentialEnergySlice.visible = false;
thermalEnergySlice.visible = false;
kineticEnergySlice.visible = false;
Expand Down
6 changes: 4 additions & 2 deletions js/energy-skate-park/common/view/PlaybackSpeedControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ define( require => {
assert && assert( options.children === undefined, 'PlaybackSpeedControl sets children' );

const slowMotionRadioButton = new AquaRadioButton( speedProperty, 'slow', new Text( slowMotionString, merge( {
tandem: tandem.createTandem( 'slowMotionTextNode' ) }, LABEL_OPTIONS )
tandem: tandem.createTandem( 'slowMotionTextNode' )
}, LABEL_OPTIONS )
), {
radius: RADIO_BUTTON_RADIUS,
tandem: tandem.createTandem( 'slowMotionRadioButton' )
} );
const normalSpeedRadioButton = new AquaRadioButton( speedProperty, 'normal', new Text( normalString, merge( {
tandem: tandem.createTandem( 'normalSpeedTextNode' ) }, LABEL_OPTIONS )
tandem: tandem.createTandem( 'normalSpeedTextNode' )
}, LABEL_OPTIONS )
), {
radius: RADIO_BUTTON_RADIUS,
x: 130,
Expand Down
2 changes: 1 addition & 1 deletion js/energy-skate-park/common/view/ReferenceHeightLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ define( require => {
* @param {NumberProperty} referenceHeightProperty
* @param {Tandem} tandem
*/
constructor( modelViewTransform, referenceHeightProperty, referenceHeightVisibleProperty, tandem ) {
constructor( modelViewTransform, referenceHeightProperty, referenceHeightVisibleProperty, tandem ) {

// line will extend 9.5 meters through along the grid in model coordinates
const lineLength = modelViewTransform.modelToViewDeltaX( 9.5 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ define( require => {
const alignedNode = buttonAlignGroup.createBox( node );
const margin = Math.abs( alignedNode.width - alignedNode.height ) / 2;
if ( margin !== 0 ) {
const setterFunction = alignedNode.height < alignedNode.width ? alignedNode.setYMargin : alignedNode.setXMargin;
const setterFunction = alignedNode.height < alignedNode.width ? alignedNode.setYMargin : alignedNode.setXMargin;
setterFunction.call( alignedNode, margin );
}

Expand Down
2 changes: 1 addition & 1 deletion js/energy-skate-park/common/view/SkaterNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ define( require => {
const normal = targetTrack.getUnitNormalVector( targetU );
skater.onTopSideOfTrackProperty.value = normal.y > 0;

skater.angleProperty.value = targetTrack.getViewAngleAt( targetU ) + (skater.onTopSideOfTrackProperty.value ? 0 : Math.PI);
skater.angleProperty.value = targetTrack.getViewAngleAt( targetU ) + ( skater.onTopSideOfTrackProperty.value ? 0 : Math.PI );

closeEnough = true;
}
Expand Down
5 changes: 4 additions & 1 deletion js/energy-skate-park/common/view/ToolboxPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ define( require => {
const measuringTapeIcon = MeasuringTapeNode.createIcon();
measuringTapeIcon.cursor = 'pointer';

const stopwatchIcon = new StopwatchNode( new Stopwatch( { isVisible: true, tandem: Tandem.OPT_OUT } ), { tandem: Tandem.OPT_OUT } ).rasterized( {
const stopwatchIcon = new StopwatchNode( new Stopwatch( {
isVisible: true,
tandem: Tandem.OPT_OUT
} ), { tandem: Tandem.OPT_OUT } ).rasterized( {
cursor: 'pointer',
resolution: 5,
tandem: tandem.createTandem( 'timerIcon' )
Expand Down
Loading

0 comments on commit 7d1fa72

Please sign in to comment.