Matrix3x2

public struct Matrix3x2<Scalar> : Hashable, CustomStringConvertible where Scalar : ElementaryFunctions, Scalar : FloatingPoint
extension Matrix3x2: Encodable where Scalar: Encodable
extension Matrix3x2: Decodable where Scalar: Decodable

Plain 3-row 2-column Matrix for 2D affine transformations with floating-point components.

  • Undocumented

    Declaration

    Swift

    public typealias Vector = Vector2<Scalar>
  • Gets the identity matrix.

    Declaration

    Swift

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

    Element (1,1)

    Declaration

    Swift

    public let m11: Scalar
  • m12

    Element (1,2)

    Declaration

    Swift

    public let m12: Scalar
  • m21

    Element (2,1)

    Declaration

    Swift

    public let m21: Scalar
  • m22

    Element (2,2)

    Declaration

    Swift

    public let m22: Scalar
  • m31

    Element (3,1)

    Declaration

    Swift

    public let m31: Scalar
  • m32

    Element (3,2)

    Declaration

    Swift

    public let m32: Scalar
  • Gets the first row in the matrix; that is M11 and M12.

    Declaration

    Swift

    public var row1: [Scalar] { get }
  • Gets the second row in the matrix; that is M21 and M22.

    Declaration

    Swift

    public var row2: [Scalar] { get }
  • Gets the third row in the matrix; that is M31 and M32.

    Declaration

    Swift

    public var row3: [Scalar] { get }
  • Gets the first column in the matrix; that is M11, M21, and M31.

    Declaration

    Swift

    public var column1: [Scalar] { get }
  • Gets the second column in the matrix; that is M12, M22, and M32.

    Declaration

    Swift

    public var column2: [Scalar] { get }
  • Gets the translation of the matrix; that is M31 and M32.

    Declaration

    Swift

    public var translationVector: Vector { get }
  • Gets the scale of the matrix; that is M11 and M22.

    Declaration

    Swift

    public var scaleVector: Vector { get }
  • Gets a value indicating whether this instance is an identity matrix.

    true if this instance is an identity matrix; otherwise, false.

    Declaration

    Swift

    public var isIdentity: Bool { get }
  • Gets or sets the component at the specified index.

    Declaration

    Swift

    public subscript(index index: Int) -> Scalar { get }

    Parameters

    index

    The zero-based index of the component to access.

    Return Value

    The value of the component at the specified index.

  • Gets or sets the component at the specified index.

    Precondition

    row >= 0 && row <= 2 && column >= 0 && column <= 1

    Declaration

    Swift

    public subscript(column column: Int, row row: Int) -> Scalar { get }

    Parameters

    row

    The row of the matrix to access.

    column

    The column of the matrix to access.

    Return Value

    The value of the component at the specified index.

  • Returns a String that represents this instance.

    Declaration

    Swift

    public var description: String { get }
  • Initializes a new instance of the Matrix3x2 struct.

    Declaration

    Swift

    public init(value: Scalar)

    Parameters

    value

    The value that will be assigned to all components.

  • Initializes a new instance of the Matrix3x2 struct.

    Declaration

    Swift

    public init(m11: Scalar, m12: Scalar, m21: Scalar, m22: Scalar, m31: Scalar, m32: Scalar)

    Parameters

    m11

    The value to assign at row 1 column 1 of the matrix.

    m12

    The value to assign at row 1 column 2 of the matrix.

    m21

    The value to assign at row 2 column 1 of the matrix.

    m22

    The value to assign at row 2 column 2 of the matrix.

    m31

    The value to assign at row 3 column 1 of the matrix.

    m32

    The value to assign at row 3 column 2 of the matrix.

  • Initializes a new instance of the Matrix3x2 struct.

    Precondition

    values.count == 6

    Declaration

    Swift

    public init(values: [Scalar])

    Parameters

    values

    The values to assign to the components of the matrix. This must be an array with six elements, otherwise a runtime error is thrown

  • Creates an array containing the elements of the matrix.

    Declaration

    Swift

    public func toArray() -> [Scalar]

    Return Value

    A six-element array containing the components of the matrix.

  • Calculates the determinant of this matrix.

    Declaration

    Swift

    public func determinant() -> Scalar

    Return Value

    Result of the determinant.

  • Calculates the inverse of this matrix instance.

    Declaration

    Swift

    public func inverted() -> Matrix3x2
  • Determines the sum of two matrices.

    Declaration

    Swift

    public static func add(_ left: Matrix3x2, _ right: Matrix3x2) -> Matrix3x2

    Parameters

    left

    The first matrix to add.

    right

    The second matrix to add.

  • Determines the difference between two matrices.

    Declaration

    Swift

    public static func subtract(_ left: Matrix3x2, _ right: Matrix3x2) -> Matrix3x2

    Parameters

    left

    The first matrix to subtract.

    right

    The second matrix to subtract.

  • Scales a matrix by the given value.

    Declaration

    Swift

    public static func multiply(_ left: Matrix3x2, _ right: Scalar) -> Matrix3x2

    Parameters

    left

    The matrix to scale.

    right

    The amount by which to scale.

  • Determines the product of two matrices.

    Declaration

    Swift

    public static func multiply(_ left: Matrix3x2, _ right: Matrix3x2) -> Matrix3x2

    Parameters

    left

    The first matrix to multiply.

    right

    The second matrix to multiply.

  • Scales a matrix by the given value.

    Declaration

    Swift

    public static func divide(_ left: Matrix3x2, _ right: Scalar) -> Matrix3x2

    Parameters

    left

    The matrix to scale.

    right

    The amount by which to scale. Must be greater than zero

  • Determines the quotient of two matrices.

    Declaration

    Swift

    public static func divide(_ left: Matrix3x2, _ right: Matrix3x2) -> Matrix3x2

    Parameters

    left

    The first matrix to divide.

    right

    The second matrix to divide.

  • Negates a matrix.

    Declaration

    Swift

    public static func negate(_ value: Matrix3x2) -> Matrix3x2

    Parameters

    value

    The matrix to be negated.

  • Performs a linear interpolation between two matrices.

    Passing amount a value of 0 will cause start to be returned; a value of 1 will cause end to be returned.

    Declaration

    Swift

    public static func lerp(start: Matrix3x2, end: Matrix3x2, amount: Scalar) -> Matrix3x2

    Parameters

    start

    Start matrix.

    end

    End matrix.

    amount

    Value between 0 and 1 indicating the weight of end.

  • Creates a matrix that scales along the x-axis and y-axis.

    Declaration

    Swift

    public static func scaling(scale: Vector) -> Matrix3x2

    Parameters

    scale

    Scaling factor for both axes.

  • Creates a matrix that scales along the x-axis and y-axis.

    Declaration

    Swift

    public static func scaling(x: Scalar, y: Scalar) -> Matrix3x2

    Parameters

    x

    Scaling factor that is applied along the x-axis.

    y

    Scaling factor that is applied along the y-axis.

  • Creates a matrix that uniformly scales along both axes.

    Declaration

    Swift

    public static func scaling(scale: Scalar) -> Matrix3x2

    Parameters

    scale

    The uniform scale that is applied along both axes.

  • Creates a matrix that is scaling from a specified center.

    Declaration

    Swift

    public static func scaling(x: Scalar, y: Scalar, center: Vector) -> Matrix3x2

    Parameters

    x

    Scaling factor that is applied along the x-axis.

    y

    Scaling factor that is applied along the y-axis.

    center

    The center of the scaling.

  • Creates a matrix that rotates.

    Declaration

    Swift

    public static func rotation(angle: Scalar) -> Matrix3x2

    Parameters

    angle

    Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.

    result

    When the method completes, contains the created rotation matrix.

  • Creates a matrix that rotates about a specified center.

    Declaration

    Swift

    public static func rotation(angle: Scalar, center: Vector) -> Matrix3x2

    Parameters

    angle

    Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.

    center

    The center of the rotation.

  • Creates a translation matrix using the specified offsets.

    Declaration

    Swift

    public static func translation(_ value: Vector) -> Matrix3x2

    Parameters

    value

    The offset for both coordinate planes.

    result

    When the method completes, contains the created translation matrix.

  • Creates a translation matrix using the specified offsets.

    Declaration

    Swift

    public static func translation(x: Scalar, y: Scalar) -> Matrix3x2

    Parameters

    x

    X-coordinate offset.

    y

    Y-coordinate offset.

  • Creates a transformation matrix.

    Declaration

    Swift

    public static func transformation(xScale: Scalar,
                                      yScale: Scalar,
                                      angle: Scalar,
                                      xOffset: Scalar,
                                      yOffset: Scalar) -> Matrix3x2

    Parameters

    xScale

    Scaling factor that is applied along the x-axis.

    yScale

    Scaling factor that is applied along the y-axis.

    angle

    Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.

    xOffset

    X-coordinate offset.

    yOffset

    Y-coordinate offset.

  • Transforms a vector by this matrix.

    Declaration

    Swift

    @inlinable
    public static func transformPoint(matrix: Matrix3x2, point: Vector) -> Vector

    Parameters

    matrix

    The matrix to use as a transformation matrix.

    point

    The original vector to apply the transformation.

    Return Value

    The result of the transformation for the input vector.

  • Transforms a vector by this matrix.

    Declaration

    Swift

    @inlinable
    public static func transformPoint<V>(matrix: Matrix3x2, point: V) -> V where Scalar == V.Scalar, V : Vector2Type

    Parameters

    matrix

    The matrix to use as a transformation matrix.

    point

    The original vector to apply the transformation.

    Return Value

    The result of the transformation for the input vector.

  • Creates a skew matrix.

    Declaration

    Swift

    public static func skew(angleX: Scalar, angleY: Scalar) -> Matrix3x2

    Parameters

    angleX

    Angle of skew along the X-axis in radians.

    angleY

    Angle of skew along the Y-axis in radians.

  • Calculates the inverse of the specified matrix.

    Declaration

    Swift

    public static func invert(_ value: Matrix3x2) -> Matrix3x2

    Parameters

    value

    The matrix whose inverse is to be calculated.

    result

    When the method completes, contains the inverse of the specified matrix.

  • Adds two matrices.

    Declaration

    Swift

    public static func + (left: Matrix3x2, right: Matrix3x2) -> Matrix3x2

    Parameters

    left

    The first matrix to add.

    right

    The second matrix to add.

    Return Value

    The sum of the two matrices.

  • Assert a matrix (return it unchanged).

    Declaration

    Swift

    public prefix static func + (value: Matrix3x2) -> Matrix3x2

    Parameters

    value

    The matrix to assert (unchanged).

    Return Value

    The asserted (unchanged) matrix.

  • Subtracts two matrices.

    Declaration

    Swift

    public static func - (left: Matrix3x2, right: Matrix3x2) -> Matrix3x2

    Parameters

    left

    The first matrix to subtract.

    right

    The second matrix to subtract.

    Return Value

    The difference between the two matrices.

  • Negates a matrix.

    Declaration

    Swift

    public prefix static func - (value: Matrix3x2) -> Matrix3x2

    Parameters

    value

    The matrix to negate.

    Return Value

    The negated matrix.

  • Scales a matrix by a given value.

    Declaration

    Swift

    public static func * (left: Scalar, right: Matrix3x2) -> Matrix3x2

    Parameters

    right

    The matrix to scale.

    left

    The amount by which to scale.

    Return Value

    The scaled matrix.

  • Scales a matrix by a given value.

    Declaration

    Swift

    public static func * (left: Matrix3x2, right: Scalar) -> Matrix3x2

    Parameters

    left

    The matrix to scale.

    right

    The amount by which to scale.

    Return Value

    The scaled matrix.

  • Multiplies two matrices.

    Declaration

    Swift

    public static func * (left: Matrix3x2, right: Matrix3x2) -> Matrix3x2

    Parameters

    left

    The first matrix to multiply.

    right

    The second matrix to multiply.

    Return Value

    The product of the two matrices.

  • Scales a matrix by a given value.

    Declaration

    Swift

    public static func / (left: Matrix3x2, right: Scalar) -> Matrix3x2

    Parameters

    left

    The matrix to scale.

    right

    The amount by which to scale.

    Return Value

    The scaled matrix.

  • Divides two matrices.

    Declaration

    Swift

    public static func / (left: Matrix3x2, right: Matrix3x2) -> Matrix3x2

    Parameters

    left

    The first matrix to divide.

    right

    The second matrix to divide.

    Return Value

    The quotient of the two matrices.

Geometry transformation

  • Transforms a given rectangle’s bounds using this transformation matrix.

    The scale and rotation transformations use the origin (0, 0) for the base of the transformation, so scaling and rotating do not happen around the origin or center of the rectangle itself.

    Declaration

    Swift

    @inlinable
    func transform<V>(_ rect: NRectangle<V>) -> NRectangle<V> where Scalar == V.Scalar, V : Vector2Type, V : VectorAdditive, V : VectorComparable
  • Undocumented

    Declaration

    Swift

    @inlinable
    func transform<V>(_ point: V) -> V where Scalar == V.Scalar, V : Vector2Type
  • Undocumented

    Declaration

    Swift

    @inlinable
    func transform<V>(points: [V]) -> [V] where Scalar == V.Scalar, V : Vector2Type