Constructor
new SFSVector2(x, y)
Creates a new instance of the SFSVector2 class.
Parameters:| Name | Type | Description |
|---|
x | number | The vector component along the X axis. |
y | number | The vector component along the Y axis. |
Members
(readonly) angle :number
Angle of this vector with respect to the positive X axis, in radians.
The returned angle ranges from -PI to PI.
(readonly) aspect :number
Aspect ratio of this vector (ratio of x to y).
(readonly) isNormalized :boolean
Indicates if the vector is normalized, i.e. its length is approximately equal to 1.
(readonly) length :number
The length (magnitude) of the vector.
x :number
The vector component along the X axis.
y :number
The vector component along the Y axis.
Methods
Returns a new vector with all components in absolute values.
Returns:A new vector with absolute components.
- Type:
- SFSVector2
Returns a new vector with all components rounded up to the nearest integer.
Returns:A new vector with rounded up components.
- Type:
- SFSVector2
cross(vec) → {number}
Returns the 2D cross product (also known as the perpendicular dot product or wedge product) of this vector and the passed vector.
This returns a scalar representing the z-component of the 3D cross product when treating the 2D vectors as 3D vectors with z equal to 0.
The magnitude represents the area of the parallelogram formed by the two vectors. The sign indicates orientation: positive if the passed vector is counterclockwise from this vector, negative if clockwise.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to compute the cross product with. |
Returns:The scalar cross product of the vectors.
- Type:
- number
distanceSquaredTo(vec) → {number}
Returns the squared distance between this vector and the passed vector.
This method is more efficient than SFSVector2#distanceTo method when comparing distances.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to measure the squared distance from. |
Returns:The squared distance between the vectors.
- Type:
- number
distanceTo(vec) → {number}
Returns the Euclidean distance between this vector and the passed vector.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to measure the distance from. |
Returns:The distance between the vectors.
- Type:
- number
Returns a new vector that is the component-wise division of this vector by the passed vector.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to divide this vector by. |
Returns:A new vector representing the component-wise division of the two vectors.
- Type:
- SFSVector2
dot(vec) → {number}
Returns the dot product of this vector and the passed vector.
The dot product will be 0 for a right angle (90 degrees), greater than 0 for angles narrower than 90 degrees and lower than 0 for angles wider than 90 degrees.
When using unit (normalized) vectors, the result will always be between -1.0 (180 degrees angle), when the vectors are facing opposite directions, and 1.0 (0 degrees angle) when the vectors are aligned.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to compute the dot product with. |
Returns:The dot product of the vectors.
- Type:
- number
Returns a new vector with all components rounded down to the nearest integer.
Returns:A new vector with rounded down components.
- Type:
- SFSVector2
lerp(vec, weight) → {SFSVector2}
Returns the result of the linear interpolation between this vector and the passed vector by the passe weight.
The weight range is 0.0 to 1.0, representing the amount of interpolation. Values outside this range will extrapolate.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The target vector to interpolate towards. |
weight | number | The interpolation weight (0.0 = this vector, 1.0 = target vector). |
Returns:A new interpolated vector.
- Type:
- SFSVector2
Returns a new vector with the component-wise maximum of this vector and the passed vector.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to compare to. |
Returns:A new vector with the maximum components of the vectors.
- Type:
- SFSVector2
Returns a new vector with the component-wise minimum of this vector and the passed vector.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to compare to. |
Returns:A new vector with the minimum components of the vectors.
- Type:
- SFSVector2
Returns a new vector that is the component-wise multiplication of this vector and the passed vector.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to multiply this vector by. |
Returns:A new vector representing the component-wise product of the two vectors.
- Type:
- SFSVector2
Returns a new vector that is the normalized (unit length) version of this vector.
If this vector has zero length, returns a zero vector.
Returns a new vector that is the result of rotating this vector by the passed angle.
Parameters:| Name | Type | Description |
|---|
angle | number | The angle to rotate the vector by, in radians. |
Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
Returns:A new vector with rounded components.
- Type:
- SFSVector2
Returns a new vector that is the result of subtracting the passed vector from this vector.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to subtract from this vector. |
Returns:A new vector representing the difference between the two vectors.
- Type:
- SFSVector2
Returns a new vector that is the sum of this vector and the passed vector.
Parameters:| Name | Type | Description |
|---|
vec | SFSVector2 | The vector to sum to this vector. |
Returns:A new vector representing the sum of the two vectors.
- Type:
- SFSVector2
toString() → {string}
Returns a string containing the X and Y components of the vector.
Returns:The string representation of the
SFSVector2 object.
- Type:
- string