Skip to content

Commit

Permalink
factor out ZERO_MAGNITUDE_THRESHOLD constant, #260
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Oct 29, 2019
1 parent 073931d commit 9783180
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion js/common/view/RootVectorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ define( require => {
VectorAdditionConstants.DEFAULT_GRAPH_BOUNDS.height - VectorAdditionConstants.VECTOR_TAIL_DRAG_MARGIN
).magnitude;

// magnitude smaller than this value is effectively zero
const ZERO_MAGNITUDE_THRESHOLD = 1E-10;

class RootVectorNode extends Node {

/**
Expand Down Expand Up @@ -167,7 +170,7 @@ define( require => {

// If the magnitude is effectively 0, center the label on the vector's position.
// See https://github.com/phetsims/vector-addition/issues/260
if ( rootVector.magnitude < 1E-10 ) {
if ( rootVector.magnitude < ZERO_MAGNITUDE_THRESHOLD ) {
this.labelNode.center = modelViewTransform.modelToViewDelta( Vector2.ZERO );
return;
}
Expand Down

0 comments on commit 9783180

Please sign in to comment.