Exemplo n.º 1
0
 /// <summary>
 /// Returns the intersection of two rectangles.
 /// </summary>
 /// <param name="rect1"></param>
 /// <param name="rect2"></param>
 /// <returns></returns>
 public static Rectangle Intersect(Rectangle rect1, Rectangle rect2)
 {
     if (rect1.Intersects(rect2))
     {
         return(new Rectangle(new Point(Math.Max(rect1.Left, rect2.Left), Math.Max(rect1.Bottom, rect2.Bottom)),
                              new Point(Math.Min(rect1.Right, rect2.Right), Math.Min(rect1.Top, rect2.Top))));
     }
     return(Rectangle.CreateAnEmptyBox());
 }
        Rectangle GetCommonRectangle(Size[] sizes, Point[] points)
        {
            var rect = Rectangle.CreateAnEmptyBox();

            Debug.Assert(sizes.Length == points.Length);
            for (int i = 0; i < sizes.Length; i++)
            {
                rect.Add(sizes[i], points[i]);
            }
            return(rect);
        }
Exemplo n.º 3
0
        private void insertNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (gViewer == null || gViewer.Graph == null)
            {
                MessageBox.Show("Please create graph first.", "Insert Node Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var tree = RectangleNode <object> .CreateRectangleNodeOnEnumeration(GetRectangleNodesFromGraph());

            if (tree == null)
            {
                return;
            }

            var       numberOfTries = 10000;
            Random    random        = new Random(1);
            double    rectWidth     = 100;
            double    rectHeight    = 100;
            var       delta         = new Point(rectWidth / 2, rectHeight / 2);
            Rectangle bestRectangle = Rectangle.CreateAnEmptyBox();

            Point  hint        = (gViewer.Graph.BoundingBox.LeftBottom + gViewer.Graph.BoundingBox.RightTop) / 2;
            double minDistance = double.PositiveInfinity;

            for (int i = 0; i < numberOfTries; i++)
            {
                Point     randomCenter = GetRandomCenter(rectHeight, rectWidth, random);
                Rectangle r            = new Rectangle(randomCenter);
                r.Add(randomCenter + delta);
                r.Add(randomCenter - delta);
                if (tree.GetNodeItemsIntersectingRectangle(r).Any())
                {
                }
                else
                {
                    var len = (randomCenter - hint).LengthSquared;
                    if (len < minDistance)
                    {
                        minDistance   = len;
                        bestRectangle = r;
                    }
                }
            }

            if (bestRectangle.IsEmpty == false)
            {
                InsertNodeIntoGraph(bestRectangle);
            }
            else
            {
                MessageBox.Show("cannot insert");
            }
        }
Exemplo n.º 4
0
        static void RebuildBBHierarchyUnderObject(DObject dObj)
        {
            BBNode oldNode = dObj.BbNode;
            BBNode newNode = BuildBBHierarchyUnderDObject(dObj);

            if (newNode != null)
            {
                //now copy all fields, except the parent
                oldNode.left     = newNode.left;
                oldNode.right    = newNode.right;
                oldNode.geometry = newNode.geometry;
                oldNode.bBox     = newNode.bBox;
            }
            else
            {
                oldNode.bBox = Rectangle.CreateAnEmptyBox();
            }
        }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)  //this is abstract.dot of GraphViz
        {
            var tree = RectangleNode <object> .CreateRectangleNodeOnEnumeration(GetRectangleNodesFromGraph());

            var       numberOfTries = 10000;
            Random    random        = new Random(1);
            double    rectWidth     = 50;
            double    rectHeight    = 200;
            var       delta         = new Point(rectWidth / 2, rectHeight / 2);
            Rectangle bestRectangle = Rectangle.CreateAnEmptyBox();

            Point  hint        = (gViewer.Graph.BoundingBox.LeftBottom + gViewer.Graph.BoundingBox.RightTop) / 2;
            double minDistance = double.PositiveInfinity;

            for (int i = 0; i < numberOfTries; i++)
            {
                Point     randomCenter = GetRandomCenter(rectHeight, rectWidth, random);
                Rectangle r            = new Rectangle(randomCenter);
                r.Add(randomCenter + delta);
                r.Add(randomCenter - delta);
                if (tree.GetNodeItemsIntersectingRectangle(r).Any())
                {
                }
                else
                {
                    var len = (randomCenter - hint).LengthSquared;
                    if (len < minDistance)
                    {
                        minDistance   = len;
                        bestRectangle = r;
                    }
                }
            }
            if (bestRectangle.IsEmpty == false)
            {
                InsertNodeIntoGraph(bestRectangle);
            }
            else
            {
                MessageBox.Show("cannot insert");
            }
        }