/// <summary>
        /// Replaces a box of the receiver with the contents of another matrix's box.
        /// The source box ranges from <i>[sourceColumn,sourceRow]</i> to <i>[sourceColumn+width-1,sourceRow+height-1]</i>, all inclusive.
        /// The destination box ranges from <i>[column,row]</i> to <i>[column+width-1,row+height-1]</i>, all inclusive.
        /// Does nothing if <i>width &lt;= 0 || height &lt;= 0</i>.
        /// If <i>source==this</i> and the source and destination box intersect in an ambiguous way, then replaces as if using an intermediate auxiliary copy of the receiver.
        /// </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>
        /// <param name="source">the source matrix to copy from(may be identical to the receiver).</param>
        /// <param name="sourceColumn">the index of the source column-coordinate.</param>
        /// <param name="sourceRow">the index of the source row-coordinate.</param>
        /// <exception cref="">if <i>column&lt;0 || column+width&gt;columns() || row&lt;0 || row+height&gt;rows()</i></exception>
        /// <exception cref="">if <i>sourceColumn&lt;0 || sourceColumn+width&gt;source.Columns || sourceRow&lt;0 || sourceRow+height&gt;source.Rows</i></exception>
        public void ReplaceBoxWith(int column, int row, int width, int height, BitMatrix source, int sourceColumn, int sourceRow)
        {
            this.ContainsBox(column, row, width, height);
            source.ContainsBox(sourceColumn, sourceRow, width, height);
            if (width <= 0 || height <= 0)
            {
                return;
            }

            if (source == this)
            {
                Rectangle destRect   = new Rectangle(column, row, width, height);
                Rectangle sourceRect = new Rectangle(sourceColumn, sourceRow, width, height);
                if (destRect.IntersectsWith(sourceRect))
                { // dangerous intersection
                    source = source.Copy();
                }
            }

            BitVector sourceVector  = source.ToBitVector();
            BitVector destVector    = this.ToBitVector();
            int       sourceColumns = source.Columns;

            for (; --height >= 0; row++, sourceRow++)
            {
                int offset       = row * _columns + column;
                int sourceOffset = sourceRow * sourceColumns + sourceColumn;
                destVector.ReplaceFromToWith(offset, offset + width - 1, sourceVector, sourceOffset);
            }
        }
        /// <summary>
        /// Compares this object against the specified object.
        /// The result is <code>true</code> if and only if the argument is
        /// not <code>null</code> and is a <code>BitMatrix</code> object
        /// that has the same number of columns and rows as the receiver and
        /// that has exactly the same bits set to <code>true</code> as the receiver.
        /// </summary>
        /// <param name="obj">the object to compare with.</param>
        /// <returns>
        /// <code>true</code> if the objects are the same;
        /// <code>false</code> otherwise.
        /// </returns>
        public override Boolean Equals(Object obj)
        {
            if (obj == null || !(obj is BitMatrix))
            {
                return(false);
            }
            if (this == obj)
            {
                return(true);
            }

            BitMatrix other = (BitMatrix)obj;

            if (_columns != other.Columns || _rows != other.Rows)
            {
                return(false);
            }

            return(ToBitVector().Equals(other.ToBitVector()));
        }
 /// <summary>
 /// Performs a logical <b>AND</b> of the receiver with another bit matrix.
 /// The receiver is modified so that a bit in it has the
 /// value <code>true</code> if and only if it already had the
 /// value <code>true</code> and the corresponding bit in the other bit matrix
 /// argument has the value <code>true</code>.
 /// </summary>
 /// <param name="other">a bit matrix.</param>
 /// <exception cref="ArgumentException">if <i>columns() != other.Columns || rows() != other.Rows</i>.</exception>
 public void And(BitMatrix other)
 {
     CheckDimensionCompatibility(other);
     ToBitVector().And(other.ToBitVector());
 }
Example #4
0
 /// <summary>
 /// Performs a logical <b>XOR</b> of the receiver with another bit matrix.
 /// The receiver is modified so that a bit in it has the
 /// value <code>true</code> if and only if one of the following statements holds:
 /// <ul>
 /// <li>The bit initially has the value <code>true</code>, and the
 ///     corresponding bit in the argument has the value <code>false</code>.
 /// <li>The bit initially has the value <code>false</code>, and the
 ///     corresponding bit in the argument has the value <code>true</code>d
 /// </ul>
 /// </summary>
 /// <param name="other">a bit matrix.</param>
 /// <exception cref="ArgumentException">if <i>columns() != other.Columns || rows() != other.Rows</i>.</exception>
 public void Xor(BitMatrix other)
 {
     checkDimensionCompatibility(other);
     ToBitVector().Xor(other.ToBitVector());
 }