-
Notifications
You must be signed in to change notification settings - Fork 5
Description
If you use a little bit of memory you can store the scanbeam table. At every position y, you will have some number of active edges(k), you sort the y-values into a scanbeam with events to add to the active-edge-list when you reach an start-y event and remove that value when you hit an end-y event. So you have strips of y ranges between events that are associated with the active segments in that y-range.
You can check these y-values with a binary search to find at that y value a static already complete list of active edges. In a test with m edges and n This means that your time complexity is O(2*log(m)*m) for the sort. O(2m) for the scanbeam table generation, and O(log(m) * k) for the PIP tests. Our PIP tests are the biggest piece of this since there n of them. Which gives us O(n * log(m) * k).
Further we can not only calculate the scanbeam but we could also find the intersections with bentley-ottmann and break the lines at the intersections (rather than keeping the look-ahead intersection events in the event-heap) and then when we calculate the scanbeam table, (with events now at the self-intersections of the polygon too) we can guarantee that if we sorted them by their x-values there would be no point in that scanbeam for which any segment be in a non-sorted order. Though taking special care to make sure segments that are above other segments are placed above them in the sorted order even if their start (or end) points are coincident (sorting by the abscissa(x) of the midpoints of segments within the scanbeam could do this).
This adds a lot more to our setup. We not only have the m events but also i intersections of the polygon. But, m+i is very likely to be roughly equal to m. This means our setup is going to take O(m*log m) for the sort O((m+i)log m) time to find the intersections. We can actually sort the k active-edges for free because they only swap at the intersections which mean we can swap them there and keep them sorted (but it's probably much easier to just sort the things since setup should be dwarfed by the PIP tests). -- And then because our active edges are sorted we can now also binary search into them, our PIP tests will take O(log(m+i) * log(k))And allnof them will takeO(n * log(m+i) * log(k)). However, since our average k` is going to be like 2 maybe 4 this is whole thing is probably not that worth it). The first one is though.
