Skip to content

Commit

Permalink
Properly instrumenting mirror and using DerivedProperty.valueEqualsCo…
Browse files Browse the repository at this point in the history
…nstant #109
  • Loading branch information
AgustinVallejo committed Mar 3, 2025
1 parent 878e5de commit 53bee6b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
13 changes: 10 additions & 3 deletions js/photons/model/Mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import Vector2 from '../../../../dot/js/Vector2.js';
import { Line } from '../../../../kite/js/segments/Segment.js';
import { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import Photon from './Photon.js';
import { PhotonMotionState } from './PhotonMotionState.js';
Expand All @@ -24,7 +24,7 @@ type MirrorOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>;
// constants
const MIRROR_LENGTH = 0.095; // meters

export default class Mirror implements TPhotonInteraction {
export default class Mirror extends PhetioObject implements TPhotonInteraction {

// The position of the center of the mirror in 2D space. Units are in meters.
public readonly centerPosition: Vector2;
Expand All @@ -33,6 +33,13 @@ export default class Mirror implements TPhotonInteraction {
public readonly mirrorSurfaceLine: Line;

public constructor( centerPosition: Vector2, providedOptions: MirrorOptions ) {

const options = optionize<MirrorOptions, SelfOptions, PhetioObjectOptions>()( {
phetioState: false
}, providedOptions );

super( options );

this.centerPosition = centerPosition;

// Initialize the line that represents the position of the mirror surface in the model.
Expand Down
5 changes: 1 addition & 4 deletions js/photons/view/PhotonsExperimentSceneView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ class PhotonsExperimentSceneView extends Node {
normalizedOutcomeVectorGraph.showExpectationValueProperty,
showDecimalValuesProperty
),
visibleProperty: new DerivedProperty(
[ model.normalizedExpectationValueProperty ],
expectationValue => expectationValue !== null
),
visibleProperty: DerivedProperty.valueNotEqualsConstant( model.normalizedExpectationValueProperty, null ),
tandemControlName: 'expectationValueControl'
},
{
Expand Down
12 changes: 4 additions & 8 deletions js/photons/view/PhotonsScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,14 @@ class PhotonsScreenView extends QuantumMeasurementScreenView {

// Create the views for the two scenes that can be shown on this screen.
const singlePhotonExperimentSceneView = new PhotonsExperimentSceneView( model.singlePhotonSceneModel, {
visibleProperty: new DerivedProperty(
[ model.experimentModeProperty ],
experimentMode => experimentMode === ExperimentModeValues.SINGLE_PHOTON
),
visibleProperty: DerivedProperty.valueEqualsConstant(
model.experimentModeProperty, ExperimentModeValues.SINGLE_PHOTON ),
translation: sceneTranslation,
tandem: tandem.createTandem( 'singlePhotonExperimentSceneView' )
} );
const manyPhotonsExperimentSceneView = new PhotonsExperimentSceneView( model.manyPhotonsExperimentSceneModel, {
visibleProperty: new DerivedProperty(
[ model.experimentModeProperty ],
experimentMode => experimentMode === ExperimentModeValues.MANY_PHOTONS
),
visibleProperty: DerivedProperty.valueEqualsConstant(
model.experimentModeProperty, ExperimentModeValues.MANY_PHOTONS ),
translation: sceneTranslation,
tandem: tandem.createTandem( 'manyPhotonsExperimentSceneView' )
} );
Expand Down
3 changes: 2 additions & 1 deletion js/spin/view/SpinStatePreparationArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export default class SpinStatePreparationArea extends VBox {
const stateReadout = new RichText( stateReadoutStringProperty, { font: new PhetFont( 18 ) } );

const probabilityControlBox = new VBox( {
visibleProperty: new DerivedProperty( [ model.currentExperimentProperty ], currentExperiment => currentExperiment === SpinExperiment.CUSTOM ),
visibleProperty: DerivedProperty.valueEqualsConstant(
model.currentExperimentProperty, SpinExperiment.CUSTOM ),
children: [
new ProbabilityValueControl(
`|${MathSymbols.ALPHA}|<sup>2`,
Expand Down

0 comments on commit 53bee6b

Please sign in to comment.