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

Add Planar Graph #269

Merged
merged 7 commits into from
Jul 24, 2021
Merged

Add Planar Graph #269

merged 7 commits into from
Jul 24, 2021

Conversation

keithdoggett
Copy link
Member

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

  • A few validation checks become fairly trivial with the use of a graph (disconnected interior and consistent area, for example).
  • Later on, this could be extended slightly to compute the relationships between geometries (intersection, difference, etc.).

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.

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.
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
@keithdoggett keithdoggett requested a review from BuonOmo July 7, 2021 21:58
Copy link
Member

@BuonOmo BuonOmo left a 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 Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
Comment on lines 333 to 334
# It is possible that the half-edge will be nil if a suitable one cannot
# be found. This indicates the polygon is likely invalid.
Copy link
Member

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 ?

Copy link
Member Author

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 :)

lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
Copy link
Member

@BuonOmo BuonOmo left a 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!

lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
test/cartesian_planar_graph_test.rb Outdated Show resolved Hide resolved
Copy link
Member

@BuonOmo BuonOmo left a 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 :)

lib/rgeo/cartesian/planar_graph.rb Outdated Show resolved Hide resolved
@keithdoggett
Copy link
Member Author

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.

@keithdoggett keithdoggett merged commit b3ece0b into validity-handling Jul 24, 2021
@keithdoggett keithdoggett deleted the planar-graph branch July 24, 2021 14:42
@keithdoggett keithdoggett mentioned this pull request Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants