new Vec2(x, y)
2-dimension Cartesian vector with built-in (optional) object pool.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Number | |
y |
Number |
Methods
-
add(v) → {Vec2}
-
Add some vector to this one.
Parameters:
Name Type Description vVec2 Returns:
This vector.- Type
- Vec2
-
angle() → {Number}
-
Get the angle of this vector.
Returns:
- Type
- Number
-
angleBetween(v) → {Number}
-
Get the angle between this vector and another.
Parameters:
Name Type Description vVec2 Returns:
- Type
- Number
-
assign(v) → {Vec2}
-
Assign this vector the value of another.
Parameters:
Name Type Description vVec2 Returns:
This vector.- Type
- Vec2
-
clear() → {Vec2}
-
Reset this vector to (0,0).
Returns:
This vector.- Type
- Vec2
-
copy() → {Vec2}
-
Make a copy of this vector.
Returns:
A new vector.- Type
- Vec2
-
det(v) → {Number}
-
Get the determinate of this vector and another.
Parameters:
Name Type Description vVec2 Returns:
- Type
- Number
-
dot(v) → {Number}
-
Get the dot product of this vector and another.
Parameters:
Name Type Description vVec2 Returns:
- Type
- Number
-
equals(v) → {Boolean}
-
Determine if this vector is equal to another.
Parameters:
Name Type Description vVec2 Returns:
True if vectors are equal.- Type
- Boolean
-
limit(size) → {Vec2}
-
Limit this vector to a specific magnitude.
Parameters:
Name Type Description sizeNumber Returns:
This vector.- Type
- Vec2
-
magnitude() → {Number}
-
Get the magnitude of this vector.
Returns:
- Type
- Number
-
magnitude2() → {Number}
-
Get the squared magnitude of this vector.
Returns:
- Type
- Number
-
normalize(m) → {Vec2}
-
Normalize this vector.
Parameters:
Name Type Argument Description mNumber <optional>
Length. Returns:
This vector.- Type
- Vec2
-
pcopy() → {Vec2}
-
Make a pooled copy of this vector
Returns:
A new vector.- Type
- Vec2
-
rotate(theta) → {Vec2}
-
Rotate this vector clockwise about the origin by a certain angle.
Parameters:
Name Type Description thetaNumber Returns:
This vector.- Type
- Vec2
-
set(x, y) → {Vec2}
-
Set this vector to a set of coordinates.
Parameters:
Name Type Description xNumber yNumber Returns:
This vector.- Type
- Vec2
-
smult(n) → {Vec2}
-
Scalar multiply this vector by a value.
Parameters:
Name Type Description nNumber Returns:
This vector.- Type
- Vec2
-
sub(v) → {Vec2}
-
Subtract some vector from this one.
Parameters:
Name Type Description vVec2 Returns:
This vector.- Type
- Vec2
-
toString()
-
Output this vector.
-
<static> aquire() → {Vec2}
-
Returns:
Vector from the pool.- Type
- Vec2
-
<static> fromAngle(theta, m) → {Vec2}
-
Create a vector with a specific angle and magnitude.
Parameters:
Name Type Argument Description thetaNumber mNumber <optional>
Returns:
A new vector.- Type
- Vec2
-
<static> pfromAngle(theta, m) → {Vec2}
-
Create a pooled vector with a specific angle and magnitude.
Parameters:
Name Type Description thetaNumber mNumber Returns:
A new vector.- Type
- Vec2
-
<static> rectContains(p1, r1, p2, r2) → {Boolean}
-
Determines if rectangle 1 is entirely inside of rectangle 2.
Parameters:
Name Type Description p1Vec2 Position of rectangle 1 r1Vec2 Halfwidths of rectangle 1 p2Vec2 Position of rectangle 2 r2Vec2 Halfwidths of rectangle 2 Returns:
True if they rectangle 1 is inside of rectangle 2- Type
- Boolean
-
<static> rectIntersect(p1, r1, p2, r2) → {Boolean}
-
Determine if two rectangles, defined by a position and a halfwidth vector, overlap.
Parameters:
Name Type Description p1Vec2 Position of rectangle 1 r1Vec2 Halfwidths of rectangle 1 p2Vec2 Position of rectangle 2 r2Vec2 Halfwidths of rectangle 2 Returns:
True if they intersect- Type
- Boolean
-
<static> release(v) → {Number}
-
Parameters:
Name Type Description vVec2 Returns:
Current pool count.- Type
- Number
-
<static> sizeToHwidth(position, size, out__position, out__hwidth)
-
Convert a rectangle specified by top-left point + size into center location + halfwidths.
Parameters:
Name Type Description positionVec2 sizeVec2 out__positionVec2 Output position out__hwidthVec2 Output hwidths