new Vec2(vOrX, y)
Constructs a new Vec2.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
vOrX |
JustMath.Vec2 | number | Other Vec2 to copy or X coordinate |
|
y |
number |
<optional> |
Y coordinate if vOrX is X coordinate |
Members
-
x :number
-
X coordinate.
-
y :number
-
Y coordinate.
Methods
-
add(vOrX, y) → {JustMath.Vec2}
-
Adds a value to this Vec2.
Parameters:
Name Type Argument Description vOrXJustMath.Vec2 | number Other Vec2 or X coordinate
ynumber <optional>
Y coordinate if vOrX is X coordinate
Returns:
This Vec2
- Type
- JustMath.Vec2
-
clone() → {JustMath.Vec2}
-
Clones this Vec2.
Returns:
Cloned Vec2
- Type
- JustMath.Vec2
-
copy() → {JustMath.Vec2}
-
Copies this Vec2. This is an alias of JustMath.Vec2#clone.
Returns:
Copied Vec2
- Type
- JustMath.Vec2
-
dir() → {number}
-
Calculates the direction of this Vec2. This operation requires a call to JustMath.atan2.
Returns:
Direction in radians
- Type
- number
-
dist(b) → {number}
-
Calculates the distance between this and another Vec2. This operation requires a call to JustMath.sqrt.
Parameters:
Name Type Description bJustMath.Vec2 Other Vec2
Returns:
Distance
- Type
- number
-
distSq(b) → {number}
-
Calculates the squared distance between this and another Vec2.
Parameters:
Name Type Description bJustMath.Vec2 Other Vec2
Returns:
Squared distance
- Type
- number
-
dot(b) → {number}
-
Calculates the dot product of this and another Vec2.
Parameters:
Name Type Description bJustMath.Vec2 Other Vec2
Returns:
Dot product
- Type
- number
-
equals(b) → {boolean}
-
Tests if this Vec2 equals another Vec2.
Parameters:
Name Type Description bJustMath.Vec2 Other Vec2
Returns:
true if equal, false otherwise
- Type
- boolean
-
getX() → {number}
-
Gets the X coordinate of this Vec2.
Returns:
X coordinate
- Type
- number
-
getXY() → {{x: number, y: number}}
-
Gets the coordinate payload of this Vec2.
Returns:
Coordinate payload
- Type
- {x: number, y: number}
-
getY() → {number}
-
Gets the Y coordinate of this Vec2.
Returns:
Y coordinate
- Type
- number
-
inRect(p1, p2) → {boolean}
-
Tests if this Vec2 is contained in the rectangle created between p1 and p2.
Parameters:
Name Type Description p1JustMath.Vec2 p2JustMath.Vec2 Returns:
true if contained, else false
- Type
- boolean
-
inv() → {JustMath.Vec2}
-
Inverts this Vec2.
Returns:
This Vec2
- Type
- JustMath.Vec2
-
lerp(p, percent) → {JustMath.Vec2}
-
Interpolates the point between this and another point (in that direction) at the given percentage.
Parameters:
Name Type Description pJustMath.Vec2 Other point
percentnumber Percentage
Returns:
This Vec2
- Type
- JustMath.Vec2
-
mag() → {number}
-
Calculates the magnitude of this Vec2. This operation requires a call to JustMath.sqrt.
Returns:
Magnitude
- Type
- number
-
magSq() → {number}
-
Calculates the squared magnitude of this Vec2.
Returns:
Squared magnitude
- Type
- number
-
norm() → {JustMath.Vec2}
-
Normalizes this Vec2.
Returns:
This Vec2
- Type
- JustMath.Vec2
-
ort() → {JustMath.Vec2}
-
Makes this Vec2 an orthogonal of itself by setting x=-y and y=x.
Returns:
This Vec2
- Type
- JustMath.Vec2
-
project(b) → {JustMath.Vec2}
-
Projects this Vec2 on another Vec2.
Parameters:
Name Type Description bJustMath.Vec2 Other Vec2
Returns:
This Vec2
- Type
- JustMath.Vec2
-
reflect(n) → {JustMath.Vec2}
-
Reflects this Vec2 from another Vec2.
Parameters:
Name Type Description nJustMath.Vec2 Vector to reflect from
Returns:
This Vec2
- Type
- JustMath.Vec2
-
reflectAndScale(n, projectFactor, rejectFactor) → {JustMath.Vec2}
-
Reflects this Vec2 from another Vec2 and scales the projected and reflected component by the given factors.
Parameters:
Name Type Description nJustMath.Vec2 Vector to reflect from
projectFactornumber Projected component factor
rejectFactornumber Rejected component factor
Returns:
This Vec2
- Type
- JustMath.Vec2
-
reject(b) → {JustMath.Vec2}
-
Rejects this Vec2 from another Vec2.
Parameters:
Name Type Description bJustMath.Vec2 Other Vec2
Returns:
This Vec2
- Type
- JustMath.Vec2
-
rotate(theta) → {JustMath.Vec2}
-
Rotates this Vec2 by the given angle. This operation requires a call to JustMath.sin and JustMath.cos.
Parameters:
Name Type Description thetanumber Rotation angle in radians
Returns:
This Vec2
- Type
- JustMath.Vec2
-
scale(factor) → {JustMath.Vec2}
-
Scales this Vec2 by a factor.
Parameters:
Name Type Description factornumber Scaling factor
Returns:
This Vec2
- Type
- JustMath.Vec2
-
set(vOrX, y) → {JustMath.Vec2}
-
Sets the coordinates of this Vec2.
Parameters:
Name Type Argument Description vOrXJustMath.Vec2 | number Other Vec2 or X coordinate
ynumber <optional>
Y coordinate if vOrX is X coordinate
Returns:
This Vec2
- Type
- JustMath.Vec2
-
sub(vOrX, y) → {JustMath.Vec2}
-
Subtracts a value from this Vec2.
Parameters:
Name Type Argument Description vOrXJustMath.Vec2 | number Other Vec2 or X coordinate
ynumber <optional>
Y coordinate if vOrX is X coordinate
Returns:
This Vec2
- Type
- JustMath.Vec2
-
toString() → {string}
-
Gets a string representation of this Vec2.
Returns:
String representation as of "Vec2(x/y)"
- Type
- string
-
<static> det(v1, v2) → {number}
-
Calculates the determinant of the matrix [v1,v2].
Parameters:
Name Type Description v1JustMath.Vec2 Vector 1
v2JustMath.Vec2 Vector 2
Returns:
Determinant of the matrix [v1,v2]
- Type
- number