- Source
Methods
(static) pair(x, y) → {number}
Pairs 2 positive integers, returning a unique number for each possible pairing using elegant pairing
Name | Type | Description |
---|---|---|
x | number | 1st number, must be positive integer |
y | number | 2nd number, must be positive integer |
- Source
Unique number from those
- Type:
- number
(static) unpair(n) → {vec}
Takes a paired number and returns the x/y values that created that number
Name | Type | Description |
---|---|---|
n | number | Paired number |
- Source
Pair of x/y that created that pair
- Type:
- vec
(static) pairCommon(x, y) → {number}
Pairs 2 positive integers, returning a unique number for each possible pairing using elegant pairing Returns the same value if x/y are switched
Name | Type | Description |
---|---|---|
x | number | 1st number, must be positive integer |
y | number | 2nd number, must be positive integer |
- Source
Unique number given inputs
- Type:
- number
(static) getCenterOfMass(vertices)
Calculates the center of mass of a convex body. Uses algorithm from bell0bytes.eu/centroid-convex
Name | Type | Description |
---|---|---|
vertices | Array | Convex body vertices |
- Source
(static) parseColor(originalColor) → {Array}
Parses a color into its base hex code and alpha. Supports hex, hex with alpha, rgb, and rgba
Name | Type | Description |
---|---|---|
originalColor | string | Color to be parsed |
- Source
Array of [hex code, alpha] of parsed color
- Type:
- Array
(static) merge(objA, objB, maxDepth)
Deep copies objB
onto objA
in place.
Name | Type | Description |
---|---|---|
objA | Object | First object |
objB | Object | 2nd object, copied onto |
maxDepth | number | Maximum depth it can copy. If set to 1 it is a shallow copy only |
- Source
(static) isClass(obj) → {boolean}
Finds if a variable is a class in disguise
Name | Type | Description |
---|---|---|
obj | * | Variable to check |
- Source
If the variable is a class
- Type:
- boolean
(static) lineIntersects(a1, a2, b1, b2) → {vec|object}
Checks if line a1
->a2
is intersecting line b1
->b2
, and at what point
Name | Type | Description |
---|---|---|
a1 | vec | Start of line 1 |
a2 | vec | End of line 1 |
b1 | vec | Start of line 2 |
b2 | vec | End of line 2 |
- Source
Point of intersection, or null if they don't intersect
- Type:
- vec |
object
(static) lineIntersectsBody(a1, a2, body) → {boolean}
Tests if line a1
->a2
is intersecting body
- Source
If the line is intersecting the body
- Type:
- boolean
(static) getRayNearbyStaticBodies(start, end, World)
Finds the static bodies around the ray from start
to end
. Useful for getting bodies when calling Common.raycast
or Common.raycastSimple
Name | Type | Description |
---|---|---|
start | vec | Start of ray |
end | vec | End of ray |
World | World | World to get bodies from |
- Source
(static) raycast(start, end, bodiesopt) → {Object}
Name | Type | Attributes | Description |
---|---|---|---|
start | vec | Start of ray | |
end | vec | End of ray | |
bodies | Array | <optional> | Array of bodies to test |
- Source
{ collision: boolean, distance: Number, point: vec, body: RigidBody, verticeIndex: Number }
- Type:
- Object
(static) arrayDelete(array, value)
Deletes first instance of value
from array
Name | Type | Description |
---|---|---|
array | Array | Array item is deleted from |
value | * | Value deleted from array |
- Source