phetsims / kite

A library for creating, manipulating and displaying 2D shapes in JavaScript.
MIT License
12 stars 6 forks source link

Vector Rendering Update Error #69

Closed Denz1994 closed 7 years ago

Denz1994 commented 7 years ago

While working with @samreid in Masses and Springs we discovered that the startPoint and subpath.getFirstPoint() are not equal and thus firing an error.

Steps to reproduce:

  1. Start Masses and Springs sim
  2. Select Vector Screen
  3. Select Velocity Vector in visibility panel
  4. Drag mass and attach to spring so it oscillates
  5. Stop spring using stop sign button next to the spring hanger.
  6. Drag mass off of spring
  7. Error should be fired

Checking the startPoint and subpath.getFirstpoint() shows that they aren't equal in this piece of code.

Shape.js

        if ( subpath.isDrawable() ) {
          // since the commands after this are relative to the previous 'point', we need to specify a move to the initial point
          var startPoint = subpath.segments[ 0 ].start;
          assert && assert( startPoint.equalsEpsilon( subpath.getFirstPoint(), 0.00001 ) ); // sanity check
          string += 'M ' + kite.svgNumber( startPoint.x ) + ' ' + kite.svgNumber( startPoint.y ) + ' ';

Any insight would help. Thanks @jonathanolson.

samreid commented 7 years ago

I committed a workaround for MassNode. You can uncomment any of the if ( Math.abs( springForce ) < 1E-6 ) { lines to get the bug back.

jonathanolson commented 7 years ago

The mutation of Shape points triggered the assertion (since the assertion was written before the mutability was supported). There's no good way for the assertion to help (or for Kite to internally track those point changes), so I've removed the assertion.