thibauts / b-spline

B-spline interpolation
MIT License
299 stars 48 forks source link

Rounding error causing 'out of bounds' #14

Closed davidgilbertson closed 5 years ago

davidgilbertson commented 5 years ago

When this part of the codebase runs: https://github.com/thibauts/b-spline/blob/fdc3a3184a99884153580896478b69f21e74436c/index.js#L36-L40 it throws "Out of bounds" with valid values, because of a rounding error.

For example with these values, we get an error:

    let t = 1;

    const high = 83.50120024816177;
    const low = 1.545996015332399

    t = t * (high - low) + low;

    // t is now 83.50120024816178 - higher than high!= by 0.00000000000001

    if(t < low || t > high) throw new Error('out of bounds');
davidgilbertson commented 5 years ago

Oh, I just saw that that the owner of dxf has made a pull request to fix this: https://github.com/thibauts/b-spline/pull/13. I'll close this, but would be great if that could be merged