diff --git a/js/common/model/MultipleParticleModel.js b/js/common/model/MultipleParticleModel.js index 817880c7..f82ff94c 100644 --- a/js/common/model/MultipleParticleModel.js +++ b/js/common/model/MultipleParticleModel.js @@ -227,14 +227,12 @@ class MultipleParticleModel extends PhetioObject { this.numMoleculesQueuedForInjectionProperty, this.isExplodedProperty, this.maxNumberOfMoleculesProperty, - this.containerHeightProperty, this.targetNumberOfMoleculesProperty ], - ( isPlaying, numberOfMoleculesQueuedForInjection, isExploded, maxNumberOfMoleculesProperty, containerHeight, targetNumberOfMolecules ) => { + ( isPlaying, numberOfMoleculesQueuedForInjection, isExploded, maxNumberOfMoleculesProperty, targetNumberOfMolecules ) => { return isPlaying && numberOfMoleculesQueuedForInjection < MAX_MOLECULES_QUEUED_FOR_INJECTION && !isExploded && - ( containerHeight / this.particleDiameter ) > this.injectionPointY && targetNumberOfMolecules < maxNumberOfMoleculesProperty; } ); @@ -265,13 +263,14 @@ class MultipleParticleModel extends PhetioObject { // @public, normalized velocity at which lid is moving in y direction this.normalizedLidVelocityY = 0; + // @protected (read-only) {Vector2} - the location where new molecules are injected, in normalized coordinates + this.injectionPoint = Vector2.ZERO.copy(); + // @private, various internal model variables this.particleDiameter = 1; this.minModelTemperature = null; this.residualTime = 0; this.moleculeInjectionHoldoffTimer = 0; - this.injectionPointX = 0; - this.injectionPointY = 0; this.heightChangeThisStep = 0; this.moleculeInjectedThisStep = false; @@ -559,8 +558,10 @@ class MultipleParticleModel extends PhetioObject { this.updateNormalizedContainerDimensions(); // Adjust the injection point based on the new particle diameter. These are using the normalized coordinate values. - this.injectionPointX = CONTAINER_WIDTH / this.particleDiameter * INJECTION_POINT_HORIZ_PROPORTION; - this.injectionPointY = CONTAINER_INITIAL_HEIGHT / this.particleDiameter * INJECTION_POINT_VERT_PROPORTION; + this.injectionPoint.setXY( + CONTAINER_WIDTH / this.particleDiameter * INJECTION_POINT_HORIZ_PROPORTION, + CONTAINER_INITIAL_HEIGHT / this.particleDiameter * INJECTION_POINT_VERT_PROPORTION + ); // Add the atoms and set their initial positions. this.initializeAtoms( phase ); @@ -703,7 +704,7 @@ class MultipleParticleModel extends PhetioObject { // Set the position(s) of the atom(s). const atomsPerMolecule = this.moleculeDataSet.atomsPerMolecule; - const moleculeCenterOfMassPosition = new Vector2( this.injectionPointX, this.injectionPointY ); + const moleculeCenterOfMassPosition = this.injectionPoint.copy(); const moleculeVelocity = new Vector2( xVel, yVel ); const atomPositions = []; for ( let i = 0; i < atomsPerMolecule; i++ ) { diff --git a/js/phase-changes/PhaseChangesModel.js b/js/phase-changes/PhaseChangesModel.js index bda60a16..91038257 100644 --- a/js/phase-changes/PhaseChangesModel.js +++ b/js/phase-changes/PhaseChangesModel.js @@ -5,6 +5,7 @@ */ import BooleanProperty from '../../../axon/js/BooleanProperty.js'; +import DerivedProperty from '../../../axon/js/DerivedProperty.js'; import NumberProperty from '../../../axon/js/NumberProperty.js'; import Range from '../../../dot/js/Range.js'; import Utils from '../../../dot/js/Utils.js'; @@ -56,6 +57,14 @@ class PhaseChangesModel extends MultipleParticleModel { range: new Range( MIN_ALLOWABLE_CONTAINER_HEIGHT, MultipleParticleModel.PARTICLE_CONTAINER_INITIAL_HEIGHT ) } ); + // @public (read-only) - a derived property that indicates whether the lid is higher than the injection point + this.lidAboveInjectionPointProperty = new DerivedProperty( [ this.containerHeightProperty ], containerHeight => { + + // This may appear a little suspect, but the model is designed such that the container height is always reset + // to its max when the particle diameter and injection change, so this can be trusted. + return ( containerHeight / this.particleDiameter ) > this.injectionPoint.y; + } ); + // reset the target container height in the event of an explosion this.isExplodedProperty.lazyLink( isExploded => { if ( isExploded ) { diff --git a/js/phase-changes/view/PhaseChangesScreenView.js b/js/phase-changes/view/PhaseChangesScreenView.js index 3fc75ade..ed4a4ba9 100644 --- a/js/phase-changes/view/PhaseChangesScreenView.js +++ b/js/phase-changes/view/PhaseChangesScreenView.js @@ -171,12 +171,14 @@ function PhaseChangesScreenView( model, isPotentialGraphEnabled, tandem ) { [ model.isPlayingProperty, model.isExplodedProperty, + model.lidAboveInjectionPointProperty, model.maxNumberOfMoleculesProperty, model.targetNumberOfMoleculesProperty ], - ( isPlaying, isExploded, maxNumberOfMoleculesProperty, targetNumberOfMolecules ) => { + ( isPlaying, isExploded, lidAboveInjectionPoint, maxNumberOfMoleculesProperty, targetNumberOfMolecules ) => { return isPlaying && !isExploded && + lidAboveInjectionPoint && targetNumberOfMolecules < maxNumberOfMoleculesProperty; } );