VectorFloatingPoint
public protocol VectorFloatingPoint : VectorComparable, VectorDivisible, VectorSigned where Self.Scalar : FloatingPoint
Protocol for vector types where the components are floating-point numbers
-
length
Default implementationReturns the Euclidean norm (square root of the squared length), or magnitude, of this
VectorFloatingPoint
.Default Implementation
Returns the Euclidean norm (square root of the squared length), or magnitude, of this
VectorFloatingPoint
.Declaration
Swift
var length: Scalar { get }
-
normalize()
Default implementationNormalizes this
Vector
.Returns
Vector.zero
, if the vector haslength == 0
.Default Implementation
Normalizes this
Vector
.Returns
Vector.zero
, if the vector haslength == 0
.Declaration
Swift
mutating func normalize()
-
normalized()
Default implementationReturns a normalized version of this
Vector
.Returns
Vector.zero
if the vector haslength == 0
.Default Implementation
Returns a normalized version of this vector.
Returns
Vector2.zero
if the vector haslength == 0
.Declaration
Swift
func normalized() -> Self
-
distance(to:
Default implementation) Returns the distance between this
VectorFloatingPoint
and anotherVectorFloatingPoint
.Default Implementation
Returns the distance between this
VectorFloatingPoint
and anotherVectorFloatingPoint
.Declaration
Swift
func distance(to vec: Self) -> Scalar
-
Returns the result of adding the product of the two given vectors to this vector, computed without intermediate rounding.
This method is equivalent to calling C
fma
function on each component.Declaration
Swift
func addingProduct(_ a: Self, _ b: Self) -> Self
Parameters
lhs
One of the vectors to multiply before adding to this vector.
rhs
The other vector to multiply.
Return Value
The product of
lhs
andrhs
, added to this vector. -
Returns the result of adding the product of the given scalar and vector to this vector, computed without intermediate rounding.
This method is equivalent to calling C
fma
function on each component.Declaration
Swift
func addingProduct(_ a: Scalar, _ b: Self) -> Self
Parameters
lhs
A scalar to multiply before adding to this vector.
rhs
A vector to multiply.
Return Value
The product of
lhs
andrhs
, added to this vector. -
Returns the result of adding the product of the given vector and scalar to this vector, computed without intermediate rounding.
This method is equivalent to calling C
fma
function on each component.Declaration
Swift
func addingProduct(_ a: Self, _ b: Scalar) -> Self
Parameters
lhs
A vector to multiply before adding to this vector.
rhs
A scalar to multiply.
Return Value
The product of
lhs
andrhs
, added to this vector. -
Rounds the components of this
VectorType
using a givenFloatingPointRoundingRule
.Declaration
Swift
func rounded(_ rule: FloatingPointRoundingRule) -> Self
-
rounded()
Default implementationRounds the components of this
VectorType
using a givenFloatingPointRoundingRule.toNearestOrAwayFromZero
.Equivalent to calling C’s round() function on each component.
Default Implementation
Rounds the components of this
VectorFloatingPoint
using a givenFloatingPointRoundingRule.toNearestOrAwayFromZero
.Equivalent to calling C’s round() function on each component.
Declaration
Swift
func rounded() -> Self
-
ceil()
Default implementationRounds the components of this
VectorType
using a givenFloatingPointRoundingRule.up
.Equivalent to calling C’s ceil() function on each component.
Default Implementation
Rounds the components of this
VectorFloatingPoint
using a givenFloatingPointRoundingRule.up
.Equivalent to calling C’s ceil() function on each component.
Declaration
Swift
func ceil() -> Self
-
floor()
Default implementationRounds the components of this
VectorType
using a givenFloatingPointRoundingRule.down
.Equivalent to calling C’s floor() function on each component.
Default Implementation
Rounds the components of this
VectorFloatingPoint
using a givenFloatingPointRoundingRule.down
.Equivalent to calling C’s floor() function on each component.
Declaration
Swift
func floor() -> Self
-
Declaration
Swift
static func % (lhs: Self, rhs: Self) -> Self
-
Declaration
Swift
static func % (lhs: Self, rhs: Scalar) -> Self