Collection

public extension Collection
  • Averages this collection of vectors into one VectorDivisible point as the mean location of each vector.

    Returns VectorDivisible.zero, if the collection is empty.

    let vectors = [
        Vector2D(x: 3.0, y: 4.3),
        Vector2D(x: -2.0, y: 2.3),
        Vector2D(x: 2.0, y: 6.9)
    ]
    
    print(vectors.averageVector()) // Prints "(x: 1.0, y: 4.5)"
    

    Declaration

    Swift

    @inlinable
    func averageVector<V>() -> V where V : VectorDivisible, V == Self.Element, V.Scalar : FloatingPoint