Package Exports
- aabb-collisions-detector
- aabb-collisions-detector/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aabb-collisions-detector) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
AABB Collisions Detector
It is a library for detecting collisions between simple geometric shapes such as rectangles, circles, points and lines. It uses typescript and has no dependencies. Easy to use, compatible with both canvas and any rendering libraries such as pixi.js , phaser.js and others.
Installation
npm
npm i --save aabb-collisions-detectoryarn
yarn add aabb-collisions-detectorAPI
| Detector | Description |
|---|---|
| isRectIntersectsRect(squareA, squareB) | Determines whether two rectangles intersect |
| isRectIntersectsCircle(square, circle) | Determines whether the rectangle intersects with the circle |
| isCircleIntersectsCircle(circleA, circleB) | Determines whether two circles intersect |
| isPointIntersectsCircle(point, circle) | Determines whether a point is inside a circle |
| isCircleIntersectsLine(circle, line) | Determines whether the line intersects with the circle |
Code Example
import {
// types
CollisionsRectangle,
CollisionsCircle,
CollisionsLine,
Point2d,
// detectors
isRectIntersectsRect,
isRectIntersectsCircle,
isCircleIntersectsCircle,
isPointIntersectsCircle,
isCircleIntersectsLine,
} from 'aabb-collisions-detector';
const squareA: CollisionsRectangle = {x: 0, y: 0, width: 100, height: 50};
const squareB: CollisionsRectangle = {x: 50, y: 50, width: 50, height: 25};
const circleA: CollisionsCircle = {x: 25, y: 25, radius: 10};
const circleB: CollisionsCircle = {x: 0, 100, radius: 10};
const point: CollisionsLine = {p1: {x: 0, y: 0}, p2: {x: 100, y: 100}};
isRectIntersectsRect(squareA, squareB);
isRectIntersectsCircle(squareA, circle);
isCircleIntersectsCircle(circleA, circleB);
isPointIntersectsCircle(point, circleA);
isCircleIntersectsLine(circleA, line);