In doubly connected edge list how to link halfedges properly


I’m working on doubly connected edge list. In the image below I need to add a new edge (consisting of halfedges $ g$ and $ h$ ). When adding a new edge we need to assign each half edge a previous and next half edges. In this example edge $ g$ would have halfedge $ f$ and $ h$ as previous and next halfedges respectively. And edge $ h$ would have halfedge $ g$ and $ a$ as previous and next halfedges respectively. If we ignore for a second them being linked to each other, $ g$ and $ h$ are linked to the pair $ f$ and $ a$ . I hope this makes sense. My question is when adding a new edge, how do we know how to choose the correct pair to link to? In this example we could link our halfedges to the pair $ a, f$ or $ c,b$ , or $ e,d$ . Do we have to resort to linear algebra, doing cross/dot product calculations to calculate what pair of halfedges to choose, based on the geometry of the edges? Am I possibly going in the completely wrong direction?

To get the potential canditates of pair of halfedges to link to, I iterate through all halfedges linked to vertex $ v$ , which here would be $ a,c,e$ and for each I find the previous halfedge which would $ f, b,d$ respectively.

enter image description here