hapticdata / toxiclibsjs

Toxiclibsjs is a library for computational design tasks with JavaScript. This library is a port of http://toxiclibs.org for java and processing.
http://haptic-data.com/toxiclibsjs
GNU Lesser General Public License v2.1
810 stars 107 forks source link

Fixed methods of Spline2D.js and Spline3D.js in geom package #32

Closed baseten closed 9 years ago

baseten commented 9 years ago

This commit fixes the getEstimatedArcLength and getDecimatedVertices methods of Spline2D.js and Spline3D.js. The bug in getEstimatedArcLength was that in the original Java the arcLenIndex array is instantiated with a length (arcLenIndex = new float[vertices.size()];). As this isn't really possible in JS, the loop following the instantiation wasn't running at all. In addition, index 0 (arcLenIndex[0]) must always be set to 0 so that the calculations in getDecimatedVertices work correctly. In the Java this is again a result of the arcLenIndex instantiation as the loop which fills this array always begins at 1. There was also another small syntax error in getDecimatedVertices where the uniform array is referenced as a property of the object rather than a local variable.

hapticdata commented 9 years ago

Thank you for this fix, as well as for the explanation. That is a tricky one to spot. Thanks again it is greatly appreciated!

baseten commented 9 years ago

No worries. You've done a great job porting this to JS, really useful!