/// <summary>
 /// Fills the Matrix complete with BlockParts
 /// </summary>
 public void FillComplete()
 {
     for (int row = 0; row < Rows; row++)
     {
         for (int col = 0; col < Cols; col++)
         {
             matrix[row, col] = new BlockPart(row, col);
         }
     }
 }
 /// <summary>
 /// Deserializes a Matrix from a serialized Matrix, used when BlockStructure is saved to a file.
 /// </summary>
 /// <param name="serializedMatrix">A Matrix of bools</param>
 /// <returns>A BlockPart Matrix</returns>
 private BlockPart[,] DeserializeMatrix(bool[,] serializedMatrix)
 {
     BlockPart[,] newMatrix = new BlockPart[Rows, Cols];
     for (int row = 0; row < Rows; row++)
     {
         for (int col = 0; col < Cols; col++)
         {
             if (serializedMatrix[row, col])
             {
                 newMatrix[row, col] = new BlockPart(row, col);
             }
         }
     }
     return(newMatrix);
 }
        /// <summary>
        /// Crops the Matrix and returnes the cropped Matrix. If a cropped Matrix already exsists, it is
        /// returned imidiatly
        /// </summary>
        /// <returns>A cropped Matrix</returns>
        public BlockPart[,] GetCroppedMatrix()
        {
            //Return already exsiting CroppedMatrix
            if (croppedMatrix != null)
            {
                return(croppedMatrix);
            }

            int emptyRows = 0;
            int emptyCols = 0;

            //Find leading empty Rows
            for (int row = 0; row < Rows; row++)
            {
                if (!IsEmpty(GetRow(matrix, row)))
                {
                    emptyRows = row;
                    break;
                }
            }

            //Find leading empty Columns
            for (int col = 0; col < Cols; col++)
            {
                if (!IsEmpty(GetColumn(matrix, col)))
                {
                    emptyCols = col;
                    break;
                }
            }

            //Create new CroppedMatrix with no leading empty Rows or Columns
            RowsCropped = Rows - emptyRows;
            ColsCropped = Cols - emptyCols;

            croppedMatrix = new BlockPart[RowsCropped, ColsCropped];

            for (int row = 0; row < Rows; row++)
            {
                for (int col = 0; col < Cols; col++)
                {
                    if (matrix[row, col] != null)
                    {
                        croppedMatrix[row - emptyRows, col - emptyCols] = new BlockPart(row - emptyRows, col - emptyCols);
                    }
                }
            }


            //Find the trailing empty Rows and set the CroppedRow variable to last occupied Row
            for (int row = 0; row < RowsCropped; row++)
            {
                if (IsEmpty(GetRow(croppedMatrix, row)))
                {
                    RowsCropped = row;
                    break;
                }
            }

            //Find the trailing empty Rows and set the CroppedRow variable to last occupied Row
            for (int col = 0; col < ColsCropped; col++)
            {
                if (IsEmpty(GetColumn(croppedMatrix, col)))
                {
                    ColsCropped = col;
                    break;
                }
            }

            //Return the CroppedMatrix
            return(croppedMatrix);
        }
 /// <summary>
 /// Adds a BlockPart to the Matrix
 /// </summary>
 /// <param name="node">The Part to add</param>
 /// <param name="row">The Row in the Matrix</param>
 /// <param name="col">The Column in the Matrix</param>
 public void AddNode(BlockPart node, int row, int col)
 {
     matrix[row, col] = node;
 }