Esempio n. 1
0
        private static void combLeft(ref MarchingSquares.GeomPoly polya, ref MarchingSquares.GeomPoly polyb)
        {
            MarchingSquares.CxFastList <TSVector2>     points          = polya.Points;
            MarchingSquares.CxFastList <TSVector2>     points2         = polyb.Points;
            MarchingSquares.CxFastListNode <TSVector2> cxFastListNode  = points.Begin();
            MarchingSquares.CxFastListNode <TSVector2> cxFastListNode2 = points2.Begin();
            TSVector2 tSVector = cxFastListNode2.Elem();

            MarchingSquares.CxFastListNode <TSVector2> cxFastListNode3 = null;
            while (cxFastListNode != points.End())
            {
                TSVector2 tSVector2 = cxFastListNode.Elem();
                bool      flag      = MarchingSquares.VecDsq(tSVector2, tSVector) < Settings.Epsilon;
                if (flag)
                {
                    bool flag2 = cxFastListNode3 != null;
                    if (flag2)
                    {
                        TSVector2 value = cxFastListNode3.Elem();
                        tSVector = cxFastListNode2.Next().Elem();
                        TSVector2 a     = tSVector2 - value;
                        TSVector2 b     = tSVector - tSVector2;
                        FP        fP    = MarchingSquares.VecCross(a, b);
                        bool      flag3 = fP * fP < Settings.Epsilon;
                        if (flag3)
                        {
                            points.Erase(cxFastListNode3, cxFastListNode);
                            polya.Length--;
                            cxFastListNode = cxFastListNode3;
                        }
                    }
                    bool flag4 = true;
                    MarchingSquares.CxFastListNode <TSVector2> cxFastListNode4 = null;
                    while (!points2.Empty())
                    {
                        TSVector2 value2 = points2.Front();
                        points2.Pop();
                        bool flag5 = !flag4 && !points2.Empty();
                        if (flag5)
                        {
                            cxFastListNode = points.Insert(cxFastListNode, value2);
                            polya.Length++;
                            cxFastListNode4 = cxFastListNode;
                        }
                        flag4 = false;
                    }
                    cxFastListNode = cxFastListNode.Next();
                    TSVector2 tSVector3 = cxFastListNode.Elem();
                    cxFastListNode = cxFastListNode.Next();
                    bool flag6 = cxFastListNode == points.End();
                    if (flag6)
                    {
                        cxFastListNode = points.Begin();
                    }
                    TSVector2 value3 = cxFastListNode.Elem();
                    TSVector2 value4 = cxFastListNode4.Elem();
                    TSVector2 a2     = tSVector3 - value4;
                    TSVector2 b2     = value3 - tSVector3;
                    FP        fP2    = MarchingSquares.VecCross(a2, b2);
                    bool      flag7  = fP2 * fP2 < Settings.Epsilon;
                    if (flag7)
                    {
                        points.Erase(cxFastListNode4, cxFastListNode4.Next());
                        polya.Length--;
                    }
                    break;
                }
                cxFastListNode3 = cxFastListNode;
                cxFastListNode  = cxFastListNode.Next();
            }
        }
