Skip to content

Commit

Permalink
Use roundSymmetric and other minor cleanup, see phetsims/tasks#275
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jun 23, 2015
1 parent 302f3c2 commit 7e1d33e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion js/common/view/ReadoutArrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ define( function( require ) {
//Update when the value changes
valueProperty.link( function( value ) {
readoutArrow.value = value;
readoutArrow.valueNode.text = StringUtils.format( forceReadoutPattern, Math.abs( Math.round( value ) ).toFixed( 0 ) );
readoutArrow.valueNode.text = StringUtils.format( forceReadoutPattern, Math.round( Math.abs( value ) ).toFixed( 0 ) );
readoutArrow.update();
} );

Expand Down
12 changes: 8 additions & 4 deletions js/motion/view/MotionScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ define( function( require ) {
var Property = require( 'AXON/Property' );
var DerivedProperty = require( 'AXON/DerivedProperty' );
var ArrowButton = require( 'SCENERY_PHET/buttons/ArrowButton' );
var Util = require( 'DOT/Util' );

var skateboardImage = require( 'image!FORCES_AND_MOTION_BASICS/skateboard.png' );

/**
Expand Down Expand Up @@ -121,7 +123,7 @@ define( function( require ) {
model.appliedForceProperty.link( function( appliedForce ) {

//Must match the other formatters below, see roundedAppliedForceProperty near the creation of the ReadoutArrows
var numberText = parseInt( Math.round( appliedForce ).toFixed( 0 ), 10 ).toFixed( 0 );
var numberText = parseInt( Util.roundSymmetric( appliedForce ).toFixed( 0 ), 10 ).toFixed( 0 );

//Prevent -0 from appearing, see https://github.com/phetsims/forces-and-motion-basics/issues/70
if ( numberText === '-0' ) { numberText = '0'; }
Expand Down Expand Up @@ -272,17 +274,19 @@ define( function( require ) {
var roundedAppliedForceProperty = new DerivedProperty(
[ model.appliedForceProperty ],
function( appliedForce ) {
return Math.round( appliedForce );
return Util.roundSymmetric( appliedForce );
} );
var roundedFrictionForceProperty = new DerivedProperty(
[ model.frictionForceProperty ],
function( frictionForce ) {
return Math.round( frictionForce );
return Util.roundSymmetric( frictionForce );
} );

//Only update the sum force arrow after both friction and applied force changed, so we don't get partial updates, see https://github.com/phetsims/forces-and-motion-basics/issues/83
var roundedSumProperty = new Property( roundedAppliedForceProperty.get() + roundedFrictionForceProperty.get() );
model.on( 'stepped', function() { roundedSumProperty.set( roundedAppliedForceProperty.get() + roundedFrictionForceProperty.get() ); } );
model.on( 'stepped', function() {
roundedSumProperty.set( roundedAppliedForceProperty.get() + roundedFrictionForceProperty.get() );
} );

this.sumArrow = new ReadoutArrow( sumOfForcesString, '#96c83c', this.layoutBounds.width / 2, 230, roundedSumProperty, model.showValuesProperty, {
labelPosition: 'top',
Expand Down
3 changes: 2 additions & 1 deletion js/motion/view/PusherNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define( function( require ) {
var Node = require( 'SCENERY/nodes/Node' );
var SimpleDragHandler = require( 'SCENERY/input/SimpleDragHandler' );
var inherit = require( 'PHET_CORE/inherit' );

var pusherStraightImage = require( 'image!FORCES_AND_MOTION_BASICS/pusher_straight_on.png' );
var pusherFallDownImage = require( 'image!FORCES_AND_MOTION_BASICS/pusher_fall_down.png' );
var pusherImage0 = require( 'image!FORCES_AND_MOTION_BASICS/pusher_0.png' );
Expand Down Expand Up @@ -130,7 +131,7 @@ define( function( require ) {
updateZeroForcePosition();
}
else {
var index = Math.min( 14, Math.round( Math.abs( (appliedForce / 500 * 14) ) ) );
var index = Math.min( 14, Math.round( Math.abs( appliedForce / 500 * 14 ) ) );
if ( appliedForce > 0 ) {
setVisibleNode( pushingRightNodes[ index ] );
}
Expand Down

0 comments on commit 7e1d33e

Please sign in to comment.