VectorMultiplicative
public protocol VectorMultiplicative : VectorAdditive where Self.Scalar : Numeric
Protocol for Vectors that support multiplication
-
oneDefault implementationA unit-value
VectorTypevalue where each component corresponds to its representation of1.Default Implementation
A unit-value
VectorMultiplicativevalue where each component corresponds to its representation of1.Declaration
Swift
static var one: Self { get } -
lengthSquaredDefault implementationReturns the length squared of this
VectorType.Performs the computation
x0 * x0 + x1 * x1 + ... + xN * xNfor any N-dimensional vector type, and is equivalent to the squared distance to the origin of the vector space, or thedot(_:)product of the vector with itself.Default Implementation
Returns the length squared of this
VectorTypeDeclaration
Swift
var lengthSquared: Scalar { get } -
distanceSquared(to:Default implementation) Returns the squared distance between this
VectorTypeand anotherVectorType.Equivalent to
(vec - self).distanceSquared.Default Implementation
Returns the squared distance between this
VectorTypeand anotherVectorType.Equivalent to
(vec - self).distanceSquared.Declaration
Swift
func distanceSquared(to vec: Self) -> Scalar -
Calculates the dot product between this vector and another.
Performs the computation
x1 * y1 + x2 * y2 + ... + xN + yNfor any N-dimensional vector type.let v1 = Vector2D(x: 3.0, y: -2.0) let v2 = Vector2D(x: 2.5, y: 7.0) print(v1.dot(v2)) // Prints "-6.5"Declaration
Swift
func dot(_ other: Self) -> Scalar -
lerp(start:Default implementationend: amount: ) Performs a linear interpolation between two vectors.
Passing
amounta value of 0 will causestartto be returned; a value of 1 will causeendto be returned.Default Implementation
Performs a linear interpolation between two points.
Passing
amounta value of 0 will causestartto be returned; a value of 1 will causeendto be returned.Declaration
Swift
static func lerp(start: Self, end: Self, amount: Scalar) -> SelfParameters
startStart point.
endEnd point.
amountValue between 0 and 1 indicating the weight of
end. -
Declaration
Swift
static func * (lhs: Self, rhs: Self) -> Self -
Declaration
Swift
static func * (lhs: Self, rhs: Scalar) -> Self -
Declaration
Swift
static func * (lhs: Scalar, rhs: Self) -> Self -
*=(_:Default implementation_: ) Default Implementation
Declaration
Swift
static func *= (lhs: inout Self, rhs: Self) -
Declaration
Swift
static func *= (lhs: inout Self, rhs: Scalar)