HarryStevens / geometric

A JavaScript library for doing geometry.
https://www.npmjs.com/package/geometric
MIT License
980 stars 49 forks source link

Two lines of same length and lying on the same line are being detected as intersecting #25

Closed kuzkokov closed 3 years ago

kuzkokov commented 3 years ago

Hi there! Thanks for your great library!

So, I've discovered an issue with the lines intersection function (which is described in the title). To be more specific here is sandbox with an example of the issue. I've made some changes, and here is the pull request, but I'm not really sure if it works correctly for every case. It works for me though. Also, I think it might be simplified somehow. Anyway, please take a look at the sandbox and at PR and maybe share some thoughts.

HarryStevens commented 3 years ago

Hey @kuzkokov, thanks for pointing this out! This is due to a bug introduced in the previous patch (2.2.7), which I should have caught when updating. If you switch your version of Geometric.js to 2.2.6, it'll work.

I'll take a look at your PR this weekend, but I might be able to fix it simply by reverting back to 2.2.6. Sorry for the trouble.

HarryStevens commented 3 years ago

I decided to look just now. It looks good. I just added a test and merged it. If you use 2.2.8, it'll work now. https://codesandbox.io/s/naughty-cache-zk23x?file=/index.html

kuzkokov commented 3 years ago

Awesome, thank you! I was thinking that it definitely should be tested but somehow didn't notice that there are actually tests in the project. 🤦

Actually, I was googling how to do it, and it seems to me that this solution is a bit more, uh, mathematical. Maybe it does make sense to implement it?