private HalfEdge Flip(HalfEdge edge) { var twin = edge.Twin; var edgeNext = edge.Next; var twinNext = twin.Next; edge.Prev.Next = twinNext; twin.Prev.Next = edgeNext; edge.Detach(); twin.Detach(); edge = new HalfEdge(edgeNext.Next.Origin) { Next = twinNext.Next }; twin = new HalfEdge(twinNext.Next.Origin) { Next = edgeNext.Next }; edge.TwinWith(twin); edgeNext.Next = edge; twinNext.Next = twin; return(edge); }