/// <summary> /// Pack the given graph components to the specified aspect ratio /// </summary> /// <param name="components">set of graphs to pack</param> /// <param name="settings">settings for packing method and desired aspect ratio</param> /// <returns>Bounding box of the packed components</returns> public static Rectangle PackGraphs(IEnumerable <GeometryGraph> components, LayoutAlgorithmSettings settings) { ValidateArg.IsNotEmpty(components, "components"); List <RectangleToPack <GeometryGraph> > rectangles = (from c in components select new RectangleToPack <GeometryGraph>(c.BoundingBox, c)).ToList(); if (rectangles.Count > 1) { OptimalPacking <GeometryGraph> packing = settings.PackingMethod == PackingMethod.Compact ? new OptimalRectanglePacking <GeometryGraph>(rectangles, settings.PackingAspectRatio) : (OptimalPacking <GeometryGraph>) new OptimalColumnPacking <GeometryGraph>(rectangles, settings.PackingAspectRatio); packing.Run(); foreach (var r in rectangles) { GeometryGraph component = r.Data; var delta = r.Rectangle.LeftBottom - component.boundingBox.LeftBottom; component.Translate(delta); } return(new Rectangle(0, 0, packing.PackedWidth, packing.PackedHeight)); } return(rectangles[0].Rectangle); }