Vector2
public struct Vector2<Scalar> : Vector2Type
extension Vector2: Equatable where Scalar: Equatable
extension Vector2: Hashable where Scalar: Hashable
extension Vector2: Encodable where Scalar: Encodable
extension Vector2: Decodable where Scalar: Decodable
extension Vector2: VectorComparable where Scalar: Comparable
extension Vector2: AdditiveArithmetic where Scalar: AdditiveArithmetic
extension Vector2: VectorAdditive where Scalar: AdditiveArithmetic
extension Vector2: Vector2Additive where Scalar: AdditiveArithmetic
extension Vector2: VectorMultiplicative where Scalar: Numeric
extension Vector2: Vector2Multiplicative where Scalar: Numeric
extension Vector2: VectorSigned where Scalar: SignedNumeric & Comparable
extension Vector2: Vector2Signed where Scalar: SignedNumeric & Comparable
extension Vector2: VectorDivisible where Scalar: DivisibleArithmetic
extension Vector2: VectorFloatingPoint where Scalar: DivisibleArithmetic & FloatingPoint
extension Vector2: SignedDistanceMeasurableType where Scalar: DivisibleArithmetic & FloatingPoint
extension Vector2: Vector2FloatingPoint where Scalar: DivisibleArithmetic & FloatingPoint
extension Vector2: VectorReal where Scalar: DivisibleArithmetic & Real
extension Vector2: Vector2Real where Scalar: DivisibleArithmetic & Real
A two-component vector type
-
X coordinate of this vector
Declaration
Swift
public var x: Scalar
-
Y coordinate of this vector
Declaration
Swift
public var y: Scalar
-
Textual representation of this
Vector2
Declaration
Swift
@inlinable public var description: String { get }
-
Declaration
Swift
public init(x: Scalar, y: Scalar)
-
Declaration
Swift
public init(repeating scalar: Scalar)
-
Initializes this
Vector2
with the values from a given tuple.Declaration
Swift
public init(_ tuple: (Scalar, Scalar))
-
Returns the pointwise minimal Vector where each component is the minimal scalar value at each index for both vectors.
Declaration
Swift
public static func pointwiseMin(_ lhs: `Self`, _ rhs: `Self`) -> Vector2<Scalar>
-
Returns the pointwise maximal Vector where each component is the maximal scalar value at each index for both vectors.
Declaration
Swift
public static func pointwiseMax(_ lhs: `Self`, _ rhs: `Self`) -> Vector2<Scalar>
-
Compares two vectors and returns
true
if all components oflhs
are greater thanrhs
.Performs
lhs.x > rhs.x && lhs.y > rhs.y
Declaration
Swift
public static func > (lhs: `Self`, rhs: `Self`) -> Bool
-
Compares two vectors and returns
true
if all components oflhs
are greater than or equal torhs
.Performs
lhs.x >= rhs.x && lhs.y >= rhs.y
Declaration
Swift
public static func >= (lhs: `Self`, rhs: `Self`) -> Bool
-
Compares two vectors and returns
true
if all components oflhs
are less thanrhs
.Performs
lhs.x < rhs.x && lhs.y < rhs.y
Declaration
Swift
public static func < (lhs: `Self`, rhs: `Self`) -> Bool
-
Compares two vectors and returns
true
if all components oflhs
are less than or equal torhs
.Performs
lhs.x <= rhs.x && lhs.y <= rhs.y
Declaration
Swift
public static func <= (lhs: `Self`, rhs: `Self`) -> Bool
-
A zero-value
Vector2
value where each component corresponds to its representation of0
.Declaration
Swift
public static var zero: `Self` { get }
-
Declaration
Swift
@inlinable public var nonZeroScalarCount: Int { get }
-
Declaration
Swift
public static func + (lhs: `Self`, rhs: `Self`) -> Vector2<Scalar>
-
Declaration
Swift
public static func - (lhs: `Self`, rhs: `Self`) -> Vector2<Scalar>
-
Declaration
Swift
public static func + (lhs: `Self`, rhs: Scalar) -> Vector2<Scalar>
-
Declaration
Swift
public static func - (lhs: `Self`, rhs: Scalar) -> Vector2<Scalar>
-
A unit-value
Vector2Type
value where each component corresponds to its representation of1
.Declaration
Swift
public static var one: `Self` { get }
-
Calculates the dot product between this and another provided
Vector2Type
Declaration
Swift
public func dot(_ other: `Self`) -> Scalar
-
Declaration
Swift
public static func * (lhs: `Self`, rhs: `Self`) -> Vector2<Scalar>
-
Declaration
Swift
public static func * (lhs: `Self`, rhs: Scalar) -> Vector2<Scalar>
-
Declaration
Swift
public static func * (lhs: Scalar, rhs: `Self`) -> Vector2<Scalar>
-
Returns a
Vector2
where each component is the absolute value of the components of thisVector2
.Declaration
Swift
public var absolute: `Self` { get }
-
Declaration
Swift
public var sign: `Self` { get }
-
Negates this Vector
Declaration
Swift
public prefix static func - (lhs: `Self`) -> Vector2<Scalar>
-
Makes this Vector perpendicular to its current position relative to the origin. This alters the vector instance.
Declaration
Swift
public mutating func formPerpendicular()
-
Returns a Vector perpendicular to this Vector relative to the origin.
Declaration
Swift
public func perpendicular() -> Vector2<Scalar>
-
Returns a vector that represents this vector’s point, rotated 90º counter clockwise (in Cartesian space with Y growing up) relative to the origin.
Declaration
Swift
public func leftRotated() -> Vector2<Scalar>
-
Rotates this vector 90º counter clockwise (in Cartesian space with Y growing up) relative to the origin. This alters the vector instance.
Declaration
Swift
public mutating func formLeftRotated()
-
Returns a vector that represents this vector’s point, rotated 90º clockwise clockwise (in Cartesian space with Y growing up) relative to the origin.
Declaration
Swift
public func rightRotated() -> Vector2<Scalar>
-
Rotates this vector 90º clockwise relative (in Cartesian space with Y growing up) to the origin. This alters the vector instance.
Declaration
Swift
public mutating func formRightRotated()
-
Declaration
Swift
public static func / (lhs: `Self`, rhs: `Self`) -> Vector2<Scalar>
-
Declaration
Swift
public static func / (lhs: `Self`, rhs: Scalar) -> Vector2<Scalar>
-
Declaration
Swift
public static func / (lhs: Scalar, rhs: `Self`) -> Vector2<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
public func addingProduct(_ a: `Self`, _ b: `Self`) -> Vector2<Scalar>
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
public func addingProduct(_ a: Scalar, _ b: `Self`) -> Vector2<Scalar>
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
public func addingProduct(_ a: `Self`, _ b: Scalar) -> Vector2<Scalar>
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
Vector2Type
using a givenFloatingPointRoundingRule
.Declaration
Swift
public func rounded(_ rule: FloatingPointRoundingRule) -> Vector2<Scalar>
-
Rounds the components of this
Vector2Type
using a givenFloatingPointRoundingRule.toNearestOrAwayFromZero
.Equivalent to calling C’s round() function on each component.
Declaration
Swift
public func rounded() -> Vector2<Scalar>
-
Rounds the components of this
Vector2Type
using a givenFloatingPointRoundingRule.up
.Equivalent to calling C’s ceil() function on each component.
Declaration
Swift
public func ceil() -> Vector2<Scalar>
-
Rounds the components of this
Vector2Type
using a givenFloatingPointRoundingRule.down
.Equivalent to calling C’s floor() function on each component.
Declaration
Swift
public func floor() -> Vector2<Scalar>
-
Declaration
Swift
public static func % (lhs: `Self`, rhs: `Self`) -> Vector2<Scalar>
-
Declaration
Swift
public static func % (lhs: `Self`, rhs: Scalar) -> Vector2<Scalar>
-
Declaration
Swift
public func signedDistance(to other: `Self`) -> Scalar
-
Declaration
Swift
public init<V>(_ vec: V) where V : Vector2Type, V.Scalar : BinaryInteger
-
Declaration
Swift
public static func pow(_ vec: `Self`, _ exponent: Int) -> Vector2<Scalar>
-
Declaration
Swift
public static func pow(_ vec: `Self`, _ exponent: `Self`) -> Vector2<Scalar>
-
Returns the angle in radians of the line formed by tracing from the origin (0, 0) to this
Vector2
.Declaration
Swift
public var angle: Scalar { get }
-
Returns a rotated version of this vector, rotated around the origin by a given angle in radians
Declaration
Swift
public func rotated(by angle: Angle<Scalar>) -> Vector2<Scalar>
-
Rotates this vector around the origin by a given angle in radians
Declaration
Swift
public mutating func rotate(by angle: Angle<Scalar>)
-
Rotates this vector around a given pivot by a given angle in radians
Declaration
Swift
@inlinable public func rotated(by angle: Angle<Scalar>, around pivot: `Self`) -> Vector2<Scalar>
-
Rotates a given vector around the origin by an angle in radians
Declaration
Swift
@inlinable public static func rotate(_ vec: `Self`, by angle: Angle<Scalar>) -> Vector2<Scalar>
-
Creates a matrix that when multiplied with a Vector object applies the given set of transformations.
If all default values are set, an identity matrix is created, which does not alter a Vector’s coordinates once applied.
The order of operations are: scaling -> rotation -> translation
-
Declaration
Swift
public static func * (lhs: `Self`, rhs: Matrix3x2<Scalar>) -> Vector2<Scalar>
-
Declaration
Swift
public static func *= (lhs: inout `Self`, rhs: Matrix3x2<Scalar>)