Skip to content

Commit

Permalink
reduce coupling, see #339
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Aug 4, 2023
1 parent 5696a19 commit 5ac22a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions js/waves/view/WaveLandscapeObservationWindow.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2021-2023, University of Colorado Boulder

/**
* WaveLandscapeObservationWindow adds the ability to depict electromagnetic waves to its parent class.
* WaveLandscapeObservationWindow is a specialization class that adds the ability to depict electromagnetic waves to its
* parent class.
*
* @author John Blanco (PhET Interactive Simulations)
*/
Expand All @@ -23,7 +24,7 @@ class WaveLandscapeObservationWindow extends LandscapeObservationWindow {

super( model, options );

const wavesCanvasNode = new WavesCanvasNode( model, this.modelViewTransform, {
const wavesCanvasNode = new WavesCanvasNode( model.waveGroup, this.modelViewTransform, {
canvasBounds: GreenhouseEffectObservationWindow.SIZE.toBounds(),
tandem: options.tandem.createTandem( 'wavesCanvasNode' )
} );
Expand Down
13 changes: 8 additions & 5 deletions js/waves/view/WavesCanvasNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import { CanvasNode, CanvasNodeOptions, ColorProperty } from '../../../../scener
import GreenhouseEffectColors from '../../common/GreenhouseEffectColors.js';
import GreenhouseEffectConstants from '../../common/GreenhouseEffectConstants.js';
import greenhouseEffect from '../../greenhouseEffect.js';
import Wave from '../model/Wave.js';
import Wave, { WaveCreatorArguments } from '../model/Wave.js';
import WavesModel from '../model/WavesModel.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import PhetioGroup from '../../../../tandem/js/PhetioGroup.js';

// constants
const TWO_PI = 2 * Math.PI;
Expand All @@ -42,22 +43,24 @@ type SelfOptions = EmptySelfOptions;
type WavesCanvasNodeOptions = SelfOptions & PickRequired<CanvasNode, 'canvasBounds' | 'tandem'>;

class WavesCanvasNode extends CanvasNode {
private readonly model: WavesModel;
private readonly waveGroup: PhetioGroup<Wave, WaveCreatorArguments>;
private readonly modelViewTransform: ModelViewTransform2;

// A JS Map of the parameters used to render waves of different wavelengths. The key is the wavelength and the value
// is the set of rendering parameters that define the visual appearance of the wave.
private readonly waveRenderingParameterMap: Map<number, RenderingParameters>;

public constructor( model: WavesModel, modelViewTransform: ModelViewTransform2, providedOptions: WavesCanvasNodeOptions ) {
public constructor( waveGroup: PhetioGroup<Wave, WaveCreatorArguments>,
modelViewTransform: ModelViewTransform2,
providedOptions: WavesCanvasNodeOptions ) {

const options = optionize<WavesCanvasNodeOptions, SelfOptions, CanvasNodeOptions>()( {
isDisposable: false,
visiblePropertyOptions: { phetioFeatured: true }
}, providedOptions );

super( options );
this.model = model;
this.waveGroup = waveGroup;
this.modelViewTransform = modelViewTransform;

const modelVisibleWavelength = WavesModel.REAL_TO_RENDERING_WAVELENGTH_MAP.get( GreenhouseEffectConstants.VISIBLE_WAVELENGTH );
Expand Down Expand Up @@ -90,7 +93,7 @@ class WavesCanvasNode extends CanvasNode {
}

public override paintCanvas( context: CanvasRenderingContext2D ): void {
this.model.waveGroup.forEach( wave => this.drawWave( context, wave ) );
this.waveGroup.forEach( wave => this.drawWave( context, wave ) );
}

/**
Expand Down

0 comments on commit 5ac22a0

Please sign in to comment.