Skip to content
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

Implement lazy walk. #46

Merged
merged 13 commits into from
Aug 6, 2018
Merged

Implement lazy walk. #46

merged 13 commits into from
Aug 6, 2018

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Aug 4, 2018

Instead of precomputing the sequence of halfedges for each input site, the Voronoi constructor now computes an index from point id to starting halfedge id, such that the neighboring points can be computed lazily. For points on the hull, the starting halfedge is the incoming edge on the hull; a separate hull index is also needed to store the outgoing hull edge.

To handle coincident input points, these indexes are initialized with -1.

Open questions:

  1. Should these indexes be computed in the Delaunay constructor rather than the Voronoi constructor? It’d be nice to have them for traversing the Delaunay triangulation, for example to construct the nearest neighbor graph. Then the Voronoi constructor would only be responsible for computing the circumcenters and hull vectors. And then I could add neighbor iteration and nearest-neighbor computation to the Delaunay class, and move voronoi.find to delaunay.find, without needing to compute circumcenters.

  2. Suggestions for better names than “halfedgeIndex” and “hullIndex”? I’m tempted to name them “incoming” and “outgoing” but that’s a little vague…

Fixes #34. /cc @redblobgames

@mbostock mbostock requested a review from mourner August 4, 2018 20:15
@redblobgames
Copy link

Last year I called this starts and then a few months later I called it r_in_s which is meaningless to anyone outside my project. So I don't have a good name suggestion :(

I did find it really useful for navigating the delaunay triangulation (both to find the points neighboring a point, and to find the triangles touching a point), so I'd recommend putting it into Delaunay. It's pretty cheap to compute but uses some space.

@mbostock
Copy link
Member Author

mbostock commented Aug 5, 2018

Thanks for the feedback.

I moved the indexes up to Delaunay and renamed them to “inedges” and “outedges”.

I dropped the typed array representation of the hull in favor of Delaunator’s linked list.

I moved voronoi.find up to delaunay.find (though I left voronoi.contains where it is, since the name seemed more appropriate there).

@mbostock
Copy link
Member Author

mbostock commented Aug 5, 2018

Seems like I broke voronoi.renderCell… Will followup with some fixes.

image

@mbostock
Copy link
Member Author

mbostock commented Aug 5, 2018

Fixed.

Copy link
Collaborator

@mourner mourner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love how this makes the code simpler!

@mbostock mbostock merged commit 4f90031 into master Aug 6, 2018
@mbostock mbostock deleted the lazy-walk branch August 6, 2018 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants