Pomax / bezierjs

A nodejs and client-side library for (cubic) Bezier curve work
MIT License
1.7k stars 230 forks source link

Should bezier.lineIntersects(line) work for line-line intersections? #200

Open justvanrossum opened 11 months ago

justvanrossum commented 11 months ago

It currently doesn't for me, failing like this:

TypeError: Cannot read properties of undefined (reading 'y')
    at Object.roots (bezier-js.js:553:23)
    at Bezier.lineIntersects (bezier-js.js:1824:18)

I'm not immediately sure what's going on, but if the intention is for this to work, I'd be happy to try to contribute a fix.

Pomax commented 11 months ago

It's not, unless those lines are degenerate Bezier curves. That said, that opinion's not set in stone, so if there's a use-case that justifies it being there, that could be made to happen.

justvanrossum commented 11 months ago

I don't have a strong opinion, I just noticed many things just work for lines, such as project, derivative, get/compute, so I was intuitively hoping it would do line intersection, too.

justvanrossum commented 11 months ago

My use case is finding all the intersections with a line in a complex path (multiple contours, each with line + curve segments). I represent each segment (line, quad or cubic) with a Bezier instance, calling lineIntersects() on each segment — except lines: I special-case the points.length === 2 case and use my own line-line intersect function.