Changeset 13477
- Timestamp:
- 12/17/15 19:18:54 (9 years ago)
- Location:
- branches/HeuristicLab.BinPacking/PackingPlanVisualizations/2D
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/PackingPlanVisualizations/2D/CenteredContainer2D.cs
r13468 r13477 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using SharpDX; 24 25 … … 27 28 public class CenteredContainer2D { 28 29 private Vector2 containerSize; 29 private Vector2 controlSize;30 30 private float xScaling; 31 31 private float yScaling; 32 32 private readonly List<PackingItem> packingItems = new List<PackingItem>(); 33 33 34 public Vector2 ContainerCenter {35 get { return new Vector2(controlSize.X / 2, controlSize.Y / 2); }36 }34 //public Vector2 ContainerCenter { 35 // get { return new Vector2(controlSize.X / 2, controlSize.Y / 2); } 36 //} 37 37 38 38 private struct PackingItem { 39 privateVector2 position;40 privateVector2 size;41 privatereadonly string label;39 internal readonly Vector2 position; 40 internal readonly Vector2 size; 41 internal readonly string label; 42 42 public PackingItem(Vector2 size, Vector2 position, string label) { 43 43 this.size = size; 44 44 this.position = position; 45 45 this.label = label; 46 }47 public RectangleF GetRectangle(Vector2 topLeft, float sx, float sy) {48 return new RectangleF(49 topLeft.X + position.X * sx + 2,50 topLeft.Y + position.Y * sy + 2,51 topLeft.X + position.X * sx + size.X * sx - 2,52 topLeft.Y + position.Y * sy + size.Y * sy - 253 );54 }55 public string GetLabel() {56 return label;57 46 } 58 47 } … … 74 63 75 64 public void UpdateContainer(Vector2 controlSize) { 76 this.controlSize = controlSize; 77 xScaling = controlSize.X / (containerSize.X + 5); 78 yScaling = controlSize.Y / (containerSize.Y + 5); 65 xScaling = (controlSize.X - 4) / (containerSize.X); // leave 2 pixel space on each side 66 yScaling = (controlSize.Y - 4) / (containerSize.Y); 79 67 } 80 68 public void UpdateContainer(float controlWidth, float controlHeight) { … … 85 73 public RectangleF GetContainerData() { 86 74 //Compute centered rectangle 87 SharpDX.RectangleF result = new SharpDX.RectangleF( 88 ContainerCenter.X - containerSize.X * xScaling / 2 - 2, 89 ContainerCenter.Y - containerSize.Y * yScaling / 2 - 2, 90 ContainerCenter.X + containerSize.X * xScaling / 2 + 2, 91 ContainerCenter.Y + containerSize.Y * yScaling / 2 + 2); 92 93 return result; 75 return new RectangleF(2, 2, containerSize.X * xScaling, containerSize.Y * yScaling); 94 76 } 95 77 … … 105 87 106 88 public List<LabeledRectangle> GetItemRectangles() { 107 List<LabeledRectangle> result = new List<LabeledRectangle>(); 108 109 foreach (PackingItem item in packingItems) { 110 result.Add(new LabeledRectangle(item.GetLabel(), 111 item.GetRectangle(new Vector2(ContainerCenter.X - containerSize.X * xScaling / 2, 112 ContainerCenter.Y - containerSize.Y * yScaling / 2), xScaling, yScaling))); 113 } 114 115 return result; 89 return packingItems.Select(item => 90 new LabeledRectangle(item.label, 91 new RectangleF(item.position.X * xScaling + 2, item.position.Y * yScaling + 2, item.size.X * xScaling, item.size.Y * yScaling))) 92 .ToList(); 116 93 } 117 94 } -
branches/HeuristicLab.BinPacking/PackingPlanVisualizations/2D/PackingPlan2D.cs
r13468 r13477 49 49 50 50 CenteredContainer2D container; 51 #endregion Packing members END 52 51 #endregion 53 52 54 53 //Initialization-Methods … … 81 80 //Packing-Methods 82 81 public void InitializeContainer(float width, float height) { 83 container = new CenteredContainer2D(new Vector2( this.Width, this.Height), new Vector2(width, height));82 container = new CenteredContainer2D(new Vector2(Math.Max(this.Width - 12, 1), Math.Max(this.Height - 12, 1)), new Vector2(width, height)); 84 83 } 85 84 … … 103 102 wndRender.FillRectangle(container.GetContainerData(), containerFillingBrush); 104 103 105 foreach ( PackingPlanVisualizations.CenteredContainer2D.LabeledRectangleitem in container.GetItemRectangles()) {104 foreach (var item in container.GetItemRectangles()) { 106 105 wndRender.DrawRectangle(item.rectangle, itemBrush, 2f); 107 106 wndRender.FillRectangle(item.rectangle, itemFillingBrush);
Note: See TracChangeset
for help on using the changeset viewer.