Sort half-edges before generating triangles.

Also, ensure triangles are only generated for connected edges, which is
not always the case in unclosed (border) sites.