Skip to content

Commit

Permalink
pass options to Curve in preparation for instrumentation (see #48)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Veillette <[email protected]>
  • Loading branch information
veillette committed Sep 22, 2022
1 parent d48d683 commit 1572099
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
6 changes: 3 additions & 3 deletions js/common/model/CalculusGrapherModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default class CalculusGrapherModel {
const options = optionize<CalculusGrapherModelOptions, SelfOptions>()( {}, providedOptions );

this.originalCurve = new OriginalCurve( options );
this.derivativeCurve = new DerivativeCurve( this.originalCurve );
this.secondDerivativeCurve = new DerivativeCurve( this.derivativeCurve );
this.integralCurve = new IntegralCurve( this.originalCurve );
this.derivativeCurve = new DerivativeCurve( this.originalCurve, options );
this.secondDerivativeCurve = new DerivativeCurve( this.derivativeCurve, options );
this.integralCurve = new IntegralCurve( this.originalCurve, options );

}
}
Expand Down
10 changes: 8 additions & 2 deletions js/common/model/Curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

import Emitter from '../../../../axon/js/Emitter.js';
import Utils from '../../../../dot/js/Utils.js';
import { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import calculusGrapher from '../../calculusGrapher.js';
import CalculusGrapherConstants from '../CalculusGrapherConstants.js';
import CalculusGrapherQueryParameters from '../CalculusGrapherQueryParameters.js';
Expand All @@ -32,6 +35,10 @@ import CurvePoint from './CurvePoint.js';
const CURVE_X_RANGE = CalculusGrapherConstants.CURVE_X_RANGE;
const POINTS_PER_COORDINATE = CalculusGrapherQueryParameters.pointsPerCoordinate;

type SelfOptions = EmptySelfOptions;

export type CurveOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>;

export default class Curve {

public readonly points: CurvePoint[];
Expand All @@ -43,8 +50,7 @@ export default class Curve {

public cusps: CurvePoint[] | null;


public constructor() {
public constructor( providedOptions: CurveOptions ) {

// the Points that map out the curve at a finite number of partitions within
// the domain. See the comment at the top of this file for full context.
Expand Down
14 changes: 12 additions & 2 deletions js/common/model/DerivativeCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@
*/

import Vector2 from '../../../../dot/js/Vector2.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 calculusGrapher from '../../calculusGrapher.js';
import CalculusGrapherQueryParameters from '../CalculusGrapherQueryParameters.js';
import CalculusGrapherUtils from '../CalculusGrapherUtils.js';
import Curve from './Curve.js';
import { IntegralCurveOptions } from './IntegralCurve.js';

// constants
const DERIVATIVE_THRESHOLD = CalculusGrapherQueryParameters.derivativeThreshold;

type SelfOptions = EmptySelfOptions;

export type DerivativeCurveOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>;

export default class DerivativeCurve extends Curve {

// reference to the 'base' Curve that was passed-in.
Expand All @@ -37,9 +45,11 @@ export default class DerivativeCurve extends Curve {
/**
* @param baseCurve - the curve to differentiate to get the values of this DerivativeCurve.
*/
public constructor( baseCurve: Curve ) {
public constructor( baseCurve: Curve, providedOptions?: DerivativeCurveOptions ) {

const options = optionize<IntegralCurveOptions, SelfOptions>()( {}, providedOptions );

super();
super( options );

this.baseCurve = baseCurve;

Expand Down
14 changes: 11 additions & 3 deletions js/common/model/IntegralCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,31 @@
* @author Brandon Li
*/

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 calculusGrapher from '../../calculusGrapher.js';
import CalculusGrapherUtils from '../CalculusGrapherUtils.js';
import Curve from './Curve.js';
import OriginalCurve from './OriginalCurve.js';

type SelfOptions = EmptySelfOptions;

export type IntegralCurveOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>;

export default class IntegralCurve extends Curve {

// reference to the 'base' Curve that was passed-in.
private baseCurve: OriginalCurve;


/**
* @param baseCurve - the curve to integrate to get the values of this IntegralCurve.
*/
public constructor( baseCurve: OriginalCurve ) {
public constructor( baseCurve: OriginalCurve, providedOptions?: IntegralCurveOptions ) {

const options = optionize<IntegralCurveOptions, SelfOptions>()( {}, providedOptions );

super();
super( options );

this.baseCurve = baseCurve;

Expand Down
4 changes: 2 additions & 2 deletions js/common/model/OriginalCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export default class OriginalCurve extends Curve {
// user-manipulation.
public curveManipulationWidthProperty: NumberProperty;

public constructor( providedOptions: OriginalCurveOptions ) {
public constructor( providedOptions?: OriginalCurveOptions ) {

const options = optionize<OriginalCurveOptions, SelfOptions>()( {}, providedOptions );

super();
super( options );

this.curveManipulationModeProperty = new EnumerationProperty( CurveManipulationMode.HILL, {
tandem: options.tandem.createTandem( 'curveManipulationModeProperty' )
Expand Down

0 comments on commit 1572099

Please sign in to comment.