Skip to content

Commit

Permalink
Minor documentation and initialize primitives at declaration, see #123
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed May 7, 2024
1 parent aac86ef commit 2965f8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
13 changes: 5 additions & 8 deletions js/buoyancy/model/Boat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ export default class Boat extends ApplicationsMass {

// The volume that the boat can hold inside it.
public readonly liquidMaterialProperty: TProperty<Material>;

// The interior that can contain liquid
public readonly basin: BoatBasin;

// Amount of volume contained in the basin
public stepInternalVolume: number;
public stepInternalVolume = 0;

// How to multiply our one-liter boat shape up to the model coordinates, since the boat changes size based on its
// volume. This is much preferred to trying to redraw the shape to a different size.
public stepMultiplier: number;
public stepMultiplier = 0;

// Wether the boat is underwater or not
// Whether the boat is underwater (at all) or not. Does not need to be fully submerged.
public isUnderwater = false;

public constructor( engine: PhysicsEngine, blockWidthProperty: TReadOnlyProperty<number>, liquidMaterialProperty: TProperty<Material>, providedOptions: BoatOptions ) {
Expand Down Expand Up @@ -97,15 +99,10 @@ export default class Boat extends ApplicationsMass {

this.basin = new BoatBasin( this );

this.stepInternalVolume = 0;
this.stepMultiplier = 0;
Multilink.multilink( [ this.liquidMaterialProperty, this.basin.liquidVolumeProperty ], ( material, volume ) => {
this.containedMassProperty.value = material.density * volume;
} );

this.stepInternalVolume = 0;
this.stepMultiplier = 0;

const intersectionMesh = new THREE.Mesh( BoatDesign.getPrimaryGeometry( 1 ), new THREE.MeshLambertMaterial() );
this.intersectionGroup.add( intersectionMesh );

Expand Down
8 changes: 2 additions & 6 deletions js/common/model/Mass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ export default abstract class Mass extends PhetioObject {
public readonly customColorProperty?: Property<Color>;

// Whether we are modifying the volumeProperty directly
protected volumeLock: boolean;
protected volumeLock = false;

// Whether we are modifying the massProperty directly
protected massLock: boolean;
protected massLock = false;

// In m^3 (cubic meters)
public readonly volumeProperty: NumberProperty;
Expand Down Expand Up @@ -377,8 +377,6 @@ export default abstract class Mass extends PhetioObject {
} );
}

this.volumeLock = false;

this.volumeProperty = new NumberProperty( options.volume, combineOptions<NumberPropertyOptions>( {
tandem: tandem?.createTandem( 'volumeProperty' ),
range: new Range( options.minVolume, options.maxVolume ),
Expand All @@ -398,8 +396,6 @@ export default abstract class Mass extends PhetioObject {
tandem: Tandem.OPT_OUT
} );

this.massLock = false;

this.massProperty = new GuardedNumberProperty( this.materialProperty.value.density * this.volumeProperty.value + this.containedMassProperty.value, combineOptions<GuardedNumberPropertyOptions>( {
tandem: tandem?.createTandem( 'massProperty' ),
phetioReadOnly: true,
Expand Down

0 comments on commit 2965f8d

Please sign in to comment.