Skip to content

Commit

Permalink
delete FELMovable, move positionProperty into the 3 places where it's…
Browse files Browse the repository at this point in the history
… needed in the model, #163
  • Loading branch information
pixelzoom committed May 24, 2024
1 parent cd95fce commit c937b10
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 88 deletions.
64 changes: 0 additions & 64 deletions js/common/model/FELMovable.ts

This file was deleted.

38 changes: 29 additions & 9 deletions js/common/model/FieldMeasurementTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,54 @@ import Vector2 from '../../../../dot/js/Vector2.js';
import optionize from '../../../../phet-core/js/optionize.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import FELMovable, { FELMovableOptions } from './FELMovable.js';
import Property from '../../../../axon/js/Property.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import Vector2Property from '../../../../dot/js/Vector2Property.js';
import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import PickOptional from '../../../../phet-core/js/types/PickOptional.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';

type SelfOptions = {
position?: Vector2; // Initial value of positionProperty, unitless
visible?: boolean;
};

export type FieldMeasurementToolOptions = SelfOptions & FELMovableOptions;
export type FieldMeasurementToolOptions = SelfOptions &
PickOptional<PhetioObjectOptions, 'phetioDocumentation'> &
PickRequired<PhetioObjectOptions, 'tandem'>;

export default class FieldMeasurementTool extends FELMovable {
export default class FieldMeasurementTool extends PhetioObject {

// The field vector at the meter's position, in gauss
// The tool's position, unitless.
public readonly positionProperty: Property<Vector2>;

// The field vector at the tool's position, in gauss.
public readonly fieldVectorProperty: TReadOnlyProperty<Vector2>;

// Whether the tool is visible.
public readonly visibleProperty: Property<boolean>;

protected constructor( magnet: Magnet, providedOptions: FieldMeasurementToolOptions ) {

const options = optionize<FieldMeasurementToolOptions, SelfOptions, FELMovableOptions>()( {
const options = optionize<FieldMeasurementToolOptions, SelfOptions, PhetioObjectOptions>()( {

// SelfOptions
position: Vector2.ZERO,
visible: true,

//SelfOptions
visible: true
// PhetioObjectOptions
isDisposable: false,
phetioState: false,
phetioFeatured: true
}, providedOptions );

super( options );

this.positionProperty = new Vector2Property( options.position, {
tandem: options.tandem.createTandem( 'positionProperty' ),
phetioFeatured: true
} );

// This needs to be a new Vector2 instance, so do not pass an output vector to magnet.getFieldVector.
this.fieldVectorProperty = new DerivedProperty(
[ this.positionProperty, magnet.positionProperty, magnet.rotationProperty, magnet.strengthProperty ],
Expand All @@ -56,8 +76,8 @@ export default class FieldMeasurementTool extends FELMovable {
} );
}

public override reset(): void {
super.reset();
public reset(): void {
this.positionProperty.reset();
this.visibleProperty.reset();
}
}
Expand Down
42 changes: 34 additions & 8 deletions js/common/model/Magnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@ import Range from '../../../../dot/js/Range.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import Property from '../../../../axon/js/Property.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import optionize from '../../../../phet-core/js/optionize.js';
import FELMovable, { FELMovableOptions } from './FELMovable.js';
import optionize, { combineOptions } from '../../../../phet-core/js/optionize.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import Bounds2 from '../../../../dot/js/Bounds2.js';
import Dimension3 from '../../../../dot/js/Dimension3.js';
import Utils from '../../../../dot/js/Utils.js';
import FELQueryParameters from '../FELQueryParameters.js';
import FELConstants from '../FELConstants.js';
import Vector2Property, { Vector2PropertyOptions } from '../../../../dot/js/Vector2Property.js';
import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import PickOptional from '../../../../phet-core/js/types/PickOptional.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';

type SelfOptions = {

// Initial value of positionProperty, unitless
position?: Vector2;

// Options passed to positionProperty
positionPropertyOptions?: Vector2PropertyOptions;

// initial value of rotationProperty, radians
rotation?: number;

Expand All @@ -33,16 +43,21 @@ type SelfOptions = {
size: Dimension3;
};

export type MagnetOptions = SelfOptions & FELMovableOptions;
export type MagnetOptions = SelfOptions &
PickOptional<PhetioObjectOptions, 'phetioDocumentation'> &
PickRequired<PhetioObjectOptions, 'tandem'>;

export default abstract class Magnet extends FELMovable {
export default abstract class Magnet extends PhetioObject {

// Dimensions of a 3D magnet, with origin at its center.
public readonly size: Dimension3;

// Bounds of the magnet in its local coordinate frame.
public readonly localBounds: Bounds2;

// Position of the magnet, unitless.
public readonly positionProperty: Property<Vector2>;

// The range of the magnet's strength, in gauss.
public readonly strengthRange: Range;

Expand All @@ -68,10 +83,16 @@ export default abstract class Magnet extends FELMovable {

protected constructor( strengthProperty: TReadOnlyProperty<number>, strengthRange: Range, providedOptions: MagnetOptions ) {

const options = optionize<MagnetOptions, SelfOptions, FELMovableOptions>()( {
const options = optionize<MagnetOptions, StrictOmit<SelfOptions, 'positionPropertyOptions'>, PhetioObjectOptions>()( {

// SelfOptions
rotation: 0
position: Vector2.ZERO,
rotation: 0,

// PhetioObjectOptions
isDisposable: false,
phetioState: false,
phetioFeatured: true
}, providedOptions );

super( options );
Expand All @@ -81,6 +102,11 @@ export default abstract class Magnet extends FELMovable {
// Rectangular, with origin at the center
this.localBounds = new Bounds2( -this.size.width / 2, -this.size.height / 2, this.size.width / 2, this.size.height / 2 );

this.positionProperty = new Vector2Property( options.position, combineOptions<Vector2PropertyOptions>( {
tandem: options.tandem.createTandem( 'positionProperty' ),
phetioFeatured: true
}, options.positionPropertyOptions ) );

this.strengthRange = strengthRange;
this.strengthProperty = strengthProperty;

Expand All @@ -103,8 +129,8 @@ export default abstract class Magnet extends FELMovable {
this.reusablePosition = new Vector2( 0, 0 );
}

protected override reset(): void {
super.reset();
protected reset(): void {
this.positionProperty.reset();
this.rotationProperty.reset();
this.fieldVisibleProperty.reset();
// Do not reset Properties documented as 'DEBUG' above.
Expand Down
36 changes: 29 additions & 7 deletions js/common/model/PickupCoil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import LightBulb, { LightBulbOptions } from './LightBulb.js';
import Voltmeter, { VoltmeterOptions } from './Voltmeter.js';
import CurrentIndicator from './CurrentIndicator.js';
import FELMovable, { FELMovableOptions } from './FELMovable.js';
import FELConstants from '../FELConstants.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import PickOptional from '../../../../phet-core/js/types/PickOptional.js';
Expand All @@ -31,8 +30,13 @@ import FELQueryParameters, { CurrentFlow } from '../FELQueryParameters.js';
import NumberIO from '../../../../tandem/js/types/NumberIO.js';
import ConstantDtClock from './ConstantDtClock.js';
import Dimension2 from '../../../../dot/js/Dimension2.js';
import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import Vector2Property, { Vector2PropertyOptions } from '../../../../dot/js/Vector2Property.js';

type SelfOptions = {
position?: Vector2; // Initial value of positionProperty, unitless
positionPropertyOptions?: Vector2PropertyOptions; // Options passed to positionProperty
maxEMF: number; // the initial value of maxEMFProperty
transitionSmoothingScale: number; // the initial value of transitionSmoothingScaleProperty
samplePointsSpacing: number; // spacing between B-field sample points
Expand All @@ -42,16 +46,21 @@ type SelfOptions = {
voltmeterOptions?: PickOptional<VoltmeterOptions, 'kinematicsEnabledProperty'>; // passed to Voltmeter
};

export type PickupCoilOptions = SelfOptions & FELMovableOptions;
export type PickupCoilOptions = SelfOptions &
PickOptional<PhetioObjectOptions, 'phetioDocumentation'> &
PickRequired<PhetioObjectOptions, 'tandem'>;

export default class PickupCoil extends FELMovable {
export default class PickupCoil extends PhetioObject {

// The magnet whose field this coil is in
public readonly magnet: Magnet;

// The coil that induces the EMF
public readonly coil: Coil;

// Position of the poickup coil, unitless.
public readonly positionProperty: Property<Vector2>;

// Flux in the coil
private readonly _fluxProperty: Property<number>;
public readonly fluxProperty: TReadOnlyProperty<number>;
Expand Down Expand Up @@ -124,10 +133,18 @@ export default class PickupCoil extends FELMovable {

public constructor( magnet: Magnet, currentFlowProperty: TReadOnlyProperty<CurrentFlow>, providedOptions: PickupCoilOptions ) {

const options = optionize<PickupCoilOptions, StrictOmit<SelfOptions, 'coilOptions' | 'lightBulbOptions' | 'voltmeterOptions'>, FELMovableOptions>()( {
const options = optionize<PickupCoilOptions,
StrictOmit<SelfOptions, 'positionPropertyOptions' | 'coilOptions' | 'lightBulbOptions' | 'voltmeterOptions'>,
PhetioObjectOptions>()( {

// SelfOptions
fluxAreaCompensationEnabled: true
position: Vector2.ZERO,
fluxAreaCompensationEnabled: true,

// PhetioObjectOptions
isDisposable: false,
phetioState: false,
phetioFeatured: true
}, providedOptions );

super( options );
Expand All @@ -136,6 +153,11 @@ export default class PickupCoil extends FELMovable {

this.magnet = magnet;

this.positionProperty = new Vector2Property( options.position, combineOptions<Vector2PropertyOptions>( {
tandem: options.tandem.createTandem( 'positionProperty' ),
phetioFeatured: true
}, options.positionPropertyOptions ) );

// We want some Properties to appear to be children of the coil element. We could also have done this by
// subclassing Coil, but having something like PickupCoilCoil seemed confusing, and unnecessary.
const coilTandem = options.tandem.createTandem( 'coil' );
Expand Down Expand Up @@ -235,8 +257,8 @@ export default class PickupCoil extends FELMovable {
this.fluxProperty = this._fluxProperty;
}

public override reset(): void {
super.reset();
public reset(): void {
this.positionProperty.reset();
this.coil.reset();
this._fluxProperty.reset();
this._deltaFluxProperty.reset();
Expand Down

0 comments on commit c937b10

Please sign in to comment.