From 3d0f5454862121d1bf175db091f29c58178817b4 Mon Sep 17 00:00:00 2001 From: jbphet Date: Thu, 9 Jan 2025 16:48:21 -0700 Subject: [PATCH] clear counts when measurement time changes, see https://github.com/phetsims/quantum-measurement/issues/54 --- js/bloch-sphere/model/BlochSphereModel.ts | 12 ++++++++++-- js/bloch-sphere/view/MeasurementTimerControl.ts | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/js/bloch-sphere/model/BlochSphereModel.ts b/js/bloch-sphere/model/BlochSphereModel.ts index 256070c..0da9c09 100644 --- a/js/bloch-sphere/model/BlochSphereModel.ts +++ b/js/bloch-sphere/model/BlochSphereModel.ts @@ -169,6 +169,11 @@ class BlochSphereModel implements TModel { tandem: providedOptions.tandem.createTandem( 'measurementStateProperty' ) } ); + // Clear the measurement counts when the time to measurement changes, since this changes the nature of the + // measurement that is being made. + this.timeToMeasurementProperty.link( () => this.resetCounts() ); + + // Change the selected preset state direction to CUSTOM when the user manually changes the angles of the Bloch Sphere. Multilink.multilink( [ this.preparationBlochSphere.polarAngleProperty, @@ -331,8 +336,11 @@ class BlochSphereModel implements TModel { } ); if ( this.measurementStateProperty.value === 'timingObservation' ) { - this.measurementTimeProperty.value = this.measurementTimeProperty.value + dt; - if ( this.measurementTimeProperty.value > this.timeToMeasurementProperty.value ) { + this.measurementTimeProperty.value = Math.min( + this.measurementTimeProperty.value + dt, + this.timeToMeasurementProperty.value + ); + if ( this.measurementTimeProperty.value >= this.timeToMeasurementProperty.value ) { // The time when the observation should be made has been reached. Make the observation. this.observe(); diff --git a/js/bloch-sphere/view/MeasurementTimerControl.ts b/js/bloch-sphere/view/MeasurementTimerControl.ts index fb439e4..a2a09b4 100644 --- a/js/bloch-sphere/view/MeasurementTimerControl.ts +++ b/js/bloch-sphere/view/MeasurementTimerControl.ts @@ -62,6 +62,8 @@ export default class MeasurementTimerControl extends Node { majorTickLength: 10, minorTickLength: 5 } ); + + // Add the major and minor tick marks to the slider. timeToMeasurementSlider.addMajorTick( 0, new Text( '0', { font: new PhetFont( 15 ) } ) ); timeToMeasurementSlider.addMajorTick( maxMeasurementTime, new Text( 't', { font: new PhetFont( 15 ) } ) ); _.times( NUMBER_OF_MINOR_TICKS, i => {