Skip to content

Commit

Permalink
Rename WaveTemporalType=>DisturbanceType, see #269
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 19, 2018
1 parent 2dc5056 commit 0d55921
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ define( require => {
const Enumeration = require( 'PHET_CORE/Enumeration' );
const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' );

return waveInterference.register( 'WaveTemporalType', new Enumeration( [ 'PULSE', 'CONTINUOUS' ] ) );
return waveInterference.register( 'DisturbanceType', new Enumeration( [ 'PULSE', 'CONTINUOUS' ] ) );
} );
20 changes: 10 additions & 10 deletions js/common/model/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ define( require => {
const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' );
const WaveInterferenceConstants = require( 'WAVE_INTERFERENCE/common/WaveInterferenceConstants' );
const WaveSpatialType = require( 'WAVE_INTERFERENCE/common/model/WaveSpatialType' );
const WaveTemporalType = require( 'WAVE_INTERFERENCE/common/model/WaveTemporalType' );
const DisturbanceType = require( 'WAVE_INTERFERENCE/common/model/DisturbanceType' );

// strings
const distanceUnitsString = require( 'string!WAVE_INTERFERENCE/distanceUnits' );
Expand Down Expand Up @@ -179,18 +179,18 @@ define( require => {
// @public {NumberProperty} - controls the amplitude of the wave.
this.amplitudeProperty = new NumberProperty( config.initialAmplitude, { range: new Range( 0, 10 ) } );

// @public {Property.<WaveTemporalType>} - pulse or continuous
this.waveTemporalTypeProperty = new Property( WaveTemporalType.CONTINUOUS, {
validValues: WaveTemporalType.VALUES
// @public {Property.<DisturbanceType>} - pulse or continuous
this.disturbanceTypeProperty = new Property( DisturbanceType.CONTINUOUS, {
validValues: DisturbanceType.VALUES
} );

// The first button can trigger a pulse, or continuous wave, depending on the waveTemporalTypeProperty
// The first button can trigger a pulse, or continuous wave, depending on the disturbanceTypeProperty
this.button1PressedProperty.lazyLink( isPressed => {
if ( config.sceneType !== SceneType.WATER ) {
if ( isPressed ) {
this.resetPhase();
}
if ( isPressed && this.waveTemporalTypeProperty.value === WaveTemporalType.PULSE ) {
if ( isPressed && this.disturbanceTypeProperty.value === DisturbanceType.PULSE ) {
this.startPulse();
}
else {
Expand Down Expand Up @@ -245,8 +245,8 @@ define( require => {
// @public {BooleanProperty} - true when the second source is continuously oscillating
this.continuousWave2OscillatingProperty = new BooleanProperty( false );

// When the user changes temporal wave type, the button pops out and waves stop
this.waveTemporalTypeProperty.link( inputType => {
// When the user changes disturbance type, the button pops out and waves stop
this.disturbanceTypeProperty.link( inputType => {
this.button1PressedProperty.value = false;
this.continuousWave1OscillatingProperty.value = false;
this.continuousWave2OscillatingProperty.value = false;
Expand Down Expand Up @@ -355,7 +355,7 @@ define( require => {
const period = 1 / frequency;
const timeSincePulseStarted = time - this.pulseStartTime;
const lattice = this.lattice;
const isContinuous = ( this.waveTemporalTypeProperty.get() === WaveTemporalType.CONTINUOUS );
const isContinuous = ( this.disturbanceTypeProperty.get() === DisturbanceType.CONTINUOUS );
const continuous1 = isContinuous && this.continuousWave1OscillatingProperty.get();
const continuous2 = isContinuous && this.continuousWave2OscillatingProperty.get();
if ( continuous1 || continuous2 || this.pulseFiringProperty.get() ) {
Expand Down Expand Up @@ -584,7 +584,7 @@ define( require => {
this.slitSeparationProperty.reset();
this.sourceSeparationProperty.reset();
this.amplitudeProperty.reset();
this.waveTemporalTypeProperty.reset();
this.disturbanceTypeProperty.reset();
this.button1PressedProperty.reset();
this.button2PressedProperty.reset();
this.oscillator1Property.reset();
Expand Down
8 changes: 4 additions & 4 deletions js/common/model/WaterScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define( require => {
const WaterDrop = require( 'WAVE_INTERFERENCE/common/model/WaterDrop' );
const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' );
const WaveSpatialType = require( 'WAVE_INTERFERENCE/common/model/WaveSpatialType' );
const WaveTemporalType = require( 'WAVE_INTERFERENCE/common/model/WaveTemporalType' );
const DisturbanceType = require( 'WAVE_INTERFERENCE/common/model/DisturbanceType' );

class WaterScene extends Scene {

Expand Down Expand Up @@ -67,7 +67,7 @@ define( require => {
} );

// For the water scene, remove water drops so one mode doesn't create waves in the other mode
this.waveTemporalTypeProperty.link( inputType => this.removeAllDrops() );
this.disturbanceTypeProperty.link( inputType => this.removeAllDrops() );
}

/**
Expand All @@ -85,15 +85,15 @@ define( require => {
// Send a water drop if the button is pressed but not if the button is still pressed from the last pulse.
// model.button1PressedProperty.value not consulted because we send a shutoff water drop. so that the previous
// drop gets a full cycle
const isPulseMode = this.waveTemporalTypeProperty.value === WaveTemporalType.PULSE;
const isPulseMode = this.disturbanceTypeProperty.value === DisturbanceType.PULSE;
const firePulseDrop = isPulseMode && !this.pulseFiringProperty.value && this.button1PressedProperty.value;
if ( !isPulseMode || firePulseDrop ) {

// capture closure vars for when the water drop is absorbed.
const buttonPressed = buttonProperty.value;
const frequency = this.desiredFrequencyProperty.value;
const amplitude = this.desiredAmplitudeProperty.value;
const isPulse = this.waveTemporalTypeProperty.value === WaveTemporalType.PULSE;
const isPulse = this.disturbanceTypeProperty.value === DisturbanceType.PULSE;
const sourceSeparation = this.desiredSourceSeparationProperty.value;
this.waterDrops.push( new WaterDrop(
amplitude,
Expand Down
14 changes: 7 additions & 7 deletions js/common/view/EmitterNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define( require => {
const ShadedSphereNode = require( 'SCENERY_PHET/ShadedSphereNode' );
const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' );
const WaveInterferenceConstants = require( 'WAVE_INTERFERENCE/common/WaveInterferenceConstants' );
const WaveTemporalType = require( 'WAVE_INTERFERENCE/common/model/WaveTemporalType' );
const DisturbanceType = require( 'WAVE_INTERFERENCE/common/model/DisturbanceType' );

class EmitterNode extends Node {

Expand All @@ -36,7 +36,7 @@ define( require => {
verticalOffset = 0,
buttonOffset = 0,
showButtonBackground = false ) {
const pulseIcon = new InputTypeIconNode( WaveTemporalType.PULSE, { scale: 0.48 } );
const pulseIcon = new InputTypeIconNode( DisturbanceType.PULSE, { scale: 0.48 } );

const buttonOptions = {
centerY: sourceNode.centerY + buttonOffset,
Expand Down Expand Up @@ -69,20 +69,20 @@ define( require => {
const nodeWithButton = new Node( { children: children } );

const updateEnabled = () => {
if ( scene.waveTemporalTypeProperty.value === WaveTemporalType.PULSE ) {
if ( scene.disturbanceTypeProperty.value === DisturbanceType.PULSE ) {
button.enabled = !scene.pulseFiringProperty.value && !scene.isAboutToFireProperty.value;
}
else if ( scene.waveTemporalTypeProperty.value === WaveTemporalType.CONTINUOUS ) {
else if ( scene.disturbanceTypeProperty.value === DisturbanceType.CONTINUOUS ) {
button.enabled = true;
}
};

// When changing between PULSE and CONTINUOUS, update the buttons.
scene.waveTemporalTypeProperty.link( waveTemporalType => {
button.setBaseColor( waveTemporalType === WaveTemporalType.CONTINUOUS ?
scene.disturbanceTypeProperty.link( disturbanceType => {
button.setBaseColor( disturbanceType === DisturbanceType.CONTINUOUS ?
WaveInterferenceConstants.CONTINUOUS_EMITTER_BUTTON_COLOR :
WaveInterferenceConstants.PULSE_EMITTER_BUTTON_COLOR );
pulseIcon.visible = waveTemporalType === WaveTemporalType.PULSE;
pulseIcon.visible = disturbanceType === DisturbanceType.PULSE;
updateEnabled();
}
);
Expand Down
19 changes: 10 additions & 9 deletions js/common/view/InputTypeIconNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018, University of Colorado Boulder

//REVIEW^ This is a visual representation of WaveTemporalType, so why is this class name totally different? why not WaveTermTypeNode?
//REVIEW: Note to self, WaveTemporalType became DisturbanceType
/**
* Shows the icons for the radio buttons that choose between pulse and continuous waves.
*
Expand All @@ -15,7 +16,7 @@ define( require => {
const Shape = require( 'KITE/Shape' );
const Util = require( 'DOT/Util' );
const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' );
const WaveTemporalType = require( 'WAVE_INTERFERENCE/common/model/WaveTemporalType' );
const DisturbanceType = require( 'WAVE_INTERFERENCE/common/model/DisturbanceType' );

// constants
const NUMBER_OF_SAMPLES = 100; // Number of samples to take along the curve
Expand All @@ -27,27 +28,27 @@ define( require => {
class InputTypeIconNode extends Node {

//REVIEW rename to waveTemporalType
//REVIEW* done, please review
//REVIEW* done, please review. UPDATE: also renamed to disturbanceType
/**
* @param {WaveTemporalType} waveTemporalType
* @param {DisturbanceType} disturbanceType
* @param {Object} [options]
*/
constructor( waveTemporalType, options ) {
constructor( disturbanceType, options ) {
super();

//REVIEW Implementation is unnecessarily complicated because you're trying to do both icons in one class. Separate into 2 classes?
//REVIEW* That would lead to a significant amount of duplicated code. What do you recommend?
const minAngle = waveTemporalType === WaveTemporalType.PULSE ? Math.PI : 0;
const minX = waveTemporalType === WaveTemporalType.PULSE ? MARGIN : 0;
const maxX = waveTemporalType === WaveTemporalType.PULSE ? ( WIDTH - MARGIN ) : WIDTH;
const minAngle = disturbanceType === DisturbanceType.PULSE ? Math.PI : 0;
const minX = disturbanceType === DisturbanceType.PULSE ? MARGIN : 0;
const maxX = disturbanceType === DisturbanceType.PULSE ? ( WIDTH - MARGIN ) : WIDTH;

const shape = new Shape();
for ( let i = 0; i < NUMBER_OF_SAMPLES; i++ ) {
const angle = Util.linear( 0, NUMBER_OF_SAMPLES - 1, minAngle, MAX_ANGLE, i );
const y = -Math.cos( angle ) * WAVE_HEIGHT;
const x = Util.linear( minAngle, MAX_ANGLE, minX, maxX, angle );
if ( i === 0 ) {
if ( waveTemporalType === WaveTemporalType.PULSE ) {
if ( disturbanceType === DisturbanceType.PULSE ) {
shape.moveTo( x - MARGIN, y );
shape.lineTo( x, y );
}
Expand All @@ -59,7 +60,7 @@ define( require => {
shape.lineTo( x, y );
}
}
if ( waveTemporalType === WaveTemporalType.PULSE ) {
if ( disturbanceType === DisturbanceType.PULSE ) {
shape.lineToRelative( MARGIN, 0 );
}

Expand Down
17 changes: 9 additions & 8 deletions js/common/view/PulseContinuousRadioButtonGroup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018, University of Colorado Boulder

//REVIEW^ since this is related to WaveTemporalType, rename to WaveTemporalTypeRadioButtonGroup ?
//REVIEW: Note to self, WaveTemporalType became DisturbanceType
/**
* Shows the "pulse" vs "continuous" radio buttons.
*
Expand All @@ -13,21 +14,21 @@ define( require => {
const InputTypeIconNode = require( 'WAVE_INTERFERENCE/common/view/InputTypeIconNode' );
const RadioButtonGroup = require( 'SUN/buttons/RadioButtonGroup' );
const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' );
const WaveTemporalType = require( 'WAVE_INTERFERENCE/common/model/WaveTemporalType' );
const DisturbanceType = require( 'WAVE_INTERFERENCE/common/model/DisturbanceType' );

class PulseContinuousRadioButtonGroup extends RadioButtonGroup {

/**
* @param {Property.<WaveTemporalType>} waveTemporalTypeProperty
* @param {Property.<DisturbanceType>} disturbanceTypeProperty
* @param {Object} [options]
*/
constructor( waveTemporalTypeProperty, options ) {
super( waveTemporalTypeProperty, [ {
value: WaveTemporalType.CONTINUOUS,
node: new InputTypeIconNode( WaveTemporalType.CONTINUOUS )
constructor( disturbanceTypeProperty, options ) {
super( disturbanceTypeProperty, [ {
value: DisturbanceType.CONTINUOUS,
node: new InputTypeIconNode( DisturbanceType.CONTINUOUS )
}, {
value: WaveTemporalType.PULSE,
node: new InputTypeIconNode( WaveTemporalType.PULSE )
value: DisturbanceType.PULSE,
node: new InputTypeIconNode( DisturbanceType.PULSE )
} ], _.extend( {
orientation: 'vertical',
buttonContentXMargin: 0,
Expand Down
2 changes: 1 addition & 1 deletion js/waves/view/WavesScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ define( require => {

this.addChild( new SceneToggleNode(
model,
scene => new PulseContinuousRadioButtonGroup( scene.waveTemporalTypeProperty ), {
scene => new PulseContinuousRadioButtonGroup( scene.disturbanceTypeProperty ), {
bottom: this.waveAreaNode.bottom,
centerX: ( this.waveAreaNode.left + this.layoutBounds.left ) / 2
} ) );
Expand Down

0 comments on commit 0d55921

Please sign in to comment.