private void CalculateWastedArea() { Wasted.Add(new RectangularBox { X = Gap.X, Y = Gap.Y }); Gap = new RectangularBox { X = ContainerWidth - MinX, Y = MaxY - CurrentHeight }; }
private void ResetGap() { Gap = new RectangularBox { X = ContainerWidth, Y = int.MaxValue }; CursorX = 0; CursorY = MaxY; CurrentHeight = MaxY; }
public BoxFittingAlgorithm() { CurrentBin = new RectangularBox(); Gap = new RectangularBox(); Wasted = new List <RectangularBox>(); CurrentContainer = new RectangularBox(); BoxList = new Dictionary <int, RectangularBox>(); OptimizedBoxList = new Dictionary <int, RectangularBox>(); ResultList = new List <RectangularBox>(); ResultListCoordinates = new List <Point>(); CursorPoints = new List <Point>(); }
private void CaculateGap(bool hasNewline) { if (hasNewline) { ResetGap(); } else { Gap = new RectangularBox { X = ContainerWidth - CursorX, Y = CurrentHeight - CursorY }; if (Gap.X == 0 && Gap.Y == 0) { ResetGap(); } } }
private bool SelectBin(List <List <int> > pairIndexValueList) { int i = 0; while (pairIndexValueList.Count > 0 && i < pairIndexValueList.Count) { var width = pairIndexValueList[i][1]; var index = pairIndexValueList[i][0]; var heights = pairIndexValueList.Where(t => t[0] == index && pairIndexValueList.IndexOf(t) != pairIndexValueList.IndexOf(pairIndexValueList[i])).ToList(); if (heights.Count > 0) { var height = heights[0][1]; //width = Math.Max(width, height); //height = Math.Min(width, height); if (width <= Gap.X && height <= Gap.Y) { CurrentPair1 = pairIndexValueList[i]; index = pairIndexValueList.IndexOf(CurrentPair1); var CurrentPair2s = pairIndexValueList.Where(t => t[0] == CurrentPair1[0] && pairIndexValueList.IndexOf(t) != index).ToList(); if (CurrentPair2s.Count > 0) { CurrentPair2 = CurrentPair2s[0]; } //width = Math.Max(CurrentPair1[1], CurrentPair2[1]); //height = Math.Min(CurrentPair1[1], CurrentPair2[1]); PreviuosBin = new RectangularBox { X = CurrentBin.X, Y = CurrentBin.Y }; CurrentBin = new RectangularBox { X = width, Y = height }; return(true); } else if (height <= Gap.X && width <= Gap.Y) { CurrentPair1 = pairIndexValueList[i]; index = pairIndexValueList.IndexOf(CurrentPair1); var CurrentPair2s = pairIndexValueList.Where(t => t[0] == CurrentPair1[0] && pairIndexValueList.IndexOf(t) != index).ToList(); if (CurrentPair2s.Count > 0) { CurrentPair2 = CurrentPair2s[0]; } var temp = width; width = height; height = temp; PreviuosBin = new RectangularBox { X = CurrentBin.X, Y = CurrentBin.Y }; CurrentBin = new RectangularBox { X = width, Y = height }; return(true); } i++; } else { return(false); } } return(false); }