Skip to content

Commit

Permalink
expose all densityPropertyOptions via options, #273
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kauzmann <[email protected]>
  • Loading branch information
zepumph committed Jul 24, 2024
1 parent 8db5e2c commit e39c558
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions js/buoyancy/model/applications/Bottle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default class Bottle extends ApplicationsMass {
customMaterialOptions: {
nameProperty: DensityBuoyancyCommonStrings.systemAStringProperty,
density: ( BOTTLE_MASS + BOTTLE_INITIAL_INTERIOR_MATERIAL.density * BOTTLE_INITIAL_INTERIOR_VOLUME ) / BOTTLE_VOLUME,
densityRange: new Range( 0, 1000000000 )
densityPropertyOptions: { range: new Range( 0, 1000000000 ) }
},
massShape: MassShape.BLOCK,

Expand All @@ -230,7 +230,7 @@ export default class Bottle extends ApplicationsMass {

const customInsideMaterial = new CustomSolidMaterial( materialInsidePropertyTandem.createTandem( 'customMaterial' ), {
density: BOTTLE_INITIAL_INTERIOR_MATERIAL.density,
densityRange: new Range( 50, 20000 )
densityPropertyOptions: { range: new Range( 50, 20000 ) }
} );

this.materialInsideProperty = new MaterialProperty( BOTTLE_INITIAL_INTERIOR_MATERIAL, customInsideMaterial, [
Expand Down
4 changes: 3 additions & 1 deletion js/common/model/CompareBlockSetModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ export default class CompareBlockSetModel extends BlockSetModel<BlockSet> {
cubeData.colorProperty, densityProperty.hasChangedProperty, options.initialMaterials,
combineOptions<StrictCubeOptions>( {
customMaterialOptions: {
densityRange: options.sameDensityRange
densityPropertyOptions: {
range: options.sameDensityRange
}
}
}, getCubeOptions( cubeData.sameDensityCubeOptions ) ) );

Expand Down
20 changes: 10 additions & 10 deletions js/common/model/Material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import TinyProperty from '../../../../axon/js/TinyProperty.js';
import ReadOnlyProperty from '../../../../axon/js/ReadOnlyProperty.js';
import Range from '../../../../dot/js/Range.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import NumberProperty, { NumberPropertyOptions } from '../../../../axon/js/NumberProperty.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
Expand All @@ -33,7 +33,7 @@ type SelfOptions = {
density?: number;

// What potential densities can this Material accept? (mostly applies to custom materials)
densityRange?: Range;
densityPropertyOptions?: NumberPropertyOptions;

// in SI (Pa * s). For reference a poise is 1e-2 Pa*s, and a centipoise is 1e-3 Pa*s.
viscosity?: number;
Expand Down Expand Up @@ -74,7 +74,13 @@ export default class Material extends PhetioObject implements HasValueProperty {
const options = optionize<MaterialOptions, SelfOptions, PhetioObjectOptions>()( {
nameProperty: new TinyProperty( 'unknown' ),
density: 1,
densityRange: new Range( 0.8, 27000 ),
densityPropertyOptions: {
tandem: tandem.createTandem( 'densityProperty' ),
phetioFeatured: true,
phetioDocumentation: 'Density of the material',
range: new Range( 0.8, 27000 ),
units: 'kg/m^3'
},
viscosity: 1e-3,
custom: false,
hidden: false,
Expand All @@ -90,13 +96,7 @@ export default class Material extends PhetioObject implements HasValueProperty {
} );

this.nameProperty = options.nameProperty;
this.densityProperty = new NumberProperty( options.density, {
tandem: this.tandem.createTandem( 'densityProperty' ),
phetioFeatured: true,
phetioDocumentation: 'Density of the material',
range: options.densityRange,
units: 'kg/m^3'
} );
this.densityProperty = new NumberProperty( options.density, options.densityPropertyOptions );
this.viscosity = options.viscosity;
this.custom = options.custom;
this.hidden = options.hidden;
Expand Down
4 changes: 3 additions & 1 deletion js/common/model/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export default class Pool extends Basin {

const customFluidMaterial = new CustomLiquidMaterial( fluidMaterialPropertyTandem.createTandem( 'customMaterial' ), {
density: Material.WATER.density,
densityRange: DensityBuoyancyCommonConstants.FLUID_DENSITY_RANGE_PER_M3
densityPropertyOptions: {
range: DensityBuoyancyCommonConstants.FLUID_DENSITY_RANGE_PER_M3
}
} );

const availableMaterials = fluidSelectionType === 'justWater' ? [ Material.WATER ] :
Expand Down

0 comments on commit e39c558

Please sign in to comment.