Skip to content

Commit

Permalink
conditionally instrument things that are not relevant when container …
Browse files Browse the repository at this point in the history
…has a fixed width, #77
  • Loading branch information
pixelzoom committed May 1, 2024
1 parent b66764f commit 16a15da
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
9 changes: 8 additions & 1 deletion js/common/model/BaseContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class BaseContainer extends PhetioObject {
this.leftWallVelocity = new Vector2( 0, 0 );

this.userIsAdjustingWidthProperty = new BooleanProperty( false, {
tandem: options.widthRange.getLength() === 0 ? Tandem.OPT_OUT : options.tandem.createTandem( 'userIsAdjustingWidthProperty' ),
tandem: this.isFixedWidth ? Tandem.OPT_OUT : options.tandem.createTandem( 'userIsAdjustingWidthProperty' ),
phetioReadOnly: true,
phetioDocumentation: 'For internal use only.'
} );
Expand All @@ -122,6 +122,13 @@ export default class BaseContainer extends PhetioObject {
*/
public get width(): number { return this.widthProperty.value; }

/**
* Does the container have a fixed width?
*/
public get isFixedWidth(): boolean {
return this.widthProperty.range.getLength() === 0;
}

/**
* Convenience getter for inside bounds, in pm.
*/
Expand Down
9 changes: 5 additions & 4 deletions js/common/model/IdealGasLawContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import Utils from '../../../../dot/js/Utils.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import optionize from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import gasProperties from '../../gasProperties.js';
import GasPropertiesQueryParameters from '../GasPropertiesQueryParameters.js';
import BaseContainer, { BaseContainerOptions } from './BaseContainer.js';
import BooleanIO from '../../../../tandem/js/types/BooleanIO.js';
import WithRequired from '../../../../phet-core/js/types/WithRequired.js';
import Tandem from '../../../../tandem/js/Tandem.js';

// constants

Expand All @@ -30,7 +31,7 @@ type SelfOptions = {
leftWallDoesWork?: boolean; // true if the left wall does work on particles, as in the Explore screen
};

type IdealGasLawContainerOptions = SelfOptions & PickRequired<BaseContainerOptions, 'tandem'>;
export type IdealGasLawContainerOptions = SelfOptions & WithRequired<BaseContainerOptions, 'tandem'>;

export default class IdealGasLawContainer extends BaseContainer {

Expand Down Expand Up @@ -107,14 +108,14 @@ export default class IdealGasLawContainer extends BaseContainer {

this.desiredWidthProperty = new NumberProperty( this.widthProperty.value, {
units: 'pm',
tandem: options.tandem.createTandem( 'desiredWidthProperty' ),
tandem: this.isFixedWidth ? Tandem.OPT_OUT : options.tandem.createTandem( 'desiredWidthProperty' ),
phetioReadOnly: true,
phetioDocumentation: 'For internal use only.'
} );

this.previousLeftProperty = new NumberProperty( this.left, {
units: 'pm',
tandem: options.tandem.createTandem( 'previousLeftProperty' ),
tandem: this.isFixedWidth ? Tandem.OPT_OUT : options.tandem.createTandem( 'previousLeftProperty' ),
phetioReadOnly: true,
phetioDocumentation: 'For internal use only.'
} );
Expand Down
20 changes: 10 additions & 10 deletions js/common/model/IdealGasLawModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import StringUnionProperty from '../../../../axon/js/StringUnionProperty.js';
import Range from '../../../../dot/js/Range.js';
import Utils from '../../../../dot/js/Utils.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import optionize from '../../../../phet-core/js/optionize.js';
import optionize, { combineOptions } from '../../../../phet-core/js/optionize.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import gasProperties from '../../gasProperties.js';
import GasPropertiesConstants from '../GasPropertiesConstants.js';
Expand All @@ -31,17 +31,16 @@ import BaseModel, { BaseModelOptions } from './BaseModel.js';
import CollisionCounter from './CollisionCounter.js';
import CollisionDetector from './CollisionDetector.js';
import { HoldConstant, HoldConstantValues } from './HoldConstant.js';
import IdealGasLawContainer from './IdealGasLawContainer.js';
import IdealGasLawContainer, { IdealGasLawContainerOptions } from './IdealGasLawContainer.js';
import ParticleSystem from './ParticleSystem.js';
import PressureGauge from './PressureGauge.js';
import PressureModel from './PressureModel.js';
import TemperatureModel from './TemperatureModel.js';
import PickOptional from '../../../../phet-core/js/types/PickOptional.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';

type SelfOptions = {

// Does the container's left wall do work on particles?
leftWallDoesWork?: boolean;

// Whether the screen has a collision counter.
hasCollisionCounter?: boolean;

Expand All @@ -50,6 +49,9 @@ type SelfOptions = {

// Initial value for holdConstantProperty.
holdConstant?: HoldConstant;

// Passed to IdealGasLawContainer.
containerOptions?: PickOptional<IdealGasLawContainerOptions, 'leftWallDoesWork' | 'widthRange'>;
};

export type IdealGasLawModelOptions = SelfOptions & BaseModelOptions;
Expand Down Expand Up @@ -110,10 +112,9 @@ export default class IdealGasLawModel extends BaseModel {

public constructor( providedOptions: IdealGasLawModelOptions ) {

const options = optionize<IdealGasLawModelOptions, SelfOptions, BaseModelOptions>()( {
const options = optionize<IdealGasLawModelOptions, StrictOmit<SelfOptions, 'containerOptions'>, BaseModelOptions>()( {

// SelfOptions
leftWallDoesWork: false,
hasCollisionCounter: true,
hasHoldConstantFeature: false,
holdConstant: 'nothing'
Expand Down Expand Up @@ -141,10 +142,9 @@ export default class IdealGasLawModel extends BaseModel {
phetioDocumentation: 'Determines whether collisions between particles are enabled.'
} );

this.container = new IdealGasLawContainer( {
leftWallDoesWork: options.leftWallDoesWork,
this.container = new IdealGasLawContainer( combineOptions<IdealGasLawContainerOptions>( {
tandem: options.tandem.createTandem( 'container' )
} );
}, options.containerOptions ) );

this.particleSystem = new ParticleSystem(
() => this.temperatureModel.getInitialTemperature(),
Expand Down
11 changes: 5 additions & 6 deletions js/energy/model/EnergyModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import IdealGasLawModel from '../../common/model/IdealGasLawModel.js';
import gasProperties from '../../gasProperties.js';
import AverageSpeedModel from './AverageSpeedModel.js';
import HistogramsModel from './HistogramsModel.js';
import RangeWithValue from '../../../../dot/js/RangeWithValue.js';

// constants
const SAMPLE_PERIOD = 1; // sample period for Average Speed and histograms, in ps
const CONTAINER_WIDTH = 10000; // pm

export default class EnergyModel extends IdealGasLawModel {

Expand All @@ -25,6 +26,9 @@ export default class EnergyModel extends IdealGasLawModel {
super( {
holdConstant: 'volume',
hasCollisionCounter: false,
containerOptions: {
widthRange: new RangeWithValue( CONTAINER_WIDTH, CONTAINER_WIDTH, CONTAINER_WIDTH )
},
tandem: tandem
} );

Expand All @@ -33,11 +37,6 @@ export default class EnergyModel extends IdealGasLawModel {
throw new Error( 'holdConstant is fixed in the Energy screen' );
} );

// In case clients attempt to use this feature of the base class
this.container.widthProperty.lazyLink( width => {
throw new Error( 'container width is fixed in the Energy screen' );
} );

this.histogramsModel = new HistogramsModel( this.particleSystem, this.isPlayingProperty, SAMPLE_PERIOD, {
tandem: tandem.createTandem( 'histogramsModel' )
} );
Expand Down
4 changes: 3 additions & 1 deletion js/explore/model/ExploreModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default class ExploreModel extends IdealGasLawModel {

super( {
holdConstant: 'nothing',
leftWallDoesWork: true, // moving the left wall does work on particles
containerOptions: {
leftWallDoesWork: true // moving the left wall does work on particles
},
tandem: tandem
} );

Expand Down

0 comments on commit 16a15da

Please sign in to comment.