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 authored and jessegreenberg committed Apr 21, 2021
1 parent c73b3dc commit 36234af
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 150 deletions.
38 changes: 19 additions & 19 deletions js/photon-absorption/model/Molecule.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ define( require => {
const Vector2Property = require( 'DOT/Vector2Property' );

// constants
var PHOTON_EMISSION_SPEED = 3000; // Picometers per second.
var PHOTON_ABSORPTION_DISTANCE = 100; // Distance where the molecule begins to query photon for absorption.
var VIBRATION_FREQUENCY = 5; // Cycles per second of sim time.
var ROTATION_RATE = 1.1; // Revolutions per second of sim time.
var ABSORPTION_HYSTERESIS_TIME = 0.2; // seconds
var PASS_THROUGH_PHOTON_LIST_SIZE = 10; // Size of list which tracks photons not absorbed due to random probability.
const PHOTON_EMISSION_SPEED = 3000; // Picometers per second.
const PHOTON_ABSORPTION_DISTANCE = 100; // Distance where the molecule begins to query photon for absorption.
const VIBRATION_FREQUENCY = 5; // Cycles per second of sim time.
const ROTATION_RATE = 1.1; // Revolutions per second of sim time.
const ABSORPTION_HYSTERESIS_TIME = 0.2; // seconds
const PASS_THROUGH_PHOTON_LIST_SIZE = 10; // Size of list which tracks photons not absorbed due to random probability.

// utility method used for serialization
function serializeArray( array ) {
var serializedArray = [];
const serializedArray = [];
array.forEach( function( arrayElement ) {
serializedArray.push( arrayElement.toStateObject() );
} );
Expand All @@ -43,7 +43,7 @@ define( require => {

// utility method for finding atom with the specified ID in a list
function findAtomWithID( atomArray, id ) {
for ( var i = 0; i < atomArray.length; i++ ) {
for ( let i = 0; i < atomArray.length; i++ ) {
if ( atomArray[ i ].uniqueID === id ) {
return atomArray[ i ];
}
Expand Down Expand Up @@ -263,7 +263,7 @@ define( require => {
}

if ( this.rotatingProperty.get() ) {
var directionMultiplier = this.rotationDirectionClockwiseProperty.get() ? -1 : 1;
const directionMultiplier = this.rotationDirectionClockwiseProperty.get() ? -1 : 1;
this.rotate( dt * ROTATION_RATE * 2 * Math.PI * directionMultiplier );
}

Expand Down Expand Up @@ -406,15 +406,15 @@ define( require => {
**/
queryAbsorbPhoton: function( photon ) {

var absorbPhoton = false;
let absorbPhoton = false;

if ( !this.isPhotonAbsorbed() &&
this.absorptionHysteresisCountdownTime <= 0 &&
photon.locationProperty.get().distance( this.getCenterOfGravityPos() ) < PHOTON_ABSORPTION_DISTANCE && !this.isPhotonMarkedForPassThrough( photon ) ) {

// The circumstances for absorption are correct, but do we have an absorption strategy for this photon's
// wavelength?
var candidateAbsorptionStrategy = this.mapWavelengthToAbsorptionStrategy[ photon.wavelength ];
const candidateAbsorptionStrategy = this.mapWavelengthToAbsorptionStrategy[ photon.wavelength ];
if ( typeof candidateAbsorptionStrategy !== 'undefined' ) {
// Yes, there is a strategy available for this wavelength.
// Ask it if it wants the photon.
Expand Down Expand Up @@ -462,11 +462,11 @@ define( require => {
* @param {number} wavelength - The photon to be emitted.
**/
emitPhoton: function( wavelength ) {
var photonToEmit = new Photon( wavelength, this.photonGroupTandem.createNextTandem() );
var emissionAngle = phet.joist.random.nextDouble() * Math.PI * 2;
const photonToEmit = new Photon( wavelength, this.photonGroupTandem.createNextTandem() );
const emissionAngle = phet.joist.random.nextDouble() * Math.PI * 2;
photonToEmit.setVelocity( PHOTON_EMISSION_SPEED * Math.cos( emissionAngle ),
( PHOTON_EMISSION_SPEED * Math.sin( emissionAngle ) ) );
var centerOfGravityPosRef = this.centerOfGravityProperty.get();
const centerOfGravityPosRef = this.centerOfGravityProperty.get();
photonToEmit.location = new Vector2( centerOfGravityPosRef.x, centerOfGravityPosRef.y );
this.absorptionHysteresisCountdownTime = ABSORPTION_HYSTERESIS_TIME;
this.photonEmittedEmitter.emit( photonToEmit );
Expand All @@ -479,9 +479,9 @@ define( require => {
**/
updateAtomPositions: function() {

for ( var uniqueID in this.initialAtomCogOffsets ) {
for ( const uniqueID in this.initialAtomCogOffsets ) {
if ( this.initialAtomCogOffsets.hasOwnProperty( uniqueID ) ) {
var atomOffset = new Vector2( this.initialAtomCogOffsets[ uniqueID ].x, this.initialAtomCogOffsets[ uniqueID ].y );
const atomOffset = new Vector2( this.initialAtomCogOffsets[ uniqueID ].x, this.initialAtomCogOffsets[ uniqueID ].y );
// Add the vibration, if any exists.
atomOffset.add( this.vibrationAtomOffsets[ uniqueID ] );
// Rotate.
Expand Down Expand Up @@ -522,7 +522,7 @@ define( require => {
fromStateObject: function( stateObject ) {

// Create a molecule that is basically blank.
var molecule = new Molecule();
const molecule = new Molecule();

// Fill in the straightforward stuff
molecule.highElectronicEnergyStateProperty.set( stateObject.highElectronicEnergyState );
Expand All @@ -537,8 +537,8 @@ define( require => {

// add the bonds
stateObject.atomicBonds.forEach( function( bondStateObject ) {
var atom1 = findAtomWithID( molecule.atoms, bondStateObject.atom1ID );
var atom2 = findAtomWithID( molecule.atoms, bondStateObject.atom2ID );
const atom1 = findAtomWithID( molecule.atoms, bondStateObject.atom1ID );
const atom2 = findAtomWithID( molecule.atoms, bondStateObject.atom2ID );
assert && assert( atom1 && atom2, 'Error: Couldn\'t match atom ID in bond with atoms in molecule' );
molecule.addAtomicBond( new AtomicBond( atom1, atom2, { bondCount: bondStateObject.bondCount } ) );
} );
Expand Down
40 changes: 20 additions & 20 deletions js/photon-absorption/model/PhotonAbsorptionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ define( require => {
// ------- constants -------------

// constants that control where and how photons are emitted.
var PHOTON_EMISSION_LOCATION = new Vector2( -2000, 0 );
const PHOTON_EMISSION_LOCATION = new Vector2( -2000, 0 );

// Velocity of emitted photons. Since they are emitted horizontally, only one value is needed.
var PHOTON_VELOCITY = 3000; // picometers/second
const PHOTON_VELOCITY = 3000; // picometers/second

// Defaults for photon emission periods.
var DEFAULT_PHOTON_EMISSION_PERIOD = Number.POSITIVE_INFINITY; // Milliseconds of sim time.
const DEFAULT_PHOTON_EMISSION_PERIOD = Number.POSITIVE_INFINITY; // Milliseconds of sim time.

// Default values for various parameters that weren't already covered.
var DEFAULT_EMITTED_PHOTON_WAVELENGTH = WavelengthConstants.IR_WAVELENGTH;
var INITIAL_COUNTDOWN_WHEN_EMISSION_ENABLED = 0.3; // seconds
const DEFAULT_EMITTED_PHOTON_WAVELENGTH = WavelengthConstants.IR_WAVELENGTH;
const INITIAL_COUNTDOWN_WHEN_EMISSION_ENABLED = 0.3; // seconds

// Minimum for photon emission periods.
var MIN_PHOTON_EMISSION_PERIOD_SINGLE_TARGET = 0.4; // seconds
const MIN_PHOTON_EMISSION_PERIOD_SINGLE_TARGET = 0.4; // seconds

/**
* Constructor for a photon absorption model.
Expand All @@ -73,7 +73,7 @@ define( require => {
*/
function PhotonAbsorptionModel( initialPhotonTarget, tandem ) {

var self = this;
const self = this;

this.photonAbsorptionModel = tandem; // @private

Expand Down Expand Up @@ -132,7 +132,7 @@ define( require => {
self.setPhotonEmissionPeriod( Number.POSITIVE_INFINITY );
}
else {
var singleTargetPeriodFrequency = self.getSingleTargetPeriodFromFrequency( emissionFrequency );
const singleTargetPeriodFrequency = self.getSingleTargetPeriodFromFrequency( emissionFrequency );
self.setPhotonEmissionPeriod( singleTargetPeriodFrequency );
}
} );
Expand Down Expand Up @@ -161,7 +161,7 @@ define( require => {
this.photons.clear();

// Reset all active molecules, which will stop any vibrations.
for ( var molecule = 0; molecule < this.activeMolecules.length; molecule++ ) {
for ( let molecule = 0; molecule < this.activeMolecules.length; molecule++ ) {
this.activeMolecules.get( molecule ).reset();
}

Expand Down Expand Up @@ -227,8 +227,8 @@ define( require => {
* @param {number} dt - the incremental times step, in seconds
*/
stepPhotons: function( dt ) {
var self = this;
var photonsToRemove = [];
const self = this;
const photonsToRemove = [];

// check for possible interaction between each photon and molecule
this.photons.forEach( function( photon ) {
Expand All @@ -243,13 +243,13 @@ define( require => {

// Remove any photons that were marked for removal.
this.photons.removeAll( photonsToRemove );
for ( var i = 0; i < photonsToRemove.length; i++ ) {
for ( let i = 0; i < photonsToRemove.length; i++ ) {
photonsToRemove[ i ].dispose();
}
},

clearPhotons: function() {
for ( var i = 0; i < this.photons.length; i++ ) {
for ( let i = 0; i < this.photons.length; i++ ) {
this.photons.get( i ).dispose();
}
this.photons.clear();
Expand All @@ -261,8 +261,8 @@ define( require => {
* @param {number} dt - The incremental time step.
*/
stepMolecules: function( dt ) {
var moleculesToStep = this.activeMolecules.getArray().slice( 0 );
for ( var molecule = 0; molecule < moleculesToStep.length; molecule++ ) {
const moleculesToStep = this.activeMolecules.getArray().slice( 0 );
for ( let molecule = 0; molecule < moleculesToStep.length; molecule++ ) {
moleculesToStep[ molecule ].step( dt );
}
},
Expand Down Expand Up @@ -290,9 +290,9 @@ define( require => {
* frames.
*/
emitPhoton: function( advanceAmount ) {
var photon = new Photon( this.photonWavelengthProperty.get(), this.photonGroupTandem.createNextTandem() );
const photon = new Photon( this.photonWavelengthProperty.get(), this.photonGroupTandem.createNextTandem() );
photon.locationProperty.set( new Vector2( PHOTON_EMISSION_LOCATION.x + PHOTON_VELOCITY * advanceAmount, PHOTON_EMISSION_LOCATION.y ) );
var emissionAngle = 0; // Straight to the right.
const emissionAngle = 0; // Straight to the right.
photon.setVelocity( PHOTON_VELOCITY * Math.cos( emissionAngle ), PHOTON_VELOCITY * Math.sin( emissionAngle ) );
this.photons.add( photon );
},
Expand Down Expand Up @@ -374,15 +374,15 @@ define( require => {
*/
updateActiveMolecule: function( photonTarget, tandem ) {

var self = this;
const self = this;

this.activeMolecules.forEach( function( molecule ) { molecule.dispose(); } );

// Remove the old photon target(s).
this.activeMolecules.clear(); // Clear the old active molecules array

// Add the new photon target(s).
var newMolecule =
const newMolecule =
photonTarget === PhotonTarget.SINGLE_CO_MOLECULE ? new CO( { tandem: tandem.createTandem( 'CO' ) } ) :
photonTarget === PhotonTarget.SINGLE_CO2_MOLECULE ? new CO2( { tandem: tandem.createTandem( 'CO2' ) } ) :
photonTarget === PhotonTarget.SINGLE_H2O_MOLECULE ? new H2O( { tandem: tandem.createTandem( 'H2O' ) } ) :
Expand Down Expand Up @@ -430,7 +430,7 @@ define( require => {
* in cases where an atom has broken apart and needs to be restored to its original condition.
*/
restoreActiveMolecule: function() {
var currentTarget = this.photonTargetProperty.get();
const currentTarget = this.photonTargetProperty.get();
this.updateActiveMolecule( currentTarget, this.photonAbsorptionModel );
}
} );
Expand Down
4 changes: 2 additions & 2 deletions js/photon-absorption/model/PhotonAbsorptionModelIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ define( require => {
*/
static addChildInstance( photonAbsorptionModel, tandem, stateObject ) {
validate( photonAbsorptionModel, this.validator );
var value = PhotonIO.fromStateObject( stateObject );
const value = PhotonIO.fromStateObject( stateObject );

var photon = new phet.moleculesAndLight.Photon( value.wavelength, tandem );
const photon = new phet.moleculesAndLight.Photon( value.wavelength, tandem );
photon.setVelocity( stateObject.vx, stateObject.vy );
photonAbsorptionModel.photons.add( photon );
}
Expand Down
6 changes: 3 additions & 3 deletions js/photon-absorption/model/PhotonAbsorptionStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ define( require => {
const moleculesAndLight = require( 'MOLECULES_AND_LIGHT/moleculesAndLight' );
const Property = require( 'AXON/Property' );

var MIN_PHOTON_HOLD_TIME = 0.6; // seconds of sim time
var MAX_PHOTON_HOLD_TIME = 1.2; // seconds of sim time
const MIN_PHOTON_HOLD_TIME = 0.6; // seconds of sim time
const MAX_PHOTON_HOLD_TIME = 1.2; // seconds of sim time

/**
* Constructor for photon absorption strategy.
Expand Down Expand Up @@ -65,7 +65,7 @@ define( require => {
queryAndAbsorbPhoton: function( photon ) {
// All circumstances are correct for photon absorption, so now we decide probabilistically whether or not to
// actually do it. This essentially simulates the quantum nature of the absorption.
var absorbed = (!this.isPhotonAbsorbed) && ( phet.joist.random.nextDouble() < this.photonAbsorptionProbabilityProperty.get() );
const absorbed = (!this.isPhotonAbsorbed) && ( phet.joist.random.nextDouble() < this.photonAbsorptionProbabilityProperty.get() );
if ( absorbed ) {
this.isPhotonAbsorbed = true;
this.photonHoldCountdownTime = MIN_PHOTON_HOLD_TIME + phet.joist.random.nextDouble() * ( MAX_PHOTON_HOLD_TIME - MIN_PHOTON_HOLD_TIME );
Expand Down
2 changes: 1 addition & 1 deletion js/photon-absorption/model/PhotonHoldStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ define( require => {
**/
queryAndAbsorbPhoton: function( photon ) {

var absorbed = PhotonAbsorptionStrategy.prototype.queryAndAbsorbPhoton.call( this, photon );
const absorbed = PhotonAbsorptionStrategy.prototype.queryAndAbsorbPhoton.call( this, photon );
if ( absorbed ) {
this.absorbedWavelength = photon.wavelength;
this.photonAbsorbed();
Expand Down
2 changes: 1 addition & 1 deletion js/photon-absorption/model/RotationStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ define( require => {
const PhotonHoldStrategy = require( 'MOLECULES_AND_LIGHT/photon-absorption/model/PhotonHoldStrategy' );

//Random boolean generator.
var RAND = {
const RAND = {
nextBoolean: function() {
return phet.joist.random.nextDouble() < 0.50;
}
Expand Down
2 changes: 1 addition & 1 deletion js/photon-absorption/model/WavelengthConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define( require => {
const quadWavelengthSelectorUltravioletString = require( 'string!MOLECULES_AND_LIGHT/QuadWavelengthSelector.Ultraviolet' );
const quadWavelengthSelectorVisibleString = require( 'string!MOLECULES_AND_LIGHT/QuadWavelengthSelector.Visible' );

var WavelengthConstants = {
const WavelengthConstants = {

// all values in meters
SUNLIGHT_WAVELENGTH: 400E-9, // Ported from the original JAVA version, but not used in Molecules And Light
Expand Down
2 changes: 1 addition & 1 deletion js/photon-absorption/model/atoms/Atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define( require => {
const PhetColorScheme = require( 'SCENERY_PHET/PhetColorScheme' );

// Static data
var instanceCount = 0; // Base count for the unique ID of this atom.
let instanceCount = 0; // Base count for the unique ID of this atom.

/**
* Constructor for creating an individual atom. This is generally invoked using factory methods for specify atoms.
Expand Down
18 changes: 9 additions & 9 deletions js/photon-absorption/model/molecules/CH4.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ define( require => {
const WavelengthConstants = require( 'MOLECULES_AND_LIGHT/photon-absorption/model/WavelengthConstants' );

// Model Data for Methane
var INITIAL_CARBON_HYDROGEN_DISTANCE = 170; // In picometers.
const INITIAL_CARBON_HYDROGEN_DISTANCE = 170; // In picometers.

// Assume that the angle from the carbon to the hydrogen is 45 degrees.
var ROTATED_INITIAL_CARBON_HYDROGEN_DISTANCE = INITIAL_CARBON_HYDROGEN_DISTANCE * Math.sin( Math.PI / 4 );
const ROTATED_INITIAL_CARBON_HYDROGEN_DISTANCE = INITIAL_CARBON_HYDROGEN_DISTANCE * Math.sin( Math.PI / 4 );

var HYDROGEN_VIBRATION_DISTANCE = 30;
var HYDROGEN_VIBRATION_ANGLE = Math.PI / 4;
var HYDROGEN_VIBRATION_DISTANCE_X = HYDROGEN_VIBRATION_DISTANCE * Math.cos( HYDROGEN_VIBRATION_ANGLE );
var HYDROGEN_VIBRATION_DISTANCE_Y = HYDROGEN_VIBRATION_DISTANCE * Math.sin( HYDROGEN_VIBRATION_ANGLE );
const HYDROGEN_VIBRATION_DISTANCE = 30;
const HYDROGEN_VIBRATION_ANGLE = Math.PI / 4;
const HYDROGEN_VIBRATION_DISTANCE_X = HYDROGEN_VIBRATION_DISTANCE * Math.cos( HYDROGEN_VIBRATION_ANGLE );
const HYDROGEN_VIBRATION_DISTANCE_Y = HYDROGEN_VIBRATION_DISTANCE * Math.sin( HYDROGEN_VIBRATION_ANGLE );

/**
* Constructor for a Methane molecule.
Expand Down Expand Up @@ -102,7 +102,7 @@ define( require => {
// Molecule.prototype.setVibration.call( this, vibrationRadians );

this.currentVibrationRadians = vibrationRadians;
var multFactor = Math.sin( vibrationRadians );
const multFactor = Math.sin( vibrationRadians );

if ( vibrationRadians !== 0 ) {
this.addInitialAtomCogOffset( this.hydrogenAtom1, new Vector2( -ROTATED_INITIAL_CARBON_HYDROGEN_DISTANCE + multFactor * HYDROGEN_VIBRATION_DISTANCE_X,
Expand All @@ -115,10 +115,10 @@ define( require => {
-ROTATED_INITIAL_CARBON_HYDROGEN_DISTANCE + multFactor * HYDROGEN_VIBRATION_DISTANCE_Y ) );

// Position the carbon atom so that the center of mass of the molecule remains the same.
var carbonXPos = -( this.hydrogenAtom1.mass / this.carbonAtom.mass ) *
const carbonXPos = -( this.hydrogenAtom1.mass / this.carbonAtom.mass ) *
( this.getInitialAtomCogOffset( this.hydrogenAtom1 ).x + this.getInitialAtomCogOffset( this.hydrogenAtom2 ).x +
this.getInitialAtomCogOffset( this.hydrogenAtom3 ).x + this.getInitialAtomCogOffset( this.hydrogenAtom4 ).x );
var carbonYPos = -( this.hydrogenAtom1.mass / this.carbonAtom.mass ) *
const carbonYPos = -( this.hydrogenAtom1.mass / this.carbonAtom.mass ) *
( this.getInitialAtomCogOffset( this.hydrogenAtom1 ).y + this.getInitialAtomCogOffset( this.hydrogenAtom2 ).y +
this.getInitialAtomCogOffset( this.hydrogenAtom3 ).y + this.getInitialAtomCogOffset( this.hydrogenAtom4 ).y );
this.addInitialAtomCogOffset( this.carbonAtom, new Vector2( carbonXPos, carbonYPos ) );
Expand Down
6 changes: 3 additions & 3 deletions js/photon-absorption/model/molecules/CO.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ define( require => {
const WavelengthConstants = require( 'MOLECULES_AND_LIGHT/photon-absorption/model/WavelengthConstants' );

// Model Data for the carbon monoxide molecule
var INITIAL_CARBON_OXYGEN_DISTANCE = 170; // In picometers.
var VIBRATION_MAGNITUDE = 20; // In picometers.
const INITIAL_CARBON_OXYGEN_DISTANCE = 170; // In picometers.
const VIBRATION_MAGNITUDE = 20; // In picometers.

/**
* Constructor for a carbon monoxide molecule.
Expand Down Expand Up @@ -67,7 +67,7 @@ define( require => {
setVibration: function( vibrationRadians ) {

this.currentVibrationRadians = vibrationRadians;
var multFactor = Math.sin( vibrationRadians );
const multFactor = Math.sin( vibrationRadians );
this.getVibrationAtomOffset( this.carbonAtom ).setXY( VIBRATION_MAGNITUDE * multFactor, 0 );
this.getVibrationAtomOffset( this.oxygenAtom ).setXY( -VIBRATION_MAGNITUDE * multFactor, 0 );
this.updateAtomPositions();
Expand Down
Loading

0 comments on commit 36234af

Please sign in to comment.