Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vec2

Representation of 2D vectors and points.

Hierarchy

Index

Constructors

constructor

  • newVec2(other: Vec2): Vec2
  • newVec2(x?: undefined | number, y?: undefined | number): Vec2

Properties

x

x: number

x component.

y

y: number

y component.

Static NEG_ONE

NEG_ONE: Readonly<Vec2> = Object.freeze(new Vec2(-1, -1))

Static ONE

ONE: Readonly<Vec2> = Object.freeze(new Vec2(1, 1))

Static UNIT_X

UNIT_X: Readonly<Vec2> = Object.freeze(new Vec2(1, 0))

Static UNIT_Y

UNIT_Y: Readonly<Vec2> = Object.freeze(new Vec2(0, 1))

Static ZERO

ZERO: Readonly<Vec2> = Object.freeze(new Vec2(0, 0))

Methods

add

  • add(other: Vec2): this

add2f

  • add2f(x: number, y: number): this
  • Adds the current vector with another one and return this

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns this

angle

  • angle(other: Vec2): number
  • Calculates radian angle between two vectors

    Parameters

    • other: Vec2

      specified vector

    Returns number

    The angle between the current vector and the specified vector (in radians); if there are zero vectors in the current vector and the specified vector, 0 is returned.

clampf

  • clampf(minInclusive: Vec2, maxInclusive: Vec2): this
  • Clamp the vector between minInclusive and maxInclusive.

    Parameters

    • minInclusive: Vec2

      Minimum value allowed

    • maxInclusive: Vec2

      Maximum value allowed

    Returns this

    this

clone

cross

  • cross(other: Vec2): number

divide

  • divide(other: Vec2): this
  • Element-wisely divides this vector with another one, and return this.

    Parameters

    • other: Vec2

      specified vector

    Returns this

divide2f

  • divide2f(x: number, y: number): this
  • Element-wisely divides this vector with another one, and return this.

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns this

dot

  • dot(other: Vec2): number
  • Calculates the dot product with another vector

    Parameters

    • other: Vec2

      specified vector

    Returns number

    The result of calculates the dot product with another vector

equals

  • equals(other: Vec2, epsilon?: number): boolean
  • Check whether the vector approximately equals another one.

    Parameters

    • other: Vec2

      Specified vector

    • Default value epsilon: number = EPSILON

      The error allowed. It`s should be a non-negative number.

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

equals2f

  • equals2f(x: number, y: number, epsilon?: number): boolean
  • Check whether the vector approximately equals another one.

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    • Default value epsilon: number = EPSILON

      The error allowed. It`s should be a non-negative number.

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

length

  • length(): number

lengthSqr

  • lengthSqr(): number

lerp

  • lerp(to: Vec2, ratio: number): this
  • Calculate linear interpolation result between this vector and another one with given ratio.

    Parameters

    • to: Vec2

      Target vector

    • ratio: number

      The interpolation coefficient.The range is [0,1].

    Returns this

multiply

  • multiply(other: Vec2): this
  • Multiplies the current vector with another one and return this

    Parameters

    • other: Vec2

      specified vector

    Returns this

multiply2f

  • multiply2f(x: number, y: number): this
  • Multiplies the current vector with another one and return this

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns this

multiplyScalar

  • multiplyScalar(scalar: number): this
  • Multiplies the current vector with a number, and returns this.

    Parameters

    • scalar: number

      scalar number

    Returns this

negative

  • negative(): this

normalize

  • normalize(): this

project

  • project(other: Vec2): this

rotate

  • rotate(radians: number): this
  • Rotates the current vector by an angle in radian value

    Parameters

    • radians: number

      radius of rotation

    Returns this

set

  • set(other: Vec2): any
  • set(x?: undefined | number, y?: undefined | number): any

signAngle

  • signAngle(other: Vec2): number
  • Get angle in radian between this and vector with direction.

    Parameters

    • other: Vec2

      specified vector

    Returns number

    The signed angle between the current vector and the specified vector (in radians); if there is a zero vector in the current vector and the specified vector, 0 is returned.

strictEquals

  • strictEquals(other: Vec2): boolean
  • Check whether the current vector strictly equals another Vec2.

    Parameters

    • other: Vec2

      specified vector

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

strictEquals2f

  • strictEquals2f(x: number, y: number): boolean
  • Check whether the current vector strictly equals another Vec2.

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

subtract

  • subtract(other: Vec2): this

subtract2f

  • subtract2f(x: number, y: number): this
  • Subtracts one vector from this, and returns this.

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns this

toString

  • toString(): string

