Transform

public struct Transform: Equatable

A structure for holding a transform matrix.

Transform can translate, rotate, scale.

  • Initializes a Transform. Defaults to an identity transform.

    Declaration

    Swift

    public init()
  • Creates a new transform from a CGAffineTransform structure. - parameter t: A CGAffineTransform structure.

    Declaration

    Swift

    public init(_ t: CGAffineTransform)

    Parameters

    t

    A CGAffineTransform structure.

  • Creates a new transform from a CATransform3D structure. - parameter t: A CATransform3D structure.

    Declaration

    Swift

    public init(_ t: CATransform3D)

    Parameters

    t

    A CATransform3D structure.

  • Returns true if transform is affine, otherwise false.

    Declaration

    Swift

    public func isAffine() -> Bool
  • The translation component of the tranform. - returns: A Vector that represents the translation of the transform, where x = [0,3], y = [1,3]

    Declaration

    Swift

    public var translation: Vector

    Return Value

    A Vector that represents the translation of the transform, where x = [0,3], y = [1,3]

  • Creates a transform that represents a translation in 2d (x,y) let v = Vector(x: 1, y: 1) let t = Transform.makeTranslation(v) - parameter translation: A Vector that represents the translation to apply. - returns: A Transform that can be used to apply a translation to a receiver.

    Declaration

    Swift

    public static func makeTranslation(translation: Vector) -> Transform

    Parameters

    translation

    A Vector that represents the translation to apply.

    Return Value

    A Transform that can be used to apply a translation to a receiver.

  • Creates a transform that represents a scale in 3d (x, y, z). The z component is optional. let t = Transform.makeScale(2.0, 2.0) - parameter sx: The amount to scale in the x axis - parameter sy: The amount to scale in the y axis - parameter sz: The amount to scale in the z axis - returns: A Transform that can be used to scale a receiver.

    Declaration

    Swift

    public static func makeScale(sx: Double, _ sy: Double, _ sz: Double = 1) -> Transform

    Parameters

    sx

    The amount to scale in the x axis

    sy

    The amount to scale in the y axis

    sz

    The amount to scale in the z axis

    Return Value

    A Transform that can be used to scale a receiver.

  • Creates a transform that represents a rotation. The axis component is optional. let t = Transform.makeRotation(M_PI) - parameter angle: The angle, in radians, to rotate - parameter axis: The axis around which to rotate, defaults to the z axis {0,0,1} - returns: A Transform that can be used to rotate a receiver.

    Declaration

    Swift

    public static func makeRotation(angle: Double, axis: Vector = Vector(x: 0, y: 0, z : 1)) -> Transform

    Parameters

    angle

    The angle, in radians, to rotate

    axis

    The axis around which to rotate, defaults to the z axis {0,0,1}

    Return Value

    A Transform that can be used to rotate a receiver.

  • Applies a translation to the receiver. let v = Vector(x: 1, y: 1) let t = Transform() t.translate(v) - parameter translation: A Vector that represents the translation to apply.

    Declaration

    Swift

    public mutating func translate(translation: Vector)

    Parameters

    translation

    A Vector that represents the translation to apply.

  • Applies a scale to the receiver. The z variable is optional. let t = Transform() t.scale(2.0, 2.0) - parameter sx: The amount to scale in the x axis - parameter sy: The amount to scale in the y axis - parameter sz: The amount to scale in the z axis

    Declaration

    Swift

    public mutating func scale(sx: Double, _ sy: Double, _ sz: Double = 1)

    Parameters

    sx

    The amount to scale in the x axis

    sy

    The amount to scale in the y axis

    sz

    The amount to scale in the z axis

  • Applies a rotation. The axis component is optional. let t = Transform() t.rotate(M_PI) - parameter angle: The angle, in radians, to rotate - parameter axis: The axis around which to rotate, defaults to the z axis {0,0,1}

    Declaration

    Swift

    public mutating func rotate(angle: Double, axis: Vector = Vector(x: 0, y: 0, z: 1))

    Parameters

    angle

    The angle, in radians, to rotate

    axis

    The axis around which to rotate, defaults to the z axis {0,0,1}

  • The CGAffineTransform version of the receiver. - returns: A CGAffineTransform that is equivalent to the receiver.

    Declaration

    Swift

    public var affineTransform: CGAffineTransform

    Return Value

    A CGAffineTransform that is equivalent to the receiver.

  • The CATransform3D version of the receiver. - returns: A CATransform3D that is equivalent to the receiver.

    Declaration

    Swift

    public var transform3D: CATransform3D

    Return Value

    A CATransform3D that is equivalent to the receiver.