private void PackBlock(Block bl, int maxX, int[] level, Graphics g)
        {
            TryPlaceBlockRightToLeft(bl, maxX, level);
            TryPlaceBlockLeftToRight(bl, maxX, level);

            if (g.VisibleClipBounds.Height - bl.LeftTop.Y < bl.Size.Height)
            {
                bl.LeftTop = new PointF(-bl.Size.Width, -bl.Size.Height);
                return;
            }
            AddBlockToLevel(bl, level);
        }
 private void TryPlaceBlockRightToLeft(Block bl, int maxX, int[] level)
 {
     var height = level[maxX];
     var width = 1;
     for (var x = maxX - 1; x >= 0; --x)
     {
         if (level[x] > height)
             height = level[x];
         ++width;
         if (bl.Size.Width <= width)
         {
             bl.LeftTop = new PointF(maxX - width, height);
             break;
         }
     }
 }
        private void TryPlaceBlockLeftToRight(Block bl, int maxX, int[] level)
        {
            var height = level[0];
            var width = 1;
            var startX = 0;
            for (var x = 1; x <= maxX; ++x)
            {
                if (level[x] < bl.LeftTop.Y && height > bl.LeftTop.Y)
                {
                    width = 1;
                    startX = x;
                    height = level[x];
                }

                if (level[x] > height)
                    height = level[x];
                ++width;
                if (bl.Size.Width <= width && height <= bl.LeftTop.Y)
                {
                    bl.LeftTop = new PointF(startX, height);
                    break;
                }
            }
        }
 private void AddBlockToLevel(Block bl, int[] level)
 {
     for (var x = 0; x < (int)bl.Size.Width; ++x)
         level[(int)bl.LeftTop.X + x] = (int)(bl.LeftTop.Y + bl.Size.Height);
     
 }
Exemple #5
0
 public bool Contains(Block other)
     => other.IsInside(this);
Exemple #6
0
 public bool IsInside(Block container)
     => container.LeftTop.X <= LeftTop.X && 
     container.LeftTop.Y <= LeftTop.Y && 
     container.RightBottom.X >= RightBottom.X && 
     container.RightBottom.Y >= RightBottom.Y;