I have a hex grid stored in a 2d array; now I want to add some properties to the edges of the grid (e.g. rivers between hexes) and also potentially to the vertices. How can I store edges and vertices
- Without duplication, i.e. I don't want to store a river between two hexes in both, or check neighboring hexes - I want to store it once in the edge.
- With a fast way to find mapping between things, i.e. from a given edge to two hexes it's dividing, or from a given vertex to its 3 edges, etc.
- Efficiently i.e. without tons of pointers in every object to every neighboring object?
I was thinking there should be 3 2d arrays (hexes, vertices, edges) with arithmetic formulas to map things to things. However for the only schemes I can come up with to store vertices and edges (since they don't map naturally onto a 2d array), the mapping formulas between array coordinates are very convoluted. I wonder if there's some simple scheme that I'm missing?