コード例 #1
0
        public void BasicTriangulation()
        {
            int i = numPoints;

            if (i < 3)
            {
                return;
            }
            numEdges     = 0;
            numTriangles = 0;
            sV           = new int[i];

            if (0.0D < Area())
            {
                for (int k = 0; k < i; k++)
                {
                    sV[k] = k;
                }
            }
            else
            {
                for (int l = 0; l < i; l++)
                {
                    sV[l] = numPoints - 1 - l;
                }
            }
            int k1 = 2 * i;
            int i1 = i - 1;

            while (i > 2)
            {
                if (0 >= k1--)
                {
                    throw new Exception("Bad polygon");
                }

                int j = i1;
                if (i <= j)
                {
                    j = 0;
                }
                i1 = j + 1;
                if (i <= i1)
                {
                    i1 = 0;
                }
                int j1 = i1 + 1;
                if (i <= j1)
                {
                    j1 = 0;
                }
                if (Snip(j, i1, j1, i))
                {
                    int l1 = sV[j];
                    int i2 = sV[i1];
                    int j2 = sV[j1];
                    if (numTriangles == triangles.Length)
                    {
                        TriangleNeat.Triangle[] atriangle = new TriangleNeat.Triangle[triangles.Length * 2];
                        System.Array.Copy(triangles, 0, atriangle, 0, numTriangles);
                        triangles = atriangle;
                    }
                    triangles[numTriangles] = new TriangleNeat.Triangle(l1, i2, j2);
                    AddEdge(l1, i2, numTriangles);
                    AddEdge(i2, j2, numTriangles);
                    AddEdge(j2, l1, numTriangles);
                    numTriangles++;
                    int k2 = i1;
                    for (int l2 = i1 + 1; l2 < i; l2++)
                    {
                        sV[k2] = sV[l2];
                        k2++;
                    }

                    i--;
                    k1 = 2 * i;
                }
            }
            sV = null;
        }
コード例 #2
0
        public void BasicTriangulation()
        {
            int i = numPoints;
            if (i < 3)
                return;
            numEdges = 0;
            numTriangles = 0;
            sV = new int[i];

            if (0.0D < Area())
            {
                for (int k = 0; k < i; k++)
                    sV[k] = k;

            }
            else
            {
                for (int l = 0; l < i; l++)
                    sV[l] = numPoints - 1 - l;

            }
            int k1 = 2 * i;
            int i1 = i - 1;
            while (i > 2)
            {
                if (0 >= k1--)
                {
                    throw new Exception("Bad polygon");
                }

                int j = i1;
                if (i <= j)
                    j = 0;
                i1 = j + 1;
                if (i <= i1)
                    i1 = 0;
                int j1 = i1 + 1;
                if (i <= j1)
                    j1 = 0;
                if (Snip(j, i1, j1, i))
                {
                    int l1 = sV[j];
                    int i2 = sV[i1];
                    int j2 = sV[j1];
                    if (numTriangles == triangles.Length)
                    {
                        TriangleNeat.Triangle[] atriangle = new TriangleNeat.Triangle[triangles.Length * 2];
                        System.Array.Copy(triangles, 0, atriangle, 0, numTriangles);
                        triangles = atriangle;
                    }
                    triangles[numTriangles] = new TriangleNeat.Triangle(l1, i2, j2);
                    AddEdge(l1, i2, numTriangles);
                    AddEdge(i2, j2, numTriangles);
                    AddEdge(j2, l1, numTriangles);
                    numTriangles++;
                    int k2 = i1;
                    for (int l2 = i1 + 1; l2 < i; l2++)
                    {
                        sV[k2] = sV[l2];
                        k2++;
                    }

                    i--;
                    k1 = 2 * i;
                }
            }
            sV = null;
        }