2.9 KiB
2.9 KiB
| outline | description | package |
|---|---|---|
| deep | A 2-dimensional vector, set of coordinates or dimensions | @prozilla-os/core |
Class Vector2
{{ $frontmatter.description }}
Constructor
new Vector2(x, y)
Parameters
x
- Type:
number
y
- Optional
- Type:
number
Examples
new Vector2(2, 4)
// Result: Vector2(2, 4)
new Vector2(3)
// Result: Vector2(3, 3)
Properties
x
- Type:
number
y
- Type:
number
ZERO
Returns a vector with each value set to zero
-
Static
-
Type:
Vector2 -
Example
Vector2.ZERO // Result: Vector2(0, 0)
clone
Returns a clone of this vector
- Type:
Vector2
Methods
round()
Round the values of this vector to whole numbers
::: details
-
Returns
- Type:
this
- Type:
-
Example
new Vector2(3.6, 1.3).round() // Result: Vector2(4, 1)
:::
getDistance(x, y)
Get the distance between this vector and another
::: details
- Parameters
- x
- Type:
number
- Type:
- y
- Type:
number
- Type:
- x
- Returns
- Type:
number
- Type:
:::
getDistance(vector2)
Get the distance between this vector and another
::: details
- Parameters
- vector2
- Type:
Vector2
- Type:
- vector2
- Returns
- Type:
number
- Type:
:::
add(vector2A, vector2B)
Add two vectors together
::: details
- Static
- Parameters
- vector2A
- Type:
Vector2
- Type:
- vector2B
- Type:
Vector2
- Type:
- vector2A
- Returns
- Type:
Vector2
- Type:
:::
subtract(vector2A, vector2B)
Subtract two vectors
::: details
- Static
- Parameters
- vector2A
- Type:
Vector2
- Type:
- vector2B
- Type:
Vector2
- Type:
- vector2A
- Returns
- Type:
Vector2
- Type:
:::
scale(vector2, scalar)
Scale a vector
::: details
- Static
- Parameters
- vector2
- Type:
Vector2
- Type:
- scalar
- Type:
number
- Type:
- vector2
- Returns
- Type:
Vector2
- Type:
:::
magnitude(vector2)
Get the magnitude of a vector
::: details
- Static
- Parameters
- vector2
- Type:
Vector2
- Type:
- vector2
- Returns
- Type:
number
- Type:
:::
normalize(vector2)
Normalize a vector
::: details
- Static
- Parameters
- vector2
- Type:
Vector2
- Type:
- vector2
- Returns
- Type:
Vector2
- Type:
:::
sqrDistance (vector2A, vector2B)
Get the square distance between two vectors
::: details
- Static
- Parameters
- vector2A
- Type:
Vector2
- Type:
- vector2B
- Type:
Vector2
- Type:
- vector2A
- Returns
- Type:
number
- Type:
:::
lerp(vector2A, vector2B, t)
Lerp between two vectors
::: details
- Static
- Parameters
- vector2A
- Type:
Vector2
- Type:
- vector2B
- Type:
Vector2
- Type:
- t
- Type:
number
- Type:
- vector2A
- Returns
- Type:
Vector2
- Type:
:::