Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13477 for branches


Ignore:
Timestamp:
12/17/15 19:18:54 (9 years ago)
Author:
gkronber
Message:

#1966 fixed visualization of 2d packing

Location:
branches/HeuristicLab.BinPacking/PackingPlanVisualizations/2D
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/2D/CenteredContainer2D.cs

    r13468 r13477  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using SharpDX;
    2425
     
    2728  public class CenteredContainer2D {
    2829    private Vector2 containerSize;
    29     private Vector2 controlSize;
    3030    private float xScaling;
    3131    private float yScaling;
    3232    private readonly List<PackingItem> packingItems = new List<PackingItem>();
    3333
    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    //}
    3737
    3838    private struct PackingItem {
    39       private Vector2 position;
    40       private Vector2 size;
    41       private readonly string label;
     39      internal readonly Vector2 position;
     40      internal readonly Vector2 size;
     41      internal readonly string label;
    4242      public PackingItem(Vector2 size, Vector2 position, string label) {
    4343        this.size = size;
    4444        this.position = position;
    4545        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 - 2
    53         );
    54       }
    55       public string GetLabel() {
    56         return label;
    5746      }
    5847    }
     
    7463
    7564    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);
    7967    }
    8068    public void UpdateContainer(float controlWidth, float controlHeight) {
     
    8573    public RectangleF GetContainerData() {
    8674      //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);
    9476    }
    9577
     
    10587
    10688    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();
    11693    }
    11794  }
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/2D/PackingPlan2D.cs

    r13468 r13477  
    4949
    5050    CenteredContainer2D container;
    51     #endregion Packing members END
    52 
     51    #endregion
    5352
    5453    //Initialization-Methods
     
    8180    //Packing-Methods
    8281    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));
    8483    }
    8584
     
    103102        wndRender.FillRectangle(container.GetContainerData(), containerFillingBrush);
    104103
    105         foreach (PackingPlanVisualizations.CenteredContainer2D.LabeledRectangle item in container.GetItemRectangles()) {
     104        foreach (var item in container.GetItemRectangles()) {
    106105          wndRender.DrawRectangle(item.rectangle, itemBrush, 2f);
    107106          wndRender.FillRectangle(item.rectangle, itemFillingBrush);
Note: See TracChangeset for help on using the changeset viewer.