Vector2

Vector2

Creates two-dimensional vectors.

Constructor

new Vector2($x, $y)

Description:
  • Creates a new two-dimensional vector.
Source:
Examples
// without chaining
const vector = new Vector2(3, 2);
vector.add(new Vector2(1, 0));
// with chaining
const vector = new Vector2(3, 2).add(new Vector2(1, 0));
Parameters:
Name Type Description
$x number The x component of the vector to create.
$y number The y component of the vector to create.

Members

x :number

Description:
  • Gets the x component.
Source:
Gets the x component.
Type:
  • number

y :number

Description:
  • Gets the y component.
Source:
Gets the y component.
Type:
  • number

Methods

add($vector) → {this}

Description:
  • Adds the given vector.
Source:
Parameters:
Name Type Description
$vector Vector2 The vector to add.
Returns:
Type
this

clone() → {Vector2}

Description:
  • Clones the vector.
Source:
Returns:
Type
Vector2

equal($vector) → {boolean}

Description:
  • Checks the equality with the given vector.
Source:
Parameters:
Name Type Description
$vector Vector2 The vector to check with.
Returns:
Type
boolean

length() → {number}

Description:
  • Gets the length of the vector.
Source:
Returns:
Type
number

multiply($vector) → {this}

Description:
  • Multiplies with the given vector.
Source:
Parameters:
Name Type Description
$vector Vector2 The vector to multiply with.
Returns:
Type
this

negate() → {this}

Description:
  • Negates the vector.
Source:
Returns:
Type
this

normalize() → {this}

Description:
  • Normalizes the vector.
Source:
Returns:
Type
this

rotate($angle) → {this}

Description:
  • Rotates the vector by the given angle.
Source:
Parameters:
Name Type Description
$angle number The angle of rotation to apply (in degrees) (clockwise).
Returns:
Type
this

scale($factor) → {this}

Description:
  • Scales the vector by the given scalar factor.
Source:
Parameters:
Name Type Description
$factor number The scalar factor to multiply with.
Returns:
Type
this

subtract($vector) → {this}

Description:
  • Subtracts the given vector.
Source:
Parameters:
Name Type Description
$vector Vector2 The vector to subtract.
Returns:
Type
this

(static) from($vector) → {Vector2}

Description:
  • Creates a new vector from the given vector.
Source:
Parameters:
Name Type Description
$vector Vector2 The given vector.
Returns:
Type
Vector2