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 } -
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) -
Gets or sets all coefficients of this matrix as a single 2x2 tuple.
Declaration
Swift
public var m: M -
The first row of this matrix
Equivalent to
self.m.0.Declaration
Swift
public var r0: Row { get set } -
The second row of this matrix
Equivalent to
self.m.1.Declaration
Swift
public var r1: Row { get set } -
The first column of this matrix
Equivalent to
(self.r0.0, self.r1.0).Declaration
Swift
public var c0: Column { get set } -
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
Matrix2x2instances, this value is always2.Declaration
Swift
public let rowCount: Int -
Returns the number of columns in this matrix.
For
Matrix2x2instances, this value is always2.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
Stringthat 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
Vector2Typevalues 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
Matrix2x2that 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,
nilis returned, instead.Declaration
Swift
public func inverted() -> `Self`? -
Performs a matrix addition between
lhsandrhsand returns the result.Declaration
Swift
public static func + (lhs: `Self`, rhs: `Self`) -> Matrix2x2<Scalar> -
Performs a matrix subtraction between
lhsandrhsand 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
lhsandrhsand returns the result.Declaration
Swift
public static func * (lhs: `Self`, rhs: Scalar) -> Matrix2x2<Scalar> -
Performs a scalar division between the elements of
lhsandrhsand returns the result.Declaration
Swift
public static func / (lhs: `Self`, rhs: Scalar) -> Matrix2x2<Scalar> -
Performs a matrix multiplication between
lhsandrhsand returns the result.Declaration
Swift
public static func * (lhs: `Self`, rhs: `Self`) -> Matrix2x2<Scalar> -
Performs an in-place matrix multiplication between
lhsandrhsand stores the result back tolhs.Declaration
Swift
public static func *= (lhs: inout `Self`, rhs: `Self`) -
Returns
trueiff all coefficients fromlhsandrhsare equal.Declaration
Swift
public static func == (lhs: `Self`, rhs: `Self`) -> Bool