Exemplo n.º 1
0
//=========================================================================================
bool Matrix::AssignInverse( const Matrix& matrix, InverseType inverseType, InverseResult& inverseResult )
{
	// TODO: Calculate left and right inverse matrices for non-square matrices.

	inverseResult = NONSINGULAR_MATRIX;

	Scalar scalar;
	if( !matrix.AssignDeterminantTo( scalar ) )
		return false;

	if( scalar == 0.0 )
	{
		inverseResult = SINGULAR_MATRIX;
		return true;
	}

	if( !scalar.Invert() )
		return false;

	if( matrix.rows == 1 && matrix.cols == 1 )
	{
		if( !AssignDimensions( 1, 1 ) )
			return false;

		if( !AssignScalarFrom( 0, 0, scalar ) )
			return false;
	}
	else if( matrix.rows == matrix.cols )
	{
		if( !AssignAdjugate( matrix ) )
			return false;

		if( !Scale( scalar ) )
			return false;
	}
	else if( matrix.rows > matrix.cols )
		return false;		// TODO: Deal with this case.
	else if( matrix.rows < matrix.cols )
		return false;		// TODO: Deal with this case.

	return true;
}