getRow() 공개 메소드

A fast method to retrieve one row of data from the matrix as a BitArray.
public getRow ( int y, BitArray row ) : BitArray
y int The row to retrieve ///
row BitArray An optional caller-allocated BitArray, will be allocated if null or too small ///
리턴 BitArray
예제 #1
0
        public void testGetRow()
        {
            BitMatrix matrix = new BitMatrix(102, 5);

            for (int x = 0; x < 102; x++)
            {
                if ((x & 0x03) == 0)
                {
                    matrix[x, 2] = true;
                }
            }

            // Should allocate
            BitArray array = matrix.getRow(2, null);

            Assert.AreEqual(102, array.Size);

            // Should reallocate
            BitArray array2 = new BitArray(60);

            array2 = matrix.getRow(2, array2);
            Assert.AreEqual(102, array2.Size);

            // Should use provided object, with original BitArray size
            BitArray array3 = new BitArray(200);

            array3 = matrix.getRow(2, array3);
            Assert.AreEqual(200, array3.Size);

            for (int x = 0; x < 102; x++)
            {
                bool on = (x & 0x03) == 0;
                Assert.AreEqual(on, array[x]);
                Assert.AreEqual(on, array2[x]);
                Assert.AreEqual(on, array3[x]);
            }
        }
예제 #2
0
        /// <summary>
        /// Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the corresponding
        /// mask bit is set.
        /// </summary>
        /// <param name="mask">The mask.</param>
        public void xor(BitMatrix mask)
        {
            if (width != mask.Width || height != mask.Height || rowSize != mask.RowSize)
            {
                throw new ArgumentException("input matrix dimensions do not match");
            }
            var rowArray = new BitArray(width);

            for (int y = 0; y < height; y++)
            {
                int   offset = y * rowSize;
                int[] row    = mask.getRow(y, rowArray).Array;
                for (int x = 0; x < rowSize; x++)
                {
                    bits[offset + x] ^= row[x];
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the corresponding
 /// mask bit is set.
 /// </summary>
 /// <param name="mask">The mask.</param>
 public void xor(BitMatrix mask)
 {
     if (width != mask.Width || height != mask.Height
         || rowSize != mask.RowSize)
     {
         throw new ArgumentException("input matrix dimensions do not match");
     }
     var rowArray = new BitArray(width / 32 + 1);
     for (int y = 0; y < height; y++)
     {
         int offset = y * rowSize;
         int[] row = mask.getRow(y, rowArray).Array;
         for (int x = 0; x < rowSize; x++)
         {
             bits[offset + x] ^= row[x];
         }
     }
 }
예제 #4
0
      // The following could go to the BitMatrix class (maybe in a more efficient version using the BitMatrix internal
      // data structures)
      /// <summary>
      /// Rotate180s the specified bit matrix.
      /// </summary>
      /// <param name="bitMatrix">bit matrix to rotate</param>
      internal static void rotate180(BitMatrix bitMatrix)
      {
         int width = bitMatrix.Width;
         int height = bitMatrix.Height;
         BitArray firstRowBitArray = new BitArray(width);
         BitArray secondRowBitArray = new BitArray(width);
         BitArray tmpBitArray = new BitArray(width);
         for (int y = 0; y < height + 1 >> 1; y++)
         {

            firstRowBitArray = bitMatrix.getRow(y, firstRowBitArray);
            bitMatrix.setRow(y, mirror(bitMatrix.getRow(height - 1 - y, secondRowBitArray), tmpBitArray));
            bitMatrix.setRow(height - 1 - y, mirror(firstRowBitArray, tmpBitArray));
         }
      }