Object
MatrixSIS
Matrix2
All Implemented Interfaces:
Serializable, Cloneable, Lenient­Comparable, Matrix

public class Matrix2 extends MatrixSIS
A matrix of fixed 2×2 size, typically resulting from Math­Transform2D derivative computation. The matrix members are:
 ┌         ┐
 │ m00 m01 │
 │ m10 m11 │
 └         ┘
Since:
0.4
See Also:

Defined in the sis-referencing module

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
    The first matrix element in the first row.
    double
    The second matrix element in the first row.
    double
    The first matrix element in the second row.
    double
    The second matrix element in the second row.
    static final int
    The matrix size, which is 2.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new identity matrix.
    Matrix2(double[] elements)
    Creates a new matrix initialized to the specified values.
    Matrix2(double m00, double m01, double m10, double m11)
    Creates a new matrix initialized to the specified values.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Matrix2
    Casts or copies the given matrix to a Matrix2 implementation.
    Returns a clone of this matrix.
    boolean
    equals(Object object)
    Returns true if the specified object is of type Matrix2 and all of the data members are equal to the corresponding data members in this matrix.
    final double
    get­Element(int row, int column)
    Retrieves the value at the specified row and column of this matrix.
    final double[]
    Returns all matrix elements in a flat, row-major (column indices vary fastest) array.
    final int
    Returns the number of columns in this matrix, which is always 2 in this implementation.
    final int
    Returns the number of rows in this matrix, which is always 2 in this implementation.
    int
    Returns a hash code value based on the data values in this object.
    final boolean
    Returns true if this matrix represents an affine transform.
    final boolean
    Returns true if this matrix is an identity matrix.
    final void
    set­Element(int row, int column, double value)
    Modifies the value at the specified row and column of this matrix.
    final void
    set­Elements(double[] elements)
    Sets all matrix elements from a flat, row-major (column indices vary fastest) array.
    void
    Sets the value of this matrix to its transpose.

    Methods inherited from class Object

    finalize, get­Class, notify, notify­All, wait, wait, wait
  • Field Details

    • SIZE

      public static final int SIZE
      The matrix size, which is 2.
      See Also:
    • m00

      public double m00
      The first matrix element in the first row.
    • m01

      public double m01
      The second matrix element in the first row.
    • m10

      public double m10
      The first matrix element in the second row.
    • m11

      public double m11
      The second matrix element in the second row.
  • Constructor Details

    • Matrix2

      public Matrix2()
      Creates a new identity matrix.
    • Matrix2

      public Matrix2(double m00, double m01, double m10, double m11)
      Creates a new matrix initialized to the specified values.
      Parameters:
      m00 - the first matrix element in the first row.
      m01 - the second matrix element in the first row.
      m10 - the first matrix element in the second row.
      m11 - the second matrix element in the second row.
    • Matrix2

      public Matrix2(double[] elements) throws IllegalArgumentException
      Creates a new matrix initialized to the specified values. The length of the given array must be 4 and the values in the same order than the above constructor.
      Parameters:
      elements - elements of the matrix. Column indices vary fastest.
      Throws:
      Illegal­Argument­Exception - if the given array does not have the expected length.
      See Also:
  • Method Details

    • castOrCopy

      public static Matrix2 castOrCopy(Matrix matrix) throws MismatchedMatrixSizeException
      Casts or copies the given matrix to a Matrix2 implementation. If the given matrix is already an instance of Matrix2, then it is returned unchanged. Otherwise this method verifies the matrix size, then copies all elements in a new Matrix2 object.
      Parameters:
      matrix - the matrix to cast or copy, or null.
      Returns:
      the matrix argument if it can be safely casted (including null argument), or a copy of the given matrix otherwise.
      Throws:
      Mismatched­Matrix­Size­Exception - if the size of the given matrix is not 2×2.
    • getNumRow

      public final int getNumRow()
      Returns the number of rows in this matrix, which is always 2 in this implementation.
      Returns:
      always 2.
    • getNumCol

      public final int getNumCol()
      Returns the number of columns in this matrix, which is always 2 in this implementation.
      Returns:
      always 2.
    • getElement

      public final double getElement(int row, int column)
      Retrieves the value at the specified row and column of this matrix. This method can be invoked when the matrix size or type is unknown. If the matrix is known to be an instance of Matrix2, then the m00m11 fields can be read directly for efficiency.
      Specified by:
      get­Element in interface Matrix
      Specified by:
      get­Element in class Matrix­SIS
      Parameters:
      row - the row index, which can only be 0 or 1.
      column - the column index, which can only be 0 or 1.
      Returns:
      the current value at the given row and column.
    • setElement

      public final void setElement(int row, int column, double value)
      Modifies the value at the specified row and column of this matrix. This method can be invoked when the matrix size or type is unknown. If the matrix is known to be an instance of Matrix2, then the m00m11 fields can be set directly for efficiency.
      Parameters:
      row - the row index, which can only be 0 or 1.
      column - the column index, which can only be 0 or 1.
      value - the new value to set at the given row and column.
    • getElements

      public final double[] getElements()
      Returns all matrix elements in a flat, row-major (column indices vary fastest) array. The array length is 4.
      Overrides:
      get­Elements in class Matrix­SIS
      Returns:
      a copy of all current matrix elements in a row-major array.
    • setElements

      public final void setElements(double[] elements)
      Sets all matrix elements from a flat, row-major (column indices vary fastest) array. The array length shall be 4.
      Specified by:
      set­Elements in class Matrix­SIS
      Parameters:
      elements - The new matrix elements in a row-major array.
      See Also:
    • isAffine

      public final boolean isAffine()
      Returns true if this matrix represents an affine transform. A transform is affine if the matrix is square and its last row contains only zeros, except in the last column which contains 1.
      Overrides:
      is­Affine in class Matrix­SIS
      Returns:
      true if this matrix represents an affine transform.
      See Also:
    • isIdentity

      public final boolean isIdentity()
      Returns true if this matrix is an identity matrix. This method is equivalent to the following code, except that it is potentially more efficient:
      return Matrices.isIdentity(this, 0.0);
      Specified by:
      is­Identity in interface Matrix
      Specified by:
      is­Identity in class Matrix­SIS
      Returns:
      true if this matrix is an identity matrix.
      See Also:
    • transpose

      public void transpose()
      Sets the value of this matrix to its transpose.
      Specified by:
      transpose in class Matrix­SIS
    • clone

      public Matrix2 clone()
      Returns a clone of this matrix.
      Specified by:
      clone in interface Matrix
      Overrides:
      clone in class Matrix­SIS
      Returns:
      a new matrix of the same class and with the same values than this matrix.
      See Also:
    • equals

      public boolean equals(Object object)
      Returns true if the specified object is of type Matrix2 and all of the data members are equal to the corresponding data members in this matrix.
      Specified by:
      equals in interface Lenient­Comparable
      Overrides:
      equals in class Matrix­SIS
      Parameters:
      object - the object to compare with this matrix for equality.
      Returns:
      true if the given object is equal to this matrix.
      See Also:
    • hashCode

      public int hashCode()
      Returns a hash code value based on the data values in this object.
      Overrides:
      hash­Code in class Matrix­SIS
      Returns:
      a hash code value for this matrix.