Skip to content

Commit

Permalink
bump above ground if constraining control points puts spline below gr…
Browse files Browse the repository at this point in the history
…ound, seee #191
  • Loading branch information
jessegreenberg committed Feb 25, 2020
1 parent d3652f4 commit 265dc3f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion js/energy-skate-park/common/model/Track.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,28 @@ define( require => {
this.controlPoints[ i ].sourcePositionProperty.value = newPoint;
}
}

this.updateSplines();

// It is possible that containing the control points has pushed a portion of the spline back
// underground, if that is the case bump them back above ground. But only do this if no control points
// are "snapping" as the spline *could* be underground temporarily in this case
const anyControlPointsSnapping = _.some( this.controlPoints, point => point.snapTargetProperty.get() );
if ( !anyControlPointsSnapping ) {

const lowestY = this.getLowestY();
if ( lowestY < 0 ) {

// push the track above ground by an amount that isn't prone to precision errors, see
// https://github.com/phetsims/energy-skate-park/issues/191
const correction = lowestY - 0.001;

// translate updates splines for us
this.translate( 0, -correction );
assert && assert( this.getLowestY() >= 0, 'track should be above ground' );
}
}

// assert && assert( this.getLowestY() >= 0, 'track should be above ground' );
this.updateEmitter.emit();
}

Expand Down

0 comments on commit 265dc3f

Please sign in to comment.