Vector

public struct Vector : Hashable

A structure that contains a two-dimensional vector.

  • The vector whose components are both zero.

    Declaration

    Swift

    public static let zero: Vector
  • dx

    The x component of the vector.

    Declaration

    Swift

    public var dx: Float
  • dy

    The y component of the vector.

    Declaration

    Swift

    public var dy: Float
  • Creates a vector with components specified as floating-point values.

    Declaration

    Swift

    @inlinable
    public init(dx: Float, dy: Float)

    Parameters

    dx

    The x component of the vector.

    dy

    The y component of the vector.

  • Creates a vector with components specified as integer values.

    Declaration

    Swift

    @inlinable
    public init(dx: Int, dy: Int)

    Parameters

    x

    The x-coordinate of the point.

    y

    The y-coordinate of the point.

  • Returns the given vector unchanged.

    You can use the unary plus operator (+) to provide symmetry in your code.

    Declaration

    Swift

    @inlinable
    public prefix static func + (x: Vector) -> Vector

    Parameters

    x

    A vector.

    Return Value

    The given argument without any changes.

  • Returns the inverse of the specified vector.

    Declaration

    Swift

    @inlinable
    public prefix static func - (x: Vector) -> Vector

    Parameters

    x

    A vector.

    Return Value

    The inverse of this vector.

  • Adds two vectors and produces their sum vector.

    Declaration

    Swift

    @inlinable
    public static func + (lhs: Vector, rhs: Vector) -> Vector

    Parameters

    lhs

    The first vector to add.

    rhs

    The second vector to add.

    Return Value

    The sum vector.

  • Subtracts one value from another and produces their difference vector.

    Declaration

    Swift

    @inlinable
    public static func - (lhs: Vector, rhs: Vector) -> Vector

    Parameters

    lhs

    A vector.

    rhs

    The vector to subtract from lhs.

    Return Value

    The difference vector.

  • Multiplies a vector by a floating-point scalar value.

    Declaration

    Swift

    @inlinable
    public static func * (lhs: Vector, rhs: Float) -> Vector

    Parameters

    lhs

    A vector.

    rhs

    A floating-point scalar value.

    Return Value

    The scaled vector.

  • Multiplies a vector by an integer scalar value.

    Declaration

    Swift

    @inlinable
    public static func * (lhs: Vector, rhs: Int) -> Vector

    Parameters

    lhs

    A vector.

    rhs

    An integer scalar value.

    Return Value

    The scaled vector.

  • Multiplies a vector by a floating-point scalar value.

    Declaration

    Swift

    @inlinable
    public static func * (lhs: Float, rhs: Vector) -> Vector

    Parameters

    lhs

    A floating-point scalar value.

    rhs

    A vector.

    Return Value

    The scaled vector.

  • Multiplies a vector by an integer scalar value.

    Declaration

    Swift

    @inlinable
    public static func * (lhs: Int, rhs: Vector) -> Vector

    Parameters

    lhs

    An integer scalar value.

    rhs

    A vector.

    Return Value

    The scaled vector.

  • Declaration

    Swift

    public var debugDescription: String { get }