GeometryClassLibrary.MatricesMatrix.ConvertToMatrix C# (CSharp) Method

ConvertToMatrix() public method

Strips out all the elements from each submatrix and creates an equivalent matrix. For a more detailed explanation, see http://stackoverflow.com/questions/24678305/converting-a-2d-array-of-2d-arrays-into-a-single-2d-array
public ConvertToMatrix ( ) : Matrix
return Matrix
        public Matrix ConvertToMatrix()
        {
            //Creates a matrix big enough to hold all of the values in the MatricesMatrix
            Matrix returnMatrix = new Matrix(this.TotalRows(), this.TotalColumns());

            int nextRow = 0;
            int nextCol = 0;

            //Loop through the rows of this matrices matrix
            for (int row = 0; row < this.NumberOfRows; row++)
            {
                //Loop through the columns of this matrices matrix
                for (int col = 0; col < this.NumberOfColumns; col++)
                {
                    Matrix currentMatrix = this.GetElement(row, col);
                    returnMatrix.InsertMatrixAt(currentMatrix, nextRow, nextCol);
                    nextCol += this.GetColumnWidth(col); //The next column of the Matrix should be inserted a distance away that is equal to the total width of the current MatricesMatrix column
                }
                nextRow += this.GetRowHeight(row); //The next row of the Matrix should be inserted a distance away that is equal to the total height of the current MatricesMatrix row
                nextCol = 0;
            }

            return returnMatrix;
        }

Usage Example

コード例 #1
0
        public void MatricesMatrix_ConvertToMatrixTest_VariedDistances()
        {
            Matrix m1 = new Matrix(1,1);
            Matrix m2 = new Matrix(2,2);
            Matrix m3 = new Matrix(3,3);
            Matrix m4 = new Matrix(4,4);

            double[] m1Row1 = { 1};

            double[] m2Row1 = { 2, 2 };
            double[] m2Row2 = { 2, 2 };

            double[] m3Row1 = { 3, 3, 3 };
            double[] m3Row2 = { 3, 3, 3 };
            double[] m3Row3 = { 3, 3, 3 };

            double[] m4Row1 = { 4, 4, 4, 4 };
            double[] m4Row2 = { 4, 4, 4, 4 };
            double[] m4Row3 = { 4, 4, 4, 4 };
            double[] m4Row4 = { 4, 4, 4, 4 };


            m1.SetRow(0, m1Row1);

            m2.SetRow(0, m2Row1);
            m2.SetRow(1, m2Row2);

            m3.SetRow(0, m3Row1);
            m3.SetRow(1, m3Row2);
            m3.SetRow(2, m3Row3);

            m4.SetRow(0, m4Row1);
            m4.SetRow(1, m4Row2);
            m4.SetRow(2, m4Row3);
            m4.SetRow(3, m4Row4);

            MatricesMatrix testMatricesMatrix = new MatricesMatrix(2, 2);

            testMatricesMatrix.SetElement(0, 0, m1);
            testMatricesMatrix.SetElement(0, 1, m3);
            testMatricesMatrix.SetElement(1, 0, m2);
            testMatricesMatrix.SetElement(1, 1, m4);

            Matrix expectedResult = new Matrix(7, 6);

            double[] expectedRow1 = { 1, 0, 3, 3, 3, 0 };
            double[] expectedRow2 = { 0, 0, 3, 3, 3, 0 };
            double[] expectedRow3 = { 0, 0, 3, 3, 3, 0 };
            double[] expectedRow4 = { 2, 2, 4, 4, 4, 4 };
            double[] expectedRow5 = { 2, 2, 4, 4, 4, 4 };
            double[] expectedRow6 = { 0, 0, 4, 4, 4, 4 };
            double[] expectedRow7 = { 0, 0, 4, 4, 4, 4 };

            expectedResult.SetRow(0, expectedRow1);
            expectedResult.SetRow(1, expectedRow2);
            expectedResult.SetRow(2, expectedRow3);
            expectedResult.SetRow(3, expectedRow4);
            expectedResult.SetRow(4, expectedRow5);
            expectedResult.SetRow(5, expectedRow6);
            expectedResult.SetRow(6, expectedRow7);


            Matrix actualResult = testMatricesMatrix.ConvertToMatrix();

            (actualResult == expectedResult).Should().BeTrue();

        }
All Usage Examples Of GeometryClassLibrary.MatricesMatrix::ConvertToMatrix