public getRow ( int y, |
||
y | int | The row to retrieve /// |
row | An optional caller-allocated BitArray, will be allocated if null or too small /// | |
리턴 |
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]); } }
/// <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]; } } }
/// <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]; } } }
// 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)); } }