Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

isPANN
Copy link

@isPANN isPANN commented Jul 14, 2025

No description provided.

Copy link
Contributor

@GiggleLiu GiggleLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

Comment on lines +75 to +76
is_square_grid(g::GridGraph) = g.gridtype isa SquareGrid
is_triangular_grid(g::GridGraph) = g.gridtype isa TriangularGrid
Copy link
Contributor

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)
Copy link
Contributor

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]
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

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.

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.

2 participants