@@ -216,23 +216,24 @@ function HalfEdgeTopology(elems::AbstractVector{<:Connectivity}; sort=true)
216
216
end
217
217
218
218
function adjsortperm (elems:: AbstractVector{<:Connectivity} )
219
+ # remaining list of elements to process
220
+ oinds = collect (eachindex (elems)[2 : end ])
221
+
219
222
# initialize list of adjacent elements
220
223
# with first element from original list
221
- einds = Int[1 ]
224
+ einds = Int[]
222
225
sizehint! (einds, length (elems))
223
226
224
- # remaining list of elements to process
225
- oinds = collect (2 : length (elems))
226
-
227
227
# `found` minimizes adjacency discontinuities. if `found == true` for the last edge in an
228
228
# element, then we continue from that new element adjacent to that edge
229
229
found = false
230
+ lastfound = firstindex (elems)
230
231
231
232
# lookup all elements that share at least
232
233
# two vertices (i.e., edge) with the last
233
234
# adjacent element
234
235
while ! isempty (oinds)
235
- lelem = elems[last (einds) ]
236
+ lelem = elems[lastfound ]
236
237
vinds = indices (lelem)
237
238
for v in vinds
238
239
# vertices that are not `v`
@@ -245,23 +246,27 @@ function adjsortperm(elems::AbstractVector{<:Connectivity})
245
246
vinds′ = indices (oelem)
246
247
if any (== (v), vinds′) && ! isdisjoint (v!, vinds′)
247
248
found = true
248
- push! (einds, popat! (oinds, iter))
249
+ push! (einds, lastfound)
250
+ lastfound = popat! (oinds, iter)
249
251
# don't increment j here because `popat!` just put the j+1 element at j
250
252
# (avoids the need to reverse the array)
251
253
else
252
- found = false
253
254
iter += 1
254
255
end
255
256
end
256
257
end
257
258
258
- if ! found && ! isempty (oinds)
259
+ if found
260
+ found = false
261
+ elseif ! isempty (oinds)
259
262
# we are done with this connected component
260
263
# pop a new element from the original list
261
- push! (einds, popfirst! (oinds))
264
+ push! (einds, lastfound)
265
+ lastfound = popfirst! (oinds)
262
266
found = false
263
267
end
264
268
end
269
+ push! (einds, lastfound)
265
270
266
271
einds
267
272
end
0 commit comments