@@ -34,6 +34,7 @@ function (𝒜::Adjacency{0,D,T})(ind::Integer) where {D,T<:GridTopology}
3434 # construct topology for vertices
3535 vtopo = GridTopology (dims .+ 1 , cycl)
3636 𝒜vert = Adjacency {D} (vtopo)
37+
3738 𝒜vert (ind)
3839end
3940
@@ -44,25 +45,25 @@ function (𝒜::Adjacency{D,D,T})(ind::Integer) where {D,T<:GridTopology}
4445 cycl = isperiodic (topo)
4546 cind = elem2cart (topo, ind)
4647
47- # offsets along each dimension
48- offsets = [ntuple (i -> i == d ? s : 0 , D) for d in 1 : D for s in (- 1 , 1 )]
48+ inds = Int[]
49+ for d in 1 : D, s in (- 1 , 1 )
50+ # offset along each dimension
51+ offset = ntuple (i -> i == d ? s : 0 , D)
4952
50- ninds = NTuple{D,Int}[]
51- for offset in offsets
5253 # apply offset to center index
5354 sind = cind .+ offset
5455
5556 # wrap indices in case of periodic dimension
56- wrap (i) = mod1 (sind[i], dims[i])
57- wind = ntuple (i -> cycl[i] ? wrap (i) : sind[i], D)
57+ wind = ntuple (D) do i
58+ cycl[i] ? mod1 (sind[i], dims[i]) : sind[i]
59+ end
5860
5961 # discard invalid indices
6062 valid (i) = 1 ≤ wind[i] ≤ dims[i]
61- all (valid, 1 : D) && push! (ninds, wind)
63+ all (valid, 1 : D) && push! (inds, cart2elem (topo, wind... ) )
6264 end
6365
64- # return linear index of element
65- [cart2elem (topo, ind... ) for ind in ninds]
66+ ntuple (i -> inds[i], length (inds))
6667end
6768
6869# -------------------
@@ -74,32 +75,32 @@ function (𝒜::Adjacency{0,2,T})(vert::Integer) where {T<:HalfEdgeTopology}
7475 e = half4vert (𝒜. topology, vert)
7576
7677 # initialize result
77- vertices = [e. half. head]
78+ inds = [e. half. head]
7879
7980 # search in CCW orientation
8081 p = e. prev
8182 h = p. half
8283 while ! isnothing (h. elem) && h != e
83- push! (vertices , p. head)
84+ push! (inds , p. head)
8485 p = h. prev
8586 h = p. half
8687 end
8788
8889 # if border edge is hit
8990 if isnothing (h. elem)
9091 # add last arm manually
91- push! (vertices , p. head)
92+ push! (inds , p. head)
9293
9394 # search in CW orientation
9495 h = e. half
9596 while ! isnothing (h. elem)
9697 n = h. next
9798 h = n. half
98- pushfirst! (vertices , h. head)
99+ pushfirst! (inds , h. head)
99100 end
100101 end
101102
102- vertices
103+ ntuple (i -> inds[i], length (inds))
103104end
104105
105106# adjacent elements in a 2D half-edge topology
@@ -117,5 +118,5 @@ function (𝒜::Adjacency{2,2,T})(ind::Integer) where {T<:HalfEdgeTopology}
117118 n = n. next
118119 end
119120
120- inds
121+ ntuple (i -> inds[i], length (inds))
121122end
0 commit comments