Example #1
0
        /// <summary>
        ///     Calculates the sub <see cref="IMatrix" /> of the current <see cref="IMatrix" /> by removing the specified column
        ///     and row.
        /// </summary>
        /// <param name="matrix">The <see cref="ISquareMatrix" />.</param>
        /// <param name="row">The row that should be removed.</param>
        /// <param name="column">The column that should be removed.</param>
        /// <returns>The calculated sub <see cref="ISquareMatrix" />.</returns>
        public static ISquareMatrix GetSubMatrix(this ISquareMatrix matrix, uint row, uint column)
        {
            ISquareMatrix resultMatrix;

            switch (matrix.Dimension)
            {
            case 2:
                resultMatrix = new Matrix1x1();
                break;

            case 3:
                resultMatrix = new Matrix2x2();
                break;

            case 4:
                resultMatrix = new Matrix3x3();
                break;

            default:
                throw new InvalidOperationException("Cannot build sub matrix of " + nameof(matrix) +
                                                    " as there is no lower dimension defined for it.");
            }

            uint y = 0;

            for (uint cy = 0; cy < matrix.RowCount; cy++)
            {
                if (cy != row)
                {
                    uint x = 0;
                    for (uint cx = 0; cx < matrix.ColumnCount; ++cx)
                    {
                        if (cx != column)
                        {
                            resultMatrix[y, x] = matrix[cy, cx];
                            x++;
                        }
                    }

                    y++;
                }
            }

            return(resultMatrix);
        }
Example #2
0
 public bool Equals(Matrix1x1 other)
 {
     return(this == other);
 }