It doesnât depend at all on vert order, and thatâs by design. Each vert knows its neighbors to both sides regardless of the vertex ordering. The only thing we donât know is if the left vert, or the right vert is the first neighbor in the list.
Instead of using numbers, Iâll use letters. Hopefully that will illustrate that numbers donât matter, all that matters is the relationship in neighborDict.
neighborDict = {
a: [e, b],
b: [c, a],
c: [b, d],
d: [c, e],
e: [a, d],
}
Say we start the while loop with vertLoop = [a, b]
. As long as weâve got 2 verts that are neighbors as the first 2 items in vertLoop
, the code will work (For instance, it would still work if we started with vertLoop = [e, d]
)
So we look in the dict for the last item in the current loop (thatâs b
in this case), and see that its neighbors are [c, a]
. So we check, is the first item c
right before b
in vertLoop
? Itâs not, so we can append that to vertLoop
.
Now weâve got vertLoop = [a, b, c]
, so we look in the dict and find c
and see its neighbors are [b, d]
. So we check is b
right before c
in vertLoop
? It is, so we can append the other neighbor to our list. In this case, thatâs d
.
This keeps going like that until we get to vertLoop = [a, b, c, d, e, a]
. Notice how a
got added to the end? Well, now the first and last item in the list are the same. That means weâve come back to where we started, so weâve got an entire loop! So we can just chop off that ending a
and return.
Now that youâve got the loop, itâs easy to do something like
vertLoop = reversed(vertLoop)
to reverse it.
Or vertLoop = vertLoop[3:] + vertLoop[:3]
to shift the loop so youâre starting with the item at index 3.