From 22dd1bd336524d7001fa93e2a0462f1d20b6d5d4 Mon Sep 17 00:00:00 2001 From: AgustinVallejo Date: Fri, 1 Nov 2024 11:27:02 -0500 Subject: [PATCH] Fixing the update of particle rays, see https://github.com/phetsims/quantum-measurement/issues/53 --- js/spin/model/SpinModel.ts | 51 ++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/js/spin/model/SpinModel.ts b/js/spin/model/SpinModel.ts index a954c7f..9b0de7e 100644 --- a/js/spin/model/SpinModel.ts +++ b/js/spin/model/SpinModel.ts @@ -151,9 +151,11 @@ export default class SpinModel implements TModel { Multilink.multilink( [ this.currentExperimentProperty, - this.particleSourceModel.sourceModeProperty + this.particleSourceModel.sourceModeProperty, + this.particleSourceModel.particleAmmountProperty, + this.particleSourceModel.spinStateProperty ], - ( experiment, sourceMode ) => { + ( experiment, sourceMode, particleAmmount ) => { this.particleRays.reset(); this.particleRays.isShortExperiment = experiment.isShortExperiment; this.particleRays.updateExperiment(); @@ -167,38 +169,27 @@ export default class SpinModel implements TModel { this.measurementLines.forEach( line => line.measurementStateProperty.reset() ); this.singleParticles.forEach( particle => particle.reset() ); - } - ); - - this.particleSourceModel.particleAmmountProperty.link( particleAmmount => { - updateProbabilities( particleAmmount ); - } ); + this.singleParticles.forEach( particle => particle.reset() ); - this.currentExperimentProperty.link( experiment => { - this.singleParticles.forEach( particle => particle.reset() ); - - this.sternGerlachs.forEach( ( SternGerlach, index ) => { - if ( experiment.experimentSetting.length > index ) { - // TODO: Should visibility be only handled via the View? https://github.com/phetsims/quantum-measurement/issues/53 - SternGerlach.isVisibleProperty.set( experiment.experimentSetting[ index ].active ); - SternGerlach.isZOrientedProperty.set( experiment.experimentSetting[ index ].isZOriented ); - } - else { - SternGerlach.isVisibleProperty.set( false ); - } - } ); - - // Set the probabilities of the experiment. In the continuous case, this immediately alters the shown rays - // In the single case, this prepares the probabilities for the particle that will be shot - this.prepare(); + this.sternGerlachs.forEach( ( SternGerlach, index ) => { + if ( experiment.experimentSetting.length > index ) { + // TODO: Should visibility be only handled via the View? https://github.com/phetsims/quantum-measurement/issues/53 + SternGerlach.isVisibleProperty.set( experiment.experimentSetting[ index ].active ); + SternGerlach.isZOrientedProperty.set( experiment.experimentSetting[ index ].isZOriented ); + } + else { + SternGerlach.isVisibleProperty.set( false ); + } + } ); - updateProbabilities( this.particleSourceModel.particleAmmountProperty.value ); - } ); + // Set the probabilities of the experiment. In the continuous case, this immediately alters the shown rays + // In the single case, this prepares the probabilities for the particle that will be shot + this.prepare(); - this.particleSourceModel.spinStateProperty.link( () => { - this.prepare(); - } ); + updateProbabilities( particleAmmount ); + } + ); // Find the first inactive single particle and activate it this.particleSourceModel.currentlyShootingParticlesProperty.link( shooting => {