Skip to end of metadata
Go to start of metadata

Represents a 2D matrix of bits. In function arguments below, and throughout the common module, x is the column position, and y is the row position. The ordering is always x, y. The origin is at the top-left. Internally the bits are represented in a 1-D array of 32-bit ints. However, each row begins with a new int. This is done intentionally so that we can copy out a row into a BitArray very efficiently. The ordering of bits is row-major. Within each int, the least significant bits are used first, meaning they represent lower x values. This is compatible with BitArray's implementation.

Definition

public sealed class BitMatrix

Summary

The following table summarizes the members exposed in this class.

Public Constructors

BitMatrix Constructor(int) Initializes a new instance of the BitMatrix class.
BitMatrix Constructor(int, int) Initializes a new instance of the BitMatrix class.

Public Properties

Dimension This method is for compatibility with older code. It's only logical to call if the matrix is square, so I'm throwing if that's not the case.
Height Gets the height.
this[int, int] Gets the requested bit, where true means black.
Width Gets the width.

Public Methods

Clear() Clears all bits (sets to false).
Clone() Clones this instance.
Equals(object) Determines whether the specified System.Object, is equal to this instance.
Flip(int, int) Flips the given bit.
GetBottomRightOnBit() Gets the bottom right on bit.
GetEnclosingRectangle() This is useful in detecting the enclosing rectangle of a 'pure' barcode.
GetHashCode() Returns a hash code for this instance.
GetRow(int, BitArray) A fast method to retrieve one row of data from the matrix as a BitArray.
GetTopLeftOnBit() This is useful in detecting a corner of a 'pure' barcode.
Rotate180() Modifies this BitMatrix to represent the same but rotated 180 degrees
SetRegion(int, int, int, int) Sets a square region of the bit matrix to true.
SetRow(int, BitArray) Sets the row.
ToString() Returns a string that represents the current object.

Public Constructors

public BitMatrix(int dimension)

Initializes a new instance of the BitMatrix class.

Parameters

dimension The dimension.

public BitMatrix(int width, int height)

Initializes a new instance of the BitMatrix class.

Parameters

width The width.
height The height.

Exceptions

ArgumentException Both dimensions must be greater than 0

Public Properties

public int Dimension { get; }

This method is for compatibility with older code. It's only logical to call if the matrix is square, so I'm throwing if that's not the case.

public int Height { get; }

Gets the height.

public bool this[int x, int y] { get; set; }

Gets the requested bit, where true means black.

Parameters

x The horizontal component (i.e. which column)
y The vertical component (i.e. which row)

public int Width { get; }

Gets the width.

Public Methods

public void Clear()

Clears all bits (sets to false).

public object Clone()

Clones this instance.

public bool Equals(object obj)

Determines whether the specified System.Object, is equal to this instance.

Parameters

obj The System.Object to compare with this instance.

Return Types

true if the specified System.Object is equal to this instance; otherwise, false.

public void Flip(int x, int y)

Flips the given bit.

Parameters

x The horizontal component (i.e. which column)
y The vertical component (i.e. which row)

public Int32[] GetBottomRightOnBit()

Gets the bottom right on bit.

public Int32[] GetEnclosingRectangle()

This is useful in detecting the enclosing rectangle of a 'pure' barcode.

Return Types

{left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white

public int GetHashCode()

Returns a hash code for this instance.

Return Types

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

public BitArray GetRow(int y, BitArray row)

A fast method to retrieve one row of data from the matrix as a BitArray.

Parameters

y The row to retrieve
row An optional caller-allocated BitArray, will be allocated if null or too small

Return Types

The resulting BitArray - this reference should always be used even when passing your own row

public Int32[] GetTopLeftOnBit()

This is useful in detecting a corner of a 'pure' barcode.

Return Types

{x,y} coordinate of top-left-most 1 bit, or null if it is all white

public void Rotate180()

Modifies this BitMatrix to represent the same but rotated 180 degrees

public void SetRegion(int left, int top, int width, int height)

Sets a square region of the bit matrix to true.

Parameters

left The horizontal position to begin at (inclusive)
top The vertical position to begin at (inclusive)
width The width of the region
height The height of the region

public void SetRow(int y, BitArray row)

Sets the row.

Parameters

y row to set
row BitArray to copy from

public string ToString()

Returns a string that represents the current object.

Return Types

A string that represents the current object.
  • No labels