Constructor
new Vector2D(xopt, yopt)
Creates a new instance of the Vector2D class.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
x |
number |
<optional> |
0.0 | The x-component of the vector. |
y |
number |
<optional> |
0.0 | The y-component of the vector. |
- Source:
Extends
Members
x :number
The horizontal coordinate of the point. The default value is 0.
Type:
- number
- Inherited From:
- Source:
y :number
The vertical coordinate of the point. The default value is 0.
Type:
- number
- Inherited From:
- Source:
Methods
abs() → {rune.geom.Vector2D}
Set the vector axes values to absolute values.
- Source:
Returns:
- Type
- rune.geom.Vector2D
add(vector) → {rune.geom.Vector2D}
Adds the argument vector to this vector.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
rune.geom.Vector2D | The second vector. |
- Source:
Returns:
- Type
- rune.geom.Vector2D
angleTo(target) → {number}
Returns the direction from this point to a target in radians, between -pi
and pi. Zero points along positive x. With screen coordinates, positive
angles turn toward positive y. Neither point is modified.
Returns zero when both points have the same coordinates.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
rune.geom.Point | Target point. |
- Inherited From:
- Source:
Returns:
Direction to the target in radians.
- Type
- number
copyFrom(point) → {rune.geom.Point}
Copies the coordinates of the specified point to this point.
Parameters:
| Name | Type | Description |
|---|---|---|
point |
rune.geom.Point | The point to copy coordinates from. |
- Inherited From:
- Source:
Returns:
This point.
- Type
- rune.geom.Point
cross(vector) → {number}
Returns the cross product of this vector by another.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
rune.geom.Vector2D | The second vector. |
- Source:
Returns:
- Type
- number
distance(point) → {number}
Returns the distance between the current and specified point.
Parameters:
| Name | Type | Description |
|---|---|---|
point |
rune.geom.Point | The specified point. |
- Inherited From:
- Source:
Returns:
- Type
- number
distanceSquared(point) → {number}
Returns the squared distance between the current and specified point without
calculating a square root. Compare the result against a squared distance.
Parameters:
| Name | Type | Description |
|---|---|---|
point |
rune.geom.Point | The specified point. |
- Inherited From:
- Source:
Returns:
The squared distance between the points.
- Type
- number
divide(value) → {rune.geom.Vector2D}
Divides this vector by another vector, or by a number specified as a
floating point number.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
rune.geom.Vector2D | number | The value to divide by. |
- Source:
Returns:
- Type
- rune.geom.Vector2D
dot(vector) → {number}
Returns the dot product of this vector by another.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
rune.geom.Vector2D | The second vector. |
- Source:
Returns:
- Type
- number
equals(vector) → {boolean}
Determine if the specified vector is equal to the current vector.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
rune.geom.Vector2D | The second vector. |
- Source:
Returns:
- Type
- boolean
interpolate(point, fractionopt, outputopt) → {rune.geom.Point}
Determines a point between two specified points. The parameter fraction
determines where the new interpolated point is located relative to the two
end points.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
point |
rune.geom.Point | The second point. | |
fraction |
number |
<optional> |
The level of interpolation between the two points. |
output |
rune.geom.Point |
<optional> |
Save results to this object. |
- Inherited From:
- Source:
Returns:
The new, interpolated point.
- Type
- rune.geom.Point
magnitude(squaredopt) → {number}
Returns the magnitude (length) of this vector.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
squared |
boolean |
<optional> |
Request squared magnitude. |
- Source:
Returns:
- Type
- number
moveTowards(target, distance) → {rune.geom.Point}
Moves this point toward a target by at most the specified distance without
passing it. The target is not modified. A distance of zero or less leaves
this point unchanged. All coordinates and the distance use the same units.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
rune.geom.Point | Target point. |
distance |
number | Maximum distance to move for this call. |
- Inherited From:
- Source:
Returns:
This point.
- Type
- rune.geom.Point
multiply(value) → {rune.geom.Vector2D}
Multiplies this vector by another vector, or by a number specified as a
floating point number.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
rune.geom.Vector2D | number | The value to multiply by. |
- Source:
Returns:
- Type
- rune.geom.Vector2D
normalize(scaleopt) → {rune.geom.Vector2D}
Scales the line segment between (0,0) and the current vector to a set length.
A scale of zero clears a nonzero vector. A zero vector remains unchanged.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
scale |
number |
<optional> |
1 | The scaling value. |
- Source:
Returns:
- Type
- rune.geom.Vector2D
reverse() → {rune.geom.Vector2D}
Reverses this vector i.e multiplies it by -1.
- Source:
Returns:
- Type
- rune.geom.Vector2D
rotate(rads) → {rune.geom.Vector2D}
Rotates the vector with specified radians.
Parameters:
| Name | Type | Description |
|---|---|---|
rads |
number | Amount of rotation specified in radians. |
- Source:
Returns:
- Type
- rune.geom.Vector2D
round(n) → {rune.geom.Vector2D}
Rotates the vector by provided radians.
Parameters:
| Name | Type | Description |
|---|---|---|
n |
number | Number of decimals for precision. |
- Source:
Returns:
- Type
- rune.geom.Vector2D
set(x, y) → {rune.geom.Point}
Sets the horizontal and vertical coordinates of this point.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number | The horizontal coordinate. |
y |
number | The vertical coordinate. |
- Inherited From:
- Source:
Returns:
This point.
- Type
- rune.geom.Point
setFromAngle(angle, speed) → {rune.geom.Vector2D}
Sets this vector from an angle in radians and a magnitude. Zero radians
points right; positive angles turn clockwise in screen coordinates.
A negative magnitude reverses the direction. No new object is allocated.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
number | Direction in radians. |
speed |
number | Magnitude in the vector's existing units. |
- Source:
Returns:
This vector.
- Type
- rune.geom.Vector2D
setTowards(source, target, speed) → {rune.geom.Vector2D}
Sets this vector toward a target from a source position, with the specified
magnitude. Coincident positions produce a zero vector. A negative magnitude
points away from the target. No new object is allocated or position moved.
Read both positions before writing so either may also be this vector.
Parameters:
| Name | Type | Description |
|---|---|---|
source |
rune.geom.Point | Starting position. |
target |
rune.geom.Point | Target position. |
speed |
number | Magnitude in the vector's existing units. |
- Source:
Returns:
This vector.
- Type
- rune.geom.Vector2D
subtract(vector) → {rune.geom.Vector2D}
Subtracts the argument vector from this vector.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
rune.geom.Vector2D | The second vector. |
- Source:
Returns:
- Type
- rune.geom.Vector2D
toString() → {string}
Returns a string that contains the values of the x and y coordinates.
- Overrides:
- Source:
Returns:
The string representation of the coordinates.
- Type
- string