Esempio n. 2
0
        public static List <Vertices> DetectSquares(AABB domain, FP cellWidth, FP cellHeight, sbyte[,] f, int lerpCount, bool combine)
        {
            MarchingSquares.CxFastList <MarchingSquares.GeomPoly> cxFastList = new MarchingSquares.CxFastList <MarchingSquares.GeomPoly>();
            List <Vertices> list  = new List <Vertices>();
            int             num   = (int)((long)(domain.Extents.x * 2 / cellWidth));
            bool            flag  = num == domain.Extents.x * 2 / cellWidth;
            int             num2  = (int)((long)(domain.Extents.y * 2 / cellHeight));
            bool            flag2 = num2 == domain.Extents.y * 2 / cellHeight;
            bool            flag3 = !flag;

            if (flag3)
            {
                num++;
            }
            bool flag4 = !flag2;

            if (flag4)
            {
                num2++;
            }
            sbyte[,] array = new sbyte[num + 1, num2 + 1];
            MarchingSquares.GeomPolyVal[,] array2 = new MarchingSquares.GeomPolyVal[num + 1, num2 + 1];
            for (int i = 0; i < num + 1; i++)
            {
                bool flag5 = i == num;
                int  num3;
                if (flag5)
                {
                    num3 = (int)((long)domain.UpperBound.x);
                }
                else
                {
                    num3 = (int)((long)(i * cellWidth + domain.LowerBound.x));
                }
                for (int j = 0; j < num2 + 1; j++)
                {
                    bool flag6 = j == num2;
                    int  num4;
                    if (flag6)
                    {
                        num4 = (int)((long)domain.UpperBound.y);
                    }
                    else
                    {
                        num4 = (int)((long)(j * cellHeight + domain.LowerBound.y));
                    }
                    array[i, j] = f[num3, num4];
                }
            }
            for (int k = 0; k < num2; k++)
            {
                FP   fP    = k * cellHeight + domain.LowerBound.y;
                bool flag7 = k == num2 - 1;
                FP   y;
                if (flag7)
                {
                    y = domain.UpperBound.y;
                }
                else
                {
                    y = fP + cellHeight;
                }
                MarchingSquares.GeomPoly geomPoly = null;
                for (int l = 0; l < num; l++)
                {
                    FP   fP2   = l * cellWidth + domain.LowerBound.x;
                    bool flag8 = l == num - 1;
                    FP   x;
                    if (flag8)
                    {
                        x = domain.UpperBound.x;
                    }
                    else
                    {
                        x = fP2 + cellWidth;
                    }
                    MarchingSquares.GeomPoly geomPoly2 = new MarchingSquares.GeomPoly();
                    int  num5  = MarchingSquares.MarchSquare(f, array, ref geomPoly2, l, k, fP2, fP, x, y, lerpCount);
                    bool flag9 = geomPoly2.Length != 0;
                    if (flag9)
                    {
                        bool flag10 = combine && geomPoly != null && (num5 & 9) != 0;
                        if (flag10)
                        {
                            MarchingSquares.combLeft(ref geomPoly, ref geomPoly2);
                            geomPoly2 = geomPoly;
                        }
                        else
                        {
                            cxFastList.Add(geomPoly2);
                        }
                        array2[l, k] = new MarchingSquares.GeomPolyVal(geomPoly2, num5);
                    }
                    else
                    {
                        geomPoly2 = null;
                    }
                    geomPoly = geomPoly2;
                }
            }
            bool            flag11 = !combine;
            List <Vertices> result;

            if (flag11)
            {
                List <MarchingSquares.GeomPoly> listOfElements = cxFastList.GetListOfElements();
                foreach (MarchingSquares.GeomPoly current in listOfElements)
                {
                    list.Add(new Vertices(current.Points.GetListOfElements()));
                }
                result = list;
            }
            else
            {
                for (int m = 1; m < num2; m++)
                {
                    int n = 0;
                    while (n < num)
                    {
                        MarchingSquares.GeomPolyVal geomPolyVal = array2[n, m];
                        bool flag12 = geomPolyVal == null;
                        if (flag12)
                        {
                            n++;
                        }
                        else
                        {
                            bool flag13 = (geomPolyVal.Key & 12) == 0;
                            if (flag13)
                            {
                                n++;
                            }
                            else
                            {
                                MarchingSquares.GeomPolyVal geomPolyVal2 = array2[n, m - 1];
                                bool flag14 = geomPolyVal2 == null;
                                if (flag14)
                                {
                                    n++;
                                }
                                else
                                {
                                    bool flag15 = (geomPolyVal2.Key & 3) == 0;
                                    if (flag15)
                                    {
                                        n++;
                                    }
                                    else
                                    {
                                        FP fP3 = n * cellWidth + domain.LowerBound.x;
                                        FP y2  = m * cellHeight + domain.LowerBound.y;
                                        MarchingSquares.CxFastList <TSVector2> points  = geomPolyVal.GeomP.Points;
                                        MarchingSquares.CxFastList <TSVector2> points2 = geomPolyVal2.GeomP.Points;
                                        bool flag16 = geomPolyVal2.GeomP == geomPolyVal.GeomP;
                                        if (flag16)
                                        {
                                            n++;
                                        }
                                        else
                                        {
                                            MarchingSquares.CxFastListNode <TSVector2> cxFastListNode = points.Begin();
                                            while (MarchingSquares.Square(cxFastListNode.Elem().y - y2) > Settings.Epsilon || cxFastListNode.Elem().x < fP3)
                                            {
                                                cxFastListNode = cxFastListNode.Next();
                                            }
                                            TSVector2 tSVector = cxFastListNode.Next().Elem();
                                            bool      flag17   = MarchingSquares.Square(tSVector.y - y2) > Settings.Epsilon;
                                            if (flag17)
                                            {
                                                n++;
                                            }
                                            else
                                            {
                                                bool flag18 = true;
                                                MarchingSquares.CxFastListNode <TSVector2> cxFastListNode2;
                                                for (cxFastListNode2 = points2.Begin(); cxFastListNode2 != points2.End(); cxFastListNode2 = cxFastListNode2.Next())
                                                {
                                                    bool flag19 = MarchingSquares.VecDsq(cxFastListNode2.Elem(), tSVector) < Settings.Epsilon;
                                                    if (flag19)
                                                    {
                                                        flag18 = false;
                                                        break;
                                                    }
                                                }
                                                bool flag20 = flag18;
                                                if (flag20)
                                                {
                                                    n++;
                                                }
                                                else
                                                {
                                                    MarchingSquares.CxFastListNode <TSVector2> cxFastListNode3 = cxFastListNode.Next().Next();
                                                    bool flag21 = cxFastListNode3 == points.End();
                                                    if (flag21)
                                                    {
                                                        cxFastListNode3 = points.Begin();
                                                    }
                                                    while (cxFastListNode3 != cxFastListNode)
                                                    {
                                                        cxFastListNode2 = points2.Insert(cxFastListNode2, cxFastListNode3.Elem());
                                                        cxFastListNode3 = cxFastListNode3.Next();
                                                        bool flag22 = cxFastListNode3 == points.End();
                                                        if (flag22)
                                                        {
                                                            cxFastListNode3 = points.Begin();
                                                        }
                                                        geomPolyVal2.GeomP.Length++;
                                                    }
                                                    fP3 = n + 1;
                                                    while (fP3 < num)
                                                    {
                                                        MarchingSquares.GeomPolyVal geomPolyVal3 = array2[(int)((long)fP3), m];
                                                        bool flag23 = geomPolyVal3 == null || geomPolyVal3.GeomP != geomPolyVal.GeomP;
                                                        if (flag23)
                                                        {
                                                            fP3 += 1;
                                                        }
                                                        else
                                                        {
                                                            geomPolyVal3.GeomP = geomPolyVal2.GeomP;
                                                            fP3 += 1;
                                                        }
                                                    }
                                                    fP3 = n - 1;
                                                    while (fP3 >= 0)
                                                    {
                                                        MarchingSquares.GeomPolyVal geomPolyVal4 = array2[(int)((long)fP3), m];
                                                        bool flag24 = geomPolyVal4 == null || geomPolyVal4.GeomP != geomPolyVal.GeomP;
                                                        if (flag24)
                                                        {
                                                            fP3 -= 1;
                                                        }
                                                        else
                                                        {
                                                            geomPolyVal4.GeomP = geomPolyVal2.GeomP;
                                                            fP3 -= 1;
                                                        }
                                                    }
                                                    cxFastList.Remove(geomPolyVal.GeomP);
                                                    geomPolyVal.GeomP = geomPolyVal2.GeomP;
                                                    n = (int)((long)((cxFastListNode.Next().Elem().x - domain.LowerBound.x) / cellWidth)) + 1;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                List <MarchingSquares.GeomPoly> listOfElements = cxFastList.GetListOfElements();
                foreach (MarchingSquares.GeomPoly current2 in listOfElements)
                {
                    list.Add(new Vertices(current2.Points.GetListOfElements()));
                }
                result = list;
            }
            return(result);
        }