Exemplo n.º 1
0
		private float Area(PointList contour) {
			int n = contour.Size();
	
			float sA = 0.0f;
	
			for (int p = n - 1, q = 0; q < n; p = q++) {
				Point contourP = contour.Get(p);
				Point contourQ = contour.Get(q);
	
				sA += contourP.GetX() * contourQ.GetY() - contourQ.GetX()
						* contourP.GetY();
			}
			return sA * 0.5f;
		}
Exemplo n.º 2
0
        private float Area(PointList contour)
        {
            int n = contour.Size();

            float sA = 0.0f;

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

                sA += contourP.GetX() * contourQ.GetY() - contourQ.GetX()
                      * contourP.GetY();
            }
            return(sA * 0.5f);
        }
Exemplo n.º 3
0
        public virtual float[] GetTrianglePoint(int t, int i)
        {
            if (!tried)
            {
                throw new Exception("this not Triangle !");
            }

            return(tris.Get((t * 3) + i).ToArray());
        }
Exemplo n.º 4
0
        private bool Snip(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);
        }
Exemplo n.º 5
0
 public float[] GetPolyPoint(int index)
 {
     return(new float[] { poly.Get(index).GetX(), poly.Get(index).GetY() });
 }
Exemplo n.º 6
0
        private bool Process(PointList contour, 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);
        }
Exemplo n.º 7
0
 private PointList<int, int> CalcEnemyShipCountPerSector()
 {
     PointList<int, int> result = new PointList<int, int>();
     foreach (IVisible unit in mComputerView)
         if (unit is ISpaceship && unit.Allegiance == Allegiance.Player)
         {
             Point sector = mUnitSectorManager.GetSector(unit.Position);
             if (result.Contains(sector.X, sector.Y))
                 result.Set(sector.X, sector.Y, result.Get(sector.X, sector.Y)+1);
             else
                 result.Add(sector.X, sector.Y, 1);
         }
     return result;
 }
Exemplo n.º 8
0
		private bool Snip(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;
		}
Exemplo n.º 9
0
		private bool Process(PointList contour, 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;
		}