Skip to content

Commit

Permalink
move instantiation of TangentScrubber and AreaUnderCurveScrubber so t…
Browse files Browse the repository at this point in the history
…hey are not instantiated for screens that do not include them
  • Loading branch information
pixelzoom committed Mar 11, 2023
1 parent 8f88f79 commit d4e5827
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
41 changes: 14 additions & 27 deletions js/common/model/CalculusGrapherModel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2023, University of Colorado Boulder

/**
* Base class for the top-level model of every screen in the 'Calculus Grapher' simulation.
* CalculusGrapherModel is the base class for the top-level model of every screen in the 'Calculus Grapher' simulation.
*
* @author Brandon Li
* @author Martin Veillette
Expand All @@ -28,8 +28,6 @@ import CalculusGrapherConstants from '../CalculusGrapherConstants.js';
import ReferenceLine from './ReferenceLine.js';
import LabeledLine from './LabeledLine.js';
import LabeledPoint from './LabeledPoint.js';
import TangentScrubber from './TangentScrubber.js';
import AreaUnderCurveScrubber from './AreaUnderCurveScrubber.js';
import GraphSet from './GraphSet.js';
import CalculusGrapherPreferences from './CalculusGrapherPreferences.js';
import BooleanIO from '../../../../tandem/js/types/BooleanIO.js';
Expand All @@ -46,11 +44,11 @@ type SelfOptions = {
// Identifies the curve manipulation modes that are supported by the screen associated with this model.
curveManipulationModeChoices?: CurveManipulationMode[];

// Should the TangentScrubber be instrumented for PhET-iO?
phetioTangentScrubberInstrumented?: boolean;
// Should the model create a TangentScrubber?
hasTangentScrubber?: boolean;

// Should the AreaUnderCurveScrubber be instrumented for PhET-iO?
phetioAreaUnderCurveScrubberInstrumented?: boolean;
// Should the model create an AreaUnderCurveScrubber?
hasAreaUnderCurveScrubber?: boolean;
};

export type CalculusGrapherModelOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>;
Expand Down Expand Up @@ -88,11 +86,12 @@ export default class CalculusGrapherModel implements TModel {

// Model elements for the various tools
public readonly referenceLine: ReferenceLine;
public readonly tangentScrubber: TangentScrubber;
public readonly areaUnderCurveScrubber: AreaUnderCurveScrubber;
public readonly labeledPoints: LabeledPoint[];
public readonly labeledLines: LabeledLine[];

// Tandem that can be used to add additional tools in the subclasses
protected readonly toolsTandem: Tandem;

// These exist so that we have something to link to from the view.
// See https://github.com/phetsims/calculus-grapher/issues/198
public readonly labeledPointsLinkableElement: PhetioObject;
Expand All @@ -105,8 +104,8 @@ export default class CalculusGrapherModel implements TModel {
// SelfOptions
graphSet: providedOptions.graphSets[ 0 ],
curveManipulationModeChoices: CurveManipulationMode.enumeration.values,
phetioTangentScrubberInstrumented: false,
phetioAreaUnderCurveScrubberInstrumented: false
hasTangentScrubber: false,
hasAreaUnderCurveScrubber: false
}, providedOptions );

assert && assert( options.graphSets.length > 0, 'there must be at least one valid graphSet' );
Expand Down Expand Up @@ -174,27 +173,17 @@ export default class CalculusGrapherModel implements TModel {
this.secondDerivativeCurve = new DerivativeCurve( this.derivativeCurve, createCurveTandem( GraphType.SECOND_DERIVATIVE ) );
this.integralCurve = new IntegralCurve( this.originalCurve, createCurveTandem( GraphType.INTEGRAL ) );

const toolsTandem = options.tandem.createTandem( 'tools' );
this.toolsTandem = options.tandem.createTandem( 'tools' );

this.referenceLine = new ReferenceLine(
this.integralCurve, this.originalCurve, this.derivativeCurve, this.secondDerivativeCurve,
toolsTandem.createTandem( 'referenceLine' )
);

this.tangentScrubber = new TangentScrubber(
this.integralCurve, this.originalCurve, this.derivativeCurve, this.secondDerivativeCurve,
options.phetioTangentScrubberInstrumented ? toolsTandem.createTandem( 'tangentScrubber' ) : Tandem.OPT_OUT
);

this.areaUnderCurveScrubber = new AreaUnderCurveScrubber(
this.integralCurve, this.originalCurve, this.derivativeCurve, this.secondDerivativeCurve,
options.phetioAreaUnderCurveScrubberInstrumented ? toolsTandem.createTandem( 'areaUnderCurveScrubber' ) : Tandem.OPT_OUT
this.toolsTandem.createTandem( 'referenceLine' )
);

// This exists so that we have something we can link to from the view.
// See https://github.com/phetsims/calculus-grapher/issues/198
this.labeledPointsLinkableElement = new PhetioObject( {
tandem: toolsTandem.createTandem( 'labeledPoints' ),
tandem: this.toolsTandem.createTandem( 'labeledPoints' ),
phetioState: false
} );

Expand All @@ -210,7 +199,7 @@ export default class CalculusGrapherModel implements TModel {
// This exists so that we have something we can link to from the view.
// See https://github.com/phetsims/calculus-grapher/issues/198
this.labeledLinesLinkableElement = new PhetioObject( {
tandem: toolsTandem.createTandem( 'labeledLines' ),
tandem: this.toolsTandem.createTandem( 'labeledLines' ),
phetioState: false
} );

Expand All @@ -237,8 +226,6 @@ export default class CalculusGrapherModel implements TModel {

// Reset tools
this.referenceLine.reset();
this.tangentScrubber.reset();
this.areaUnderCurveScrubber.reset();
// Do not reset this.labeledPoints, because they are configured only via PhET-iO.
// Do not reset this.labeledLines, because they are configured only via PhET-iO.
}
Expand Down
14 changes: 13 additions & 1 deletion js/derivative/model/DerivativeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import CalculusGrapherModel, { CalculusGrapherModelOptions } from '../../common/
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import CurveManipulationMode from '../../common/model/CurveManipulationMode.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import TangentScrubber from '../../common/model/TangentScrubber.js';

type SelfOptions = EmptySelfOptions;

type DerivativeModelOptions = SelfOptions & PickRequired<CalculusGrapherModelOptions, 'graphSets' | 'tandem'>;

export default class DerivativeModel extends CalculusGrapherModel {

public readonly tangentScrubber: TangentScrubber;

public constructor( providedOptions: DerivativeModelOptions ) {

const options = optionize<DerivativeModelOptions, SelfOptions, CalculusGrapherModelOptions>()( {
Expand All @@ -31,10 +34,19 @@ export default class DerivativeModel extends CalculusGrapherModel {
CurveManipulationMode.TILT,
CurveManipulationMode.SHIFT
],
phetioTangentScrubberInstrumented: true
hasTangentScrubber: true
}, providedOptions );

super( options );

this.tangentScrubber = new TangentScrubber( this.integralCurve, this.originalCurve, this.derivativeCurve,
this.secondDerivativeCurve, this.toolsTandem.createTandem( 'tangentScrubber' )
);
}

public override reset(): void {
this.tangentScrubber.reset();
super.reset();
}
}
calculusGrapher.register( 'DerivativeModel', DerivativeModel );
2 changes: 1 addition & 1 deletion js/integral/IntegralScreen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2023, University of Colorado Boulder

/**
* The 'Integral Lab' screen.
* The 'Integral' screen.
*
* @author Brandon Li
* @author Martin Veillette
Expand Down
15 changes: 13 additions & 2 deletions js/integral/model/IntegralModel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2023, University of Colorado Boulder

/**
* Top-level model for the 'Integral Lab' screen.
* Top-level model for the 'Integral' screen.
*
* @author Brandon Li
* @author Martin Veillette
Expand All @@ -13,13 +13,16 @@ import CalculusGrapherModel, { CalculusGrapherModelOptions } from '../../common/
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import CurveManipulationMode from '../../common/model/CurveManipulationMode.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import AreaUnderCurveScrubber from '../../common/model/AreaUnderCurveScrubber.js';

type SelfOptions = EmptySelfOptions;

type IntegralModelOptions = SelfOptions & PickRequired<CalculusGrapherModelOptions, 'graphSets' | 'tandem'>;

export default class IntegralModel extends CalculusGrapherModel {

public readonly areaUnderCurveScrubber: AreaUnderCurveScrubber;

public constructor( providedOptions: IntegralModelOptions ) {

const options = optionize<IntegralModelOptions, SelfOptions, CalculusGrapherModelOptions>()( {
Expand All @@ -31,10 +34,18 @@ export default class IntegralModel extends CalculusGrapherModel {
CurveManipulationMode.TILT,
CurveManipulationMode.SHIFT
],
phetioAreaUnderCurveScrubberInstrumented: true
hasAreaUnderCurveScrubber: true
}, providedOptions );

super( options );

this.areaUnderCurveScrubber = new AreaUnderCurveScrubber( this.integralCurve, this.originalCurve,
this.derivativeCurve, this.secondDerivativeCurve, this.toolsTandem.createTandem( 'areaUnderCurveScrubber' ) );
}

public override reset(): void {
this.areaUnderCurveScrubber.reset();
super.reset();
}
}

Expand Down

1 comment on commit d4e5827

@pixelzoom
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.