detect-collisions-quad-tree
Version:
Points, Lines, Boxes, Polygons (also hollow), Ellipses, Circles. RayCasting, offsets, rotation, scaling, bounding box padding, flags for static and ghost/trigger bodies.(based on https://github.com/Prozi/detect-collisions)
2 lines • 37.4 kB
JavaScript
/*! For license information please see index.mjs.LICENSE.txt */
var t={499:function(t,e,n){var r,s;r=function(){var t={};function e(t,e){this.x=t||0,this.y=e||0}function n(t,n){this.pos=t||new e,this.r=n||0,this.offset=new e}function r(t,n){this.pos=t||new e,this.angle=0,this.offset=new e,this.setPoints(n||[])}function s(t,n,r){this.pos=t||new e,this.w=n||0,this.h=r||0}function i(){this.a=null,this.b=null,this.overlapN=new e,this.overlapV=new e,this.clear()}t.Vector=e,t.V=e,e.prototype.copy=e.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this},e.prototype.clone=e.prototype.clone=function(){return new e(this.x,this.y)},e.prototype.perp=e.prototype.perp=function(){var t=this.x;return this.x=this.y,this.y=-t,this},e.prototype.rotate=e.prototype.rotate=function(t){var e=this.x,n=this.y;return this.x=e*Math.cos(t)-n*Math.sin(t),this.y=e*Math.sin(t)+n*Math.cos(t),this},e.prototype.reverse=e.prototype.reverse=function(){return this.x=-this.x,this.y=-this.y,this},e.prototype.normalize=e.prototype.normalize=function(){var t=this.len();return t>0&&(this.x=this.x/t,this.y=this.y/t),this},e.prototype.add=e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.sub=e.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},e.prototype.scale=e.prototype.scale=function(t,e){return this.x*=t,this.y*=void 0!==e?e:t,this},e.prototype.project=e.prototype.project=function(t){var e=this.dot(t)/t.len2();return this.x=e*t.x,this.y=e*t.y,this},e.prototype.projectN=e.prototype.projectN=function(t){var e=this.dot(t);return this.x=e*t.x,this.y=e*t.y,this},e.prototype.reflect=e.prototype.reflect=function(t){var e=this.x,n=this.y;return this.project(t).scale(2),this.x-=e,this.y-=n,this},e.prototype.reflectN=e.prototype.reflectN=function(t){var e=this.x,n=this.y;return this.projectN(t).scale(2),this.x-=e,this.y-=n,this},e.prototype.dot=e.prototype.dot=function(t){return this.x*t.x+this.y*t.y},e.prototype.len2=e.prototype.len2=function(){return this.dot(this)},e.prototype.len=e.prototype.len=function(){return Math.sqrt(this.len2())},t.Circle=n,n.prototype.getAABBAsBox=n.prototype.getAABBAsBox=function(){var t=this.r;return new s(this.pos.clone().add(this.offset).sub(new e(t,t)),2*t,2*t)},n.prototype.getAABB=n.prototype.getAABB=function(){return this.getAABBAsBox().toPolygon()},n.prototype.setOffset=n.prototype.setOffset=function(t){return this.offset=t,this},t.Polygon=r,r.prototype.setPoints=r.prototype.setPoints=function(t){if(!this.points||this.points.length!==t.length){var n,r=this.calcPoints=[],s=this.edges=[],i=this.normals=[];for(n=0;n<t.length;n++){var o=t[n],a=n<t.length-1?t[n+1]:t[0];o===a||o.x!==a.x||o.y!==a.y?(r.push(new e),s.push(new e),i.push(new e)):(t.splice(n,1),n-=1)}}return this.points=t,this._recalc(),this},r.prototype.setAngle=r.prototype.setAngle=function(t){return this.angle=t,this._recalc(),this},r.prototype.setOffset=r.prototype.setOffset=function(t){return this.offset=t,this._recalc(),this},r.prototype.rotate=r.prototype.rotate=function(t){for(var e=this.points,n=e.length,r=0;r<n;r++)e[r].rotate(t);return this._recalc(),this},r.prototype.translate=r.prototype.translate=function(t,e){for(var n=this.points,r=n.length,s=0;s<r;s++)n[s].x+=t,n[s].y+=e;return this._recalc(),this},r.prototype._recalc=function(){var t,e=this.calcPoints,n=this.edges,r=this.normals,s=this.points,i=this.offset,o=this.angle,a=s.length;for(t=0;t<a;t++){var h=e[t].copy(s[t]);h.x+=i.x,h.y+=i.y,0!==o&&h.rotate(o)}for(t=0;t<a;t++){var c=e[t],l=t<a-1?e[t+1]:e[0],u=n[t].copy(l).sub(c);r[t].copy(u).perp().normalize()}return this},r.prototype.getAABBAsBox=r.prototype.getAABBAsBox=function(){for(var t=this.calcPoints,n=t.length,r=t[0].x,i=t[0].y,o=t[0].x,a=t[0].y,h=1;h<n;h++){var c=t[h];c.x<r?r=c.x:c.x>o&&(o=c.x),c.y<i?i=c.y:c.y>a&&(a=c.y)}return new s(this.pos.clone().add(new e(r,i)),o-r,a-i)},r.prototype.getAABB=r.prototype.getAABB=function(){return this.getAABBAsBox().toPolygon()},r.prototype.getCentroid=r.prototype.getCentroid=function(){for(var t=this.calcPoints,n=t.length,r=0,s=0,i=0,o=0;o<n;o++){var a=t[o],h=o===n-1?t[0]:t[o+1],c=a.x*h.y-h.x*a.y;r+=(a.x+h.x)*c,s+=(a.y+h.y)*c,i+=c}return new e(r/=i*=3,s/=i)},t.Box=s,s.prototype.toPolygon=s.prototype.toPolygon=function(){var t=this.pos,n=this.w,s=this.h;return new r(new e(t.x,t.y),[new e,new e(n,0),new e(n,s),new e(0,s)])},t.Response=i,i.prototype.clear=i.prototype.clear=function(){return this.aInB=!0,this.bInA=!0,this.overlap=Number.MAX_VALUE,this};for(var o=[],a=0;a<10;a++)o.push(new e);var h=[];for(a=0;a<5;a++)h.push([]);var c=new i,l=new s(new e,1e-6,1e-6).toPolygon();function u(t,e,n){for(var r=Number.MAX_VALUE,s=-Number.MAX_VALUE,i=t.length,o=0;o<i;o++){var a=t[o].dot(e);a<r&&(r=a),a>s&&(s=a)}n[0]=r,n[1]=s}function p(t,e,n,r,s,i){var a=h.pop(),c=h.pop(),l=o.pop().copy(e).sub(t),p=l.dot(s);if(u(n,s,a),u(r,s,c),c[0]+=p,c[1]+=p,a[0]>c[1]||c[0]>a[1])return o.push(l),h.push(a),h.push(c),!0;if(i){var y,f,x=0;a[0]<c[0]?(i.aInB=!1,a[1]<c[1]?(x=a[1]-c[0],i.bInA=!1):x=(y=a[1]-c[0])<(f=c[1]-a[0])?y:-f):(i.bInA=!1,a[1]>c[1]?(x=a[0]-c[1],i.aInB=!1):x=(y=a[1]-c[0])<(f=c[1]-a[0])?y:-f);var g=Math.abs(x);g<i.overlap&&(i.overlap=g,i.overlapN.copy(s),x<0&&i.overlapN.reverse())}return o.push(l),h.push(a),h.push(c),!1}function y(t,e){var n=t.len2(),r=e.dot(t);return r<0?f:r>n?g:x}t.isSeparatingAxis=p;var f=-1,x=0,g=1;function d(t,e,n){for(var r=o.pop().copy(e.pos).add(e.offset).sub(t.pos),s=e.r,i=s*s,a=t.calcPoints,h=a.length,c=o.pop(),l=o.pop(),u=0;u<h;u++){var p=u===h-1?0:u+1,x=0===u?h-1:u-1,d=0,v=null;c.copy(t.edges[u]),l.copy(r).sub(a[u]),n&&l.len2()>i&&(n.aInB=!1);var m=y(c,l);if(m===f){c.copy(t.edges[x]);var P=o.pop().copy(r).sub(a[x]);if((m=y(c,P))===g){if((B=l.len())>s)return o.push(r),o.push(c),o.push(l),o.push(P),!1;n&&(n.bInA=!1,v=l.normalize(),d=s-B)}o.push(P)}else if(m===g){if(c.copy(t.edges[p]),l.copy(r).sub(a[p]),(m=y(c,l))===f){if((B=l.len())>s)return o.push(r),o.push(c),o.push(l),!1;n&&(n.bInA=!1,v=l.normalize(),d=s-B)}}else{var A=c.perp().normalize(),B=l.dot(A),b=Math.abs(B);if(B>0&&b>s)return o.push(r),o.push(A),o.push(l),!1;n&&(v=A,d=s-B,(B>=0||d<2*s)&&(n.bInA=!1))}v&&n&&Math.abs(d)<Math.abs(n.overlap)&&(n.overlap=d,n.overlapN.copy(v))}return n&&(n.a=t,n.b=e,n.overlapV.copy(n.overlapN).scale(n.overlap)),o.push(r),o.push(c),o.push(l),!0}function v(t,e,n){for(var r=t.calcPoints,s=r.length,i=e.calcPoints,o=i.length,a=0;a<s;a++)if(p(t.pos,e.pos,r,i,t.normals[a],n))return!1;for(a=0;a<o;a++)if(p(t.pos,e.pos,r,i,e.normals[a],n))return!1;return n&&(n.a=t,n.b=e,n.overlapV.copy(n.overlapN).scale(n.overlap)),!0}return t.pointInCircle=function(t,e){var n=o.pop().copy(t).sub(e.pos).sub(e.offset),r=e.r*e.r,s=n.len2();return o.push(n),s<=r},t.pointInPolygon=function(t,e){l.pos.copy(t),c.clear();var n=v(l,e,c);return n&&(n=c.aInB),n},t.testCircleCircle=function(t,e,n){var r=o.pop().copy(e.pos).add(e.offset).sub(t.pos).sub(t.offset),s=t.r+e.r,i=s*s,a=r.len2();if(a>i)return o.push(r),!1;if(n){var h=Math.sqrt(a);n.a=t,n.b=e,n.overlap=s-h,n.overlapN.copy(r.normalize()),n.overlapV.copy(r).scale(n.overlap),n.aInB=t.r<=e.r&&h<=e.r-t.r,n.bInA=e.r<=t.r&&h<=t.r-e.r}return o.push(r),!0},t.testPolygonCircle=d,t.testCirclePolygon=function(t,e,n){var r=d(e,t,n);if(r&&n){var s=n.a,i=n.aInB;n.overlapN.reverse(),n.overlapV.reverse(),n.a=n.b,n.b=s,n.aInB=n.bInA,n.bInA=i}return r},t.testPolygonPolygon=v,t},void 0===(s=r.call(e,n,e,t))||(t.exports=s)},545:(t,e)=>{function n(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function r(t,e){return t<e?-1:t>e?1:0}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function t(e,s){for(var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e.length-1,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:r;o>i;){if(o-i>600){var h=o-i+1,c=s-i+1,l=Math.log(h),u=.5*Math.exp(2*l/3),p=.5*Math.sqrt(l*u*(h-u)/h)*(c-h/2<0?-1:1);t(e,s,Math.max(i,Math.floor(s-c*u/h+p)),Math.min(o,Math.floor(s+(h-c)*u/h+p)),a)}var y=e[s],f=i,x=o;for(n(e,i,s),a(e[o],y)>0&&n(e,i,o);f<x;){for(n(e,f,x),f++,x--;a(e[f],y)<0;)f++;for(;a(e[x],y)>0;)x--}0===a(e[i],y)?n(e,i,x):n(e,++x,o),x<=s&&(i=x+1),s<=x&&(o=x-1)}}},706:(t,e,n)=>{e.A=void 0;var r,s=(r=n(545))&&r.__esModule?r:{default:r};function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function o(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return a(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function h(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,c(r.key),r)}}function c(t){var e=function(t){if("object"!=i(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==i(e)?e:e+""}function l(t,e,n){if(!n)return e.indexOf(t);for(var r=0;r<e.length;r++)if(n(t,e[r]))return r;return-1}function u(t,e){p(t,0,t.children.length,e,t)}function p(t,e,n,r,s){s||(s=P(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(var i=e;i<n;i++){var o=t.children[i];y(s,t.leaf?r(o):o)}return s}function y(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function f(t,e){return t.minX-e.minX}function x(t,e){return t.minY-e.minY}function g(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function d(t){return t.maxX-t.minX+(t.maxY-t.minY)}function v(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function m(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function P(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function A(t,e,n,r,i){for(var o=[e,n];o.length;)if(!((n=o.pop())-(e=o.pop())<=r)){var a=e+Math.ceil((n-e)/r/2)*r;(0,s.default)(t,a,e,n,i),o.push(e,a,a,n)}}e.A=function(){return function(t,e){return e&&h(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}((function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:9;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}),[{key:"all",value:function(){return this._all(this.data,[])}},{key:"search",value:function(t){var e=this.data,n=[];if(!m(t,e))return n;for(var r=this.toBBox,s=[];e;){for(var i=0;i<e.children.length;i++){var o=e.children[i],a=e.leaf?r(o):o;m(t,a)&&(e.leaf?n.push(o):v(t,a)?this._all(o,n):s.push(o))}e=s.pop()}return n}},{key:"collides",value:function(t){var e=this.data;if(!m(t,e))return!1;for(var n=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],i=e.leaf?this.toBBox(s):s;if(m(t,i)){if(e.leaf||v(t,i))return!0;n.push(s)}}e=n.pop()}return!1}},{key:"load",value:function(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(var e=0;e<t.length;e++)this.insert(t[e]);return this}var n=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this}},{key:"insert",value:function(t){return t&&this._insert(t,this.data.height-1),this}},{key:"clear",value:function(){return this.data=P([]),this}},{key:"remove",value:function(t,e){if(!t)return this;for(var n,r,s,i=this.data,o=this.toBBox(t),a=[],h=[];i||a.length;){if(i||(i=a.pop(),r=a[a.length-1],n=h.pop(),s=!0),i.leaf){var c=l(t,i.children,e);if(-1!==c)return i.children.splice(c,1),a.push(i),this._condense(a),this}s||i.leaf||!v(i,o)?r?(n++,i=r.children[n],s=!1):i=null:(a.push(i),h.push(n),n=0,r=i,i=i.children[0])}return this}},{key:"toBBox",value:function(t){return t}},{key:"compareMinX",value:function(t,e){return t.minX-e.minX}},{key:"compareMinY",value:function(t,e){return t.minY-e.minY}},{key:"toJSON",value:function(){return this.data}},{key:"fromJSON",value:function(t){return this.data=t,this}},{key:"_all",value:function(t,e){for(var n=[];t;)t.leaf?e.push.apply(e,o(t.children)):n.push.apply(n,o(t.children)),t=n.pop();return e}},{key:"_build",value:function(t,e,n,r){var s,i=n-e+1,o=this._maxEntries;if(i<=o)return u(s=P(t.slice(e,n+1)),this.toBBox),s;r||(r=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/Math.pow(o,r-1))),(s=P([])).leaf=!1,s.height=r;var a=Math.ceil(i/o),h=a*Math.ceil(Math.sqrt(o));A(t,e,n,h,this.compareMinX);for(var c=e;c<=n;c+=h){var l=Math.min(c+h-1,n);A(t,c,l,a,this.compareMinY);for(var p=c;p<=l;p+=a){var y=Math.min(p+a-1,l);s.children.push(this._build(t,p,y,r-1))}}return u(s,this.toBBox),s}},{key:"_chooseSubtree",value:function(t,e,n,r){for(;r.push(e),!e.leaf&&r.length-1!==n;){for(var s=1/0,i=1/0,o=void 0,a=0;a<e.children.length;a++){var h=e.children[a],c=g(h),l=(u=t,p=h,(Math.max(p.maxX,u.maxX)-Math.min(p.minX,u.minX))*(Math.max(p.maxY,u.maxY)-Math.min(p.minY,u.minY))-c);l<i?(i=l,s=c<s?c:s,o=h):l===i&&c<s&&(s=c,o=h)}e=o||e.children[0]}var u,p;return e}},{key:"_insert",value:function(t,e,n){var r=n?t:this.toBBox(t),s=[],i=this._chooseSubtree(r,this.data,e,s);for(i.children.push(t),y(i,r);e>=0&&s[e].children.length>this._maxEntries;)this._split(s,e),e--;this._adjustParentBBoxes(r,s,e)}},{key:"_split",value:function(t,e){var n=t[e],r=n.children.length,s=this._minEntries;this._chooseSplitAxis(n,s,r);var i=this._chooseSplitIndex(n,s,r),o=P(n.children.splice(i,n.children.length-i));o.height=n.height,o.leaf=n.leaf,u(n,this.toBBox),u(o,this.toBBox),e?t[e-1].children.push(o):this._splitRoot(n,o)}},{key:"_splitRoot",value:function(t,e){this.data=P([t,e]),this.data.height=t.height+1,this.data.leaf=!1,u(this.data,this.toBBox)}},{key:"_chooseSplitIndex",value:function(t,e,n){for(var r,s,i,o,a,h,c,l=1/0,u=1/0,y=e;y<=n-e;y++){var f=p(t,0,y,this.toBBox),x=p(t,y,n,this.toBBox),d=(s=f,i=x,void 0,void 0,void 0,void 0,o=Math.max(s.minX,i.minX),a=Math.max(s.minY,i.minY),h=Math.min(s.maxX,i.maxX),c=Math.min(s.maxY,i.maxY),Math.max(0,h-o)*Math.max(0,c-a)),v=g(f)+g(x);d<l?(l=d,r=y,u=v<u?v:u):d===l&&v<u&&(u=v,r=y)}return r||n-e}},{key:"_chooseSplitAxis",value:function(t,e,n){var r=t.leaf?this.compareMinX:f,s=t.leaf?this.compareMinY:x;this._allDistMargin(t,e,n,r)<this._allDistMargin(t,e,n,s)&&t.children.sort(r)}},{key:"_allDistMargin",value:function(t,e,n,r){t.children.sort(r);for(var s=this.toBBox,i=p(t,0,e,s),o=p(t,n-e,n,s),a=d(i)+d(o),h=e;h<n-e;h++){var c=t.children[h];y(i,t.leaf?s(c):c),a+=d(i)}for(var l=n-e-1;l>=e;l--){var u=t.children[l];y(o,t.leaf?s(u):u),a+=d(o)}return a}},{key:"_adjustParentBBoxes",value:function(t,e,n){for(var r=n;r>=0;r--)y(e[r],t)}},{key:"_condense",value:function(t){for(var e,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(e=t[n-1].children).splice(e.indexOf(t[n]),1):this.clear():u(t[n],this.toBBox)}}])}()}},e={};function n(r){var s=e[r];if(void 0!==s)return s.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var r={};n.d(r,{g9:()=>i,Dh:()=>s,az:()=>Mt,jl:()=>Bt,up:()=>$,Pp:()=>Ct,N1:()=>_t,bR:()=>wt,tS:()=>bt,a5:()=>q,XC:()=>a.A,YK:()=>o.Response,$S:()=>o.Circle,hf:()=>o.Polygon,gH:()=>o.Vector,iQ:()=>Yt,cp:()=>vt,iC:()=>nt,bc:()=>it,P9:()=>ot,Gr:()=>I,Qp:()=>k,UY:()=>S,x8:()=>tt,kK:()=>at,RE:()=>xt,ge:()=>J,zd:()=>W,AQ:()=>pt,kU:()=>H,Io:()=>Z,Pz:()=>ft,F$:()=>yt,iw:()=>M,GB:()=>mt,At:()=>F,S7:()=>Q,vH:()=>et,SA:()=>lt,Wx:()=>dt,Jy:()=>ut,S8:()=>Pt,G0:()=>st,Op:()=>D,eI:()=>V,M_:()=>O,S4:()=>E,ed:()=>G,pn:()=>v,AV:()=>ct,Kg:()=>ht,Cy:()=>At,N0:()=>rt,s3:()=>_,yC:()=>Y,cU:()=>w,x4:()=>X,KJ:()=>K,FN:()=>gt});var s,i,o=n(499),a=n(706);function h(t,e,n,r){const s=e[0]-t[0],i=e[1]-t[1],o=r[0]-n[0],a=r[1]-n[1];if(o*i-a*s==0)return!1;const h=(s*(n[1]-t[1])+i*(t[0]-n[0]))/(o*i-a*s),c=(o*(t[1]-n[1])+a*(n[0]-t[0]))/(a*s-o*i);return h>=0&&h<=1&&c>=0&&c<=1}function c(t,e,n){return(e[0]-t[0])*(n[1]-t[1])-(n[0]-t[0])*(e[1]-t[1])}function l(t,e,n){return c(t,e,n)>0}function u(t,e,n){return c(t,e,n)<0}function p(t,e,n){return c(t,e,n)<=0}function y(t,e){const n=e[0]-t[0],r=e[1]-t[1];return n*n+r*r}function f(t,e){const n=t.length;return t[e<0?e%n+n:e%n]}function x(t,e,n,r){for(let s=n;s<r;s++)t.push(e[s])}function g(t,e){return u(f(t,e-1),f(t,e),f(t,e+1))}function d(t,e,n){for(let r=0;r!==t.length;++r)if(r!==e&&r!==n&&(r+1)%t.length!==e&&(r+1)%t.length!==n&&h(f(t,e),f(t,n),f(t,r),f(t,r+1)))return!1;return!0}function v(t){const e=t;let n;for(n=0;n<e.length-1;n++)for(let t=0;t<n-1;t++)if(h(e[n],e[n+1],e[t],e[t+1]))return!1;for(n=1;n<e.length-2;n++)if(h(e[0],e[e.length-1],e[n],e[n+1]))return!1;return!0}function m(t,e,n,r,s){void 0===s&&(s=0);const i=e[1]-t[1],o=t[0]-e[0],a=i*t[0]+o*t[1],h=r[1]-n[1],c=n[0]-r[0],l=h*n[0]+c*n[1],u=i*c-h*o;return p=u,y=0,void 0===(f=s)&&(f=0),f=f||0,Math.abs(p-y)<=f?[0,0]:[(c*a-o*l)/u,(i*l-h*a)/u];var p,y,f}function P(t,e,n,r,s,i,o){void 0===e&&(e=[]),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===s&&(s=25),void 0===i&&(i=100),void 0===o&&(o=0);let a=[0,0],h=[0,0],v=[0,0],A=0,B=0,b=0,C=0,M=0,w=0,_=0;const X=[],Y=[],I=t,k=t;if(k.length<3)return e;if(++o>i)return console.warn("quickDecomp: max level ("+i+") reached."),e;for(let E=0;E<t.length;++E)if(g(I,E)){n.push(I[E]),A=B=Number.MAX_VALUE;for(let e=0;e<t.length;++e)l(f(I,E-1),f(I,E),f(I,e))&&p(f(I,E-1),f(I,E),f(I,e-1))&&(v=m(f(I,E-1),f(I,E),f(I,e),f(I,e-1)),u(f(I,E+1),f(I,E),v)&&(b=y(I[E],v),b<B&&(B=b,h=v,w=e))),l(f(I,E+1),f(I,E),f(I,e+1))&&p(f(I,E+1),f(I,E),f(I,e))&&(v=m(f(I,E+1),f(I,E),f(I,e),f(I,e+1)),l(f(I,E-1),f(I,E),v)&&(b=y(I[E],v),b<A&&(A=b,a=v,M=e)));if(w===(M+1)%t.length)v[0]=(h[0]+a[0])/2,v[1]=(h[1]+a[1])/2,r.push(v),E<M?(x(X,I,E,M+1),X.push(v),Y.push(v),0!==w&&x(Y,I,w,I.length),x(Y,I,0,E+1)):(0!==E&&x(X,I,E,I.length),x(X,I,0,M+1),X.push(v),Y.push(v),x(Y,I,w,E+1));else{if(w>M&&(M+=t.length),C=Number.MAX_VALUE,M<w)return e;for(let e=w;e<=M;++e)S=f(I,E-1),V=f(I,E),N=f(I,e),c(S,V,N)>=0&&p(f(I,E+1),f(I,E),f(I,e))&&(b=y(f(I,E),f(I,e)),b<C&&d(I,E,e)&&(C=b,_=e%t.length));E<_?(x(X,I,E,_+1),0!==_&&x(Y,I,_,k.length),x(Y,I,0,E+1)):(0!==E&&x(X,I,E,k.length),x(X,I,0,_+1),x(Y,I,_,E+1))}return X.length<Y.length?(P(X,e,n,r,s,i,o),P(Y,e,n,r,s,i,o)):(P(Y,e,n,r,s,i,o),P(X,e,n,r,s,i,o)),e}var S,V,N;return e.push(t),e}!function(t){t.Ellipse="Ellipse",t.Circle="Circle",t.Polygon="Polygon",t.Box="Box",t.Line="Line",t.Point="Point"}(s||(s={})),function(t){t[t.Ellipse=32]="Ellipse",t[t.Circle=16]="Circle",t[t.Polygon=8]="Polygon",t[t.Box=4]="Box",t[t.Line=2]="Line",t[t.Point=1]="Point"}(i||(i={}));const A=(t,e)=>{for(let n=0,r=t.length;n<r;n++)e(t[n],n)},B=(t,e)=>{for(let n=0,r=t.length;n<r;n++)if(e(t[n],n))return!0;return!1},b=(t,e)=>{for(let n=0,r=t.length;n<r;n++)if(!e(t[n],n))return!1;return!0},C=(t,e)=>{const n=t.length,r=new Array(n);for(let s=0;s<n;s++)r[s]=e(t[s],s);return r};function M(t){return t.isConvex||t.typeGroup!==i.Polygon?[t]:t.convexPolygons}function w(t,e){return b(t.calcPoints,(n=>{const r={x:n.x+t.pos.x,y:n.y+t.pos.y};return(0,o.pointInCircle)(r,e)}))}function _(t,e){return B(M(e),(e=>(0,o.pointInPolygon)(t,e)))}function X(t,e){return b(t.calcPoints,(n=>_({x:n.x+t.pos.x,y:n.y+t.pos.y},e)))}function Y(t,e){return(t.x-e.pos.x)*(t.x-e.pos.x)+(t.y-e.pos.y)*(t.y-e.pos.y)==e.r*e.r}function I(t,e){const n=t.pos.x,r=t.pos.y,s=e.pos.x,i=e.pos.y,o=t.r,a=e.r,h=Math.sqrt((n-s)*(n-s)+(r-i)*(r-i));return h+a===o||h+a<o}function k(t,e){if(0===t.r)return!1;if(!_(t.pos,e))return!1;const n=C(e.calcPoints,(({x:t,y:n})=>({x:t+e.pos.x,y:n+e.pos.y})));return!B(n,(e=>(0,o.pointInCircle)(e,t)))&&!B(n,((e,r)=>V({start:r?n[r-1]:n[n.length-1],end:e},t).length>0))}function S(t,e){if(0===t.r)return!1;if(_(t.pos,e))return!1;const n=C(e.calcPoints,(({x:t,y:n})=>({x:t+e.pos.x,y:n+e.pos.y})));return!B(n,(e=>(0,o.pointInCircle)(e,t)||Y(e,t)))&&!B(n,((e,r)=>V({start:r?n[r-1]:n[n.length-1],end:e},t).length>0))}function V(t,{pos:e,r:n}){const r=t.end.x-t.start.x,s=t.end.y-t.start.y,i=t.start.x-e.x,o=t.start.y-e.y,a=-2*(r*i+s*o),h=2*(r*r+s*s),c=Math.sqrt(a*a-(i*i+o*o-n*n)*h*2);if(isNaN(c))return[];const l=(a-c)/h,u=(a+c)/h,p=[];return l<=1&&l>=0&&p.push({x:t.start.x+r*l,y:t.start.y+s*l}),u<=1&&u>=0&&p.push({x:t.start.x+r*u,y:t.start.y+s*u}),p}function N(t,e,n){const r=(n.x-t.x)*(e.y-t.y),s=(e.x-t.x)*(n.y-t.y);return r>s+Number.EPSILON?1:r+Number.EPSILON<s?-1:0}function E(t,e){return N(t.start,e.start,e.end)!==N(t.end,e.start,e.end)&&N(t.start,t.end,e.start)!==N(t.start,t.end,e.end)}function O(t,e){const n=t.end.x-t.start.x,r=t.end.y-t.start.y,s=n*(e.end.y-e.start.y)-(e.end.x-e.start.x)*r;if(0===s)return;const i=((e.end.y-e.start.y)*(e.end.x-t.start.x)+(e.start.x-e.end.x)*(e.end.y-t.start.y))/s,o=((t.start.y-t.end.y)*(e.end.x-t.start.x)+n*(e.end.y-t.start.y))/s;return i>=0&&i<=1&&o>=0&&o<=1?{x:t.start.x+i*n,y:t.start.y+i*r}:void 0}function G(t,e){const n=[];return A(e.calcPoints,((r,s)=>{const i=s?e.calcPoints[s-1]:e.calcPoints[e.calcPoints.length-1],o={start:{x:i.x+e.pos.x,y:i.y+e.pos.y},end:{x:r.x+e.pos.x,y:r.y+e.pos.y}},a=O(t,o);a&&n.push(a)})),n}function D(t,e){const n=[],r=t.pos.x,s=t.pos.y,i=t.r,o=e.pos.x,a=e.pos.y,h=e.r,c=o-r,l=a-s,u=Math.sqrt(c*c+l*l);if(u>i+h||u<Math.abs(i-h)||0===u)return n;const p=(i*i-h*h+u*u)/(2*u),y=Math.sqrt(i*i-p*p),f=r+c*p/u,x=s+l*p/u,g={x:f+y*l/u,y:x-y*c/u};n.push(g);const d={x:f-y*l/u,y:x+y*c/u};return n.push(d),n}const T={satCircleCircle:o.testCircleCircle,satCirclePolygon:o.testCirclePolygon,satPolygonCircle:o.testPolygonCircle,satPolygonPolygon:o.testPolygonPolygon,inCircleCircle:I,inCirclePolygon:k,inPolygonCircle:w,inPolygonPolygon:X};function L(t,e){const n=[],r=Object.values(i).filter((t=>"number"==typeof t));return A(r,(r=>{n[r]=r===i.Circle?T[`${e}${t}Circle`]:T[`${e}${t}Polygon`]})),n}const R=L(s.Circle,"sat"),j=L(s.Circle,"in"),z=L(s.Polygon,"sat"),U=L(s.Polygon,"in"),$=Math.PI/180,q=180/Math.PI;function H(t){return t*$}function K(t){return t*q}function W(t,e=t,n=1){const r=Math.PI*Math.hypot(t,e)*2,s=Math.max(8,Math.ceil(r/Math.max(1,n))),i=[];for(let n=0;n<s;n++){const r=n/s*2*Math.PI,a=Math.cos(r)*t,h=Math.sin(r)*e;i.push(new o.Vector(a,h))}return i}function J(t,e){return[new o.Vector(0,0),new o.Vector(t,0),new o.Vector(t,e),new o.Vector(0,e)]}function Q(t={}){return t instanceof o.Vector?t:new o.Vector(t.x||0,t.y||0)}function F(t=[]){const e=C(t,Q);return tt(e)?e.reverse():e}function Z(t,e){const n=t.x-e.x,r=t.y-e.y;return Math.hypot(n,r)}function tt(t){const e=t.length;let n=0;return A(t,((r,s)=>{const i=t[(s+1)%e];n+=(i.x-r.x)*(i.y+r.y)})),n>0}function et(t,e={}){var n;t.isStatic=!!e.isStatic,t.isTrigger=!!e.isTrigger,t.padding=e.padding||0,t.group=null!==(n=e.group)&&void 0!==n?n:2147483647,"userData"in e&&(t.userData=e.userData),e.isCentered&&t.typeGroup!==i.Circle&&(t.isCentered=!0),e.angle&&t.setAngle(e.angle)}function nt(t){const{bbox:e,minX:n,minY:r,maxX:s,maxY:i}=t;return e.minX<n||e.minY<r||e.maxX>s||e.maxY>i}function rt(t,e){return e.minX>t.maxX||e.minY>t.maxY||e.maxX<t.minX||e.maxY<t.minY}function st(t,e){return!rt(t,e)}function it({group:t},{group:e}){return t===e||!!(t>>16&65535&e)&&!!(e>>16&65535&t)}function ot(t,e){return(t.typeGroup===i.Circle?j:U)[e.typeGroup](t,e)}function at(t){return C(t,(({x:t,y:e})=>({x:t,y:e})))}function ht({x:t,y:e}={x:0,y:0}){return[t,e]}function ct([t,e]=[0,0]){return{x:t,y:e}}function lt(t,e){const n=new o.Vector(e.x-t.x,e.y-t.y),r=new o.Vector(t.x-e.x,t.y-e.y),s=2*r.dot(n.normalize());return new o.Vector(n.x*s-r.x,n.y*s-r.y).normalize()}function ut(t,e){return(t.typeGroup===i.Circle?R:z)[e.typeGroup]}function pt(t,e,n,r,s,i=2,o=4){const a=r-e,h=s-n,c=Math.atan2(h,a),l=Math.cos(c),u=Math.sin(c);let p=e,y=n,f=Math.hypot(a,h);for(;f>0;){const e=Math.min(f,i);t.moveTo(p,y),t.lineTo(p+l*e,y+u*e),p+=l*(i+o),y+=u*(i+o),f-=i+o}}function yt(t,{pos:e,calcPoints:n},r=!1){const s=n[n.length-1],i=e.x+s.x,o=e.y+s.y;1===n.length?t.arc(i,o,1,0,2*Math.PI):t.moveTo(i,o),A(n,((i,o)=>{const a=e.x+i.x,h=e.y+i.y;if(r){const r=n[o-1]||s;pt(t,e.x+r.x,e.y+r.y,a,h)}else t.lineTo(a,h)}))}function ft(t,e,n=!0){yt(t,{pos:{x:e.minX,y:e.minY},calcPoints:J(e.maxX-e.minX,e.maxY-e.minY)},n)}function xt(t){const e=new o.Response,{a:n,b:r,overlap:s,overlapN:i,overlapV:a,aInB:h,bInA:c}=t;return e.a=n,e.b=r,e.overlap=s,e.overlapN=i.clone(),e.overlapV=a.clone(),e.aInB=h,e.bInA=c,e}function gt(){return!0}function dt(t){return Math.max(0,Math.min(t,2147483647))}function vt(t){return Number(`0b${t}`.replace(/\s/g,""))}function mt(t){return"number"==typeof t?t:vt(t)}function Pt(t,e=t){return mt(t)<<16|mt(e)}function At(t,e=1,n=!0){if(!e)return;const r=Math.cos(t.angle)*e,s=Math.sin(t.angle)*e;t.setPosition(t.x+r,t.y+s,n)}class Bt extends o.Circle{constructor(t,e,n){super(Q(t),e),this.offsetCopy={x:0,y:0},this.dirty=!1,this.isConvex=!0,this.type=s.Circle,this.typeGroup=i.Circle,this.isCentered=!0,et(this,n),this.unscaledRadius=e}get x(){return this.pos.x}set x(t){this.pos.x=t,this.markAsDirty()}get y(){return this.pos.y}set y(t){this.pos.y=t,this.markAsDirty()}get scale(){return this.r/this.unscaledRadius}set scale(t){this.setScale(t)}get scaleX(){return this.scale}get scaleY(){return this.scale}get group(){return this._group}set group(t){this._group=dt(t)}move(t=1,e=!0){return At(this,t,e),this}setPosition(t,e,n=!0){return this.pos.x=t,this.pos.y=e,this.markAsDirty(n),this}setScale(t,e=t,n=!0){return this.r=this.unscaledRadius*Math.abs(t),this.markAsDirty(n),this}setAngle(t,e=!0){this.angle=t;const{x:n,y:r}=this.getOffsetWithAngle();return this.offset.x=n,this.offset.y=r,this.markAsDirty(e),this}setOffset(t,e=!0){this.offsetCopy.x=t.x,this.offsetCopy.y=t.y;const{x:n,y:r}=this.getOffsetWithAngle();return this.offset.x=n,this.offset.y=r,this.markAsDirty(e),this}getAABBAsBBox(){const t=this.pos.x+this.offset.x,e=this.pos.y+this.offset.y;return{minX:t-this.r,maxX:t+this.r,minY:e-this.r,maxY:e+this.r}}draw(t){const e=this.pos.x+this.offset.x,n=this.pos.y+this.offset.y,r=Math.abs(this.r);if(this.isTrigger){const r=Math.max(8,this.r);for(let s=0;s<r;s++){const i=s/r*2*Math.PI,o=(s-1)/r*2*Math.PI;pt(t,e+Math.cos(o)*this.r,n+Math.sin(o)*this.r,e+Math.cos(i)*this.r,n+Math.sin(i)*this.r)}}else t.moveTo(e+r,n),t.arc(e,n,r,0,2*Math.PI)}drawBVH(t){ft(t,this)}updateBody(t=this.dirty){var e;t&&(null===(e=this.system)||void 0===e||e.insert(this),this.dirty=!1)}markAsDirty(t=!1){t?this.updateBody(!0):this.dirty=!0}getOffsetWithAngle(){if(!this.offsetCopy.x&&!this.offsetCopy.y||!this.angle)return this.offsetCopy;const t=Math.sin(this.angle),e=Math.cos(this.angle);return{x:this.offsetCopy.x*e-this.offsetCopy.y*t,y:this.offsetCopy.x*t+this.offsetCopy.y*e}}}class bt extends o.Polygon{constructor(t,e,n){if(super(Q(t),F(e)),this.dirty=!1,this.type=s.Polygon,this.typeGroup=i.Polygon,this.centered=!1,this.scaleVector={x:1,y:1},!e.length)throw new Error("No points in polygon");et(this,n)}set isCentered(t){if(this.centered!==t){const{x:e,y:n}=this.getCentroidWithoutRotation();if(e||n){const r=t?1:-1;this.translate(-e*r,-n*r)}this.centered=t}}get isCentered(){return this.centered}get x(){return this.pos.x}set x(t){this.pos.x=t,this.markAsDirty()}get y(){return this.pos.y}set y(t){this.pos.y=t,this.markAsDirty()}get scaleX(){return this.scaleVector.x}get scaleY(){return this.scaleVector.y}get scale(){return(this.scaleVector.x+this.scaleVector.y)/2}set scale(t){this.setScale(t)}get group(){return this._group}set group(t){this._group=dt(t)}move(t=1,e=!0){return At(this,t,e),this}setPosition(t,e,n=!0){return this.pos.x=t,this.pos.y=e,this.markAsDirty(n),this}setScale(t,e=t,n=!0){return this.scaleVector.x=Math.abs(t),this.scaleVector.y=Math.abs(e),super.setPoints(C(this.points,((t,e)=>(t.x=this.pointsBackup[e].x*this.scaleVector.x,t.y=this.pointsBackup[e].y*this.scaleVector.y,t)))),this.markAsDirty(n),this}setAngle(t,e=!0){return super.setAngle(t),this.markAsDirty(e),this}setOffset(t,e=!0){return super.setOffset(t),this.markAsDirty(e),this}getAABBAsBBox(){const{pos:t,w:e,h:n}=this.getAABBAsBox();return{minX:t.x,minY:t.y,maxX:t.x+e,maxY:t.y+n}}getEdge(t){const{x:e,y:n}=this.calcPoints[t],r=this.calcPoints[(t+1)%this.calcPoints.length];return{start:{x:this.x+e,y:this.y+n},end:{x:this.x+r.x,y:this.y+r.y}}}draw(t){yt(t,this,this.isTrigger)}drawBVH(t){ft(t,this)}getCentroidWithoutRotation(){const t=this.angle;if(t){this.setAngle(0);const e=this.getCentroid();return this.setAngle(t),e}return this.getCentroid()}setPoints(t){return super.setPoints(t),this.updateIsConvex(),this.pointsBackup=at(t),this}translate(t,e){return super.translate(t,e),this.pointsBackup=at(this.points),this}rotate(t){return super.rotate(t),this.pointsBackup=at(this.points),this}isSimple(){return v(C(this.calcPoints,ht))}updateBody(t=this.dirty){var e;t&&(this.updateConvexPolygonPositions(),null===(e=this.system)||void 0===e||e.insert(this),this.dirty=!1)}retranslate(t=this.isCentered){const e=this.getCentroidWithoutRotation();if(e.x||e.y){const n=e.x*(t?1:-1),r=e.y*(t?1:-1);this.translate(-n,-r)}}markAsDirty(t=!1){t?this.updateBody(!0):this.dirty=!0}updateConvexPolygonPositions(){!this.isConvex&&this.convexPolygons&&A(this.convexPolygons,(t=>{t.pos.x=this.pos.x,t.pos.y=this.pos.y,t.angle!==this.angle&&t.setAngle(this.angle)}))}getConvex(){return this.typeGroup&&this.typeGroup!==i.Polygon||this.points.length<4?[]:P(C(this.calcPoints,ht))}updateConvexPolygons(t=this.getConvex()){this.isConvex||(this.convexPolygons||(this.convexPolygons=[]),A(t,((t,e)=>{this.convexPolygons[e]||(this.convexPolygons[e]=new o.Polygon),this.convexPolygons[e].pos.x=this.pos.x,this.convexPolygons[e].pos.y=this.pos.y,this.convexPolygons[e].angle=this.angle,this.convexPolygons[e].setPoints(F(C(t,ct)))})),this.convexPolygons.length=t.length)}updateIsConvex(){const t=this.getConvex();this.isConvex=t.length<=1,this.updateConvexPolygons(t)}}class Ct extends bt{constructor(t,e,n=e,r=(e+n)/Math.PI,o){super(t,W(e,n,r),o),this.type=s.Ellipse,this.typeGroup=i.Ellipse,this.isConvex=!0,this._radiusX=e,this._radiusY=n,this._step=r}set isCentered(t){}get isCentered(){return!0}get step(){return this._step}set step(t){this._step=t,this.setPoints(W(this._radiusX,this._radiusY,this._step))}get radiusX(){return this._radiusX}set radiusX(t){this._radiusX=t,this.setPoints(W(this._radiusX,this._radiusY,this._step))}get radiusY(){return this._radiusY}set radiusY(t){this._radiusY=t,this.setPoints(W(this._radiusX,this._radiusY,this._step))}center(){}updateIsConvex(){}}class Mt extends bt{constructor(t,e,n,r){super(t,J(e,n),r),this.type=s.Box,this.typeGroup=i.Box,this.isConvex=!0,this._width=e,this._height=n}get width(){return this._width}set width(t){this._width=t,this.afterUpdateSize()}get height(){return this._height}set height(t){this._height=t,this.afterUpdateSize()}afterUpdateSize(){this.isCentered&&this.retranslate(!1),this.setPoints(J(this._width,this._height)),this.isCentered&&this.retranslate()}updateIsConvex(){}}class wt extends Mt{constructor(t,e){super(Q(t),.001,.001,e),this.type=s.Point,this.typeGroup=i.Point}}class _t extends bt{constructor(t,e,n){if(super(t,[{x:0,y:0},{x:e.x-t.x,y:e.y-t.y}],n),this.type=s.Line,this.typeGroup=i.Line,this.isConvex=!0,1===this.calcPoints.length||!e)throw console.error({start:t,end:e}),new Error("No end point for line provided")}get start(){return{x:this.x+this.calcPoints[0].x,y:this.y+this.calcPoints[0].y}}set start({x:t,y:e}){this.x=t,this.y=e}get end(){return{x:this.x+this.calcPoints[1].x,y:this.y+this.calcPoints[1].y}}set end({x:t,y:e}){this.points[1].x=t-this.start.x,this.points[1].y=e-this.start.y,this.setPoints(this.points)}getCentroid(){return new o.Vector((this.end.x-this.start.x)/2,(this.end.y-this.start.y)/2)}updateIsConvex(){}}class Xt extends a.A{createPoint(t,e,n){const r=new(n||wt)(t,e);return this.insert(r),r}createLine(t,e,n,r){const s=new(r||_t)(t,e,n);return this.insert(s),s}createCircle(t,e,n,r){const s=new(r||Bt)(t,e,n);return this.insert(s),s}createBox(t,e,n,r,s){const i=new(s||Mt)(t,e,n,r);return this.insert(i),i}createEllipse(t,e,n=e,r,s,i){const o=new(i||Ct)(t,e,n,r,s);return this.insert(o),o}createPolygon(t,e,n,r){const s=new(r||bt)(t,e,n);return this.insert(s),s}insert(t){if(t.bbox=t.getAABBAsBBox(),t.system){if(!nt(t))return this;t.system.remove(t)}return t.minX=t.bbox.minX-t.padding,t.minY=t.bbox.minY-t.padding,t.maxX=t.bbox.maxX+t.padding,t.maxY=t.bbox.maxY+t.padding,super.insert(t)}updateBody(t){t.updateBody()}update(){A(this.all(),(t=>{this.updateBody(t)}))}draw(t){A(this.all(),(e=>{e.draw(t)}))}drawBVH(t,e=!0){const n=r=>{ft(t,r,e),r.children&&A(r.children,n)};A(this.data.children,n)}remove(t,e){return t.system=void 0,super.remove(t,e)}getPotentials(t){return(e=>{const n=[];for(let r=0,s=e.length;r<s;r++){const s=e[r];s!==t&&n.push(s)}return n})(this.search(t))}traverse(t,{children:e}=this.data){return null==e?void 0:e.find(((n,r)=>!!n&&(!(!n.typeGroup||!t(n,e,r))||void(n.children&&this.traverse(t,n)))))}}class Yt extends Xt{constructor(){super(...arguments),this.response=new o.Response}insert(t){const e=super.insert(t);return t.system=this,e}separate(t=gt,e=this.response){A(this.all(),(n=>{this.separateBody(n,t,e)}))}separateBody(t,e=gt,n=this.response){if(t.isStatic&&!t.isTrigger)return;const r={x:0,y:0};this.checkOne(t,(n=>{!e(n)||t.isTrigger||n.b.isTrigger||(r.x+=n.overlapV.x,r.y+=n.overlapV.y)}),n),(r.x||r.y)&&t.setPosition(t.x-r.x,t.y-r.y)}checkOne(t,e=gt,n=this.response){if(t.isStatic&&!t.isTrigger)return!1;const r=this.search(t);return B(r,(r=>{if(r!==t&&this.checkCollision(t,r,n))return e(n)}))}checkArea(t,e=gt,n=this.response){return B(this.search(t),(t=>this.checkOne(t,e,n)))}checkAll(t=gt,e=this.response){return B(this.all(),(n=>this.checkOne(n,t,e)))}checkCollision(t,e,n=this.response){const{bbox:r,padding:s}=t,{bbox:i,padding:a}=e;if(!r||!i||!it(t,e)||(s||a)&&rt(r,i))return!1;const h=ut(t,e);if(t.isConvex&&e.isConvex)return n.clear(),h(t,e,n);const c=M(t),l=M(e);let u=0,p=0,y=!1;if(A(c,(t=>{A(l,(e=>{n.clear(),h(t,e,n)&&(y=!0,u+=n.overlapV.x,p+=n.overlapV.y)}))})),y){const r=new o.Vector(u,p);n.a=t,n.b=e,n.overlapV.x=u,n.overlapV.y=p,n.overlapN=r.normalize(),n.overlap=r.len(),n.aInB=ot(t,e),n.bInA=ot(e,t)}return y}raycast(t,e,n=gt){let r,s=1/0;return this.ray?(this.ray.start=t,this.ray.end=e):this.ray=new _t(t,e,{isTrigger:!0}),this.insert(this.ray),this.checkOne(this.ray,(({b:e})=>{if(!n(e,this.ray))return!1;const o=e.typeGroup===i.Circle?V(this.ray,e):G(this.ray,e);A(o,(n=>{const i=Z(t,n);i<s&&(s=i,r={point:n,body:e})}))})),this.remove(this.ray),r}getCollisionPoints(t,e){const n=[];if(t.typeGroup===i.Circle&&e.typeGroup===i.Circle&&n.push(...D(t,e)),t.typeGroup===i.Circle&&e.typeGroup!==i.Circle)for(let r=0;r<e.calcPoints.length;r++){const s=e.getEdge(r);n.push(...V(s,t))}if(t.typeGroup!==i.Circle)for(let r=0;r<t.calcPoints.length;r++){const s=t.getEdge(r);if(e.typeGroup===i.Circle)n.push(...V(s,e));else for(let t=0;t<e.calcPoints.length;t++){const r=O(s,e.getEdge(t));r&&n.push(r)}}return n.filter((({x:t,y:e},r)=>r===n.findIndex((n=>n.x===t&&n.y===e))))}}var It=r.g9,kt=r.Dh,St=r.az,Vt=r.jl,Nt=r.up,Et=r.Pp,Ot=r.N1,Gt=r.bR,Dt=r.tS,Tt=r.a5,Lt=r.XC,Rt=r.YK,jt=r.$S,zt=r.hf,Ut=r.gH,$t=r.iQ,qt=r.cp,Ht=r.iC,Kt=r.bc,Wt=r.P9,Jt=r.Gr,Qt=r.Qp,Ft=r.UY,Zt=r.x8,te=r.kK,ee=r.RE,ne=r.ge,re=r.zd,se=r.AQ,ie=r.kU,oe=r.Io,ae=r.Pz,he=r.F$,ce=r.iw,le=r.GB,ue=r.At,pe=r.S7,ye=r.vH,fe=r.SA,xe=r.Wx,ge=r.Jy,de=r.S8,ve=r.G0,me=r.Op,Pe=r.eI,Ae=r.M_,Be=r.S4,be=r.ed,Ce=r.pn,Me=r.AV,we=r.Kg,_e=r.Cy,Xe=r.N0,Ye=r.s3,Ie=r.yC,ke=r.cU,Se=r.x4,Ve=r.KJ,Ne=r.FN;export{It as BodyGroup,kt as BodyType,St as Box,Vt as Circle,Nt as DEG2RAD,Et as Ellipse,Ot as Line,Gt as Point,Dt as Polygon,Tt as RAD2DEG,Lt as RBush,Rt as Response,jt as SATCircle,zt as SATPolygon,Ut as SATVector,$t as System,qt as bin2dec,Ht as bodyMoved,Kt as canInteract,Wt as checkAInB,Jt as circleInCircle,Qt as circleInPolygon,Ft as circleOutsidePolygon,Zt as clockwise,te as clonePointsArray,ee as cloneResponse,ne as createBox,re as createEllipse,se as dashLineTo,ie as deg2rad,oe as distance,ae as drawBVH,he as drawPolygon,ce as ensureConvex,le as ensureNumber,ue as ensurePolygonPoints,pe as ensureVectorPoint,ye as extendBody,fe as getBounceDirection,xe as getGroup,ge as getSATTest,de as groupBits,ve as intersectAABB,me as intersectCircleCircle,Pe as intersectLineCircle,Ae as intersectLineLine,Be as intersectLineLineFast,be as intersectLinePolygon,Ce as isSimple,Me as mapArrayToVector,we as mapVectorToArray,_e as move,Xe as notIntersectAABB,Ye as pointInPolygon,Ie as pointOnCircle,ke as polygonInCircle,Se as polygonInPolygon,Ve as rad2deg,Ne as returnTrue};