Vector2F

value class Vector2F

Represents a vector of two single-precision 32-bit IEEE 754 floating point numbers.

On the JVM, non-nullable values of this type are represented as values of the primitive type long.

Constructors

Link copied to clipboard
constructor(x: Float, y: Float)

Constructs a new vector with given x and y components.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns the length of this vector.

Link copied to clipboard

Returns the magnitude of this vector.

Link copied to clipboard

Returns a normalized copy of this vector if this vector magnitude is large enough to safely normalize. Else returns ZERO.

Link copied to clipboard

Returns the squared length of this vector.

Link copied to clipboard

Returns the squared magnitude of this vector.

Link copied to clipboard
val x: Float

First component of the vector.

Link copied to clipboard

Returns a vector composed of two x components of this vector.

Link copied to clipboard

Returns a vector composed of x and y components of this vector, respectively.

Link copied to clipboard
val y: Float

Second component of the vector.

Link copied to clipboard

Returns vector composed of y and x components of this vector, respectively.

Link copied to clipboard

Returns a vector composed of two y components of this vector.

Functions

Link copied to clipboard
fun angleTo(other: Vector2F): AngleF

Returns the smallest angle between this vector and the other vector. Angle is signed when the shortest angular path from this vector to the other vector is clockwise.

Link copied to clipboard
inline fun coerceAtLeast(minimum: Vector2F): Vector2F

Returns a vector composed of x and y components that are not less than the specified minimum components.

Link copied to clipboard
inline fun coerceAtMost(maximum: Vector2F): Vector2F

Returns a vector composed of x and y components that are not greater than the specified maximum components.

Link copied to clipboard
inline fun coerceIn(minimum: Vector2F, maximum: Vector2F): Vector2F

Returns a vector composed of x and y components coerced to specified range of minimum..maximum.

Link copied to clipboard
inline operator fun component1(): Float

Returns the x component of this vector.

Link copied to clipboard
inline operator fun component2(): Float

Returns the y component of this vector.

Link copied to clipboard
inline fun copy(x: Float = this.x, y: Float = this.y): Vector2F

Returns a copy of this instance with specified properties altered.

Link copied to clipboard
inline fun distanceTo(other: Vector2F): Float

Returns the distance from this vector to the other.

Link copied to clipboard
inline operator fun div(other: ComplexF): Vector2F

Divides this vector by the other complex number.

inline operator fun div(other: Vector2F): ComplexF

Divides this vector by the other vector.

inline operator fun div(other: Float): Vector2F

Divides this vector by the other scalar.

Link copied to clipboard
infix inline fun dividedComponentWiseBy(other: Vector2F): Vector2F

Divides this vector by the other vector component-wise.

Link copied to clipboard
infix inline fun dot(other: Vector2F): Float

Returns the dot product of this and the other vector.

Link copied to clipboard
inline operator fun get(index: Int): Float

Returns a component specified by an index.

Link copied to clipboard
inline fun isApproximately(other: Vector2F, epsilon: Float = 1.0E-5f): Boolean

Returns a value indicating whether this vector is approximately the other vector given the specified epsilon tolerance.

Link copied to clipboard
inline operator fun minus(other: Vector2F): Vector2F

Subtracts the other vector from this vector.

Link copied to clipboard
infix inline fun multipliedComponentWiseBy(other: Vector2F): Vector2F

Multiplies this vector by the other vector component-wise.

Link copied to clipboard
inline fun normalizedOrElse(defaultValue: Vector2F): Vector2F

Returns a normalized copy of this vector if this vector magnitude is large enough to safely normalize. Else returns defaultValue.

inline fun normalizedOrElse(defaultValue: () -> Vector2F): Vector2F

Returns a normalized copy of this vector if this vector magnitude is large enough to safely normalize. Else returns the result of calling the defaultValue function.

Link copied to clipboard
infix inline fun perpDot(other: Vector2F): Float

Returns the perp dot product of this and the other vector.

Link copied to clipboard
inline operator fun plus(other: Vector2F): Vector2F

Adds the other vector to this vector.

Link copied to clipboard
inline fun rotationTo(other: Vector2F): ComplexF

Returns a normalized complex number which represent rotation from this vector to the other vector.

Link copied to clipboard
inline fun squaredDistanceTo(other: Vector2F): Float

Returns the squared distance from this vector to the other.

Link copied to clipboard
inline operator fun times(other: ComplexF): Vector2F

Multiplies this vector by the other complex number.

inline operator fun times(other: Vector2F): ComplexF

Multiplies this vector by the other vector.

inline operator fun times(other: Float): Vector2F

Multiplies this vector by the other scalar.

Link copied to clipboard

Converts this Vector2F value to ComplexF, where x and y represents the real and imaginary parts of a complex number.

Link copied to clipboard
open override fun toString(): String

Returns a String representation of this vector in "Vector2F(x=x, y=y)" format.

Link copied to clipboard
inline fun toVector2I(): Vector2I

Converts this Vector2F value to Vector2I.

Link copied to clipboard
inline operator fun unaryMinus(): Vector2F

Returns the negative of this vector.

Link copied to clipboard
inline operator fun unaryPlus(): Vector2F

Returns this vector.