# How to handle Half edge boundary edge iteration from vertex?

Ok so let's say we have a portion of a mesh that looks somewhat like this: A triangle fan with one of the triangles removed. If that triangles was not removed, we could get all the edges adjacent to that vertex this way:

std::vector<GraphEdgePtr> GraphVertex::GetVertexEdges()
{
std::vector<GraphEdgePtr> edges;
auto current_edge = edge;
do
{
edges.push_back(current_edge);
current_edge = current_edge->pair->next;
} while(current_edge != edges);

return edges;
}


However, if the triangle is removed, the above will segfault. One could create an additional loop that iterates backwards from the starting edge in the case the first loop finds a null pointer.

However that is a bit inelegant in my opinion. Is there a way to do it in a single loop? Using a stack or a queue or some sort for example?

• Iterate in both directions - from the current clockwide, and anti-clockwise. – lightxbulb Feb 13 at 4:58
• Right, but that's essentially the second loop I mentioned. Which I am hoping to avoid if can be – Makogan Feb 13 at 5:01
• You visit all elements exactly once - what is the issue? Otherwise you would have to assign to your vertices, the leftmost/rightmost edges - then you would start at one end and finish at the other. – lightxbulb Feb 13 at 6:34

So the boundary edge actually does have an opposite (or pair pointer) and that opposite is fully integrated into the pointer structure, complete with next pointer and everything. Just that its face pointer in null, thus denoting an empty face or hole. So basically every hole is represented by a null face with half edges going around it.