-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First full working implementation #4
base: master
Are you sure you want to change the base?
Conversation
Wow @sheerun I'm really looking forward to seeing what you've done, I'll spend some time this evening checking it out! |
Hi @sheerun I've just updated the I also have a branch called On the downside running
My general experience is that this is due to the union-ing step, from what I can see your approach potentially calls union twice which isn't ideal. I was hoping I might be able to use shamos-hoey to detect if there were any self-intersections before performing a union. Anyway I'll need to do some further digging into what might be causing the slowness. Thanks for a massive contribution! |
@rowanwins I think at this point most performance improvement, including shamos-hoey, can go directly to polygon-clipping repository (even if only as a flag), so other people can also use it. As for calling union twice it's only appears so. In reality underneath union is called for each pair of polygons anyway, so there are N union calls, not 2 of them. |
Hi @sheerun
I'm not quite sure I understand this comment sorry. Are you basically saying that effort needs to go to speeding up the Using my
We're taking a big performance hit by calling
Even detecting the self-intersections is quick with
However it's working out how to remedy the self-intersections that's the hard part.... unfortunately thats the part that most journal papers are a bit vague on (eg this paper references bentley-otmann but that's it, this paper leverages the c++ GLU tessellator to handle it). Perhaps the simplest work I've come across is here which makes it look simple but I'm sure the devil is in the detail.... I suspect part of the benefit that jsts has is that all the data structures are in the one place, whereas we're passing data from library to library which comes with overhead... I'm not sure if @dr-jts has any helpful advice at this stage - I guess the basic question is do I need to use a full blown union algorithm (eg |
That's pretty much what I mean :) I don't really know how polygon-clipping is working internally but I think some improvements could happen e.g. if polygons were being "unionised" by selecting each time polygons with 2 least amount of edges. It's because according to the authors:
Maybe polygon-clipping could also skip unionizing in some cases e.g. if bounding boxes of some polygons are not overlapping. Maybe also by clustering polygons and skipping unionizing in some cases, hard to tell...
I believe slowdown might not be because of passing references but because of algorithm itself which seems that needs to be very complicated to handle all edge cases. It's better to measrure this first before optimizing. Especially difficult case is big buffer with small polygon where there are countless possibilities to cover.. I think it could take many months to develop correct algorithm that doesn't depend on |
In short I believe the correct way forward is to:
I also believe currently the only fool-proof way to remedy detected intersections is to use Martinez-Rueda-Feito which seems to have the same performance as dissolving algorithm you're linking. |
Another optimizatin can come from reducing number of "parts" that we call .union with post-processing resulting In short there are many ways to improve performance, but current implementation is good enough to ship |
I'm just using @turfjs/nearest-point " https://github.com/Turfjs/turf/tree/master/packages/turf-nearest-point " to get nearby users |
Hi @anastely I'm not sure why you're asking your question in this repo? If you've got an issue with turf open it over in the turf repo. Thanks |
@rowanwins I'm confused, so sorry, I was think he have a answer or something |
@rowanwins May I suggest to incorporate this implemetation as part of Turf 7 just so you could publish stable version of it without JSTS, and then publish separate version of |
This PR builds on top of #1 but totall changes algorithm that relies on
union
anddifference
of polygon-clipping library (it turned out that martinez-polygon-clipping that you currently use has bugs that prevent correct union). The performance is more or less on par with JSTS but there is some room for improvement..The change of algorithm is because it's really hard to handle cases where buffer is more wide than feature that is buffered (e.g. buffering series of small angles with buffer 5x of their size). Your approach of finding intersection of elongated segments simpley doesn't work in such cases which you might be already aware. The approach I've selected doesn't have any issues except bug within polygon-clipping itself: mfogel/polygon-clipping#60 (it can be reproduces on Warsaw example I've added to demo app).
I'm sending this PR because it's mostly working implementation and I won't have much more time this week to polish this and fix all tests. I've improved debugger so I'm pretty sure it works is most cases.
The polygons I'm unioning have shape of santa claus staff because I've found it's minimal shape that I can draw for each angle of polygon that covers all the cases.
Here's video how it currently works: https://v.usetapes.com/4py5dUu9Wc