Esempio n. 1
0
        private float Area(TriangleBasic.PointList contour)
        {
            int n = contour.Size();

            float sA = 0.0f;

            for (int p = n - 1, q = 0; q < n; p = q++)
            {
                TriangleBasic.Point contourP = contour.Get(p);
                TriangleBasic.Point contourQ = contour.Get(q);

                sA += contourP.GetX() * contourQ.GetY() - contourQ.GetX()
                      * contourP.GetY();
            }
            return(sA * 0.5f);
        }
Esempio n. 2
0
        private bool Snip(TriangleBasic.PointList contour, int u, int v, int w, int n, int[] V)
        {
            int   p;
            float Ax, Ay, Bx, By, Cx, Cy, Px, Py;

            Ax = contour.Get(V[u]).GetX();
            Ay = contour.Get(V[u]).GetY();

            Bx = contour.Get(V[v]).GetX();
            By = contour.Get(V[v]).GetY();

            Cx = contour.Get(V[w]).GetX();
            Cy = contour.Get(V[w]).GetY();

            if (EPSILON > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax))))
            {
                return(false);
            }

            for (p = 0; p < n; p++)
            {
                if ((p == u) || (p == v) || (p == w))
                {
                    continue;
                }

                Px = contour.Get(V[p]).GetX();
                Py = contour.Get(V[p]).GetY();

                if (InsideTriangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
        private bool Process(TriangleBasic.PointList contour, TriangleBasic.PointList result)
        {
            result.Clear();

            int n = contour.Size();

            if (n < 3)
            {
                return(false);
            }
            int[] sV = new int[n];

            if (0.0f < Area(contour))
            {
                for (int v = 0; v < n; v++)
                {
                    sV[v] = v;
                }
            }
            else
            {
                for (int v_0 = 0; v_0 < n; v_0++)
                {
                    sV[v_0] = (n - 1) - v_0;
                }
            }

            int nv = n;

            int count = 2 * nv;

            for (int v_1 = nv - 1; nv > 2;)
            {
                if (0 >= (count--))
                {
                    return(false);
                }

                int u = v_1;
                if (nv <= u)
                {
                    u = 0;
                }
                v_1 = u + 1;
                if (nv <= v_1)
                {
                    v_1 = 0;
                }
                int w = v_1 + 1;
                if (nv <= w)
                {
                    w = 0;
                }
                if (Snip(contour, u, v_1, w, nv, sV))
                {
                    int a, b, c, s, t;

                    a = sV[u];
                    b = sV[v_1];
                    c = sV[w];

                    result.Add(contour.Get(a));
                    result.Add(contour.Get(b));
                    result.Add(contour.Get(c));

                    for (s = v_1, t = v_1 + 1; t < nv; s++, t++)
                    {
                        sV[s] = sV[t];
                    }
                    nv--;

                    count = 2 * nv;
                }
            }

            return(true);
        }
Esempio n. 4
0
 public TriangleBasic()
 {
     this.poly = new TriangleBasic.PointList();
     this.tris = new TriangleBasic.PointList();
 }