/// <summary> /// Subtracts a matrix from a matrix and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="MatrixF"/> instance to subtract from.</param> /// <param name="b">A <see cref="MatrixF"/> instance to subtract.</param> /// <param name="result">A <see cref="MatrixF"/> instance to hold the result.</param> /// <remarks>result[x][y] = a[x][y] - b[x][y]</remarks> /// <exception cref="System.ArgumentException">Matrix dimentions do not match.</exception> public static void Subtract(MatrixF a, MatrixF b, MatrixF result) { if ((!MatrixF.EqualDimentions(a,b)) && (!MatrixF.EqualDimentions(a,result))) { throw new ArgumentException("Matrix dimentions do not match."); } for(int r = 0; r < a.Rows; r++) { for(int c = 0; c < a.Columns; c++) { result._data[r][c] = a._data[r][c] - b._data[r][c]; } } }
/// <summary> /// Returns a value indicating whether this instance is equal to /// the specified object. /// </summary> /// <param name="obj">An object to compare to this instance.</param> /// <returns><see langword="true"/> if <paramref name="obj"/> is a <see cref="MatrixF"/> and has the same values as this instance; otherwise, <see langword="false"/>.</returns> public override bool Equals(object obj) { if (obj is MatrixF) { MatrixF m = (MatrixF)obj; for (int i = 0; i < m.Rows; i++) { for (int j = 0; j < m.Columns; j++) { if (_data[i][j] != m._data[i][j]) return false; } } return true; } return false; }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="a">A <see cref="MatrixF"/> instance to subtract from.</param> /// <param name="b">A <see cref="MatrixF"/> instance to subtract.</param> /// <returns>A new <see cref="MatrixF"/> instance containing the difference.</returns> /// <remarks>result[x][y] = a[x][y] - b[x][y]</remarks> /// <exception cref="System.ArgumentException">Matrix dimentions do not match.</exception> public static MatrixF Subtract(MatrixF a, MatrixF b) { if (!MatrixF.EqualDimentions(a,b)) { throw new ArgumentException("Matrix dimentions do not match."); } MatrixF result = new MatrixF(a.Rows, a.Columns); for(int r = 0; r < a.Rows; r++) { for(int c = 0; c < a.Columns; c++) { result._data[r][c] = a._data[r][c] - b._data[r][c]; } } return result; }
/// <summary> /// Initializes a new instance of the <see cref="MatrixF"/> using a given matrix. /// </summary> /// <param name="matrix">A <see cref="MatrixF"/> instance.</param> public MatrixF(MatrixF matrix) { _rows = matrix._rows; _columns= matrix._columns; _data = (float[][])matrix._data.Clone(); }
/// <summary> /// Multiplies a matrix by a scalar. /// </summary> /// <param name="m">A <see cref="MatrixF"/> instance.</param> /// <param name="s">A single-precision floating point value.</param> /// <returns>A new <see cref="MatrixF"/> instance containing the result.</returns> public static MatrixF operator*(float s, MatrixF m) { return MatrixF.Multiply(m,s); }
/// <summary> /// Adds two matrices. /// </summary> /// <param name="a">A <see cref="MatrixF"/> instance.</param> /// <param name="b">A <see cref="MatrixF"/> instance.</param> /// <returns>A new <see cref="MatrixF"/> instance containing the sum.</returns> public static MatrixF operator+(MatrixF a, MatrixF b) { return MatrixF.Add(a,b); }
/// <summary> /// Negates the values of a matrix. /// </summary> /// <param name="m">A <see cref="MatrixF"/> instance.</param> /// <returns>A new <see cref="MatrixF"/> instance containing the result.</returns> public static MatrixF operator-(MatrixF m) { return MatrixF.Negate(m); }