phetsims / calculus-grapher

"Calculus Grapher" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
4 stars 4 forks source link

Convert Curve `deltaX` from getter to field #311

Closed pixelzoom closed 1 year ago

pixelzoom commented 1 year ago

In Curve.ts:

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

Both of the quantities used to compute deltaX are constants, so deltaX is a constant. So it's preferrable to convert deltaX to protected readonly deltaX: number and compute it once in the constructor.

It's unlikely to make a noticable performance difference. But deltaX is used in loops, like this one in TransformedCurve smooth:

      for ( let dx = this.deltaX; dx <= numberOfStandardDeviations * STANDARD_DEVIATION;
            dx += this.deltaX ) {

@veillette any reason why I shouldn't do this?

veillette commented 1 year ago

No go ahead.

pixelzoom commented 1 year ago

This was relatively trivial, so I'll go ahead and close. But @veillette feel free to have a look.