com.io7m.jtensors

## Class MatrixM2x2D

- java.lang.Object
- - com.io7m.jtensors.MatrixM2x2D

- All Implemented Interfaces:
    MatrixReadable2x2DType, MatrixReadableDType

      public class MatrixM2x2D
      extends Object
      implements MatrixReadable2x2DType

  A 2x2 mutable matrix type with double precision elements.

  Values of type `MatrixM2x2D` are backed by direct memory, with the rows and columns of the matrices being stored in column-major format. This allows the matrices to be passed to OpenGL directly, without requiring transposition.

  Values of this type cannot be accessed safely from multiple threads without explicit synchronization.

  See "Mathematics for 3D Game Programming and Computer Graphics" 2nd Ed for the derivations of most of the code in this class (ISBN: 1-58450-277-0).

  See Elementary operations for the three elementary operations defined on matrices.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MatrixM2x2D()` Construct a new matrix, initialized to the identity matrix.
    `MatrixM2x2D(MatrixReadable2x2DType source)` Construct a new copy of the given matrix.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static MatrixM2x2D` | `add(MatrixReadable2x2DType m0, MatrixReadable2x2DType m1, MatrixM2x2D out)` Elementwise add of matrices `m0` and `m1`.
    `static MatrixM2x2D` | `addInPlace(MatrixM2x2D m0, MatrixReadable2x2DType m1)` Elementwise add of matrices `m0` and `m1`, returning the result in `m0`.
    `static MatrixM2x2D` | `addRowScaled(MatrixM2x2D m, int row_a, int row_b, int row_c, double r)` Add the values in row `row_b` to the values in row `row_a` scaled by `r`, saving the resulting row in row `row_c` of the matrix `m`.
    `static MatrixM2x2D` | `addRowScaled(MatrixReadable2x2DType m, int row_a, int row_b, int row_c, double r, MatrixM2x2D out)` Add the values in row `row_b` to the values in row `row_a` scaled by `r`, saving the resulting row in row `row_c` of the matrix `out`.
    `static MatrixM2x2D` | `copy(MatrixReadable2x2DType input, MatrixM2x2D output)` Copy the contents of the matrix `input` to the matrix `output`, completely replacing all elements.
    `static double` | `determinant(MatrixReadable2x2DType m)` Calculate the determinant of the matrix `m`.
    `static DoubleBuffer` | `doubleBuffer(MatrixM2x2D m)` Return a view of the buffer that backs this matrix.
    `boolean` | `equals(Object obj)`
    `static MatrixM2x2D` | `exchangeRows(MatrixM2x2D m, int row_a, int row_b)` Exchange two rows `row_a` and row `row_b` of the matrix `m`, saving the exchanged rows to `m` .
    `static MatrixM2x2D` | `exchangeRows(MatrixReadable2x2DType m, int row_a, int row_b, MatrixM2x2D out)` Exchange two rows `row_a` and row `row_b` of the matrix `m`, saving the exchanged rows to `out` .
    `double` | `get(int row, int column)`
    `static double` | `get(MatrixReadable2x2DType m, int row, int column)` Retrieve the value from the matrix `m` at row `row` , column `column`.
    `DoubleBuffer` | `getDoubleBuffer()`
    `void` | `getRow2D(int row, VectorM2D out)` Retrieve row `row`, saving the result to `out`.
    `double` | `getRowColumnD(int row, int column)`
    `int` | `hashCode()`
    `static com.io7m.jfunctional.OptionType<MatrixM2x2D>` | `invert(MatrixReadable2x2DType m, MatrixM2x2D out)` Calculate the inverse of the matrix `m`, saving the resulting matrix to `out`.
    `static com.io7m.jfunctional.OptionType<MatrixM2x2D>` | `invertInPlace(MatrixM2x2D m)` Calculate the inverse of the matrix `m`, saving the resulting matrix to `m`.
    `static MatrixM2x2D` | `multiply(MatrixM2x2D m0, MatrixReadable2x2DType m1)` Multiply the matrix `m0` with the matrix `m1`, writing the result to `m0`.
    `static MatrixM2x2D` | `multiply(MatrixReadable2x2DType m0, MatrixReadable2x2DType m1, MatrixM2x2D out)` Multiply the matrix `m0` with the matrix `m1`, writing the result to `out`.
    `static VectorM2D` | `multiplyVector2D(MatrixReadable2x2DType m, VectorReadable2DType v, VectorM2D out)` Multiply the matrix `m` with the vector `v`, writing the resulting vector to `out`.
    `static VectorM2D` | `row(MatrixReadable2x2DType m, int row, VectorM2D out)` Return row `row` of the matrix `m` in the vector `out`.
    `static MatrixM2x2D` | `scale(MatrixM2x2D m, double r)` Scale all elements of the matrix `m` by the scaling value `r`, saving the result in `m`.
    `static MatrixM2x2D` | `scale(MatrixReadable2x2DType m, double r, MatrixM2x2D out)` Scale all elements of the matrix `m` by the scaling value `r`, saving the result in `out`.
    `static MatrixM2x2D` | `scaleRow(MatrixM2x2D m, int row, double r)` Scale row `r` of the matrix `m` by `r`, saving the result to row `r` of `m`.
    `static MatrixM2x2D` | `scaleRow(MatrixReadable2x2DType m, int row, double r, MatrixM2x2D out)` Scale row `r` of the matrix `m` by `r`, saving the result to row `r` of `out`.
    `MatrixM2x2D` | `set(int row, int column, double value)`
    `static MatrixM2x2D` | `set(MatrixM2x2D m, int row, int column, double value)` Set the value in the matrix `m` at row `row`, column `column` to `value`.
    `static MatrixM2x2D` | `setIdentity(MatrixM2x2D m)` Set the given matrix `m` to the identity matrix.
    `static MatrixM2x2D` | `setZero(MatrixM2x2D m)` Set the given matrix `m` to the zero matrix.
    `String` | `toString()`
    `static double` | `trace(MatrixReadable2x2DType m)` Return the trace of the matrix `m`.
    `static MatrixM2x2D` | `transpose(MatrixM2x2D m)` Transpose the given matrix `m`, writing the resulting matrix to `m`.
    `static MatrixM2x2D` | `transpose(MatrixReadable2x2DType m, MatrixM2x2D out)` Transpose the given matrix `m`, writing the resulting matrix to `out`.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### MatrixM2x2D

          public MatrixM2x2D()

      Construct a new matrix, initialized to the identity matrix.

    - #### MatrixM2x2D

          public MatrixM2x2D(MatrixReadable2x2DType source)

      Construct a new copy of the given matrix.
      Parameters:
        `source` - The source matrix.

  - ### Method Detail

    - #### add

          public static final MatrixM2x2D add(MatrixReadable2x2DType m0,
                                              MatrixReadable2x2DType m1,
                                              MatrixM2x2D out)

      Elementwise add of matrices `m0` and `m1`.
      Parameters:
        `m0` - The left input matrix.
        `m1` - The right input matrix.
        `out` - The output matrix.
      Returns:
        `out`

    - #### addInPlace

          public static final MatrixM2x2D addInPlace(MatrixM2x2D m0,
                                                     MatrixReadable2x2DType m1)

      Elementwise add of matrices `m0` and `m1`, returning the result in `m0`.
      Parameters:
        `m0` - The left input matrix.
        `m1` - The right input matrix.
      Returns:
        `m0`

    - #### addRowScaled

          public static final MatrixM2x2D addRowScaled(MatrixM2x2D m,
                                                       int row_a,
                                                       int row_b,
                                                       int row_c,
                                                       double r)

      Add the values in row `row_b` to the values in row `row_a` scaled by `r`, saving the resulting row in row `row_c` of the matrix `m`.

      This is one of the three elementary operations defined on matrices.

      Parameters:
        `m` - The input matrix.
        `row_a` - The row on the lefthand side of the addition.
        `row_b` - The row on the righthand side of the addition.
        `row_c` - The destination row.
        `r` - The scaling value.
      Returns:
        `m`

    - #### addRowScaled

          public static final MatrixM2x2D addRowScaled(MatrixReadable2x2DType m,
                                                       int row_a,
                                                       int row_b,
                                                       int row_c,
                                                       double r,
                                                       MatrixM2x2D out)

      Add the values in row `row_b` to the values in row `row_a` scaled by `r`, saving the resulting row in row `row_c` of the matrix `out`.

      This is one of the three elementary operations defined on matrices.

      Parameters:
        `m` - The input matrix.
        `row_a` - The row on the lefthand side of the addition.
        `row_b` - The row on the righthand side of the addition.
        `row_c` - The destination row.
        `r` - The scaling value.
        `out` - The output matrix.
      Returns:
        `out`

    - #### copy

          public static final MatrixM2x2D copy(MatrixReadable2x2DType input,
                                               MatrixM2x2D output)

      Copy the contents of the matrix `input` to the matrix `output`, completely replacing all elements.
      Parameters:
        `input` - The input vector.
        `output` - The output vector.
      Returns:
        `output`

    - #### determinant

          public static final double determinant(MatrixReadable2x2DType m)

      Calculate the determinant of the matrix `m`.
      Parameters:
        `m` - The input matrix.
      Returns:
        The determinant.

    - #### doubleBuffer

          public static final DoubleBuffer doubleBuffer(MatrixM2x2D m)

      Return a view of the buffer that backs this matrix.
      Parameters:
        `m` - The input matrix.
      Returns:
        The buffer that backs the matrix.

    - #### exchangeRows

          public static final MatrixM2x2D exchangeRows(MatrixM2x2D m,
                                                       int row_a,
                                                       int row_b)

      Exchange two rows `row_a` and row `row_b` of the matrix `m`, saving the exchanged rows to `m` .

      This is one of the three elementary operations defined on matrices.

      Parameters:
        `m` - The input matrix.
        `row_a` - The first row.
        `row_b` - The second row.
      Returns:
        `m`

    - #### exchangeRows

          public static final MatrixM2x2D exchangeRows(MatrixReadable2x2DType m,
                                                       int row_a,
                                                       int row_b,
                                                       MatrixM2x2D out)

      Exchange two rows `row_a` and row `row_b` of the matrix `m`, saving the exchanged rows to `out` .

      This is one of the three elementary operations defined on matrices.

      Parameters:
        `m` - The input matrix.
        `row_a` - The first row.
        `row_b` - The second row.
        `out` - The output matrix.
      Returns:
        `out`

    - #### get

          public static final double get(MatrixReadable2x2DType m,
                                         int row,
                                         int column)

      Retrieve the value from the matrix `m` at row `row` , column `column`.
      Parameters:
        `row` - The row.
        `column` - The column.
        `m` - The matrix.
      Returns:
        The value at the given row and column.

    - #### invert

          public static final com.io7m.jfunctional.OptionType<MatrixM2x2D> invert(MatrixReadable2x2DType m,
                                                                                  MatrixM2x2D out)

      Calculate the inverse of the matrix `m`, saving the resulting matrix to `out`. The function returns `Some(out)` iff it was possible to invert the matrix, and `None` otherwise. It is not possible to invert a matrix that has a determinant of `0`. If the function returns `None`, `m` is untouched.
      Parameters:
        `m` - The input matrix.
        `out` - The output matrix.
      Returns:
        The inverion of `m`, if any.
      See Also:
        `determinant(MatrixReadable2x2DType)`

    - #### invertInPlace

          public static final com.io7m.jfunctional.OptionType<MatrixM2x2D> invertInPlace(MatrixM2x2D m)

      Calculate the inverse of the matrix `m`, saving the resulting matrix to `m`. The function returns `Some(m)` iff it was possible to invert the matrix, and `None` otherwise. It is not possible to invert a matrix that has a determinant of `0`. If the function returns `None`, `m` is untouched.
      Parameters:
        `m` - The input matrix.
      Returns:
        The inverion of `m`, if any.
      See Also:
        `determinant(MatrixReadable2x2DType)`

    - #### multiply

          public static final MatrixM2x2D multiply(MatrixM2x2D m0,
                                                   MatrixReadable2x2DType m1)

      Multiply the matrix `m0` with the matrix `m1`, writing the result to `m0`.
      Parameters:
        `m0` - The left input matrix.
        `m1` - The right input matrix.
      Returns:
        `out`

    - #### multiply

          public static final MatrixM2x2D multiply(MatrixReadable2x2DType m0,
                                                   MatrixReadable2x2DType m1,
                                                   MatrixM2x2D out)

      Multiply the matrix `m0` with the matrix `m1`, writing the result to `out`.
      Parameters:
        `m0` - The left input matrix.
        `m1` - The right input matrix.
        `out` - The output matrix.
      Returns:
        `out`

    - #### multiplyVector2D

          public static final VectorM2D multiplyVector2D(MatrixReadable2x2DType m,
                                                         VectorReadable2DType v,
                                                         VectorM2D out)

      Multiply the matrix `m` with the vector `v`, writing the resulting vector to `out`.
      Parameters:
        `m` - The input matrix.
        `v` - The input vector.
        `out` - The output vector.
      Returns:
        `out`

    - #### row

          public static final VectorM2D row(MatrixReadable2x2DType m,
                                            int row,
                                            VectorM2D out)

      Return row `row` of the matrix `m` in the vector `out`.
      Parameters:
        `row` - The row.
        `out` - The output vector.
        `m` - The matrix.
      Returns:
        The row.

    - #### scale

          public static final MatrixM2x2D scale(MatrixM2x2D m,
                                                double r)

      Scale all elements of the matrix `m` by the scaling value `r`, saving the result in `m`.
      Parameters:
        `m` - The input matrix.
        `r` - The scaling value.
      Returns:
        `m`

    - #### scale

          public static final MatrixM2x2D scale(MatrixReadable2x2DType m,
                                                double r,
                                                MatrixM2x2D out)

      Scale all elements of the matrix `m` by the scaling value `r`, saving the result in `out`.
      Parameters:
        `m` - The input matrix.
        `r` - The scaling value.
        `out` - The output row.
      Returns:
        `m`

    - #### scaleRow

          public static final MatrixM2x2D scaleRow(MatrixM2x2D m,
                                                   int row,
                                                   double r)

      Scale row `r` of the matrix `m` by `r`, saving the result to row `r` of `m`.

      This is one of the three elementary operations defined on matrices.

      Parameters:
        `m` - The input matrix.
        `row` - The index of the row `(0 <= row < 4)`.
        `r` - The scaling value.
      Returns:
        `out`

    - #### scaleRow

          public static final MatrixM2x2D scaleRow(MatrixReadable2x2DType m,
                                                   int row,
                                                   double r,
                                                   MatrixM2x2D out)

      Scale row `r` of the matrix `m` by `r`, saving the result to row `r` of `out`.

      This is one of the three elementary operations defined on matrices.

      Parameters:
        `m` - The input matrix.
        `row` - The index of the row `(0 <= row < 4)`.
        `r` - The scaling value.
        `out` - The output matrix.
      Returns:
        `out`

    - #### set

          public static final MatrixM2x2D set(MatrixM2x2D m,
                                              int row,
                                              int column,
                                              double value)

      Set the value in the matrix `m` at row `row`, column `column` to `value`.
      Parameters:
        `m` - The input matrix
        `row` - The row
        `column` - The column
        `value` - The value
      Returns:
        m

    - #### setIdentity

          public static final MatrixM2x2D setIdentity(MatrixM2x2D m)

      Set the given matrix `m` to the identity matrix.
      Parameters:
        `m` - The matrix
      Returns:
        `m`

    - #### setZero

          public static final MatrixM2x2D setZero(MatrixM2x2D m)

      Set the given matrix `m` to the zero matrix.
      Parameters:
        `m` - The matrix
      Returns:
        `m`

    - #### trace

          public static final double trace(MatrixReadable2x2DType m)

      Return the trace of the matrix `m`. The trace is defined as the sum of the diagonal elements of the matrix.
      Parameters:
        `m` - The input matrix
      Returns:
        The trace of the matrix
      Since:
        5.0.0

    - #### transpose

          public static final MatrixM2x2D transpose(MatrixM2x2D m)

      Transpose the given matrix `m`, writing the resulting matrix to `m`.
      Parameters:
        `m` - The input matrix.
      Returns:
        `m`

    - #### transpose

          public static final MatrixM2x2D transpose(MatrixReadable2x2DType m,
                                                    MatrixM2x2D out)

      Transpose the given matrix `m`, writing the resulting matrix to `out`.
      Parameters:
        `m` - The input matrix.
        `out` - The output matrix.
      Returns:
        `out`

    - #### equals

          public final boolean equals(@Nullable
                                      Object obj)

      Overrides:
        `equals` in class `Object`

    - #### get

          public final double get(int row,
                                  int column)

      Parameters:
        `row` - The row.
        `column` - The column.
      Returns:
        The value at the given row and column.

    - #### getDoubleBuffer

          public final DoubleBuffer getDoubleBuffer()

      Specified by:
        `getDoubleBuffer` in interface `MatrixReadableDType`
      Returns:
        A view of the buffer that backs this matrix.

    - #### getRow2D

          public final void getRow2D(int row,
                                     VectorM2D out)

      Description copied from interface: `MatrixReadable2x2DType`
      Retrieve row `row`, saving the result to `out`.
      Specified by:
        `getRow2D` in interface `MatrixReadable2x2DType`
      Parameters:
        `row` - The index of the row, starting at `0`.
        `out` - The output vector.

    - #### getRowColumnD

          public final double getRowColumnD(int row,
                                            int column)

      Specified by:
        `getRowColumnD` in interface `MatrixReadableDType`
      Parameters:
        `row` - The row
        `column` - The column
      Returns:
        The value from the matrix at row `row` , column `column`.

    - #### hashCode

          public final int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### set

          public final MatrixM2x2D set(int row,
                                       int column,
                                       double value)

      Parameters:
        `row` - The row.
        `column` - The column.
        `value` - The value.
      Returns:
        Set the value at the given row and column.

    - #### toString

          public final String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2015 <code@io7m.com> http://io7m.com