Exemple #1
0
 internal bool Contains(CPolygon poly)
 {
     return this.mainPoints[0].x < poly.mainPoints[0].x &&
            this.mainPoints[0].y < poly.mainPoints[0].y &&
            this.mainPoints[1].x > poly.mainPoints[1].x &&
            this.mainPoints[1].y > poly.mainPoints[1].y;
 }
Exemple #2
0
        private void PreBuildPolygon(CLine fl)
        {
            var lines = new List<CLine>();
            Vector2[] mp = { new Vector2(fl.x1, fl.y1), new Vector2(fl.x2, fl.y2) };

            var polygon = new CPolygon(mp, lines);
            int diagonals = 0;

            while (fl != null)
            {
                lines.Add(fl);
                fl.container = polygon;

                foreach (var p in fl.NPoints)
                {
                    if (mp[0].x > p.x)
                        mp[0].x = p.x;

                    if (mp[0].y > p.y)
                        mp[0].y = p.y;

                    if (mp[1].x < p.x)
                        mp[1].x = p.x;

                    if (mp[1].y < p.y)
                        mp[1].y = p.y;
                }

                var nl = linesMX[fl.x2, fl.y2];

                if (nl != null && nl.Count != 0)
                {
                    if (nl.Count == 1)
                    {
                        fl = nl[0];
                        linesMX[fl.x1, fl.y1] = null;
                    }
                    else
                    {
                        diagonals++;
                        if (fl.IsOrthogonal(nl[0]))
                        {
                            fl = nl[0];
                            nl.RemoveAt(0);
                        }
                        else
                        {
                            fl = nl[1];
                            nl.RemoveAt(1);
                        }
                    }
                }
                else
                    fl = null;
            }

            polygon.diagonals = diagonals;
            polygon.Recalculate();
            polys.Add(polygon);
        }
Exemple #3
0
        private void DefineSubPolygons()
        {
            bool freeExists = true;
            var freePolys = new List<CPolygon>(polys);
            while (freeExists)
            {
                var children = freePolys[0];
                freePolys.RemoveAt(0);

                CPolygon parent = null;

                foreach (var p in polys)
                    if (p.Contains(children) && (parent == null || p.recS < parent.recS))
                        parent = p;

                if (parent != null)
                {
                    children.depth = 1;
                    parent.subPolygons.Add(children);
                }
                else
                {
                    mainPolygon = children;
                    mainPolygon.depth = 0;
                }

                if (freePolys.Count == 0) freeExists = false;
            }

            mainPolygon.SetLinesMX(linesMXCopy);
            DefineSubPolygonsDepth(mainPolygon);
        }
Exemple #4
0
 private void DefineSubPolygonsDepth(CPolygon poly)
 {
     foreach (var p in poly.subPolygons)
     {
         p.depth = poly.depth + 1;
         DefineSubPolygonsDepth(p);
     }
 }