Exemplo n.º 1
0
        /// <summary>
        /// Calculate area prioritizing vertically
        /// </summary>
        /// <param name="block"></param>
        /// <param name="vert"></param>
        /// <param name="hori"></param>
        public GroupData CalcAreaVert(Block block, Direction vert, Direction hori)
        {
            Block     place       = block;
            Block     current     = null;
            Block     cornerBlock = null;
            GroupData data        = new GroupData();

            int height        = 0;
            int currentHeight = 0;
            int width         = boundary.width + 1;
            int currentWidth  = 0;

            switch (hori)
            {
            case Direction.left:
                IterateHori = SameLeft;
                break;

            case Direction.right:
                IterateHori = SameRight;
                break;

            default:
                return(data);
            }

            switch (vert)
            {
            case Direction.up:
                IterateVert = SameUp;
                break;

            case Direction.down:
                IterateVert = SameDown;
                break;

            default:
                return(data);
            }

            //Iterate prioritizing vertical
            while (place != null && place.IsGrouped() == false)
            {
                currentWidth = 0;
                current      = place;

                //Check if current block is null,.IsGrouped(), or passed the width
                while (current != null && current.IsGrouped() == false && currentWidth < width)
                {
                    //This currently priorites vertical rectangles
                    if (currentWidth >= 2)
                    {
                        cornerBlock = current;
                    }

                    current = IterateHori(current);

                    currentWidth++;
                }

                //Iterate vertically
                place = IterateVert(place);

                if (currentWidth >= 2)
                {
                    height++;
                    //Set height to shortest height
                    if (width > currentWidth)
                    {
                        width = currentWidth;
                    }
                }
                else
                {
                    return(data);
                }


                currentHeight++;
            }

            if (width == boundary.width + 1 || width <= 1 || height <= 1)
            {
                return(data);
            }

            data.width  = width;
            data.height = height;

            width  = width - 1;
            height = height - 1;

            int x = block.X;
            int y = block.Y;

            //Corners will be opposite of the direction the data points (up and left means block is bottom right corner
            if (vert.Equals(Direction.up) && hori.Equals(Direction.left))
            {
                data.topLeft     = board.GetBlock(x - width, y + height);
                data.topRight    = board.GetBlock(x, y + height);
                data.bottomLeft  = board.GetBlock(x - width, y);
                data.bottomRight = block;
            }
            else if (vert.Equals(Direction.up) && hori.Equals(Direction.right))
            {
                data.topLeft     = board.GetBlock(x, y + height);
                data.topRight    = board.GetBlock(x + width, y + height);
                data.bottomLeft  = block;
                data.bottomRight = board.GetBlock(x + width, y);
            }
            else if (vert.Equals(Direction.down) && hori.Equals(Direction.left))
            {
                data.topLeft     = board.GetBlock(x - width, y);
                data.topRight    = block;
                data.bottomLeft  = board.GetBlock(x - width, y - height);
                data.bottomRight = board.GetBlock(x, y - height);
            }
            else if (vert.Equals(Direction.down) && hori.Equals(Direction.right))
            {
                data.topLeft     = block;
                data.topRight    = board.GetBlock(x + width, y);
                data.bottomLeft  = board.GetBlock(x, y - height);
                data.bottomRight = board.GetBlock(x + width, y - height);
            }

            return(data);
        }