Skip to content

Commit

Permalink
Apply WebStorm formatting, see phetsims/phet-info#155
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Feb 26, 2021
1 parent 0e01429 commit 21f33ee
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 181 deletions.
50 changes: 25 additions & 25 deletions js/model/ISLCModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const OBJECT_ONE = ISLCObjectEnum.OBJECT_ONE;
const OBJECT_TWO = ISLCObjectEnum.OBJECT_TWO;

class ISLCModel {

/**
* @param {number} forceConstant the appropriate force constant (e.g. G or k)
* @param {ISLCObject} object1 - the first Mass or Charge object
Expand All @@ -33,44 +33,44 @@ class ISLCModel {
* @param {Object} [options]
*/
constructor( forceConstant, object1, object2, positionRange, tandem, options ) {

options = merge( {
snapObjectsToNearest: null, // {number|null} if defined, objects will snap to nearest value in model coordinates
minSeparationBetweenObjects: 0.1 // in meters
}, options );

assert && assert( object1.positionProperty.units === object2.positionProperty.units, 'units should be the same' );

// @public (read-only)
this.leftObjectBoundary = positionRange.min;
this.rightObjectBoundary = positionRange.max;

// @public {Property.<boolean>} - whether to display the force values
this.showForceValuesProperty = new BooleanProperty( true, {
tandem: tandem.createTandem( 'showForceValuesProperty' ),
phetioDocumentation: 'Whether or not the force values should be displayed'
} );

// @public
this.object1 = object1;
this.object2 = object2;

// set the appropriate enum reference to each object.
object1.enum = ISLCObjectEnum.OBJECT_ONE;
object2.enum = ISLCObjectEnum.OBJECT_TWO;

// @public
// {Property.<ISLCObjectEnum|null>} - needed for adjusting alerts when an object moves as a result of a radius increase
this.pushedObjectEnumProperty = new Property( null );

// @private
this.snapObjectsToNearest = options.snapObjectsToNearest;
this.minSeparationBetweenObjects = options.minSeparationBetweenObjects;
this.forceConstant = forceConstant;

// @public - emits an event when the model is updated by step
this.stepEmitter = new Emitter();

// @public {Property.<number>} - calculates the force based on changes to values and positions
// objects are never destroyed, so forceProperty does not require disposal
this.forceProperty = new DerivedProperty( [
Expand All @@ -84,7 +84,7 @@ class ISLCModel {
units: 'N',
phetioDocumentation: 'The force of one object on the other (in Newtons)'
} );

// @private {Property.<number>} - The distance between the two objects. Added for PhET-iO.
this.separationProperty = new DerivedProperty( [
this.object1.positionProperty,
Expand All @@ -95,45 +95,45 @@ class ISLCModel {
units: object1.positionProperty.units,
phetioDocumentation: 'The distance between the two objects\' centers'
} );

const updateRange = object => {
const maxPosition = this.getObjectMaxPosition( object );
const minPosition = this.getObjectMinPosition( object );

object.enabledRangeProperty.set( new Range( minPosition, maxPosition ) );
};

// pdom - necessary to reset the enabledRangeProperty to prevent object overlap, disposal not necessary
// We need to update the available range for each object when the either's radius or position changes.
Property.multilink( [ object1.positionProperty, object2.positionProperty ], () => {
updateRange( object1 );
updateRange( object2 );
} );

// when sim is reset, we only reset the position properties of each object to their initial values
// thus, there is no need to dispose of the listeners below
this.object1.radiusProperty.link( () => {
this.object1.radiusLastChanged = true;
this.object2.radiusLastChanged = false;

// update range if radius changed with "constant radius" setting (which didn't trigger other model updates)
updateRange( object1 );
updateRange( object2 );
} );

this.object2.radiusProperty.link( () => {
this.object2.radiusLastChanged = true;
this.object1.radiusLastChanged = false;

// update range if radius changed with "constant radius" setting (which didn't trigger other model updates)
updateRange( object2 );
updateRange( object1 );
} );

// wire up logic to update the state of the pushedObjectEnumProperty
const createPushedPositionListener = objectEnum => {
return () => {

// This conditional should only be hit if the mass has changed in addition to the position. Since the object's
// valueProperty would be set in the previous frame, and then this frame's step function would update the
// position.
Expand All @@ -145,11 +145,11 @@ class ISLCModel {
}
};
};

// lazy link so we don't have a strange initial condition even though we haven't moved the pushers.
object1.positionProperty.lazyLink( createPushedPositionListener( ISLCObjectEnum.OBJECT_ONE ) );
object2.positionProperty.lazyLink( createPushedPositionListener( ISLCObjectEnum.OBJECT_TWO ) );

// when the mass is lessened, there is no way that pushed an object, so set to null
const massChangedListener = ( newMass, oldMass ) => {
if ( oldMass > newMass ) {
Expand All @@ -158,7 +158,7 @@ class ISLCModel {
};
object1.valueProperty.link( massChangedListener );
object2.valueProperty.link( massChangedListener );

// reset after step is complete.
this.stepEmitter.addListener( () => {
this.object1.onStepEnd();
Expand Down Expand Up @@ -408,7 +408,7 @@ class ISLCModel {
/**
* Get whether or not the position of a mass was most recently changed based on the other pushing it.
* @public
*
*
* @returns {boolean}
*/
massWasPushed() {
Expand Down
22 changes: 11 additions & 11 deletions js/view/ISLCDragBoundsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ import Node from '../../../scenery/js/nodes/Node.js';
import inverseSquareLawCommon from '../inverseSquareLawCommon.js';

class ISLCDragBoundsNode extends Node {

/**
* @param {ISLCModel} model
* @param {Bounds2} layoutBounds
* @param {ModelViewTransform2} modelViewTransform
* @param {Object} [options]
*/
constructor( model, layoutBounds, modelViewTransform, options ) {

options = merge( {
lineWidth: 2,
object1Stroke: 'blue',
object2Stroke: 'red'
}, options );

super( options );

// Show the min/max positions for dragging the objects
const verticalMin = layoutBounds.minY;
const verticalMax = layoutBounds.height;
const object1LineOptions = { stroke: options.object1Stroke, lineWidth: options.lineWidth };
const object2LineOptions = { stroke: options.object1Stroke, lineWidth: options.lineWidth };

// vertical lines (drawn from yMin to yMax) that will be positioned according to the draggable limits of each object
const object1MinLine = new Line( 0, verticalMin, 0, verticalMax, object1LineOptions );
const object1MaxLine = new Line( 0, verticalMin, 0, verticalMax, object1LineOptions );
const object2MinLine = new Line( 0, verticalMin, 0, verticalMax, object2LineOptions );
const object2MaxLine = new Line( 0, verticalMin, 0, verticalMax, object2LineOptions );

this.children = [ object1MinLine, object2MinLine, object1MaxLine, object2MaxLine ];

let object1MinX;
let object1MaxX;
let object2MinX;
Expand All @@ -55,20 +55,20 @@ class ISLCDragBoundsNode extends Node {
model.object2.positionProperty,
model.object2.radiusProperty
];

Property.multilink( objectProperties, () => {
object1MinX = modelViewTransform.modelToViewX( model.getObjectMinPosition( model.object1 ) );
object1MinLine.x1 = object1MinX;
object1MinLine.x2 = object1MinX;

object1MaxX = modelViewTransform.modelToViewX( model.getObjectMaxPosition( model.object1 ) );
object1MaxLine.x1 = object1MaxX;
object1MaxLine.x2 = object1MaxX;

object2MinX = modelViewTransform.modelToViewX( model.getObjectMinPosition( model.object2 ) );
object2MinLine.x1 = object2MinX;
object2MinLine.x2 = object2MinX;

object2MaxX = modelViewTransform.modelToViewX( model.getObjectMaxPosition( model.object2 ) );
object2MaxLine.x1 = object2MaxX;
object2MaxLine.x2 = object2MaxX;
Expand Down
40 changes: 20 additions & 20 deletions js/view/ISLCForceArrowNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ARROW_LENGTH = 8; // empirically determined
const TEXT_OFFSET = 10; // empirically determined to make sure text does not go out of bounds

class ISLCForceArrowNode extends Node {

/**
* @param {Range} arrowForceRange - the range in force magnitude
* @param {Bounds2} layoutBounds
Expand All @@ -41,21 +41,21 @@ class ISLCForceArrowNode extends Node {
* @param {Object} [options]
*/
constructor( arrowForceRange, layoutBounds, label, otherObjectLabel, tandem, options ) {

options = merge( {
defaultDirection: DefaultDirection.LEFT,
attractNegative: true, // if true, arrows will point towards each other if force is negative
arrowNodeLineWidth: 0.25,

// label options
arrowLabelFont: new PhetFont( 16 ),
arrowLabelFill: '#fff',
arrowLabelStroke: null,
forceReadoutDecimalPlaces: ISLCConstants.DECIMAL_NOTATION_PRECISION, // number of decimal places in force readout

// arrow node arguments
forceArrowHeight: 150,

// arrow node options
maxArrowWidth: 15, // max width of the arrow when when redrawn, in view coordinates - used in mapping function
minArrowWidth: 0, // Some ISLC sims support an object value of zero, setting this to zero supports this case.
Expand All @@ -65,21 +65,21 @@ class ISLCForceArrowNode extends Node {
arrowStroke: null,
arrowFill: '#fff',
backgroundFill: 'black',

// arrow mapping function options
// By default, only use a single mapping function to go from force to arrow width, but with this option and
// those below use two.
mapArrowWidthWithTwoFunctions: false,

// only if mapArrowWidthWithTwoFunctions is true
forceThresholdPercent: 0, // the percent to switch mappings from the min to the main linear function.
thresholdArrowWidth: 1 // This default is used by GFL(B) as a good in between the min/max arrow widths.
}, options );

options.tandem = tandem;

super( options );

// @private
this.layoutBounds = layoutBounds;
this.defaultDirection = options.defaultDirection;
Expand All @@ -88,24 +88,24 @@ class ISLCForceArrowNode extends Node {
this.otherObjectLabel = otherObjectLabel;
this.scientificNotationMode = false;
this.attractNegative = options.attractNegative;

assert && options.mapArrowWidthWithTwoFunctions && assert( options.forceThresholdPercent !== 0,
'set forceThresholdPercent to map arrow width with two functions' );

const forceThreshold = arrowForceRange.min + ( arrowForceRange.getLength() * options.forceThresholdPercent );

// Maps the force value to the desired width of the arrow in view coordinates. This mapping can be done
// two ways. The first is with a single function (when `options.mapArrowWidthWithTwoFunctions` is set to false).
// If that is the case, this is the only mapping function. This is to support single mapping in CL and multi mapping
// in GFL(B). See https://github.com/phetsims/inverse-square-law-common/issues/76 for details on the design.
const mainForceToArrowWidthFunction = new LinearFunction( forceThreshold, arrowForceRange.max,
options.mapArrowWidthWithTwoFunctions ? options.thresholdArrowWidth : options.minArrowWidth, options.maxArrowWidth, false );

// When `options.mapArrowWidthWithTwoFunctions` is true, this function will be used to map the arrow width
// from the minimum to a specified percentage of the force range, see options.forceThresholdPercent.
const minTwoForceToArrowWidthFunction = new LinearFunction( arrowForceRange.min, forceThreshold,
options.minArrowWidth, options.thresholdArrowWidth, false );

/**
* Map a force value to an arrow width
* @param {number} forceValue
Expand All @@ -115,7 +115,7 @@ class ISLCForceArrowNode extends Node {
const linearFunction = forceValue < forceThreshold ? minTwoForceToArrowWidthFunction : mainForceToArrowWidthFunction;
return linearFunction( forceValue );
};

// @public (read-only) - for layout, the label for the arrow
this.arrowText = new RichText( '', {
font: options.arrowLabelFont,
Expand All @@ -128,22 +128,22 @@ class ISLCForceArrowNode extends Node {
phetioDocumentation: 'This text updates from the model as the force changes, and cannot be edited.',
textPropertyOptions: { phetioReadOnly: true }
} );

// @private - tip and tail set in redrawArrow
this.arrow = new ArrowNode( 0, -options.forceArrowHeight, 200, -options.forceArrowHeight, merge( {
lineWidth: options.arrowNodeLineWidth,
stroke: options.arrowStroke,
fill: options.arrowFill,
tandem: tandem.createTandem( 'arrowNode' )
}, _.pick( options, [ 'headHeight', 'headWidth', 'tailWidth' ] ) ) );

// @private
this.arrowTextBackground = new Rectangle( 0, 0, 1000, 1000, { fill: options.backgroundFill, opacity: .3 } );
this.arrowTextBackground = new Rectangle( 0, 0, 1000, 1000, { fill: options.backgroundFill, opacity: .3 } );
this.addChild( this.arrowTextBackground );

this.addChild( this.arrowText );
this.addChild( this.arrow );

this.y = 0;
}

Expand Down
Loading

0 comments on commit 21f33ee

Please sign in to comment.