ImmutableVector2

Represent an immutable vector 2D

You may use ImmutableVector2.toMutable to create a (mutable) Vector2 from a an ImmutableVector2. And an ImmutableVector2 can be created from a Vector2 with Vector2.toImmutable.

Constructors

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

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open val len: Float

Returns the euclidean length

Link copied to clipboard
open override val len2: Float

Returns the squared euclidean length

Link copied to clipboard
open override val nor: ImmutableVector2

Returns the unit vector of same direction or this vector if it is zero.

Link copied to clipboard
val x: Float

the x-component of this vector

Link copied to clipboard
val y: Float

the y-component of this vector

Functions

Link copied to clipboard
Link copied to clipboard
inline fun angle(reference: ImmutableVector2 = X): Float
Link copied to clipboard
inline fun ImmutableVector2.angleDeg(reference: ImmutableVector2 = ImmutableVector2.X): Float

Returns the angle in degrees of this vector relative to the reference. Angles are towards the positive y-axis (typically counter-clockwise.) between -180 and +180

inline fun ImmutableVector2.angleDeg(referenceX: Float, referenceY: Float): Float

Returns the angle in degrees of this vector relative to the reference vector described by referenceX and referenceY.

Link copied to clipboard
fun angleRad(reference: ImmutableVector2 = X): Float

Returns the angle in radians of this vector relative to the reference. Angles are towards the positive y-axis. (typically counter-clockwise)

fun angleRad(referenceX: Float, referenceY: Float): Float

Returns the angle in radians of this vector relative to the (referenceX, referenceY) reference. Angles are towards the positive y-axis. (typically counter-clockwise)

Link copied to clipboard
open fun clamp(min: Float, max: Float): ImmutableVector2
Link copied to clipboard
open operator override fun compareTo(other: ImmutableVector2): Int
Link copied to clipboard
Link copied to clipboard
fun crs(otherX: Float, otherY: Float): Float

Calculates the 2D cross product between this and the (otherX, otherY) vector

Link copied to clipboard
infix inline fun ImmutableVector2.crs(other: ImmutableVector2): Float

Calculates the 2D cross product between this and the other vector

Link copied to clipboard
open operator override fun dec(): ImmutableVector2

Returns a new vector instance with all members decremented by 1

Link copied to clipboard
open infix override fun dot(vector: ImmutableVector2): Float

Returns the dot product of this vector by the given vector

fun dot(otherX: Float, otherY: Float): Float

Returns the dot product of this vector by the given (otherX, otherY) vector

Link copied to clipboard
fun dst(otherX: Float, otherY: Float): Float
Link copied to clipboard
open infix override fun dst2(vector: ImmutableVector2): Float

Returns the squared distance between this and the other vector

fun dst2(otherX: Float, otherY: Float): Float

Returns the squared distance between this and the (otherX, otherY) vector

Link copied to clipboard
open override fun epsilonEquals(other: ImmutableVector2, epsilon: Float): Boolean

Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing

fun epsilonEquals(otherX: Float, otherY: Float, epsilon: Float): Boolean

Compares this vector with the (otherX, otherY) vector, using the supplied epsilon for fuzzy equality testing

Link copied to clipboard
open operator override fun inc(): ImmutableVector2

Returns a new vector instance with all members incremented by 1

Link copied to clipboard
open fun interpolate(target: ImmutableVector2, alpha: Float, interpolator: Interpolation): ImmutableVector2
Link copied to clipboard
open override fun isOnLine(other: ImmutableVector2, epsilon: Float): Boolean

Returns true if this vector is on-line with the other vector (either in the same or the opposite direction)

Link copied to clipboard
open fun isUnit(margin: Float = MathUtils.FLOAT_ROUNDING_ERROR): Boolean

Returns whether this vector is a unit length vector within the given margin. (no margin by default)

Link copied to clipboard
open override fun isZero(margin: Float): Boolean

