Skip to content

Commit

Permalink
convert deltaX from a getter to a field, #311
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Mar 23, 2023
1 parent 7b60d7c commit baab2e7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions js/common/model/Curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export default class Curve extends PhetioObject {
// Number of points (evenly-spaced along the x-axis) that will be used to approximate the curve
public readonly numberOfPoints: number;

// Delta between x coordinate values
protected readonly deltaX: number;

protected constructor( providedOptions: CurveOptions ) {

const options = optionize<CurveOptions, SelfOptions, PhetioObjectOptions>()( {
Expand All @@ -85,9 +88,9 @@ export default class Curve extends PhetioObject {

super( options );

// create a reference to these option fields
this.xRange = options.xRange;
this.numberOfPoints = options.numberOfPoints;
this.deltaX = this.xRange.getLength() / ( this.numberOfPoints - 1 );

// Initial points, with equally-spaced x values, and y=0.
// These CurvePoint instances are reused throughout the lifetime of the sim, and never disposed.
Expand Down Expand Up @@ -171,10 +174,6 @@ export default class Curve extends PhetioObject {
return Utils.roundSymmetric( normalizedValue * ( this.numberOfPoints - 1 ) );
}

protected get deltaX(): number {
return this.xRange.getLength() / ( this.numberOfPoints - 1 );
}

/**
* Gets the index of the array whose x-value is closest to the given x-value.
*/
Expand Down

0 comments on commit baab2e7

Please sign in to comment.