transformMat4

  • transformMat4(matrix: Mat4): this
  • Transforms the vec2 with a mat4. 3rd vector component is implicitly '0', 4th vector component is implicitly '1'

    Parameters

    • matrix: Mat4

      matrix to transform with

    Returns this

Static add

  • add<Out>(out: Out, a: Out, b: Out): Out
  • Element-wise vector addition and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static angle

  • angle<Out>(a: Out, b: Out): number

Static ceil

  • ceil<Out>(out: Out, a: Out): Out
  • Rounds up by elements of the vector and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out

    Returns Out

Static clone

  • clone<Out>(a: Out): Vec2

Static copy

  • copy<Out>(out: Out, a: Out): Out

Static cross

  • cross<Out>(out: Vec3, a: Out, b: Out): Vec3

Static distance

  • distance<Out>(a: Out, b: Out): number

Static divide

  • divide<Out>(out: Out, a: Out, b: Out): Out
  • Element-wise vector division and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static dot

  • dot<Out>(a: Out, b: Out): number

Static equals

  • equals<Out>(a: Out, b: Out, epsilon?: number): boolean
  • Check whether the two given vectors are approximately equivalent

    Type parameters

    Parameters

    • a: Out
    • b: Out
    • Default value epsilon: number = EPSILON

    Returns boolean

Static floor

  • floor<Out>(out: Out, a: Out): Out
  • Element-wise rounds down of the current vector and save the results to the out vector

    Type parameters

    Parameters

    • out: Out
    • a: Out

    Returns Out

Static fromArray

  • fromArray<Out>(out: Out, arr: IWritableArrayLike<number>, ofs?: number): Out
  • Converts the given array to a vector

    Type parameters

    Parameters

    • out: Out
    • arr: IWritableArrayLike<number>
    • Default value ofs: number = 0

      Array Start Offset

    Returns Out

Static inverse

  • inverse<Out>(out: Out, a: Out): Out
  • Sets each element to its inverse value, zero value will become Infinity

    Type parameters

    Parameters

    • out: Out
    • a: Out

    Returns Out

Static inverseSafe

  • inverseSafe<Out>(out: Out, a: Out): Out

Static len

  • len<Out>(a: Out): number

Static lengthSqr

  • lengthSqr<Out>(a: Out): number

Static lerp

  • lerp<Out>(out: Out, a: Out, b: Out, t: number): Out
  • Calculates the linear interpolation between two vectors with a given ratio

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out
    • t: number

    Returns Out

Static max

  • max<Out>(out: Out, a: Out, b: Out): Out
  • Calculates element-wise maximum values and save to the out vector

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static min

  • min<Out>(out: Out, a: Out, b: Out): Out
  • Calculates element-wise minimum values and save to the out vector

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static multiply

  • multiply<Out>(out: Out, a: Out, b: Out): Out
  • Element-wise vector multiplication and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static multiplyScalar

  • multiplyScalar<Out>(out: Out, a: Out, b: number): Out
  • Vector scalar multiplication and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: number

    Returns Out

Static negate

  • negate<Out>(out: Out, a: Out): Out

Static normalize

  • normalize<Out, Vec2Like>(out: Out, a: Vec2Like): Out

Static random

  • random<Out>(out: Out, scale?: undefined | number): Out
  • Generates a uniformly distributed random vector points from center to the surface of the unit sphere

    Type parameters

    Parameters

    • out: Out
    • Optional scale: undefined | number

      vector length

    Returns Out

Static round

  • round<Out>(out: Out, a: Out): Out

Static scaleAndAdd

  • scaleAndAdd<Out>(out: Out, a: Out, b: Out, scale: number): Out
  • Element-wise multiplication and addition with the equation: a + b * scale

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out
    • scale: number

    Returns Out

Static set

  • set<Out>(out: Out, x: number, y: number): Out

Static squaredDistance

  • squaredDistance<Out>(a: Out, b: Out): number

Static str

  • str<Out>(a: Out): string

Static strictEquals

  • strictEquals<Out>(a: Out, b: Out): boolean

Static subtract

  • subtract<Out>(out: Out, a: Out, b: Out): Out
  • Element-wise vector subtraction and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static toArray

  • toArray<Out>(out: Out, v: IVec2Like, ofs?: number): Out
  • Converts the given vector to an array

    Type parameters

    • Out: IWritableArrayLike<number>

    Parameters

    • out: Out
    • v: IVec2Like
    • Default value ofs: number = 0

      Array Start Offset

    Returns Out

Static transformMat3

  • transformMat3<Out, MatLike>(out: Out, a: Out, m: IMat3Like): Out

Static transformMat4

  • transformMat4<Out, MatLike>(out: Out, a: Out, m: IMat4Like): Out

Generated using TypeDoc