From a2f8c2f36365a8736ffe95c29eece12793893004 Mon Sep 17 00:00:00 2001 From: redka Date: Thu, 9 Apr 2020 04:49:51 +0100 Subject: [PATCH] GrowingArray#clear() --- index.coffee | 3 +++ pnpm-lock.yaml | 18 +++++++-------- rbush.js | 60 ++++++++++++++++++++++++++++++++++---------------- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/index.coffee b/index.coffee index 33a4c12..235e190 100644 --- a/index.coffee +++ b/index.coffee @@ -40,6 +40,9 @@ class GrowingArray @current.length = @size @other?.length = @size + clear: -> + @currentLen = 0 + class GrowingArrayPool extends GrowingArray constructor: (size, @innerSize) -> diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eebb032..377c431 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,5 @@ dependencies: - box-intersect: github.com/thisredone/box-intersect/ea41cd4f9294cfece9b3f225878b4992456215db + box-intersect: github.com/thisredone/box-intersect/01c3bbf7e159937c579de2d559df0dc6c078bada devDependencies: '@rollup/plugin-buble': 0.21.1_rollup@2.3.4 '@rollup/plugin-commonjs': 11.0.2_rollup@2.3.4 @@ -116,13 +116,13 @@ packages: dev: true resolution: integrity: sha512-hRJD2ahnnpLgsj6KWMYSrmXkM3rm2Dl1qkx6IOFD5FnuNPXJIG5L0dhgKXCYTRMGzU4n0wImQ/xfmRc4POUFlg== - /@types/node/13.11.0: + /@types/node/13.11.1: dev: true resolution: - integrity: sha512-uM4mnmsIIPK/yeO+42F2RQhGUIs39K2RFmugcJANppXe6J1nvH87PvzPZYpza7Xhhs8Yn9yIAVdLZ84z61+0xQ== + integrity: sha512-eWQGP3qtxwL8FGneRrC5DwrJLGN4/dH1clNTuLfN81HCrxVtxRjygDTUoZJ5ASlDEeo0ppYFQjQIlXhtXpOn6g== /@types/resolve/0.0.8: dependencies: - '@types/node': 13.11.0 + '@types/node': 13.11.1 dev: true resolution: integrity: sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ== @@ -1195,7 +1195,7 @@ packages: rollup: 2.3.4 rollup-pluginutils: 2.8.2 serialize-javascript: 2.1.2 - terser: 4.6.10 + terser: 4.6.11 dev: true peerDependencies: rollup: '>=0.66.0 <3' @@ -1426,7 +1426,7 @@ packages: node: '>=8' resolution: integrity: sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g== - /terser/4.6.10: + /terser/4.6.11: dependencies: commander: 2.20.3 source-map: 0.6.1 @@ -1436,7 +1436,7 @@ packages: node: '>=6.0.0' hasBin: true resolution: - integrity: sha512-qbF/3UOo11Hggsbsqm2hPa6+L4w7bkr+09FNseEe8xrcVD3APGLFqE+Oz1ZKAxjYnFsj80rLOfgAtJ0LNJjtTA== + integrity: sha512-76Ynm7OXUG5xhOpblhytE7X58oeNSmC8xnNhjWVo8CksHit0U0kO4hfNbPrrYwowLWFgM2n9L176VNx2QaHmtA== /test-exclude/6.0.0: dependencies: '@istanbuljs/schema': 0.1.2 @@ -1634,14 +1634,14 @@ packages: node: '>=8' resolution: integrity: sha512-92O1HWEjw27sBfgmXiixJWT5hRBp2eobqXicLtPBIDBhYB+1HpwZlXmbW2luivBJHBzki+7VyCLRtAkScbTBQA== - github.com/thisredone/box-intersect/ea41cd4f9294cfece9b3f225878b4992456215db: + github.com/thisredone/box-intersect/01c3bbf7e159937c579de2d559df0dc6c078bada: dependencies: bit-twiddle: 1.0.2 typedarray-pool: 1.2.0 dev: false name: box-intersect resolution: - tarball: 'https://codeload.github.com/thisredone/box-intersect/tar.gz/ea41cd4f9294cfece9b3f225878b4992456215db' + tarball: 'https://codeload.github.com/thisredone/box-intersect/tar.gz/01c3bbf7e159937c579de2d559df0dc6c078bada' version: 1.0.2 specifiers: '@rollup/plugin-buble': ^0.21.1 diff --git a/rbush.js b/rbush.js index 208e008..5dd0707 100644 --- a/rbush.js +++ b/rbush.js @@ -1,8 +1,8 @@ (function (global, factory) { -typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('box-intersect')) : -typeof define === 'function' && define.amd ? define(['box-intersect'], factory) : -(global = global || self, global.RBush = factory(global.boxIntersect)); -}(this, (function (boxIntersect$1) { 'use strict'; +typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('box-intersect')) : +typeof define === 'function' && define.amd ? define(['exports', 'box-intersect'], factory) : +(global = global || self, factory(global.RBush = {}, global.boxIntersect)); +}(this, (function (exports, boxIntersect$1) { 'use strict'; boxIntersect$1 = boxIntersect$1 && Object.prototype.hasOwnProperty.call(boxIntersect$1, 'default') ? boxIntersect$1['default'] : boxIntersect$1; @@ -95,6 +95,10 @@ GrowingArray = /*@__PURE__*/(function () { return (ref = this.other) != null ? ref.length = this.size : void 0; }; + GrowingArray.prototype.clear = function clear () { + return this.currentLen = 0; + }; + return GrowingArray; }()); @@ -271,18 +275,22 @@ RBush = /*@__PURE__*/(function () { this.clear(); } - RBush.prototype.all = function all () { - this.result.currentLen = 0; + RBush.prototype.all = function all (predicate, result) { + if ( result === void 0 ) result = this.result; + + result.currentLen = 0; this.searchPath.currentLen = 0; - return this._all(this.data); + return this._all(this.data, predicate, result); }; - RBush.prototype.search = function search (bbox, predicate) { + RBush.prototype.search = function search (bbox, predicate, result) { + if ( result === void 0 ) result = this.result; + var child, j, len, node, ref; node = this.data; - this.result.currentLen = 0; + result.currentLen = 0; if (!intersects(bbox, node.bbox)) { - return this.result; + return result; } this.searchPath.currentLen = 0; while (node) { @@ -293,10 +301,10 @@ RBush = /*@__PURE__*/(function () { if (intersects(bbox, child.bbox)) { if (node.leaf) { if ((predicate == null) || predicate(child)) { - this.result.push(child); + result.push(child); } } else if (contains(bbox, child.bbox)) { - this._all(child, predicate); + this._all(child, predicate, result); } else { this.searchPath.push(child); } @@ -305,7 +313,7 @@ RBush = /*@__PURE__*/(function () { } node = this.searchPath.pop(); } - return this.result; + return result; }; RBush.prototype.collides = function collides (bbox) { @@ -516,7 +524,7 @@ RBush = /*@__PURE__*/(function () { return this.raycastResponse; }; - RBush.prototype._all = function _all (node, predicate) { + RBush.prototype._all = function _all (node, predicate, result) { var child, i, j, l, len, len1, ref, ref1; i = this.searchPath.currentLen; while (node) { @@ -526,7 +534,7 @@ RBush = /*@__PURE__*/(function () { child = ref[j]; if (!child._ignore) { if ((predicate == null) || predicate(child)) { - this.result.push(child); + result.push(child); } } } @@ -542,7 +550,7 @@ RBush = /*@__PURE__*/(function () { } node = this.searchPath.pop(); } - return this.result; + return result; }; RBush.prototype._chooseSubtree = function _chooseSubtree (bbox, node) { @@ -820,8 +828,22 @@ createNode = function(children) { return node; }; -var rbush = RBush; - -return rbush; +var rbush = {RBush: RBush, boxIntersect: boxIntersect, rayBboxDistance: rayBboxDistance, GrowingArray: GrowingArray, GrowingArrayPool: GrowingArrayPool, ObjectStorage: ObjectStorage}; +var rbush_1 = rbush.RBush; +var rbush_2 = rbush.boxIntersect; +var rbush_3 = rbush.rayBboxDistance; +var rbush_4 = rbush.GrowingArray; +var rbush_5 = rbush.GrowingArrayPool; +var rbush_6 = rbush.ObjectStorage; + +exports.GrowingArray = rbush_4; +exports.GrowingArrayPool = rbush_5; +exports.ObjectStorage = rbush_6; +exports.RBush = rbush_1; +exports.boxIntersect = rbush_2; +exports.default = rbush; +exports.rayBboxDistance = rbush_3; + +Object.defineProperty(exports, '__esModule', { value: true }); })));