Vector2Type

public protocol Vector2Type : VectorTakeable where Self.TakeDimensions == Vector2TakeDimensions

Protocol for types that can represent 2D vectors.

  • Undocumented

    Declaration

    Swift

    associatedtype SubVector2 = Self
  • x

    The X coordinate of this 2D vector.

    Declaration

    Swift

    var x: Scalar { get set }
  • y

    The Y coordinate of this 2D vector.

    Declaration

    Swift

    var y: Scalar { get set }
  • Initializes this vector type with the given coordinates.

    Declaration

    Swift

    init(x: Scalar, y: Scalar)
  • init(_:) Default implementation

    Initializes a new instance of this Vector2Type type by copying the coordinates of another Vector2Type of matching scalar type.

    Default Implementation

    Declaration

    Swift

    init<Vector>(_ vector: Vector) where Vector : Vector2Type, Self.Scalar == Vector.Scalar
  • scalarCount Extension method

    The number of scalars in the vector.

    For 2D vectors, this value is always 2.

    Declaration

    Swift

    var scalarCount: Int { get }
  • subscript(_:) Extension method

    Accesses the scalar at the specified position.

    • index 0: x
    • index 1: y

    Precondition

    index >= 0 && index < 2

    Declaration

    Swift

    @inlinable
    subscript(index: Int) -> Scalar { get set }

Available where Self: VectorComparable

  • maximalComponentIndex Extension method

    Returns the index of the component of this vector that has the greatest value.

    Vector2D(x: -3.0, y: 2.5).maximalComponentIndex // Returns 1
    

    Declaration

    Swift

    var maximalComponentIndex: Int { get }
  • minimalComponentIndex Extension method

    Returns the index of the component of this vector that has the least value.

    Vector2D(x: -3.0, y: 2.5).minimalComponentIndex // Returns 0
    

    Declaration

    Swift

    var minimalComponentIndex: Int { get }
  • maximalComponent Extension method

    Returns the greatest scalar component between x, y in this vector

    Vector2D(x: -3.0, y: 2.5).maximalComponent // Returns 2.5
    

    Declaration

    Swift

    var maximalComponent: Scalar { get }
  • minimalComponent Extension method

    Returns the least scalar component between x, y in this vector

    Vector2D(x: -3.0, y: 2.5).minimalComponent // Returns -3.0
    

    Declaration

    Swift

    var minimalComponent: Scalar { get }