Skip to content

Commit

Permalink
phetsims/tasks#275 replace Math.round with dot.Util.roundSymmetric
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jun 19, 2015
1 parent ab44369 commit 6d4cf34
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions js/common/view/manipulator/PointManipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ define( function( require ) {
var location = modelViewTransform.viewToModelPosition( parentPoint );

// constrain to range, snap to grid
var x = Math.round( Util.clamp( location.x, xRange.min, xRange.max ) );
var y = Math.round( Util.clamp( location.y, yRange.min, yRange.max ) );
var x = Util.roundSymmetric( Util.clamp( location.x, xRange.min, xRange.max ) );
var y = Util.roundSymmetric( Util.clamp( location.y, yRange.min, yRange.max ) );
var p = new Vector2( x, y );

// is this point the same as one of the others?
Expand Down
4 changes: 2 additions & 2 deletions js/common/view/manipulator/SlopeManipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ define( function( require ) {
var location = modelViewTransform.viewToModelPosition( parentPoint );
// constrain to dynamic range, snap to grid
var line = lineProperty.get();
var run = Math.round( Util.clamp( location.x - line.x1, runRangeProperty.get().min, runRangeProperty.get().max ) );
var rise = Math.round( Util.clamp( location.y - line.y1, riseRangeProperty.get().min, riseRangeProperty.get().max ) );
var run = Util.roundSymmetric( Util.clamp( location.x - line.x1, runRangeProperty.get().min, runRangeProperty.get().max ) );
var rise = Util.roundSymmetric( Util.clamp( location.y - line.y1, riseRangeProperty.get().min, riseRangeProperty.get().max ) );
// don't allow slope=0/0, undefined line
if ( rise !== 0 || run !== 0 ) {
lineProperty.set( Line.createPointSlope( line.x1, line.y1, rise, run, line.color ) );
Expand Down
4 changes: 2 additions & 2 deletions js/common/view/manipulator/X1Y1Manipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ define( function( require ) {
var location = modelViewTransform.viewToModelPosition( parentPoint );

// constrain to range, snap to grid
var x1 = Math.round( Util.clamp( location.x, x1RangeProperty.get().min, x1RangeProperty.get().max ) );
var y1 = Math.round( Util.clamp( location.y, y1RangeProperty.get().min, y1RangeProperty.get().max ) );
var x1 = Util.roundSymmetric( Util.clamp( location.x, x1RangeProperty.get().min, x1RangeProperty.get().max ) );
var y1 = Util.roundSymmetric( Util.clamp( location.y, y1RangeProperty.get().min, y1RangeProperty.get().max ) );
var line = lineProperty.get();

if ( constantSlope ) {
Expand Down
4 changes: 2 additions & 2 deletions js/common/view/manipulator/X2Y2Manipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ define( function( require ) {
var location = modelViewTransform.viewToModelPosition( parentPoint );

// constrain to range, snap to grid
var x2 = Math.round( Util.clamp( location.x, x2RangeProperty.get().min, x2RangeProperty.get().max ) );
var y2 = Math.round( Util.clamp( location.y, y2RangeProperty.get().min, y2RangeProperty.get().max ) );
var x2 = Util.roundSymmetric( Util.clamp( location.x, x2RangeProperty.get().min, x2RangeProperty.get().max ) );
var y2 = Util.roundSymmetric( Util.clamp( location.y, y2RangeProperty.get().min, y2RangeProperty.get().max ) );

if ( x2 !== line.x1 || y2 !== line.y1 ) {
// Don't allow points to be the same, this would result in slope=0/0 (undefined line.)
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/manipulator/YInterceptManipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ define( function( require ) {
var location = modelViewTransform.viewToModelPosition( parentPoint );

// constrain to range, snap to grid
var y1 = Math.round( Util.clamp( location.y, y1RangeProperty.get().min, y1RangeProperty.get().max ) );
var y1 = Util.roundSymmetric( Util.clamp( location.y, y1RangeProperty.get().min, y1RangeProperty.get().max ) );
var line = lineProperty.get();

// Keep slope constant, change y1.
Expand Down

0 comments on commit 6d4cf34

Please sign in to comment.