-
Notifications
You must be signed in to change notification settings - Fork 165
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
Add Planar Graph #269
Add Planar Graph #269
Conversation
Adds a PlanarGraph implementation based on a Doubly Connected Edge List (DCEL). A DCEL is a graph data structure of vertices and half-edges. Half-edges are directed edges where one segment can be represented by a pair of half-edges. Half-edges are linked so that faces can be traversed (although faces are not stored). The PlanarGraph accepts an array of segments to build it and additional edges can be added via the add_edge and add_edges methods. When edges are added, intersections are automatically recomputed and handled. When possible, existing half-edges are preserved so that geometries can reference those half-edges. Also adds GeometryGraph which is a convenient way to interface geometries to a planar graph and provides ways to find important half-edges in each geometry. I haven't done a full performance test yet, but one notable area of improvement is that everytime an edge or edges is added, all of the half-edges are re-linked when we likely only need to re-link the half-edges that originate at new vertices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for that complete implementation, at this point I'm just waiting for the third PR to see usage of all that!
I've already made a few comments, tried to answer you questions, and ask some questions of my own. I think I'll have to review that completely a second time just to be sure I've fully understood it.
lib/rgeo/cartesian/planar_graph.rb
Outdated
# It is possible that the half-edge will be nil if a suitable one cannot | ||
# be found. This indicates the polygon is likely invalid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likely here is a bit scary. Is there a possibility it is valid ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no scenario I can think of where this would happen and the polygon would be valid, but I suppose that may not be the most robust test :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 last comments, plus maybe the class renaming. I think it's good to me now, I'll let you finish :)
You can always slack me if something is unclear!
…alfEdge and Cartesian::GeometryGraph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I've added one last review, nothing mandatory though :)
… if no block is given
Thank you for all the reviews and help with this @BuonOmo. I'm going to merge this and get the validation checking PR up soon. |
Summary
Adds a PlanarGraph implementation based on a Doubly Connected Edge List (DCEL). A DCEL is a graph data structure of
vertices and half-edges. Half-edges are directed edges where one segment can be represented by a pair of half-edges.
Half-edges are linked so that faces can be traversed (although faces are not stored).
The PlanarGraph accepts an array of segments to build it and additional edges can be added via the add_edge and add_edges methods. When edges are added, intersections are automatically recomputed and handled. When possible, existing half-edges are preserved so that geometries can reference those half-edges.
Also adds GeometryGraph which is a convenient way to interface geometries to a planar graph and provides ways to find important half-edges in each geometry.
Algorithm. I can provide more info about it if needed. It's not too complex, just a lot of bookkeeping.
Purpose
Notes
GEOS does something slightly different where their edges are an entire linestring, not just a single edge. This reduces the size and can help simplify computing relationships between geometries, but updating and finding split edges becomes more tedious.