-
Notifications
You must be signed in to change notification settings - Fork 5
Add support for the triangular lattice #53
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
base: main
Are you sure you want to change the base?
Conversation
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.
Well done!
is_square_grid(g::GridGraph) = g.gridtype isa SquareGrid | ||
is_triangular_grid(g::GridGraph) = g.gridtype isa TriangularGrid |
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.
Can we remove these two functions?
print_grid(io, grid; show_weight=SHOW_WEIGHT[]) | ||
end | ||
Base.size(gg::GridGraph) = gg.size | ||
Base.size(gg::GridGraph, i::Int) = gg.size[i] | ||
function graph_and_weights(grid::GridGraph) | ||
return unit_disk_graph(getfield.(grid.nodes, :loc), grid.radius), getfield.(grid.nodes, :weight) | ||
if is_triangular_grid(grid) |
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.
use dispatch, e.g.
function graph_and_weights(grid::GridGraph{NT, <:SquareGrid})
function graph_and_weights(grid::GridGraph{NT, <:TriangularGrid}) where NT
return unit_disk_graph(getfield.(grid.nodes, :loc), grid.radius), getfield.(grid.nodes, :weight) | ||
if is_triangular_grid(grid) | ||
# For triangular grids, use physical positions | ||
physical_locs = [physical_position(node) for node in grid.nodes] |
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.
You do not need to use dispatch, just implement the same physical_position
interface for square lattice.
return g | ||
end | ||
|
||
function physical_position(node, parity=false) |
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.
Implement the same function for square lattice.
M = nrow*s+1+2*padding | ||
u = fill(empty(mode isa Weighted ? MCell{Int} : MCell{ONE}), M, N) | ||
s = get_spacing(mode) | ||
N = (n-1)*s+2+2*padding |
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.
Why +2
now?
function mis_overhead_copyline(w::W, line::CopyLine) where W | ||
if W === Weighted | ||
s = 4 | ||
function mis_overhead_copyline(w::W, line::CopyLine, s::Int=4) where W |
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.
function mis_overhead_copyline(w::W, line::CopyLine, s::Int=4) where W | |
function mis_overhead_copyline(w::W, line::CopyLine, s::Int) where W |
Do not use default parameter for low level API.
|
||
# Get spacing value based on mode | ||
get_spacing(::Union{UnWeighted, Weighted}) = 4 | ||
get_spacing(::TriangularWeighted) = 14 |
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.
It is so big. Can we make it smaller, just use different spacing for X and Y axis.
No description provided.