Skip to content

Commit

Permalink
Converted to use PhetioObject, see phetsims/tandem#46
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 15, 2017
1 parent 2f8f4ae commit 1fc908b
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions js/charges-and-fields/model/ElectricPotentialLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 1fc908b

Please sign in to comment.