示例#1
0
        public void Add(Rectangle newRectangle)
        {
            List <RectangleTree> outer = new List <RectangleTree>();

            foreach (var tree in FiguresHierarchy)
            {
                if (tree.ThisRectangle.IsInner(newRectangle))
                {
                    outer.Add(tree);
                }
            }

            if (outer.Count > 0)
            {
                RectangleTree min = outer.First();
                foreach (var tree in outer)
                {
                    if (min.ThisRectangle.Square() < tree.ThisRectangle.Square())
                    {
                        min = tree;
                    }
                }
                min.InsertRectangle(newRectangle);
                return;
            }
            FiguresHierarchy.Add(new RectangleTree(newRectangle));
        }
示例#2
0
        public void InsertRectangle(Rectangle newRectangle)
        {
            if (ThisRectangle != null && newRectangle.IsInner(ThisRectangle) && !ThisRectangle.IsSame(newRectangle))
            {
                var rec = ThisRectangle;
                ThisRectangle = newRectangle;
                InsertRectangle(rec);
                return;
            }

            List <RectangleTree> outer = new List <RectangleTree>();

            foreach (var tree in InnerRectangles)
            {
                if (tree.ThisRectangle.IsInner(newRectangle))
                {
                    outer.Add(tree);
                }
            }

            if (outer.Count > 0)
            {
                RectangleTree min = outer.First();
                foreach (var tree in outer)
                {
                    if (min.ThisRectangle.Square() < tree.ThisRectangle.Square())
                    {
                        min = tree;
                    }
                }
                min.InsertRectangle(newRectangle);
                return;
            }
            InnerRectangles.Add(new RectangleTree(newRectangle));
            if (InnerRectangles.Count >= RectanglesProgram.n_max)
            {
                OnMaxInners?.Invoke(this, new RectangleArgs(InnerRectangles));
            }
        }