From 1fc908b8bdb8366476e365c3d9651dd9f43b0223 Mon Sep 17 00:00:00 2001 From: samreid Date: Fri, 15 Dec 2017 12:27:23 -0700 Subject: [PATCH] Converted to use PhetioObject, see https://github.com/phetsims/tandem/issues/46 --- .../model/ElectricPotentialLine.js | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/js/charges-and-fields/model/ElectricPotentialLine.js b/js/charges-and-fields/model/ElectricPotentialLine.js index a377ae1c..fc703f86 100644 --- a/js/charges-and-fields/model/ElectricPotentialLine.js +++ b/js/charges-and-fields/model/ElectricPotentialLine.js @@ -12,6 +12,7 @@ define( function( require ) { var chargesAndFields = require( 'CHARGES_AND_FIELDS/chargesAndFields' ); var dot = require( 'DOT/dot' ); var inherit = require( 'PHET_CORE/inherit' ); + var PhetioObject = require( 'TANDEM/PhetioObject' ); var Shape = require( 'KITE/Shape' ); var Vector2 = require( 'DOT/Vector2' ); @@ -44,8 +45,6 @@ define( function( require ) { isPlayAreaChargedProperty, tandem ) { - var self = this; - this.getElectricPotential = getElectricPotential; // @private static this.getElectricField = getElectricField; // @private static this.chargedParticles = chargedParticles; // @private static @@ -62,20 +61,15 @@ define( function( require ) { // @public (read-only) - used to identify tandems for the corresponding views this.electricPotentialLineTandem = tandem; - tandem.addInstance( this, { phetioType: ElectricPotentialLineIO } ); - - this.disposeElectricPotentialLine = function() { - tandem.removeInstance( self ); - }; + PhetioObject.call( this, { + tandem: tandem, + phetioType: ElectricPotentialLineIO + } ); } chargesAndFields.register( 'ElectricPotentialLine', ElectricPotentialLine ); - return inherit( Object, ElectricPotentialLine, { - - dispose: function() { - this.disposeElectricPotentialLine(); - }, + return inherit( PhetioObject, ElectricPotentialLine, { /** * Given an (initial) position, find a position with the targeted electric potential within a distance 'deltaDistance' @@ -142,8 +136,8 @@ define( function( require ) { var k4Vector = this.getElectricField( position.plus( k3Vector.timesScalar( deltaDistance ) ) ).normalize().rotate( Math.PI / 2 ); // {Vector2} normalized Vector along electricPotential var deltaDisplacement = { - x: deltaDistance * (k1Vector.x + 2 * k2Vector.x + 2 * k3Vector.x + k4Vector.x) / 6, - y: deltaDistance * (k1Vector.y + 2 * k2Vector.y + 2 * k3Vector.y + k4Vector.y) / 6 + x: deltaDistance * ( k1Vector.x + 2 * k2Vector.x + 2 * k3Vector.x + k4Vector.x ) / 6, + y: deltaDistance * ( k1Vector.y + 2 * k2Vector.y + 2 * k3Vector.y + k4Vector.y ) / 6 }; return position.plus( deltaDisplacement ); // {Vector2} finalPosition }, @@ -192,8 +186,8 @@ define( function( require ) { var clockwiseEpsilonDistance = MIN_EPSILON_DISTANCE; var counterClockwiseEpsilonDistance = -clockwiseEpsilonDistance; - while ( (stepCounter < MAX_STEPS ) && !this.isLineClosed && - (this.isEquipotentialLineTerminatingInsideBounds || (stepCounter < MIN_STEPS ) ) ) { + while ( ( stepCounter < MAX_STEPS ) && !this.isLineClosed && + ( this.isEquipotentialLineTerminatingInsideBounds || ( stepCounter < MIN_STEPS ) ) ) { nextClockwisePosition = this.getNextPositionAlongEquipotentialWithElectricPotential( currentClockwisePosition, @@ -339,7 +333,7 @@ define( function( require ) { // shorten the epsilon distance in tight turns, longer steps in straighter stretch // 360 implies that a perfect circle could be generated by 360 points, i.e. a rotation of 1 degree doesn't change epsilonDistance. - epsilonDistance *= (2 * Math.PI / 360) / deflectionAngle; + epsilonDistance *= ( 2 * Math.PI / 360 ) / deflectionAngle; } // clamp the value of epsilonDistance to be within this range epsilonDistance = dot.clamp( Math.abs( epsilonDistance ), MIN_EPSILON_DISTANCE, MAX_EPSILON_DISTANCE ); @@ -388,11 +382,11 @@ define( function( require ) { }, options ); // if the line is open, there is one less segments than point vectors - var segmentsNumber = (options.isClosedLineSegments) ? positionArray.length : positionArray.length - 1; + var segmentsNumber = ( options.isClosedLineSegments ) ? positionArray.length : positionArray.length - 1; shape.moveToPoint( positionArray[ 0 ] ); for ( var i = 1; i < segmentsNumber + 1; i++ ) { - shape.lineToPoint( positionArray[ (i) % positionArray.length ] ); + shape.lineToPoint( positionArray[ ( i ) % positionArray.length ] ); } return shape; }