Skip to content

Commit

Permalink
Removing canRotate, see #277
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Jul 24, 2024
1 parent 7d476b5 commit 5bc0cef
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 41 deletions.
3 changes: 1 addition & 2 deletions js/buoyancy/model/applications/ApplicationsMass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import PhysicsEngine from '../../../common/model/PhysicsEngine.js';
import Vector2 from '../../../../../dot/js/Vector2.js';
import Vector3 from '../../../../../dot/js/Vector3.js';
import Bounds3 from '../../../../../dot/js/Bounds3.js';
import StrictOmit from '../../../../../phet-core/js/types/StrictOmit.js';

export type ApplicationsMassOptions = StrictOmit<InstrumentedMassOptions, 'canRotate'>;
export type ApplicationsMassOptions = InstrumentedMassOptions;

export default abstract class ApplicationsMass extends Mass {

Expand Down
2 changes: 0 additions & 2 deletions js/buoyancy/model/shapes/Duck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export default class Duck extends Mass {
massShape: MassShape.DUCK
}, providedConfig );

assert && assert( !options.canRotate );

super( engine, options as InstrumentedMassOptions );

this.sizeProperty = new Property( size, {
Expand Down
2 changes: 0 additions & 2 deletions js/common/model/Cone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ export default class Cone extends Mass {
massShape: isVertexUp ? MassShape.CONE : MassShape.INVERTED_CONE
}, providedOptions );

assert && assert( !options.canRotate );

super( engine, options as InstrumentedMassOptions );

this.radiusProperty = new NumberProperty( radius, {
Expand Down
2 changes: 0 additions & 2 deletions js/common/model/Cuboid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export default class Cuboid extends Mass {
massShape: MassShape.BLOCK
}, providedOptions );

assert && assert( !options.canRotate );

super( engine, options );

this.sizeProperty = new Property( size, {
Expand Down
2 changes: 0 additions & 2 deletions js/common/model/Ellipsoid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export default class Ellipsoid extends Mass {
massShape: MassShape.ELLIPSOID
}, providedOptions );

assert && assert( !options.canRotate );

super( engine, options as InstrumentedMassOptions );

this.sizeProperty = new Property( size, {
Expand Down
2 changes: 0 additions & 2 deletions js/common/model/HorizontalCylinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export default class HorizontalCylinder extends Mass {
massShape: MassShape.HORIZONTAL_CYLINDER
}, providedOptions );

assert && assert( !options.canRotate );

super( engine, options as InstrumentedMassOptions );

// {Property.<number>}
Expand Down
12 changes: 1 addition & 11 deletions js/common/model/Mass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type SelfOptions = {

visible?: boolean;
matrix?: Matrix3;
canRotate?: boolean;
canMove?: boolean;

// Allow Customization of the material beyond initial value, this includes PhET-iO support for changing the density
Expand Down Expand Up @@ -91,7 +90,6 @@ export type MassIOStateObject = {
matrix: Matrix3StateObject;
stepMatrix: Matrix3StateObject;
originalMatrix: Matrix3StateObject;
canRotate: boolean;
canMove: boolean;
tag: MassTagStateObject;
massShape: string;
Expand Down Expand Up @@ -168,7 +166,6 @@ export default abstract class Mass extends PhetioObject {
// Fired when this mass's input (drag) should be interrupted.
public readonly interruptedEmitter: TEmitter;

private canRotate: boolean;
public canMove: boolean;
public tag: MassTag;

Expand All @@ -194,7 +191,6 @@ export default abstract class Mass extends PhetioObject {
const options = optionize<MassOptions, SelfOptions, PhetioObjectOptions>()( {
visible: true,
matrix: new Matrix3(),
canRotate: false,
canMove: true,
adjustableMaterial: false,
adjustableColor: true,
Expand Down Expand Up @@ -381,7 +377,6 @@ export default abstract class Mass extends PhetioObject {
this.transformedEmitter = new Emitter();
this.interruptedEmitter = new Emitter();

this.canRotate = options.canRotate;
this.canMove = options.canMove;
this.tag = options.tag;

Expand All @@ -407,9 +402,7 @@ export default abstract class Mass extends PhetioObject {
this.massProperty
], () => {
// Don't allow a fully-zero value for the physics engines
engine.bodySetMass( this.body, Math.max( this.massProperty.value, 0.01 ), {
canRotate: options.canRotate
} );
engine.bodySetMass( this.body, Math.max( this.massProperty.value, 0.01 ) );
} );

this.writeData();
Expand Down Expand Up @@ -630,7 +623,6 @@ export default abstract class Mass extends PhetioObject {
matrix: Matrix3.Matrix3IO,
stepMatrix: Matrix3.Matrix3IO,
originalMatrix: Matrix3.Matrix3IO,
canRotate: BooleanIO,
canMove: BooleanIO,
tag: MassTag.MassTagIO,
massShape: EnumerationIO( MassShape ),
Expand All @@ -645,7 +637,6 @@ export default abstract class Mass extends PhetioObject {
matrix: Matrix3.toStateObject( mass.matrix ),
stepMatrix: Matrix3.toStateObject( mass.stepMatrix ),
originalMatrix: Matrix3.toStateObject( mass.originalMatrix ),
canRotate: mass.canRotate,
canMove: mass.canMove,
tag: MassTag.MassTagIO.toStateObject( mass.tag ),
massShape: EnumerationIO( MassShape ).toStateObject( mass.massShape )
Expand All @@ -655,7 +646,6 @@ export default abstract class Mass extends PhetioObject {
mass.matrix.set( Matrix3.fromStateObject( obj.matrix ) );
mass.stepMatrix.set( Matrix3.fromStateObject( obj.stepMatrix ) );
mass.originalMatrix.set( Matrix3.fromStateObject( obj.originalMatrix ) );
mass.canRotate = obj.canRotate;
mass.canMove = obj.canMove;
MassTag.MassTagIO.applyState( mass.tag, obj.tag );
mass.engine.bodyApplyState( mass.body, obj );
Expand Down
18 changes: 3 additions & 15 deletions js/common/model/P2Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import TEmitter from '../../../../axon/js/TEmitter.js';
import TinyEmitter from '../../../../axon/js/TinyEmitter.js';
import Matrix3 from '../../../../dot/js/Matrix3.js';
import Vector2, { Vector2StateObject } from '../../../../dot/js/Vector2.js';
import optionize from '../../../../phet-core/js/optionize.js';
import densityBuoyancyCommon from '../../densityBuoyancyCommon.js';
import DensityBuoyancyCommonQueryParameters from '../DensityBuoyancyCommonQueryParameters.js';
import PhysicsEngine, { PhysicsBodyType, PhysicsEngineBody } from './PhysicsEngine.js';
Expand All @@ -34,8 +33,6 @@ const BODY_TYPE_MAPPER: Record<PhysicsBodyType, P2BodyType> = {
STATIC: p2.Body.STATIC // Cannot move, for anything.
};

type BodySetMassOptions = { canRotate?: boolean };

export type BodyStateObject = {
position: Vector2StateObject;
velocity: Vector2StateObject;
Expand Down Expand Up @@ -131,19 +128,10 @@ export default class P2Engine extends PhysicsEngine {
/**
* Sets the mass of a body (and whether it can rotate, which for some engines needs to be set at the same time).
*/
public bodySetMass( body: PhysicsEngineBody, mass: number, providedOptions?: BodySetMassOptions ): void {
const options = optionize<BodySetMassOptions>()( {
// {boolean} - optional
canRotate: false
}, providedOptions );

public bodySetMass( body: PhysicsEngineBody, mass: number ): void {
body.mass = mass * MASS_SCALE;

if ( !options.canRotate ) {
body.fixedRotation = true;
}

body.updateMassProperties();
body.fixedRotation = true;
body.updateMassProperties();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/common/model/PhysicsEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default abstract class PhysicsEngine {
/**
* Sets the mass of a body (and whether it can rotate, which for some engines needs to be set at the same time).
*/
public abstract bodySetMass( body: PhysicsEngineBody, mass: number, options?: { canRotate?: boolean } ): void;
public abstract bodySetMass( body: PhysicsEngineBody, mass: number ): void;

/**
* Sets the provided matrix to the current transformation matrix of the body (to reduce allocations)
Expand Down
2 changes: 0 additions & 2 deletions js/common/model/VerticalCylinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export default class VerticalCylinder extends Mass {
massShape: MassShape.VERTICAL_CYLINDER
}, providedOptions );

assert && assert( !options.canRotate );

super( engine, options as InstrumentedMassOptions );

// {Property.<number>}
Expand Down

0 comments on commit 5bc0cef

Please sign in to comment.