[BMesh] How to get verts[v].link_faces[f].index in counter-clockwise order?

I’m working on my first Add-On, which computes the dual of a given mesh. This is done in two steps:

  • Compute the centroids of all faces of the existing mesh. Each centroid is added to the new mesh as a vertex.
  • For every vertex in the existing mesh, find the faces sharing that vertex. The indices of these faces are also the indices of the newly created vertices in the first step! Now, order these indices in a counter-clockwise fashion, and use them to create a face for the new mesh.

The face indices mentioned in the second step are obtained as follows (take for example the third vertex in the existing mesh):


Mesh = bpy.context.edit_object.data
BMesh = bmesh.from_edit_mesh(Mesh)

v = BMesh.verts[2]
face_indices = [v.link_faces[f].index for f in range(len(v.link_faces))]

The resulting list of face indices, however, is not necessarily ordered in a clockwise or counter-clockwise fashion. Is it possible to get the list in this order using link_loops, or should I make use of the lower level structures (e.g. the Disk Cycle)?

[Edit]
Ok, when all faces have their normal pointing outwards, the loops are in a counter-clockwise order. Assuming that the mesh of interest is a 2-manifold, we can proceed as follows.

The first face is found with


l = v.link_loops[0]
first_face = l.face.index

The other faces, in counter-clockwise fashion, are then iteratively found using

l = l.link_loop_prev.link_loop_radial_next
next_face = l.face.index

This seems to be working rather well! Still, if there are other solutions, I’d like to hear them.

interesting, docs say radial / disc data isn’t exposed to python, but apparently it is?!