Hexagonal grid graph#2262
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2262 +/- ##
==========================================
+ Coverage 83.30% 83.33% +0.02%
==========================================
Files 371 371
Lines 60910 61018 +108
==========================================
+ Hits 50739 50847 +108
Misses 10171 10171
Continue to review full report at Codecov.
|
|
Thanks for working on this, this will be great! I have not looked at either the code or its output yet, just wanted to make sure we're on the same page about the idea. The input should be the same as for the triangular lattice, and the output should be a hex lattice whose dual is the triangular lattice obtained with the same parameters. Here are some illustrations: Notice that every red tri lattice node is in the centre of a blue hexagon, but the reverse is not true. Not every blue node is in the middle of a triangle. My reasoning for this choice: if we put a node in the centre of every triangle, we will not always get complete hexagons. There will be some degree-1 nodes at the corners. I do not have hex lattice graphs implemented in Mathematica, so this implementation doesn't have to match anything. If you are wondering how I generated these: I have an implementation of various geometric meshes: not quite the same thing as a graph, but one can derive a graph from it, and in case of the hexagonal mesh it happens to give nice results. It would be great to index the vertices in a way that it wouldn't be too hard to generate coordinates for them to get nice plots like above. The way you implemented the triangular lattice makes this easy, so that's great. If you feel that in order to allow the tri and hex lattices to match, you should change something in the tri lattice implementation, feel free to do that. Let us know if you have any questions! When the PR is ready, mark it as "ready for review". |
@szhorvat Thanks for the link! For me it is also easy to draw it with The labelling at this point is row based similarly as in the case of the triangular grid if interpretting the lattice as a brick wall, which should allow for constructing a layout but I expect it to be a bit more intricate than in the case of the triangular lattice. |
|
It seems I accidentally marked this as "ready for review". I reverted to draft, just let us know when you consider it ready. The plots look great! |
|
I marked it ready for review :-) ! @szhorvat |
szhorvat
left a comment
There was a problem hiding this comment.
Just some doc formatting for now.
In the switch statements, can you un-indent the body by one level so that the case lines up with the switch?
The screenshots you shared show that this works well, so I don't expect issues. I'll do partial integration into the Mma interface and test it a bit, then I think we can merge.
|
|
||
| IGRAPH_VECTOR_INT_INIT_FINALLY(&edges, 0); | ||
|
|
||
| COMPUTE_NUMBER_OF_VERTICES |
There was a problem hiding this comment.
Would it be possible to embed opening and closing braces inside the definition of COMPUTE_NUMBER_OF_VERTICES? This would make it possible to add a semicolon after COMPUTE_NUMBEF_OF_VERTICES when it's being used here; not having a semicolon at the end of the line might confuse syntax highlighters that are not advanced enough to recognize that we are working with a macro here.
There was a problem hiding this comment.
Instead of just using { ... }, please use do { .... } while (0) when defining the macro. This will shut up some linters that would complain about an empty statement when the semicolon is added.
Actually, I'm wondering if this is better converted a real function ... but that's not really important.
There was a problem hiding this comment.
Let me know if it is Ok now.
|
I won't have time to integrate this into the Mma interface for a while. Feel free to merge, @ntamas, once you're happy. |
|
Thanks a lot! |



Implements a hexagonal grid #1843 dual to the triangular grid
Examples for some inputs from the unit test:
for
dimvector=(5),directed=true,mutual=falsefor

dimvector=(4, 5),directed=true,mutual=truefor

dimvector=(3, 4, 5),directed=false