Class Vector2

2D vector.

( class Vector2 implements Vector )

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(x?: number, y?: number): Vector2

Parameters

  • x?: number optional
  • y?: number optional

Returns

Vector2

Properties

public x: number

public y: number

Methods

public add(v: Vector2): Vector2

Adds v to this vector.

Parameters

Returns

Vector2

public addScalar(s: number): Vector2

Parameters

  • s: number

Returns

Vector2

public addVectors(a: Vector2, b: Vector2): Vector2

Sets this vector to a + b.

Parameters

Returns

Vector2

public ceil(): Vector2

Returns

Vector2

public clamp(min: Vector2, max: Vector2): Vector2

Parameters

Returns

Vector2

public clampScalar(min: number, max: number): Vector2

Parameters

  • min: number
  • max: number

Returns

Vector2

public clone(): Vector2

Clones this vector.

Returns

Vector2

public copy(v: Vector2): Vector2

Copies value of v to this vector.

Parameters

Returns

Vector2

public distanceTo(v: Vector2): number

Computes distance of this vector to v.

Parameters

Returns

number

public distanceToSquared(v: Vector2): number

Computes squared distance of this vector to v.

Parameters

Returns

number

public divideScalar(s: number): Vector2

Divides this vector by scalar s. Set vector to ( 0, 0 ) if s == 0.

Parameters

  • s: number

Returns

Vector2

public dot(v: Vector2): number

Computes dot product of this vector and v.

Parameters

Returns

number

public equals(v: Vector2): boolean

Checks for strict equality of this vector and v.

Parameters

Returns

boolean

public floor(): Vector2

Returns

Vector2

public fromArray(xy: Array<number>): Vector2

Parameters

  • xy: Array<number>

Returns

Vector2

public getComponent(index: number): number

Gets a component of this vector.

Parameters

  • index: number

Returns

number

public length(): number

Computes length of this vector.

Returns

number

public lengthSq(): number

Computes squared length of this vector.

Returns

number

public lerp(v: Vector2, alpha: number): Vector2

Parameters

Returns

Vector2

public max(v: Vector2): Vector2

Parameters

Returns

Vector2

public min(v: Vector2): Vector2

Parameters

Returns

Vector2

public multiplyScalar(s: number): Vector2

Multiplies this vector by scalar s.

Parameters

  • s: number

Returns

Vector2

public negate(): Vector2

Inverts this vector.

Returns

Vector2

public normalize(): Vector2

Normalizes this vector.

Returns

Vector2

public round(): Vector2

Returns

Vector2

public roundToZero(): Vector2

Returns

Vector2

public set(x: number, y: number): Vector2

Sets value of this vector.

Parameters

  • x: number
  • y: number

Returns

Vector2

public setComponent(index: number, value: number)

Sets a component of this vector.

Parameters

  • index: number
  • value: number

public setLength(l: number): Vector2

Normalizes this vector and multiplies it by l.

Parameters

  • l: number

Returns

Vector2

public setX(x: number): Vector2

Sets X component of this vector.

Parameters

  • x: number

Returns

Vector2

public setY(y: number): Vector2

Sets Y component of this vector.

Parameters

  • y: number

Returns

Vector2

public sub(v: Vector2): Vector2

Subtracts v from this vector.

Parameters

Returns

Vector2

public subVectors(a: Vector2, b: Vector2): Vector2

Sets this vector to a - b.

Parameters

Returns

Vector2

public toArray(): Array<number>

Returns

Array<number>