private Data.PartOfSolution insertRectangle(Data.Rectangle x, Data.Rectangle r, bool[,] t) { Data.PartOfSolution part = new Data.PartOfSolution(); int m = t.GetLength(0); //liczba wierszy int n = t.GetLength(1); //liczba kolumn for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (t[i, j] == false) { //czy mozna wstawic prostokat if (this.canBeInserted(i, j, x.Height, x.Width, t)) { part.Ylu = i; part.Xlu = j; part.Yrd = i + x.Height - 1; part.Xrd = j + x.Width - 1; return part; } //a moze obrocony? if (this.canBeInserted(i, j, x.Width, x.Height, t)) { part.Ylu = i; part.Xlu = j; part.Yrd = i + x.Width - 1; part.Xrd = j + x.Height - 1; return part; } } } } part = this.findBestPlacement(x, r, t); if (part == null) { this.rotateRectangle(x); part = this.findBestPlacement(x, r, t); } return part; }
private Data.PartOfSolution fillCorners(Data.Rectangle x, Data.Rectangle r, int c) { if ((x.Width > r.Width) || (x.Height > r.Height)) return null; Data.PartOfSolution part = new Data.PartOfSolution(); if (c==LU) //lewy gorny { part.Xlu = 0; part.Ylu = 0; part.Xrd = x.Width - 1; part.Yrd = x.Height - 1; return part; } if (c==RU) //prawy gorny { part.Xlu = r.Width - x.Width; part.Ylu = 0; part.Xrd = r.Width - 1; part.Yrd = x.Height - 1; return part; } if (c==LD) //lewy dolny { part.Xlu = 0; part.Ylu = r.Height - x.Height; part.Xrd = x.Width - 1; part.Yrd = r.Height - 1; return part; } if (c == RD) //prawy dolny { part.Xlu = r.Width - x.Width; part.Ylu = r.Height - x.Height; part.Xrd = r.Width - 1; part.Yrd = r.Height - 1; return part; } return null; }
private Data.PartOfSolution findBestPlacement(Data.Rectangle x, Data.Rectangle r, bool[,] t) { Data.PartOfSolution part = new Data.PartOfSolution(); int m = t.GetLength(0); //liczba wierszy int n = t.GetLength(1); //liczba kolumn int max = -1, tmp; int a=0, b=0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { //find the max free area for current rectangle tmp = this.countFreeSquares(x.Width, x.Height, i, j, t); if (max < tmp) { max = tmp; a = i; b = j; } } } if (max < 0) return null; //rectangle cannot be inserted part.Ylu = a; part.Xlu = b; part.Yrd = a + x.Width - 1; part.Xrd = b + x.Height - 1; return part; }
public bool constructHorizontalLayer(List<Data.Rectangle> rectangle, int w,int h) { this.directionOfLayer = direction.Horizontal; int w1 = 0; this.start = h; this.end = -1; while (w1 < w ) { if (rectangle.Count == 0) { Console.WriteLine("Zabraklo prostokatow by skonczyc warstwe"); return false; //moze cos lepiej } Data.Rectangle rect = rectangle[0]; rectangle.Remove(rect); this.listUsedRectangles.Add(rect); //niepotzrebne Data.PartOfSolution part = new Data.PartOfSolution(); part.Xlu = w1; part.Ylu = h; part.Xrd = w1 + rect.Width; part.Yrd = h + rect.Height; this.listPartOfSolution.Add(part); w1 += rect.Width; if (this.end == -1 || this.end > part.Yrd)//h + rect.Height) this.end = part.Yrd;// h + rect.Height; //zapamietuje najglebsze wciecie!!!!!! this.lastPartEnd = part.Xrd; if (this.end2 < part.Yrd) this.end2 = part.Yrd; } return true; }