CGVector
public extension CGVector
-
SwifterSwift: The angle of rotation (in radians) of the vector. The range of the angle is -π to π; an angle of 0 points to the right.
Declaration
Swift
var angle: CGFloat { get }
-
SwifterSwift: The magnitude (or length) of the vector.
Declaration
Swift
var magnitude: CGFloat { get }
-
SwifterSwift: Creates a vector with the given magnitude and angle.
let vector = CGVector(angle: .pi, magnitude: 1)
Declaration
Swift
init(angle: CGFloat, magnitude: CGFloat)
Parameters
angle
The angle of rotation (in radians) counterclockwise from the positive x-axis.
magnitude
The lenth of the vector.
-
SwifterSwift: Multiplies a scalar and a vector (commutative).
let vector = CGVector(dx: 1, dy: 1) let largerVector = vector * 2
Declaration
Swift
static func * (vector: CGVector, scalar: CGFloat) -> CGVector
Parameters
vector
The vector to be multiplied
scalar
The scale by which the vector will be multiplied
Return Value
The vector with its magnitude scaled
-
SwifterSwift: Multiplies a scalar and a vector (commutative).
let vector = CGVector(dx: 1, dy: 1) let largerVector = 2 * vector
Declaration
Swift
static func * (scalar: CGFloat, vector: CGVector) -> CGVector
Parameters
scalar
The scalar by which the vector will be multiplied
vector
The vector to be multiplied
Return Value
The vector with its magnitude scaled
-
SwifterSwift: Compound assignment operator for vector-scalr multiplication
var vector = CGVector(dx: 1, dy: 1) vector *= 2
Declaration
Swift
static func *= (vector: inout CGVector, scalar: CGFloat)
Parameters
vector
The vector to be multiplied
scalar
The scale by which the vector will be multiplied
-
SwifterSwift: Negates the vector. The direction is reversed, but magnitude remains the same.
let vector = CGVector(dx: 1, dy: 1) let reversedVector = -vector
Declaration
Swift
prefix static func - (vector: CGVector) -> CGVector
Parameters
vector
The vector to be negated
Return Value
The negated vector