예제 #1
0
        private void tryForStartRectangle()
        {
            int w1, h1;
            this.listLayer.Clear();
            startRectangle = this.rectanglesByArea[0];
            this.rectanglesByArea.RemoveAt(0);
            w = w1 = startRectangle.Width;
            h = h1 = startRectangle.Height;
            this.rectangles = copyRectangles(this.Rectangles);
            this.rectangles.Sort(sortBySquare);
            this.removeStartRect();
            bool noLayerToDelate = true;
            while (!endthread && this.buildNextLayer())
            {
            }
            w1 = w;
            h1 = h;
            if (((double)w / (double)h) > 2)
                w1 = 2 * h;

            if (((double)w / (double)h) < 0.5)
                h1 = (int)2 * w;

            while (true)
            {
                noLayerToDelate = true;
                for (int i = 0; i < this.listLayer.Count; ++i)
                {
                    FirstAppAlgorithm1.Layer layer = listLayer[i];
                    if (!layer.moveBack(w1, h1))//nie dalo sie cofnac warstwy
                    {
                        this.listLayer.RemoveAt(i);
                        for (int j = i; j < this.listLayer.Count; ++j)//cofnaac wszystkie kolejne
                        {
                            if (this.listLayer[j].isHorizontal() == layer.isHorizontal())//ktore sa tego samego typu
                                 this.listLayer[j].moveStart(layer.End - layer.Start, layer.isHorizontal());
                        }
                        noLayerToDelate = false;
                        if (layer.isHorizontal())
                            h1 = h -(layer.End - layer.Start);
                        else
                            w1 = w - (layer.End - layer.Start);
                        if (((double)w1 /(double) h1) > 2)
                            w1 = 2 * h1;
                        if (((double)w1 / (double)h1) < 0.5)
                            h1 = (int)2 * w1;
                        break;
                    }
                }
                if (noLayerToDelate)
                   break;
            w = w1;
            h = h1;
            }
        }
예제 #2
0
 //tworzy liste prostok¹tow na podstawie tablicy input
 private void createRectangles()
 {
     List<Rectangle> rectangles = new List<Rectangle>();
     for (int i = 0; i < input.Length; i++)
     {
         int w,h;
         try
         {
             String[] s = input[i].Split(',');
             w = int.Parse(s[0]);
             h = int.Parse(s[1]);
         }
         catch (Exception e)
         {
             Console.Out.WriteLine("Nieprawidlowy format danych wejsciowych "+e.ToString());
             break;
         }
         Rectangle rect = new Data.Rectangle(w,h);
         rectangles.Add(rect);
     }
     engine.Rectangles = rectangles;
 }