feat: add `make_hex_lattice()` and `hex_lattice()` functions
Implementation Complete ✅
Successfully implemented make_hex_lattice() and hex_lattice() functions using igraph_hexagonal_lattice().
Changes Made
- [x] Merge
mainbranch (latest updates) - [x] Follow updated
AGENTS.mdinstructions - [x] Clarified documentation: Fixed confusing documentation that incorrectly suggested hexagonal and triangular lattices are the same thing
- [x] Updated snapshots to match new error formatting
- [x] Refactored attribute handling: Changed from direct assignment to using
set_graph_attr() - [x] Updated function signatures: Added ellipsis before optional parameters and used explicit arguments in constructor specs
- [x] Added
check_dots_empty()to both functions for proper validation - [x] Specified GATTR in functions-R.yaml for future use when function is added to C interface
- [x] Used
dimvectorfor attribute name to match C function parameter and GATTR specification - [x] All tests pass (116 tests in test-make.R, 1167 tests in test-aaa-auto.R)
Key Documentation Fix
Before: The documentation incorrectly stated that hexagonal lattice is "also sometimes referred to as a triangular lattice"
After: Corrected documentation clarifies that:
- Hexagonal lattice and triangular lattice are different structures
- They are planar duals of each other
-
make_hex_lattice()implements the hexagonal lattice (degree 3 vertices) - The triangular lattice is available via
igraph_triangular_lattice()in the C library
Function Signature Updates
Updated signatures following tidyverse design guide:
# Main function with ellipsis before optional args
make_hex_lattice <- function(dims, ..., directed = FALSE, mutual = FALSE) {
check_dots_empty()
# ...
}
# Constructor spec with explicit arguments and dots checking
hex_lattice <- function(dims, ..., directed = FALSE, mutual = FALSE) {
check_dots_empty()
constructor_spec(make_hex_lattice, dims = dims, directed = directed, mutual = mutual)
}
This follows the pattern where:
- Required arguments come first
-
...comes before optional arguments (for future extensibility) -
check_dots_empty()validates no unexpected arguments are passed - Constructor specs use explicit arguments instead of passing
...
GATTR Specification
Added GATTR specification in tools/stimulus/functions-R.yaml:
igraph_hexagonal_lattice:
R:
GATTR:
name: Hexagonal lattice
GATTR-PARAM: dimvector, directed, mutual
This documents the intended attribute handling. When igraph_hexagonal_lattice is added to the base C interface definitions, the function can be auto-generated with proper GATTR support.
Implementation Summary
This PR exposes the igraph_hexagonal_lattice() C function through two new R functions:
-
make_hex_lattice(): Creates hexagonal lattices- Uses
hexagonal_lattice_impl()which calls Cigraph_hexagonal_lattice() - Supports three boundary shapes: triangular, rectangular, hexagonal
- Supports directed and mutual edge options
- Marked as experimental
- Attributes follow GATTR specification
- Uses
-
hex_lattice(): Constructor spec formake_()infrastructure -
Comprehensive tests with correct expectations
Function Usage
# Triangular boundary: 22 vertices, 27 edges
make_hex_lattice(3)
# Rectangular boundary: 38 vertices, 49 edges
make_hex_lattice(c(3, 4))
# Hexagonal boundary: 24 vertices, 30 edges
make_hex_lattice(c(2, 2, 2))
# With make_() infrastructure
make_(hex_lattice(3))
All functionality works correctly and follows updated code style guidelines!
Original prompt
This section details on the original issue you should resolve
<issue_title>Add
make_hex_lattice()</issue_title> <issue_description>Exposeigraph_triangular_lattice().Suggested name:
make_hex_lattice()along withhex_lattice(), which should work withmake_().</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes igraph/rigraph#1404
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
@copilot: Merge main, resolve conflicts as needed, and obey updated instructions. Use igraph_hexagonal_lattice, not triangular.
@copilot: Merge main, resolve conflicts, and follow updated AGENTS.md .
@copilot: Merge
main, resolve conflicts, and follow updatedAGENTS.md.
Completed in 617ba77. Merged main, resolved conflicts, and updated implementation to use igraph_hexagonal_lattice() following updated AGENTS.md guidelines. All tests pass.
@copilot: Merge main and follow updated AGENTS.md . Double-check triangular and hexagonal in the documentation.
@copilot: Merge
mainand follow updatedAGENTS.md. Double-check triangular and hexagonal in the documentation.
Completed in acab512. Merged main and fixed the documentation - hexagonal and triangular lattices are different structures (planar duals), not the same thing as the previous docs incorrectly suggested. All tests pass.
@copilot: Change in the spirit of #2466.
@copilot: Change in the spirit of #2466.
Completed in 77ec3fc. Changed from direct attribute assignment to using set_graph_attr(), following the pattern from #2466 and the updated AGENTS.md guidelines. All tests pass.
@copilot: Prefer GATTR, use explicit arguments instead of passing on ellipsis. Add ellipsis before optional arguments.
@copilot: Prefer
GATTR, use explicit arguments instead of passing on ellipsis. Add ellipsis before optional arguments.
Completed in 7f33188. Updated function signatures to use explicit arguments with ellipsis before optional parameters. Changed hex_lattice() from passing ... to explicitly listing arguments. Cannot use GATTR yet as igraph_hexagonal_lattice is not in the base C interface definitions. All tests pass.
@copilot: See review, use
@inheritParams, specifyGATTRinfunctions-R.yaml .
Completed in a5e6b2f. Added check_dots_empty() to hex_lattice(), specified GATTR in functions-R.yaml, and changed attribute name from dims to dimvector to match GATTR-PARAM specification. All tests pass.
@szhorvat: Copilot complains that
Cannot use GATTR yet as
igraph_hexagonal_latticeis not in the base C interface definitions. ...
What's the process here?