@@ -34,6 +34,7 @@ function (𝒜::Adjacency{0,D,T})(ind::Integer) where {D,T<:GridTopology}
34
34
# construct topology for vertices
35
35
vtopo = GridTopology (dims .+ 1 , cycl)
36
36
𝒜vert = Adjacency {D} (vtopo)
37
+
37
38
𝒜vert (ind)
38
39
end
39
40
@@ -44,25 +45,25 @@ function (𝒜::Adjacency{D,D,T})(ind::Integer) where {D,T<:GridTopology}
44
45
cycl = isperiodic (topo)
45
46
cind = elem2cart (topo, ind)
46
47
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)
49
52
50
- ninds = NTuple{D,Int}[]
51
- for offset in offsets
52
53
# apply offset to center index
53
54
sind = cind .+ offset
54
55
55
56
# 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
58
60
59
61
# discard invalid indices
60
62
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... ) )
62
64
end
63
65
64
- # return linear index of element
65
- [cart2elem (topo, ind... ) for ind in ninds]
66
+ ntuple (i -> inds[i], length (inds))
66
67
end
67
68
68
69
# -------------------
@@ -74,32 +75,32 @@ function (𝒜::Adjacency{0,2,T})(vert::Integer) where {T<:HalfEdgeTopology}
74
75
e = half4vert (𝒜. topology, vert)
75
76
76
77
# initialize result
77
- vertices = [e. half. head]
78
+ inds = [e. half. head]
78
79
79
80
# search in CCW orientation
80
81
p = e. prev
81
82
h = p. half
82
83
while ! isnothing (h. elem) && h != e
83
- push! (vertices , p. head)
84
+ push! (inds , p. head)
84
85
p = h. prev
85
86
h = p. half
86
87
end
87
88
88
89
# if border edge is hit
89
90
if isnothing (h. elem)
90
91
# add last arm manually
91
- push! (vertices , p. head)
92
+ push! (inds , p. head)
92
93
93
94
# search in CW orientation
94
95
h = e. half
95
96
while ! isnothing (h. elem)
96
97
n = h. next
97
98
h = n. half
98
- pushfirst! (vertices , h. head)
99
+ pushfirst! (inds , h. head)
99
100
end
100
101
end
101
102
102
- vertices
103
+ ntuple (i -> inds[i], length (inds))
103
104
end
104
105
105
106
# adjacent elements in a 2D half-edge topology
@@ -117,5 +118,5 @@ function (𝒜::Adjacency{2,2,T})(ind::Integer) where {T<:HalfEdgeTopology}
117
118
n = n. next
118
119
end
119
120
120
- inds
121
+ ntuple (i -> inds[i], length (inds))
121
122
end
0 commit comments