public static void ValidateFace(NativeHull hull, int faceIndex)
    {
        if (faceIndex < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(faceIndex));
        }

        NativeFace face = hull.GetFace(faceIndex);

        Debug.Assert(face.Edge >= 0,
                     "All faces should point to a starting edge index");

        Debug.Assert(face.Edge < hull.EdgeCount,
                     "A face references an out of range edge index");

        NativeHalfEdge startEdge = hull.GetEdge(face.Edge);
        NativeHalfEdge current   = startEdge;

        int currentIndex = face.Edge;
        var edgeCount    = 0;

        do
        {
            var next = hull.GetEdge(current.Next);

            Debug.Assert(faceIndex == current.Face,
                         "All edges in a face loop should point to the same face");

            Debug.Assert(currentIndex == next.Prev,
                         "Next and previous edges in a face loop should point to each other");

            ValidateEdge(hull, currentIndex);

            if (++edgeCount >= hull.EdgeCount)
            {
                Debug.Assert(true, "Infinite loop in face edges");
                break;
            }

            currentIndex = current.Next;
            current      = next;
        }while (current.Origin != startEdge.Origin);

        Debug.Assert(edgeCount > 1,
                     "Faces should have more than one edge");
    }
    public static unsafe void CheckAllVerticesAreUsed(NativeHull hull)
    {
        for (int i = 0; i < hull.VertexCount; i++)
        {
            bool isUsed = false;
            for (int j = 0; j < hull.EdgeCount; j++)
            {
                NativeHalfEdge edge = hull.GetEdge(j);
                if (edge.Origin == i)
                {
                    isUsed = true;
                    break;
                }
            }

            Debug.Assert(isUsed,
                         "All vertices should be used by an edge");
        }
    }