ig.

utilsintersection

Static utilities for intersections.

Author:
  • Collin Hover - collinhover.com
Source:

<static> AABBContains(aminX, aminY, amaxX, amaxY, bminX, bminY, bmaxX, bmaxY) → {Boolean}

Checks two 2D axis aligned bounding boxes: is A contained by B?

Parameters:
Name Type Description
aminX Number A left
aminY Number A top
amaxX Number A right
amaxY Number A bottom
bminX Number B left
bminY Number B top
bmaxX Number B right
bmaxY Number B bottom
Source:
Returns:
{ Boolean } whether bounds A contains bounds B

<static> AABBIntersect(aminX, aminY, amaxX, amaxY, bminX, bminY, bmaxX, bmaxY) → {Boolean}

Checks two 2D axis aligned bounding boxes: does A intersect B?

Parameters:
Name Type Description
aminX Number A left
aminY Number A top
amaxX Number A right
amaxY Number A bottom
bminX Number B left
bminY Number B top
bmaxX Number B right
bmaxY Number B bottom
Source:
Returns:
{ Boolean } whether bounds intersect

<static> bounds(x, y, width, height, bounds) → {Object}

Calculates bounds from a position and dimensions.

Parameters:
Name Type Argument Description
x Number x position of top left
y Number y position of top left
width Number width
height Number height
bounds Object <optional>
bounding object
Source:
Returns:
{ Object } bounding object
Example
// get bounds
var bounds = ig.utilsintersection.bounds( 0, 0, 100, 100 );
// left
bounds.minX;
// right
bounds.maxX;
// top
bounds.minY;
// bottom
bounds.maxY;
// width
bounds.width;
// height
bounds.height;

<static> boundsAABBIntersect(bounds, minX, minY, maxX, maxY) → {Boolean}

This is a convenience method to test intersection of two bounding boxes.

Parameters:
Name Type Description
bounds Object bounding object A
minX Number B left
minY Number B top
maxX Number B right
maxY Number B bottom
Source:
See:
Returns:
{ Boolean } whether bounds intersect

<static> boundsClone(boundsSource, offsetX, offsetY, bounds) → {Object}

Clones a bounds object, with the addition of optional offset position.

Parameters:
Name Type Argument Default Description
boundsSource Object bounds to clone
offsetX Number <optional>
0 offset x
offsetY Number <optional>
0 offset y
bounds Object <optional>
bounding object
Source:
See:
Returns:
{ Object } bounding object clone.

<static> boundsCopy(boundsA, boundsB, offsetX, offsetY, scaleX, scaleY) → {Object}

Copies a bounds object into another bounds object, with the addition of optional offset position and scale.

Parameters:
Name Type Argument Default Description
boundsA Object bounds to copy into
boundsB Object bounds to copy from
offsetX Number <optional>
0 offset x
offsetY Number <optional>
0 offset y
scaleX Number <optional>
1 scale x
scaleY Number <optional>
1 scale y
Source:
See:
Returns:
{ Object } bounding object based on bounds plus offset

<static> boundsCopyRotated(boundsA, boundsB, angle) → {Object}

Copies bounds after rotated by angle.

Parameters:
Name Type Description
boundsA Object bounds to copy into
boundsB Object bounds to rotate
angle Number angle in radians
Source:
Returns:
{ Object } boundsA

<static> boundsCopyX(boundsA, boundsB, offsetX, scaleX) → {Object}

Copies the horizontal properties of a bounds object into another bounds object, with the addition of optional offset position and scale.

Parameters:
Name Type Argument Default Description
boundsA Object bounds to copy into
boundsB Object bounds to copy from
offsetX Number <optional>
0 offset x
scaleX Number <optional>
1 scale x
Source:
See:
Returns:
{ Object } bounding object based on bounds plus offset

<static> boundsCopyY(boundsA, boundsB, offsetY, scaleY) → {Object}

Copies the vertical properties of a bounds object into another bounds object, with the addition of optional offset position and scale.

Parameters:
Name Type Argument Default Description
boundsA Object bounds to copy into
boundsB Object bounds to copy from
offsetY Number <optional>
0 offset y
scaleY Number <optional>
1 scale y
Source:
See:
Returns:
{ Object } bounding object based on bounds plus offset

