VectorSigned

public protocol VectorSigned : VectorMultiplicative where Self.Scalar : Comparable, Self.Scalar : SignedNumeric

Vector type where the components are signed numbers.

  • Returns a VectorSigned where each component is the absolute magnitude of the components of this VectorSigned.

    Equivalent to calling C’s abs() function on each component.

    print(Vector2D(x: 2.0, y: -1.0).absolute) // Prints "(x: 2.0, y: 1.0)"
    

    Declaration

    Swift

    var absolute: Self { get }
  • Returns a VectorSigned where each component is one with the signs of each component of this VectorSigned, unless the component is Scalar.zero, in which case the value is Scalar.zero, instead.

    print(Vector2D(x: 4.0, y: -2.0).sign) // Prints "(x: 1.0, y: -1.0)"
    print(Vector2D(x: -1.0, y: 0.0).sign) // Prints "(x: -1.0, y: 0.0)"
    

    Declaration

    Swift

    var sign: Self { get }
  • withSign(of:) Default implementation

    Returns a VectorSigned where each component is the absolute magnitude of the components of this VectorSigned, but with the signs of a secondary VectorSigned.

    Equivalent to multiplying absolute by other.sign.

    let vec1 = Vector3D(x: 5.0, y: -4.0, z: 3.0)
    let vec2 = Vector3D(x: -1.0, y: 1.0, z: 0.0)
    
    print(vec1.withSign(of: vec2)) // Prints "(x: -5.0, y: 4.0, z: 0.0)"
    

    Default Implementation

    Returns a VectorSigned where each component is the absolute magnitude of the components of this VectorSigned, but with the signs of a secondary VectorSigned.

    Equivalent to multiplying absolute by other.sign.

    let vec1 = Vector3D(x: 5.0, y: -4.0, z: 3.0)
    let vec2 = Vector3D(x: -1.0, y: 1.0, z: 0.0)
    
    print(vec1.withSign(of: vec2)) // Prints "(x: -5.0, y: 4.0, z: 0.0)"
    

    Declaration

    Swift

    func withSign(of other: Self) -> Self
  • Negates this Vector by flipping the sign of each component.

    print(-Vector2D(x: 2.0, y: -1.0)) // Prints "(x: -2.0, y: 1.0)"
    

    Declaration

    Swift

    prefix static func - (lhs: Self) -> Self