Returns whether the length of this vector is smaller than the given margin

Link copied to clipboard
open fun lerp(target: ImmutableVector2, alpha: Float): ImmutableVector2
Link copied to clipboard
open fun limit(limit: Float): ImmutableVector2
Link copied to clipboard
open fun limit2(limit2: Float): ImmutableVector2
Link copied to clipboard
open operator override fun minus(other: ImmutableVector2): ImmutableVector2

Returns the result of subtracting the other vector from this vector

fun minus(deltaX: Float = 0.0f, deltaY: Float = 0.0f): ImmutableVector2

Returns the result of subtracting the (deltaX, deltaY) vector from this vector

Link copied to clipboard
fun mul(matrix: Matrix3): ImmutableVector2
Link copied to clipboard
Link copied to clipboard
open fun nor(): ImmutableVector2
Link copied to clipboard
open operator override fun plus(other: ImmutableVector2): ImmutableVector2

Returns the result of adding the other vector to this vector

fun plus(deltaX: Float = 0.0f, deltaY: Float = 0.0f): ImmutableVector2

Returns the result of adding the given (deltaX, deltaY) vector to this vector

Link copied to clipboard
inline fun rotate(angle: Float): ImmutableVector2
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
operator fun times(transformation: Affine2): ImmutableVector2

Apply the given affine transformation and return the resulting vector

open operator override fun times(scalar: Float): ImmutableVector2

Returns a new vector instance scaled by the given scalar

open operator override fun times(vector: ImmutableVector2): ImmutableVector2

Returns a new vector instance scaled by the given vector

fun times(factorX: Float, factorY: Float): ImmutableVector2

Returns a new vector instance scaled by the given factorX and factorY factors

Link copied to clipboard
inline fun ImmutableVector2.toMutable(): Vector2
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open operator override fun unaryMinus(): ImmutableVector2

Returns the opposite vector of same length

Link copied to clipboard

Returns a vector of same length with the given angle in degree

Link copied to clipboard

Returns a vector of same length with the given angle in radians

Link copied to clipboard
open fun withClamp(min: Float, max: Float): ImmutableVector2

Returns a vector of same direction and the length clamped between min and max

Link copied to clipboard
open override fun withClamp2(min2: Float, max2: Float): ImmutableVector2

Returns a vector of same direction and the squared length clamped between min2 and max2

Link copied to clipboard
open fun withInterpolation(target: ImmutableVector2, alpha: Float, interpolation: Interpolation): ImmutableVector2

Returns the result of interpolation between this vector and the given target vector by alpha (within range 0,1) using the given interpolation method.

Link copied to clipboard
open fun withLength(length: Float): ImmutableVector2

Returns a vector of same direction and the given length

Link copied to clipboard
open override fun withLength2(length2: Float): ImmutableVector2

Returns a vector of the same direction and a squared length of length2

Link copied to clipboard
open override fun withLerp(target: ImmutableVector2, alpha: Float): ImmutableVector2

Linearly interpolates between this vector and the target vector by alpha

Link copied to clipboard
open fun withLimit(limit: Float): ImmutableVector2

Returns this vector if the ImmutableVector.len is <= limit or a vector with the same direction and length limit otherwise

Link copied to clipboard
open override fun withLimit2(limit2: Float): ImmutableVector2

Returns this vector if the ImmutableVector.len2 is <= limit2 or a vector with the same direction and length limit2 otherwise

Link copied to clipboard

Returns a vector of same length and a random direction.

Link copied to clipboard

Returns a vector of same length rotated by 90 degrees in the given direction

Link copied to clipboard

Returns a vector of same length rotated by the given angle in degree

Link copied to clipboard

Returns a vector of same length rotated by the given angle in radians

Link copied to clipboard
infix inline fun ImmutableVector2.x(other: ImmutableVector2): Float

Calculates the 2D cross product between this and the other vector