forked from mourner/rbush-knn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rbush-3d-knn.min.js
1 lines (1 loc) · 1.46 KB
/
rbush-3d-knn.min.js
1
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self)["rbush-3d-knn"]=n()}(this,(function(){"use strict";class t{constructor(t=[],e=n){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],n=this.data.pop();return this.length--,this.length>0&&(this.data[0]=n,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:n,compare:e}=this,i=n[t];for(;t>0;){const s=t-1>>1,h=n[s];if(e(i,h)>=0)break;n[t]=h,t=s}n[t]=i}_down(t){const{data:n,compare:e}=this,i=this.length>>1,s=n[t];for(;t<i;){let i=1+(t<<1),h=n[i];const o=i+1;if(o<this.length&&e(n[o],h)<0&&(i=o,h=n[o]),e(h,s)>=0)break;n[t]=h,t=i}n[t]=s}}function n(t,n){return t<n?-1:t>n?1:0}function e(t,n){return t.dist-n.dist}function i(t,n,e,i){var h=s(t,i.minX,i.maxX),o=s(n,i.minY,i.maxY),r=s(e,i.minZ,i.maxZ);return Math.sqrt(h*h+o*o+r*r)}function s(t,n,e){return t<n?n-t:t<=e?0:t-e}return function(n,s,h,o,r,a,d){for(var u,f,l,p,c=n.data,g=[],m=new t(void 0,e);c;){for(u=0;u<c.children.length;u++)f=c.children[u],l=i(s,h,o,c.children[u]),(!d||l<=d)&&m.push({node:f,isItem:c.leaf,dist:l});for(;m.length&&m.peek().isItem;)if(p=m.pop().node,a&&!a(p)||g.push(p),r&&g.length===r)return g;(c=m.pop())&&(c=c.node)}return g}}));