Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace vec2

Index

Functions

add

  • add(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
  • Adds two vec2's

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec2

    out

angle

  • angle(a: ReadonlyVec2, b: ReadonlyVec2): number
  • Get the angle between two 2D vectors

    Parameters

    • a: ReadonlyVec2

      The first operand

    • b: ReadonlyVec2

      The second operand

    Returns number

    The angle in radians

ceil

  • ceil(out: vec2, a: ReadonlyVec2): vec2
  • Math.ceil the components of a vec2

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      vector to ceil

    Returns vec2

    out

clone

  • clone(a: ReadonlyVec2): vec2
  • Creates a new vec2 initialized with values from an existing vector

    Parameters

    • a: ReadonlyVec2

      vector to clone

    Returns vec2

    a new 2D vector

copy

  • copy(out: vec2, a: ReadonlyVec2): vec2
  • Copy the values from one vec2 to another

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the source vector

    Returns vec2

    out

create

  • Creates a new, empty vec2

    Returns vec2

    a new 2D vector

cross

  • cross(out: vec3, a: ReadonlyVec2, b: ReadonlyVec2): vec3
  • Computes the cross product of two vec2's Note that the cross product must by definition produce a 3D vector

    Parameters

    • out: vec3

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec3

    out

dist

  • dist(a: ReadonlyVec2, b: ReadonlyVec2): number
  • Calculates the euclidian distance between two vec2's

    Parameters

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns number

    distance between a and b

distance

  • distance(a: ReadonlyVec2, b: ReadonlyVec2): number
  • Calculates the euclidian distance between two vec2's

    Parameters

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns number

    distance between a and b

div

  • div(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
  • Divides two vec2's

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec2

    out

divide

  • divide(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
  • Divides two vec2's

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec2

    out

dot

  • dot(a: ReadonlyVec2, b: ReadonlyVec2): number
  • Calculates the dot product of two vec2's

    Parameters

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns number

    dot product of a and b

equals

  • equals(a: ReadonlyVec2, b: ReadonlyVec2): boolean
  • Returns whether or not the vectors have approximately the same elements in the same position.

    Parameters

    • a: ReadonlyVec2

      The first vector.

    • b: ReadonlyVec2

      The second vector.

    Returns boolean

    True if the vectors are equal, false otherwise.

exactEquals

  • exactEquals(a: ReadonlyVec2, b: ReadonlyVec2): boolean
  • Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)

    Parameters

    • a: ReadonlyVec2

      The first vector.

    • b: ReadonlyVec2

      The second vector.

    Returns boolean

    True if the vectors are equal, false otherwise.

floor

  • floor(out: vec2, a: ReadonlyVec2): vec2
  • Math.floor the components of a vec2

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      vector to floor

    Returns vec2

    out

forEach

  • forEach(a: any, stride: any, offset: any, count: any, fn: any, arg: any): any
  • Parameters

    • a: any
    • stride: any
    • offset: any
    • count: any
    • fn: any
    • arg: any

    Returns any

fromValues

  • fromValues(x: number, y: number): vec2
  • Creates a new vec2 initialized with the given values

    Parameters

    • x: number

      X component

    • y: number

      Y component

    Returns vec2

    a new 2D vector

inverse

  • inverse(out: vec2, a: ReadonlyVec2): vec2
  • Returns the inverse of the components of a vec2

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      vector to invert

    Returns vec2

    out

len

  • len(a: ReadonlyVec2): number
  • Calculates the length of a vec2

    Parameters

    • a: ReadonlyVec2

      vector to calculate length of

    Returns number

    length of a

length

  • length(a: ReadonlyVec2): number
  • Calculates the length of a vec2

    Parameters

    • a: ReadonlyVec2

      vector to calculate length of

    Returns number

    length of a

lerp

  • lerp(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, t: number): vec2
  • Performs a linear interpolation between two vec2's

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    • t: number

      interpolation amount, in the range [0-1], between the two inputs

    Returns vec2

    out

max

  • max(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
  • Returns the maximum of two vec2's

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec2

    out

min

  • min(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
  • Returns the minimum of two vec2's

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec2

    out

mul

  • mul(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
  • Multiplies two vec2's

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec2

    out

multiply

  • multiply(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
  • Multiplies two vec2's

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec2

    out

negate

  • negate(out: vec2, a: ReadonlyVec2): vec2
  • Negates the components of a vec2

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      vector to negate

    Returns vec2

    out

normalize

  • normalize(out: vec2, a: ReadonlyVec2): vec2
  • Normalize a vec2

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      vector to normalize

    Returns vec2

    out

random

  • random(out: vec2, scale?: number): vec2
  • Generates a random vector with the given scale

    Parameters

    • out: vec2

      the receiving vector

    • Optional scale: number

    Returns vec2

    out

rotate

  • rotate(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, rad: number): vec2
  • Rotate a 2D vector

    Parameters

    • out: vec2

      The receiving vec2

    • a: ReadonlyVec2

      The vec2 point to rotate

    • b: ReadonlyVec2

      The origin of the rotation

    • rad: number

      The angle of rotation in radians

    Returns vec2

    out

round

  • round(out: vec2, a: ReadonlyVec2): vec2
  • Math.round the components of a vec2

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      vector to round

    Returns vec2

    out

scale

  • scale(out: vec2, a: ReadonlyVec2, b: number): vec2
  • Scales a vec2 by a scalar number

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the vector to scale

    • b: number

      amount to scale the vector by

    Returns vec2

    out

scaleAndAdd

  • scaleAndAdd(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, scale: number): vec2
  • Adds two vec2's after scaling the second operand by a scalar value

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    • scale: number

      the amount to scale b by before adding

    Returns vec2

    out

set

  • set(out: vec2, x: number, y: number): vec2
  • Set the components of a vec2 to the given values

    Parameters

    • out: vec2

      the receiving vector

    • x: number

      X component

    • y: number

      Y component

    Returns vec2

    out

sqrDist

  • sqrDist(a: ReadonlyVec2, b: ReadonlyVec2): number
  • Calculates the squared euclidian distance between two vec2's

    Parameters

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns number

    squared distance between a and b

sqrLen

  • sqrLen(a: ReadonlyVec2): number
  • Calculates the squared length of a vec2

    Parameters

    • a: ReadonlyVec2

      vector to calculate squared length of

    Returns number

    squared length of a

squaredDistance

  • squaredDistance(a: ReadonlyVec2, b: ReadonlyVec2): number
  • Calculates the squared euclidian distance between two vec2's

    Parameters

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns number

    squared distance between a and b

squaredLength

  • squaredLength(a: ReadonlyVec2): number
  • Calculates the squared length of a vec2

    Parameters

    • a: ReadonlyVec2

      vector to calculate squared length of

    Returns number

    squared length of a

str

  • str(a: ReadonlyVec2): string
  • Returns a string representation of a vector

    Parameters

    • a: ReadonlyVec2

      vector to represent as a string

    Returns string

    string representation of the vector

sub

  • sub(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
  • Subtracts vector b from vector a

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec2

    out

subtract

  • subtract(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
  • Subtracts vector b from vector a

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the first operand

    • b: ReadonlyVec2

      the second operand

    Returns vec2

    out

transformMat2

  • transformMat2(out: vec2, a: ReadonlyVec2, m: ReadonlyMat2): vec2
  • Transforms the vec2 with a mat2

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the vector to transform

    • m: ReadonlyMat2

      matrix to transform with

    Returns vec2

    out

transformMat2d

  • transformMat2d(out: vec2, a: ReadonlyVec2, m: ReadonlyMat2d): vec2
  • Transforms the vec2 with a mat2d

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the vector to transform

    • m: ReadonlyMat2d

      matrix to transform with

    Returns vec2

    out

transformMat3

  • transformMat3(out: vec2, a: ReadonlyVec2, m: ReadonlyMat3): vec2
  • Transforms the vec2 with a mat3 3rd vector component is implicitly '1'

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the vector to transform

    • m: ReadonlyMat3

      matrix to transform with

    Returns vec2

    out

transformMat4

  • transformMat4(out: vec2, a: ReadonlyVec2, m: ReadonlyMat4): vec2
  • Transforms the vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'

    Parameters

    • out: vec2

      the receiving vector

    • a: ReadonlyVec2

      the vector to transform

    • m: ReadonlyMat4

      matrix to transform with

    Returns vec2

    out

zero

  • Set the components of a vec2 to zero

    Parameters

    • out: vec2

      the receiving vector

    Returns vec2

    out