private void AddToTheRightGroup(ref BBox b1, ref int count1, int lp, ref int rp, ObjectWithBox g) { Swap(lp, rp); rp--; b1.Add(g.Box); count1++; }
static double CommonArea(ref BBox a, ref BBox b) { double l = Math.Min(a.Left, b.Left); double r = Math.Max(a.Right, b.Right); double t = Math.Max(a.Top, b.Top); double bt = Math.Min(a.Bottom, b.Bottom); return((r - l) * (t - bt)); }
private void FindSeeds(int first, int count, out int seed0, out BBox b0, out int seed1) { seed0 = first; b0 = geometries[seed0].Box; double area = -1.0f; //looking for seed0 for (int i = first + 1; i < first + count; i++) { ObjectWithBox g = geometries[i]; BBox b = g.Box; double ar = CommonArea(ref b0, ref b); if (ar > area) { seed0 = i; area = ar; } } //looking for seed1 seed1 = first;//I'm getting a compiler error: there is no need actually to init seed1 area = -1.0f; b0 = geometries[seed0].Box; for (int i = first; i < first + count; i++) { if (i == seed0) { continue; } ObjectWithBox g = geometries[i]; BBox b = g.Box; double ar = CommonArea(ref b0, ref b); if (ar > area) { seed1 = i; area = ar; } } if (seed0 > seed1) { int t = seed1; seed1 = seed0; seed0 = t; } }
private void SplitOnGroups(int first, int count, int seed0, ref BBox b0, int seed1, out BBox b1, out int count0, out int count1) { b0 = geometries[seed0].Box; b1 = geometries[seed1].Box; //reshuffling in place: //put the next element of the first group on the first not occupied place on from the left //put the next element of the second group to the last not occupied place to the right Swap(first, seed0); //this puts the seed0 the most left position Swap(first + count - 1, seed1); //this puts seed1 to the right most position double ratio = 2; //lp points to the first not assigned element to the right of group 0 int lp = first + 1; //rp int rp = first + count - 2; //seed1 stands at first +count-1 count0 = 1; count1 = 1; while (count0 + count1 < count) { //First check the ratio of numbers of elements of the groups. //We need to keep the tree balanced. Let's watch that the ratio of the numbers of elements of the // two groups is between ratio and 1/ratio. ObjectWithBox g = geometries[lp]; if (count0 * ratio < count1) { AddToTheLeftGroup(ref b0, ref count0, ref lp, g); } else if (count1 * ratio < count0) { AddToTheRightGroup(ref b1, ref count1, lp, ref rp, g); } else //make decision based on the growing of the group boxes { BBox b = g.Box; double squareGrouth0 = CommonArea(ref b0, ref b) - b0.Area; double squareGrouth1 = CommonArea(ref b1, ref b) - b1.Area; if (squareGrouth0 < squareGrouth1) { AddToTheLeftGroup(ref b0, ref count0, ref lp, g); } else { AddToTheRightGroup(ref b1, ref count1, lp, ref rp, g); } } } }
//private void SpreadGroupForMDS(MsaglMouseEventArgs args) { // if ((viewer.ModifierKeys & Microsoft.Msagl.Drawing.ModifierKeys.Shift) == Microsoft.Msagl.Drawing.ModifierKeys.Shift) { // Microsoft.Msagl.Splines.Rectangle rect = // new Microsoft.Msagl.Splines.Rectangle(this.mouseDownSourcePoint, viewer.ScreenToSource(args)); // double radius = (rect.LeftTop - rect.RightBottom).Length / 2; // Set<IViewerNode> iSet = new Set<IViewerNode>(); // Set<Microsoft.Msagl.Node> setToSpread = new Set<Microsoft.Msagl.Node>(); // GeometryGraph graph = null; // foreach (IViewerNode node in Nodes()) { // if (rect.Intersect(node.Node.BoundingBox)) { // viewer.InvalidateBeforeTheChange(node); // foreach (IViewerEdge edge in node.SelfEdges) // viewer.Invalidate(edge); // iSet.Insert(node); // setToSpread.Insert(node.Node.Attr.GeometryNode); // graph = node.Node.Attr.GeometryNode.Parent as GeometryGraph; // } // } // foreach (IViewerNode node in Nodes()) { // viewer.Invalidate(node); // foreach (IViewerEdge edge in node.OutEdges) // viewer.Invalidate(edge); // foreach (IViewerEdge edge in node.SelfEdges) // viewer.Invalidate(edge); // } // if (graph != null) { // System.Console.WriteLine("xxx"); // Microsoft.Msagl.Mds.MdsGraphLayout graphLayout = new Microsoft.Msagl.Mds.MdsGraphLayout(); // graphLayout.GroupSpread(graph, setToSpread); // } // foreach (IViewerNode node in Nodes()) { // viewer.Invalidate(node); // foreach (IViewerEdge edge in node.OutEdges) // viewer.Invalidate(edge); // foreach (IViewerEdge edge in node.SelfEdges) // viewer.Invalidate(edge); // } // viewer.Invalidate(); //remove it later // args.Handled = true; // } //} private void SelectEntitiesForDraggingWithRectangle(MsaglMouseEventArgs args) { Microsoft.Msagl.Splines.Rectangle rect = new Microsoft.Msagl.Splines.Rectangle(this.mouseDownSourcePoint, viewer.ScreenToSource(args)); foreach (IViewerNode node in Nodes()) { if (rect.Intersect(node.Node.BoundingBox)) { SelectObjectForDragging(node); } } args.Handled = true; }
internal Geometry(DObject tag) { this.tag = tag; DNode dNode = tag as DNode; if (dNode != null) { bBox = dNode.DrawingNode.BoundingBox; } else { DLabel dLabel = tag as DLabel; if (dLabel != null) { bBox = dLabel.DrawingLabel.BoundingBox; } } }
internal Geometry(DObject tag, BBox box) { this.tag = tag; this.bBox = box; }
private static void AddToTheLeftGroup(ref BBox b0, ref int count0, ref int lp, ObjectWithBox g) { lp++; count0++; b0.Add(g.Box); }
public static VA.Drawing.Rectangle ToVARectangle(MG.Splines.Rectangle n) { return(new VA.Drawing.Rectangle(n.Left, n.Bottom, n.Right, n.Top)); }