public int GetTriangleCount() { if (!tried) { throw new LSysException("this not Triangle !"); } return(tris.Size() / 3); }
public Triangulation(TArray <XY> points) { this.points = new TArray <Vector2f>(); for (int i = 0; i < points.Size(); i++) { this.points.Add(new Vector2f(points.Get(i))); } this.nonconvexPoints = new TArray <Vector2f>(); CalcPolyOrientation(); CalcNonConvexPoints(); }
private bool IsEar(Vector2f p1, Vector2f p2, Vector2f p3) { if (!(IsConvex(p1, p2, p3))) { return(false); } for (int i = 0; i < nonconvexPoints.Size(); i++) { if (Triangle2f.IsInside(p1, p2, p3, nonconvexPoints.Get(i))) { return(false); } } return(true); }
private float Area(TArray <PointF> contour) { int n = contour.Size(); float sA = 0.0f; for (int p = n - 1, q = 0; q < n; p = q++) { PointF contourP = contour.Get(p); PointF contourQ = contour.Get(q); sA += contourP.GetX() * contourQ.GetY() - contourQ.GetX() * contourP.GetY(); } return(sA * 0.5f); }
private void CalcNonConvexPoints() { if (points.Size() <= 3) { return; } Vector2f p; Vector2f v; Vector2f u; float res; for (int i = 0; i < points.Size() - 1; i++) { p = points.Get(i); Vector2f tmp = points.Get(i + 1); v = new Vector2f(); v.x = tmp.x - p.x; v.y = tmp.y - p.y; if (i == points.Size() - 2) { u = points.Get(0); } else { u = points.Get(i + 2); } res = u.x * v.y - u.y * v.x + v.x * p.y - v.y * p.x; if ((res > 0 && isCw) || (res <= 0 && !isCw)) { nonconvexPoints.Add(tmp); } } }
public int GetPolyPointCount() { return(poly.Size()); }
private bool Process(TArray <PointF> contour, TArray <PointF> 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; v < n; v++) { sV[v] = (n - 1) - v; } } int nv = n; int count = 2 * nv; for (int v = nv - 1; nv > 2;) { if (0 >= (count--)) { return(false); } int u = v; if (nv <= u) { u = 0; } v = u + 1; if (nv <= v) { v = 0; } int w = v + 1; if (nv <= w) { w = 0; } if (Snip(contour, u, v, w, nv, sV)) { int a, b, c, s, t; a = sV[u]; b = sV[v]; c = sV[w]; result.Add(contour.Get(a)); result.Add(contour.Get(b)); result.Add(contour.Get(c)); for (s = v, t = v + 1; t < nv; s++, t++) { sV[s] = sV[t]; } nv--; count = 2 * nv; } } return(true); }