From 0538657164863c0811a50e590e3a7a923037e59f Mon Sep 17 00:00:00 2001 From: jbphet Date: Thu, 16 Jan 2025 14:29:44 -0700 Subject: [PATCH] fix overzealous reset of data counts, see https://github.com/phetsims/quantum-measurement/issues/80 --- js/bloch-sphere/model/BlochSphereModel.ts | 20 ++++++++++--------- .../view/BlochSphereMeasurementArea.ts | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/js/bloch-sphere/model/BlochSphereModel.ts b/js/bloch-sphere/model/BlochSphereModel.ts index 1bfcd29..b1e4702 100644 --- a/js/bloch-sphere/model/BlochSphereModel.ts +++ b/js/bloch-sphere/model/BlochSphereModel.ts @@ -162,33 +162,34 @@ class BlochSphereModel implements TModel { // measurement that is being made. this.timeToMeasurementProperty.link( () => this.resetCounts() ); - // Clear accumulated counts, and potentially change the selected preset state direction to - // CUSTOM when the user changes the angles of the Bloch Sphere. + // Clear accumulated counts and potentially change the selected preset state direction to CUSTOM when the user + // changes the angles of the Bloch Sphere. Multilink.multilink( - [ - this.preparationBlochSphere.polarAngleProperty, - this.preparationBlochSphere.azimuthalAngleProperty - ], + [ this.preparationBlochSphere.polarAngleProperty, this.preparationBlochSphere.azimuthalAngleProperty ], () => { // Clear the accumulated counts. this.resetCounts(); if ( !selectingStateDirection ) { + // Change the selected state to indicate that the user has moved away from the preset states. this.selectedStateDirectionProperty.value = StateDirection.CUSTOM; } } ); + // Reset the counts when the user changes the magnetic field attributes. + Multilink.lazyMultilink( + [ this.magneticFieldStrengthProperty, this.magneticFieldEnabledProperty ], + () => this.resetCounts() + ); + // Set the precession rate of the Bloch sphere based on the state of the magnetic field, the selected scene, and the // measurement state. Multilink.lazyMultilink( [ this.magneticFieldStrengthProperty, this.magneticFieldEnabledProperty, this.measurementStateProperty ], ( magneticFieldStrength, showMagneticField, measurementState ) => { - // Changes to the field state should clear any accumulated counts. - this.resetCounts(); - // Set the precession rate of the Bloch sphere based on the measurement state and the state of the magnetic // field. const rotationRate = measurementState === 'timingObservation' && showMagneticField ? magneticFieldStrength : 0; @@ -213,6 +214,7 @@ class BlochSphereModel implements TModel { } ); } ); + // Reset accumulated data when the user changes the measurement axis. this.measurementAxisProperty.link( () => { this.resetCounts(); } ); diff --git a/js/bloch-sphere/view/BlochSphereMeasurementArea.ts b/js/bloch-sphere/view/BlochSphereMeasurementArea.ts index 3fcfa4d..1eca0c4 100644 --- a/js/bloch-sphere/view/BlochSphereMeasurementArea.ts +++ b/js/bloch-sphere/view/BlochSphereMeasurementArea.ts @@ -242,7 +242,7 @@ export default class BlochSphereMeasurementArea extends Node { const magneticFieldCheckbox = new Checkbox( model.magneticFieldEnabledProperty, - // TODO: This text should be localized, see https://github.com/phetsims/quantum-measurement/issues/54 + // TODO: This text should be localized, see https://github.com/phetsims/quantum-measurement/issues/80 new Text( 'Enable Magnetic Field', { font: new PhetFont( { size: 16 } ) } ), { spacing: 10,