A simple Vector object for 2d positions.
Kind: global class
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Boolean
Boolean
Number
Vector2
Number
Number
Number
Number
Number
Number
Vector2
Vector2
Number
Number
Number
Array.<Number>
\*
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Vector2
Number
Number
Number
Number
Number
Number
Number
Vector2
Vector2
Vector2
Create the Vector object.
Param | Type | Default | Description |
---|---|---|---|
x | number |
0 |
Vector X. |
y | number |
0 |
Vector Y. |
Vector2
Clone the vector.
Kind: instance method of Vector2
Returns: Vector2
- cloned vector.
Vector2
Set vector value.
Kind: instance method of Vector2
Returns: Vector2
- this.
Param | Type | Description |
---|---|---|
x | Number |
X component. |
y | Number |
Y component. |
Vector2
Copy values from other vector into self.
Kind: instance method of Vector2
Returns: Vector2
- this.
Vector2
Return a new vector of this + other.
Kind: instance method of Vector2
Returns: Vector2
- result vector.
Param | Type | Description |
---|---|---|
Other | Number | Vector2 |
Vector3 or number to add to all components. |
Vector2
Return a new vector of this - other.
Kind: instance method of Vector2
Returns: Vector2
- result vector.
Param | Type | Description |
---|---|---|
Other | Number | Vector2 |
Vector3 or number to sub from all components. |
Vector2
Return a new vector of this / other.
Kind: instance method of Vector2
Returns: Vector2
- result vector.
Param | Type | Description |
---|---|---|
Other | Number | Vector2 |
Vector3 or number to divide by all components. |
Vector2
Return a new vector of this * other.
Kind: instance method of Vector2
Returns: Vector2
- result vector.
Param | Type | Description |
---|---|---|
Other | Number | Vector2 |
Vector2 or number to multiply with all components. |
Vector2
Return a round copy of this vector.
Kind: instance method of Vector2
Returns: Vector2
- result vector.
Vector2
Return a floored copy of this vector.
Kind: instance method of Vector2
Returns: Vector2
- result vector.
Vector2
Return a ceiled copy of this vector.
Kind: instance method of Vector2
Returns: Vector2
- result vector.
Vector2
Set self values to be min values between self and a given vector.
Kind: instance method of Vector2
Returns: Vector2
- Self.
Param | Type | Description |
---|---|---|
v | Vector2 |
Vector to min with. |
Vector2
Set self values to be max values between self and a given vector.
Kind: instance method of Vector2
Returns: Vector2
- Self.
Param | Type | Description |
---|---|---|
v | Vector2 |
Vector to max with. |
Vector2
Create a clone vector that is the min result between self and a given vector.
Kind: instance method of Vector2
Returns: Vector2
- Result vector.
Param | Type | Description |
---|---|---|
v | Vector2 |
Vector to min with. |
Vector2
Create a clone vector that is the max result between self and a given vector.
Kind: instance method of Vector2
Returns: Vector2
- Result vector.
Param | Type | Description |
---|---|---|
v | Vector2 |
Vector to max with. |
Vector2
Return a normalized copy of this vector.
Kind: instance method of Vector2
Returns: Vector2
- result vector.
Vector2
Get a copy of this vector rotated by radians.
Kind: instance method of Vector2
Returns: Vector2
- New vector with the length of this vector and direction rotated by given radians.
Param | Type | Description |
---|---|---|
radians | Number |
Radians to rotate by. |
Vector2
Get a copy of this vector rotated by degrees.
Kind: instance method of Vector2
Returns: Vector2
- New vector with the length of this vector and direction rotated by given degrees.
Param | Type | Description |
---|---|---|
degrees | Number |
Degrees to rotate by. |
Vector2
Add other vector values to self.
Kind: instance method of Vector2
Returns: Vector2
- this.
Param | Type | Description |
---|---|---|
Other | Number | Vector2 |
Vector or number to add. |
Vector2
Sub other vector values from self.
Kind: instance method of Vector2
Returns: Vector2
- this.
Param | Type | Description |
---|---|---|
Other | Number | Vector2 |
Vector or number to substract. |
Vector2
Divide this vector by other vector values.
Kind: instance method of Vector2
Returns: Vector2
- this.
Param | Type | Description |
---|---|---|
Other | Number | Vector2 |
Vector or number to divide by. |
Vector2
Multiply this vector by other vector values.
Kind: instance method of Vector2
Returns: Vector2
- this.
Param | Type | Description |
---|---|---|
Other | Number | Vector2 |
Vector or number to multiply by. |
Vector2
Round self.
Kind: instance method of Vector2
Returns: Vector2
- this.
Vector2
Floor self.
Kind: instance method of Vector2
Returns: Vector2
- this.
Vector2
Ceil self.
Kind: instance method of Vector2
Returns: Vector2
- this.
Vector2
Return a normalized copy of this vector.
Kind: instance method of Vector2
Returns: Vector2
- this.
Boolean
Return if vector equals another vector.
Kind: instance method of Vector2
Returns: Boolean
- if vectors are equal.
Param | Type | Description |
---|---|---|
other | Vector2 |
Other vector to compare to. |
Boolean
Return if vector approximately equals another vector.
Kind: instance method of Vector2
Returns: Boolean
- if vectors are equal.
Param | Type | Description |
---|---|---|
other | Vector2 |
Other vector to compare to. |
threshold | Number |
Distance threshold to consider as equal. Defaults to 1. |
Number
Return vector length (aka magnitude).
Kind: instance method of Vector2
Returns: Number
- Vector length.
Vector2
Return a copy of this vector multiplied by a factor.
Kind: instance method of Vector2
Returns: Vector2
- result vector.
Number
Get degrees between this vector and another vector.
Kind: instance method of Vector2
Returns: Number
- Angle between vectors in degrees.
Param | Type | Description |
---|---|---|
other | Vector2 |
Other vector. |
Number
Get radians between this vector and another vector.
Kind: instance method of Vector2
Returns: Number
- Angle between vectors in radians.
Param | Type | Description |
---|---|---|
other | Vector2 |
Other vector. |
Number
Get degrees between this vector and another vector. Return values between 0 to 360.
Kind: instance method of Vector2
Returns: Number
- Angle between vectors in degrees.
Param | Type | Description |
---|---|---|
other | Vector2 |
Other vector. |
Number
Get radians between this vector and another vector. Return values between 0 to PI2.
Kind: instance method of Vector2
Returns: Number
- Angle between vectors in radians.
Param | Type | Description |
---|---|---|
other | Vector2 |
Other vector. |
Number
Calculate distance between this vector and another vectors.
Kind: instance method of Vector2
Returns: Number
- Distance between vectors.
Param | Type | Description |
---|---|---|
other | Vector2 |
Other vector. |
Number
Calculate squared distance between this vector and another vector.
Kind: instance method of Vector2
Returns: Number
- Distance between vectors.
Param | Type | Description |
---|---|---|
other | Vector2 |
Other vector. |
Vector2
Return a clone and clamp its values to be between min and max.
Kind: instance method of Vector2
Returns: Vector2
- Clamped vector.
Param | Type | Description |
---|---|---|
min | Vector2 |
Min vector. |
max | Vector2 |
Max vector. |
Vector2
Clamp this vector values to be between min and max.
Kind: instance method of Vector2
Returns: Vector2
- Self.
Param | Type | Description |
---|---|---|
min | Vector2 |
Min vector. |
max | Vector2 |
Max vector. |
Number
Calculate the dot product with another vector.
Kind: instance method of Vector2
Returns: Number
- Dot product value.
Param | Type | Description |
---|---|---|
other | Vector2 |
Vector to calculate dot with. |
Number
Get vector’s angle in degrees.
Kind: instance method of Vector2
Returns: Number
- Vector angle in degrees.
Number
Get vector’s angle in radians.
Kind: instance method of Vector2
Returns: Number
- Vector angle in degrees.
Convert to string.
Kind: instance method of Vector2
Array.<Number>
Convert to array of numbers.
Kind: instance method of Vector2
Returns: Array.<Number>
- Vector components as array.
\*
Convert to dictionary.
Kind: instance method of Vector2
Returns: \*
- Dictionary with {x,y}
Param | Type | Description |
---|---|---|
minimized | Boolean |
If true, will not include keys that their values are 0. You can use fromDict on minimized dicts. |
Vector with 0,0 values as a frozen shared object. Be careful not to try and change it.
Kind: static property of Vector2
Vector with 1,1 values as a frozen shared object. Be careful not to try and change it.
Kind: static property of Vector2
Vector with 0.5,0.5 values as a frozen shared object. Be careful not to try and change it.
Kind: static property of Vector2
Vector with -1,0 values as a frozen shared object. Be careful not to try and change it.
Kind: static property of Vector2
Vector with 1,0 values as a frozen shared object. Be careful not to try and change it.
Kind: static property of Vector2
Vector with 0,1 values as a frozen shared object. Be careful not to try and change it.
Kind: static property of Vector2
Vector with 0,-1 values as a frozen shared object. Be careful not to try and change it.
Kind: static property of Vector2
Vector2
Get vector (0,0).
Kind: static method of Vector2
Returns: Vector2
- result vector.
Vector2
Get vector with 1,1 values.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Vector2
Get vector with 0.5,0.5 values.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Vector2
Get vector with -1,0 values.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Vector2
Get vector with 1,0 values.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Vector2
Get vector with 0,-1 values.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Vector2
Get vector with 0,1 values.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Vector2
Get a random vector with length of 1.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Vector2
Get vector from degrees.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Param | Type | Description |
---|---|---|
degrees | Number |
Angle to create vector from (0 = vector pointing right). |
Vector2
Get vector from radians.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Param | Type | Description |
---|---|---|
radians | Number |
Angle to create vector from (0 = vector pointing right). |
Vector2
Lerp between two vectors.
Kind: static method of Vector2
Returns: Vector2
- result vector.
Param | Type | Description |
---|---|---|
p1 | Vector2 |
First vector. |
p2 | Vector2 |
Second vector. |
a | Number |
Lerp factor (0.0 - 1.0). |
Number
Get degrees between two vectors. Return values between -180 to 180.
Kind: static method of Vector2
Returns: Number
- Angle between vectors in degrees.
Param | Type | Description |
---|---|---|
p1 | Vector2 |
First vector. |
p2 | Vector2 |
Second vector. |
Number
Get radians between two vectors. Return values between -PI to PI.
Kind: static method of Vector2
Returns: Number
- Angle between vectors in radians.
Param | Type | Description |
---|---|---|
p1 | Vector2 |
First vector. |
p2 | Vector2 |
Second vector. |
Number
Get degrees between two vectors. Return values between 0 to 360.
Kind: static method of Vector2
Returns: Number
- Angle between vectors in degrees.
Param | Type | Description |
---|---|---|
p1 | Vector2 |
First vector. |
p2 | Vector2 |
Second vector. |
Number
Get radians between two vectors. Return values between 0 to PI2.
Kind: static method of Vector2
Returns: Number
- Angle between vectors in radians.
Param | Type | Description |
---|---|---|
p1 | Vector2 |
First vector. |
p2 | Vector2 |
Second vector. |
Number
Calculate distance between two vectors.
Kind: static method of Vector2
Returns: Number
- Distance between vectors.
Param | Type | Description |
---|---|---|
p1 | Vector2 |
First vector. |
p2 | Vector2 |
Second vector. |
Number
Return cross product between two vectors.
Kind: static method of Vector2
Returns: Number
- Cross between vectors.
Param | Type | Description |
---|---|---|
p1 | Vector2 |
First vector. |
p2 | Vector2 |
Second vector. |
Number
Return dot product between two vectors.
Kind: static method of Vector2
Returns: Number
- Dot between vectors.
Param | Type | Description |
---|---|---|
p1 | Vector2 |
First vector. |
p2 | Vector2 |
Second vector. |
Vector2
Parse and return a vector object from string in the form of “x,y”.
Kind: static method of Vector2
Returns: Vector2
- Parsed vector.
Param | Type | Description |
---|---|---|
str | String |
String to parse. |
Vector2
Create vector from array of numbers.
Kind: static method of Vector2
Returns: Vector2
- Vector instance.
Param | Type | Description |
---|---|---|
arr | Array.<Number> |
Array of numbers to create vector from. |
Vector2
Create vector from a dictionary.
Kind: static method of Vector2
Returns: Vector2
- Newly created vector.
Param | Type | Description |
---|---|---|
data | \* |
Dictionary with {x,y}. |