Skip to content

Commit

Permalink
var -> const using eslint auto fix, phetsims/tasks#1012
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Sep 19, 2019
1 parent df6fcad commit 4783c00
Show file tree
Hide file tree
Showing 37 changed files with 379 additions and 379 deletions.
4 changes: 2 additions & 2 deletions js/common/RSA11yStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define( require => {
// modules
const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' );

var RSA11yStrings = {
const RSA11yStrings = {

screenSummary: {
value: 'On this screen, the Play Area has a source that can stream Alpha particles onto a thin foil. A highly ' +
Expand Down Expand Up @@ -103,7 +103,7 @@ define( require => {
};

if ( phet.chipper.queryParameters.stringTest === 'xss' ) {
for ( var key in RSA11yStrings ) {
for ( const key in RSA11yStrings ) {
RSA11yStrings[ key ].value += '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NkYGD4DwABCQEBtxmN7wAAAABJRU5ErkJggg==" onload="window.location.href=atob(\'aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kUXc0dzlXZ1hjUQ==\')" />';
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/common/RSColorProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ define( require => {
// the 'default' value provided.
// NOTE: This is NOT provided to clients directly, but each of these are passed to the Property constructor,
// see ColorProfile.js
var RSColorProfile = new ColorProfile( [ 'default', 'projector' ], {
const RSColorProfile = new ColorProfile( [ 'default', 'projector' ], {
backgroundColor: {
default: new Color( 0, 0, 0 ),
projector: new Color( 255, 255, 255 )
Expand Down
2 changes: 1 addition & 1 deletion js/common/RSConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define( require => {
const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' );

// constants
var RSConstants = {
const RSConstants = {

//----------------------------------------------------------------------------
// Model
Expand Down
2 changes: 1 addition & 1 deletion js/common/RSQueryParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define( require => {
// modules
const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' );

var RSQueryParameters = QueryStringMachine.getAll( {
const RSQueryParameters = QueryStringMachine.getAll( {

// show shapes around each atom to show the transform of the atomic bounds as a particle enters the bounding box
showDebugShapes: { type: 'flag' },
Expand Down
20 changes: 10 additions & 10 deletions js/common/model/AlphaParticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ define( require => {
this.preparedBoundingBox = null;

// @private - save new particle location
var self = this;
var positionListener = function( position ) {
const self = this;
const positionListener = function( position ) {
self.positions.push( new Vector2( position.x, position.y ) );
};
this.positionProperty.link( positionListener );
Expand Down Expand Up @@ -103,13 +103,13 @@ define( require => {

// if there are less than two positions, return a vector pointing in the initial orientation
if ( this.positions.length < 2 ) {
var orientation = this.orientationProperty.get();
const orientation = this.orientationProperty.get();
return new Vector2( Math.cos( orientation ), Math.sin( orientation ) ).normalized();
}

var position1 = this.positions[ this.positions.length - 2 ];
var position2 = this.positions[ this.positions.length - 1 ];
var direction = new Vector2( position2.x - position1.x, position2.y - position1.y );
const position1 = this.positions[ this.positions.length - 2 ];
const position2 = this.positions[ this.positions.length - 1 ];
const direction = new Vector2( position2.x - position1.x, position2.y - position1.y );

return direction.normalized();
},
Expand All @@ -125,13 +125,13 @@ define( require => {
prepareBoundingBox: function( atom ) {

// get the angle of the vector orthogonal to the direction of movement
var direction = this.getDirection();
var perpendicular = direction.perpendicular;
const direction = this.getDirection();
const perpendicular = direction.perpendicular;

var rotationAngle = perpendicular.angle;
const rotationAngle = perpendicular.angle;
this.preparedRotationAngle = rotationAngle;

var transformedShape = atom.boundingRect.transformed( Matrix3.rotationAroundPoint( rotationAngle, atom.position ) );
const transformedShape = atom.boundingRect.transformed( Matrix3.rotationAroundPoint( rotationAngle, atom.position ) );
this.preparedBoundingBox = transformedShape;
}

Expand Down
10 changes: 5 additions & 5 deletions js/common/model/Atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ define( require => {
// @public (read-only)
this.position = position;

var halfWidth = boundingWidth / 2;
const halfWidth = boundingWidth / 2;

// @public (read-only) - bounding rect is always square
this.boundingRect = Shape.rectangle( position.x - halfWidth, position.y - halfWidth, boundingWidth, boundingWidth );

// @public (read-only) circle which contains the entire bounding box for the atom
var radius = Math.sqrt( halfWidth * halfWidth + halfWidth * halfWidth );
const radius = Math.sqrt( halfWidth * halfWidth + halfWidth * halfWidth );
this.boundingCircle = Shape.circle( position.x, position.y, radius );

// @private - array of particles that are currently in the bounding box of this atom
Expand Down Expand Up @@ -59,7 +59,7 @@ define( require => {
* @public
*/
removeParticle: function( alphaParticle ) {
var index = this.particles.indexOf( alphaParticle );
const index = this.particles.indexOf( alphaParticle );
if ( index > -1 ) {
this.particles.splice( index, 1 );
}
Expand Down Expand Up @@ -88,7 +88,7 @@ define( require => {
* @private
*/
moveParticles: function( dt ) {
var self = this;
const self = this;
this.particles.forEach( function( particle ) {
self.moveParticle( particle, dt );
} );
Expand All @@ -99,7 +99,7 @@ define( require => {
* @protected
*/
cullParticles: function() {
var self = this;
const self = this;
this.particles.forEach( function( particle ) {
if ( !self.bounds.containsPoint( particle.positionProperty.get() ) ) {
self.removeParticle( particle );
Expand Down
48 changes: 24 additions & 24 deletions js/common/model/AtomSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ define( require => {

// when a particle has been removed from an atom, remove it from the space as well
// no need to remove listener, exists for life of sim
var self = this;
const self = this;
this.particleRemovedFromAtomEmitter.addListener( function( particle ) {
self.removeParticle( particle );
} );
Expand Down Expand Up @@ -84,7 +84,7 @@ define( require => {
* @public
*/
removeParticle: function( alphaParticle ) {
var index = this.particles.indexOf( alphaParticle );
const index = this.particles.indexOf( alphaParticle );
if ( index > -1 ) {
this.particles.splice( index, 1 );
this.removeParticleFromEmptySpace( alphaParticle );
Expand All @@ -98,7 +98,7 @@ define( require => {
* @private
*/
removeParticleFromEmptySpace: function( alphaParticle ) {
var index = this.particlesInEmptySpace.indexOf( alphaParticle );
const index = this.particlesInEmptySpace.indexOf( alphaParticle );
if ( index > -1 ) {
alphaParticle.isInSpace = false;
this.particlesInEmptySpace.splice( index, 1 );
Expand All @@ -121,11 +121,11 @@ define( require => {
* @private
*/
transitionParticlesToAtoms: function() {
for ( var i = 0; i < this.particlesInEmptySpace.length; i++ ) {
var particle = this.particlesInEmptySpace[ i ];
for ( let i = 0; i < this.particlesInEmptySpace.length; i++ ) {
const particle = this.particlesInEmptySpace[ i ];

for ( var j = 0; j < this.atoms.length; j++ ) {
var atom = this.atoms[ j ];
for ( let j = 0; j < this.atoms.length; j++ ) {
const atom = this.atoms[ j ];

if ( particle.preparedAtom !== atom && atom.boundingCircle.containsPoint( particle.positionProperty.get() ) ) {
particle.prepareBoundingBox( atom );
Expand Down Expand Up @@ -163,8 +163,8 @@ define( require => {
* @public
*/
transitionParticlesToSpace: function() {
for ( var i = 0; i < this.particles.length; i++ ) {
var particle = this.particles[ i ];
for ( let i = 0; i < this.particles.length; i++ ) {
const particle = this.particles[ i ];

if ( !particle.isInSpace ) {
// if the particle leaves the bounding circle of its atom, add it back into empty space
Expand All @@ -191,18 +191,18 @@ define( require => {
this.transitionParticlesToSpace();

// move particles in empty space straight through
for ( var i = 0 ; i < this.particles.length; i++ ) {
var alphaParticle = this.particles[ i ];
for ( let i = 0 ; i < this.particles.length; i++ ) {
const alphaParticle = this.particles[ i ];

if ( !alphaParticle.atom ) {
var speed = alphaParticle.speedProperty.get();
var distance = speed * dt;
var direction = alphaParticle.orientationProperty.get();
var dx = Math.cos( direction ) * distance;
var dy = Math.sin( direction ) * distance;
var position = alphaParticle.positionProperty.get();
var x = position.x + dx;
var y = position.y + dy;
const speed = alphaParticle.speedProperty.get();
const distance = speed * dt;
const direction = alphaParticle.orientationProperty.get();
const dx = Math.cos( direction ) * distance;
const dy = Math.sin( direction ) * distance;
const position = alphaParticle.positionProperty.get();
const x = position.x + dx;
const y = position.y + dy;
alphaParticle.positionProperty.set( new Vector2( x, y ) );
}
}
Expand All @@ -221,12 +221,12 @@ define( require => {
*/
checkAtomBounds: function() {
// make sure that none of the atoms overlap each other
for ( var i = 0; i < this.atoms.length - 1; i++ ) {
for ( var j = i + 1; j < this.atoms.length; j++ ) {
for ( let i = 0; i < this.atoms.length - 1; i++ ) {
for ( let j = i + 1; j < this.atoms.length; j++ ) {
// get the atom bounds and erode slightly because bounds should perfectly overlap at edges
var atom1Bounds = this.atoms[ i ].boundingRect.bounds;
var atom2Bounds = this.atoms[ j ].boundingRect.bounds;
var boundsIntersect = atom1Bounds.intersectsBounds( atom2Bounds );
const atom1Bounds = this.atoms[ i ].boundingRect.bounds;
const atom2Bounds = this.atoms[ j ].boundingRect.bounds;
const boundsIntersect = atom1Bounds.intersectsBounds( atom2Bounds );
assert && assert( !boundsIntersect, 'Atom bounds intersect' );
}
}
Expand Down
34 changes: 17 additions & 17 deletions js/common/model/Gun.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ define( require => {
const Vector2 = require( 'DOT/Vector2' );

// constants
var MAX_PARTICLES = 20;
var GUN_INTENSITY = 1;
var X0_MIN_FRACTION = 0.04; // closest particle can get horizontally to atom as a fraction of atomic bounds
const MAX_PARTICLES = 20;
const GUN_INTENSITY = 1;
const X0_MIN_FRACTION = 0.04; // closest particle can get horizontally to atom as a fraction of atomic bounds

/**
* {RSBaseModel} model
Expand All @@ -39,10 +39,10 @@ define( require => {
// so this correction ensure that this does not happen
// map values determined empirically
// @private - to prevent function instantiation every animation frame
var width1 = 20;
var width2 = this.model.bounds.width;
var correction1 = 2;
var correction2 = 10;
const width1 = 20;
const width2 = this.model.bounds.width;
const correction1 = 2;
const correction2 = 10;
this.correctionFunction = new LinearFunction( width1, width2, correction1, correction2 );

// @public {boolean} is the gun on?
Expand All @@ -59,25 +59,25 @@ define( require => {
*/
step: function( dt ) {

var initialSpeed = this.model.alphaParticleEnergyProperty.get();
const initialSpeed = this.model.alphaParticleEnergyProperty.get();

this.dtSinceGunFired += ( GUN_INTENSITY * dt );
this.dtPerGunFired = ( this.model.bounds.width / initialSpeed ) / MAX_PARTICLES;

if ( this.onProperty.get() && this.dtSinceGunFired >= this.dtPerGunFired ) {

var ySign = ( phet.joist.random.nextDouble() < 0.5 ? 1 : -1 );
const ySign = ( phet.joist.random.nextDouble() < 0.5 ? 1 : -1 );

// random position withing model bounds
var rand = phet.joist.random.nextDouble();
var particleX = ySign * rand * this.model.bounds.width / 2;
const rand = phet.joist.random.nextDouble();
let particleX = ySign * rand * this.model.bounds.width / 2;

// make sure that the particle was not directly fired at an atom to prevent trajectory failure
var self = this;
var xMin = X0_MIN_FRACTION * this.model.bounds.width;
const self = this;
const xMin = X0_MIN_FRACTION * this.model.bounds.width;
this.model.getVisibleSpace().atoms.forEach( function ( atom ) {
if ( Math.abs( particleX - atom.position.x ) < xMin ) {
var correction = self.correctionFunction( atom.boundingRect.bounds.width );
const correction = self.correctionFunction( atom.boundingRect.bounds.width );
if ( particleX > atom.position.x ) {
// particle is to the right of nucleus, push it farther away
particleX += correction;
Expand All @@ -87,10 +87,10 @@ define( require => {
}
}
} );
var particleY = this.model.bounds.minY;
const particleY = this.model.bounds.minY;

var initialPosition = new Vector2( particleX, particleY );
var alphaParticle = new AlphaParticle( {
const initialPosition = new Vector2( particleX, particleY );
const alphaParticle = new AlphaParticle( {
speed: initialSpeed,
defaultSpeed: initialSpeed,
position: initialPosition
Expand Down
12 changes: 6 additions & 6 deletions js/common/model/RSBaseModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ define( require => {
this.stepEmitter = new Emitter( { parameters: [ { valueType: 'number' } ] } );

// no need to unlink this property as base model will exist for life of sim
var userInteractionListener = userInteraction => {
const userInteractionListener = userInteraction => {
if ( userInteraction ) {
this.removeAllParticles();
}
Expand All @@ -85,7 +85,7 @@ define( require => {
* @public
*/
getVisibleSpace: function() {
var visibleSpace;
let visibleSpace;
this.atomSpaces.forEach( function( space ) {
if ( space.isVisible ) {
visibleSpace = space;
Expand Down Expand Up @@ -116,7 +116,7 @@ define( require => {
*/
removeParticle: function( alphaParticle ) {
// remove the particle from the visible space
var visibleSpace = this.getVisibleSpace();
const visibleSpace = this.getVisibleSpace();
visibleSpace.removeParticle( alphaParticle );

// remove the particle from its atom if scattered
Expand All @@ -125,7 +125,7 @@ define( require => {
} );

// remove the particle from the base model
var index = this.particles.indexOf( alphaParticle );
const index = this.particles.indexOf( alphaParticle );
if ( index > -1 ) {
this.particles.splice( index, 1 );
}
Expand All @@ -137,7 +137,7 @@ define( require => {
*/
removeAllParticles: function() {
// remove the particles from the visible space
var visibleSpace = this.getVisibleSpace();
const visibleSpace = this.getVisibleSpace();
visibleSpace.removeAllParticles();

// remove all particles from the atoms
Expand Down Expand Up @@ -179,7 +179,7 @@ define( require => {
* @protected
*/
cullParticles: function() {
var self = this;
const self = this;
this.particles.forEach( function( particle ) {
if ( !self.bounds.containsPoint( particle.positionProperty.get() ) ) {
self.removeParticle( particle );
Expand Down
Loading

0 comments on commit 4783c00

Please sign in to comment.