public Rectangle GetInitialBoundingBox() { Rectangle bbox = new Rectangle(); bbox.SetToEmpty(); foreach (var rect in _fixedRectangles) { bbox.Add(rect); } foreach (var rect in _moveableRectangles) { bbox.Add(rect); } return bbox; }
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"); } }
public Rectangle GetInitialBoundingBox() { Rectangle bbox = new Rectangle(); bbox.SetToEmpty(); foreach (var rect in _fixedRectangles) { bbox.Add(rect); } foreach (var rect in _moveableRectangles) { bbox.Add(rect); } return(bbox); }
internal PreGraph(EdgeGeometry[] egs, Set<ICurve> nodeBoundaries) { edgeGeometries = new List<EdgeGeometry>(egs); this.nodeBoundaries = new Set<ICurve>(nodeBoundaries); boundingBox = Rectangle.CreateAnEmptyBox(); foreach (var curve in nodeBoundaries) boundingBox.Add(curve.BoundingBox); }
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"); } }
void CreateAndIndexBoundingBox() { _boundingBox = Rectangle.CreateAnEmptyBox(); foreach(var p in _pointsToIndices.Keys) _boundingBox.Add(p); _boundingBox.Pad(1); IndexAPoint(_boundingBox.LeftBottom); IndexAPoint(_boundingBox.RightBottom); IndexAPoint(_boundingBox.LeftTop); IndexAPoint(_boundingBox.RightTop); //SplineRouter.ShowVisGraph(_visGraph, null, new[] { _boundingBox.Perimeter() }, null); }
public Rectangle GetBoundingBox(IEnumerable<TreeNode> nodes) { Rectangle bbox = new Rectangle(); bbox.SetToEmpty(); foreach (var node in nodes) { bbox.Add(node.rect); } return bbox; }
void CalculateOriginalGraphBox(out double aspectRatio) { aspectRatio = 0; if (anchors.Length > 0) { var box = new Rectangle(anchors[0].Left, anchors[0].Top, anchors[0].Right, anchors[0].Bottom); for (int i = 1; i < anchors.Length; i++) { Anchor a = anchors[i]; box.Add(a.LeftTop); box.Add(a.RightBottom); } aspectRatio = box.Width/box.Height; // Console.WriteLine("bb aspect ratio {0}", aspectRatio); double delta = (box.LeftTop - box.RightBottom).Length/2; var del = new Point(-delta, delta); box.Add(box.LeftTop + del); box.Add(box.RightBottom - del); originalGraph.BoundingBox = box; } }
Rectangle TriangleRectangle(ThreeArray<CdtSite> sites) { var rect = new Rectangle(sites[0].Point); rect.Add(sites[1].Point); rect.Add(sites[2].Point); return rect; }
/// <summary> /// creates a "tight" bounding box /// </summary> /// <param name="affectedEntity">the object corresponding to the graph</param> /// <param name="geometryGraph"></param> public void FitGraphBoundingBox(IViewerObject affectedEntity, GeometryGraph geometryGraph) { if (geometryGraph != null) { var uAction = new UndoRedoAction(geometryGraph) {Graph = geometryGraph}; UndoRedoActionsList.AddAction(uAction); var r = new Rectangle(); foreach (GeomNode n in geometryGraph.Nodes) { r = n.BoundingBox; break; } foreach (GeomNode n in geometryGraph.Nodes) { r.Add(n.BoundingBox); } foreach (GeomEdge e in geometryGraph.Edges) { r.Add(e.BoundingBox); if (e.Label != null) r.Add(e.Label.BoundingBox); } r.Left -= geometryGraph.Margins; r.Top += geometryGraph.Margins; r.Bottom -= geometryGraph.Margins; r.Right += geometryGraph.Margins; uAction.ClearAffectedObjects(); uAction.AddAffectedObject(affectedEntity); uAction.GraphBoundingBoxAfter = geometryGraph.BoundingBox = r; } }
private void CalcTheBoxFromAnchors() { if (anchors.Length > 0) { Rectangle box = new Rectangle(anchors[0].Left, anchors[0].Top, anchors[0].Right, anchors[0].Bottom); for (int i = 1; i < anchors.Length; i++) { Anchor a = anchors[i]; box.Add(a.LeftTop); box.Add(a.RightBottom); } double m = Math.Max(box.Width, box.Height); double delta = this.tree.Margins / 100.0 * m; Point del = new Point(-delta, delta); box.Add(box.LeftTop + del); box.Add(box.RightBottom - del); this.tree.BoundingBox = box; } }
/// <summary> /// displays the database /// </summary> /// <param name="db"></param> /// <param name="curves"></param> public static void ShowDataBase(Database db, params ICurve[] curves){ var g = new Graph(""); AllocateDebugCurves(g); var graphBox = new Rectangle(db.Anchors[0].LeftTop); var cl = new List<ICurve>(curves); foreach (Anchor a in db.Anchors){ graphBox.Add(a.LeftTop); graphBox.Add(a.RightBottom); cl.Add(a.PolygonalBoundary); } AddCurvesToGraph(cl, g); Point del = (graphBox.LeftBottom - graphBox.RightTop)/10; graphBox.Add(graphBox.LeftBottom + del); graphBox.Add(graphBox.RightTop - del); var gg = new GeometryGraph{BoundingBox = graphBox}; g.DataBase = db; g.GeometryGraph = gg; DisplayGraph(g, new Form()); db.nodesToShow = null; }
void ExtendVisibilityGraphToTargetBoundaryPort(Point takenOutTargetPortLocation) { List<Polygon> addedPolygons = null; if (VisibilityGraph == null) VisibilityGraph = new VisibilityGraph(); if (!activeRectangle.Contains(takenOutTargetPortLocation) || !activeRectangle.Contains(TargetLoosePolyline.BoundingBox)) { if (activeRectangle.IsEmpty) { activeRectangle = TargetLoosePolyline.BoundingBox; activeRectangle.Add(SourcePort.Location); activeRectangle.Add(StartPointOfEdgeRouting); activeRectangle.Add(takenOutTargetPortLocation); } else { activeRectangle.Add(takenOutTargetPortLocation); activeRectangle.Add(TargetLoosePolyline.BoundingBox); } addedPolygons = GetAddedPolygonesAndMaybeExtendActiveRectangle(); foreach (Polygon polygon in addedPolygons) VisibilityGraph.AddHole(polygon.Polyline); } if (addedPolygons == null) { if (targetVisibilityVertex != null) VisibilityGraph.RemoveVertex(targetVisibilityVertex); CalculateEdgeTargetVisibilityGraph(takenOutTargetPortLocation); } else { RemovePointVisibilityGraphs(); var visibilityGraphGenerator = new InteractiveTangentVisibilityGraphCalculator(addedPolygons, activePolygons, VisibilityGraph); visibilityGraphGenerator.Run(); activePolygons.AddRange(addedPolygons); CalculateEdgeTargetVisibilityGraph(takenOutTargetPortLocation); CalculateSourcePortVisibilityGraph(); } }
static void TestEllipseBoxOnEllipse(Ellipse ell) { var b = ell.BoundingBox; var smallerBox = new Rectangle(ell.Start); const int steps = 1000; var del = (ell.ParEnd - ell.ParStart) / steps; for (int i = 1; i <= steps; i++) smallerBox.Add(ell[ell.ParStart + i * del]); #if GDI_DEBUG_VIEWER if (!MsaglTestBase.DontShowTheDebugViewer()) { LayoutAlgorithmSettings.ShowDebugCurves( new DebugCurve(100, 0.1, "purple", ell), new DebugCurve(100, 0.1, "red", smallerBox.Perimeter()), new DebugCurve(100, 0.05, "green", b.Perimeter()), new DebugCurve(100, 0.1, "brown", new LineSegment(ell.Start, ell.End)), new DebugCurve(100, 0.1, "black", new LineSegment(ell.Center, ell.Start)), new DebugCurve(100, 0.1, "black", new LineSegment(ell.Center, ell.End))); } #endif Assert.IsTrue(ApproximateComparer.CloseIntersections(b.LeftTop, smallerBox.LeftTop) && ApproximateComparer.CloseIntersections(b.RightBottom, smallerBox.RightBottom)); }
internal Rectangle BoundingBox() { Rectangle rect = new Rectangle(Sites[0].Point, Sites[1].Point); rect.Add(Sites[2].Point); return rect; }
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"); }
void AddArrowToBox(Point start, Point end, double width, ref Rectangle box) { //it does not hurt to add a larger piece Point dir = (end - start).Rotate(Math.PI / 2); box.Add(end + dir); box.Add(end - dir); box.Add(start + dir); box.Add(start - dir); box.Left -= width; box.Top += width; box.Right += width; box.Bottom -= width; }
void AddLabelBox(ref Rectangle box) { if (Label != null && DGraph.DLabelIsValid(Label)) box.Add(Label.DrawingLabel.BoundingBox); }
/// <summary> /// enlarge the rectangle to contain the graph /// </summary> /// <param name="b"></param> void PumpTheBoxToTheGraph(ref Rectangle b) { foreach (Edge e in Edges) { if (e.UnderCollapsedCluster()) continue; if (e.Curve != null) { var cb = e.Curve.BoundingBox; cb.Pad(e.LineWidth); b.Add(cb); } foreach (var l in e.Labels.Where(lbl => lbl != null)) b.Add(l.BoundingBox); } foreach (Node n in Nodes) { if (n.UnderCollapsedCluster()) continue; b.Add(n.BoundingBox); } foreach (var c in RootCluster.Clusters) { if (c.BoundaryCurve == null) { if (c.RectangularBoundary != null) c.BoundaryCurve = c.RectangularBoundary.RectangularHull(); } if (c.BoundaryCurve != null) b.Add(c.BoundaryCurve.BoundingBox); } #if DEBUG && TEST_MSAGL if(DebugCurves!=null) foreach (var debugCurve in DebugCurves.Where(d => d.Curve != null)) b.Add(debugCurve.Curve.BoundingBox); #endif }