Example #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);
        }