Exemple #1
0
        static float FindSplit(UHull hull, UEvent edge)
        {
            float d = 0;

            if (hull.a.x < edge.a.x)
            {
                d = UTess.OrientFast(hull.a, hull.b, edge.a);
            }
            else
            {
                d = UTess.OrientFast(edge.b, edge.a, hull.a);
            }

            if (0 != d)
            {
                return(d);
            }

            if (edge.b.x < hull.b.x)
            {
                d = UTess.OrientFast(hull.a, hull.b, edge.b);
            }
            else
            {
                d = UTess.OrientFast(edge.b, edge.a, hull.b);
            }

            if (0 != d)
            {
                return(d);
            }
            return(hull.idx - edge.idx);
        }
Exemple #2
0
        bool MergeHulls(NativeArray <UHull> hulls, ref int hullCount, NativeArray <float2> points, UEvent evt)
        {
            float2 temp = evt.a;

            evt.a = evt.b;
            evt.b = temp;
            int index = UTess.GetEqual(hulls, hullCount, evt, new TestHullEventE());

            if (index < 0)
            {
                return(false);
            }

            UHull upper = hulls[index];
            UHull lower = hulls[index - 1];

            lower.iucount = upper.iucount;
            for (int i = 0; i < lower.iucount; ++i)
            {
                lower.iuarray[i] = upper.iuarray[i];
            }

            hulls[index - 1] = lower;
            EraseHull(hulls, index, ref hullCount);
            return(true);
        }
Exemple #3
0
 static void InsertHull(NativeArray <UHull> Hulls, int Pos, ref int Count, UHull Value)
 {
     if (Count < Hulls.Length - 1)
     {
         for (int i = Count; i > Pos; --i)
         {
             Hulls[i] = Hulls[i - 1];
         }
         Hulls[Pos] = Value;
         Count++;
     }
 }
Exemple #4
0
        bool AddPoint(NativeArray <UHull> hulls, int hullCount, NativeArray <float2> points, float2 p, int idx)
        {
            int l = UTess.GetLower(hulls, hullCount, p, new TestHullPointL());
            int u = UTess.GetUpper(hulls, hullCount, p, new TestHullPointU());

            if (l < 0 || u < 0)
            {
                return(false);
            }
            for (int i = l; i < u; ++i)
            {
                UHull hull = hulls[i];

                int m = hull.ilcount;
                while (m > 1 && UTess.OrientFast(points[hull.ilarray[m - 2]], points[hull.ilarray[m - 1]], p) > 0)
                {
                    int3 c = new int3();
                    c.x = hull.ilarray[m - 1];
                    c.y = hull.ilarray[m - 2];
                    c.z = idx;
                    m_Cells[m_CellCount++] = c;
                    m -= 1;
                }

                hull.ilcount = m + 1;
                if (hull.ilcount > hull.ilarray.Length)
                {
                    return(false);
                }
                hull.ilarray[m] = idx;

                m = hull.iucount;
                while (m > 1 && UTess.OrientFast(points[hull.iuarray[m - 2]], points[hull.iuarray[m - 1]], p) < 0)
                {
                    int3 c = new int3();
                    c.x = hull.iuarray[m - 2];
                    c.y = hull.iuarray[m - 1];
                    c.z = idx;
                    m_Cells[m_CellCount++] = c;
                    m -= 1;
                }

                hull.iucount = m + 1;
                if (hull.iucount > hull.iuarray.Length)
                {
                    return(false);
                }
                hull.iuarray[m] = idx;

                hulls[i] = hull;
            }
            return(true);
        }
Exemple #5
0
        bool SplitHulls(NativeArray <UHull> hulls, ref int hullCount, NativeArray <float2> points, UEvent evt)
        {
            int index = UTess.GetLower(hulls, hullCount, evt, new TestHullEventLe());

            if (index < 0)
            {
                return(false);
            }

            UHull hull = hulls[index];

            UHull newHull;

            newHull.a   = evt.a;
            newHull.b   = evt.b;
            newHull.idx = evt.idx;

            int y = hull.iuarray[hull.iucount - 1];

            newHull.iuarray = new ArraySlice <int>(m_IUArray, newHull.idx * m_NumHulls, m_NumHulls);
            newHull.iucount = hull.iucount;
            for (int i = 0; i < newHull.iucount; ++i)
            {
                newHull.iuarray[i] = hull.iuarray[i];
            }
            hull.iuarray[0] = y;
            hull.iucount    = 1;
            hulls[index]    = hull;

            newHull.ilarray    = new ArraySlice <int>(m_ILArray, newHull.idx * m_NumHulls, m_NumHulls);
            newHull.ilarray[0] = y;
            newHull.ilcount    = 1;

            InsertHull(hulls, index + 1, ref hullCount, newHull);
            return(true);
        }