UnitVector
@propertyWrapper
public struct UnitVector<Vector> where Vector : VectorFloatingPoint
extension UnitVector: Equatable where Vector: Equatable, Vector.Scalar: Equatable
extension UnitVector: Hashable where Vector: Hashable, Vector.Scalar: Hashable
extension UnitVector: Encodable where Vector: Encodable, Vector.Scalar: Encodable
extension UnitVector: Decodable where Vector: Decodable, Vector.Scalar: Decodable
Wraps a vector and ensures that assignments are always stored as a unit vector.
If a vector with .length == 0 is attempted to be stored, a zero-valued
vector is assigned instead and isValid returns false until a new
valid vector is supplied.
-
Gets or sets the underlying vector value.
When assigning a new value, the vector is first normalized before being assigned.
If a vector with
.length == 0is attempted to be stored, a zero-valued vector is assigned instead andisValidreturnsfalseuntil a new valid vector is supplied.Declaration
Swift
public var wrappedValue: Vector { get set } -
Returns
trueif the underlying vector is a non-zero value.When assigning vectors of zero-length, this property returns
trueuntil another valid vector is assigned onwrappedValue.Declaration
Swift
@inlinable public var isValid: Bool { get } -
Creates a new
UnitVectorwith a given starting value.If a vector with
.length == 0is attempted to be stored, a zero-valued vector is assigned instead andisValidreturnsfalseuntil a new valid vector is supplied.Declaration
Swift
@inlinable public init(wrappedValue: Vector)Parameters
wrappedValueA vector to initialize this
UnitVectorwith, which is normalized before being assigned. Value must havelength > 0.