Created base class for shared logic
MODIFY
WalletWasabi.Gui/Controls/QrEncoder/SquareBitMatrix.cs
WalletWasabi.Gui/Controls/QrEncoder/SquareBitMatrix.cs
namespace Gma.QrCodeNet.Encoding
{
- public class SquareBitMatrix : BitMatrix
+ public class SquareBitMatrix : BitMatrixBase
{
- private readonly bool[,] M_InternalArray;
-
- private readonly int M_Width;
-
- public SquareBitMatrix(int width)
+ public SquareBitMatrix(int width) : base(width, new bool[width, width])
{
- M_InternalArray = new bool[width, width];
- M_Width = width;
}
- internal SquareBitMatrix(bool[,] internalArray)
+ internal SquareBitMatrix(bool[,] internalArray) : base(internalArray)
{
- M_InternalArray = internalArray;
- int width = internalArray.GetLength(0);
- M_Width = width;
}
public static bool CreateSquareBitMatrix(bool[,] internalArray, out SquareBitMatrix triStateMatrix)
{
triStateMatrix = null;
- if (internalArray == null)
- return false;
- if (internalArray.GetLength(0) == internalArray.GetLength(1))
+ if (CanCreate(internalArray))
{
triStateMatrix = new SquareBitMatrix(internalArray);
return true;
}
- else
- {
return false;
}
- }
-
- /// <summary>
- /// Return value will be internal array itself. Not deep/shallow copy.
- /// </summary>
- public override bool[,] InternalArray
- {
- get
- {
- bool[,] deepCopyArray = new bool[M_Width, M_Width];
- for (int x = 0; x < M_Width; x++)
- for (int y = 0; y < M_Width; y++)
- deepCopyArray[x, y] = M_InternalArray[x, y];
- return deepCopyArray;
- }
- }
-
public override bool this[int i, int j]
{
get

MODIFY
WalletWasabi.Gui/Controls/QrEncoder/TriStateMatrix.cs
WalletWasabi.Gui/Controls/QrEncoder/TriStateMatrix.cs
namespace Gma.QrCodeNet.Encoding
{
- public class TriStateMatrix : BitMatrix
+ public class TriStateMatrix : BitMatrixBase
{
private readonly StateMatrix M_stateMatrix;
- private readonly bool[,] M_InternalArray;
-
- private readonly int M_Width;
-
- public TriStateMatrix(int width)
+ public TriStateMatrix(int width) : base(width, new bool[width, width])
{
M_stateMatrix = new StateMatrix(width);
- M_InternalArray = new bool[width, width];
- M_Width = width;
}
public static bool CreateTriStateMatrix(bool[,] internalArray, out TriStateMatrix triStateMatrix)
{
triStateMatrix = null;
- if (internalArray == null)
- return false;
-
- if (internalArray.GetLength(0) == internalArray.GetLength(1))
+ if (CanCreate(internalArray))
{
triStateMatrix = new TriStateMatrix(internalArray);
return true;
}
- else
- {
- return false;
- }
- }
- /// <summary>
- /// Return value will be deep copy of array.
- /// </summary>
- public override bool[,] InternalArray
- {
- get
- {
- bool[,] deepCopyArray = new bool[M_Width, M_Width];
- for (int x = 0; x < M_Width; x++)
- for (int y = 0; y < M_Width; y++)
- deepCopyArray[x, y] = M_InternalArray[x, y];
- return deepCopyArray;
- }
+ return false;
}
-
- internal TriStateMatrix(bool[,] internalArray)
+ internal TriStateMatrix(bool[,] internalArray) : base(internalArray)
{
- M_InternalArray = internalArray;
- int width = internalArray.GetLength(0);
- M_stateMatrix = new StateMatrix(width);
- M_Width = width;
+ M_stateMatrix = new StateMatrix(internalArray.GetLength(0));
}
public override bool this[int i, int j]

Created base class for shared logic