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 == 0
is attempted to be stored, a zero-valued vector is assigned instead andisValid
returnsfalse
until a new valid vector is supplied.Declaration
Swift
public var wrappedValue: Vector { get set }
-
Returns
true
if the underlying vector is a non-zero value.When assigning vectors of zero-length, this property returns
true
until another valid vector is assigned onwrappedValue
.Declaration
Swift
@inlinable public var isValid: Bool { get }
-
Creates a new
UnitVector
with a given starting value.If a vector with
.length == 0
is attempted to be stored, a zero-valued vector is assigned instead andisValid
returnsfalse
until a new valid vector is supplied.Declaration
Swift
@inlinable public init(wrappedValue: Vector)
Parameters
wrappedValue
A vector to initialize this
UnitVector
with, which is normalized before being assigned. Value must havelength > 0
.