UNPKG

detect-collisions

Version:

Points, Lines, Boxes, Polygons (also hollow), Ellipses, Circles. RayCasting, offsets, rotation, scaling, bounding box padding, flags for static and ghost/trigger bodies

74 lines (73 loc) 1.84 kB
"use strict"; /* tslint:disable:one-variable-per-declaration */ Object.defineProperty(exports, "__esModule", { value: true }); exports.map = exports.filter = exports.every = exports.some = exports.forEach = void 0; /** * 40-90% faster than built-in Array.forEach function. * * basic benchmark: https://jsbench.me/urle772xdn */ const forEach = (array, callback) => { for (let i = 0, l = array.length; i < l; i++) { callback(array[i], i); } }; exports.forEach = forEach; /** * 20-90% faster than built-in Array.some function. * * basic benchmark: https://jsbench.me/l0le7bnnsq */ const some = (array, callback) => { for (let i = 0, l = array.length; i < l; i++) { if (callback(array[i], i)) { return true; } } return false; }; exports.some = some; /** * 20-40% faster than built-in Array.every function. * * basic benchmark: https://jsbench.me/unle7da29v */ const every = (array, callback) => { for (let i = 0, l = array.length; i < l; i++) { if (!callback(array[i], i)) { return false; } } return true; }; exports.every = every; /** * 20-60% faster than built-in Array.filter function. * * basic benchmark: https://jsbench.me/o1le77ev4l */ const filter = (array, callback) => { const output = []; for (let i = 0, l = array.length; i < l; i++) { const item = array[i]; if (callback(item, i)) { output.push(item); } } return output; }; exports.filter = filter; /** * 20-70% faster than built-in Array.map * * basic benchmark: https://jsbench.me/oyle77vbpc */ const map = (array, callback) => { const l = array.length; const output = new Array(l); for (let i = 0; i < l; i++) { output[i] = callback(array[i], i); } return output; }; exports.map = map;