private void CollapseCircles(int node) { var children = sg.Children[node]; if (children.Count == 0) { radii[node] = LeafRadius; return; } foreach (var child in children) { placed[child] = false; } var orderedChildren = children.OrderBy(x => positions[x].LengthSquared()).ToArray(); placed[orderedChildren.First()] = true; foreach (var child in orderedChildren.Skip(1)) { ApplySpringsForNodeChildren(node, true); placed[child] = true; } var childCircles = children.Select(x => new Circle2(positions[x], radii[x])).ToArray(); var boundingCircle = Circle2.BoundingCircle(childCircles); foreach (var child in children) { positions[child] -= boundingCircle.Center; } radii[node] = boundingCircle.Radius; }