private void FindFathestPointToHalfSpaceOnce(QHullTrianglePlanePoints plane)
 {
     for (int i = 0; i < mVertexCount; ++i)
     {
         plane.AddPoint(mPoints[i]);
     }
 }
 private void SaveOnce(QHullTrianglePlanePoints facePositive, QHullTrianglePlanePoints faceNegative)
 {
     for (int i = 0; i < mVertexCount; ++i)
     {
         if (!facePositive.AddPoint(mPoints[i]))
         {
             faceNegative.AddPoint(mPoints[i]);
         }
     }
 }
        private void FindOnce(out Vector3 min, out Vector3 max, out Vector3 fathestPoint)
        {
            int minI = -1;
            int maxI = -1;

            FindGappestTwoPointsOnce(ref minI, ref maxI);
            min = mPoints[minI];
            max = mPoints[maxI];
            // parallel z axis
            QHullTrianglePlanePoints trianglePlanePoints = new QHullTrianglePlanePoints(min, max);

            FindFathestPointToHalfSpaceOnce(trianglePlanePoints);
            fathestPoint = trianglePlanePoints.mFathestPoint;
        }
        private void Build()
        {
            Vector3 min;
            Vector3 max;
            Vector3 fathestPoint;

            FindOnce(out min, out max, out fathestPoint);
            // make two sides faces
            QHullTrianglePlanePoints facePositive = new QHullTrianglePlanePoints(min, max, fathestPoint);
            QHullTrianglePlanePoints faceNegative = new QHullTrianglePlanePoints(min, fathestPoint, max);

            // split all Points into two sides faces
            SaveOnce(facePositive, faceNegative);
            // save the face
            mTrianglePlanePoints.Add(facePositive);
            mTrianglePlanePoints.Add(faceNegative);
            // travel
            int step = 0;

            while (step < mTrianglePlanePoints.Count)
            {
                QHullTrianglePlanePoints trianglePlanePointsLoop1 = mTrianglePlanePoints[step++];
                if (trianglePlanePointsLoop1.mIsDelete || trianglePlanePointsLoop1.IsEmpty())
                {
                    continue;
                }
                fathestPoint = trianglePlanePointsLoop1.mFathestPoint;
                int size = mTrianglePlanePoints.Count;
                QHullEdgeBounding edgeStack      = new QHullEdgeBounding();
                List <Vector3>    tempPointsList = new List <Vector3>();
                for (int i = 0; i < size; ++i)
                {
                    QHullTrianglePlanePoints trianglePlanePointsLoop2 = mTrianglePlanePoints[i];
                    if (!trianglePlanePointsLoop2.mIsDelete && trianglePlanePointsLoop2.Inside(fathestPoint))
                    {
                        trianglePlanePointsLoop2.mIsDelete = true;
                        // save the face edges
                        Vector3[] planePoints = trianglePlanePointsLoop2.mTrianglePlane.mVertexPoints;
                        edgeStack.Push(planePoints[0], planePoints[1]);
                        edgeStack.Push(planePoints[1], planePoints[2]);
                        edgeStack.Push(planePoints[2], planePoints[0]);
                        // save the face retaining points
                        if (!trianglePlanePointsLoop2.IsEmpty())
                        {
                            int tempSize = trianglePlanePointsLoop2.mPointsList.Count;
                            for (int j = 0; j < tempSize; ++j)
                            {
                                tempPointsList.Add(trianglePlanePointsLoop2.mPointsList[j]);
                            }
                            trianglePlanePointsLoop2.mPointsList.Clear();
                        }
                    }
                }
                while (!edgeStack.IsEmpty())
                {
                    GeoSegment3 edge = edgeStack.Pop();
                    QHullTrianglePlanePoints newTrianglePlanePs = new QHullTrianglePlanePoints(edge.mP1, edge.mP2, fathestPoint);
                    List <Vector3>           tempPointsList2    = new List <Vector3>();
                    for (int k = 0; k < tempPointsList.Count; ++k)
                    {
                        Vector3 point = tempPointsList[k];
                        if (!newTrianglePlanePs.AddPoint(point))
                        {
                            tempPointsList2.Add(point);
                        }
                    }
                    // add the new trianglePlane
                    mTrianglePlanePoints.Add(newTrianglePlanePs);
                    // reset, save points
                    tempPointsList = tempPointsList2;
                }
                // clear the points
                tempPointsList.Clear();
            }
        }