public void Execute(LayoutEngine target) { var boundsWidth = (int)Bounds.Width; var boundsHeight = (int)Bounds.Height; var seed = Seed; var rnd = new Random(seed); foreach (var item in target.Nodes) { if (item.Control.HasValidLayout) { continue; } var x = (int)Bounds.X; var y = (int)Bounds.Y; item.Position = new Point(rnd.Next(x, x + boundsWidth - 45), rnd.Next(y, y + boundsHeight - 45)); } }
public void Execute(LayoutEngine target) { var perimeter = 0.0; var usableNodes = target.Nodes; var halfSize = new double[usableNodes.Length]; var i = 0; foreach (var s in usableNodes.Select(v => new Size(45.0, 45.0))) { halfSize[i] = Math.Sqrt(s.Width * s.Width + s.Height * s.Height) * 0.5; perimeter += halfSize[i] * 2; i++; } var radius = perimeter / (2 * Math.PI); var angle = 0.0; double a; i = 0; foreach (var v in usableNodes) { a = Math.Sin(halfSize[i] * 0.5 / radius) * 2; angle += a; v.Position = new Point(Math.Cos(angle) * radius + radius, Math.Sin(angle) * radius + radius); angle += a; } radius = angle / (2 * Math.PI) * radius; angle = 0; i = 0; foreach (var v in usableNodes) { a = Math.Sin(halfSize[i] * 0.5 / radius) * 2; angle += a; v.Position = new Point(Math.Cos(angle) * radius + radius, Math.Sin(angle) * radius + radius); angle += a; } }
public void Assign(LayoutEngine layout) { _sourceIndex ??= layout.Nodes.Single(x => x.Control == Control.Source).Index; _targetIndex ??= layout.Nodes.Single(x => x.Control == Control.Target).Index; }
public void Assign(LayoutEngine layout) { _incomingEdges ??= layout.Edges.Where(x => x.TargetIndex == Index).Select(x => x.Index).ToArray(); _outgoingEdges ??= layout.Edges.Where(x => x.SourceIndex == Index).Select(x => x.Index).ToArray(); }