Exemplo n.º 1
0
        public static IPolygonReader[] PolygonsInterconnect(IPolygonReader[] polygons, Point pt, Vector v)
        {
            IPolygonReader[] ret = null;
            List <Tuple <double, int, int> > cr = new List <Tuple <double, int, int> >();

            bool[] bcr  = new bool[polygons.Length];
            Point  ptt  = new Point();
            Vector norm = Funcs2D.VectorNormal(v);

            for (int i = 0; i < polygons.Length; i++)
            {
                for (int j = 0; j < polygons[i].Length; j++)
                {
                    polygons[i].GetRow(j, out double x, out double y);
                    ptt.X = x; ptt.Y = y;
                    if (TwoLine2D.CrossRel(pt, v, ptt, norm, out Point pr))
                    {
                        if (Funcs2D.IsEqual(pr.Y, 0.0, Funcs2D.Epson))
                        {
                            cr.Add(new Tuple <double, int, int>(pr.X, i, j));
                            bcr[i] = true;
                        }
                    }
                }
            }
            if (cr.Count < 2)
            {
                return(null);
            }
            int k = 1;

            foreach (var b in bcr)
            {
                if (!b)
                {
                    k++;
                }
            }
            ret = new IPolygonReader[k];
            k   = 0;
            for (int i = 0; i < bcr.Length; i++)
            {
                if (!bcr[i])
                {
                    ret[k++] = polygons[i];
                }
            }

            // trideni
            cr.Sort((a, b) => a.Item1.CompareTo(b.Item1));

            List <Point> rpt = new List <Point>();

            f_InterconnectJoin(0, cr, polygons, rpt);

            ret[k] = new BoxListPoint(Funcs2D.PolygonPure(new BoxListPoint(rpt), true));
            return(ret);
        }
Exemplo n.º 2
0
 private IPolygonReader[] f_MakeResults()
 {
     IPolygonReader[] ret = new IPolygonReader[myRet.Count];
     for (int i = 0; i < ret.Length; i++)
     {
         ret[i] = new BoxListPoint(myRet[i]);
     }
     return(ret);
 }
Exemplo n.º 3
0
 // rozdeli polygon v bodech krizeni na jedntlive dilci polygony
 // pokud neni selfCrossing vraci null
 public IPolygonReader[] GetSplitPolygons()
 {
     if (!f_MakeSplits())
     {
         return(null);
     }
     IPolygonReader[] ret = new IPolygonReader[mySplits.Count];
     for (int i = 0; i < ret.Length; i++)
     {
         ret[i] = new BoxListPoint(mySplits[i]);
     }
     return(ret);
 }
Exemplo n.º 4
0
        // rekurzivni metoda pro napojeni
        private static void f_InterconnectJoin(int inx, List <Tuple <double, int, int> > cr, IPolygonReader[] polygons, List <Point> rpt)
        {
            int start = cr[inx].Item3;         // startovni bod polygonu
            int j     = cr[inx].Item2;         // index polygonu

            List <Point>             p = new BoxListPoint(polygons[j]).Value;
            Tuple <double, int, int> c = null;

            // najdu bod kde se meni polygony
            int k = inx;

            for (; k < cr.Count; k++)
            {
                if (j != cr[k].Item2)
                {
                    c = cr[k];
                    break;
                }
            }

            if (c != null)
            {
                // vlozim od i po c[k-1].Item1
                // rekurze
                // vlozim zbytek
                for (int i = start; ; i++)
                {
                    rpt.Add(p[i]);
                    if (i == cr[k - 1].Item3)
                    {
                        f_InterconnectJoin(k, cr, polygons, rpt);
                        rpt.Add(p[i]);
                    }
                    if (i + 1 == start)
                    {
                        rpt.Add(p[i + 1]);
                        break;
                    }
                    if (i + 1 == p.Count)
                    {
                        i = -1;
                    }
                }
            }
            else
            {
                // vlozim cely polygon
                rpt.AddRange(p.GetRange(start, p.Count - start));
                rpt.AddRange(p.GetRange(0, start + 1));
            }
        }