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
Vector2Declaration
Swift
@inlinable public var description: String { get } -
Declaration
Swift
public init(x: Scalar, y: Scalar) -
Declaration
Swift
public init(repeating scalar: Scalar) -
Initializes this
Vector2with 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
trueif all components oflhsare greater thanrhs.Performs
lhs.x > rhs.x && lhs.y > rhs.yDeclaration
Swift
public static func > (lhs: `Self`, rhs: `Self`) -> Bool -
Compares two vectors and returns
trueif all components oflhsare greater than or equal torhs.Performs
lhs.x >= rhs.x && lhs.y >= rhs.yDeclaration
Swift
public static func >= (lhs: `Self`, rhs: `Self`) -> Bool -
Compares two vectors and returns
trueif all components oflhsare less thanrhs.Performs
lhs.x < rhs.x && lhs.y < rhs.yDeclaration
Swift
public static func < (lhs: `Self`, rhs: `Self`) -> Bool -
Compares two vectors and returns
trueif all components oflhsare less than or equal torhs.Performs
lhs.x <= rhs.x && lhs.y <= rhs.yDeclaration
Swift
public static func <= (lhs: `Self`, rhs: `Self`) -> Bool
-
A zero-value
Vector2value 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
Vector2Typevalue 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
Vector2TypeDeclaration
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
Vector2where 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
fmafunction on each component.Declaration
Swift
public func addingProduct(_ a: `Self`, _ b: `Self`) -> Vector2<Scalar>Parameters
lhsOne of the vectors to multiply before adding to this vector.
rhsThe other vector to multiply.
Return Value
The product of
lhsandrhs, 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
fmafunction on each component.Declaration
Swift
public func addingProduct(_ a: Scalar, _ b: `Self`) -> Vector2<Scalar>Parameters
lhsA scalar to multiply before adding to this vector.
rhsA vector to multiply.
Return Value
The product of
lhsandrhs, 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
fmafunction on each component.Declaration
Swift
public func addingProduct(_ a: `Self`, _ b: Scalar) -> Vector2<Scalar>Parameters
lhsA vector to multiply before adding to this vector.
rhsA scalar to multiply.
Return Value
The product of
lhsandrhs, added to this vector. -
Rounds the components of this
Vector2Typeusing a givenFloatingPointRoundingRule.Declaration
Swift
public func rounded(_ rule: FloatingPointRoundingRule) -> Vector2<Scalar> -
Rounds the components of this
Vector2Typeusing 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
Vector2Typeusing 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
Vector2Typeusing 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>)