com.io7m.jtensors

## Class MatrixM2x2F

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

- All Implemented Interfaces:
    MatrixReadable2x2FType, MatrixReadableFType

      public class MatrixM2x2F
      extends Object
      implements MatrixReadable2x2FType

  A 2x2 mutable matrix type with single precision elements.

  Values of type `MatrixM2x2F` 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
    `MatrixM2x2F()` Construct a new identity matrix.
    `MatrixM2x2F(MatrixReadable2x2FType source)` Construct a new matrix from the given source matrix.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static MatrixM2x2F` | `add(MatrixReadable2x2FType m0, MatrixReadable2x2FType m1, MatrixM2x2F out)` Elementwise add of matrices `m0` and `m1`.
    `static MatrixM2x2F` | `addInPlace(MatrixM2x2F m0, MatrixReadable2x2FType m1)` Elementwise add of matrices `m0` and `m1`, returning the result in `m0`.
    `static MatrixM2x2F` | `addRowScaled(MatrixReadable2x2FType m, int row_a, int row_b, int row_c, float r, MatrixM2x2F 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 MatrixM2x2F` | `addRowScaledInPlace(MatrixM2x2F m, int row_a, int row_b, int row_c, float 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 MatrixM2x2F` | `copy(MatrixReadable2x2FType input, MatrixM2x2F output)` Copy the contents of the matrix `input` to the matrix `output`, completely replacing all elements.
    `static float` | `determinant(MatrixReadable2x2FType m)` Calculate the determinant of the matrix `m`.
    `boolean` | `equals(Object obj)`
    `static MatrixM2x2F` | `exchangeRows(MatrixReadable2x2FType m, int row_a, int row_b, MatrixM2x2F out)` Exchange two rows `row_a` and row `row_b` of the matrix `m`, saving the exchanged rows to `out`.
    `static MatrixM2x2F` | `exchangeRowsInPlace(MatrixM2x2F 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 FloatBuffer` | `floatBuffer(MatrixM2x2F m)`
    `float` | `get(int row, int column)`
    `static float` | `get(MatrixReadable2x2FType m, int row, int column)`
    `FloatBuffer` | `getFloatBuffer()`
    `void` | `getRow2F(int row, VectorM2F out)` Retrieve row `row`, saving the result to `out`.
    `float` | `getRowColumnF(int row, int column)`
    `int` | `hashCode()`
    `static com.io7m.jfunctional.OptionType<MatrixM2x2F>` | `invert(MatrixReadable2x2FType m, MatrixM2x2F out)` Calculate the inverse of the matrix `m`, saving the resulting matrix to `out`.
    `static com.io7m.jfunctional.OptionType<MatrixM2x2F>` | `invertInPlace(MatrixM2x2F m)` Calculate the inverse of the matrix `m`, saving the resulting matrix to `m`.
    `static MatrixM2x2F` | `multiply(MatrixM2x2F m0, MatrixReadable2x2FType m1)` Multiply the matrix `m0` with the matrix `m1`, writing the result to `m0`.
    `static MatrixM2x2F` | `multiply(MatrixReadable2x2FType m0, MatrixReadable2x2FType m1, MatrixM2x2F out)` Multiply the matrix `m0` with the matrix `m1`, writing the result to `out`.
    `static VectorM2F` | `multiplyVector2F(MatrixReadable2x2FType m, VectorReadable2FType v, VectorM2F out)` Multiply the matrix `m` with the vector `v`, writing the resulting vector to `out`.
    `static VectorM2F` | `row(MatrixReadable2x2FType m, int row, VectorM2F out)`
    `static MatrixM2x2F` | `scale(MatrixM2x2F m, float r)` Scale all elements of the matrix `m` by the scaling value `r`, saving the result in `m`.
    `static MatrixM2x2F` | `scale(MatrixReadable2x2FType m, float r, MatrixM2x2F out)` Scale all elements of the matrix `m` by the scaling value `r`, saving the result in `out`.
    `static MatrixM2x2F` | `scaleRow(MatrixM2x2F m, int row, float r)` Scale row `r` of the matrix `m` by `r`, saving the result to row `r` of `m`.
    `static MatrixM2x2F` | `scaleRow(MatrixReadable2x2FType m, int row, float r, MatrixM2x2F out)` Scale row `r` of the matrix `m` by `r`, saving the result to row `r` of `out`.
    `MatrixM2x2F` | `set(int row, int column, float value)`
    `static MatrixM2x2F` | `set(MatrixM2x2F m, int row, int column, float value)` Set the value in the matrix `m` at row `row`, column `column` to `value`.
    `static MatrixM2x2F` | `setIdentity(MatrixM2x2F m)` Set the given matrix `m` to the identity matrix.
    `static MatrixM2x2F` | `setZero(MatrixM2x2F m)` Set the given matrix `m` to the zero matrix.
    `String` | `toString()`
    `static float` | `trace(MatrixReadable2x2FType m)` Return the trace of the matrix `m`.
    `static MatrixM2x2F` | `transpose(MatrixM2x2F m)` Transpose the given matrix `m`, writing the resulting matrix to `m`.
    `static MatrixM2x2F` | `transpose(MatrixReadable2x2FType m, MatrixM2x2F 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

    - #### MatrixM2x2F

          public MatrixM2x2F()

      Construct a new identity matrix.

    - #### MatrixM2x2F

          public MatrixM2x2F(MatrixReadable2x2FType source)

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

  - ### Method Detail

    - #### add

          public static final MatrixM2x2F add(MatrixReadable2x2FType m0,
                                              MatrixReadable2x2FType m1,
                                              MatrixM2x2F 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 MatrixM2x2F addInPlace(MatrixM2x2F m0,
                                                     MatrixReadable2x2FType 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`
      Since:
        5.0.0

    - #### addRowScaled

          public static final MatrixM2x2F addRowScaled(MatrixReadable2x2FType m,
                                                       int row_a,
                                                       int row_b,
                                                       int row_c,
                                                       float r,
                                                       MatrixM2x2F 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`

    - #### addRowScaledInPlace

          public static final MatrixM2x2F addRowScaledInPlace(MatrixM2x2F m,
                                                              int row_a,
                                                              int row_b,
                                                              int row_c,
                                                              float 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`

    - #### copy

          public static final MatrixM2x2F copy(MatrixReadable2x2FType input,
                                               MatrixM2x2F 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 float determinant(MatrixReadable2x2FType m)

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

    - #### exchangeRows

          public static final MatrixM2x2F exchangeRows(MatrixReadable2x2FType m,
                                                       int row_a,
                                                       int row_b,
                                                       MatrixM2x2F 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`

    - #### exchangeRowsInPlace

          public static final MatrixM2x2F exchangeRowsInPlace(MatrixM2x2F 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`

    - #### floatBuffer

          public static final FloatBuffer floatBuffer(MatrixM2x2F m)

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

    - #### get

          public static final float get(MatrixReadable2x2FType m,
                                        int row,
                                        int column)

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

    - #### invert

          public static final com.io7m.jfunctional.OptionType<MatrixM2x2F> invert(MatrixReadable2x2FType m,
                                                                                  MatrixM2x2F 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:
        `out`
      See Also:
        `determinant(MatrixReadable2x2FType)`

    - #### invertInPlace

          public static final com.io7m.jfunctional.OptionType<MatrixM2x2F> invertInPlace(MatrixM2x2F 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:
        `m`
      See Also:
        `determinant(MatrixReadable2x2FType)`

    - #### multiply

          public static final MatrixM2x2F multiply(MatrixM2x2F m0,
                                                   MatrixReadable2x2FType m1)

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

    - #### multiply

          public static final MatrixM2x2F multiply(MatrixReadable2x2FType m0,
                                                   MatrixReadable2x2FType m1,
                                                   MatrixM2x2F 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`

    - #### multiplyVector2F

          public static final VectorM2F multiplyVector2F(MatrixReadable2x2FType m,
                                                         VectorReadable2FType v,
                                                         VectorM2F 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 VectorM2F row(MatrixReadable2x2FType m,
                                            int row,
                                            VectorM2F out)

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

    - #### scale

          public static final MatrixM2x2F scale(MatrixM2x2F m,
                                                float 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 MatrixM2x2F scale(MatrixReadable2x2FType m,
                                                float r,
                                                MatrixM2x2F 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 matrix.
      Returns:
        `out`

    - #### scaleRow

          public static final MatrixM2x2F scaleRow(MatrixM2x2F m,
                                                   int row,
                                                   float 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:
        `m`

    - #### scaleRow

          public static final MatrixM2x2F scaleRow(MatrixReadable2x2FType m,
                                                   int row,
                                                   float r,
                                                   MatrixM2x2F 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 MatrixM2x2F set(MatrixM2x2F m,
                                              int row,
                                              int column,
                                              float value)

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

    - #### setIdentity

          public static final MatrixM2x2F setIdentity(MatrixM2x2F m)

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

    - #### setZero

          public static final MatrixM2x2F setZero(MatrixM2x2F m)

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

    - #### trace

          public static final float trace(MatrixReadable2x2FType 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 MatrixM2x2F transpose(MatrixM2x2F m)

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

    - #### transpose

          public static final MatrixM2x2F transpose(MatrixReadable2x2FType m,
                                                    MatrixM2x2F 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 float get(int row,
                                 int column)

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

    - #### getFloatBuffer

          public final FloatBuffer getFloatBuffer()

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

    - #### getRow2F

          public final void getRow2F(int row,
                                     VectorM2F out)

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

    - #### getRowColumnF

          public final float getRowColumnF(int row,
                                           int column)

      Specified by:
        `getRowColumnF` in interface `MatrixReadableFType`
      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 MatrixM2x2F set(int row,
                                       int column,
                                       float 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