Common

Methods

(static) pair(x, y) → {number}

Pairs 2 positive integers, returning a unique number for each possible pairing using elegant pairing

Parameters:
NameTypeDescription
xnumber

1st number, must be positive integer

ynumber

2nd number, must be positive integer

Returns:

Unique number from those

Type: 
number

(static) unpair(n) → {vec}

Takes a paired number and returns the x/y values that created that number

Parameters:
NameTypeDescription
nnumber

Paired number

Returns:

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

Parameters:
NameTypeDescription
xnumber

1st number, must be positive integer

ynumber

2nd number, must be positive integer

Returns:

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

Parameters:
NameTypeDescription
verticesArray

Convex body vertices

(static) parseColor(originalColor) → {Array}

Parses a color into its base hex code and alpha. Supports hex, hex with alpha, rgb, and rgba

Parameters:
NameTypeDescription
originalColorstring

Color to be parsed

Returns:

Array of [hex code, alpha] of parsed color

Type: 
Array

(static) merge(objA, objB, maxDepth)

Deep copies objB onto objA in place.

Parameters:
NameTypeDescription
objAObject

First object

objBObject

2nd object, copied onto objA

maxDepthnumber

Maximum depth it can copy. If set to 1 it is a shallow copy only

(static) isClass(obj) → {boolean}

Finds if a variable is a class in disguise

Parameters:
NameTypeDescription
obj*

Variable to check

Returns:

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

Parameters:
NameTypeDescription
a1vec

Start of line 1

a2vec

End of line 1

b1vec

Start of line 2

b2vec

End of line 2

Returns:

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

Parameters:
NameTypeDescription
a1vec

Start of line

a2vec

End of line

bodyRigidBody

Body to test

Returns:

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

Parameters:
NameTypeDescription
startvec

Start of ray

endvec

End of ray

WorldWorld

World to get bodies from

(static) raycast(start, end, bodiesopt) → {Object}

Parameters:
NameTypeAttributesDescription
startvec

Start of ray

endvec

End of ray

bodiesArray<optional>

Array of bodies to test

Returns:

{ collision: boolean, distance: Number, point: vec, body: RigidBody, verticeIndex: Number }

Type: 
Object

(static) arrayDelete(array, value)

Deletes first instance of value from array

Parameters:
NameTypeDescription
arrayArray

Array item is deleted from

value*

Value deleted from array