Exemplo n.º 1
0
        /// <summary>
        /// Constructs and returns a new matrix with <i>width</i> columns and <i>height</i> rows which is a copy of the contents of the given box.
        /// The box ranges from <i>[column,row]</i> to <i>[column+width-1,row+height-1]</i>, all inclusive.
        /// </summary>
        /// <param name="column">the index of the column-coordinate.</param>
        /// <param name="row">the index of the row-coordinate.</param>
        /// <param name="width">the width of the box.</param>
        /// <param name="height">the height of the box.</param>
        /// <returns></returns>
        /// <exception cref="IndexOutOfRangeException">if <i>column&lt;0 || column+width&gt;columns() || row&lt;0 || row+height&gt;rows()</i></exception>
        public BitMatrix Part(int column, int row, int width, int height)
        {
            if (column < 0 || column + width > _columns || row < 0 || row + height > _rows)
            {
                throw new IndexOutOfRangeException("column:" + column + ", row:" + row + " ,width:" + width + ", height:" + height);
            }
            if (width <= 0 || height <= 0)
            {
                return(new BitMatrix(0, 0));
            }

            BitMatrix subMatrix = new BitMatrix(width, height);

            subMatrix.ReplaceBoxWith(0, 0, width, height, this, column, row);
            return(subMatrix);
        }