Matrix2x2

public struct Matrix2x2<Scalar> : SquareMatrixType, CustomStringConvertible where Scalar : DivisibleArithmetic, Scalar : Real

Plain 2-row 2-column Matrix with real components.

  • Returns a 2x2 identity matrix.

    Declaration

    Swift

    public static var identity: `Self` { get }
  • M

    The full type of this matrix’s backing, as a tuple of columns.

    Declaration

    Swift

    public typealias M = (Row, Row)
  • Row

    The type of this matrix’s row.

    Declaration

    Swift

    public typealias Row = (Scalar, Scalar)
  • The type of this matrix’s column.

    Declaration

    Swift

    public typealias Column = (Scalar, Scalar)
  • m

    Gets or sets all coefficients of this matrix as a single 2x2 tuple.

    Declaration

    Swift

    public var m: M
  • r0

    The first row of this matrix

    Equivalent to self.m.0.

    Declaration

    Swift

    public var r0: Row { get set }
  • r1

    The second row of this matrix

    Equivalent to self.m.1.

    Declaration

    Swift

    public var r1: Row { get set }
  • c0

    The first column of this matrix

    Equivalent to (self.r0.0, self.r1.0).

    Declaration

    Swift

    public var c0: Column { get set }
  • c1

    The second column of this matrix

    Equivalent to (self.r0.1, self.r1.1).

    Declaration

    Swift

    public var c1: Column { get set }
  • Gets the first row of this matrix in a Vector2.

    Declaration

    Swift

    public var r0Vec: Vector2<Scalar> { get }
  • Gets the second row of this matrix in a Vector2.

    Declaration

    Swift

    public var r1Vec: Vector2<Scalar> { get }
  • Gets the first column of this matrix in a Vector2.

    Declaration

    Swift

    public var c0Vec: Vector2<Scalar> { get }
  • Gets the second column of this matrix in a Vector2.

    Declaration

    Swift

    public var c1Vec: Vector2<Scalar> { get }
  • Returns the number of rows in this matrix.

    For Matrix2x2 instances, this value is always 2.

    Declaration

    Swift

    public let rowCount: Int
  • Returns the number of columns in this matrix.

    For Matrix2x2 instances, this value is always 2.

    Declaration

    Swift

    public let columnCount: Int
  • Subscripts into this matrix using column/row numbers.

    Declaration

    Swift

    public subscript(column: Int, row: Int) -> Scalar { get set }
  • Returns the trace of this matrix, i.e. the sum of all the values on its diagonal:

    self[0, 0] + self[1, 1]
    

    Declaration

    Swift

    public var trace: Scalar { get }
  • Returns a String that represents this instance.

    Declaration

    Swift

    public var description: String { get }
  • Initializes an identity matrix.

    Declaration

    Swift

    public init()
  • Initializes a new matrix with the given row values.

    Declaration

    Swift

    public init(rows: (Row, Row))
  • Initializes a new matrix with the given Vector2Type values as the values for each row.

    Declaration

    Swift

    public init<Vector: Vector2Type>(
        rows: (Vector, Vector)
    ) where Vector.Scalar == Scalar
  • Initializes a matrix with the given scalar on all positions.

    Declaration

    Swift

    public init(repeating scalar: Scalar)
  • Initializes a matrix with the given scalars laid out on the diagonal, with all remaining elements being .zero.

    Declaration

    Swift

    public init(diagonal: (Scalar, Scalar))
  • Initializes a matrix with the given scalar laid out on the diagonal, with all remaining elements being .zero.

    Declaration

    Swift

    public init(diagonal: Scalar)
  • Returns the determinant of this matrix.

    Declaration

    Swift

    @inlinable
    public func determinant() -> Scalar
  • Transforms a given vector as a point, applying scaling, rotation and translation to the vector.

    Declaration

    Swift

    public func transformPoint<Vector: Vector2FloatingPoint>(
        _ vec: Vector
    ) -> Vector where Vector.Scalar == Scalar
  • Returns a new Matrix2x2 that is a transposition of this matrix.

    Declaration

    Swift

    public func transposed() -> Matrix2x2<Scalar>
  • Performs an in-place transposition of this matrix.

    Declaration

    Swift

    public mutating func transpose()
  • Returns the inverse of this matrix.

    If this matrix has no inversion, nil is returned, instead.

    Declaration

    Swift

    public func inverted() -> `Self`?
  • Performs a matrix addition between lhs and rhs and returns the result.

    Declaration

    Swift

    public static func + (lhs: `Self`, rhs: `Self`) -> Matrix2x2<Scalar>
  • Performs a matrix subtraction between lhs and rhs and returns the result.

    Declaration

    Swift

    public static func - (lhs: `Self`, rhs: `Self`) -> Matrix2x2<Scalar>
  • Negates (i.e. flips) the signs of all the values of this matrix.

    Declaration

    Swift

    public prefix static func - (value: `Self`) -> Matrix2x2<Scalar>
  • Performs a scalar multiplication between lhs and rhs and returns the result.

    Declaration

    Swift

    public static func * (lhs: `Self`, rhs: Scalar) -> Matrix2x2<Scalar>
  • Performs a scalar division between the elements of lhs and rhs and returns the result.

    Declaration

    Swift

    public static func / (lhs: `Self`, rhs: Scalar) -> Matrix2x2<Scalar>
  • Performs a matrix multiplication between lhs and rhs and returns the result.

    Declaration

    Swift

    public static func * (lhs: `Self`, rhs: `Self`) -> Matrix2x2<Scalar>
  • Performs an in-place matrix multiplication between lhs and rhs and stores the result back to lhs.

    Declaration

    Swift

    public static func *= (lhs: inout `Self`, rhs: `Self`)
  • Returns true iff all coefficients from lhs and rhs are equal.

    Declaration

    Swift

    public static func == (lhs: `Self`, rhs: `Self`) -> Bool