Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Nov 1, 2021
1 parent 86703a6 commit 679fe3b
Show file tree
Hide file tree
Showing 29 changed files with 180 additions and 175 deletions.
12 changes: 6 additions & 6 deletions js/model/ACVoltage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ class ACVoltage extends VoltageSource {
* @param {Vertex} endVertex - the other battery vertex
* @param {Property.<number>} internalResistanceProperty - the resistance of the battery
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( startVertex: Vertex, endVertex: Vertex, internalResistanceProperty: Property<number>, tandem: Tandem, options?: Partial<ACVoltageOptions> ) {
constructor( startVertex: Vertex, endVertex: Vertex, internalResistanceProperty: Property<number>, tandem: Tandem, providedOptions?: Partial<ACVoltageOptions> ) {
assert && assert( internalResistanceProperty, 'internalResistanceProperty should be defined' );
const filledOptions = merge( {
const options = merge( {
initialOrientation: 'right',
voltage: 9.0,
isFlammable: true,
numberOfDecimalPlaces: 1,
voltagePropertyOptions: {
range: new Range( -MAX_VOLTAGE, MAX_VOLTAGE )
}
}, options ) as ACVoltageOptions;
super( startVertex, endVertex, internalResistanceProperty, CCKCConstants.BATTERY_LENGTH, tandem, filledOptions );
}, providedOptions ) as ACVoltageOptions;
super( startVertex, endVertex, internalResistanceProperty, CCKCConstants.BATTERY_LENGTH, tandem, options );

// @public {NumberProperty} - the maximum voltage, which can be controlled by the CircuitElementNumberControl
this.maximumVoltageProperty = new NumberProperty( filledOptions.voltage, {
this.maximumVoltageProperty = new NumberProperty( options.voltage, {
tandem: tandem.createTandem( 'maximumVoltageProperty' ),
range: new Range( 0, MAX_VOLTAGE )
} );
Expand Down
7 changes: 4 additions & 3 deletions js/model/Battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class Battery extends VoltageSource {
* @param {Property.<number>} internalResistanceProperty - the resistance of the battery
* @param {BatteryType} batteryType
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( startVertex: Vertex, endVertex: Vertex, internalResistanceProperty: Property<number>, batteryType: BatteryType, tandem: Tandem, options?: Partial<BatteryOptions> ) {
constructor( startVertex: Vertex, endVertex: Vertex, internalResistanceProperty: Property<number>, batteryType: BatteryType,
tandem: Tandem, providedOptions?: Partial<BatteryOptions> ) {
assert && assert( internalResistanceProperty, 'internalResistanceProperty should be defined' );
const filledOptions = merge( {
initialOrientation: 'right',
Expand All @@ -44,7 +45,7 @@ class Battery extends VoltageSource {
voltagePropertyOptions: {
range: batteryType === 'normal' ? new Range( 0, 120 ) : new Range( 100, 100000 )
}
}, options ) as BatteryOptions;
}, providedOptions ) as BatteryOptions;
super( startVertex, endVertex, internalResistanceProperty, BATTERY_LENGTH, tandem, filledOptions );

// @public (read-only) {string} - track which way the battery "button" (plus side) was facing the initial state so
Expand Down
12 changes: 6 additions & 6 deletions js/model/Capacitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ class Capacitor extends DynamicCircuitElement {
* @param {Vertex} startVertex
* @param {Vertex} endVertex
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( startVertex: Vertex, endVertex: Vertex, tandem: Tandem, options?: Partial<CapacitorOptions> ) {
const filledOptions = merge( {
constructor( startVertex: Vertex, endVertex: Vertex, tandem: Tandem, providedOptions?: Partial<CapacitorOptions> ) {
const options = merge( {
capacitance: CCKCConstants.DEFAULT_CAPACITANCE,

// The number of decimal places is only used in the view, but we define it in the model as a convenient way to
// associate the value with the component
numberOfDecimalPlaces: 2
}, options ) as CapacitorOptions;
}, providedOptions ) as CapacitorOptions;

super( startVertex, endVertex, CCKCConstants.CAPACITOR_LENGTH, tandem, filledOptions );
super( startVertex, endVertex, CCKCConstants.CAPACITOR_LENGTH, tandem, options );

// @public {Property.<number>} the capacitance in farads
this.capacitanceProperty = new NumberProperty( filledOptions.capacitance, {
this.capacitanceProperty = new NumberProperty( options.capacitance, {
range: new Range( 0.05, 0.20 ),
tandem: tandem.createTandem( 'capacitanceProperty' )
} );
Expand Down
9 changes: 5 additions & 4 deletions js/model/Circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,19 @@ class Circuit {
* @param {Property.<CircuitElementViewType>} viewTypeProperty
* @param {Property.<boolean>} addRealBulbsProperty
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( viewTypeProperty: Property<CircuitElementViewType>, addRealBulbsProperty: Property<boolean>, tandem: Tandem, options?: Partial<CircuitOptions> ) {
constructor( viewTypeProperty: Property<CircuitElementViewType>, addRealBulbsProperty: Property<boolean>, tandem: Tandem,
providedOptions?: Partial<CircuitOptions> ) {

// @public
this.viewTypeProperty = viewTypeProperty;
this.addRealBulbsProperty = addRealBulbsProperty;

const filledOptions = merge( { blackBoxStudy: false }, options ) as CircuitOptions;
const options = merge( { blackBoxStudy: false }, providedOptions ) as CircuitOptions;

// @public {Object}
this.blackBoxStudy = filledOptions.blackBoxStudy;
this.blackBoxStudy = options.blackBoxStudy;

// @public {NumberProperty} - All wires share the same resistivity, which is defined by
// resistance = resistivity * length. On the Lab Screen, there is a wire resistivity control
Expand Down
12 changes: 6 additions & 6 deletions js/model/CircuitConstructionKitModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ class CircuitConstructionKitModel {

/**
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( tandem: Tandem, options?: Partial<CircuitConstructionKitModelOptions> ) {
constructor( tandem: Tandem, providedOptions?: Partial<CircuitConstructionKitModelOptions> ) {

const filledOptions = merge( {
const options = merge( {

// Determines whether electrons can be shown. In black box, electrons can only be shown when the user reveals
// the answer by pressing the reveal answer button.
revealing: true,
blackBoxStudy: false
}, options ) as CircuitConstructionKitModelOptions;
}, providedOptions ) as CircuitConstructionKitModelOptions;

// @private {ZoomAnimation|null} - animation for the zoom level or null if not animating
this.zoomAnimation = null;
Expand All @@ -83,7 +83,7 @@ class CircuitConstructionKitModel {
} );

// @public (read-only) {Circuit} - contains CircuitElements, Vertices, etc.
this.circuit = new Circuit( this.viewTypeProperty, this.addRealBulbsProperty, tandem.createTandem( 'circuit' ), { blackBoxStudy: filledOptions.blackBoxStudy } );
this.circuit = new Circuit( this.viewTypeProperty, this.addRealBulbsProperty, tandem.createTandem( 'circuit' ), { blackBoxStudy: options.blackBoxStudy } );

// @public (read-only) {Voltmeter[]} - created statically and indexed starting at 1 for human-readability for PhET-iO
this.voltmeters = [
Expand Down Expand Up @@ -209,7 +209,7 @@ class CircuitConstructionKitModel {
} );

// @public - true when the user is holding down the reveal button and the answer (inside the black box) is showing
this.revealingProperty = new BooleanProperty( filledOptions.revealing, {
this.revealingProperty = new BooleanProperty( options.revealing, {
tandem: tandem.createTandem( 'revealingProperty' )
} );

Expand Down
24 changes: 12 additions & 12 deletions js/model/CircuitElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ abstract class CircuitElement extends PhetioObject {
* @param {Vertex} endVertex
* @param {number} chargePathLength
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( startVertex: Vertex, endVertex: Vertex, chargePathLength: number, tandem: Tandem, options?: Partial<CircuitElementOptions> ) {
constructor( startVertex: Vertex, endVertex: Vertex, chargePathLength: number, tandem: Tandem, providedOptions?: Partial<CircuitElementOptions> ) {
assert && assert( startVertex !== endVertex, 'startVertex cannot be the same as endVertex' );
assert && assert( typeof chargePathLength === 'number', 'charge path length should be a number' );
assert && assert( chargePathLength > 0, 'charge path length must be positive' );

const filledOptions = merge( {
const options = merge( {
canBeDroppedInToolbox: true, // In the CCK: Basics intro screen, CircuitElements can't be dropped into the toolbox
interactive: true, // In CCK: Black Box Study, CircuitElements in the black box cannot be manipulated
isSizeChangedOnViewChange: true,
Expand All @@ -90,9 +90,9 @@ abstract class CircuitElement extends PhetioObject {
isCurrentReentrant: false,
phetioDynamicElement: true,
phetioType: CircuitElement.CircuitElementIO
}, options ) as CircuitElementOptions;
}, providedOptions ) as CircuitElementOptions;

super( filledOptions );
super( options );

// @public (read-only) {number} unique identifier for looking up corresponding views
this.id = index++;
Expand All @@ -102,19 +102,19 @@ abstract class CircuitElement extends PhetioObject {
this.creationTime = phet.joist.elapsedTime;

// @public (read-only) {boolean} flammable circuit elements can catch on fire
this.isFlammable = filledOptions.isFlammable;
this.isFlammable = options.isFlammable;

// @public (read-only) {boolean} metallic circuit elements behave like exposed wires--sensor values can be read
// directly on the resistor. For instance, coins and paper clips and wires are metallic and can have their values
// read directly.
this.isMetallic = filledOptions.isMetallic;
this.isMetallic = options.isMetallic;

// @public (read-only) {boolean} - whether the size changes when changing from lifelike/schematic, used to determine
// whether the highlight region should be changed. True for everything except the switch.
this.isSizeChangedOnViewChange = filledOptions.isSizeChangedOnViewChange;
this.isSizeChangedOnViewChange = options.isSizeChangedOnViewChange;

// @public (read-only) {number} - whether it is possible to drop the CircuitElement in the toolbox
this.canBeDroppedInToolbox = filledOptions.canBeDroppedInToolbox;
this.canBeDroppedInToolbox = options.canBeDroppedInToolbox;

// @public {Property.<Vertex>} - the Vertex at the origin of the CircuitElement, may change when CircuitElements are
// connected
Expand All @@ -126,7 +126,7 @@ abstract class CircuitElement extends PhetioObject {

// @public {NumberProperty} - the flowing current, in amps.
this.currentProperty = new NumberProperty( 0, {
reentrant: filledOptions.isCurrentReentrant
reentrant: options.isCurrentReentrant
} );
this.currentProperty.link( ( current: number ) => {
assert && assert( !isNaN( current ) );
Expand All @@ -137,11 +137,11 @@ abstract class CircuitElement extends PhetioObject {
this.currentSenseProperty = new Property( 'unspecified' );

// @public (read-only) {BooleanProperty} - true if the CircuitElement can be edited and dragged
this.interactiveProperty = new BooleanProperty( filledOptions.interactive );
this.interactiveProperty = new BooleanProperty( options.interactive );

// @public {BooleanProperty} - whether the circuit element is inside the true black box, not inside the user-created
// black box, on the interface or outside of the black box
this.insideTrueBlackBoxProperty = new BooleanProperty( filledOptions.insideTrueBlackBox );
this.insideTrueBlackBoxProperty = new BooleanProperty( options.insideTrueBlackBox );

// @public {boolean} - true if the charge layout must be updated (each element is visited every frame to check this)
this.chargeLayoutDirty = true;
Expand Down
6 changes: 3 additions & 3 deletions js/model/Dog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Dog extends Resistor {
* @param {Vertex} startVertex
* @param {Vertex} endVertex
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( startVertex: Vertex, endVertex: Vertex, tandem: Tandem, options?: ResistorOptions ) {
super( startVertex, endVertex, Resistor.ResistorType.DOG, tandem, options );
constructor( startVertex: Vertex, endVertex: Vertex, tandem: Tandem, providedOptions?: ResistorOptions ) {
super( startVertex, endVertex, Resistor.ResistorType.DOG, tandem, providedOptions );

// @private - keep track of whether the dog is barking, so we can update the view accordingly
this.isBarkingProperty = new BooleanProperty( false );
Expand Down
6 changes: 3 additions & 3 deletions js/model/DynamicCircuitElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ abstract class DynamicCircuitElement extends FixedCircuitElement {
* @param {Vertex} endVertex
* @param {number} length
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/

constructor( startVertex: Vertex, endVertex: Vertex, length: number, tandem: Tandem, options?: Partial<DynamicCircuitElementOptions> ) {
super( startVertex, endVertex, length, tandem, options );
constructor( startVertex: Vertex, endVertex: Vertex, length: number, tandem: Tandem, providedOptions?: Partial<DynamicCircuitElementOptions> ) {
super( startVertex, endVertex, length, tandem, providedOptions );

// @public {number} - value of the voltage drop set and read by the modified nodal analysis. This is in addition
// to the typical voltage calculation which is based on vertices.
Expand Down
12 changes: 6 additions & 6 deletions js/model/FixedCircuitElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ abstract class FixedCircuitElement extends CircuitElement {
* @param {Vertex} endVertex
* @param {number} chargePathLength - the distance the charges travel (in view coordinates), see CircuitElement.js
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( startVertex: Vertex, endVertex: Vertex, chargePathLength: number, tandem: Tandem, options?: Partial<FixedCircuitElementOptions> ) {
constructor( startVertex: Vertex, endVertex: Vertex, chargePathLength: number, tandem: Tandem, providedOptions?: Partial<FixedCircuitElementOptions> ) {

const filledOptions = merge( {
const options = merge( {
numberOfDecimalPlaces: 1
}, options ) as FixedCircuitElementOptions;
}, providedOptions ) as FixedCircuitElementOptions;

// Super constructor
super( startVertex, endVertex, chargePathLength, tandem, filledOptions );
super( startVertex, endVertex, chargePathLength, tandem, options );

// @public (read-only) {number} - the number of decimal places to show in readouts and controls
this.numberOfDecimalPlaces = filledOptions.numberOfDecimalPlaces;
this.numberOfDecimalPlaces = options.numberOfDecimalPlaces;

// @public (read-only) {number} The distance from one vertex to another (as the crow flies), used for rotation
// about a vertex
Expand Down
12 changes: 6 additions & 6 deletions js/model/Fuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ class Fuse extends FixedCircuitElement {
* @param {Vertex} startVertex
* @param {Vertex} endVertex
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( startVertex: Vertex, endVertex: Vertex, tandem: Tandem, options?: Partial<FuseOptions> ) {
const filledOptions = merge( {
constructor( startVertex: Vertex, endVertex: Vertex, tandem: Tandem, providedOptions?: Partial<FuseOptions> ) {
const options = merge( {
resistance: CCKCConstants.MINIMUM_RESISTANCE,
fuseLength: CCKCConstants.RESISTOR_LENGTH, // Same length as a resistor
currentRating: 4, // Amps
isCurrentReentrant: true, // Changing the current can trip a fuse, which changes the current
numberOfDecimalPlaces: 1
}, options ) as FuseOptions;
}, providedOptions ) as FuseOptions;

super( startVertex, endVertex, filledOptions.fuseLength, tandem, filledOptions );
super( startVertex, endVertex, options.fuseLength, tandem, options );

// @public {Property.<number>} the current at which the fuse trips, in amps
this.currentRatingProperty = new NumberProperty( filledOptions.currentRating, {
this.currentRatingProperty = new NumberProperty( options.currentRating, {
range: new Range( 0.5, 20 )
} );

Expand Down
12 changes: 6 additions & 6 deletions js/model/Inductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ class Inductor extends DynamicCircuitElement {
* @param {Vertex} startVertex
* @param {Vertex} endVertex
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( startVertex: Vertex, endVertex: Vertex, tandem: Tandem, options?: Partial<InductorOptions> ) {
const filledOptions = merge( {
constructor( startVertex: Vertex, endVertex: Vertex, tandem: Tandem, providedOptions?: Partial<InductorOptions> ) {
const options = merge( {
inductance: CCKCQueryParameters.inductanceDefault,
numberOfDecimalPlaces: CCKCQueryParameters.inductorNumberDecimalPlaces
}, options ) as InductorOptions;
}, providedOptions ) as InductorOptions;

super( startVertex, endVertex, INDUCTOR_LENGTH, tandem, filledOptions );
super( startVertex, endVertex, INDUCTOR_LENGTH, tandem, options );

// @public {Property.<number>} the inductance in Henries
this.inductanceProperty = new NumberProperty( filledOptions.inductance, {
this.inductanceProperty = new NumberProperty( options.inductance, {
range: new Range( CCKCQueryParameters.inductanceMin, CCKCQueryParameters.inductanceMax ),
tandem: tandem.createTandem( 'inductanceProperty' )
} );
Expand Down
16 changes: 8 additions & 8 deletions js/model/Resistor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ class Resistor extends FixedCircuitElement {
* @param {Vertex} endVertex
* @param {Resistor.ResistorType} resistorType
* @param {Tandem} tandem
* @param {Object} [options]
* @param {Object} [providedOptions]
*/
constructor( startVertex: Vertex, endVertex: Vertex, resistorType: any, tandem: Tandem, options?: Partial<ResistorOptions> ) {
const filledOptions = merge( {
constructor( startVertex: Vertex, endVertex: Vertex, resistorType: any, tandem: Tandem, providedOptions?: Partial<ResistorOptions> ) {
const options = merge( {
isFlammable: true, // All resistors are flammable except for the dog, which automatically disconnects at high current.
phetioType: Resistor.ResistorIO,
numberOfDecimalPlaces: resistorType === Resistor.ResistorType.RESISTOR ? 1 : 0
}, options ) as ResistorOptions;
}, providedOptions ) as ResistorOptions;

assert && assert( !filledOptions.hasOwnProperty( 'resistance' ), 'Resistance should be passed through resistorType' );
assert && assert( !options.hasOwnProperty( 'resistance' ), 'Resistance should be passed through resistorType' );

// validate resistor type
// @ts-ignore
validate( resistorType, { valueType: Resistor.ResistorType } );

// @public (read-only)
assert && assert( !filledOptions.hasOwnProperty( 'isMetallic' ), 'isMetallic is given by the resistorType' );
filledOptions.isMetallic = resistorType.isMetallic;
assert && assert( !options.hasOwnProperty( 'isMetallic' ), 'isMetallic is given by the resistorType' );
options.isMetallic = resistorType.isMetallic;

super( startVertex, endVertex, resistorType.length, tandem, filledOptions );
super( startVertex, endVertex, resistorType.length, tandem, options );

// @public (read-only) {Resistor.ResistorType} indicates one of ResistorType values
this.resistorType = resistorType;
Expand Down
Loading

0 comments on commit 679fe3b

Please sign in to comment.