<static> boundsIntersect(boundsA, boundsB) → {Boolean}

This is a convenience method to test intersection of two bounding boxes.

Parameters:
Name Type Description
boundsA Object bounding object A
boundsB Object bounding object B
Source:
See:
Returns:
{ Boolean } whether bounds intersect

<static> boundsMinMax(minX, minY, maxX, maxY, bounds) → {Object}

Calculates bounds from min/max values.

Parameters:
Name Type Argument Description
minX Number x position of top left
minY Number y position of top left
maxX Number x position of bottom right
maxY Number y position of bottom right
bounds Object <optional>
bounding object
Source:
Returns:
{ Object } bounding object
Example
// get bounds
var bounds = ig.utilsintersection.boundsMinMax( 0, 0, 100, 100 );
// left
bounds.minX;
// right
bounds.maxX;
// top
bounds.minY;
// bottom
bounds.maxY;
// width
bounds.width;
// height
bounds.height;

<static> boundsOfPoints(points, bounds) → {Object}

Returns bounds from a set of points. Tip: each point should be an object with x and y values.

Parameters:
Name Type Argument Description
points Array Array of points.
bounds Object <optional>
bounding object
Source:
Returns:
{ Object } bounding object
Example
// get bounds
var bounds = ig.utilsintersection.boundsOfPoints( [
     {x: 0, y: 0},
     {x: 100, y: 0},
     {x: 100, y: 100},
     {x: 0, y: 100}
]);
// left
bounds.minX;
// right
bounds.maxX;
// top
bounds.minY;
// bottom
bounds.maxY;
// width
bounds.width;
// height
bounds.height;

<static> entitiesInAABB(minX, minY, maxX, maxY, targetable, layerName, unsorted) → {Array}

Finds all entities intersecting an axis aligned bounding box in world space coordinates.

Parameters:
Name Type Argument Description
minX Number left position.
minY Number top position.
maxX Number right position.
maxY Number bottom position.
targetable Boolean <optional>
only find entities that are targetable.
layerName Object <optional>
name of layer to search.
unsorted Boolean <optional>
whether to sort.
Source:
Returns:
{ Array } list of all entities intersecting box.

<static> getIsAABBInScreen(x, y, width, height) → {Boolean}

Gets if an axis aligned bounding box is in the screen.

Parameters:
Name Type Description
x Number bounds top left x position
y Number bounds top left y position
width Number bounds width
height Number bounds height
Source:
Returns:
{ Boolean } whether bounds is in screen

<static> pointInAABB(x, y, minX, minY, maxX, maxY) → {Boolean}

This is a convenience method to test intersection of a point with a bounding box.

Parameters:
Name Type Description
x Number point x
y Number point y
minX Number bounds left
minY Number bounds top
maxX Number bounds right
maxY Number bounds bottom
Source:
See:
Returns:
{ Boolean } whether point is inside bounds

<static> pointInBounds(x, y, bounds) → {Boolean}

This is a convenience method to test intersection of a point with a bounding box.

Parameters:
Name Type Description
x Number point x
y Number point y
bounds Object bounding object
Source:
See:
Returns:
{ Boolean } whether point is inside bounds

<static> pointInCircle(x, y, cx, cy, radius) → {Boolean}

Checks if a point lies inside or on the edge of a circle.

Parameters:
Name Type Description
x Number point x
y Number point y
cx Number center x of circle
cy Number center y of circle
radius Number radius of circle
Source:
Returns:
{ Boolean } whether point is inside circle

<static> pointInPolygon(x, y, vertices) → {Boolean}

Determine if a point is inside a polygon.

Parameters:
Name Type Description
x Number point x
y Number point y
vertices Array array of vertices that defines a polygon
Source:
Returns:
{ Boolean } true if polygon contains the given point

<static> sortByDistance(x, y, entities) → {Array}

Sort a list of entities by distance to a point in world space coordinates. IMPORTANT: this modifies the array in place.

Parameters:
Name Type Description
x Number x position
y Number y position
entities Array list of entities
Source:
Returns:
{ Array } list of entities modified in place.