VectorSigned
public protocol VectorSigned : VectorMultiplicative where Self.Scalar : Comparable, Self.Scalar : SignedNumeric
Vector type where the components are signed numbers.
-
Returns a
VectorSignedwhere each component is the absolute magnitude of the components of thisVectorSigned.Equivalent to calling C’s
abs()function on each component.print(Vector2D(x: 2.0, y: -1.0).absolute) // Prints "(x: 2.0, y: 1.0)"Declaration
Swift
var absolute: Self { get } -
Returns a
VectorSignedwhere each component isonewith the signs of each component of thisVectorSigned, unless the component isScalar.zero, in which case the value isScalar.zero, instead.print(Vector2D(x: 4.0, y: -2.0).sign) // Prints "(x: 1.0, y: -1.0)" print(Vector2D(x: -1.0, y: 0.0).sign) // Prints "(x: -1.0, y: 0.0)"Declaration
Swift
var sign: Self { get } -
withSign(of:Default implementation) Returns a
VectorSignedwhere each component is the absolute magnitude of the components of thisVectorSigned, but with the signs of a secondaryVectorSigned.Equivalent to multiplying
absolutebyother.sign.let vec1 = Vector3D(x: 5.0, y: -4.0, z: 3.0) let vec2 = Vector3D(x: -1.0, y: 1.0, z: 0.0) print(vec1.withSign(of: vec2)) // Prints "(x: -5.0, y: 4.0, z: 0.0)"Default Implementation
Returns a
VectorSignedwhere each component is the absolute magnitude of the components of thisVectorSigned, but with the signs of a secondaryVectorSigned.Equivalent to multiplying
absolutebyother.sign.let vec1 = Vector3D(x: 5.0, y: -4.0, z: 3.0) let vec2 = Vector3D(x: -1.0, y: 1.0, z: 0.0) print(vec1.withSign(of: vec2)) // Prints "(x: -5.0, y: 4.0, z: 0.0)"Declaration
Swift
func withSign(of other: Self) -> Self -
Negates this Vector by flipping the sign of each component.
print(-Vector2D(x: 2.0, y: -1.0)) // Prints "(x: -2.0, y: 1.0)"Declaration
Swift
prefix static func - (lhs: Self) -> Self