Skip to content

Commit

Permalink
Addressing review comments, factoring out string into more readable v…
Browse files Browse the repository at this point in the history
…ariable names, see #109
  • Loading branch information
AgustinVallejo committed Feb 24, 2025
1 parent e64a107 commit 562e313
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions js/bloch-sphere/view/BlochSphereMeasurementArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const TIMES = MathSymbols.TIMES;
// nominal max width of text elements, empirically determined
const MAX_WIDTH = 200;

const UP = QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER;
const DOWN = QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER;
const KET = QuantumMeasurementConstants.KET;

export default class BlochSphereMeasurementArea extends Node {

public constructor( model: BlochSphereModel, providedOptions: BlochSphereMeasurementAreaOptions ) {
Expand Down Expand Up @@ -145,15 +149,13 @@ export default class BlochSphereMeasurementArea extends Node {
visibleProperty: DerivedProperty.not( model.isSingleMeasurementModeProperty )
} );

const KET = QuantumMeasurementConstants.KET;

const spinUpLabelStringProperty = new DerivedStringProperty(
[ model.measurementAxisProperty ],
measurementAxis => `|${QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER}<sub>${measurementAxis.label}</sub>${KET}`
measurementAxis => `|${UP}<sub>${measurementAxis.label}</sub>${KET}`
);
const spinDownLabelStringProperty = new DerivedStringProperty(
[ model.measurementAxisProperty ],
measurementAxis => `|${QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER}<sub>${measurementAxis.label}</sub>${KET}`
measurementAxis => `|${DOWN}<sub>${measurementAxis.label}</sub>${KET}`
);

const measurementResultHistogramTandem = providedOptions.tandem.createTandem( 'measurementResultHistogram' );
Expand Down
12 changes: 8 additions & 4 deletions js/spin/view/SpinMeasurementArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import ParticleSourceNode from './ParticleSourceNode.js';
import ParticleSprites from './ParticleSprites.js';
import SternGerlachNode from './SternGerlachNode.js';

const UP = QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER;
const DOWN = QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER;
const KET = QuantumMeasurementConstants.KET;

export default class SpinMeasurementArea extends VBox {

private manyParticlesCanvasNode: ManyParticlesCanvasNode;
Expand Down Expand Up @@ -106,15 +110,15 @@ export default class SpinMeasurementArea extends VBox {
[
sternGerlach.isZOrientedProperty
], isZOriented => isZOriented ?
`|${QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER}<sub>Z</sub>${QuantumMeasurementConstants.KET}` :
`|${QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER}<sub>X</sub>${QuantumMeasurementConstants.KET}`
`|${UP}<sub>Z</sub>${KET}` :
`|${UP}<sub>X</sub>${KET}`
);
const spinDownLabelStringProperty = new DerivedStringProperty(
[
sternGerlach.isZOrientedProperty
], isZOriented => isZOriented ?
`|${QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER}<sub>Z</sub>${QuantumMeasurementConstants.KET}` :
`|${QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER}<sub>X</sub>${QuantumMeasurementConstants.KET}`
`|${DOWN}<sub>Z</sub>${KET}` :
`|${DOWN}<sub>X</sub>${KET}`
);

const tandemName = `histogram${histogramCounter++}`;
Expand Down

0 comments on commit 562e313

Please sign in to comment.