Skip to content

Commit

Permalink
Cleanup in FaradaysLawModel, see #86
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Nov 5, 2017
1 parent 523af6d commit 944b299
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions js/faradays-law/model/FaradaysLawModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ define( function( require ) {
'use strict';

// modules
var BooleanProperty = require( 'AXON/BooleanProperty' );
var Bounds2 = require( 'DOT/Bounds2' );
var CoilModel = require( 'FARADAYS_LAW/faradays-law/model/CoilModel' );
var faradaysLaw = require( 'FARADAYS_LAW/faradaysLaw' );
var inherit = require( 'PHET_CORE/inherit' );
var MagnetModel = require( 'FARADAYS_LAW/faradays-law/model/MagnetModel' );
var Property = require( 'AXON/Property' );
var Vector2 = require( 'DOT/Vector2' );
var VoltmeterModel = require( 'FARADAYS_LAW/faradays-law/model/VoltmeterModel' );

// phet-io modules
var TBoolean = require( 'ifphetio!PHET_IO/types/TBoolean' );

// constants
// restricted zones for magnet because of coils
var TWO_COIL_RESTRICTED_BOUNDS = new Bounds2( 0, 0, 25, 11 );
Expand All @@ -43,14 +40,12 @@ define( function( require ) {
this.bounds = new Bounds2( 0, 0, width, height );

// Whether the top coil should be shown
this.showTopCoilProperty = new Property( false, {
tandem: tandem.createTandem( 'showTopCoilProperty' ),
phetioValueType: TBoolean
this.showTopCoilProperty = new BooleanProperty( false, {
tandem: tandem.createTandem( 'showTopCoilProperty' )
} );

this.showMagnetArrowsProperty = new Property( true, {
tandem: tandem.createTandem( 'showMagnetArrowsProperty' ),
phetioValueType: TBoolean
this.showMagnetArrowsProperty = new BooleanProperty( true, {
tandem: tandem.createTandem( 'showMagnetArrowsProperty' )
} );

this.magnetModel = new MagnetModel( 647, 219, 140, 30, tandem.createTandem( 'magnetModel' ) );
Expand Down Expand Up @@ -88,6 +83,9 @@ define( function( require ) {

return inherit( Object, FaradaysLawModel, {

/**
* @public - restore to initial conditions
*/
reset: function() {
this.magnetModel.reset();
this.showTopCoilProperty.reset();
Expand Down Expand Up @@ -133,6 +131,7 @@ define( function( require ) {

// check intersection with any restricted areas if not intersected yet
if ( this.intersectedBounds === null ) {

// if first coil not visible, check only second coil restrictions
for ( var i = this.showTopCoilProperty.get() ? 0 : 2; i < this.restricted.length; i++ ) {
var restricted = this.restricted[ i ];
Expand All @@ -141,7 +140,9 @@ define( function( require ) {
// extend area so magnet cannot jump through restricted area on other side of it if mouse far enough
var movingDelta = position.minus( this.magnetModel.positionProperty.get() );
this.intersectedBounds = restricted.copy();
if ( Math.abs( movingDelta.y ) > Math.abs( movingDelta.x ) ) { //vertical direction
if ( Math.abs( movingDelta.y ) > Math.abs( movingDelta.x ) ) {

// vertical direction
if ( movingDelta.y > 0 ) { //bottom
this.magnetMovingDirection = 'bottom';
this.intersectedBounds.setMaxY( 3000 );
Expand All @@ -151,7 +152,9 @@ define( function( require ) {
this.intersectedBounds.setMinY( -3000 );
}
}
else { //horizontal
else {

//horizontal
if ( movingDelta.x > 0 ) { //right
this.magnetMovingDirection = 'right';
this.intersectedBounds.setMaxX( 3000 );
Expand Down

0 comments on commit 944b299

Please sign in to comment.