PointBase

public struct PointBase<VectorType> where VectorType : Addable

A 2-dimensional vector.

  • The number of components in a PointBase instance.

    Declaration

    Swift

    public static var numberOfComponents: Int { get }
  • The values of this vector.

    Declaration

    Swift

    public private(set) var components: [VectorType]
  • x

    The x coordinate of the PointBase (the first component of the vector).

    Declaration

    Swift

    public var x: VectorType { get set }
  • y

    The y coordinate of the PointBase (the second component of the vector).

    Declaration

    Swift

    public var y: VectorType { get set }
  • Initializes the zero point.

    Declaration

    Swift

    public init()
  • Initializes a PointBase with the given values.

    Declaration

    Swift

    public init(x: VectorType, y: VectorType)

    Parameters

    x

    The first component of the vector.

    y

    The second component of the vector.

  • Initializes a PointBase with the given value for x. The y component is set to VectorType.zero.

    Declaration

    Swift

    public init(x: VectorType)

    Parameters

    x

    The first component of the vector.

  • Initializes a PointBase with the given value for y. The x component is set to VectorType.zero.

    Declaration

    Swift

    public init(y: VectorType)

    Parameters

    y

    The second component of the vector.

  • Initializes a PointBase with the given value for x and y.

    Declaration

    Swift

    public init(xy: VectorType)

    Parameters

    xy

    The value of both components of the vector.

  • Provides access to the underlying components of this instance.

    Declaration

    Swift

    public subscript(index: Int) -> VectorType { get set }

    Parameters

    index

    The index of the component to access.

    Return Value

    The component at the given index.

  • Returns a PointBase with flipped components, so x becomes y and vice versa.

    Declaration

    Swift

    public func flip() -> PointBase<VectorType>

    Return Value

    A PointBase instance whose x is this instance’s y and vice versa.

  • The unit vector in the x direction.

    Declaration

    Swift

    public static var unitX: PointBase<VectorType> { get }
  • The unit vector in the y direction.

    Declaration

    Swift

    public static var unitY: PointBase<VectorType> { get }
  • Calculates the angle of this vector relative to the x-axis.

    Declaration

    Swift

    public func angle() -> VectorType

    Return Value

    The angle this vector makes with the x-axis when positioned at the origin.

  • Calculates the angle of the vector starting at self and ending at vector, assuming both vectors are positioned at the origin.

    Declaration

    Swift

    public func angle(to vector: PointBase<VectorType>) -> VectorType

    Parameters

    vector

    The vector to calculate the angle to.

    Return Value

    The angle between this vector and vector in the range [-pi, pi].