Skip to content

Commit

Permalink
Minor updates and documentation, see #123
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed May 7, 2024
1 parent 413e1c8 commit aac86ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 6 additions & 4 deletions js/buoyancy/model/ApplicationsMass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default abstract class ApplicationsMass extends Mass {

protected massLabelOffsetVector3: Vector3;

public readonly intersectionGroup: THREE.Group;
// For ray casting/hit testing
public readonly intersectionGroup = new THREE.Group();

protected constructor( engine: PhysicsEngine, displacementVolumeProperty: NumberProperty, options: ApplicationsMassOptions ) {

Expand All @@ -41,8 +42,6 @@ export default abstract class ApplicationsMass extends Mass {

this.massLabelOffsetOrientationProperty.value = new Vector2( 1, -1 / 2 );
this.massLabelOffsetProperty.value = this.massLabelOffsetVector3;

this.intersectionGroup = new THREE.Group();
}

/**
Expand All @@ -55,7 +54,7 @@ export default abstract class ApplicationsMass extends Mass {

/**
* If there is an intersection with the ray and this mass, the t-value (distance the ray would need to travel to
* reach the intersection, e.g. ray.position + ray.distance * t === intersectionPoint) will be returned. Otherwise
* reach the intersection, e.g. ray.position + ray.distance * t === intersectionPoint) will be returned. Otherwise,
* if there is no intersection, null will be returned.
*/
public override intersect( ray: Ray3, isTouch: boolean, scale = 1 ): number | null {
Expand All @@ -77,11 +76,14 @@ export default abstract class ApplicationsMass extends Mass {
* Returns the displayed area of this object at a given y level
*
* Assumes step information was updated.
*
* TODO: Why is this different than getDisplacedVolume? Should they share implementation? See https://github.com/phetsims/density-buoyancy-common/issues/123
*/
public getDisplacedArea( liquidLevel: number ): number {
const bottom = this.stepBottom;
const top = this.stepTop;

// TODO: https://github.com/phetsims/density-buoyancy-common/issues/123 if the liquid level is beyond the top, it probably shouldn't be 0, right?
if ( liquidLevel < bottom || liquidLevel > top ) {
return 0;
}
Expand Down
6 changes: 2 additions & 4 deletions js/common/model/Mass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ export default abstract class Mass extends PhetioObject {
}, providedOptions );

assert && assert( options.body, 'options.body required' );
assert && assert( options.shape instanceof Shape, 'options.shape required as a Shape' );
assert && assert( options.material instanceof Material, 'options.material required as a Material' );
assert && assert( options.volume > 0, 'non-zero options.volume required' );

super( options );
Expand Down Expand Up @@ -629,11 +627,11 @@ export default abstract class Mass extends PhetioObject {
public abstract setRatios( widthRatio: number, heightRatio: number ): void;

/**
* Called after a engine-physics-model step once before doing other operations (like computing buoyant forces,
* Called after the engine-physics-model step once before doing other operations (like computing buoyant forces,
* displacement, etc.) so that it can set high-performance flags used for this purpose.
*
* Type-specific values are likely to be set, but this should set at least stepX/stepBottom/stepTop (as those are
* used for determining basin volumes and cross sections)
* used for determining basin volumes and cross-sections)
*/
public updateStepInformation(): void {
this.engine.bodyGetStepMatrixTransform( this.body, this.stepMatrix );
Expand Down

0 comments on commit aac86ef

Please sign in to comment.