Skip to content

Commit

Permalink
Cleanup in Magnet, see #86
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Nov 5, 2017
1 parent 7ceeb6b commit bb5ed27
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
28 changes: 14 additions & 14 deletions js/faradays-law/model/FaradaysLawModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ define( function( require ) {
},

/**
* @param position position of magnet
* @param {Vector2} magnetPosition - position of magnet
*/
moveMagnetToPosition: function( position ) {
moveMagnetToPosition: function( magnetPosition ) {
var magnetBounds = new Bounds2(
Math.min( position.x, this.magnet.positionProperty.get().x ),
Math.min( position.y, this.magnet.positionProperty.get().y ),
Math.max( position.x, this.magnet.positionProperty.get().x ),
Math.max( position.y, this.magnet.positionProperty.get().y )
Math.min( magnetPosition.x, this.magnet.positionProperty.get().x ),
Math.min( magnetPosition.y, this.magnet.positionProperty.get().y ),
Math.max( magnetPosition.x, this.magnet.positionProperty.get().x ),
Math.max( magnetPosition.y, this.magnet.positionProperty.get().y )
).dilatedXY( this.magnet.width / 2 - 1, this.magnet.height / 2 - 1 );

// check intersection with any restricted areas if not intersected yet
Expand All @@ -142,7 +142,7 @@ define( function( require ) {
if ( magnetBounds.intersectsBounds( restricted ) ) {

// extend area so magnet cannot jump through restricted area on other side of it if mouse far enough
var movingDelta = position.minus( this.magnet.positionProperty.get() );
var movingDelta = magnetPosition.minus( this.magnet.positionProperty.get() );
this.intersectedBounds = restricted.copy();
if ( Math.abs( movingDelta.y ) > Math.abs( movingDelta.x ) ) {

Expand Down Expand Up @@ -177,16 +177,16 @@ define( function( require ) {
if ( this.intersectedBounds && magnetBounds.intersectsBounds( this.intersectedBounds ) ) {
switch( this.magnetMovingDirection ) {
case 'bottom' :
position.y = this.intersectedBounds.y - this.magnet.height / 2;
magnetPosition.y = this.intersectedBounds.y - this.magnet.height / 2;
break;
case 'top' :
position.y = this.intersectedBounds.maxY + this.magnet.height / 2;
magnetPosition.y = this.intersectedBounds.maxY + this.magnet.height / 2;
break;
case 'left' :
position.x = this.intersectedBounds.maxX + this.magnet.width / 2;
magnetPosition.x = this.intersectedBounds.maxX + this.magnet.width / 2;
break;
case 'right' :
position.x = this.intersectedBounds.x - this.magnet.width / 2;
magnetPosition.x = this.intersectedBounds.x - this.magnet.width / 2;
break;
default:
throw new Error( 'invalid magnetMovingDirection: ' + this.magnetMovingDirection );
Expand All @@ -197,11 +197,11 @@ define( function( require ) {

// out of simulation bounds
if ( !this.bounds.containsBounds( magnetBounds ) ) {
position.x = Math.max( Math.min( position.x, this.bounds.maxX - this.magnet.width / 2 ), this.bounds.x + this.magnet.width / 2 );
position.y = Math.max( Math.min( position.y, this.bounds.maxY - this.magnet.height / 2 ), this.bounds.y + this.magnet.height / 2 );
magnetPosition.x = Math.max( Math.min( magnetPosition.x, this.bounds.maxX - this.magnet.width / 2 ), this.bounds.x + this.magnet.width / 2 );
magnetPosition.y = Math.max( Math.min( magnetPosition.y, this.bounds.maxY - this.magnet.height / 2 ), this.bounds.y + this.magnet.height / 2 );
}
}
this.magnet.positionProperty.set( position );
this.magnet.positionProperty.set( magnetPosition );
}
} );
} );
4 changes: 2 additions & 2 deletions js/faradays-law/model/Magnet.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2014-2017, University of Colorado Boulder

/**
* Model container for the magnet in 'Faradays Law' simulation.
* Magnet model for the 'Faradays Law' simulation.
*
* @author Vasily Shakhov (MLearner)
* @author Sam Reid (PhET Interactive Simulations)
*/
define( function( require ) {
'use strict';
Expand All @@ -19,7 +20,6 @@ define( function( require ) {
var TBoolean = require( 'ifphetio!PHET_IO/types/TBoolean' );

/**
*
* @param {number} x - x position of magnet
* @param {number} y - y position of magnet
* @param {number} width - width of magnet
Expand Down
10 changes: 5 additions & 5 deletions js/faradays-law/view/MagnetFieldLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,23 @@ define( function( require ) {
};

/**
* @param magnetModel - magnet model of 'Faradays Law' simulation
* @param magnet - magnet model of 'Faradays Law' simulation
* @constructor
*/
function MagnetFieldLines( magnetModel ) {
function MagnetFieldLines( magnet ) {
//TODO: Shoule we declare the above functions within the constructor? It seems like this structure needs an update.
Node.call( this );

// top field lines
var topLines = createSideFieldLines( magnetModel.flippedProperty );
var topLines = createSideFieldLines( magnet.flippedProperty );
this.addChild( topLines );

// bottom field lines
var bottomLines = createSideFieldLines( magnetModel.flippedProperty );
var bottomLines = createSideFieldLines( magnet.flippedProperty );
bottomLines.scale( 1, -1 );
this.addChild( bottomLines );

magnetModel.showFieldLinesProperty.linkAttribute( this, 'visible' );
magnet.showFieldLinesProperty.linkAttribute( this, 'visible' );

}

Expand Down
8 changes: 4 additions & 4 deletions js/faradays-law/view/MagnetNodeWithField.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ define( function( require ) {
var SimpleDragHandler = require( 'SCENERY/input/SimpleDragHandler' );

// Create single MagnetNode View
var createMagnetNode = function( magnetModel ) {
return new MagnetNode( magnetModel.flippedProperty.get(), {
width: magnetModel.width,
height: magnetModel.height,
var createMagnetNode = function( magnet ) {
return new MagnetNode( magnet.flippedProperty.get(), {
width: magnet.width,
height: magnet.height,
showArrows: true
} );
};
Expand Down

0 comments on commit bb5ed27

Please sign in to comment.