Closed jfirebaugh closed 9 years ago
This implements an optimization I think we should try for the JS implementation: f4b0a71.
Interesting! So you suggest storing x
and y
in Node
instances instead of using data[node.i], data[node.i + 1]
for all calculations, right?
Why would this be faster? Better memory access, or shorter path to data?
Yeah, I don't know for sure that it would be faster, but intuitively, since you usually already have a node
reference available, it should be faster because it avoids two memory accesses and may also improve cache locality.
I would like to eliminate the boost::pool
dependency from this PR and instead use a simple preallocated std::unique_ptr<Node[]>
with one Node
for each input vertex. This would depend on eliminating the second place that Nodes are created:
@mourner @kkaefer Is it somehow possible to reuse the existing Nodes in splitPolygon
rather than creating new ones?
@jfirebaugh I believe not since new nodes have different prev/next/prevZ/nextZ pointers. However, polygon split is a relatively rare occurrence — once for each hole and a few more times in case of bad data, so maybe you could do some manual dynamic allocation magic specifically for these.
:+1: for merging, @kkaefer said :+1: in Slack too.
This brings the code closer to the JS implementation, and ensures that it is usable by mapbox-gl-native per #9.
It turned out that discarding unused vertices was not the only way that the indices generated by earcut.hpp were out of sync with input order indices. There were two other sources of desynchronization:
linkedList
(fixed in c18fa5cd377cfe022568bcbc6c895d1e835e9489)@mourner This implements an optimization I think we should try for the JS implementation: f4b0a71df0863bc495cae66170dafc492f489c8f.
Before
After
So the degenerate results are slower, but they are super fast anyway. Real-world cases are a wash.
cc @kkaefer