コード例 #1
0
 //probuje do istniejace prostokata stworzyc linie prostokatow ktora bedzie przylegac do jednego z bokow
 private static bool TryFillLine(int currentSum, int currentSide, Rectangle tempRect,
     List<Rectangle> correctRects, List<Rectangle> tempRectsList, Taio.Rectangle.Orientation orientation)
 {
     bool foundLine = true;
     while (currentSum < currentSide)
     {
         int minSide = (orientation == Rectangle.Orientation.Horizontal) ? tempRect.SideB : tempRect.SideA;
         Rectangle tmp = TryFindNextRect(minSide, currentSum, currentSide, correctRects, orientation);
         if (tmp == null)
         {
             foundLine = false;
             break;
         }
         currentSum += (orientation == Rectangle.Orientation.Horizontal) ? tmp.SideA : tmp.SideB;
         tempRectsList.Add(tmp);
     }
     return foundLine;
 }
コード例 #2
0
 //probuje znalezc prostokat do uzupelnienia linii prostokatow
 private static Rectangle TryFindNextRect(int shorterSide, int currentSide, int maxSide,
     List<Rectangle> rects, Taio.Rectangle.Orientation orientation)
 {
     int index = -1;
     int val = Int32.MaxValue;
     bool needRotate = true;
     Rectangle rect = null;
     for (int i = 0; i < rects.Count; i++)
     {
         Rectangle tempRect = rects[i];
         int lostAreaHorz = CountAreaLost(currentSide, maxSide, shorterSide, tempRect.SideA,
             tempRect.SideB);
         int lostAreaVert = CountAreaLost(currentSide, maxSide, shorterSide, tempRect.SideB,
             tempRect.SideA);
         int lostArea = Math.Min(lostAreaHorz, lostAreaVert);
         if (lostArea < val)
         {
             index = i;
             val = lostArea;
             if (lostArea == lostAreaVert)
                 needRotate = true;
             else
                 needRotate = false;
         }
     }
     if (index != -1)
     {
         rect = rects[index];
         rects.Remove(rect);
         if (needRotate && orientation == Rectangle.Orientation.Horizontal)
             rect.Rotate();
         else if (!needRotate && orientation == Rectangle.Orientation.Vertical)
             rect.Rotate();
     }
     return rect;
 }
コード例 #3
0
 //seeks complex rectangle and extracts all simple rectangles
 private void ExtractRectangles(Taio.Rectangle rectangle)
 {
     if (rectangle.ContainedRectangles.Count == 0)
     {
         Taio.Rectangle rec = new Taio.Rectangle(rectangle.SideA, rectangle.SideB, rectangle.LeftTop);
         rec.Number = rectangle.Number;
         extractedRectangles.Add(rec);
     }
     else
         for (int i = 0; i < rectangle.ContainedRectangles.Count; ++i)
             ExtractRectangles(rectangle.ContainedRectangles[i]);
 }