andreaferretti / paths-js

Generate SVG paths for geometric shapes :bar_chart:
http://andreaferretti.github.io/paths-js-react-demo/
Apache License 2.0
1.72k stars 84 forks source link

Bezier curves error out on minus method #31

Closed ekosz closed 8 years ago

ekosz commented 8 years ago

Hi there I'm using paths-js version 0.3.5 and I'm having issues with Bezier curves. Anytime I try to generate a curve either though a SmothCurve graph or directly using the Bezier function, I get an error. Here is a way to reproduce the error.

> var Bezier = require('paths-js/bezier');
undefined
> Bezier({points: [[97,219],[119.69932031054931,198.5]]})
TypeError: Cannot read property '0' of undefined
    at Object.module.exports.minus (node_modules/paths-js/ops.js:38:13)
    at module.exports.reflect (node_modules/paths-js/bezier.js:14:14)
    at node_modules/paths-js/bezier.js:27:41
> Bezier({points: [[0,0],[1,1]]})
TypeError: Cannot read property '0' of undefined
  [snip]

As you can see, even the simple example going from (0,0) to (1,1) errors out. Is there something I'm doing wrong here?

andreaferretti commented 8 years ago

You are right, Bezier curves only work for three or more points. They should not give an error - on two points it would make sense to just draw the line between the points - so it was a mistake on my part.

I am correcting this error, but right now I am in the mid of a translation. Many people are leaving coffeescript for ES6 and I do not want to leave paths.js on a dead end, hence I am rewriting it into ES6. I am almost done, so I should have a new release by the end of the week or so. After that, I will fix the issue.

In the meantime, you can check that you are using at least three points, and when you get less, use a line.

andreaferretti commented 8 years ago

I have fixed the issue on the version that is coming in a few days. I could quickly fix it on the coffeescript version as well, but then making a release takes a little time

andreaferretti commented 8 years ago

Should be fixed now in version 0.4.0-beta

ekosz commented 8 years ago

@andreaferretti Awesome, should I close this issue?

Sorry for bothering you with this, I figured the multiple points out a couple hours after opening this issue and reading the source code for a bit.

andreaferretti commented 8 years ago

Sure, just check it works for you before closing! ;-)