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]
-
The x coordinate of the
PointBase
(the first component of the vector).Declaration
Swift
public var x: VectorType { get set }
-
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.
-
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.
-
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 atvector
, 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].