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 v
Vec2 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 v
Vec2 Returns:
- Type
- Number
-
assign(v) → {Vec2}
-
Assign this vector the value of another.
Parameters:
Name Type Description v
Vec2 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 v
Vec2 Returns:
- Type
- Number
-
dot(v) → {Number}
-
Get the dot product of this vector and another.
Parameters:
Name Type Description v
Vec2 Returns:
- Type
- Number
-
equals(v) → {Boolean}
-
Determine if this vector is equal to another.
Parameters:
Name Type Description v
Vec2 Returns:
True if vectors are equal.- Type
- Boolean
-
limit(size) → {Vec2}
-
Limit this vector to a specific magnitude.
Parameters:
Name Type Description size
Number 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 m
Number <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 theta
Number Returns:
This vector.- Type
- Vec2
-
set(x, y) → {Vec2}
-
Set this vector to a set of coordinates.
Parameters:
Name Type Description x
Number y
Number Returns:
This vector.- Type
- Vec2
-
smult(n) → {Vec2}
-
Scalar multiply this vector by a value.
Parameters:
Name Type Description n
Number Returns:
This vector.- Type
- Vec2
-
sub(v) → {Vec2}
-
Subtract some vector from this one.
Parameters:
Name Type Description v
Vec2 Returns:
This vector.- Type
- Vec2
-
toString()
-
Output this vector.
-
<static> aquire() → {Vec2}
-
Get a vector from the pool.
Returns:
- Type
- Vec2
-
<static> fromAngle(theta, m) → {Vec2}
-
Create a vector with a specific angle and magnitude.
Parameters:
Name Type Argument Description theta
Number m
Number <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 theta
Number m
Number 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 p1
Vec2 Position of rectangle 1 r1
Vec2 Halfwidths of rectangle 1 p2
Vec2 Position of rectangle 2 r2
Vec2 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 p1
Vec2 Position of rectangle 1 r1
Vec2 Halfwidths of rectangle 1 p2
Vec2 Position of rectangle 2 r2
Vec2 Halfwidths of rectangle 2 Returns:
True if they intersect- Type
- Boolean
-
<static> release(v) → {Number}
-
Return a vector to the pool.
Parameters:
Name Type Description v
Vec2 Returns:
- 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 position
Vec2 size
Vec2 out__position
Vec2 Output position out__hwidth
Vec2 Output hwidths