-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
planck.min.js
39 lines (37 loc) · 208 KB
/
planck.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Planck.js v1.0.6
* @license The MIT license
* @copyright Copyright (c) 2023 Erin Catto, Ali Shakiba
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).planck={})}(this,(function(t){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(t,i){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])})(t,i)};function i(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function o(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)}var o=function(){return(o=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var s in e=arguments[i])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t}).apply(this,arguments)},s=function(t,e){null==t&&(t={});var i=o({},t);for(var s in e)e.hasOwnProperty(s)&&void 0===t[s]&&(i[s]=e[s]);if("function"==typeof Object.getOwnPropertySymbols)for(var n=Object.getOwnPropertySymbols(e),r=0;r<n.length;r++){var a=n[r];e.propertyIsEnumerable(a)&&void 0===t[a]&&(i[a]=e[a])}return i},n=Math.random,r=1e-9,a=Number.isFinite;function m(t,e,i){return void 0===e?(i=1,e=0):void 0===i&&(i=e,e=0),i>e?(t=(t-e)%(i-e))+(t<0?i:e):(t=(t-i)%(e-i))+(t<=0?e:i)}function h(t,e,i){return t<e?e:t>i?i:t}var c=Object.create(Math);c.EPSILON=r,c.isFinite=a,c.nextPowerOfTwo=function(t){return t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,(t|=t>>16)+1},c.isPowerOfTwo=function(t){return t>0&&0==(t&t-1)},c.mod=m,c.clamp=h,c.random=function(t,e){return void 0===t?(e=1,t=0):void 0===e&&(e=t,t=0),t===e?t:n()*(e-t)+t};var _=Math.abs,l=Math.sqrt,u=Math.max,p=Math.min,y=function(){function t(e,i){if(!(this instanceof t))return new t(e,i);void 0===e?(this.x=0,this.y=0):"object"==typeof e?(this.x=e.x,this.y=e.y):(this.x=e,this.y=i)}return t.prototype._serialize=function(){return{x:this.x,y:this.y}},t._deserialize=function(e){var i=Object.create(t.prototype);return i.x=e.x,i.y=e.y,i},t.zero=function(){var e=Object.create(t.prototype);return e.x=0,e.y=0,e},t.neo=function(e,i){var o=Object.create(t.prototype);return o.x=e,o.y=i,o},t.clone=function(e){return t.neo(e.x,e.y)},t.prototype.toString=function(){return JSON.stringify(this)},t.isValid=function(t){return null!=t&&(Number.isFinite(t.x)&&Number.isFinite(t.y))},t.assert=function(t){},t.prototype.clone=function(){return t.clone(this)},t.prototype.setZero=function(){return this.x=0,this.y=0,this},t.prototype.set=function(t,e){return"object"==typeof t?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e),this},t.prototype.setNum=function(t,e){return this.x=t,this.y=e,this},t.prototype.setVec2=function(t){return this.x=t.x,this.y=t.y,this},t.prototype.wSet=function(t,e,i,o){return void 0!==i||void 0!==o?this.setCombine(t,e,i,o):this.setMul(t,e)},t.prototype.setCombine=function(t,e,i,o){var s=t*e.x+i*o.x,n=t*e.y+i*o.y;return this.x=s,this.y=n,this},t.prototype.setMul=function(t,e){var i=t*e.x,o=t*e.y;return this.x=i,this.y=o,this},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},t.prototype.wAdd=function(t,e,i,o){return void 0!==i||void 0!==o?this.addCombine(t,e,i,o):this.addMul(t,e)},t.prototype.addCombine=function(t,e,i,o){var s=t*e.x+i*o.x,n=t*e.y+i*o.y;return this.x+=s,this.y+=n,this},t.prototype.addMul=function(t,e){var i=t*e.x,o=t*e.y;return this.x+=i,this.y+=o,this},t.prototype.wSub=function(t,e,i,o){return void 0!==i||void 0!==o?this.subCombine(t,e,i,o):this.subMul(t,e)},t.prototype.subCombine=function(t,e,i,o){var s=t*e.x+i*o.x,n=t*e.y+i*o.y;return this.x-=s,this.y-=n,this},t.prototype.subMul=function(t,e){var i=t*e.x,o=t*e.y;return this.x-=i,this.y-=o,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this},t.prototype.length=function(){return t.lengthOf(this)},t.prototype.lengthSquared=function(){return t.lengthSquared(this)},t.prototype.normalize=function(){var t=this.length();if(t<r)return 0;var e=1/t;return this.x*=e,this.y*=e,t},t.lengthOf=function(t){return l(t.x*t.x+t.y*t.y)},t.lengthSquared=function(t){return t.x*t.x+t.y*t.y},t.distance=function(t,e){var i=t.x-e.x,o=t.y-e.y;return l(i*i+o*o)},t.distanceSquared=function(t,e){var i=t.x-e.x,o=t.y-e.y;return i*i+o*o},t.areEqual=function(t,e){return t===e||"object"==typeof e&&null!==e&&t.x===e.x&&t.y===e.y},t.skew=function(e){return t.neo(-e.y,e.x)},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.cross=function(e,i){return"number"==typeof i?t.neo(i*e.y,-i*e.x):"number"==typeof e?t.neo(-e*i.y,e*i.x):e.x*i.y-e.y*i.x},t.crossVec2Vec2=function(t,e){return t.x*e.y-t.y*e.x},t.crossVec2Num=function(e,i){return t.neo(i*e.y,-i*e.x)},t.crossNumVec2=function(e,i){return t.neo(-e*i.y,e*i.x)},t.addCross=function(e,i,o){return"number"==typeof o?t.neo(o*i.y+e.x,-o*i.x+e.y):"number"==typeof i?t.neo(-i*o.y+e.x,i*o.x+e.y):void 0},t.addCrossVec2Num=function(e,i,o){return t.neo(o*i.y+e.x,-o*i.x+e.y)},t.addCrossNumVec2=function(e,i,o){return t.neo(-i*o.y+e.x,i*o.x+e.y)},t.add=function(e,i){return t.neo(e.x+i.x,e.y+i.y)},t.wAdd=function(e,i,o,s){return void 0!==o||void 0!==s?t.combine(e,i,o,s):t.mulNumVec2(e,i)},t.combine=function(e,i,o,s){return t.zero().setCombine(e,i,o,s)},t.sub=function(e,i){return t.neo(e.x-i.x,e.y-i.y)},t.mul=function(e,i){return"object"==typeof e?t.neo(e.x*i,e.y*i):"object"==typeof i?t.neo(e*i.x,e*i.y):void 0},t.mulVec2Num=function(e,i){return t.neo(e.x*i,e.y*i)},t.mulNumVec2=function(e,i){return t.neo(e*i.x,e*i.y)},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this},t.neg=function(e){return t.neo(-e.x,-e.y)},t.abs=function(e){return t.neo(_(e.x),_(e.y))},t.mid=function(e,i){return t.neo(.5*(e.x+i.x),.5*(e.y+i.y))},t.upper=function(e,i){return t.neo(u(e.x,i.x),u(e.y,i.y))},t.lower=function(e,i){return t.neo(p(e.x,i.x),p(e.y,i.y))},t.prototype.clamp=function(t){var e=this.x*this.x+this.y*this.y;if(e>t*t){var i=t/l(e);this.x*=i,this.y*=i}return this},t.clamp=function(e,i){var o=t.neo(e.x,e.y);return o.clamp(i),o},t.scaleFn=function(e,i){return function(o){return t.neo(o.x*e,o.y*i)}},t.translateFn=function(e,i){return function(o){return t.neo(o.x+e,o.y+i)}},t}(),d=Math.max,f=Math.min,v=function(){function t(e,i){if(!(this instanceof t))return new t(e,i);this.lowerBound=y.zero(),this.upperBound=y.zero(),"object"==typeof e&&this.lowerBound.setVec2(e),"object"==typeof i?this.upperBound.setVec2(i):"object"==typeof e&&this.upperBound.setVec2(e)}return t.prototype.isValid=function(){return t.isValid(this)},t.isValid=function(t){return null!=t&&(y.isValid(t.lowerBound)&&y.isValid(t.upperBound)&&y.sub(t.upperBound,t.lowerBound).lengthSquared()>=0)},t.assert=function(t){},t.prototype.getCenter=function(){return y.neo(.5*(this.lowerBound.x+this.upperBound.x),.5*(this.lowerBound.y+this.upperBound.y))},t.prototype.getExtents=function(){return y.neo(.5*(this.upperBound.x-this.lowerBound.x),.5*(this.upperBound.y-this.lowerBound.y))},t.prototype.getPerimeter=function(){return 2*(this.upperBound.x-this.lowerBound.x+this.upperBound.y-this.lowerBound.y)},t.prototype.combine=function(t,e){e=e||this;var i=t.lowerBound,o=t.upperBound,s=e.lowerBound,n=e.upperBound,r=f(i.x,s.x),a=f(i.y,s.y),m=d(n.x,o.x),h=d(n.y,o.y);this.lowerBound.setNum(r,a),this.upperBound.setNum(m,h)},t.prototype.combinePoints=function(t,e){this.lowerBound.setNum(f(t.x,e.x),f(t.y,e.y)),this.upperBound.setNum(d(t.x,e.x),d(t.y,e.y))},t.prototype.set=function(t){this.lowerBound.setNum(t.lowerBound.x,t.lowerBound.y),this.upperBound.setNum(t.upperBound.x,t.upperBound.y)},t.prototype.contains=function(t){var e=!0;return e=(e=(e=(e=e&&this.lowerBound.x<=t.lowerBound.x)&&this.lowerBound.y<=t.lowerBound.y)&&t.upperBound.x<=this.upperBound.x)&&t.upperBound.y<=this.upperBound.y},t.prototype.extend=function(e){return t.extend(this,e),this},t.extend=function(t,e){return t.lowerBound.x-=e,t.lowerBound.y-=e,t.upperBound.x+=e,t.upperBound.y+=e,t},t.testOverlap=function(t,e){var i=e.lowerBound.x-t.upperBound.x,o=t.lowerBound.x-e.upperBound.x,s=e.lowerBound.y-t.upperBound.y,n=t.lowerBound.y-e.upperBound.y;return!(i>0||s>0||o>0||n>0)},t.areEqual=function(t,e){return y.areEqual(t.lowerBound,e.lowerBound)&&y.areEqual(t.upperBound,e.upperBound)},t.diff=function(t,e){var i=d(0,f(t.upperBound.x,e.upperBound.x)-d(e.lowerBound.x,t.lowerBound.x)),o=d(0,f(t.upperBound.y,e.upperBound.y)-d(e.lowerBound.y,t.lowerBound.y));return(t.upperBound.x-t.lowerBound.x)*(t.upperBound.y-t.lowerBound.y)+(e.upperBound.x-e.lowerBound.x)*(e.upperBound.y-e.lowerBound.y)-i*o},t.prototype.rayCast=function(t,e){for(var i=-1/0,o=1/0,s=e.p1,n=y.sub(e.p2,e.p1),a=y.abs(n),m=y.zero(),h="x";null!==h;h="x"===h?"y":null)if(a.x<r){if(s[h]<this.lowerBound[h]||this.upperBound[h]<s[h])return!1}else{var c=1/n[h],_=(this.lowerBound[h]-s[h])*c,l=(this.upperBound[h]-s[h])*c,u=-1;if(_>l){var p=_;_=l,l=p,u=1}if(_>i&&(m.setZero(),m[h]=u,i=_),i>(o=f(o,l)))return!1}return!(i<0||e.maxFraction<i)&&(t.fraction=i,t.normal=m,!0)},t.prototype.toString=function(){return JSON.stringify(this)},t.combinePoints=function(t,e,i){return t.lowerBound.x=f(e.x,i.x),t.lowerBound.y=f(e.y,i.y),t.upperBound.x=d(e.x,i.x),t.upperBound.y=d(e.y,i.y),t},t.combinedPerimeter=function(t,e){var i=f(t.lowerBound.x,e.lowerBound.x),o=f(t.lowerBound.y,e.lowerBound.y);return 2*(d(t.upperBound.x,e.upperBound.x)-i+d(t.upperBound.y,e.upperBound.y)-o)},t}(),x=Math.PI,A=function(){function t(){}return Object.defineProperty(t,"polygonRadius",{get:function(){return 2*t.linearSlop},enumerable:!1,configurable:!0}),t.lengthUnitsPerMeter=1,t.maxManifoldPoints=2,t.maxPolygonVertices=12,t.aabbExtension=.1,t.aabbMultiplier=2,t.linearSlop=.005,t.angularSlop=2/180*x,t.maxSubSteps=8,t.maxTOIContacts=32,t.maxTOIIterations=20,t.maxDistanceIterations=20,t.velocityThreshold=1,t.maxLinearCorrection=.2,t.maxAngularCorrection=8/180*x,t.maxTranslation=2,t.maxRotation=.5*x,t.baumgarte=.2,t.toiBaugarte=.75,t.timeToSleep=.5,t.linearSleepTolerance=.01,t.angularSleepTolerance=2/180*x,t}(),g=function(){function t(){}return Object.defineProperty(t,"maxManifoldPoints",{get:function(){return A.maxManifoldPoints},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxPolygonVertices",{get:function(){return A.maxPolygonVertices},enumerable:!1,configurable:!0}),Object.defineProperty(t,"aabbExtension",{get:function(){return A.aabbExtension*A.lengthUnitsPerMeter},enumerable:!1,configurable:!0}),Object.defineProperty(t,"aabbMultiplier",{get:function(){return A.aabbMultiplier},enumerable:!1,configurable:!0}),Object.defineProperty(t,"linearSlop",{get:function(){return A.linearSlop*A.lengthUnitsPerMeter},enumerable:!1,configurable:!0}),Object.defineProperty(t,"linearSlopSquared",{get:function(){return A.linearSlop*A.lengthUnitsPerMeter*A.linearSlop*A.lengthUnitsPerMeter},enumerable:!1,configurable:!0}),Object.defineProperty(t,"angularSlop",{get:function(){return A.angularSlop},enumerable:!1,configurable:!0}),Object.defineProperty(t,"polygonRadius",{get:function(){return 2*A.linearSlop},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxSubSteps",{get:function(){return A.maxSubSteps},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxTOIContacts",{get:function(){return A.maxTOIContacts},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxTOIIterations",{get:function(){return A.maxTOIIterations},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxDistanceIterations",{get:function(){return A.maxDistanceIterations},enumerable:!1,configurable:!0}),Object.defineProperty(t,"velocityThreshold",{get:function(){return A.velocityThreshold*A.lengthUnitsPerMeter},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxLinearCorrection",{get:function(){return A.maxLinearCorrection*A.lengthUnitsPerMeter},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxAngularCorrection",{get:function(){return A.maxAngularCorrection},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxTranslation",{get:function(){return A.maxTranslation*A.lengthUnitsPerMeter},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxTranslationSquared",{get:function(){return A.maxTranslation*A.lengthUnitsPerMeter*A.maxTranslation*A.lengthUnitsPerMeter},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxRotation",{get:function(){return A.maxRotation},enumerable:!1,configurable:!0}),Object.defineProperty(t,"maxRotationSquared",{get:function(){return A.maxRotation*A.maxRotation},enumerable:!1,configurable:!0}),Object.defineProperty(t,"baumgarte",{get:function(){return A.baumgarte},enumerable:!1,configurable:!0}),Object.defineProperty(t,"toiBaugarte",{get:function(){return A.toiBaugarte},enumerable:!1,configurable:!0}),Object.defineProperty(t,"timeToSleep",{get:function(){return A.timeToSleep},enumerable:!1,configurable:!0}),Object.defineProperty(t,"linearSleepTolerance",{get:function(){return A.linearSleepTolerance*A.lengthUnitsPerMeter},enumerable:!1,configurable:!0}),Object.defineProperty(t,"linearSleepToleranceSqr",{get:function(){return A.linearSleepTolerance*A.lengthUnitsPerMeter*A.linearSleepTolerance*A.lengthUnitsPerMeter},enumerable:!1,configurable:!0}),Object.defineProperty(t,"angularSleepTolerance",{get:function(){return A.angularSleepTolerance},enumerable:!1,configurable:!0}),Object.defineProperty(t,"angularSleepToleranceSqr",{get:function(){return A.angularSleepTolerance*A.angularSleepTolerance},enumerable:!1,configurable:!0}),t}(),b=function(){function t(t){this._list=[],this._max=1/0,this._hasCreateFn=!1,this._createCount=0,this._hasAllocateFn=!1,this._allocateCount=0,this._hasReleaseFn=!1,this._releaseCount=0,this._hasDisposeFn=!1,this._disposeCount=0,this._list=[],this._max=t.max||this._max,this._createFn=t.create,this._hasCreateFn="function"==typeof this._createFn,this._allocateFn=t.allocate,this._hasAllocateFn="function"==typeof this._allocateFn,this._releaseFn=t.release,this._hasReleaseFn="function"==typeof this._releaseFn,this._disposeFn=t.dispose,this._hasDisposeFn="function"==typeof this._disposeFn}return t.prototype.max=function(t){return"number"==typeof t?(this._max=t,this):this._max},t.prototype.size=function(){return this._list.length},t.prototype.allocate=function(){var t;return this._list.length>0?t=this._list.shift():(this._createCount++,t=this._hasCreateFn?this._createFn():{}),this._allocateCount++,this._hasAllocateFn&&this._allocateFn(t),t},t.prototype.release=function(t){this._list.length<this._max?(this._releaseCount++,this._hasReleaseFn&&this._releaseFn(t),this._list.push(t)):(this._disposeCount++,this._hasDisposeFn&&(t=this._disposeFn(t)))},t.prototype.toString=function(){return" +"+this._createCount+" >"+this._allocateCount+" <"+this._releaseCount+" -"+this._disposeCount+" ="+this._list.length+"/"+this._max},t}(),B=Math.abs,w=Math.max,V=function(){function t(t){this.aabb=new v,this.userData=null,this.parent=null,this.child1=null,this.child2=null,this.height=-1,this.id=t}return t.prototype.toString=function(){return this.id+": "+this.userData},t.prototype.isLeaf=function(){return null==this.child1},t}(),C=new b({create:function(){return new V},release:function(t){t.userData=null,t.parent=null,t.child1=null,t.child2=null,t.height=-1,t.id=void 0}}),M=function(){function t(){this.inputPool=new b({create:function(){return{}},release:function(t){}}),this.stackPool=new b({create:function(){return[]},release:function(t){t.length=0}}),this.iteratorPool=new b({create:function(){return new I},release:function(t){t.close()}}),this.m_root=null,this.m_nodes={},this.m_lastProxyId=0}return t.prototype.getUserData=function(t){return this.m_nodes[t].userData},t.prototype.getFatAABB=function(t){return this.m_nodes[t].aabb},t.prototype.allocateNode=function(){var t=C.allocate();return t.id=++this.m_lastProxyId,this.m_nodes[t.id]=t,t},t.prototype.freeNode=function(t){delete this.m_nodes[t.id],C.release(t)},t.prototype.createProxy=function(t,e){var i=this.allocateNode();return i.aabb.set(t),v.extend(i.aabb,g.aabbExtension),i.userData=e,i.height=0,this.insertLeaf(i),i.id},t.prototype.destroyProxy=function(t){var e=this.m_nodes[t];this.removeLeaf(e),this.freeNode(e)},t.prototype.moveProxy=function(t,e,i){var o=this.m_nodes[t];return!o.aabb.contains(e)&&(this.removeLeaf(o),o.aabb.set(e),e=o.aabb,v.extend(e,g.aabbExtension),i.x<0?e.lowerBound.x+=i.x*g.aabbMultiplier:e.upperBound.x+=i.x*g.aabbMultiplier,i.y<0?e.lowerBound.y+=i.y*g.aabbMultiplier:e.upperBound.y+=i.y*g.aabbMultiplier,this.insertLeaf(o),!0)},t.prototype.insertLeaf=function(t){if(null==this.m_root)return this.m_root=t,void(this.m_root.parent=null);for(var e=t.aabb,i=this.m_root;!i.isLeaf();){var o=i.child1,s=i.child2,n=i.aabb.getPerimeter(),r=v.combinedPerimeter(i.aabb,e),a=2*r,m=2*(r-n),h=v.combinedPerimeter(e,o.aabb)+m;if(!o.isLeaf())h-=o.aabb.getPerimeter();var c=v.combinedPerimeter(e,s.aabb)+m;if(!s.isLeaf())c-=s.aabb.getPerimeter();if(a<h&&a<c)break;i=h<c?o:s}var _=i,l=_.parent,u=this.allocateNode();for(u.parent=l,u.userData=null,u.aabb.combine(e,_.aabb),u.height=_.height+1,null!=l?(l.child1===_?l.child1=u:l.child2=u,u.child1=_,u.child2=t,_.parent=u,t.parent=u):(u.child1=_,u.child2=t,_.parent=u,t.parent=u,this.m_root=u),i=t.parent;null!=i;){o=(i=this.balance(i)).child1,s=i.child2;i.height=1+w(o.height,s.height),i.aabb.combine(o.aabb,s.aabb),i=i.parent}},t.prototype.removeLeaf=function(t){if(t!==this.m_root){var e,i=t.parent,o=i.parent;if(e=i.child1===t?i.child2:i.child1,null!=o){o.child1===i?o.child1=e:o.child2=e,e.parent=o,this.freeNode(i);for(var s=o;null!=s;){var n=(s=this.balance(s)).child1,r=s.child2;s.aabb.combine(n.aabb,r.aabb),s.height=1+w(n.height,r.height),s=s.parent}}else this.m_root=e,e.parent=null,this.freeNode(i)}else this.m_root=null},t.prototype.balance=function(t){var e=t;if(e.isLeaf()||e.height<2)return t;var i=e.child1,o=e.child2,s=o.height-i.height;if(s>1){var n=o.child1,r=o.child2;return o.child1=e,o.parent=e.parent,e.parent=o,null!=o.parent?o.parent.child1===t?o.parent.child1=o:o.parent.child2=o:this.m_root=o,n.height>r.height?(o.child2=n,e.child2=r,r.parent=e,e.aabb.combine(i.aabb,r.aabb),o.aabb.combine(e.aabb,n.aabb),e.height=1+w(i.height,r.height),o.height=1+w(e.height,n.height)):(o.child2=r,e.child2=n,n.parent=e,e.aabb.combine(i.aabb,n.aabb),o.aabb.combine(e.aabb,r.aabb),e.height=1+w(i.height,n.height),o.height=1+w(e.height,r.height)),o}if(s<-1){var a=i.child1,m=i.child2;return i.child1=e,i.parent=e.parent,e.parent=i,null!=i.parent?i.parent.child1===e?i.parent.child1=i:i.parent.child2=i:this.m_root=i,a.height>m.height?(i.child2=a,e.child1=m,m.parent=e,e.aabb.combine(o.aabb,m.aabb),i.aabb.combine(e.aabb,a.aabb),e.height=1+w(o.height,m.height),i.height=1+w(e.height,a.height)):(i.child2=m,e.child1=a,a.parent=e,e.aabb.combine(o.aabb,a.aabb),i.aabb.combine(e.aabb,m.aabb),e.height=1+w(o.height,a.height),i.height=1+w(e.height,m.height)),i}return e},t.prototype.getHeight=function(){return null==this.m_root?0:this.m_root.height},t.prototype.getAreaRatio=function(){if(null==this.m_root)return 0;for(var t,e=this.m_root.aabb.getPerimeter(),i=0,o=this.iteratorPool.allocate().preorder(this.m_root);t=o.next();)t.height<0||(i+=t.aabb.getPerimeter());return this.iteratorPool.release(o),i/e},t.prototype.computeHeight=function(t){var e;if((e=void 0!==t?this.m_nodes[t]:this.m_root).isLeaf())return 0;var i=this.computeHeight(e.child1.id),o=this.computeHeight(e.child2.id);return 1+w(i,o)},t.prototype.validateStructure=function(t){if(null!=t){this.m_root;var e=t.child1,i=t.child2;t.isLeaf()||(this.validateStructure(e),this.validateStructure(i))}},t.prototype.validateMetrics=function(t){if(null!=t){var e=t.child1,i=t.child2;if(!t.isLeaf())e.height,i.height,(new v).combine(e.aabb,i.aabb),this.validateMetrics(e),this.validateMetrics(i)}},t.prototype.validate=function(){},t.prototype.getMaxBalance=function(){for(var t,e=0,i=this.iteratorPool.allocate().preorder(this.m_root);t=i.next();)if(!(t.height<=1)){var o=B(t.child2.height-t.child1.height);e=w(e,o)}return this.iteratorPool.release(i),e},t.prototype.rebuildBottomUp=function(){for(var t,e=[],i=0,o=this.iteratorPool.allocate().preorder(this.m_root);t=o.next();)t.height<0||(t.isLeaf()?(t.parent=null,e[i]=t,++i):this.freeNode(t));for(this.iteratorPool.release(o);i>1;){for(var s=1/0,n=-1,r=-1,a=0;a<i;++a)for(var m=e[a].aabb,h=a+1;h<i;++h){var c=e[h].aabb,_=v.combinedPerimeter(m,c);_<s&&(n=a,r=h,s=_)}var l=e[n],u=e[r],p=this.allocateNode();p.child1=l,p.child2=u,p.height=1+w(l.height,u.height),p.aabb.combine(l.aabb,u.aabb),p.parent=null,l.parent=p,u.parent=p,e[r]=e[i-1],e[n]=p,--i}this.m_root=e[0]},t.prototype.shiftOrigin=function(t){for(var e,i=this.iteratorPool.allocate().preorder(this.m_root);e=i.next();){var o=e.aabb;o.lowerBound.x-=t.x,o.lowerBound.y-=t.y,o.upperBound.x-=t.x,o.upperBound.y-=t.y}this.iteratorPool.release(i)},t.prototype.query=function(t,e){var i=this.stackPool.allocate();for(i.push(this.m_root);i.length>0;){var o=i.pop();if(null!=o)if(v.testOverlap(o.aabb,t))if(o.isLeaf()){if(!1===e(o.id))return}else i.push(o.child1),i.push(o.child2)}this.stackPool.release(i)},t.prototype.rayCast=function(t,e){var i=t.p1,o=t.p2,s=y.sub(o,i);s.normalize();var n=y.crossNumVec2(1,s),r=y.abs(n),a=t.maxFraction,m=new v,h=y.combine(1-a,i,a,o);m.combinePoints(i,h);var c=this.stackPool.allocate(),_=this.inputPool.allocate();for(c.push(this.m_root);c.length>0;){var l=c.pop();if(null!=l&&!1!==v.testOverlap(l.aabb,m)){var u=l.aabb.getCenter(),p=l.aabb.getExtents();if(!(B(y.dot(n,y.sub(i,u)))-y.dot(r,p)>0))if(l.isLeaf()){_.p1=y.clone(t.p1),_.p2=y.clone(t.p2),_.maxFraction=a;var d=e(_,l.id);if(0===d)break;d>0&&(a=d,h=y.combine(1-a,i,a,o),m.combinePoints(i,h))}else c.push(l.child1),c.push(l.child2)}}this.stackPool.release(c),this.inputPool.release(_)},t}(),I=function(){function t(){this.parents=[],this.states=[]}return t.prototype.preorder=function(t){return this.parents.length=0,this.parents.push(t),this.states.length=0,this.states.push(0),this},t.prototype.next=function(){for(;this.parents.length>0;){var t=this.parents.length-1,e=this.parents[t];if(0===this.states[t])return this.states[t]=1,e;if(1===this.states[t]&&(this.states[t]=2,e.child1))return this.parents.push(e.child1),this.states.push(1),e.child1;if(2===this.states[t]&&(this.states[t]=3,e.child2))return this.parents.push(e.child2),this.states.push(1),e.child2;this.parents.pop(),this.states.pop()}},t.prototype.close=function(){this.parents.length=0},t}(),P=Math.max,S=Math.min,T=function(){function t(){var t=this;this.m_tree=new M,this.m_moveBuffer=[],this.query=function(e,i){t.m_tree.query(e,i)},this.queryCallback=function(e){if(e===t.m_queryProxyId)return!0;var i=S(e,t.m_queryProxyId),o=P(e,t.m_queryProxyId),s=t.m_tree.getUserData(i),n=t.m_tree.getUserData(o);return t.m_callback(s,n),!0}}return t.prototype.getUserData=function(t){return this.m_tree.getUserData(t)},t.prototype.testOverlap=function(t,e){var i=this.m_tree.getFatAABB(t),o=this.m_tree.getFatAABB(e);return v.testOverlap(i,o)},t.prototype.getFatAABB=function(t){return this.m_tree.getFatAABB(t)},t.prototype.getProxyCount=function(){return this.m_moveBuffer.length},t.prototype.getTreeHeight=function(){return this.m_tree.getHeight()},t.prototype.getTreeBalance=function(){return this.m_tree.getMaxBalance()},t.prototype.getTreeQuality=function(){return this.m_tree.getAreaRatio()},t.prototype.rayCast=function(t,e){this.m_tree.rayCast(t,e)},t.prototype.shiftOrigin=function(t){this.m_tree.shiftOrigin(t)},t.prototype.createProxy=function(t,e){var i=this.m_tree.createProxy(t,e);return this.bufferMove(i),i},t.prototype.destroyProxy=function(t){this.unbufferMove(t),this.m_tree.destroyProxy(t)},t.prototype.moveProxy=function(t,e,i){this.m_tree.moveProxy(t,e,i)&&this.bufferMove(t)},t.prototype.touchProxy=function(t){this.bufferMove(t)},t.prototype.bufferMove=function(t){this.m_moveBuffer.push(t)},t.prototype.unbufferMove=function(t){for(var e=0;e<this.m_moveBuffer.length;++e)this.m_moveBuffer[e]===t&&(this.m_moveBuffer[e]=null)},t.prototype.updatePairs=function(t){for(this.m_callback=t;this.m_moveBuffer.length>0;)if(this.m_queryProxyId=this.m_moveBuffer.pop(),null!==this.m_queryProxyId){var e=this.m_tree.getFatAABB(this.m_queryProxyId);this.m_tree.query(e,this.queryCallback)}},t}(),z=Math.sin,F=Math.cos,L=Math.sqrt;function q(t,e){return{x:t,y:e}}function N(t,e,i){return t.x=e,t.y=i,t}function k(t,e){return t.x=e.x,t.y=e.y,t}function D(t){return t.x=0,t.y=0,t}function j(t){return t.x=-t.x,t.y=-t.y,t}function O(t,e){return t.x+=e.x,t.y+=e.y,t}function R(t,e){return t.x-=e.x,t.y-=e.y,t}function E(t,e,i){return t.x=e.x-i.x,t.y=e.y-i.y,t}function J(t,e){return t.x*=e,t.y*=e,t}function Y(t,e,i){return t.x=e*i.x,t.y=e*i.y,t}function W(t,e,i){return t.x+=e*i.x,t.y+=e*i.y,t}function H(t,e,i){return t.x-=e*i.x,t.y-=e*i.y,t}function U(t,e,i,o,s){return t.x=e*i.x+o*s.x,t.y=e*i.y+o*s.y,t}function Z(t,e,i,o,s,n,r){return t.x=e*i.x+o*s.x+n*r.x,t.y=e*i.y+o*s.y+n*r.y,t}function K(t){var e=L(t.x*t.x+t.y*t.y);if(e>0){var i=1/e;t.x*=i,t.y*=i}return t}function X(t,e,i){var o=i*e.y,s=-i*e.x;return t.x=o,t.y=s,t}function G(t,e,i){var o=-e*i.y,s=e*i.x;return t.x=o,t.y=s,t}function Q(t,e){return t.x*e.y-t.y*e.x}function $(t,e){return t.x*e.x+t.y*e.y}function tt(t){return t.x*t.x+t.y*t.y}function et(t,e){var i=t.x-e.x,o=t.y-e.y;return L(i*i+o*o)}function it(t,e){var i=t.x-e.x,o=t.y-e.y;return i*i+o*o}function ot(t,e,i){return t.x=e.c*i.x-e.s*i.y,t.y=e.s*i.x+e.c*i.y,t}function st(t,e,i){var o=e.c*i.x+e.s*i.y,s=-e.s*i.x+e.c*i.y;return t.x=o,t.y=s,t}function nt(t,e,i){return{p:q(t,e),q:(o=i,{s:z(o),c:F(o)})};var o}function rt(t,e){return t.p.x=e.p.x,t.p.y=e.p.y,t.q.s=e.q.s,t.q.c=e.q.c,t}function at(t,e,i){var o=e.q.c*i.x-e.q.s*i.y+e.p.x,s=e.q.s*i.x+e.q.c*i.y+e.p.y;return t.x=o,t.y=s,t}function mt(t,e,i){var o=i.x-e.p.x,s=i.y-e.p.y,n=e.q.c*o+e.q.s*s,r=-e.q.s*o+e.q.c*s;return t.x=n,t.y=r,t}function ht(t,e,i,o){var s=e.q.c*o.x-e.q.s*o.y+e.p.x,n=e.q.s*o.x+e.q.c*o.y+e.p.y,r=s-i.p.x,a=n-i.p.y,m=i.q.c*r+i.q.s*a,h=-i.q.s*r+i.q.c*a;return t.x=m,t.y=h,t}function ct(t,e,i){var o=e.q.c*i.q.c+e.q.s*i.q.s,s=e.q.c*i.q.s-e.q.s*i.q.c,n=e.q.c*(i.p.x-e.p.x)+e.q.s*(i.p.y-e.p.y),r=-e.q.s*(i.p.x-e.p.x)+e.q.c*(i.p.y-e.p.y);return t.q.c=o,t.q.s=s,t.p.x=n,t.p.y=r,t}var _t=Math.sin,lt=Math.cos,ut=Math.atan2,pt=function(){function t(e){if(!(this instanceof t))return new t(e);"number"==typeof e?this.setAngle(e):"object"==typeof e?this.setRot(e):this.setIdentity()}return t.neo=function(e){var i=Object.create(t.prototype);return i.setAngle(e),i},t.clone=function(e){var i=Object.create(t.prototype);return i.s=e.s,i.c=e.c,i},t.identity=function(){var e=Object.create(t.prototype);return e.s=0,e.c=1,e},t.isValid=function(t){return null!=t&&(Number.isFinite(t.s)&&Number.isFinite(t.c))},t.assert=function(t){},t.prototype.setIdentity=function(){this.s=0,this.c=1},t.prototype.set=function(t){"object"==typeof t?(this.s=t.s,this.c=t.c):(this.s=_t(t),this.c=lt(t))},t.prototype.setRot=function(t){this.s=t.s,this.c=t.c},t.prototype.setAngle=function(t){this.s=_t(t),this.c=lt(t)},t.prototype.getAngle=function(){return ut(this.s,this.c)},t.prototype.getXAxis=function(){return y.neo(this.c,this.s)},t.prototype.getYAxis=function(){return y.neo(-this.s,this.c)},t.mul=function(e,i){if("c"in i&&"s"in i){var o=t.identity();return o.s=e.s*i.c+e.c*i.s,o.c=e.c*i.c-e.s*i.s,o}if("x"in i&&"y"in i)return y.neo(e.c*i.x-e.s*i.y,e.s*i.x+e.c*i.y)},t.mulRot=function(e,i){var o=t.identity();return o.s=e.s*i.c+e.c*i.s,o.c=e.c*i.c-e.s*i.s,o},t.mulVec2=function(t,e){return y.neo(t.c*e.x-t.s*e.y,t.s*e.x+t.c*e.y)},t.mulSub=function(t,e,i){var o=t.c*(e.x-i.x)-t.s*(e.y-i.y),s=t.s*(e.x-i.x)+t.c*(e.y-i.y);return y.neo(o,s)},t.mulT=function(e,i){if("c"in i&&"s"in i){var o=t.identity();return o.s=e.c*i.s-e.s*i.c,o.c=e.c*i.c+e.s*i.s,o}if("x"in i&&"y"in i)return y.neo(e.c*i.x+e.s*i.y,-e.s*i.x+e.c*i.y)},t.mulTRot=function(e,i){var o=t.identity();return o.s=e.c*i.s-e.s*i.c,o.c=e.c*i.c+e.s*i.s,o},t.mulTVec2=function(t,e){return y.neo(t.c*e.x+t.s*e.y,-t.s*e.x+t.c*e.y)},t}(),yt=Math.atan2,dt=Math.PI,ft=q(0,0),vt=function(){function t(){this.localCenter=y.zero(),this.c=y.zero(),this.a=0,this.alpha0=0,this.c0=y.zero(),this.a0=0}return t.prototype.recycle=function(){D(this.localCenter),D(this.c),this.a=0,this.alpha0=0,D(this.c0),this.a0=0},t.prototype.setTransform=function(t){at(ft,t,this.localCenter),k(this.c,ft),k(this.c0,ft),this.a=this.a0=yt(t.q.s,t.q.c)},t.prototype.setLocalCenter=function(t,e){k(this.localCenter,t),at(ft,e,this.localCenter),k(this.c,ft),k(this.c0,ft)},t.prototype.getTransform=function(t,e){void 0===e&&(e=0),function(t,e){t.c=F(e),t.s=z(e)}(t.q,(1-e)*this.a0+e*this.a),U(t.p,1-e,this.c0,e,this.c),R(t.p,ot(ft,t.q,this.localCenter))},t.prototype.advance=function(t){var e=(t-this.alpha0)/(1-this.alpha0);U(this.c0,e,this.c,1-e,this.c0),this.a0=e*this.a+(1-e)*this.a0,this.alpha0=t},t.prototype.forward=function(){this.a0=this.a,k(this.c0,this.c)},t.prototype.normalize=function(){var t=m(this.a0,-dt,+dt);this.a-=this.a0-t,this.a0=t},t.prototype.set=function(t){k(this.localCenter,t.localCenter),k(this.c,t.c),this.a=t.a,this.alpha0=t.alpha0,k(this.c0,t.c0),this.a0=t.a0},t}(),xt=function(){function t(e,i){if(!(this instanceof t))return new t(e,i);this.p=y.zero(),this.q=pt.identity(),void 0!==e&&this.p.setVec2(e),void 0!==i&&this.q.setAngle(i)}return t.clone=function(e){var i=Object.create(t.prototype);return i.p=y.clone(e.p),i.q=pt.clone(e.q),i},t.neo=function(e,i){var o=Object.create(t.prototype);return o.p=y.clone(e),o.q=pt.clone(i),o},t.identity=function(){var e=Object.create(t.prototype);return e.p=y.zero(),e.q=pt.identity(),e},t.prototype.setIdentity=function(){this.p.setZero(),this.q.setIdentity()},t.prototype.set=function(t,e){void 0===e?(this.p.set(t.p),this.q.set(t.q)):(this.p.set(t),this.q.set(e))},t.prototype.setNum=function(t,e){this.p.setVec2(t),this.q.setAngle(e)},t.prototype.setTransform=function(t){this.p.setVec2(t.p),this.q.setRot(t.q)},t.isValid=function(t){return null!=t&&(y.isValid(t.p)&&pt.isValid(t.q))},t.assert=function(t){},t.mul=function(e,i){if(Array.isArray(i)){for(var o=[],s=0;s<i.length;s++)o[s]=t.mul(e,i[s]);return o}return"x"in i&&"y"in i?t.mulVec2(e,i):"p"in i&&"q"in i?t.mulXf(e,i):void 0},t.mulAll=function(e,i){for(var o=[],s=0;s<i.length;s++)o[s]=t.mul(e,i[s]);return o},t.mulFn=function(e){return function(i){return t.mul(e,i)}},t.mulVec2=function(t,e){var i=t.q.c*e.x-t.q.s*e.y+t.p.x,o=t.q.s*e.x+t.q.c*e.y+t.p.y;return y.neo(i,o)},t.mulXf=function(e,i){var o=t.identity();return o.q=pt.mulRot(e.q,i.q),o.p=y.add(pt.mulVec2(e.q,i.p),e.p),o},t.mulT=function(e,i){return"x"in i&&"y"in i?t.mulTVec2(e,i):"p"in i&&"q"in i?t.mulTXf(e,i):void 0},t.mulTVec2=function(t,e){var i=e.x-t.p.x,o=e.y-t.p.y,s=t.q.c*i+t.q.s*o,n=-t.q.s*i+t.q.c*o;return y.neo(s,n)},t.mulTXf=function(e,i){var o=t.identity();return o.q.setRot(pt.mulTRot(e.q,i.q)),o.p.setVec2(pt.mulTVec2(e.q,y.sub(i.p,e.p))),o},t}(),At=function(){this.v=y.zero(),this.w=0},gt=Math.sin,bt=Math.cos,Bt=function(){function t(){this.c=y.zero(),this.a=0}return t.prototype.getTransform=function(t,e){return t.q.c=bt(this.a),t.q.s=gt(this.a),t.p.x=this.c.x-(t.q.c*e.x-t.q.s*e.y),t.p.y=this.c.y-(t.q.s*e.x+t.q.c*e.y),t},t}();function wt(t,e,i,o){return t.q.c=bt(o),t.q.s=gt(o),t.p.x=i.x-(t.q.c*e.x-t.q.s*e.y),t.p.y=i.y-(t.q.s*e.x+t.q.c*e.y),t}var Vt=function(){function t(){this.style={},this.appData={}}return t.isValid=function(t){return null!=t&&("string"==typeof t.m_type&&"number"==typeof t.m_radius)},t}(),Ct=new v,Mt=new v,It=q(0,0),Pt={userData:null,friction:.2,restitution:0,density:0,isSensor:!1,filterGroupIndex:0,filterCategoryBits:1,filterMaskBits:65535},St=function(t,e){this.aabb=new v,this.fixture=t,this.childIndex=e,this.proxyId},Tt=function(){function t(t,e,i){this.style={},this.appData={},e.shape?(i=e,e=e.shape):"number"==typeof i&&(i={density:i}),i=s(i,Pt),this.m_body=t,this.m_friction=i.friction,this.m_restitution=i.restitution,this.m_density=i.density,this.m_isSensor=i.isSensor,this.m_filterGroupIndex=i.filterGroupIndex,this.m_filterCategoryBits=i.filterCategoryBits,this.m_filterMaskBits=i.filterMaskBits,this.m_shape=e,this.m_next=null,this.m_proxies=[],this.m_proxyCount=0;for(var o=this.m_shape.getChildCount(),n=0;n<o;++n)this.m_proxies[n]=new St(this,n);this.m_userData=i.userData}return t.prototype._reset=function(){var t=this.getBody(),e=t.m_world.m_broadPhase;this.destroyProxies(e),this.m_shape._reset&&this.m_shape._reset();for(var i=this.m_shape.getChildCount(),o=0;o<i;++o)this.m_proxies[o]=new St(this,o);this.createProxies(e,t.m_xf),t.resetMassData()},t.prototype._serialize=function(){return{friction:this.m_friction,restitution:this.m_restitution,density:this.m_density,isSensor:this.m_isSensor,filterGroupIndex:this.m_filterGroupIndex,filterCategoryBits:this.m_filterCategoryBits,filterMaskBits:this.m_filterMaskBits,shape:this.m_shape}},t._deserialize=function(e,i,o){var s=o(Vt,e.shape);return s&&new t(i,s,e)},t.prototype.getType=function(){return this.m_shape.m_type},t.prototype.getShape=function(){return this.m_shape},t.prototype.isSensor=function(){return this.m_isSensor},t.prototype.setSensor=function(t){t!=this.m_isSensor&&(this.m_body.setAwake(!0),this.m_isSensor=t)},t.prototype.getUserData=function(){return this.m_userData},t.prototype.setUserData=function(t){this.m_userData=t},t.prototype.getBody=function(){return this.m_body},t.prototype.getNext=function(){return this.m_next},t.prototype.getDensity=function(){return this.m_density},t.prototype.setDensity=function(t){this.m_density=t},t.prototype.getFriction=function(){return this.m_friction},t.prototype.setFriction=function(t){this.m_friction=t},t.prototype.getRestitution=function(){return this.m_restitution},t.prototype.setRestitution=function(t){this.m_restitution=t},t.prototype.testPoint=function(t){return this.m_shape.testPoint(this.m_body.getTransform(),t)},t.prototype.rayCast=function(t,e,i){return this.m_shape.rayCast(t,e,this.m_body.getTransform(),i)},t.prototype.getMassData=function(t){this.m_shape.computeMass(t,this.m_density)},t.prototype.getAABB=function(t){return this.m_proxies[t].aabb},t.prototype.createProxies=function(t,e){this.m_proxyCount=this.m_shape.getChildCount();for(var i=0;i<this.m_proxyCount;++i){var o=this.m_proxies[i];this.m_shape.computeAABB(o.aabb,e,i),o.proxyId=t.createProxy(o.aabb,o)}},t.prototype.destroyProxies=function(t){for(var e=0;e<this.m_proxyCount;++e){var i=this.m_proxies[e];t.destroyProxy(i.proxyId),i.proxyId=null}this.m_proxyCount=0},t.prototype.synchronize=function(t,e,i){for(var o=0;o<this.m_proxyCount;++o){var s=this.m_proxies[o];this.m_shape.computeAABB(Ct,e,s.childIndex),this.m_shape.computeAABB(Mt,i,s.childIndex),s.aabb.combine(Ct,Mt),E(It,i.p,e.p),t.moveProxy(s.proxyId,s.aabb,It)}},t.prototype.setFilterData=function(t){this.m_filterGroupIndex=t.groupIndex,this.m_filterCategoryBits=t.categoryBits,this.m_filterMaskBits=t.maskBits,this.refilter()},t.prototype.getFilterGroupIndex=function(){return this.m_filterGroupIndex},t.prototype.setFilterGroupIndex=function(t){this.m_filterGroupIndex=t,this.refilter()},t.prototype.getFilterCategoryBits=function(){return this.m_filterCategoryBits},t.prototype.setFilterCategoryBits=function(t){this.m_filterCategoryBits=t,this.refilter()},t.prototype.getFilterMaskBits=function(){return this.m_filterMaskBits},t.prototype.setFilterMaskBits=function(t){this.m_filterMaskBits=t,this.refilter()},t.prototype.refilter=function(){if(null!=this.m_body){for(var t=this.m_body.getContactList();t;){var e=t.contact,i=e.getFixtureA(),o=e.getFixtureB();i!=this&&o!=this||e.flagForFiltering(),t=t.next}var s=this.m_body.getWorld();if(null!=s)for(var n=s.m_broadPhase,r=0;r<this.m_proxyCount;++r)n.touchProxy(this.m_proxies[r].proxyId)}},t.prototype.shouldCollide=function(t){if(t.m_filterGroupIndex===this.m_filterGroupIndex&&0!==t.m_filterGroupIndex)return t.m_filterGroupIndex>0;var e=0!=(t.m_filterMaskBits&this.m_filterCategoryBits),i=0!=(t.m_filterCategoryBits&this.m_filterMaskBits);return e&&i},t}(),zt="static",Ft="kinematic",Lt="dynamic",qt=q(0,0),Nt=q(0,0),kt=q(0,0),Dt=q(0,0),jt=nt(0,0,0),Ot={type:zt,position:y.zero(),angle:0,linearVelocity:y.zero(),angularVelocity:0,linearDamping:0,angularDamping:0,fixedRotation:!1,bullet:!1,gravityScale:1,allowSleep:!0,awake:!0,active:!0,userData:null},Rt=function(){function t(t,e){this.style={},this.appData={},e=s(e,Ot),this.m_world=t,this.m_awakeFlag=e.awake,this.m_autoSleepFlag=e.allowSleep,this.m_bulletFlag=e.bullet,this.m_fixedRotationFlag=e.fixedRotation,this.m_activeFlag=e.active,this.m_islandFlag=!1,this.m_toiFlag=!1,this.m_userData=e.userData,this.m_type=e.type,this.m_type==Lt?(this.m_mass=1,this.m_invMass=1):(this.m_mass=0,this.m_invMass=0),this.m_I=0,this.m_invI=0,this.m_xf=xt.identity(),this.m_xf.p.setVec2(e.position),this.m_xf.q.setAngle(e.angle),this.m_sweep=new vt,this.m_sweep.setTransform(this.m_xf),this.c_velocity=new At,this.c_position=new Bt,this.m_force=y.zero(),this.m_torque=0,this.m_linearVelocity=y.clone(e.linearVelocity),this.m_angularVelocity=e.angularVelocity,this.m_linearDamping=e.linearDamping,this.m_angularDamping=e.angularDamping,this.m_gravityScale=e.gravityScale,this.m_sleepTime=0,this.m_jointList=null,this.m_contactList=null,this.m_fixtureList=null,this.m_prev=null,this.m_next=null,this.m_destroyed=!1}return t.prototype._serialize=function(){for(var t=[],e=this.m_fixtureList;e;e=e.m_next)t.push(e);return{type:this.m_type,bullet:this.m_bulletFlag,position:this.m_xf.p,angle:this.m_xf.q.getAngle(),linearVelocity:this.m_linearVelocity,angularVelocity:this.m_angularVelocity,fixtures:t}},t._deserialize=function(e,i,o){var s=new t(i,e);if(e.fixtures)for(var n=e.fixtures.length-1;n>=0;n--){var r=o(Tt,e.fixtures[n],s);s._addFixture(r)}return s},t.prototype.isWorldLocked=function(){return!(!this.m_world||!this.m_world.isLocked())},t.prototype.getWorld=function(){return this.m_world},t.prototype.getNext=function(){return this.m_next},t.prototype.setUserData=function(t){this.m_userData=t},t.prototype.getUserData=function(){return this.m_userData},t.prototype.getFixtureList=function(){return this.m_fixtureList},t.prototype.getJointList=function(){return this.m_jointList},t.prototype.getContactList=function(){return this.m_contactList},t.prototype.isStatic=function(){return this.m_type==zt},t.prototype.isDynamic=function(){return this.m_type==Lt},t.prototype.isKinematic=function(){return this.m_type==Ft},t.prototype.setStatic=function(){return this.setType(zt),this},t.prototype.setDynamic=function(){return this.setType(Lt),this},t.prototype.setKinematic=function(){return this.setType(Ft),this},t.prototype.getType=function(){return this.m_type},t.prototype.setType=function(t){if(1!=this.isWorldLocked()&&this.m_type!=t){this.m_type=t,this.resetMassData(),this.m_type==zt&&(this.m_linearVelocity.setZero(),this.m_angularVelocity=0,this.m_sweep.forward(),this.synchronizeFixtures()),this.setAwake(!0),this.m_force.setZero(),this.m_torque=0;for(var e=this.m_contactList;e;){var i=e;e=e.next,this.m_world.destroyContact(i.contact)}this.m_contactList=null;for(var o=this.m_world.m_broadPhase,s=this.m_fixtureList;s;s=s.m_next)for(var n=0;n<s.m_proxyCount;++n)o.touchProxy(s.m_proxies[n].proxyId)}},t.prototype.isBullet=function(){return this.m_bulletFlag},t.prototype.setBullet=function(t){this.m_bulletFlag=!!t},t.prototype.isSleepingAllowed=function(){return this.m_autoSleepFlag},t.prototype.setSleepingAllowed=function(t){this.m_autoSleepFlag=!!t,0==this.m_autoSleepFlag&&this.setAwake(!0)},t.prototype.isAwake=function(){return this.m_awakeFlag},t.prototype.setAwake=function(t){t?(this.m_awakeFlag=!0,this.m_sleepTime=0):(this.m_awakeFlag=!1,this.m_sleepTime=0,this.m_linearVelocity.setZero(),this.m_angularVelocity=0,this.m_force.setZero(),this.m_torque=0)},t.prototype.isActive=function(){return this.m_activeFlag},t.prototype.setActive=function(t){if(t!=this.m_activeFlag)if(this.m_activeFlag=!!t,this.m_activeFlag){for(var e=this.m_world.m_broadPhase,i=this.m_fixtureList;i;i=i.m_next)i.createProxies(e,this.m_xf);this.m_world.m_newFixture=!0}else{for(e=this.m_world.m_broadPhase,i=this.m_fixtureList;i;i=i.m_next)i.destroyProxies(e);for(var o=this.m_contactList;o;){var s=o;o=o.next,this.m_world.destroyContact(s.contact)}this.m_contactList=null}},t.prototype.isFixedRotation=function(){return this.m_fixedRotationFlag},t.prototype.setFixedRotation=function(t){this.m_fixedRotationFlag!=t&&(this.m_fixedRotationFlag=!!t,this.m_angularVelocity=0,this.resetMassData())},t.prototype.getTransform=function(){return this.m_xf},t.prototype.setTransform=function(t,e){if(1!=this.isWorldLocked()){this.m_xf.setNum(t,e),this.m_sweep.setTransform(this.m_xf);for(var i=this.m_world.m_broadPhase,o=this.m_fixtureList;o;o=o.m_next)o.synchronize(i,this.m_xf,this.m_xf);this.setAwake(!0)}},t.prototype.synchronizeTransform=function(){this.m_sweep.getTransform(this.m_xf,1)},t.prototype.synchronizeFixtures=function(){this.m_sweep.getTransform(jt,0);for(var t=this.m_world.m_broadPhase,e=this.m_fixtureList;e;e=e.m_next)e.synchronize(t,jt,this.m_xf)},t.prototype.advance=function(t){this.m_sweep.advance(t),k(this.m_sweep.c,this.m_sweep.c0),this.m_sweep.a=this.m_sweep.a0,this.m_sweep.getTransform(this.m_xf,1)},t.prototype.getPosition=function(){return this.m_xf.p},t.prototype.setPosition=function(t){this.setTransform(t,this.m_sweep.a)},t.prototype.getAngle=function(){return this.m_sweep.a},t.prototype.setAngle=function(t){this.setTransform(this.m_xf.p,t)},t.prototype.getWorldCenter=function(){return this.m_sweep.c},t.prototype.getLocalCenter=function(){return this.m_sweep.localCenter},t.prototype.getLinearVelocity=function(){return this.m_linearVelocity},t.prototype.getLinearVelocityFromWorldPoint=function(t){var e=y.sub(t,this.m_sweep.c);return y.add(this.m_linearVelocity,y.crossNumVec2(this.m_angularVelocity,e))},t.prototype.getLinearVelocityFromLocalPoint=function(t){return this.getLinearVelocityFromWorldPoint(this.getWorldPoint(t))},t.prototype.setLinearVelocity=function(t){this.m_type!=zt&&(y.dot(t,t)>0&&this.setAwake(!0),this.m_linearVelocity.setVec2(t))},t.prototype.getAngularVelocity=function(){return this.m_angularVelocity},t.prototype.setAngularVelocity=function(t){this.m_type!=zt&&(t*t>0&&this.setAwake(!0),this.m_angularVelocity=t)},t.prototype.getLinearDamping=function(){return this.m_linearDamping},t.prototype.setLinearDamping=function(t){this.m_linearDamping=t},t.prototype.getAngularDamping=function(){return this.m_angularDamping},t.prototype.setAngularDamping=function(t){this.m_angularDamping=t},t.prototype.getGravityScale=function(){return this.m_gravityScale},t.prototype.setGravityScale=function(t){this.m_gravityScale=t},t.prototype.getMass=function(){return this.m_mass},t.prototype.getInertia=function(){return this.m_I+this.m_mass*y.dot(this.m_sweep.localCenter,this.m_sweep.localCenter)},t.prototype.getMassData=function(t){t.mass=this.m_mass,t.I=this.getInertia(),k(t.center,this.m_sweep.localCenter)},t.prototype.resetMassData=function(){if(this.m_mass=0,this.m_invMass=0,this.m_I=0,this.m_invI=0,D(this.m_sweep.localCenter),this.isStatic()||this.isKinematic())return k(this.m_sweep.c0,this.m_xf.p),k(this.m_sweep.c,this.m_xf.p),void(this.m_sweep.a0=this.m_sweep.a);D(Nt);for(var t=this.m_fixtureList;t;t=t.m_next)if(0!=t.m_density){var e={mass:0,center:q(0,0),I:0};t.getMassData(e),this.m_mass+=e.mass,W(Nt,e.mass,e.center),this.m_I+=e.I}this.m_mass>0?(this.m_invMass=1/this.m_mass,Y(Nt,this.m_invMass,Nt)):(this.m_mass=1,this.m_invMass=1),this.m_I>0&&0==this.m_fixedRotationFlag?(this.m_I-=this.m_mass*$(Nt,Nt),this.m_invI=1/this.m_I):(this.m_I=0,this.m_invI=0),k(qt,this.m_sweep.c),this.m_sweep.setLocalCenter(Nt,this.m_xf),E(kt,this.m_sweep.c,qt),G(Dt,this.m_angularVelocity,kt),O(this.m_linearVelocity,Dt)},t.prototype.setMassData=function(t){1!=this.isWorldLocked()&&this.m_type==Lt&&(this.m_invMass=0,this.m_I=0,this.m_invI=0,this.m_mass=t.mass,this.m_mass<=0&&(this.m_mass=1),this.m_invMass=1/this.m_mass,t.I>0&&0==this.m_fixedRotationFlag&&(this.m_I=t.I-this.m_mass*$(t.center,t.center),this.m_invI=1/this.m_I),k(qt,this.m_sweep.c),this.m_sweep.setLocalCenter(t.center,this.m_xf),E(kt,this.m_sweep.c,qt),G(Dt,this.m_angularVelocity,kt),O(this.m_linearVelocity,Dt))},t.prototype.applyForce=function(t,e,i){void 0===i&&(i=!0),this.m_type==Lt&&(i&&0==this.m_awakeFlag&&this.setAwake(!0),this.m_awakeFlag&&(this.m_force.add(t),this.m_torque+=y.crossVec2Vec2(y.sub(e,this.m_sweep.c),t)))},t.prototype.applyForceToCenter=function(t,e){void 0===e&&(e=!0),this.m_type==Lt&&(e&&0==this.m_awakeFlag&&this.setAwake(!0),this.m_awakeFlag&&this.m_force.add(t))},t.prototype.applyTorque=function(t,e){void 0===e&&(e=!0),this.m_type==Lt&&(e&&0==this.m_awakeFlag&&this.setAwake(!0),this.m_awakeFlag&&(this.m_torque+=t))},t.prototype.applyLinearImpulse=function(t,e,i){void 0===i&&(i=!0),this.m_type==Lt&&(i&&0==this.m_awakeFlag&&this.setAwake(!0),this.m_awakeFlag&&(this.m_linearVelocity.addMul(this.m_invMass,t),this.m_angularVelocity+=this.m_invI*y.crossVec2Vec2(y.sub(e,this.m_sweep.c),t)))},t.prototype.applyAngularImpulse=function(t,e){void 0===e&&(e=!0),this.m_type==Lt&&(e&&0==this.m_awakeFlag&&this.setAwake(!0),this.m_awakeFlag&&(this.m_angularVelocity+=this.m_invI*t))},t.prototype.shouldCollide=function(t){if(this.m_type!=Lt&&t.m_type!=Lt)return!1;for(var e=this.m_jointList;e;e=e.next)if(e.other==t&&0==e.joint.m_collideConnected)return!1;return!0},t.prototype._addFixture=function(t){if(1==this.isWorldLocked())return null;if(this.m_activeFlag){var e=this.m_world.m_broadPhase;t.createProxies(e,this.m_xf)}return t.m_next=this.m_fixtureList,this.m_fixtureList=t,t.m_density>0&&this.resetMassData(),this.m_world.m_newFixture=!0,t},t.prototype.createFixture=function(t,e){if(1==this.isWorldLocked())return null;var i=new Tt(this,t,e);return this._addFixture(i),i},t.prototype.destroyFixture=function(t){if(1!=this.isWorldLocked()){if(this.m_fixtureList===t)this.m_fixtureList=t.m_next;else for(var e=this.m_fixtureList;null!=e;){if(e.m_next===t){e.m_next=t.m_next;break}e=e.m_next}for(var i=this.m_contactList;i;){var o=i.contact;i=i.next;var s=o.getFixtureA(),n=o.getFixtureB();t!=s&&t!=n||this.m_world.destroyContact(o)}if(this.m_activeFlag){var r=this.m_world.m_broadPhase;t.destroyProxies(r)}t.m_body=null,t.m_next=null,this.m_world.publish("remove-fixture",t),this.resetMassData()}},t.prototype.getWorldPoint=function(t){return xt.mulVec2(this.m_xf,t)},t.prototype.getWorldVector=function(t){return pt.mulVec2(this.m_xf.q,t)},t.prototype.getLocalPoint=function(t){return xt.mulTVec2(this.m_xf,t)},t.prototype.getLocalVector=function(t){return pt.mulTVec2(this.m_xf.q,t)},t.STATIC="static",t.KINEMATIC="kinematic",t.DYNAMIC="dynamic",t}(),Et=function(){this.other=null,this.joint=null,this.prev=null,this.next=null},Jt=function(){function t(t,e,i){this.m_type="unknown-joint",this.m_prev=null,this.m_next=null,this.m_edgeA=new Et,this.m_edgeB=new Et,this.m_islandFlag=!1,this.style={},this.appData={},e="bodyA"in t?t.bodyA:e,i="bodyB"in t?t.bodyB:i,this.m_bodyA=e,this.m_bodyB=i,this.m_collideConnected=!!t.collideConnected,this.m_userData=t.userData}return t.prototype.isActive=function(){return this.m_bodyA.isActive()&&this.m_bodyB.isActive()},t.prototype.getType=function(){return this.m_type},t.prototype.getBodyA=function(){return this.m_bodyA},t.prototype.getBodyB=function(){return this.m_bodyB},t.prototype.getNext=function(){return this.m_next},t.prototype.getUserData=function(){return this.m_userData},t.prototype.setUserData=function(t){this.m_userData=t},t.prototype.getCollideConnected=function(){return this.m_collideConnected},t.prototype.shiftOrigin=function(t){},t.prototype._resetAnchors=function(t){return this._reset(t)},t}(),Yt={gjkCalls:0,gjkIters:0,gjkMaxIters:0,toiTime:0,toiMaxTime:0,toiCalls:0,toiIters:0,toiMaxIters:0,toiRootIters:0,toiMaxRootIters:0,toString:function(t){t="string"==typeof t?t:"\n";var e="";for(var i in this)"function"!=typeof this[i]&&"object"!=typeof this[i]&&(e+=i+": "+this[i]+t);return e}},Wt=function(){return Date.now()},Ht=function(t){return Date.now()-t},Ut=Math.max,Zt=q(0,0),Kt=q(0,0),Xt=q(0,0),Gt=q(0,0),Qt=q(0,0),$t=q(0,0),te=q(0,0);Yt.gjkCalls=0,Yt.gjkIters=0,Yt.gjkMaxIters=0;var ee=function(){function t(){this.proxyA=new ne,this.proxyB=new ne,this.transformA=xt.identity(),this.transformB=xt.identity(),this.useRadii=!1}return t.prototype.recycle=function(){this.proxyA.recycle(),this.proxyB.recycle(),this.transformA.setIdentity(),this.transformB.setIdentity(),this.useRadii=!1},t}(),ie=function(){function t(){this.pointA=q(0,0),this.pointB=q(0,0),this.distance=0,this.iterations=0}return t.prototype.recycle=function(){D(this.pointA),D(this.pointB),this.distance=0,this.iterations=0},t}(),oe=function(){function t(){this.metric=0,this.indexA=[],this.indexB=[],this.count=0}return t.prototype.recycle=function(){this.metric=0,this.indexA.length=0,this.indexB.length=0,this.count=0},t}(),se=function(t,e,i){++Yt.gjkCalls;var o=i.proxyA,s=i.proxyB,n=i.transformA,a=i.transformB;ce.recycle(),ce.readCache(e,o,n,s,a);for(var m=ce.m_v,h=g.maxDistanceIterations,c=[],_=[],l=0,u=0;u<h;){l=ce.m_count;for(var p=0;p<l;++p)c[p]=m[p].indexA,_[p]=m[p].indexB;if(ce.solve(),3===ce.m_count)break;var y=ce.getSearchDirection();if(tt(y)<1e-18)break;var d=m[ce.m_count];d.indexA=o.getSupport(st(Zt,n.q,Y(Zt,-1,y))),at(d.wA,n,o.getVertex(d.indexA)),d.indexB=s.getSupport(st(Zt,a.q,y)),at(d.wB,a,s.getVertex(d.indexB)),E(d.w,d.wB,d.wA),++u,++Yt.gjkIters;var f=!1;for(p=0;p<l;++p)if(d.indexA===c[p]&&d.indexB===_[p]){f=!0;break}if(f)break;++ce.m_count}if(Yt.gjkMaxIters=Ut(Yt.gjkMaxIters,u),ce.getWitnessPoints(t.pointA,t.pointB),t.distance=et(t.pointA,t.pointB),t.iterations=u,ce.writeCache(e),i.useRadii){var v=o.m_radius,x=s.m_radius;if(t.distance>v+x&&t.distance>r)t.distance-=v+x,E(Kt,t.pointB,t.pointA),K(Kt),W(t.pointA,v,Kt),H(t.pointB,x,Kt);else{var A=E(Zt,t.pointA,t.pointB);k(t.pointA,A),k(t.pointB,A),t.distance=0}}},ne=function(){function t(){this.m_vertices=[],this.m_count=0,this.m_radius=0}return t.prototype.recycle=function(){this.m_vertices.length=0,this.m_count=0,this.m_radius=0},t.prototype.getVertexCount=function(){return this.m_count},t.prototype.getVertex=function(t){return this.m_vertices[t]},t.prototype.getSupport=function(t){for(var e=-1,i=-1/0,o=0;o<this.m_count;++o){var s=$(this.m_vertices[o],t);s>i&&(e=o,i=s)}return e},t.prototype.getSupportVertex=function(t){return this.m_vertices[this.getSupport(t)]},t.prototype.set=function(t,e){t.computeDistanceProxy(this,e)},t.prototype.setVertices=function(t,e,i){this.m_vertices=t,this.m_count=e,this.m_radius=i},t}(),re=function(){function t(){this.wA=q(0,0),this.indexA=0,this.wB=q(0,0),this.indexB=0,this.w=q(0,0),this.a=0}return t.prototype.recycle=function(){this.indexA=0,this.indexB=0,D(this.wA),D(this.wB),D(this.w),this.a=0},t.prototype.set=function(t){this.indexA=t.indexA,this.indexB=t.indexB,k(this.wA,t.wA),k(this.wB,t.wB),k(this.w,t.w),this.a=t.a},t}(),ae=q(0,0),me=q(0,0),he=function(){function t(){this.m_v1=new re,this.m_v2=new re,this.m_v3=new re,this.m_v=[this.m_v1,this.m_v2,this.m_v3]}return t.prototype.recycle=function(){this.m_v1.recycle(),this.m_v2.recycle(),this.m_v3.recycle(),this.m_count=0},t.prototype.toString=function(){return 3===this.m_count?["+"+this.m_count,this.m_v1.a,this.m_v1.wA.x,this.m_v1.wA.y,this.m_v1.wB.x,this.m_v1.wB.y,this.m_v2.a,this.m_v2.wA.x,this.m_v2.wA.y,this.m_v2.wB.x,this.m_v2.wB.y,this.m_v3.a,this.m_v3.wA.x,this.m_v3.wA.y,this.m_v3.wB.x,this.m_v3.wB.y].toString():2===this.m_count?["+"+this.m_count,this.m_v1.a,this.m_v1.wA.x,this.m_v1.wA.y,this.m_v1.wB.x,this.m_v1.wB.y,this.m_v2.a,this.m_v2.wA.x,this.m_v2.wA.y,this.m_v2.wB.x,this.m_v2.wB.y].toString():1===this.m_count?["+"+this.m_count,this.m_v1.a,this.m_v1.wA.x,this.m_v1.wA.y,this.m_v1.wB.x,this.m_v1.wB.y].toString():"+"+this.m_count},t.prototype.readCache=function(t,e,i,o,s){this.m_count=t.count;for(var n=0;n<this.m_count;++n){(_=this.m_v[n]).indexA=t.indexA[n],_.indexB=t.indexB[n];var a=e.getVertex(_.indexA),m=o.getVertex(_.indexB);at(_.wA,i,a),at(_.wB,s,m),E(_.w,_.wB,_.wA),_.a=0}if(this.m_count>1){var h=t.metric,c=this.getMetric();(c<.5*h||2*h<c||c<r)&&(this.m_count=0)}if(0===this.m_count){var _;(_=this.m_v[0]).indexA=0,_.indexB=0;a=e.getVertex(0),m=o.getVertex(0);at(_.wA,i,a),at(_.wB,s,m),E(_.w,_.wB,_.wA),_.a=1,this.m_count=1}},t.prototype.writeCache=function(t){t.metric=this.getMetric(),t.count=this.m_count;for(var e=0;e<this.m_count;++e)t.indexA[e]=this.m_v[e].indexA,t.indexB[e]=this.m_v[e].indexB},t.prototype.getSearchDirection=function(){var t=this.m_v1,e=this.m_v2;switch(this.m_v3,this.m_count){case 1:return N(ae,-t.w.x,-t.w.y);case 2:return E(Xt,e.w,t.w),-Q(Xt,t.w)>0?N(ae,-Xt.y,Xt.x):N(ae,Xt.y,-Xt.x);default:return D(ae)}},t.prototype.getClosestPoint=function(){var t=this.m_v1,e=this.m_v2;switch(this.m_v3,this.m_count){case 0:return D(me);case 1:return k(me,t.w);case 2:return U(me,t.a,t.w,e.a,e.w);case 3:default:return D(me)}},t.prototype.getWitnessPoints=function(t,e){var i=this.m_v1,o=this.m_v2,s=this.m_v3;switch(this.m_count){case 0:break;case 1:k(t,i.wA),k(e,i.wB);break;case 2:U(t,i.a,i.wA,o.a,o.wA),U(e,i.a,i.wB,o.a,o.wB);break;case 3:Z(t,i.a,i.wA,o.a,o.wA,s.a,s.wA),k(e,t)}},t.prototype.getMetric=function(){switch(this.m_count){case 0:case 1:return 0;case 2:return et(this.m_v1.w,this.m_v2.w);case 3:return Q(E($t,this.m_v2.w,this.m_v1.w),E(te,this.m_v3.w,this.m_v1.w));default:return 0}},t.prototype.solve=function(){switch(this.m_count){case 1:break;case 2:this.solve2();break;case 3:this.solve3()}},t.prototype.solve2=function(){var t=this.m_v1.w,e=this.m_v2.w;E(Xt,e,t);var i=-$(t,Xt);if(i<=0)return this.m_v1.a=1,void(this.m_count=1);var o=$(e,Xt);if(o<=0)return this.m_v2.a=1,this.m_count=1,void this.m_v1.set(this.m_v2);var s=1/(o+i);this.m_v1.a=o*s,this.m_v2.a=i*s,this.m_count=2},t.prototype.solve3=function(){var t=this.m_v1.w,e=this.m_v2.w,i=this.m_v3.w;E(Xt,e,t);var o=$(t,Xt),s=$(e,Xt),n=-o;E(Gt,i,t);var r=$(t,Gt),a=$(i,Gt),m=-r;E(Qt,i,e);var h=$(e,Qt),c=$(i,Qt),_=-h,l=Q(Xt,Gt),u=l*Q(e,i),p=l*Q(i,t),y=l*Q(t,e);if(n<=0&&m<=0)return this.m_v1.a=1,void(this.m_count=1);if(s>0&&n>0&&y<=0){var d=1/(s+n);return this.m_v1.a=s*d,this.m_v2.a=n*d,void(this.m_count=2)}if(a>0&&m>0&&p<=0){var f=1/(a+m);return this.m_v1.a=a*f,this.m_v3.a=m*f,this.m_count=2,void this.m_v2.set(this.m_v3)}if(s<=0&&_<=0)return this.m_v2.a=1,this.m_count=1,void this.m_v1.set(this.m_v2);if(a<=0&&c<=0)return this.m_v3.a=1,this.m_count=1,void this.m_v1.set(this.m_v3);if(c>0&&_>0&&u<=0){var v=1/(c+_);return this.m_v2.a=c*v,this.m_v3.a=_*v,this.m_count=2,void this.m_v1.set(this.m_v3)}var x=1/(u+p+y);this.m_v1.a=u*x,this.m_v2.a=p*x,this.m_v3.a=y*x,this.m_count=3},t}(),ce=new he,_e=new ee,le=new oe,ue=new ie,pe=function(t,e,i,o,s,n){return _e.recycle(),_e.proxyA.set(t,e),_e.proxyB.set(i,o),rt(_e.transformA,s),rt(_e.transformB,n),_e.useRadii=!0,ue.recycle(),le.recycle(),se(ue,le,_e),ue.distance<1e-8};se.testOverlap=pe,se.Input=ee,se.Output=ie,se.Proxy=ne,se.Cache=oe;var ye,de=function(){function t(){this.proxyA=new ne,this.proxyB=new ne,this.transformA=xt.identity(),this.transformB=xt.identity(),this.translationB=y.zero()}return t.prototype.recycle=function(){this.proxyA.recycle(),this.proxyB.recycle(),this.transformA.setIdentity(),this.transformB.setIdentity(),D(this.translationB)},t}(),fe=function(){this.point=y.zero(),this.normal=y.zero(),this.lambda=1,this.iterations=0},ve=function(t,e){t.iterations=0,t.lambda=1,t.normal.setZero(),t.point.setZero();var i=e.proxyA,o=e.proxyB,s=Ut(i.m_radius,g.polygonRadius),n=s+Ut(o.m_radius,g.polygonRadius),r=e.transformA,a=e.transformB,m=e.translationB,h=y.zero(),c=0,_=new he;_.m_count=0;for(var l=_.m_v,u=i.getSupport(pt.mulTVec2(r.q,y.neg(m))),p=xt.mulVec2(r,i.getVertex(u)),d=o.getSupport(pt.mulTVec2(a.q,m)),f=xt.mulVec2(a,o.getVertex(d)),v=y.sub(p,f),x=Ut(g.polygonRadius,n-g.polygonRadius),A=.5*g.linearSlop,b=0;b<20&&v.length()-x>A;){t.iterations+=1,u=i.getSupport(pt.mulTVec2(r.q,y.neg(v))),p=xt.mulVec2(r,i.getVertex(u)),d=o.getSupport(pt.mulTVec2(a.q,v)),f=xt.mulVec2(a,o.getVertex(d));var B=y.sub(p,f);v.normalize();var w=y.dot(v,B),V=y.dot(v,m);if(w-x>c*V){if(V<=0)return!1;if((c=(w-x)/V)>1)return!1;h.setMul(-1,v),_.m_count=0}var C=l[_.m_count];switch(C.indexA=d,C.wA=y.combine(1,f,c,m),C.indexB=u,C.wB=p,C.w=y.sub(C.wB,C.wA),C.a=1,_.m_count+=1,_.m_count){case 1:break;case 2:_.solve2();break;case 3:_.solve3()}if(3==_.m_count)return!1;v.setVec2(_.getClosestPoint()),++b}if(0==b)return!1;var M=y.zero(),I=y.zero();return _.getWitnessPoints(I,M),v.lengthSquared()>0&&(h.setMul(-1,v),h.normalize()),t.point=y.combine(1,M,s,h),t.normal=h,t.lambda=c,t.iterations=b,!0},xe=Math.abs,Ae=Math.max,ge=function(){function t(){this.proxyA=new ne,this.proxyB=new ne,this.sweepA=new vt,this.sweepB=new vt}return t.prototype.recycle=function(){this.proxyA.recycle(),this.proxyB.recycle(),this.sweepA.recycle(),this.sweepB.recycle(),this.tMax=-1},t}();t.TOIOutputState=void 0,(ye=t.TOIOutputState||(t.TOIOutputState={}))[ye.e_unset=-1]="e_unset",ye[ye.e_unknown=0]="e_unknown",ye[ye.e_failed=1]="e_failed",ye[ye.e_overlapped=2]="e_overlapped",ye[ye.e_touching=3]="e_touching",ye[ye.e_separated=4]="e_separated";var be=function(){function e(){this.state=t.TOIOutputState.e_unset,this.t=-1}return e.prototype.recycle=function(){this.state=t.TOIOutputState.e_unset,this.t=-1},e}();Yt.toiTime=0,Yt.toiMaxTime=0,Yt.toiCalls=0,Yt.toiIters=0,Yt.toiMaxIters=0,Yt.toiRootIters=0,Yt.toiMaxRootIters=0;var Be,we=new ee,Ve=new ie,Ce=new oe,Me=nt(0,0,0),Ie=nt(0,0,0),Pe=q(0,0),Se=q(0,0),Te=q(0,0),ze=q(0,0),Fe=q(0,0),Le=q(0,0),qe=q(0,0),Ne=q(0,0),ke=function(e,i){var o=Wt();++Yt.toiCalls,e.state=t.TOIOutputState.e_unknown,e.t=i.tMax;var s=i.proxyA,n=i.proxyB,r=i.sweepA,a=i.sweepB;r.normalize(),a.normalize();var m=i.tMax,h=s.m_radius+n.m_radius,c=Ae(g.linearSlop,h-3*g.linearSlop),_=.25*g.linearSlop,l=0,u=g.maxTOIIterations,p=0;for(Ce.recycle(),we.proxyA.setVertices(s.m_vertices,s.m_count,s.m_radius),we.proxyB.setVertices(n.m_vertices,n.m_count,n.m_radius),we.useRadii=!1;;){if(r.getTransform(Me,l),a.getTransform(Ie,l),rt(we.transformA,Me),rt(we.transformB,Ie),se(Ve,Ce,we),Ve.distance<=0){e.state=t.TOIOutputState.e_overlapped,e.t=0;break}if(Ve.distance<c+_){e.state=t.TOIOutputState.e_touching,e.t=l;break}De.initialize(Ce,s,r,n,a,l);for(var y=!1,d=m,f=0;;){var v=De.findMinSeparation(d);if(v>c+_){e.state=t.TOIOutputState.e_separated,e.t=m,y=!0;break}if(v>c-_){l=d;break}var x=De.evaluate(l);if(x<c-_){e.state=t.TOIOutputState.e_failed,e.t=l,y=!0;break}if(x<=c+_){e.state=t.TOIOutputState.e_touching,e.t=l,y=!0;break}for(var A=0,b=l,B=d;;){var w=void 0;w=1&A?b+(c-x)*(B-b)/(v-x):.5*(b+B),++A,++Yt.toiRootIters;var V=De.evaluate(w);if(xe(V-c)<_){d=w;break}if(V>c?(b=w,x=V):(B=w,v=V),50===A)break}if(Yt.toiMaxRootIters=Ae(Yt.toiMaxRootIters,A),++f===g.maxPolygonVertices)break}if(++p,++Yt.toiIters,y)break;if(p===u){e.state=t.TOIOutputState.e_failed,e.t=l;break}}Yt.toiMaxIters=Ae(Yt.toiMaxIters,p);var C=Ht(o);Yt.toiMaxTime=Ae(Yt.toiMaxTime,C),Yt.toiTime+=C,De.recycle()};!function(t){t[t.e_unset=-1]="e_unset",t[t.e_points=1]="e_points",t[t.e_faceA=2]="e_faceA",t[t.e_faceB=3]="e_faceB"}(Be||(Be={}));var De=new(function(){function t(){this.m_proxyA=null,this.m_proxyB=null,this.m_sweepA=null,this.m_sweepB=null,this.m_type=Be.e_unset,this.m_localPoint=q(0,0),this.m_axis=q(0,0),this.indexA=-1,this.indexB=-1}return t.prototype.recycle=function(){this.m_proxyA=null,this.m_proxyB=null,this.m_sweepA=null,this.m_sweepB=null,this.m_type=Be.e_unset,D(this.m_localPoint),D(this.m_axis),this.indexA=-1,this.indexB=-1},t.prototype.initialize=function(t,e,i,o,s,n){var r=t.count;if(this.m_proxyA=e,this.m_proxyB=o,this.m_sweepA=i,this.m_sweepB=s,this.m_sweepA.getTransform(Me,n),this.m_sweepB.getTransform(Ie,n),1===r){this.m_type=Be.e_points;var a=this.m_proxyA.getVertex(t.indexA[0]),m=this.m_proxyB.getVertex(t.indexB[0]);return at(Se,Me,a),at(Te,Ie,m),E(this.m_axis,Te,Se),p=function(t){var e=L(t.x*t.x+t.y*t.y);if(0!==e){var i=1/e;t.x*=i,t.y*=i}return e}(this.m_axis)}if(t.indexA[0]===t.indexA[1]){this.m_type=Be.e_faceB;var h=o.getVertex(t.indexB[0]),c=o.getVertex(t.indexB[1]);X(this.m_axis,E(Pe,c,h),1),K(this.m_axis),ot(ze,Ie.q,this.m_axis),U(this.m_localPoint,.5,h,.5,c),at(Te,Ie,this.m_localPoint);var _=e.getVertex(t.indexA[0]);return(p=$(xt.mulVec2(Me,_),ze)-$(Te,ze))<0&&(j(this.m_axis),p=-p),p}this.m_type=Be.e_faceA;var l=this.m_proxyA.getVertex(t.indexA[0]),u=this.m_proxyA.getVertex(t.indexA[1]);X(this.m_axis,E(Pe,u,l),1),K(this.m_axis),ot(ze,Me.q,this.m_axis),U(this.m_localPoint,.5,l,.5,u),at(Se,Me,this.m_localPoint);var p,y=this.m_proxyB.getVertex(t.indexB[0]);return at(Te,Ie,y),(p=$(Te,ze)-$(Se,ze))<0&&(j(this.m_axis),p=-p),p},t.prototype.compute=function(t,e){switch(this.m_sweepA.getTransform(Me,e),this.m_sweepB.getTransform(Ie,e),this.m_type){case Be.e_points:return t&&(st(Fe,Me.q,this.m_axis),st(Le,Ie.q,Y(Pe,-1,this.m_axis)),this.indexA=this.m_proxyA.getSupport(Fe),this.indexB=this.m_proxyB.getSupport(Le)),k(qe,this.m_proxyA.getVertex(this.indexA)),k(Ne,this.m_proxyB.getVertex(this.indexB)),at(Se,Me,qe),at(Te,Ie,Ne),$(Te,this.m_axis)-$(Se,this.m_axis);case Be.e_faceA:return ot(ze,Me.q,this.m_axis),at(Se,Me,this.m_localPoint),t&&(st(Le,Ie.q,Y(Pe,-1,ze)),this.indexA=-1,this.indexB=this.m_proxyB.getSupport(Le)),k(Ne,this.m_proxyB.getVertex(this.indexB)),at(Te,Ie,Ne),$(Te,ze)-$(Se,ze);case Be.e_faceB:return ot(ze,Ie.q,this.m_axis),at(Te,Ie,this.m_localPoint),t&&(st(Fe,Me.q,Y(Pe,-1,ze)),this.indexB=-1,this.indexA=this.m_proxyA.getSupport(Fe)),k(qe,this.m_proxyA.getVertex(this.indexA)),at(Se,Me,qe),$(Se,ze)-$(Te,ze);default:return t&&(this.indexA=-1,this.indexB=-1),0}},t.prototype.findMinSeparation=function(t){return this.compute(!0,t)},t.prototype.evaluate=function(t){return this.compute(!1,t)},t}());ke.Input=ge,ke.Output=be;var je=Math.abs,Oe=Math.sqrt,Re=Math.min,Ee=function(){function t(){this.dt=0,this.inv_dt=0,this.velocityIterations=0,this.positionIterations=0,this.warmStarting=!1,this.blockSolve=!0,this.inv_dt0=0,this.dtRatio=1}return t.prototype.reset=function(t){this.dt>0&&(this.inv_dt0=this.inv_dt),this.dt=t,this.inv_dt=0==t?0:1/t,this.dtRatio=t*this.inv_dt0},t}(),Je=new Ee,Ye=q(0,0),We=q(0,0),He=q(0,0),Ue=new ge,Ze=new be,Ke=new vt,Xe=new vt,Ge=new vt,Qe=function(){function t(t){this.contact=t,this.normals=[],this.tangents=[]}return t.prototype.recycle=function(){this.normals.length=0,this.tangents.length=0},Object.defineProperty(t.prototype,"normalImpulses",{get:function(){var t=this.contact,e=this.normals;e.length=0;for(var i=0;i<t.v_points.length;++i)e.push(t.v_points[i].normalImpulse);return e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"tangentImpulses",{get:function(){var t=this.contact,e=this.tangents;e.length=0;for(var i=0;i<t.v_points.length;++i)e.push(t.v_points[i].tangentImpulse);return e},enumerable:!1,configurable:!0}),t}(),$e=function(){function e(t){this.m_world=t,this.m_stack=[],this.m_bodies=[],this.m_contacts=[],this.m_joints=[]}return e.prototype.clear=function(){this.m_stack.length=0,this.m_bodies.length=0,this.m_contacts.length=0,this.m_joints.length=0},e.prototype.addBody=function(t){this.m_bodies.push(t)},e.prototype.addContact=function(t){this.m_contacts.push(t)},e.prototype.addJoint=function(t){this.m_joints.push(t)},e.prototype.solveWorld=function(t){for(var e=this.m_world,i=e.m_bodyList;i;i=i.m_next)i.m_islandFlag=!1;for(var o=e.m_contactList;o;o=o.m_next)o.m_islandFlag=!1;for(var s=e.m_jointList;s;s=s.m_next)s.m_islandFlag=!1;for(var n=this.m_stack,r=e.m_bodyList;r;r=r.m_next)if(!r.m_islandFlag&&0!=r.isAwake()&&0!=r.isActive()&&!r.isStatic()){for(this.clear(),n.push(r),r.m_islandFlag=!0;n.length>0;){i=n.pop();if(this.addBody(i),i.m_awakeFlag=!0,!i.isStatic()){for(var a=i.m_contactList;a;a=a.next){var m=a.contact;if(!m.m_islandFlag&&(0!=m.isEnabled()&&0!=m.isTouching())){var h=m.m_fixtureA.m_isSensor,c=m.m_fixtureB.m_isSensor;if(!h&&!c)this.addContact(m),m.m_islandFlag=!0,(l=a.other).m_islandFlag||(n.push(l),l.m_islandFlag=!0)}}for(var _=i.m_jointList;_;_=_.next){var l;if(1!=_.joint.m_islandFlag)0!=(l=_.other).isActive()&&(this.addJoint(_.joint),_.joint.m_islandFlag=!0,l.m_islandFlag||(n.push(l),l.m_islandFlag=!0))}}}this.solveIsland(t);for(var u=0;u<this.m_bodies.length;++u){(i=this.m_bodies[u]).isStatic()&&(i.m_islandFlag=!1)}}},e.prototype.solveIsland=function(t){for(var e=this.m_world,i=e.m_gravity,o=e.m_allowSleep,s=t.dt,n=0;n<this.m_bodies.length;++n){var r=this.m_bodies[n];k(Ye,r.m_sweep.c);var a=r.m_sweep.a;k(We,r.m_linearVelocity);var m=r.m_angularVelocity;k(r.m_sweep.c0,r.m_sweep.c),r.m_sweep.a0=r.m_sweep.a,r.isDynamic()&&(W(We,s*r.m_gravityScale,i),W(We,s*r.m_invMass,r.m_force),m+=s*r.m_invI*r.m_torque,Y(We,1/(1+s*r.m_linearDamping),We),m*=1/(1+s*r.m_angularDamping)),k(r.c_position.c,Ye),r.c_position.a=a,k(r.c_velocity.v,We),r.c_velocity.w=m}for(n=0;n<this.m_contacts.length;++n){this.m_contacts[n].initConstraint(t)}for(n=0;n<this.m_contacts.length;++n){this.m_contacts[n].initVelocityConstraint(t)}if(t.warmStarting)for(n=0;n<this.m_contacts.length;++n){this.m_contacts[n].warmStartConstraint(t)}for(n=0;n<this.m_joints.length;++n){this.m_joints[n].initVelocityConstraints(t)}for(n=0;n<t.velocityIterations;++n){for(var h=0;h<this.m_joints.length;++h){this.m_joints[h].solveVelocityConstraints(t)}for(h=0;h<this.m_contacts.length;++h){this.m_contacts[h].solveVelocityConstraint(t)}}for(n=0;n<this.m_contacts.length;++n){this.m_contacts[n].storeConstraintImpulses(t)}for(n=0;n<this.m_bodies.length;++n){r=this.m_bodies[n];k(Ye,r.c_position.c);a=r.c_position.a;k(We,r.c_velocity.v);m=r.c_velocity.w;Y(He,s,We);var c=tt(He);if(c>g.maxTranslationSquared){var _=g.maxTranslation/Oe(c);J(We,_)}var l=s*m;if(l*l>g.maxRotationSquared)m*=_=g.maxRotation/je(l);W(Ye,s,We),a+=s*m,k(r.c_position.c,Ye),r.c_position.a=a,k(r.c_velocity.v,We),r.c_velocity.w=m}var u=!1;for(n=0;n<t.positionIterations;++n){var p=0;for(h=0;h<this.m_contacts.length;++h){var y=this.m_contacts[h].solvePositionConstraint(t);p=Re(p,y)}var d=p>=-3*g.linearSlop,f=!0;for(h=0;h<this.m_joints.length;++h){var v=this.m_joints[h].solvePositionConstraints(t);f=f&&v}if(d&&f){u=!0;break}}for(n=0;n<this.m_bodies.length;++n){k((r=this.m_bodies[n]).m_sweep.c,r.c_position.c),r.m_sweep.a=r.c_position.a,k(r.m_linearVelocity,r.c_velocity.v),r.m_angularVelocity=r.c_velocity.w,r.synchronizeTransform()}if(this.postSolveIsland(),o){var x=1/0,A=g.linearSleepToleranceSqr,b=g.angularSleepToleranceSqr;for(n=0;n<this.m_bodies.length;++n){(r=this.m_bodies[n]).isStatic()||(0==r.m_autoSleepFlag||r.m_angularVelocity*r.m_angularVelocity>b||tt(r.m_linearVelocity)>A?(r.m_sleepTime=0,x=0):(r.m_sleepTime+=s,x=Re(x,r.m_sleepTime)))}if(x>=g.timeToSleep&&u)for(n=0;n<this.m_bodies.length;++n){(r=this.m_bodies[n]).setAwake(!1)}}},e.prototype.solveWorldTOI=function(e){var i=this.m_world;if(i.m_stepComplete){for(var o=i.m_bodyList;o;o=o.m_next)o.m_islandFlag=!1,o.m_sweep.alpha0=0;for(var s=i.m_contactList;s;s=s.m_next)s.m_toiFlag=!1,s.m_islandFlag=!1,s.m_toiCount=0,s.m_toi=1}for(;;){for(var n=null,r=1,a=i.m_contactList;a;a=a.m_next)if(0!=a.isEnabled()&&!(a.m_toiCount>g.maxSubSteps)){var m=1;if(a.m_toiFlag)m=a.m_toi;else{var h=a.getFixtureA(),c=a.getFixtureB();if(h.isSensor()||c.isSensor())continue;var _=h.getBody(),l=c.getBody(),u=_.isAwake()&&!_.isStatic(),p=l.isAwake()&&!l.isStatic();if(0==u&&0==p)continue;var y=_.isBullet()||!_.isDynamic(),d=l.isBullet()||!l.isDynamic();if(0==y&&0==d)continue;var f=_.m_sweep.alpha0;_.m_sweep.alpha0<l.m_sweep.alpha0?(f=l.m_sweep.alpha0,_.m_sweep.advance(f)):l.m_sweep.alpha0<_.m_sweep.alpha0&&(f=_.m_sweep.alpha0,l.m_sweep.advance(f));var v=a.getChildIndexA(),x=a.getChildIndexB();_.m_sweep,l.m_sweep,Ue.proxyA.set(h.getShape(),v),Ue.proxyB.set(c.getShape(),x),Ue.sweepA.set(_.m_sweep),Ue.sweepB.set(l.m_sweep),Ue.tMax=1,ke(Ze,Ue);var A=Ze.t;m=Ze.state==t.TOIOutputState.e_touching?Re(f+(1-f)*A,1):1,a.m_toi=m,a.m_toiFlag=!0}m<r&&(n=a,r=m)}if(null==n||1-1e-8<r){i.m_stepComplete=!0;break}var b=n.getFixtureA(),B=n.getFixtureB(),w=b.getBody(),V=B.getBody();if(Xe.set(w.m_sweep),Ge.set(V.m_sweep),w.advance(r),V.advance(r),n.update(i),n.m_toiFlag=!1,++n.m_toiCount,0!=n.isEnabled()&&0!=n.isTouching()){w.setAwake(!0),V.setAwake(!0),this.clear(),this.addBody(w),this.addBody(V),this.addContact(n),w.m_islandFlag=!0,V.m_islandFlag=!0,n.m_islandFlag=!0;for(var C=[w,V],M=0;M<C.length;++M){if((F=C[M]).isDynamic())for(var I=F.m_contactList;I;I=I.next){var P=I.contact;if(!P.m_islandFlag){var S=I.other;if(!S.isDynamic()||F.isBullet()||S.isBullet()){var T=P.m_fixtureA.m_isSensor,z=P.m_fixtureB.m_isSensor;T||z||(Ke.set(S.m_sweep),0==S.m_islandFlag&&S.advance(r),P.update(i),0!=P.isEnabled()&&0!=P.isTouching()?(P.m_islandFlag=!0,this.addContact(P),S.m_islandFlag||(S.m_islandFlag=!0,S.isStatic()||S.setAwake(!0),this.addBody(S))):(S.m_sweep.set(Ke),S.synchronizeTransform()))}}}}Je.reset((1-r)*e.dt),Je.dtRatio=1,Je.positionIterations=20,Je.velocityIterations=e.velocityIterations,Je.warmStarting=!1,this.solveIslandTOI(Je,w,V);for(M=0;M<this.m_bodies.length;++M){var F;if((F=this.m_bodies[M]).m_islandFlag=!1,F.isDynamic()){F.synchronizeFixtures();for(I=F.m_contactList;I;I=I.next)I.contact.m_toiFlag=!1,I.contact.m_islandFlag=!1}}if(i.findNewContacts(),i.m_subStepping){i.m_stepComplete=!1;break}}else n.setEnabled(!1),w.m_sweep.set(Xe),V.m_sweep.set(Ge),w.synchronizeTransform(),V.synchronizeTransform()}},e.prototype.solveIslandTOI=function(t,e,i){for(var o=0;o<this.m_bodies.length;++o){k((m=this.m_bodies[o]).c_position.c,m.m_sweep.c),m.c_position.a=m.m_sweep.a,k(m.c_velocity.v,m.m_linearVelocity),m.c_velocity.w=m.m_angularVelocity}for(o=0;o<this.m_contacts.length;++o){this.m_contacts[o].initConstraint(t)}for(o=0;o<t.positionIterations;++o){for(var s=0,n=0;n<this.m_contacts.length;++n){var r=this.m_contacts[n].solvePositionConstraintTOI(t,e,i);s=Re(s,r)}if(s>=-1.5*g.linearSlop)break}k(e.m_sweep.c0,e.c_position.c),e.m_sweep.a0=e.c_position.a,k(i.m_sweep.c0,i.c_position.c),i.m_sweep.a0=i.c_position.a;for(o=0;o<this.m_contacts.length;++o){this.m_contacts[o].initVelocityConstraint(t)}for(o=0;o<t.velocityIterations;++o)for(n=0;n<this.m_contacts.length;++n){this.m_contacts[n].solveVelocityConstraint(t)}var a=t.dt;for(o=0;o<this.m_bodies.length;++o){var m=this.m_bodies[o];k(Ye,m.c_position.c);var h=m.c_position.a;k(We,m.c_velocity.v);var c=m.c_velocity.w;Y(He,a,We);var _=tt(He);if(_>g.maxTranslationSquared){var l=g.maxTranslation/Oe(_);J(We,l)}var u=a*c;if(u*u>g.maxRotationSquared)c*=l=g.maxRotation/je(u);W(Ye,a,We),h+=a*c,k(m.c_position.c,Ye),m.c_position.a=h,k(m.c_velocity.v,We),m.c_velocity.w=c,k(m.m_sweep.c,Ye),m.m_sweep.a=h,k(m.m_linearVelocity,We),m.m_angularVelocity=c,m.synchronizeTransform()}this.postSolveIsland()},e.prototype.postSolveIsland=function(){for(var t=0;t<this.m_contacts.length;++t){var e=this.m_contacts[t];this.m_world.postSolve(e,e.m_impulse)}},e}();$e.TimeStep=Ee;var ti,ei,ii,oi=function(){function t(t,e,i,o){"object"==typeof t&&null!==t?(this.ex=y.clone(t),this.ey=y.clone(e)):"number"==typeof t?(this.ex=y.neo(t,i),this.ey=y.neo(e,o)):(this.ex=y.zero(),this.ey=y.zero())}return t.prototype.toString=function(){return JSON.stringify(this)},t.isValid=function(t){return null!=t&&(y.isValid(t.ex)&&y.isValid(t.ey))},t.assert=function(t){},t.prototype.set=function(t,e,i,o){"number"==typeof t&&"number"==typeof e&&"number"==typeof i&&"number"==typeof o?(this.ex.setNum(t,i),this.ey.setNum(e,o)):"object"==typeof t&&"object"==typeof e?(this.ex.setVec2(t),this.ey.setVec2(e)):"object"==typeof t&&(this.ex.setVec2(t.ex),this.ey.setVec2(t.ey))},t.prototype.setIdentity=function(){this.ex.x=1,this.ey.x=0,this.ex.y=0,this.ey.y=1},t.prototype.setZero=function(){this.ex.x=0,this.ey.x=0,this.ex.y=0,this.ey.y=0},t.prototype.getInverse=function(){var e=this.ex.x,i=this.ey.x,o=this.ex.y,s=this.ey.y,n=e*s-i*o;0!==n&&(n=1/n);var r=new t;return r.ex.x=n*s,r.ey.x=-n*i,r.ex.y=-n*o,r.ey.y=n*e,r},t.prototype.solve=function(t){var e=this.ex.x,i=this.ey.x,o=this.ex.y,s=this.ey.y,n=e*s-i*o;0!==n&&(n=1/n);var r=y.zero();return r.x=n*(s*t.x-i*t.y),r.y=n*(e*t.y-o*t.x),r},t.mul=function(e,i){if(i&&"x"in i&&"y"in i){var o=e.ex.x*i.x+e.ey.x*i.y,s=e.ex.y*i.x+e.ey.y*i.y;return y.neo(o,s)}if(i&&"ex"in i&&"ey"in i)return new t(e.ex.x*i.ex.x+e.ey.x*i.ex.y,e.ex.x*i.ey.x+e.ey.x*i.ey.y,e.ex.y*i.ex.x+e.ey.y*i.ex.y,e.ex.y*i.ey.x+e.ey.y*i.ey.y)},t.mulVec2=function(t,e){var i=t.ex.x*e.x+t.ey.x*e.y,o=t.ex.y*e.x+t.ey.y*e.y;return y.neo(i,o)},t.mulMat22=function(e,i){return new t(e.ex.x*i.ex.x+e.ey.x*i.ex.y,e.ex.x*i.ey.x+e.ey.x*i.ey.y,e.ex.y*i.ex.x+e.ey.y*i.ex.y,e.ex.y*i.ey.x+e.ey.y*i.ey.y)},t.mulT=function(e,i){return i&&"x"in i&&"y"in i?y.neo(y.dot(i,e.ex),y.dot(i,e.ey)):i&&"ex"in i&&"ey"in i?new t(y.neo(y.dot(e.ex,i.ex),y.dot(e.ey,i.ex)),y.neo(y.dot(e.ex,i.ey),y.dot(e.ey,i.ey))):void 0},t.mulTVec2=function(t,e){return y.neo(y.dot(e,t.ex),y.dot(e,t.ey))},t.mulTMat22=function(e,i){return new t(y.neo(y.dot(e.ex,i.ex),y.dot(e.ey,i.ex)),y.neo(y.dot(e.ex,i.ey),y.dot(e.ey,i.ey)))},t.abs=function(e){return new t(y.abs(e.ex),y.abs(e.ey))},t.add=function(e,i){return new t(y.add(e.ex,i.ex),y.add(e.ey,i.ey))},t}(),si=Math.sqrt,ni=q(0,0),ri=q(0,0),ai=q(0,0),mi=q(0,0),hi=q(0,0),ci=q(0,0),_i=q(0,0),li=q(0,0);t.ManifoldType=void 0,(ti=t.ManifoldType||(t.ManifoldType={}))[ti.e_unset=-1]="e_unset",ti[ti.e_circles=0]="e_circles",ti[ti.e_faceA=1]="e_faceA",ti[ti.e_faceB=2]="e_faceB",t.ContactFeatureType=void 0,(ei=t.ContactFeatureType||(t.ContactFeatureType={}))[ei.e_unset=-1]="e_unset",ei[ei.e_vertex=0]="e_vertex",ei[ei.e_face=1]="e_face",t.PointState=void 0,(ii=t.PointState||(t.PointState={}))[ii.nullState=0]="nullState",ii[ii.addState=1]="addState",ii[ii.persistState=2]="persistState",ii[ii.removeState=3]="removeState";var ui=function(){function t(){this.v=q(0,0),this.id=new di}return t.prototype.set=function(t){k(this.v,t.v),this.id.set(t.id)},t.prototype.recycle=function(){D(this.v),this.id.recycle()},t}(),pi=function(){function e(){this.localNormal=q(0,0),this.localPoint=q(0,0),this.points=[new yi,new yi],this.pointCount=0}return e.prototype.set=function(t){this.type=t.type,k(this.localNormal,t.localNormal),k(this.localPoint,t.localPoint),this.pointCount=t.pointCount,this.points[0].set(t.points[0]),this.points[1].set(t.points[1])},e.prototype.recycle=function(){this.type=t.ManifoldType.e_unset,D(this.localNormal),D(this.localPoint),this.pointCount=0,this.points[0].recycle(),this.points[1].recycle()},e.prototype.getWorldManifold=function(e,i,o,s,n){if(0==this.pointCount)return e;(e=e||new fi).pointCount=this.pointCount;var r=e.normal,a=e.points,m=e.separations;switch(this.type){case t.ManifoldType.e_circles:N(r,1,0);var h=this.points[0];at(ni,i,this.localPoint),at(ri,s,h.localPoint),E(ci,ri,ni);var c=tt(ci);if(c>1e-18)Y(r,1/si(c),ci);U(mi,1,ni,o,r),U(hi,1,ri,-n,r),U(a[0],.5,mi,.5,hi),m[0]=$(E(ai,hi,mi),r);break;case t.ManifoldType.e_faceA:ot(r,i.q,this.localNormal),at(_i,i,this.localPoint);for(var _=0;_<this.pointCount;++_){h=this.points[_];at(li,s,h.localPoint),U(mi,1,li,o-$(E(ai,li,_i),r),r),U(hi,1,li,-n,r),U(a[_],.5,mi,.5,hi),m[_]=$(E(ai,hi,mi),r)}break;case t.ManifoldType.e_faceB:ot(r,s.q,this.localNormal),at(_i,s,this.localPoint);for(_=0;_<this.pointCount;++_){h=this.points[_];at(li,i,h.localPoint),U(hi,1,li,n-$(E(ai,li,_i),r),r),U(mi,1,li,-o,r),U(a[_],.5,mi,.5,hi),m[_]=$(E(ai,mi,hi),r)}j(r)}return e},e.clipSegmentToLine=xi,e.ClipVertex=ui,e.getPointStates=vi,e.PointState=t.PointState,e}(),yi=function(){function t(){this.localPoint=q(0,0),this.normalImpulse=0,this.tangentImpulse=0,this.id=new di}return t.prototype.set=function(t){k(this.localPoint,t.localPoint),this.normalImpulse=t.normalImpulse,this.tangentImpulse=t.tangentImpulse,this.id.set(t.id)},t.prototype.recycle=function(){D(this.localPoint),this.normalImpulse=0,this.tangentImpulse=0,this.id.recycle()},t}(),di=function(){function e(){this.key=-1,this.indexA=-1,this.indexB=-1,this.typeA=t.ContactFeatureType.e_unset,this.typeB=t.ContactFeatureType.e_unset}return e.prototype.setFeatures=function(t,e,i,o){this.indexA=t,this.indexB=i,this.typeA=e,this.typeB=o,this.key=this.indexA+4*this.indexB+16*this.typeA+64*this.typeB},e.prototype.set=function(t){this.indexA=t.indexA,this.indexB=t.indexB,this.typeA=t.typeA,this.typeB=t.typeB,this.key=this.indexA+4*this.indexB+16*this.typeA+64*this.typeB},e.prototype.swapFeatures=function(){var t=this.indexA,e=this.indexB,i=this.typeA,o=this.typeB;this.indexA=e,this.indexB=t,this.typeA=o,this.typeB=i,this.key=this.indexA+4*this.indexB+16*this.typeA+64*this.typeB},e.prototype.recycle=function(){this.indexA=0,this.indexB=0,this.typeA=t.ContactFeatureType.e_unset,this.typeB=t.ContactFeatureType.e_unset,this.key=-1},e}(),fi=function(){function t(){this.normal=q(0,0),this.points=[q(0,0),q(0,0)],this.separations=[0,0],this.pointCount=0}return t.prototype.recycle=function(){D(this.normal),D(this.points[0]),D(this.points[1]),this.separations[0]=0,this.separations[1]=0,this.pointCount=0},t}();function vi(e,i,o,s){for(var n=0;n<o.pointCount;++n){var r=o.points[n].id;e[n]=t.PointState.removeState;for(var a=0;a<s.pointCount;++a)if(s.points[a].id.key===r.key){e[n]=t.PointState.persistState;break}}for(n=0;n<s.pointCount;++n){r=s.points[n].id;i[n]=t.PointState.addState;for(a=0;a<o.pointCount;++a)if(o.points[a].id.key===r.key){i[n]=t.PointState.persistState;break}}}function xi(e,i,o,s,n){var r=0,a=$(o,i[0].v)-s,m=$(o,i[1].v)-s;if(a<=0&&e[r++].set(i[0]),m<=0&&e[r++].set(i[1]),a*m<0){var h=a/(a-m);U(e[r].v,1-h,i[0].v,h,i[1].v),e[r].id.setFeatures(n,t.ContactFeatureType.e_vertex,i[0].id.indexB,t.ContactFeatureType.e_face),++r}return r}var Ai=Math.sqrt,gi=Math.max,bi=Math.min,Bi=new b({create:function(){return new oo},release:function(t){t.recycle()}}),wi=new pi,Vi=new fi,Ci=function(){function t(t){this.prev=null,this.next=null,this.other=null,this.contact=t}return t.prototype.recycle=function(){this.prev=null,this.next=null,this.other=null},t}();function Mi(t,e){return Ai(t*e)}function Ii(t,e){return t>e?t:e}var Pi=[],Si=function(){function t(){this.rA=q(0,0),this.rB=q(0,0),this.normalImpulse=0,this.tangentImpulse=0,this.normalMass=0,this.tangentMass=0,this.velocityBias=0}return t.prototype.recycle=function(){D(this.rA),D(this.rB),this.normalImpulse=0,this.tangentImpulse=0,this.normalMass=0,this.tangentMass=0,this.velocityBias=0},t}(),Ti=q(0,0),zi=q(0,0),Fi=q(0,0),Li=q(0,0),qi=q(0,0),Ni=nt(0,0,0),ki=nt(0,0,0),Di=q(0,0),ji=q(0,0),Oi=q(0,0),Ri=q(0,0),Ei=q(0,0),Ji=q(0,0),Yi=q(0,0),Wi=q(0,0),Hi=q(0,0),Ui=q(0,0),Zi=q(0,0),Ki=q(0,0),Xi=q(0,0),Gi=q(0,0),Qi=q(0,0),$i=q(0,0),to=q(0,0),eo=q(0,0),io=q(0,0),oo=function(){function e(){this.m_nodeA=new Ci(this),this.m_nodeB=new Ci(this),this.m_fixtureA=null,this.m_fixtureB=null,this.m_indexA=-1,this.m_indexB=-1,this.m_evaluateFcn=null,this.m_manifold=new pi,this.m_prev=null,this.m_next=null,this.m_toi=1,this.m_toiCount=0,this.m_toiFlag=!1,this.m_friction=0,this.m_restitution=0,this.m_tangentSpeed=0,this.m_enabledFlag=!0,this.m_islandFlag=!1,this.m_touchingFlag=!1,this.m_filterFlag=!1,this.m_bulletHitFlag=!1,this.m_impulse=new Qe(this),this.v_points=[new Si,new Si],this.v_normal=q(0,0),this.v_normalMass=new oi,this.v_K=new oi,this.v_pointCount=0,this.v_tangentSpeed=0,this.v_friction=0,this.v_restitution=0,this.v_invMassA=0,this.v_invMassB=0,this.v_invIA=0,this.v_invIB=0,this.p_localPoints=[q(0,0),q(0,0)],this.p_localNormal=q(0,0),this.p_localPoint=q(0,0),this.p_localCenterA=q(0,0),this.p_localCenterB=q(0,0),this.p_type=t.ManifoldType.e_unset,this.p_radiusA=0,this.p_radiusB=0,this.p_pointCount=0,this.p_invMassA=0,this.p_invMassB=0,this.p_invIA=0,this.p_invIB=0}return e.prototype.initialize=function(t,e,i,o,s){this.m_fixtureA=t,this.m_fixtureB=i,this.m_indexA=e,this.m_indexB=o,this.m_evaluateFcn=s,this.m_friction=Mi(this.m_fixtureA.m_friction,this.m_fixtureB.m_friction),this.m_restitution=Ii(this.m_fixtureA.m_restitution,this.m_fixtureB.m_restitution)},e.prototype.recycle=function(){this.m_nodeA.recycle(),this.m_nodeB.recycle(),this.m_fixtureA=null,this.m_fixtureB=null,this.m_indexA=-1,this.m_indexB=-1,this.m_evaluateFcn=null,this.m_manifold.recycle(),this.m_prev=null,this.m_next=null,this.m_toi=1,this.m_toiCount=0,this.m_toiFlag=!1,this.m_friction=0,this.m_restitution=0,this.m_tangentSpeed=0,this.m_enabledFlag=!0,this.m_islandFlag=!1,this.m_touchingFlag=!1,this.m_filterFlag=!1,this.m_bulletHitFlag=!1,this.m_impulse.recycle();for(var e=0,i=this.v_points;e<i.length;e++){i[e].recycle()}D(this.v_normal),this.v_normalMass.setZero(),this.v_K.setZero(),this.v_pointCount=0,this.v_tangentSpeed=0,this.v_friction=0,this.v_restitution=0,this.v_invMassA=0,this.v_invMassB=0,this.v_invIA=0,this.v_invIB=0;for(var o=0,s=this.p_localPoints;o<s.length;o++){D(s[o])}D(this.p_localNormal),D(this.p_localPoint),D(this.p_localCenterA),D(this.p_localCenterB),this.p_type=t.ManifoldType.e_unset,this.p_radiusA=0,this.p_radiusB=0,this.p_pointCount=0,this.p_invMassA=0,this.p_invMassB=0,this.p_invIA=0,this.p_invIB=0},e.prototype.initConstraint=function(t){var e=this.m_fixtureA,i=this.m_fixtureB;if(null!==e&&null!==i){var o=e.m_body,s=i.m_body;if(null!==o&&null!==s){var n=e.m_shape,r=i.m_shape;if(null!==n&&null!==r){var a=this.m_manifold,m=a.pointCount;this.v_invMassA=o.m_invMass,this.v_invMassB=s.m_invMass,this.v_invIA=o.m_invI,this.v_invIB=s.m_invI,this.v_friction=this.m_friction,this.v_restitution=this.m_restitution,this.v_tangentSpeed=this.m_tangentSpeed,this.v_pointCount=m,this.v_K.setZero(),this.v_normalMass.setZero(),this.p_invMassA=o.m_invMass,this.p_invMassB=s.m_invMass,this.p_invIA=o.m_invI,this.p_invIB=s.m_invI,k(this.p_localCenterA,o.m_sweep.localCenter),k(this.p_localCenterB,s.m_sweep.localCenter),this.p_radiusA=n.m_radius,this.p_radiusB=r.m_radius,this.p_type=a.type,k(this.p_localNormal,a.localNormal),k(this.p_localPoint,a.localPoint),this.p_pointCount=m;for(var h=0;h<g.maxManifoldPoints;++h)this.v_points[h].recycle(),D(this.p_localPoints[h]);for(h=0;h<m;++h){var c=a.points[h],_=this.v_points[h];t.warmStarting&&(_.normalImpulse=t.dtRatio*c.normalImpulse,_.tangentImpulse=t.dtRatio*c.tangentImpulse),k(this.p_localPoints[h],c.localPoint)}}}}},e.prototype.getManifold=function(){return this.m_manifold},e.prototype.getWorldManifold=function(t){var e=this.m_fixtureA,i=this.m_fixtureB;if(null!==e&&null!==i){var o=e.m_body,s=i.m_body;if(null!==o&&null!==s){var n=e.m_shape,r=i.m_shape;if(null!==n&&null!==r)return this.m_manifold.getWorldManifold(t,o.getTransform(),n.m_radius,s.getTransform(),r.m_radius)}}},e.prototype.setEnabled=function(t){this.m_enabledFlag=!!t},e.prototype.isEnabled=function(){return this.m_enabledFlag},e.prototype.isTouching=function(){return this.m_touchingFlag},e.prototype.getNext=function(){return this.m_next},e.prototype.getFixtureA=function(){return this.m_fixtureA},e.prototype.getFixtureB=function(){return this.m_fixtureB},e.prototype.getChildIndexA=function(){return this.m_indexA},e.prototype.getChildIndexB=function(){return this.m_indexB},e.prototype.flagForFiltering=function(){this.m_filterFlag=!0},e.prototype.setFriction=function(t){this.m_friction=t},e.prototype.getFriction=function(){return this.m_friction},e.prototype.resetFriction=function(){var t=this.m_fixtureA,e=this.m_fixtureB;null!==t&&null!==e&&(this.m_friction=Mi(t.m_friction,e.m_friction))},e.prototype.setRestitution=function(t){this.m_restitution=t},e.prototype.getRestitution=function(){return this.m_restitution},e.prototype.resetRestitution=function(){var t=this.m_fixtureA,e=this.m_fixtureB;null!==t&&null!==e&&(this.m_restitution=Ii(t.m_restitution,e.m_restitution))},e.prototype.setTangentSpeed=function(t){this.m_tangentSpeed=t},e.prototype.getTangentSpeed=function(){return this.m_tangentSpeed},e.prototype.evaluate=function(t,e,i){var o=this.m_fixtureA,s=this.m_fixtureB;null!==o&&null!==s&&this.m_evaluateFcn(t,e,o,this.m_indexA,i,s,this.m_indexB)},e.prototype.update=function(t){var e=this.m_fixtureA,i=this.m_fixtureB;if(null!==e&&null!==i){var o=e.m_body,s=i.m_body;if(null!==o&&null!==s){var n=e.m_shape,r=i.m_shape;if(null!==n&&null!==r){this.m_enabledFlag=!0;var a=!1,m=this.m_touchingFlag,h=e.m_isSensor,c=i.m_isSensor,_=h||c,l=o.m_xf,u=s.m_xf;if(_)a=pe(n,this.m_indexA,r,this.m_indexB,l,u),this.m_manifold.pointCount=0;else{wi.recycle(),wi.set(this.m_manifold),this.m_manifold.recycle(),this.evaluate(this.m_manifold,l,u),a=this.m_manifold.pointCount>0;for(var p=0;p<this.m_manifold.pointCount;++p){var y=this.m_manifold.points[p];y.normalImpulse=0,y.tangentImpulse=0;for(var d=0;d<wi.pointCount;++d){var f=wi.points[d];if(f.id.key===y.id.key){y.normalImpulse=f.normalImpulse,y.tangentImpulse=f.tangentImpulse;break}}}a!==m&&(o.setAwake(!0),s.setAwake(!0))}this.m_touchingFlag=a;var v="object"==typeof t&&null!==t;!m&&a&&v&&t.beginContact(this),m&&!a&&v&&t.endContact(this),!_&&a&&v&&wi&&t.preSolve(this,wi)}}}},e.prototype.solvePositionConstraint=function(t){return this._solvePositionConstraint(t,null,null)},e.prototype.solvePositionConstraintTOI=function(t,e,i){return this._solvePositionConstraint(t,e,i)},e.prototype._solvePositionConstraint=function(e,i,o){var s=null!==i&&null!==o,n=0,r=this.m_fixtureA,a=this.m_fixtureB;if(null===r||null===a)return n;var m=r.m_body,c=a.m_body;if(null===m||null===c)return n;m.c_velocity,c.c_velocity;var _=m.c_position,l=c.c_position,u=this.p_localCenterA,p=this.p_localCenterB,y=0,d=0;s&&m!==i&&m!==o||(y=this.p_invMassA,d=this.p_invIA);var f=0,v=0;s&&c!==i&&c!==o||(f=this.p_invMassB,v=this.p_invIB),k(Ti,_.c);var x=_.a;k(Fi,l.c);for(var A=l.a,b=0;b<this.p_pointCount;++b){wt(Ni,u,Ti,x),wt(ki,p,Fi,A);var B=void 0;switch(this.p_type){case t.ManifoldType.e_circles:at(Di,Ni,this.p_localPoint),at(ji,ki,this.p_localPoints[0]),E(Wi,ji,Di),K(Wi),U(Hi,.5,Di,.5,ji),B=$(ji,Wi)-$(Di,Wi)-this.p_radiusA-this.p_radiusB;break;case t.ManifoldType.e_faceA:ot(Wi,Ni.q,this.p_localNormal),at(Ri,Ni,this.p_localPoint),at(Oi,ki,this.p_localPoints[b]),B=$(Oi,Wi)-$(Ri,Wi)-this.p_radiusA-this.p_radiusB,k(Hi,Oi);break;case t.ManifoldType.e_faceB:ot(Wi,ki.q,this.p_localNormal),at(Ri,ki,this.p_localPoint),at(Oi,Ni,this.p_localPoints[b]),B=$(Oi,Wi)-$(Ri,Wi)-this.p_radiusA-this.p_radiusB,k(Hi,Oi),j(Wi);break;default:return n}E(Ei,Hi,Ti),E(Ji,Hi,Fi),n=bi(n,B);var w=h((s?g.toiBaugarte:g.baumgarte)*(B+g.linearSlop),-g.maxLinearCorrection,0),V=Q(Ei,Wi),C=Q(Ji,Wi),M=y+f+d*V*V+v*C*C;Y(Yi,M>0?-w/M:0,Wi),H(Ti,y,Yi),x-=d*Q(Ei,Yi),W(Fi,f,Yi),A+=v*Q(Ji,Yi)}return k(_.c,Ti),_.a=x,k(l.c,Fi),l.a=A,n},e.prototype.initVelocityConstraint=function(t){var e=this.m_fixtureA,i=this.m_fixtureB;if(null!==e&&null!==i){var o=e.m_body,s=i.m_body;if(null!==o&&null!==s){var n=o.c_velocity,r=s.c_velocity,a=o.c_position,m=s.c_position,h=this.p_radiusA,c=this.p_radiusB,_=this.m_manifold,l=this.v_invMassA,u=this.v_invMassB,p=this.v_invIA,y=this.v_invIB,d=this.p_localCenterA,f=this.p_localCenterB;k(Ti,a.c);var v=a.a;k(zi,n.v);var x=n.w;k(Fi,m.c);var A=m.a;k(Li,r.v);var b=r.w;wt(Ni,d,Ti,v),wt(ki,f,Fi,A),Vi.recycle(),_.getWorldManifold(Vi,Ni,h,ki,c),k(this.v_normal,Vi.normal);for(var B=0;B<this.v_pointCount;++B){var w=this.v_points[B],V=Vi.points[B];E(w.rA,V,Ti),E(w.rB,V,Fi);var C=Q(w.rA,this.v_normal),M=Q(w.rB,this.v_normal),I=l+u+p*C*C+y*M*M;w.normalMass=I>0?1/I:0,X(qi,this.v_normal,1);var P=Q(w.rA,qi),S=Q(w.rB,qi),T=l+u+p*P*P+y*S*S;w.tangentMass=T>0?1/T:0,w.velocityBias=0;var z=0;z+=$(this.v_normal,Li),z+=$(this.v_normal,G(io,b,w.rB)),z-=$(this.v_normal,zi),(z-=$(this.v_normal,G(io,x,w.rA)))<-g.velocityThreshold&&(w.velocityBias=-this.v_restitution*z)}if(2==this.v_pointCount&&t.blockSolve){var F=this.v_points[0],L=this.v_points[1],q=Q(F.rA,this.v_normal),N=Q(F.rB,this.v_normal),D=Q(L.rA,this.v_normal),j=Q(L.rB,this.v_normal),O=l+u+p*q*q+y*N*N,R=l+u+p*D*D+y*j*j,J=l+u+p*q*D+y*N*j;if(O*O<1e3*(O*R-J*J)){this.v_K.ex.setNum(O,J),this.v_K.ey.setNum(J,R);var Y=this.v_K.ex.x,W=this.v_K.ey.x,H=this.v_K.ex.y,U=this.v_K.ey.y,Z=Y*U-W*H;0!==Z&&(Z=1/Z),this.v_normalMass.ex.x=Z*U,this.v_normalMass.ey.x=-Z*W,this.v_normalMass.ex.y=-Z*H,this.v_normalMass.ey.y=Z*Y}else this.v_pointCount=1}k(a.c,Ti),a.a=v,k(n.v,zi),n.w=x,k(m.c,Fi),m.a=A,k(r.v,Li),r.w=b}}},e.prototype.warmStartConstraint=function(t){var e=this.m_fixtureA,i=this.m_fixtureB;if(null!==e&&null!==i){var o=e.m_body,s=i.m_body;if(null!==o&&null!==s){var n=o.c_velocity,r=s.c_velocity;o.c_position,s.c_position;var a=this.v_invMassA,m=this.v_invIA,h=this.v_invMassB,c=this.v_invIB;k(zi,n.v);var _=n.w;k(Li,r.v);var l=r.w;k(Wi,this.v_normal),X(qi,Wi,1);for(var u=0;u<this.v_pointCount;++u){var p=this.v_points[u];U(Yi,p.normalImpulse,Wi,p.tangentImpulse,qi),_-=m*Q(p.rA,Yi),H(zi,a,Yi),l+=c*Q(p.rB,Yi),W(Li,h,Yi)}k(n.v,zi),n.w=_,k(r.v,Li),r.w=l}}},e.prototype.storeConstraintImpulses=function(t){for(var e=this.m_manifold,i=0;i<this.v_pointCount;++i)e.points[i].normalImpulse=this.v_points[i].normalImpulse,e.points[i].tangentImpulse=this.v_points[i].tangentImpulse},e.prototype.solveVelocityConstraint=function(t){var e=this.m_fixtureA,i=this.m_fixtureB;if(null!==e&&null!==i){var o=e.m_body,s=i.m_body;if(null!==o&&null!==s){var n=o.c_velocity;o.c_position;var r=s.c_velocity;s.c_position;var a=this.v_invMassA,m=this.v_invIA,c=this.v_invMassB,_=this.v_invIB;k(zi,n.v);var l=n.w;k(Li,r.v);var u=r.w;k(Wi,this.v_normal),X(qi,Wi,1);for(var p=this.v_friction,y=0;y<this.v_pointCount;++y){var d=this.v_points[y];D(Ui),O(Ui,Li),O(Ui,G(io,u,d.rB)),R(Ui,zi),R(Ui,G(io,l,d.rA));var f=$(Ui,qi)-this.v_tangentSpeed,v=d.tangentMass*-f,x=p*d.normalImpulse;v=(g=h(d.tangentImpulse+v,-x,x))-d.tangentImpulse,d.tangentImpulse=g,Y(Yi,v,qi),H(zi,a,Yi),l-=m*Q(d.rA,Yi),W(Li,c,Yi),u+=_*Q(d.rB,Yi)}if(1==this.v_pointCount||0==t.blockSolve)for(var A=0;A<this.v_pointCount;++A){d=this.v_points[A];D(Ui),O(Ui,Li),O(Ui,G(io,u,d.rB)),R(Ui,zi),R(Ui,G(io,l,d.rA));var g,b=$(Ui,Wi);v=-d.normalMass*(b-d.velocityBias);v=(g=gi(d.normalImpulse+v,0))-d.normalImpulse,d.normalImpulse=g,Y(Yi,v,Wi),H(zi,a,Yi),l-=m*Q(d.rA,Yi),W(Li,c,Yi),u+=_*Q(d.rB,Yi)}else{var B=this.v_points[0],w=this.v_points[1];N(Gi,B.normalImpulse,w.normalImpulse),D(Zi),O(Zi,Li),O(Zi,G(io,u,B.rB)),R(Zi,zi),R(Zi,G(io,l,B.rA)),D(Ki),O(Ki,Li),O(Ki,G(io,u,w.rB)),R(Ki,zi),R(Ki,G(io,l,w.rA));var V=$(Zi,Wi),C=$(Ki,Wi);for(N(Xi,V-B.velocityBias,C-w.velocityBias),Xi.x-=this.v_K.ex.x*Gi.x+this.v_K.ey.x*Gi.y,Xi.y-=this.v_K.ex.y*Gi.x+this.v_K.ey.y*Gi.y;;){if(D(Qi),Qi.x=-(this.v_normalMass.ex.x*Xi.x+this.v_normalMass.ey.x*Xi.y),Qi.y=-(this.v_normalMass.ex.y*Xi.x+this.v_normalMass.ey.y*Xi.y),Qi.x>=0&&Qi.y>=0){E($i,Qi,Gi),Y(to,$i.x,Wi),Y(eo,$i.y,Wi),Z(zi,-a,to,-a,eo,1,zi),l-=m*(Q(B.rA,to)+Q(w.rA,eo)),Z(Li,c,to,c,eo,1,Li),u+=_*(Q(B.rB,to)+Q(w.rB,eo)),B.normalImpulse=Qi.x,w.normalImpulse=Qi.y;break}if(Qi.x=-B.normalMass*Xi.x,Qi.y=0,V=0,C=this.v_K.ex.y*Qi.x+Xi.y,Qi.x>=0&&C>=0){E($i,Qi,Gi),Y(to,$i.x,Wi),Y(eo,$i.y,Wi),Z(zi,-a,to,-a,eo,1,zi),l-=m*(Q(B.rA,to)+Q(w.rA,eo)),Z(Li,c,to,c,eo,1,Li),u+=_*(Q(B.rB,to)+Q(w.rB,eo)),B.normalImpulse=Qi.x,w.normalImpulse=Qi.y;break}if(Qi.x=0,Qi.y=-w.normalMass*Xi.y,V=this.v_K.ey.x*Qi.y+Xi.x,C=0,Qi.y>=0&&V>=0){E($i,Qi,Gi),Y(to,$i.x,Wi),Y(eo,$i.y,Wi),Z(zi,-a,to,-a,eo,1,zi),l-=m*(Q(B.rA,to)+Q(w.rA,eo)),Z(Li,c,to,c,eo,1,Li),u+=_*(Q(B.rB,to)+Q(w.rB,eo)),B.normalImpulse=Qi.x,w.normalImpulse=Qi.y;break}if(Qi.x=0,Qi.y=0,V=Xi.x,C=Xi.y,V>=0&&C>=0){E($i,Qi,Gi),Y(to,$i.x,Wi),Y(eo,$i.y,Wi),Z(zi,-a,to,-a,eo,1,zi),l-=m*(Q(B.rA,to)+Q(w.rA,eo)),Z(Li,c,to,c,eo,1,Li),u+=_*(Q(B.rB,to)+Q(w.rB,eo)),B.normalImpulse=Qi.x,w.normalImpulse=Qi.y;break}break}}k(n.v,zi),n.w=l,k(r.v,Li),r.w=u}}},e.addType=function(t,e,i){Pi[t]=Pi[t]||{},Pi[t][e]=i},e.create=function(t,e,i,o){var s,n=t.m_shape.m_type,r=i.m_shape.m_type,a=Bi.allocate();if(s=Pi[n]&&Pi[n][r])a.initialize(t,e,i,o,s);else{if(!(s=Pi[r]&&Pi[r][n]))return null;a.initialize(i,o,t,e,s)}t=a.m_fixtureA,i=a.m_fixtureB,e=a.getChildIndexA(),o=a.getChildIndexB();var m=t.m_body,h=i.m_body;return a.m_nodeA.contact=a,a.m_nodeA.other=h,a.m_nodeA.prev=null,a.m_nodeA.next=m.m_contactList,null!=m.m_contactList&&(m.m_contactList.prev=a.m_nodeA),m.m_contactList=a.m_nodeA,a.m_nodeB.contact=a,a.m_nodeB.other=m,a.m_nodeB.prev=null,a.m_nodeB.next=h.m_contactList,null!=h.m_contactList&&(h.m_contactList.prev=a.m_nodeB),h.m_contactList=a.m_nodeB,0==t.isSensor()&&0==i.isSensor()&&(m.setAwake(!0),h.setAwake(!0)),a},e.destroy=function(t,e){var i=t.m_fixtureA,o=t.m_fixtureB;if(null!==i&&null!==o){var s=i.m_body,n=o.m_body;null!==s&&null!==n&&(t.isTouching()&&e.endContact(t),t.m_nodeA.prev&&(t.m_nodeA.prev.next=t.m_nodeA.next),t.m_nodeA.next&&(t.m_nodeA.next.prev=t.m_nodeA.prev),t.m_nodeA==s.m_contactList&&(s.m_contactList=t.m_nodeA.next),t.m_nodeB.prev&&(t.m_nodeB.prev.next=t.m_nodeB.next),t.m_nodeB.next&&(t.m_nodeB.next.prev=t.m_nodeB.prev),t.m_nodeB==n.m_contactList&&(n.m_contactList=t.m_nodeB.next),t.m_manifold.pointCount>0&&!i.m_isSensor&&!o.m_isSensor&&(s.setAwake(!0),n.setAwake(!0)),Bi.release(t))}},e}(),so={gravity:y.zero(),allowSleep:!0,warmStarting:!0,continuousPhysics:!0,subStepping:!1,blockSolve:!0,velocityIterations:8,positionIterations:3},no=function(){function t(e){if(!(this instanceof t))return new t(e);this.s_step=new Ee,e?y.isValid(e)&&(e={gravity:e}):e={},e=s(e,so),this.m_solver=new $e(this),this.m_broadPhase=new T,this.m_contactList=null,this.m_contactCount=0,this.m_bodyList=null,this.m_bodyCount=0,this.m_jointList=null,this.m_jointCount=0,this.m_stepComplete=!0,this.m_allowSleep=e.allowSleep,this.m_gravity=y.clone(e.gravity),this.m_clearForces=!0,this.m_newFixture=!1,this.m_locked=!1,this.m_warmStarting=e.warmStarting,this.m_continuousPhysics=e.continuousPhysics,this.m_subStepping=e.subStepping,this.m_blockSolve=e.blockSolve,this.m_velocityIterations=e.velocityIterations,this.m_positionIterations=e.positionIterations,this.m_t=0}return t.prototype._serialize=function(){for(var t=[],e=[],i=this.getBodyList();i;i=i.getNext())t.push(i);for(var o=this.getJointList();o;o=o.getNext())"function"==typeof o._serialize&&e.push(o);return{gravity:this.m_gravity,bodies:t,joints:e}},t._deserialize=function(e,i,o){if(!e)return new t;var s=new t(e.gravity);if(e.bodies)for(var n=e.bodies.length-1;n>=0;n-=1)s._addBody(o(Rt,e.bodies[n],s));if(e.joints)for(n=e.joints.length-1;n>=0;n--)s.createJoint(o(Jt,e.joints[n],s));return s},t.prototype.getBodyList=function(){return this.m_bodyList},t.prototype.getJointList=function(){return this.m_jointList},t.prototype.getContactList=function(){return this.m_contactList},t.prototype.getBodyCount=function(){return this.m_bodyCount},t.prototype.getJointCount=function(){return this.m_jointCount},t.prototype.getContactCount=function(){return this.m_contactCount},t.prototype.setGravity=function(t){this.m_gravity.set(t)},t.prototype.getGravity=function(){return this.m_gravity},t.prototype.isLocked=function(){return this.m_locked},t.prototype.setAllowSleeping=function(t){if(t!=this.m_allowSleep&&(this.m_allowSleep=t,0==this.m_allowSleep))for(var e=this.m_bodyList;e;e=e.m_next)e.setAwake(!0)},t.prototype.getAllowSleeping=function(){return this.m_allowSleep},t.prototype.setWarmStarting=function(t){this.m_warmStarting=t},t.prototype.getWarmStarting=function(){return this.m_warmStarting},t.prototype.setContinuousPhysics=function(t){this.m_continuousPhysics=t},t.prototype.getContinuousPhysics=function(){return this.m_continuousPhysics},t.prototype.setSubStepping=function(t){this.m_subStepping=t},t.prototype.getSubStepping=function(){return this.m_subStepping},t.prototype.setAutoClearForces=function(t){this.m_clearForces=t},t.prototype.getAutoClearForces=function(){return this.m_clearForces},t.prototype.clearForces=function(){for(var t=this.m_bodyList;t;t=t.getNext())t.m_force.setZero(),t.m_torque=0},t.prototype.queryAABB=function(t,e){var i=this.m_broadPhase;this.m_broadPhase.query(t,(function(t){var o=i.getUserData(t);return e(o.fixture)}))},t.prototype.rayCast=function(t,e,i){var o=this.m_broadPhase;this.m_broadPhase.rayCast({maxFraction:1,p1:t,p2:e},(function(t,e){var s=o.getUserData(e),n=s.fixture,r=s.childIndex,a={};if(n.rayCast(a,t,r)){var m=a.fraction,h=y.add(y.mulNumVec2(1-m,t.p1),y.mulNumVec2(m,t.p2));return i(n,h,a.normal,m)}return t.maxFraction}))},t.prototype.getProxyCount=function(){return this.m_broadPhase.getProxyCount()},t.prototype.getTreeHeight=function(){return this.m_broadPhase.getTreeHeight()},t.prototype.getTreeBalance=function(){return this.m_broadPhase.getTreeBalance()},t.prototype.getTreeQuality=function(){return this.m_broadPhase.getTreeQuality()},t.prototype.shiftOrigin=function(t){if(!this.m_locked){for(var e=this.m_bodyList;e;e=e.m_next)e.m_xf.p.sub(t),e.m_sweep.c0.sub(t),e.m_sweep.c.sub(t);for(var i=this.m_jointList;i;i=i.m_next)i.shiftOrigin(t);this.m_broadPhase.shiftOrigin(t)}},t.prototype._addBody=function(t){this.isLocked()||(t.m_prev=null,t.m_next=this.m_bodyList,this.m_bodyList&&(this.m_bodyList.m_prev=t),this.m_bodyList=t,++this.m_bodyCount)},t.prototype.createBody=function(t,e){if(this.isLocked())return null;var i={};t&&(y.isValid(t)?i={position:t,angle:e}:"object"==typeof t&&(i=t));var o=new Rt(this,i);return this._addBody(o),o},t.prototype.createDynamicBody=function(t,e){var i={};return t&&(y.isValid(t)?i={position:t,angle:e}:"object"==typeof t&&(i=t)),i.type="dynamic",this.createBody(i)},t.prototype.createKinematicBody=function(t,e){var i={};return t&&(y.isValid(t)?i={position:t,angle:e}:"object"==typeof t&&(i=t)),i.type="kinematic",this.createBody(i)},t.prototype.destroyBody=function(t){if(!this.isLocked()){if(t.m_destroyed)return!1;for(var e=t.m_jointList;e;){var i=e;e=e.next,this.publish("remove-joint",i.joint),this.destroyJoint(i.joint),t.m_jointList=e}t.m_jointList=null;for(var o=t.m_contactList;o;){var s=o;o=o.next,this.destroyContact(s.contact),t.m_contactList=o}t.m_contactList=null;for(var n=t.m_fixtureList;n;){var r=n;n=n.m_next,this.publish("remove-fixture",r),r.destroyProxies(this.m_broadPhase),t.m_fixtureList=n}return t.m_fixtureList=null,t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),t==this.m_bodyList&&(this.m_bodyList=t.m_next),t.m_destroyed=!0,--this.m_bodyCount,this.publish("remove-body",t),!0}},t.prototype.createJoint=function(t){if(this.isLocked())return null;if(t.m_prev=null,t.m_next=this.m_jointList,this.m_jointList&&(this.m_jointList.m_prev=t),this.m_jointList=t,++this.m_jointCount,t.m_edgeA.joint=t,t.m_edgeA.other=t.m_bodyB,t.m_edgeA.prev=null,t.m_edgeA.next=t.m_bodyA.m_jointList,t.m_bodyA.m_jointList&&(t.m_bodyA.m_jointList.prev=t.m_edgeA),t.m_bodyA.m_jointList=t.m_edgeA,t.m_edgeB.joint=t,t.m_edgeB.other=t.m_bodyA,t.m_edgeB.prev=null,t.m_edgeB.next=t.m_bodyB.m_jointList,t.m_bodyB.m_jointList&&(t.m_bodyB.m_jointList.prev=t.m_edgeB),t.m_bodyB.m_jointList=t.m_edgeB,0==t.m_collideConnected)for(var e=t.m_bodyB.getContactList();e;e=e.next)e.other==t.m_bodyA&&e.contact.flagForFiltering();return t},t.prototype.destroyJoint=function(t){if(!this.isLocked()){t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),t==this.m_jointList&&(this.m_jointList=t.m_next);var e=t.m_bodyA,i=t.m_bodyB;if(e.setAwake(!0),i.setAwake(!0),t.m_edgeA.prev&&(t.m_edgeA.prev.next=t.m_edgeA.next),t.m_edgeA.next&&(t.m_edgeA.next.prev=t.m_edgeA.prev),t.m_edgeA==e.m_jointList&&(e.m_jointList=t.m_edgeA.next),t.m_edgeA.prev=null,t.m_edgeA.next=null,t.m_edgeB.prev&&(t.m_edgeB.prev.next=t.m_edgeB.next),t.m_edgeB.next&&(t.m_edgeB.next.prev=t.m_edgeB.prev),t.m_edgeB==i.m_jointList&&(i.m_jointList=t.m_edgeB.next),t.m_edgeB.prev=null,t.m_edgeB.next=null,--this.m_jointCount,0==t.m_collideConnected)for(var o=i.getContactList();o;)o.other==e&&o.contact.flagForFiltering(),o=o.next;this.publish("remove-joint",t)}},t.prototype.step=function(t,e,i){if(this.publish("pre-step",t),(0|e)!==e&&(e=0),e=e||this.m_velocityIterations,i=i||this.m_positionIterations,this.m_newFixture&&(this.findNewContacts(),this.m_newFixture=!1),this.m_locked=!0,this.s_step.reset(t),this.s_step.velocityIterations=e,this.s_step.positionIterations=i,this.s_step.warmStarting=this.m_warmStarting,this.s_step.blockSolve=this.m_blockSolve,this.updateContacts(),this.m_stepComplete&&t>0){this.m_solver.solveWorld(this.s_step);for(var o=this.m_bodyList;o;o=o.getNext())0!=o.m_islandFlag&&(o.isStatic()||o.synchronizeFixtures());this.findNewContacts()}this.m_continuousPhysics&&t>0&&this.m_solver.solveWorldTOI(this.s_step),this.m_clearForces&&this.clearForces(),this.m_locked=!1,this.publish("post-step",t)},t.prototype.findNewContacts=function(){var t=this;this.m_broadPhase.updatePairs((function(e,i){return t.createContact(e,i)}))},t.prototype.createContact=function(t,e){var i=t.fixture,o=e.fixture,s=t.childIndex,n=e.childIndex,r=i.getBody(),a=o.getBody();if(r!=a){for(var m=a.getContactList();m;){if(m.other==r){var h=m.contact.getFixtureA(),c=m.contact.getFixtureB(),_=m.contact.getChildIndexA(),l=m.contact.getChildIndexB();if(h==i&&c==o&&_==s&&l==n)return;if(h==o&&c==i&&_==n&&l==s)return}m=m.next}if(0!=a.shouldCollide(r)&&0!=o.shouldCollide(i)){var u=oo.create(i,s,o,n);null!=u&&(u.m_prev=null,null!=this.m_contactList&&(u.m_next=this.m_contactList,this.m_contactList.m_prev=u),this.m_contactList=u,++this.m_contactCount)}}},t.prototype.updateContacts=function(){for(var t,e=this.m_contactList;t=e;){e=t.getNext();var i=t.getFixtureA(),o=t.getFixtureB(),s=t.getChildIndexA(),n=t.getChildIndexB(),r=i.getBody(),a=o.getBody();if(t.m_filterFlag){if(0==a.shouldCollide(r)){this.destroyContact(t);continue}if(0==o.shouldCollide(i)){this.destroyContact(t);continue}t.m_filterFlag=!1}var m=r.isAwake()&&!r.isStatic(),h=a.isAwake()&&!a.isStatic();if(0!=m||0!=h){var c=i.m_proxies[s].proxyId,_=o.m_proxies[n].proxyId;0!=this.m_broadPhase.testOverlap(c,_)?t.update(this):this.destroyContact(t)}}},t.prototype.destroyContact=function(t){t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),t==this.m_contactList&&(this.m_contactList=t.m_next),oo.destroy(t,this),--this.m_contactCount},t.prototype.on=function(t,e){return"string"!=typeof t||"function"!=typeof e||(this._listeners||(this._listeners={}),this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e)),this},t.prototype.off=function(t,e){if("string"!=typeof t||"function"!=typeof e)return this;var i=this._listeners&&this._listeners[t];if(!i||!i.length)return this;var o=i.indexOf(e);return o>=0&&i.splice(o,1),this},t.prototype.publish=function(t,e,i,o){var s=this._listeners&&this._listeners[t];if(!s||!s.length)return 0;for(var n=0;n<s.length;n++)s[n].call(this,e,i,o);return s.length},t.prototype.beginContact=function(t){this.publish("begin-contact",t)},t.prototype.endContact=function(t){this.publish("end-contact",t)},t.prototype.preSolve=function(t,e){this.publish("pre-solve",t,e)},t.prototype.postSolve=function(t,e){this.publish("post-solve",t,e)},t}(),ro=function(){function t(e,i,o){if(!(this instanceof t))return new t(e,i,o);void 0===e?(this.x=0,this.y=0,this.z=0):"object"==typeof e?(this.x=e.x,this.y=e.y,this.z=e.z):(this.x=e,this.y=i,this.z=o)}return t.prototype._serialize=function(){return{x:this.x,y:this.y,z:this.z}},t._deserialize=function(e){var i=Object.create(t.prototype);return i.x=e.x,i.y=e.y,i.z=e.z,i},t.neo=function(e,i,o){var s=Object.create(t.prototype);return s.x=e,s.y=i,s.z=o,s},t.zero=function(){var e=Object.create(t.prototype);return e.x=0,e.y=0,e.z=0,e},t.clone=function(e){return t.neo(e.x,e.y,e.z)},t.prototype.toString=function(){return JSON.stringify(this)},t.isValid=function(t){return null!=t&&(Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(t.z))},t.assert=function(t){},t.prototype.setZero=function(){return this.x=0,this.y=0,this.z=0,this},t.prototype.set=function(t,e,i){return this.x=t,this.y=e,this.z=i,this},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},t.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},t.prototype.mul=function(t){return this.x*=t,this.y*=t,this.z*=t,this},t.areEqual=function(t,e){return t===e||"object"==typeof t&&null!==t&&"object"==typeof e&&null!==e&&t.x===e.x&&t.y===e.y&&t.z===e.z},t.dot=function(t,e){return t.x*e.x+t.y*e.y+t.z*e.z},t.cross=function(e,i){return new t(e.y*i.z-e.z*i.y,e.z*i.x-e.x*i.z,e.x*i.y-e.y*i.x)},t.add=function(e,i){return new t(e.x+i.x,e.y+i.y,e.z+i.z)},t.sub=function(e,i){return new t(e.x-i.x,e.y-i.y,e.z-i.z)},t.mul=function(e,i){return new t(i*e.x,i*e.y,i*e.z)},t.prototype.neg=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},t.neg=function(e){return new t(-e.x,-e.y,-e.z)},t}(),ao=q(0,0),mo=q(0,0),ho=function(t){function e(i,o){var s=this;return s instanceof e?((s=t.call(this)||this).m_type=e.TYPE,s.m_radius=g.polygonRadius,s.m_vertex1=i?y.clone(i):y.zero(),s.m_vertex2=o?y.clone(o):y.zero(),s.m_vertex0=y.zero(),s.m_vertex3=y.zero(),s.m_hasVertex0=!1,s.m_hasVertex3=!1,s):new e(i,o)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,vertex1:this.m_vertex1,vertex2:this.m_vertex2,vertex0:this.m_vertex0,vertex3:this.m_vertex3,hasVertex0:this.m_hasVertex0,hasVertex3:this.m_hasVertex3}},e._deserialize=function(t){var i=new e(t.vertex1,t.vertex2);return i.m_hasVertex0&&i.setPrevVertex(t.vertex0),i.m_hasVertex3&&i.setNextVertex(t.vertex3),i},e.prototype._reset=function(){},e.prototype.getRadius=function(){return this.m_radius},e.prototype.getType=function(){return this.m_type},e.prototype.setNext=function(t){return this.setNextVertex(t)},e.prototype.setNextVertex=function(t){return t?(this.m_vertex3.setVec2(t),this.m_hasVertex3=!0):(this.m_vertex3.setZero(),this.m_hasVertex3=!1),this},e.prototype.getNextVertex=function(){return this.m_vertex3},e.prototype.setPrev=function(t){return this.setPrevVertex(t)},e.prototype.setPrevVertex=function(t){return t?(this.m_vertex0.setVec2(t),this.m_hasVertex0=!0):(this.m_vertex0.setZero(),this.m_hasVertex0=!1),this},e.prototype.getPrevVertex=function(){return this.m_vertex0},e.prototype._set=function(t,e){return this.m_vertex1.setVec2(t),this.m_vertex2.setVec2(e),this.m_hasVertex0=!1,this.m_hasVertex3=!1,this},e.prototype._clone=function(){var t=new e;return t.m_type=this.m_type,t.m_radius=this.m_radius,t.m_vertex1.setVec2(this.m_vertex1),t.m_vertex2.setVec2(this.m_vertex2),t.m_vertex0.setVec2(this.m_vertex0),t.m_vertex3.setVec2(this.m_vertex3),t.m_hasVertex0=this.m_hasVertex0,t.m_hasVertex3=this.m_hasVertex3,t},e.prototype.getChildCount=function(){return 1},e.prototype.testPoint=function(t,e){return!1},e.prototype.rayCast=function(t,e,i,o){var s=pt.mulTVec2(i.q,y.sub(e.p1,i.p)),n=pt.mulTVec2(i.q,y.sub(e.p2,i.p)),r=y.sub(n,s),a=this.m_vertex1,m=this.m_vertex2,h=y.sub(m,a),c=y.neo(h.y,-h.x);c.normalize();var _=y.dot(c,y.sub(a,s)),l=y.dot(c,r);if(0==l)return!1;var u=_/l;if(u<0||e.maxFraction<u)return!1;var p=y.add(s,y.mulNumVec2(u,r)),d=y.sub(m,a),f=y.dot(d,d);if(0==f)return!1;var v=y.dot(y.sub(p,a),d)/f;return!(v<0||1<v)&&(t.fraction=u,t.normal=_>0?pt.mulVec2(i.q,c).neg():pt.mulVec2(i.q,c),!0)},e.prototype.computeAABB=function(t,e,i){at(ao,e,this.m_vertex1),at(mo,e,this.m_vertex2),v.combinePoints(t,ao,mo),v.extend(t,this.m_radius)},e.prototype.computeMass=function(t,e){t.mass=0,U(t.center,.5,this.m_vertex1,.5,this.m_vertex2),t.I=0},e.prototype.computeDistanceProxy=function(t){t.m_vertices[0]=this.m_vertex1,t.m_vertices[1]=this.m_vertex2,t.m_vertices.length=2,t.m_count=2,t.m_radius=this.m_radius},e.TYPE="edge",e}(Vt),co=ho,_o=q(0,0),lo=q(0,0),uo=function(t){function e(i,o){var s=this;return s instanceof e?((s=t.call(this)||this).m_type=e.TYPE,s.m_radius=g.polygonRadius,s.m_vertices=[],s.m_count=0,s.m_prevVertex=null,s.m_nextVertex=null,s.m_hasPrevVertex=!1,s.m_hasNextVertex=!1,s.m_isLoop=!!o,i&&i.length&&(o?s._createLoop(i):s._createChain(i)),s):new e(i,o)}return i(e,t),e.prototype._serialize=function(){var t={type:this.m_type,vertices:this.m_vertices,isLoop:this.m_isLoop,hasPrevVertex:this.m_hasPrevVertex,hasNextVertex:this.m_hasNextVertex,prevVertex:null,nextVertex:null};return this.m_prevVertex&&(t.prevVertex=this.m_prevVertex),this.m_nextVertex&&(t.nextVertex=this.m_nextVertex),t},e._deserialize=function(t,i,o){var s=[];if(t.vertices)for(var n=0;n<t.vertices.length;n++)s.push(o(y,t.vertices[n]));var r=new e(s,t.isLoop);return t.prevVertex&&r.setPrevVertex(t.prevVertex),t.nextVertex&&r.setNextVertex(t.nextVertex),r},e.prototype.getType=function(){return this.m_type},e.prototype.getRadius=function(){return this.m_radius},e.prototype._createLoop=function(t){if(!(t.length<3)){for(var e=1;e<t.length;++e)t[e-1],t[e];this.m_vertices=[],this.m_count=t.length+1;for(e=0;e<t.length;++e)this.m_vertices[e]=y.clone(t[e]);return this.m_vertices[t.length]=y.clone(t[0]),this.m_prevVertex=this.m_vertices[this.m_count-2],this.m_nextVertex=this.m_vertices[1],this.m_hasPrevVertex=!0,this.m_hasNextVertex=!0,this}},e.prototype._createChain=function(t){for(var e=1;e<t.length;++e)t[e-1],t[e];this.m_count=t.length;for(e=0;e<t.length;++e)this.m_vertices[e]=y.clone(t[e]);return this.m_hasPrevVertex=!1,this.m_hasNextVertex=!1,this.m_prevVertex=null,this.m_nextVertex=null,this},e.prototype._reset=function(){this.m_isLoop?this._createLoop(this.m_vertices):this._createChain(this.m_vertices)},e.prototype.setPrevVertex=function(t){this.m_prevVertex=t,this.m_hasPrevVertex=!0},e.prototype.getPrevVertex=function(){return this.m_prevVertex},e.prototype.setNextVertex=function(t){this.m_nextVertex=t,this.m_hasNextVertex=!0},e.prototype.getNextVertex=function(){return this.m_nextVertex},e.prototype._clone=function(){var t=new e;return t._createChain(this.m_vertices),t.m_type=this.m_type,t.m_radius=this.m_radius,t.m_prevVertex=this.m_prevVertex,t.m_nextVertex=this.m_nextVertex,t.m_hasPrevVertex=this.m_hasPrevVertex,t.m_hasNextVertex=this.m_hasNextVertex,t},e.prototype.getChildCount=function(){return this.m_count-1},e.prototype.getChildEdge=function(t,e){t.m_type=ho.TYPE,t.m_radius=this.m_radius,t.m_vertex1=this.m_vertices[e],t.m_vertex2=this.m_vertices[e+1],e>0?(t.m_vertex0=this.m_vertices[e-1],t.m_hasVertex0=!0):(t.m_vertex0=this.m_prevVertex,t.m_hasVertex0=this.m_hasPrevVertex),e<this.m_count-2?(t.m_vertex3=this.m_vertices[e+2],t.m_hasVertex3=!0):(t.m_vertex3=this.m_nextVertex,t.m_hasVertex3=this.m_hasNextVertex)},e.prototype.getVertex=function(t){return t<this.m_count?this.m_vertices[t]:this.m_vertices[0]},e.prototype.isLoop=function(){return this.m_isLoop},e.prototype.testPoint=function(t,e){return!1},e.prototype.rayCast=function(t,e,i,o){return new ho(this.getVertex(o),this.getVertex(o+1)).rayCast(t,e,i,0)},e.prototype.computeAABB=function(t,e,i){at(_o,e,this.getVertex(i)),at(lo,e,this.getVertex(i+1)),v.combinePoints(t,_o,lo)},e.prototype.computeMass=function(t,e){t.mass=0,D(t.center),t.I=0},e.prototype.computeDistanceProxy=function(t,e){t.m_vertices[0]=this.getVertex(e),t.m_vertices[1]=this.getVertex(e+1),t.m_count=2,t.m_radius=this.m_radius},e.TYPE="chain",e}(Vt),po=uo,yo=Math.max,fo=Math.min,vo=q(0,0),xo=q(0,0),Ao=q(0,0),go=q(0,0),bo=q(0,0),Bo=q(0,0),wo=function(t){function e(i){var o=this;return o instanceof e?((o=t.call(this)||this).m_type=e.TYPE,o.m_radius=g.polygonRadius,o.m_centroid=y.zero(),o.m_vertices=[],o.m_normals=[],o.m_count=0,i&&i.length&&o._set(i),o):new e(i)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,vertices:this.m_vertices}},e._deserialize=function(t,i,o){var s=[];if(t.vertices)for(var n=0;n<t.vertices.length;n++)s.push(o(y,t.vertices[n]));return new e(s)},e.prototype.getType=function(){return this.m_type},e.prototype.getRadius=function(){return this.m_radius},e.prototype._clone=function(){var t=new e;t.m_type=this.m_type,t.m_radius=this.m_radius,t.m_count=this.m_count,t.m_centroid.setVec2(this.m_centroid);for(var i=0;i<this.m_count;i++)t.m_vertices.push(this.m_vertices[i].clone());for(i=0;i<this.m_normals.length;i++)t.m_normals.push(this.m_normals[i].clone());return t},e.prototype.getChildCount=function(){return 1},e.prototype._reset=function(){this._set(this.m_vertices)},e.prototype._set=function(t){if(t.length<3)this._setAsBox(1,1);else{for(var e=fo(t.length,g.maxPolygonVertices),i=[],o=0;o<e;++o){for(var s=t[o],n=!0,r=0;r<i.length;++r)if(y.distanceSquared(s,i[r])<.25*g.linearSlopSquared){n=!1;break}n&&i.push(y.clone(s))}if((e=i.length)<3)this._setAsBox(1,1);else{var a=0,m=i[0].x;for(o=1;o<e;++o){var h=i[o].x;(h>m||h===m&&i[o].y<i[a].y)&&(a=o,m=h)}for(var c=[],_=0,l=a;;){c[_]=l;var u=0;for(r=1;r<e;++r)if(u!==l){var p=y.sub(i[u],i[c[_]]),d=(s=y.sub(i[r],i[c[_]]),y.crossVec2Vec2(p,s));d<0&&(u=r),0===d&&s.lengthSquared()>p.lengthSquared()&&(u=r)}else u=r;if(++_,l=u,u===a)break}if(_<3)this._setAsBox(1,1);else{this.m_count=_,this.m_vertices=[];for(o=0;o<_;++o)this.m_vertices[o]=i[c[o]];for(o=0;o<_;++o){var f=o,v=o+1<_?o+1:0,x=y.sub(this.m_vertices[v],this.m_vertices[f]);this.m_normals[o]=y.crossVec2Num(x,1),this.m_normals[o].normalize()}this.m_centroid=function(t,e){for(var i=y.zero(),o=0,s=y.zero(),n=1/3,r=0;r<e;++r){var a=s,m=t[r],h=r+1<e?t[r+1]:t[0],c=y.sub(m,a),_=y.sub(h,a),l=.5*y.crossVec2Vec2(c,_);o+=l,Z(vo,1,a,1,m,1,h),W(i,l*n,vo)}return i.mul(1/o),i}(this.m_vertices,_)}}}},e.prototype._setAsBox=function(t,e,i,o){if(this.m_vertices[0]=y.neo(t,-e),this.m_vertices[1]=y.neo(t,e),this.m_vertices[2]=y.neo(-t,e),this.m_vertices[3]=y.neo(-t,-e),this.m_normals[0]=y.neo(1,0),this.m_normals[1]=y.neo(0,1),this.m_normals[2]=y.neo(-1,0),this.m_normals[3]=y.neo(0,-1),this.m_count=4,i&&y.isValid(i)){o=o||0,k(this.m_centroid,i);var s=xt.identity();s.p.setVec2(i),s.q.setAngle(o);for(var n=0;n<this.m_count;++n)this.m_vertices[n]=xt.mulVec2(s,this.m_vertices[n]),this.m_normals[n]=pt.mulVec2(s.q,this.m_normals[n])}},e.prototype.testPoint=function(t,e){for(var i=mt(vo,t,e),o=0;o<this.m_count;++o){if($(this.m_normals[o],i)-$(this.m_normals[o],this.m_vertices[o])>0)return!1}return!0},e.prototype.rayCast=function(t,e,i,o){for(var s=pt.mulTVec2(i.q,y.sub(e.p1,i.p)),n=pt.mulTVec2(i.q,y.sub(e.p2,i.p)),r=y.sub(n,s),a=0,m=e.maxFraction,h=-1,c=0;c<this.m_count;++c){var _=y.dot(this.m_normals[c],y.sub(this.m_vertices[c],s)),l=y.dot(this.m_normals[c],r);if(0==l){if(_<0)return!1}else l<0&&_<a*l?(a=_/l,h=c):l>0&&_<m*l&&(m=_/l);if(m<a)return!1}return h>=0&&(t.fraction=a,t.normal=pt.mulVec2(i.q,this.m_normals[h]),!0)},e.prototype.computeAABB=function(t,e,i){for(var o=1/0,s=1/0,n=-1/0,r=-1/0,a=0;a<this.m_count;++a){var m=at(vo,e,this.m_vertices[a]);o=fo(o,m.x),n=yo(n,m.x),s=fo(s,m.y),r=yo(r,m.y)}N(t.lowerBound,o-this.m_radius,s-this.m_radius),N(t.upperBound,n+this.m_radius,r+this.m_radius)},e.prototype.computeMass=function(t,e){D(bo);var i=0,o=0;D(Bo);for(var s=0;s<this.m_count;++s)O(Bo,this.m_vertices[s]);Y(Bo,1/this.m_count,Bo);var n=1/3;for(s=0;s<this.m_count;++s){E(Ao,this.m_vertices[s],Bo),s+1<this.m_count?E(go,this.m_vertices[s+1],Bo):E(go,this.m_vertices[0],Bo);var r=Q(Ao,go),a=.5*r;i+=a,U(vo,a*n,Ao,a*n,go),O(bo,vo);var m=Ao.x,h=Ao.y,c=go.x,_=go.y;o+=.25*n*r*(m*m+c*m+c*c+(h*h+_*h+_*_))}t.mass=e*i,Y(bo,1/i,bo),function(t,e,i){t.x=e.x+i.x,t.y=e.x+i.y}(t.center,bo,Bo),t.I=e*o,t.I+=t.mass*($(t.center,t.center)-$(bo,bo))},e.prototype.validate=function(){for(var t=0;t<this.m_count;++t){var e=t,i=t<this.m_count-1?e+1:0,o=this.m_vertices[e];E(xo,this.m_vertices[i],o);for(var s=0;s<this.m_count;++s){if(s!=e&&s!=i)if(Q(xo,E(vo,this.m_vertices[s],o))<0)return!1}}return!0},e.prototype.computeDistanceProxy=function(t){for(var e=0;e<this.m_count;++e)t.m_vertices[e]=this.m_vertices[e];t.m_vertices.length=this.m_count,t.m_count=this.m_count,t.m_radius=this.m_radius},e.TYPE="polygon",e}(Vt);var Vo,Co=wo,Mo=Math.sqrt,Io=Math.PI,Po=q(0,0),So=function(t){function e(i,o){var s=this;return s instanceof e?((s=t.call(this)||this).m_type=e.TYPE,s.m_p=y.zero(),s.m_radius=1,"object"==typeof i&&y.isValid(i)?(s.m_p.setVec2(i),"number"==typeof o&&(s.m_radius=o)):"number"==typeof i&&(s.m_radius=i),s):new e(i,o)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,p:this.m_p,radius:this.m_radius}},e._deserialize=function(t){return new e(t.p,t.radius)},e.prototype._reset=function(){},e.prototype.getType=function(){return this.m_type},e.prototype.getRadius=function(){return this.m_radius},e.prototype.getCenter=function(){return this.m_p},e.prototype._clone=function(){var t=new e;return t.m_type=this.m_type,t.m_radius=this.m_radius,t.m_p=this.m_p.clone(),t},e.prototype.getChildCount=function(){return 1},e.prototype.testPoint=function(t,e){return it(e,at(Po,t,this.m_p))<=this.m_radius*this.m_radius},e.prototype.rayCast=function(t,e,i,o){var s=y.add(i.p,pt.mulVec2(i.q,this.m_p)),n=y.sub(e.p1,s),a=y.dot(n,n)-this.m_radius*this.m_radius,m=y.sub(e.p2,e.p1),h=y.dot(n,m),c=y.dot(m,m),_=h*h-c*a;if(_<0||c<r)return!1;var l=-(h+Mo(_));return 0<=l&&l<=e.maxFraction*c&&(l/=c,t.fraction=l,t.normal=y.add(n,y.mulNumVec2(l,m)),t.normal.normalize(),!0)},e.prototype.computeAABB=function(t,e,i){var o=at(Po,e,this.m_p);N(t.lowerBound,o.x-this.m_radius,o.y-this.m_radius),N(t.upperBound,o.x+this.m_radius,o.y+this.m_radius)},e.prototype.computeMass=function(t,e){t.mass=e*Io*this.m_radius*this.m_radius,k(t.center,this.m_p),t.I=t.mass*(.5*this.m_radius*this.m_radius+tt(this.m_p))},e.prototype.computeDistanceProxy=function(t){t.m_vertices[0]=this.m_p,t.m_vertices.length=1,t.m_count=1,t.m_radius=this.m_radius},e.TYPE="circle",e}(Vt),To=So,zo=Math.abs,Fo=Math.PI,Lo={frequencyHz:0,dampingRatio:0},qo=function(t){function e(i,o,n,r,a){var m=this;if(!(m instanceof e))return new e(i,o,n,r,a);if(n&&r&&"m_type"in r&&"x"in n&&"y"in n){var h=n;n=r,r=h}return i=s(i,Lo),o=(m=t.call(this,i,o,n)||this).m_bodyA,n=m.m_bodyB,m.m_type=e.TYPE,m.m_localAnchorA=y.clone(r?o.getLocalPoint(r):i.localAnchorA||y.zero()),m.m_localAnchorB=y.clone(a?n.getLocalPoint(a):i.localAnchorB||y.zero()),m.m_length=Number.isFinite(i.length)?i.length:y.distance(o.getWorldPoint(m.m_localAnchorA),n.getWorldPoint(m.m_localAnchorB)),m.m_frequencyHz=i.frequencyHz,m.m_dampingRatio=i.dampingRatio,m.m_impulse=0,m.m_gamma=0,m.m_bias=0,m}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,frequencyHz:this.m_frequencyHz,dampingRatio:this.m_dampingRatio,localAnchorA:this.m_localAnchorA,localAnchorB:this.m_localAnchorB,length:this.m_length,impulse:this.m_impulse,gamma:this.m_gamma,bias:this.m_bias}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),new e(t)},e.prototype._reset=function(t){t.anchorA?this.m_localAnchorA.setVec2(this.m_bodyA.getLocalPoint(t.anchorA)):t.localAnchorA&&this.m_localAnchorA.setVec2(t.localAnchorA),t.anchorB?this.m_localAnchorB.setVec2(this.m_bodyB.getLocalPoint(t.anchorB)):t.localAnchorB&&this.m_localAnchorB.setVec2(t.localAnchorB),t.length>0?this.m_length=+t.length:t.length<0||(t.anchorA||t.anchorA||t.anchorA||t.anchorA)&&(this.m_length=y.distance(this.m_bodyA.getWorldPoint(this.m_localAnchorA),this.m_bodyB.getWorldPoint(this.m_localAnchorB))),Number.isFinite(t.frequencyHz)&&(this.m_frequencyHz=t.frequencyHz),Number.isFinite(t.dampingRatio)&&(this.m_dampingRatio=t.dampingRatio)},e.prototype.getLocalAnchorA=function(){return this.m_localAnchorA},e.prototype.getLocalAnchorB=function(){return this.m_localAnchorB},e.prototype.setLength=function(t){this.m_length=t},e.prototype.getLength=function(){return this.m_length},e.prototype.setFrequency=function(t){this.m_frequencyHz=t},e.prototype.getFrequency=function(){return this.m_frequencyHz},e.prototype.setDampingRatio=function(t){this.m_dampingRatio=t},e.prototype.getDampingRatio=function(){return this.m_dampingRatio},e.prototype.getAnchorA=function(){return this.m_bodyA.getWorldPoint(this.m_localAnchorA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.mulNumVec2(this.m_impulse,this.m_u).mul(t)},e.prototype.getReactionTorque=function(t){return 0},e.prototype.initVelocityConstraints=function(t){this.m_localCenterA=this.m_bodyA.m_sweep.localCenter,this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyA.c_velocity.v,s=this.m_bodyA.c_velocity.w,n=this.m_bodyB.c_position.c,r=this.m_bodyB.c_position.a,a=this.m_bodyB.c_velocity.v,m=this.m_bodyB.c_velocity.w,h=pt.neo(i),c=pt.neo(r);this.m_rA=pt.mulVec2(h,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=pt.mulVec2(c,y.sub(this.m_localAnchorB,this.m_localCenterB)),this.m_u=y.sub(y.add(n,this.m_rB),y.add(e,this.m_rA));var _=this.m_u.length();_>g.linearSlop?this.m_u.mul(1/_):this.m_u.setNum(0,0);var l=y.crossVec2Vec2(this.m_rA,this.m_u),u=y.crossVec2Vec2(this.m_rB,this.m_u),p=this.m_invMassA+this.m_invIA*l*l+this.m_invMassB+this.m_invIB*u*u;if(this.m_mass=0!=p?1/p:0,this.m_frequencyHz>0){var d=_-this.m_length,f=2*Fo*this.m_frequencyHz,v=2*this.m_mass*this.m_dampingRatio*f,x=this.m_mass*f*f,A=t.dt;this.m_gamma=A*(v+A*x),this.m_gamma=0!=this.m_gamma?1/this.m_gamma:0,this.m_bias=d*A*x*this.m_gamma,p+=this.m_gamma,this.m_mass=0!=p?1/p:0}else this.m_gamma=0,this.m_bias=0;if(t.warmStarting){this.m_impulse*=t.dtRatio;var b=y.mulNumVec2(this.m_impulse,this.m_u);o.subMul(this.m_invMassA,b),s-=this.m_invIA*y.crossVec2Vec2(this.m_rA,b),a.addMul(this.m_invMassB,b),m+=this.m_invIB*y.crossVec2Vec2(this.m_rB,b)}else this.m_impulse=0;this.m_bodyA.c_velocity.v.setVec2(o),this.m_bodyA.c_velocity.w=s,this.m_bodyB.c_velocity.v.setVec2(a),this.m_bodyB.c_velocity.w=m},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyA.c_velocity.v,i=this.m_bodyA.c_velocity.w,o=this.m_bodyB.c_velocity.v,s=this.m_bodyB.c_velocity.w,n=y.add(e,y.crossNumVec2(i,this.m_rA)),r=y.add(o,y.crossNumVec2(s,this.m_rB)),a=y.dot(this.m_u,r)-y.dot(this.m_u,n),m=-this.m_mass*(a+this.m_bias+this.m_gamma*this.m_impulse);this.m_impulse+=m;var h=y.mulNumVec2(m,this.m_u);e.subMul(this.m_invMassA,h),i-=this.m_invIA*y.crossVec2Vec2(this.m_rA,h),o.addMul(this.m_invMassB,h),s+=this.m_invIB*y.crossVec2Vec2(this.m_rB,h),this.m_bodyA.c_velocity.v.setVec2(e),this.m_bodyA.c_velocity.w=i,this.m_bodyB.c_velocity.v.setVec2(o),this.m_bodyB.c_velocity.w=s},e.prototype.solvePositionConstraints=function(t){if(this.m_frequencyHz>0)return!0;var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyB.c_position.c,s=this.m_bodyB.c_position.a,n=pt.neo(i),r=pt.neo(s),a=pt.mulSub(n,this.m_localAnchorA,this.m_localCenterA),m=pt.mulSub(r,this.m_localAnchorB,this.m_localCenterB),c=y.sub(y.add(o,m),y.add(e,a)),_=h(c.normalize()-this.m_length,-g.maxLinearCorrection,g.maxLinearCorrection),l=-this.m_mass*_,u=y.mulNumVec2(l,c);return e.subMul(this.m_invMassA,u),i-=this.m_invIA*y.crossVec2Vec2(a,u),o.addMul(this.m_invMassB,u),s+=this.m_invIB*y.crossVec2Vec2(m,u),this.m_bodyA.c_position.c.setVec2(e),this.m_bodyA.c_position.a=i,this.m_bodyB.c_position.c.setVec2(o),this.m_bodyB.c_position.a=s,zo(_)<g.linearSlop},e.TYPE="distance-joint",e}(Jt),No={maxForce:0,maxTorque:0},ko=function(t){function e(i,o,n,r){var a=this;return a instanceof e?(i=s(i,No),o=(a=t.call(this,i,o,n)||this).m_bodyA,n=a.m_bodyB,a.m_type=e.TYPE,a.m_localAnchorA=y.clone(r?o.getLocalPoint(r):i.localAnchorA||y.zero()),a.m_localAnchorB=y.clone(r?n.getLocalPoint(r):i.localAnchorB||y.zero()),a.m_linearImpulse=y.zero(),a.m_angularImpulse=0,a.m_maxForce=i.maxForce,a.m_maxTorque=i.maxTorque,a):new e(i,o,n,r)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,maxForce:this.m_maxForce,maxTorque:this.m_maxTorque,localAnchorA:this.m_localAnchorA,localAnchorB:this.m_localAnchorB}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),new e(t)},e.prototype._reset=function(t){t.anchorA?this.m_localAnchorA.setVec2(this.m_bodyA.getLocalPoint(t.anchorA)):t.localAnchorA&&this.m_localAnchorA.setVec2(t.localAnchorA),t.anchorB?this.m_localAnchorB.setVec2(this.m_bodyB.getLocalPoint(t.anchorB)):t.localAnchorB&&this.m_localAnchorB.setVec2(t.localAnchorB),Number.isFinite(t.maxForce)&&(this.m_maxForce=t.maxForce),Number.isFinite(t.maxTorque)&&(this.m_maxTorque=t.maxTorque)},e.prototype.getLocalAnchorA=function(){return this.m_localAnchorA},e.prototype.getLocalAnchorB=function(){return this.m_localAnchorB},e.prototype.setMaxForce=function(t){this.m_maxForce=t},e.prototype.getMaxForce=function(){return this.m_maxForce},e.prototype.setMaxTorque=function(t){this.m_maxTorque=t},e.prototype.getMaxTorque=function(){return this.m_maxTorque},e.prototype.getAnchorA=function(){return this.m_bodyA.getWorldPoint(this.m_localAnchorA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.mulNumVec2(t,this.m_linearImpulse)},e.prototype.getReactionTorque=function(t){return t*this.m_angularImpulse},e.prototype.initVelocityConstraints=function(t){this.m_localCenterA=this.m_bodyA.m_sweep.localCenter,this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_bodyA.c_position.a,i=this.m_bodyA.c_velocity.v,o=this.m_bodyA.c_velocity.w,s=this.m_bodyB.c_position.a,n=this.m_bodyB.c_velocity.v,r=this.m_bodyB.c_velocity.w,a=pt.neo(e),m=pt.neo(s);this.m_rA=pt.mulVec2(a,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=pt.mulVec2(m,y.sub(this.m_localAnchorB,this.m_localCenterB));var h=this.m_invMassA,c=this.m_invMassB,_=this.m_invIA,l=this.m_invIB,u=new oi;if(u.ex.x=h+c+_*this.m_rA.y*this.m_rA.y+l*this.m_rB.y*this.m_rB.y,u.ex.y=-_*this.m_rA.x*this.m_rA.y-l*this.m_rB.x*this.m_rB.y,u.ey.x=u.ex.y,u.ey.y=h+c+_*this.m_rA.x*this.m_rA.x+l*this.m_rB.x*this.m_rB.x,this.m_linearMass=u.getInverse(),this.m_angularMass=_+l,this.m_angularMass>0&&(this.m_angularMass=1/this.m_angularMass),t.warmStarting){this.m_linearImpulse.mul(t.dtRatio),this.m_angularImpulse*=t.dtRatio;var p=y.neo(this.m_linearImpulse.x,this.m_linearImpulse.y);i.subMul(h,p),o-=_*(y.crossVec2Vec2(this.m_rA,p)+this.m_angularImpulse),n.addMul(c,p),r+=l*(y.crossVec2Vec2(this.m_rB,p)+this.m_angularImpulse)}else this.m_linearImpulse.setZero(),this.m_angularImpulse=0;this.m_bodyA.c_velocity.v=i,this.m_bodyA.c_velocity.w=o,this.m_bodyB.c_velocity.v=n,this.m_bodyB.c_velocity.w=r},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyA.c_velocity.v,i=this.m_bodyA.c_velocity.w,o=this.m_bodyB.c_velocity.v,s=this.m_bodyB.c_velocity.w,n=this.m_invMassA,r=this.m_invMassB,a=this.m_invIA,m=this.m_invIB,c=t.dt,_=s-i,l=-this.m_angularMass*_,u=this.m_angularImpulse,p=c*this.m_maxTorque;this.m_angularImpulse=h(this.m_angularImpulse+l,-p,p),i-=a*(l=this.m_angularImpulse-u),s+=m*l;_=y.sub(y.add(o,y.crossNumVec2(s,this.m_rB)),y.add(e,y.crossNumVec2(i,this.m_rA))),l=y.neg(oi.mulVec2(this.m_linearMass,_)),u=this.m_linearImpulse;this.m_linearImpulse.add(l);p=c*this.m_maxForce;this.m_linearImpulse.lengthSquared()>p*p&&(this.m_linearImpulse.normalize(),this.m_linearImpulse.mul(p)),l=y.sub(this.m_linearImpulse,u),e.subMul(n,l),i-=a*y.crossVec2Vec2(this.m_rA,l),o.addMul(r,l),s+=m*y.crossVec2Vec2(this.m_rB,l),this.m_bodyA.c_velocity.v=e,this.m_bodyA.c_velocity.w=i,this.m_bodyB.c_velocity.v=o,this.m_bodyB.c_velocity.w=s},e.prototype.solvePositionConstraints=function(t){return!0},e.TYPE="friction-joint",e}(Jt),Do=function(){function t(t,e,i){"object"==typeof t&&null!==t?(this.ex=ro.clone(t),this.ey=ro.clone(e),this.ez=ro.clone(i)):(this.ex=ro.zero(),this.ey=ro.zero(),this.ez=ro.zero())}return t.prototype.toString=function(){return JSON.stringify(this)},t.isValid=function(t){return null!=t&&(ro.isValid(t.ex)&&ro.isValid(t.ey)&&ro.isValid(t.ez))},t.assert=function(t){},t.prototype.setZero=function(){return this.ex.setZero(),this.ey.setZero(),this.ez.setZero(),this},t.prototype.solve33=function(t){var e=this.ey.y*this.ez.z-this.ey.z*this.ez.y,i=this.ey.z*this.ez.x-this.ey.x*this.ez.z,o=this.ey.x*this.ez.y-this.ey.y*this.ez.x,s=this.ex.x*e+this.ex.y*i+this.ex.z*o;0!==s&&(s=1/s);var n=new ro;return e=this.ey.y*this.ez.z-this.ey.z*this.ez.y,i=this.ey.z*this.ez.x-this.ey.x*this.ez.z,o=this.ey.x*this.ez.y-this.ey.y*this.ez.x,n.x=s*(t.x*e+t.y*i+t.z*o),e=t.y*this.ez.z-t.z*this.ez.y,i=t.z*this.ez.x-t.x*this.ez.z,o=t.x*this.ez.y-t.y*this.ez.x,n.y=s*(this.ex.x*e+this.ex.y*i+this.ex.z*o),e=this.ey.y*t.z-this.ey.z*t.y,i=this.ey.z*t.x-this.ey.x*t.z,o=this.ey.x*t.y-this.ey.y*t.x,n.z=s*(this.ex.x*e+this.ex.y*i+this.ex.z*o),n},t.prototype.solve22=function(t){var e=this.ex.x,i=this.ey.x,o=this.ex.y,s=this.ey.y,n=e*s-i*o;0!==n&&(n=1/n);var r=y.zero();return r.x=n*(s*t.x-i*t.y),r.y=n*(e*t.y-o*t.x),r},t.prototype.getInverse22=function(t){var e=this.ex.x,i=this.ey.x,o=this.ex.y,s=this.ey.y,n=e*s-i*o;0!==n&&(n=1/n),t.ex.x=n*s,t.ey.x=-n*i,t.ex.z=0,t.ex.y=-n*o,t.ey.y=n*e,t.ey.z=0,t.ez.x=0,t.ez.y=0,t.ez.z=0},t.prototype.getSymInverse33=function(t){var e=ro.dot(this.ex,ro.cross(this.ey,this.ez));0!==e&&(e=1/e);var i=this.ex.x,o=this.ey.x,s=this.ez.x,n=this.ey.y,r=this.ez.y,a=this.ez.z;t.ex.x=e*(n*a-r*r),t.ex.y=e*(s*r-o*a),t.ex.z=e*(o*r-s*n),t.ey.x=t.ex.y,t.ey.y=e*(i*a-s*s),t.ey.z=e*(s*o-i*r),t.ez.x=t.ex.z,t.ez.y=t.ey.z,t.ez.z=e*(i*n-o*o)},t.mul=function(t,e){if(e&&"z"in e&&"y"in e&&"x"in e){var i=t.ex.x*e.x+t.ey.x*e.y+t.ez.x*e.z,o=t.ex.y*e.x+t.ey.y*e.y+t.ez.y*e.z,s=t.ex.z*e.x+t.ey.z*e.y+t.ez.z*e.z;return new ro(i,o,s)}if(e&&"y"in e&&"x"in e){i=t.ex.x*e.x+t.ey.x*e.y,o=t.ex.y*e.x+t.ey.y*e.y;return y.neo(i,o)}},t.mulVec3=function(t,e){var i=t.ex.x*e.x+t.ey.x*e.y+t.ez.x*e.z,o=t.ex.y*e.x+t.ey.y*e.y+t.ez.y*e.z,s=t.ex.z*e.x+t.ey.z*e.y+t.ez.z*e.z;return new ro(i,o,s)},t.mulVec2=function(t,e){var i=t.ex.x*e.x+t.ey.x*e.y,o=t.ex.y*e.x+t.ey.y*e.y;return y.neo(i,o)},t.add=function(e,i){return new t(ro.add(e.ex,i.ex),ro.add(e.ey,i.ey),ro.add(e.ez,i.ez))},t}(),jo=Math.abs;!function(t){t[t.inactiveLimit=0]="inactiveLimit",t[t.atLowerLimit=1]="atLowerLimit",t[t.atUpperLimit=2]="atUpperLimit",t[t.equalLimits=3]="equalLimits"}(Vo||(Vo={}));var Oo,Ro=0,Eo=0,Jo=0,Yo=0,Wo=!1,Ho=!1,Uo=function(t){function e(i,o,s,n){var r,a,m,h,c,_,l=this;return l instanceof e?(i=null!=i?i:{},o=(l=t.call(this,i,o,s)||this).m_bodyA,s=l.m_bodyB,l.m_mass=new Do,l.m_limitState=Vo.inactiveLimit,l.m_type=e.TYPE,y.isValid(n)?l.m_localAnchorA=o.getLocalPoint(n):y.isValid(i.localAnchorA)?l.m_localAnchorA=y.clone(i.localAnchorA):l.m_localAnchorA=y.zero(),y.isValid(n)?l.m_localAnchorB=s.getLocalPoint(n):y.isValid(i.localAnchorB)?l.m_localAnchorB=y.clone(i.localAnchorB):l.m_localAnchorB=y.zero(),Number.isFinite(i.referenceAngle)?l.m_referenceAngle=i.referenceAngle:l.m_referenceAngle=s.getAngle()-o.getAngle(),l.m_impulse=new ro,l.m_motorImpulse=0,l.m_lowerAngle=null!==(r=i.lowerAngle)&&void 0!==r?r:Ro,l.m_upperAngle=null!==(a=i.upperAngle)&&void 0!==a?a:Eo,l.m_maxMotorTorque=null!==(m=i.maxMotorTorque)&&void 0!==m?m:Jo,l.m_motorSpeed=null!==(h=i.motorSpeed)&&void 0!==h?h:Yo,l.m_enableLimit=null!==(c=i.enableLimit)&&void 0!==c?c:Wo,l.m_enableMotor=null!==(_=i.enableMotor)&&void 0!==_?_:Ho,l):new e(i,o,s,n)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,lowerAngle:this.m_lowerAngle,upperAngle:this.m_upperAngle,maxMotorTorque:this.m_maxMotorTorque,motorSpeed:this.m_motorSpeed,enableLimit:this.m_enableLimit,enableMotor:this.m_enableMotor,localAnchorA:this.m_localAnchorA,localAnchorB:this.m_localAnchorB,referenceAngle:this.m_referenceAngle}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),new e(t)},e.prototype._reset=function(t){t.anchorA?this.m_localAnchorA.setVec2(this.m_bodyA.getLocalPoint(t.anchorA)):t.localAnchorA&&this.m_localAnchorA.setVec2(t.localAnchorA),t.anchorB?this.m_localAnchorB.setVec2(this.m_bodyB.getLocalPoint(t.anchorB)):t.localAnchorB&&this.m_localAnchorB.setVec2(t.localAnchorB),Number.isFinite(t.referenceAngle)&&(this.m_referenceAngle=t.referenceAngle),void 0!==t.enableLimit&&(this.m_enableLimit=t.enableLimit),Number.isFinite(t.lowerAngle)&&(this.m_lowerAngle=t.lowerAngle),Number.isFinite(t.upperAngle)&&(this.m_upperAngle=t.upperAngle),Number.isFinite(t.maxMotorTorque)&&(this.m_maxMotorTorque=t.maxMotorTorque),Number.isFinite(t.motorSpeed)&&(this.m_motorSpeed=t.motorSpeed),void 0!==t.enableMotor&&(this.m_enableMotor=t.enableMotor)},e.prototype.getLocalAnchorA=function(){return this.m_localAnchorA},e.prototype.getLocalAnchorB=function(){return this.m_localAnchorB},e.prototype.getReferenceAngle=function(){return this.m_referenceAngle},e.prototype.getJointAngle=function(){var t=this.m_bodyA;return this.m_bodyB.m_sweep.a-t.m_sweep.a-this.m_referenceAngle},e.prototype.getJointSpeed=function(){var t=this.m_bodyA;return this.m_bodyB.m_angularVelocity-t.m_angularVelocity},e.prototype.isMotorEnabled=function(){return this.m_enableMotor},e.prototype.enableMotor=function(t){t!=this.m_enableMotor&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_enableMotor=t)},e.prototype.getMotorTorque=function(t){return t*this.m_motorImpulse},e.prototype.setMotorSpeed=function(t){t!=this.m_motorSpeed&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_motorSpeed=t)},e.prototype.getMotorSpeed=function(){return this.m_motorSpeed},e.prototype.setMaxMotorTorque=function(t){t!=this.m_maxMotorTorque&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_maxMotorTorque=t)},e.prototype.getMaxMotorTorque=function(){return this.m_maxMotorTorque},e.prototype.isLimitEnabled=function(){return this.m_enableLimit},e.prototype.enableLimit=function(t){t!=this.m_enableLimit&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_enableLimit=t,this.m_impulse.z=0)},e.prototype.getLowerLimit=function(){return this.m_lowerAngle},e.prototype.getUpperLimit=function(){return this.m_upperAngle},e.prototype.setLimits=function(t,e){t==this.m_lowerAngle&&e==this.m_upperAngle||(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_impulse.z=0,this.m_lowerAngle=t,this.m_upperAngle=e)},e.prototype.getAnchorA=function(){return this.m_bodyA.getWorldPoint(this.m_localAnchorA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.neo(this.m_impulse.x,this.m_impulse.y).mul(t)},e.prototype.getReactionTorque=function(t){return t*this.m_impulse.z},e.prototype.initVelocityConstraints=function(t){this.m_localCenterA=this.m_bodyA.m_sweep.localCenter,this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_bodyA.c_position.a,i=this.m_bodyA.c_velocity.v,o=this.m_bodyA.c_velocity.w,s=this.m_bodyB.c_position.a,n=this.m_bodyB.c_velocity.v,r=this.m_bodyB.c_velocity.w,a=pt.neo(e),m=pt.neo(s);this.m_rA=pt.mulVec2(a,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=pt.mulVec2(m,y.sub(this.m_localAnchorB,this.m_localCenterB));var h=this.m_invMassA,c=this.m_invMassB,_=this.m_invIA,l=this.m_invIB,u=_+l===0;if(this.m_mass.ex.x=h+c+this.m_rA.y*this.m_rA.y*_+this.m_rB.y*this.m_rB.y*l,this.m_mass.ey.x=-this.m_rA.y*this.m_rA.x*_-this.m_rB.y*this.m_rB.x*l,this.m_mass.ez.x=-this.m_rA.y*_-this.m_rB.y*l,this.m_mass.ex.y=this.m_mass.ey.x,this.m_mass.ey.y=h+c+this.m_rA.x*this.m_rA.x*_+this.m_rB.x*this.m_rB.x*l,this.m_mass.ez.y=this.m_rA.x*_+this.m_rB.x*l,this.m_mass.ex.z=this.m_mass.ez.x,this.m_mass.ey.z=this.m_mass.ez.y,this.m_mass.ez.z=_+l,this.m_motorMass=_+l,this.m_motorMass>0&&(this.m_motorMass=1/this.m_motorMass),(0==this.m_enableMotor||u)&&(this.m_motorImpulse=0),this.m_enableLimit&&0==u){var p=s-e-this.m_referenceAngle;jo(this.m_upperAngle-this.m_lowerAngle)<2*g.angularSlop?this.m_limitState=Vo.equalLimits:p<=this.m_lowerAngle?(this.m_limitState!=Vo.atLowerLimit&&(this.m_impulse.z=0),this.m_limitState=Vo.atLowerLimit):p>=this.m_upperAngle?(this.m_limitState!=Vo.atUpperLimit&&(this.m_impulse.z=0),this.m_limitState=Vo.atUpperLimit):(this.m_limitState=Vo.inactiveLimit,this.m_impulse.z=0)}else this.m_limitState=Vo.inactiveLimit;if(t.warmStarting){this.m_impulse.mul(t.dtRatio),this.m_motorImpulse*=t.dtRatio;var d=y.neo(this.m_impulse.x,this.m_impulse.y);i.subMul(h,d),o-=_*(y.crossVec2Vec2(this.m_rA,d)+this.m_motorImpulse+this.m_impulse.z),n.addMul(c,d),r+=l*(y.crossVec2Vec2(this.m_rB,d)+this.m_motorImpulse+this.m_impulse.z)}else this.m_impulse.setZero(),this.m_motorImpulse=0;this.m_bodyA.c_velocity.v=i,this.m_bodyA.c_velocity.w=o,this.m_bodyB.c_velocity.v=n,this.m_bodyB.c_velocity.w=r},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyA.c_velocity.v,i=this.m_bodyA.c_velocity.w,o=this.m_bodyB.c_velocity.v,s=this.m_bodyB.c_velocity.w,n=this.m_invMassA,r=this.m_invMassB,a=this.m_invIA,m=this.m_invIB,c=a+m===0;if(this.m_enableMotor&&this.m_limitState!=Vo.equalLimits&&0==c){var _=s-i-this.m_motorSpeed,l=-this.m_motorMass*_,u=this.m_motorImpulse,p=t.dt*this.m_maxMotorTorque;this.m_motorImpulse=h(this.m_motorImpulse+l,-p,p),i-=a*(l=this.m_motorImpulse-u),s+=m*l}if(this.m_enableLimit&&this.m_limitState!=Vo.inactiveLimit&&0==c){var d=y.zero();d.addCombine(1,o,1,y.crossNumVec2(s,this.m_rB)),d.subCombine(1,e,1,y.crossNumVec2(i,this.m_rA));var f=s-i;_=new ro(d.x,d.y,f),l=ro.neg(this.m_mass.solve33(_));if(this.m_limitState==Vo.equalLimits)this.m_impulse.add(l);else if(this.m_limitState==Vo.atLowerLimit){if(this.m_impulse.z+l.z<0){var v=y.combine(-1,d,this.m_impulse.z,y.neo(this.m_mass.ez.x,this.m_mass.ez.y)),x=this.m_mass.solve22(v);l.x=x.x,l.y=x.y,l.z=-this.m_impulse.z,this.m_impulse.x+=x.x,this.m_impulse.y+=x.y,this.m_impulse.z=0}else this.m_impulse.add(l)}else if(this.m_limitState==Vo.atUpperLimit){if(this.m_impulse.z+l.z>0){v=y.combine(-1,d,this.m_impulse.z,y.neo(this.m_mass.ez.x,this.m_mass.ez.y)),x=this.m_mass.solve22(v);l.x=x.x,l.y=x.y,l.z=-this.m_impulse.z,this.m_impulse.x+=x.x,this.m_impulse.y+=x.y,this.m_impulse.z=0}else this.m_impulse.add(l)}var A=y.neo(l.x,l.y);e.subMul(n,A),i-=a*(y.crossVec2Vec2(this.m_rA,A)+l.z),o.addMul(r,A),s+=m*(y.crossVec2Vec2(this.m_rB,A)+l.z)}else{(_=y.zero()).addCombine(1,o,1,y.crossNumVec2(s,this.m_rB)),_.subCombine(1,e,1,y.crossNumVec2(i,this.m_rA));l=this.m_mass.solve22(y.neg(_));this.m_impulse.x+=l.x,this.m_impulse.y+=l.y,e.subMul(n,l),i-=a*y.crossVec2Vec2(this.m_rA,l),o.addMul(r,l),s+=m*y.crossVec2Vec2(this.m_rB,l)}this.m_bodyA.c_velocity.v=e,this.m_bodyA.c_velocity.w=i,this.m_bodyB.c_velocity.v=o,this.m_bodyB.c_velocity.w=s},e.prototype.solvePositionConstraints=function(t){var e,i=this.m_bodyA.c_position.c,o=this.m_bodyA.c_position.a,s=this.m_bodyB.c_position.c,n=this.m_bodyB.c_position.a,r=pt.neo(o),a=pt.neo(n),m=0,c=this.m_invIA+this.m_invIB==0;if(this.m_enableLimit&&this.m_limitState!=Vo.inactiveLimit&&0==c){var _=n-o-this.m_referenceAngle,l=0;if(this.m_limitState==Vo.equalLimits){var u=h(_-this.m_lowerAngle,-g.maxAngularCorrection,g.maxAngularCorrection);l=-this.m_motorMass*u,m=jo(u)}else if(this.m_limitState==Vo.atLowerLimit){m=-(u=_-this.m_lowerAngle),u=h(u+g.angularSlop,-g.maxAngularCorrection,0),l=-this.m_motorMass*u}else if(this.m_limitState==Vo.atUpperLimit){m=u=_-this.m_upperAngle,u=h(u-g.angularSlop,0,g.maxAngularCorrection),l=-this.m_motorMass*u}o-=this.m_invIA*l,n+=this.m_invIB*l}r.setAngle(o),a.setAngle(n);var p=pt.mulVec2(r,y.sub(this.m_localAnchorA,this.m_localCenterA)),d=pt.mulVec2(a,y.sub(this.m_localAnchorB,this.m_localCenterB));(u=y.zero()).addCombine(1,s,1,d),u.subCombine(1,i,1,p),e=u.length();var f=this.m_invMassA,v=this.m_invMassB,x=this.m_invIA,A=this.m_invIB,b=new oi;b.ex.x=f+v+x*p.y*p.y+A*d.y*d.y,b.ex.y=-x*p.x*p.y-A*d.x*d.y,b.ey.x=b.ex.y,b.ey.y=f+v+x*p.x*p.x+A*d.x*d.x;var B=y.neg(b.solve(u));return i.subMul(f,B),o-=x*y.crossVec2Vec2(p,B),s.addMul(v,B),n+=A*y.crossVec2Vec2(d,B),this.m_bodyA.c_position.c.setVec2(i),this.m_bodyA.c_position.a=o,this.m_bodyB.c_position.c.setVec2(s),this.m_bodyB.c_position.a=n,e<=g.linearSlop&&m<=g.angularSlop},e.TYPE="revolute-joint",e}(Jt),Zo=Math.abs,Ko=Math.max,Xo=Math.min;!function(t){t[t.inactiveLimit=0]="inactiveLimit",t[t.atLowerLimit=1]="atLowerLimit",t[t.atUpperLimit=2]="atUpperLimit",t[t.equalLimits=3]="equalLimits"}(Oo||(Oo={}));var Go,Qo={enableLimit:!1,lowerTranslation:0,upperTranslation:0,enableMotor:!1,maxMotorForce:0,motorSpeed:0},$o=function(t){function e(i,o,n,r,a){var m=this;return m instanceof e?(i=s(i,Qo),o=(m=t.call(this,i,o,n)||this).m_bodyA,n=m.m_bodyB,m.m_type=e.TYPE,m.m_localAnchorA=y.clone(r?o.getLocalPoint(r):i.localAnchorA||y.zero()),m.m_localAnchorB=y.clone(r?n.getLocalPoint(r):i.localAnchorB||y.zero()),m.m_localXAxisA=y.clone(a?o.getLocalVector(a):i.localAxisA||y.neo(1,0)),m.m_localXAxisA.normalize(),m.m_localYAxisA=y.crossNumVec2(1,m.m_localXAxisA),m.m_referenceAngle=Number.isFinite(i.referenceAngle)?i.referenceAngle:n.getAngle()-o.getAngle(),m.m_impulse=new ro,m.m_motorMass=0,m.m_motorImpulse=0,m.m_lowerTranslation=i.lowerTranslation,m.m_upperTranslation=i.upperTranslation,m.m_maxMotorForce=i.maxMotorForce,m.m_motorSpeed=i.motorSpeed,m.m_enableLimit=i.enableLimit,m.m_enableMotor=i.enableMotor,m.m_limitState=Oo.inactiveLimit,m.m_axis=y.zero(),m.m_perp=y.zero(),m.m_K=new Do,m):new e(i,o,n,r,a)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,lowerTranslation:this.m_lowerTranslation,upperTranslation:this.m_upperTranslation,maxMotorForce:this.m_maxMotorForce,motorSpeed:this.m_motorSpeed,enableLimit:this.m_enableLimit,enableMotor:this.m_enableMotor,localAnchorA:this.m_localAnchorA,localAnchorB:this.m_localAnchorB,localAxisA:this.m_localXAxisA,referenceAngle:this.m_referenceAngle}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),t.localAxisA=y.clone(t.localAxisA),new e(t)},e.prototype._reset=function(t){t.anchorA?this.m_localAnchorA.setVec2(this.m_bodyA.getLocalPoint(t.anchorA)):t.localAnchorA&&this.m_localAnchorA.setVec2(t.localAnchorA),t.anchorB?this.m_localAnchorB.setVec2(this.m_bodyB.getLocalPoint(t.anchorB)):t.localAnchorB&&this.m_localAnchorB.setVec2(t.localAnchorB),t.localAxisA&&(this.m_localXAxisA.setVec2(t.localAxisA),this.m_localYAxisA.setVec2(y.crossNumVec2(1,t.localAxisA))),Number.isFinite(t.referenceAngle)&&(this.m_referenceAngle=t.referenceAngle),void 0!==t.enableLimit&&(this.m_enableLimit=!!t.enableLimit),Number.isFinite(t.lowerTranslation)&&(this.m_lowerTranslation=t.lowerTranslation),Number.isFinite(t.upperTranslation)&&(this.m_upperTranslation=t.upperTranslation),void 0!==t.enableMotor&&(this.m_enableMotor=!!t.enableMotor),Number.isFinite(t.maxMotorForce)&&(this.m_maxMotorForce=t.maxMotorForce),Number.isFinite(t.motorSpeed)&&(this.m_motorSpeed=t.motorSpeed)},e.prototype.getLocalAnchorA=function(){return this.m_localAnchorA},e.prototype.getLocalAnchorB=function(){return this.m_localAnchorB},e.prototype.getLocalAxisA=function(){return this.m_localXAxisA},e.prototype.getReferenceAngle=function(){return this.m_referenceAngle},e.prototype.getJointTranslation=function(){var t=this.m_bodyA.getWorldPoint(this.m_localAnchorA),e=this.m_bodyB.getWorldPoint(this.m_localAnchorB),i=y.sub(e,t),o=this.m_bodyA.getWorldVector(this.m_localXAxisA);return y.dot(i,o)},e.prototype.getJointSpeed=function(){var t=this.m_bodyA,e=this.m_bodyB,i=pt.mulVec2(t.m_xf.q,y.sub(this.m_localAnchorA,t.m_sweep.localCenter)),o=pt.mulVec2(e.m_xf.q,y.sub(this.m_localAnchorB,e.m_sweep.localCenter)),s=y.add(t.m_sweep.c,i),n=y.add(e.m_sweep.c,o),r=y.sub(n,s),a=pt.mulVec2(t.m_xf.q,this.m_localXAxisA),m=t.m_linearVelocity,h=e.m_linearVelocity,c=t.m_angularVelocity,_=e.m_angularVelocity;return y.dot(r,y.crossNumVec2(c,a))+y.dot(a,y.sub(y.addCrossNumVec2(h,_,o),y.addCrossNumVec2(m,c,i)))},e.prototype.isLimitEnabled=function(){return this.m_enableLimit},e.prototype.enableLimit=function(t){t!=this.m_enableLimit&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_enableLimit=t,this.m_impulse.z=0)},e.prototype.getLowerLimit=function(){return this.m_lowerTranslation},e.prototype.getUpperLimit=function(){return this.m_upperTranslation},e.prototype.setLimits=function(t,e){t==this.m_lowerTranslation&&e==this.m_upperTranslation||(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_lowerTranslation=t,this.m_upperTranslation=e,this.m_impulse.z=0)},e.prototype.isMotorEnabled=function(){return this.m_enableMotor},e.prototype.enableMotor=function(t){t!=this.m_enableMotor&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_enableMotor=t)},e.prototype.setMotorSpeed=function(t){t!=this.m_motorSpeed&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_motorSpeed=t)},e.prototype.setMaxMotorForce=function(t){t!=this.m_maxMotorForce&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_maxMotorForce=t)},e.prototype.getMaxMotorForce=function(){return this.m_maxMotorForce},e.prototype.getMotorSpeed=function(){return this.m_motorSpeed},e.prototype.getMotorForce=function(t){return t*this.m_motorImpulse},e.prototype.getAnchorA=function(){return this.m_bodyA.getWorldPoint(this.m_localAnchorA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.combine(this.m_impulse.x,this.m_perp,this.m_motorImpulse+this.m_impulse.z,this.m_axis).mul(t)},e.prototype.getReactionTorque=function(t){return t*this.m_impulse.y},e.prototype.initVelocityConstraints=function(t){this.m_localCenterA=this.m_bodyA.m_sweep.localCenter,this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyA.c_velocity.v,s=this.m_bodyA.c_velocity.w,n=this.m_bodyB.c_position.c,r=this.m_bodyB.c_position.a,a=this.m_bodyB.c_velocity.v,m=this.m_bodyB.c_velocity.w,h=pt.neo(i),c=pt.neo(r),_=pt.mulVec2(h,y.sub(this.m_localAnchorA,this.m_localCenterA)),l=pt.mulVec2(c,y.sub(this.m_localAnchorB,this.m_localCenterB)),u=y.zero();u.addCombine(1,n,1,l),u.subCombine(1,e,1,_);var p=this.m_invMassA,d=this.m_invMassB,f=this.m_invIA,v=this.m_invIB;this.m_axis=pt.mulVec2(h,this.m_localXAxisA),this.m_a1=y.crossVec2Vec2(y.add(u,_),this.m_axis),this.m_a2=y.crossVec2Vec2(l,this.m_axis),this.m_motorMass=p+d+f*this.m_a1*this.m_a1+v*this.m_a2*this.m_a2,this.m_motorMass>0&&(this.m_motorMass=1/this.m_motorMass),this.m_perp=pt.mulVec2(h,this.m_localYAxisA),this.m_s1=y.crossVec2Vec2(y.add(u,_),this.m_perp),this.m_s2=y.crossVec2Vec2(l,this.m_perp),y.crossVec2Vec2(_,this.m_perp);var x=p+d+f*this.m_s1*this.m_s1+v*this.m_s2*this.m_s2,A=f*this.m_s1+v*this.m_s2,b=f*this.m_s1*this.m_a1+v*this.m_s2*this.m_a2,B=f+v;0==B&&(B=1);var w=f*this.m_a1+v*this.m_a2,V=p+d+f*this.m_a1*this.m_a1+v*this.m_a2*this.m_a2;if(this.m_K.ex.set(x,A,b),this.m_K.ey.set(A,B,w),this.m_K.ez.set(b,w,V),this.m_enableLimit){var C=y.dot(this.m_axis,u);Zo(this.m_upperTranslation-this.m_lowerTranslation)<2*g.linearSlop?this.m_limitState=Oo.equalLimits:C<=this.m_lowerTranslation?this.m_limitState!=Oo.atLowerLimit&&(this.m_limitState=Oo.atLowerLimit,this.m_impulse.z=0):C>=this.m_upperTranslation?this.m_limitState!=Oo.atUpperLimit&&(this.m_limitState=Oo.atUpperLimit,this.m_impulse.z=0):(this.m_limitState=Oo.inactiveLimit,this.m_impulse.z=0)}else this.m_limitState=Oo.inactiveLimit,this.m_impulse.z=0;if(0==this.m_enableMotor&&(this.m_motorImpulse=0),t.warmStarting){this.m_impulse.mul(t.dtRatio),this.m_motorImpulse*=t.dtRatio;var M=y.combine(this.m_impulse.x,this.m_perp,this.m_motorImpulse+this.m_impulse.z,this.m_axis),I=this.m_impulse.x*this.m_s1+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a1,P=this.m_impulse.x*this.m_s2+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a2;o.subMul(p,M),s-=f*I,a.addMul(d,M),m+=v*P}else this.m_impulse.setZero(),this.m_motorImpulse=0;this.m_bodyA.c_velocity.v.setVec2(o),this.m_bodyA.c_velocity.w=s,this.m_bodyB.c_velocity.v.setVec2(a),this.m_bodyB.c_velocity.w=m},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyA.c_velocity.v,i=this.m_bodyA.c_velocity.w,o=this.m_bodyB.c_velocity.v,s=this.m_bodyB.c_velocity.w,n=this.m_invMassA,r=this.m_invMassB,a=this.m_invIA,m=this.m_invIB;if(this.m_enableMotor&&this.m_limitState!=Oo.equalLimits){var c=y.dot(this.m_axis,y.sub(o,e))+this.m_a2*s-this.m_a1*i,_=this.m_motorMass*(this.m_motorSpeed-c),l=this.m_motorImpulse,u=t.dt*this.m_maxMotorForce;this.m_motorImpulse=h(this.m_motorImpulse+_,-u,u),_=this.m_motorImpulse-l;var p=y.mulNumVec2(_,this.m_axis),d=_*this.m_a1,f=_*this.m_a2;e.subMul(n,p),i-=a*d,o.addMul(r,p),s+=m*f}var v=y.zero();if(v.x+=y.dot(this.m_perp,o)+this.m_s2*s,v.x-=y.dot(this.m_perp,e)+this.m_s1*i,v.y=s-i,this.m_enableLimit&&this.m_limitState!=Oo.inactiveLimit){var x=0;x+=y.dot(this.m_axis,o)+this.m_a2*s,x-=y.dot(this.m_axis,e)+this.m_a1*i;c=new ro(v.x,v.y,x);var A=ro.clone(this.m_impulse),g=this.m_K.solve33(ro.neg(c));this.m_impulse.add(g),this.m_limitState==Oo.atLowerLimit?this.m_impulse.z=Ko(this.m_impulse.z,0):this.m_limitState==Oo.atUpperLimit&&(this.m_impulse.z=Xo(this.m_impulse.z,0));var b=y.combine(-1,v,-(this.m_impulse.z-A.z),y.neo(this.m_K.ez.x,this.m_K.ez.y)),B=y.add(this.m_K.solve22(b),y.neo(A.x,A.y));this.m_impulse.x=B.x,this.m_impulse.y=B.y,g=ro.sub(this.m_impulse,A);p=y.combine(g.x,this.m_perp,g.z,this.m_axis),d=g.x*this.m_s1+g.y+g.z*this.m_a1,f=g.x*this.m_s2+g.y+g.z*this.m_a2;e.subMul(n,p),i-=a*d,o.addMul(r,p),s+=m*f}else{g=this.m_K.solve22(y.neg(v));this.m_impulse.x+=g.x,this.m_impulse.y+=g.y;p=y.mulNumVec2(g.x,this.m_perp),d=g.x*this.m_s1+g.y,f=g.x*this.m_s2+g.y;e.subMul(n,p),i-=a*d,o.addMul(r,p),s+=m*f}this.m_bodyA.c_velocity.v=e,this.m_bodyA.c_velocity.w=i,this.m_bodyB.c_velocity.v=o,this.m_bodyB.c_velocity.w=s},e.prototype.solvePositionConstraints=function(t){var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyB.c_position.c,s=this.m_bodyB.c_position.a,n=pt.neo(i),r=pt.neo(s),a=this.m_invMassA,m=this.m_invMassB,c=this.m_invIA,_=this.m_invIB,l=pt.mulVec2(n,y.sub(this.m_localAnchorA,this.m_localCenterA)),u=pt.mulVec2(r,y.sub(this.m_localAnchorB,this.m_localCenterB)),p=y.sub(y.add(o,u),y.add(e,l)),d=pt.mulVec2(n,this.m_localXAxisA),f=y.crossVec2Vec2(y.add(p,l),d),v=y.crossVec2Vec2(u,d),x=pt.mulVec2(n,this.m_localYAxisA),A=y.crossVec2Vec2(y.add(p,l),x),b=y.crossVec2Vec2(u,x),B=new ro,w=y.zero();w.x=y.dot(x,p),w.y=s-i-this.m_referenceAngle;var V=Zo(w.x),C=Zo(w.y),M=g.linearSlop,I=g.maxLinearCorrection,P=!1,S=0;if(this.m_enableLimit){var T=y.dot(d,p);Zo(this.m_upperTranslation-this.m_lowerTranslation)<2*M?(S=h(T,-I,I),V=Ko(V,Zo(T)),P=!0):T<=this.m_lowerTranslation?(S=h(T-this.m_lowerTranslation+M,-I,0),V=Math.max(V,this.m_lowerTranslation-T),P=!0):T>=this.m_upperTranslation&&(S=h(T-this.m_upperTranslation-M,0,I),V=Math.max(V,T-this.m_upperTranslation),P=!0)}if(P){var z=a+m+c*A*A+_*b*b,F=c*A+_*b,L=c*A*f+_*b*v;0==(D=c+_)&&(D=1);var q=c*f+_*v,N=a+m+c*f*f+_*v*v;(j=new Do).ex.set(z,F,L),j.ey.set(F,D,q),j.ez.set(L,q,N);var k=new ro;k.x=w.x,k.y=w.y,k.z=S,B=j.solve33(ro.neg(k))}else{var D,j;z=a+m+c*A*A+_*b*b,F=c*A+_*b;0==(D=c+_)&&(D=1),(j=new oi).ex.setNum(z,F),j.ey.setNum(F,D);var O=j.solve(y.neg(w));B.x=O.x,B.y=O.y,B.z=0}var R=y.combine(B.x,x,B.z,d),E=B.x*A+B.y+B.z*f,J=B.x*b+B.y+B.z*v;return e.subMul(a,R),i-=c*E,o.addMul(m,R),s+=_*J,this.m_bodyA.c_position.c=e,this.m_bodyA.c_position.a=i,this.m_bodyB.c_position.c=o,this.m_bodyB.c_position.a=s,V<=g.linearSlop&&C<=g.angularSlop},e.TYPE="prismatic-joint",e}(Jt),ts={ratio:1},es=function(t){function e(i,o,n,r,a,m){var h,c,_=this;if(!(_ instanceof e))return new e(i,o,n,r,a,m);i=s(i,ts),o=(_=t.call(this,i,o,n)||this).m_bodyA,n=_.m_bodyB,_.m_type=e.TYPE,_.m_joint1=r||i.joint1,_.m_joint2=a||i.joint2,_.m_ratio=Number.isFinite(m)?m:i.ratio,_.m_type1=_.m_joint1.getType(),_.m_type2=_.m_joint2.getType(),_.m_bodyC=_.m_joint1.getBodyA(),_.m_bodyA=_.m_joint1.getBodyB();var l=_.m_bodyA.m_xf,u=_.m_bodyA.m_sweep.a,p=_.m_bodyC.m_xf,d=_.m_bodyC.m_sweep.a;if(_.m_type1===Uo.TYPE){var f=_.m_joint1;_.m_localAnchorC=f.m_localAnchorA,_.m_localAnchorA=f.m_localAnchorB,_.m_referenceAngleA=f.m_referenceAngle,_.m_localAxisC=y.zero(),h=u-d-_.m_referenceAngleA}else{var v=_.m_joint1;_.m_localAnchorC=v.m_localAnchorA,_.m_localAnchorA=v.m_localAnchorB,_.m_referenceAngleA=v.m_referenceAngle,_.m_localAxisC=v.m_localXAxisA;var x=_.m_localAnchorC,A=pt.mulTVec2(p.q,y.add(pt.mulVec2(l.q,_.m_localAnchorA),y.sub(l.p,p.p)));h=y.dot(A,_.m_localAxisC)-y.dot(x,_.m_localAxisC)}_.m_bodyD=_.m_joint2.getBodyA(),_.m_bodyB=_.m_joint2.getBodyB();var g=_.m_bodyB.m_xf,b=_.m_bodyB.m_sweep.a,B=_.m_bodyD.m_xf,w=_.m_bodyD.m_sweep.a;if(_.m_type2===Uo.TYPE){f=_.m_joint2;_.m_localAnchorD=f.m_localAnchorA,_.m_localAnchorB=f.m_localAnchorB,_.m_referenceAngleB=f.m_referenceAngle,_.m_localAxisD=y.zero(),c=b-w-_.m_referenceAngleB}else{v=_.m_joint2;_.m_localAnchorD=v.m_localAnchorA,_.m_localAnchorB=v.m_localAnchorB,_.m_referenceAngleB=v.m_referenceAngle,_.m_localAxisD=v.m_localXAxisA;var V=_.m_localAnchorD,C=pt.mulTVec2(B.q,y.add(pt.mulVec2(g.q,_.m_localAnchorB),y.sub(g.p,B.p)));c=y.dot(C,_.m_localAxisD)-y.dot(V,_.m_localAxisD)}return _.m_constant=h+_.m_ratio*c,_.m_impulse=0,_}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,joint1:this.m_joint1,joint2:this.m_joint2,ratio:this.m_ratio}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),t.joint1=s(Jt,t.joint1,i),t.joint2=s(Jt,t.joint2,i),new e(t)},e.prototype._reset=function(t){Number.isFinite(t.ratio)&&(this.m_ratio=t.ratio)},e.prototype.getJoint1=function(){return this.m_joint1},e.prototype.getJoint2=function(){return this.m_joint2},e.prototype.setRatio=function(t){this.m_ratio=t},e.prototype.getRatio=function(){return this.m_ratio},e.prototype.getAnchorA=function(){return this.m_bodyA.getWorldPoint(this.m_localAnchorA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.mulNumVec2(this.m_impulse,this.m_JvAC).mul(t)},e.prototype.getReactionTorque=function(t){return t*(this.m_impulse*this.m_JwA)},e.prototype.initVelocityConstraints=function(t){this.m_lcA=this.m_bodyA.m_sweep.localCenter,this.m_lcB=this.m_bodyB.m_sweep.localCenter,this.m_lcC=this.m_bodyC.m_sweep.localCenter,this.m_lcD=this.m_bodyD.m_sweep.localCenter,this.m_mA=this.m_bodyA.m_invMass,this.m_mB=this.m_bodyB.m_invMass,this.m_mC=this.m_bodyC.m_invMass,this.m_mD=this.m_bodyD.m_invMass,this.m_iA=this.m_bodyA.m_invI,this.m_iB=this.m_bodyB.m_invI,this.m_iC=this.m_bodyC.m_invI,this.m_iD=this.m_bodyD.m_invI;var e=this.m_bodyA.c_position.a,i=this.m_bodyA.c_velocity.v,o=this.m_bodyA.c_velocity.w,s=this.m_bodyB.c_position.a,n=this.m_bodyB.c_velocity.v,r=this.m_bodyB.c_velocity.w,a=this.m_bodyC.c_position.a,m=this.m_bodyC.c_velocity.v,h=this.m_bodyC.c_velocity.w,c=this.m_bodyD.c_position.a,_=this.m_bodyD.c_velocity.v,l=this.m_bodyD.c_velocity.w,u=pt.neo(e),p=pt.neo(s),d=pt.neo(a),f=pt.neo(c);if(this.m_mass=0,this.m_type1==Uo.TYPE)this.m_JvAC=y.zero(),this.m_JwA=1,this.m_JwC=1,this.m_mass+=this.m_iA+this.m_iC;else{var v=pt.mulVec2(d,this.m_localAxisC),x=pt.mulSub(d,this.m_localAnchorC,this.m_lcC),A=pt.mulSub(u,this.m_localAnchorA,this.m_lcA);this.m_JvAC=v,this.m_JwC=y.crossVec2Vec2(x,v),this.m_JwA=y.crossVec2Vec2(A,v),this.m_mass+=this.m_mC+this.m_mA+this.m_iC*this.m_JwC*this.m_JwC+this.m_iA*this.m_JwA*this.m_JwA}if(this.m_type2==Uo.TYPE)this.m_JvBD=y.zero(),this.m_JwB=this.m_ratio,this.m_JwD=this.m_ratio,this.m_mass+=this.m_ratio*this.m_ratio*(this.m_iB+this.m_iD);else{v=pt.mulVec2(f,this.m_localAxisD);var g=pt.mulSub(f,this.m_localAnchorD,this.m_lcD),b=pt.mulSub(p,this.m_localAnchorB,this.m_lcB);this.m_JvBD=y.mulNumVec2(this.m_ratio,v),this.m_JwD=this.m_ratio*y.crossVec2Vec2(g,v),this.m_JwB=this.m_ratio*y.crossVec2Vec2(b,v),this.m_mass+=this.m_ratio*this.m_ratio*(this.m_mD+this.m_mB)+this.m_iD*this.m_JwD*this.m_JwD+this.m_iB*this.m_JwB*this.m_JwB}this.m_mass=this.m_mass>0?1/this.m_mass:0,t.warmStarting?(i.addMul(this.m_mA*this.m_impulse,this.m_JvAC),o+=this.m_iA*this.m_impulse*this.m_JwA,n.addMul(this.m_mB*this.m_impulse,this.m_JvBD),r+=this.m_iB*this.m_impulse*this.m_JwB,m.subMul(this.m_mC*this.m_impulse,this.m_JvAC),h-=this.m_iC*this.m_impulse*this.m_JwC,_.subMul(this.m_mD*this.m_impulse,this.m_JvBD),l-=this.m_iD*this.m_impulse*this.m_JwD):this.m_impulse=0,this.m_bodyA.c_velocity.v.setVec2(i),this.m_bodyA.c_velocity.w=o,this.m_bodyB.c_velocity.v.setVec2(n),this.m_bodyB.c_velocity.w=r,this.m_bodyC.c_velocity.v.setVec2(m),this.m_bodyC.c_velocity.w=h,this.m_bodyD.c_velocity.v.setVec2(_),this.m_bodyD.c_velocity.w=l},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyA.c_velocity.v,i=this.m_bodyA.c_velocity.w,o=this.m_bodyB.c_velocity.v,s=this.m_bodyB.c_velocity.w,n=this.m_bodyC.c_velocity.v,r=this.m_bodyC.c_velocity.w,a=this.m_bodyD.c_velocity.v,m=this.m_bodyD.c_velocity.w,h=y.dot(this.m_JvAC,e)-y.dot(this.m_JvAC,n)+y.dot(this.m_JvBD,o)-y.dot(this.m_JvBD,a);h+=this.m_JwA*i-this.m_JwC*r+(this.m_JwB*s-this.m_JwD*m);var c=-this.m_mass*h;this.m_impulse+=c,e.addMul(this.m_mA*c,this.m_JvAC),i+=this.m_iA*c*this.m_JwA,o.addMul(this.m_mB*c,this.m_JvBD),s+=this.m_iB*c*this.m_JwB,n.subMul(this.m_mC*c,this.m_JvAC),r-=this.m_iC*c*this.m_JwC,a.subMul(this.m_mD*c,this.m_JvBD),m-=this.m_iD*c*this.m_JwD,this.m_bodyA.c_velocity.v.setVec2(e),this.m_bodyA.c_velocity.w=i,this.m_bodyB.c_velocity.v.setVec2(o),this.m_bodyB.c_velocity.w=s,this.m_bodyC.c_velocity.v.setVec2(n),this.m_bodyC.c_velocity.w=r,this.m_bodyD.c_velocity.v.setVec2(a),this.m_bodyD.c_velocity.w=m},e.prototype.solvePositionConstraints=function(t){var e,i,o,s,n,r,a,m,h=this.m_bodyA.c_position.c,c=this.m_bodyA.c_position.a,_=this.m_bodyB.c_position.c,l=this.m_bodyB.c_position.a,u=this.m_bodyC.c_position.c,p=this.m_bodyC.c_position.a,d=this.m_bodyD.c_position.c,f=this.m_bodyD.c_position.a,v=pt.neo(c),x=pt.neo(l),A=pt.neo(p),b=pt.neo(f),B=0;if(this.m_type1==Uo.TYPE)o=y.zero(),n=1,a=1,B+=this.m_iA+this.m_iC,e=c-p-this.m_referenceAngleA;else{var w=pt.mulVec2(A,this.m_localAxisC),V=pt.mulSub(A,this.m_localAnchorC,this.m_lcC),C=pt.mulSub(v,this.m_localAnchorA,this.m_lcA);o=w,a=y.crossVec2Vec2(V,w),n=y.crossVec2Vec2(C,w),B+=this.m_mC+this.m_mA+this.m_iC*a*a+this.m_iA*n*n;var M=y.sub(this.m_localAnchorC,this.m_lcC),I=pt.mulTVec2(A,y.add(C,y.sub(h,u)));e=y.dot(y.sub(I,M),this.m_localAxisC)}if(this.m_type2==Uo.TYPE)s=y.zero(),r=this.m_ratio,m=this.m_ratio,B+=this.m_ratio*this.m_ratio*(this.m_iB+this.m_iD),i=l-f-this.m_referenceAngleB;else{w=pt.mulVec2(b,this.m_localAxisD);var P=pt.mulSub(b,this.m_localAnchorD,this.m_lcD),S=pt.mulSub(x,this.m_localAnchorB,this.m_lcB);s=y.mulNumVec2(this.m_ratio,w),m=this.m_ratio*y.crossVec2Vec2(P,w),r=this.m_ratio*y.crossVec2Vec2(S,w),B+=this.m_ratio*this.m_ratio*(this.m_mD+this.m_mB)+this.m_iD*m*m+this.m_iB*r*r;var T=y.sub(this.m_localAnchorD,this.m_lcD),z=pt.mulTVec2(b,y.add(S,y.sub(_,d)));i=y.dot(z,this.m_localAxisD)-y.dot(T,this.m_localAxisD)}var F=e+this.m_ratio*i-this.m_constant,L=0;return B>0&&(L=-F/B),h.addMul(this.m_mA*L,o),c+=this.m_iA*L*n,_.addMul(this.m_mB*L,s),l+=this.m_iB*L*r,u.subMul(this.m_mC*L,o),p-=this.m_iC*L*a,d.subMul(this.m_mD*L,s),f-=this.m_iD*L*m,this.m_bodyA.c_position.c.setVec2(h),this.m_bodyA.c_position.a=c,this.m_bodyB.c_position.c.setVec2(_),this.m_bodyB.c_position.a=l,this.m_bodyC.c_position.c.setVec2(u),this.m_bodyC.c_position.a=p,this.m_bodyD.c_position.c.setVec2(d),this.m_bodyD.c_position.a=f,0<g.linearSlop},e.TYPE="gear-joint",e}(Jt),is={maxForce:1,maxTorque:1,correctionFactor:.3},os=function(t){function e(i,o,n){var r=this;return r instanceof e?(i=s(i,is),o=(r=t.call(this,i,o,n)||this).m_bodyA,n=r.m_bodyB,r.m_type=e.TYPE,r.m_linearOffset=y.isValid(i.linearOffset)?y.clone(i.linearOffset):o.getLocalPoint(n.getPosition()),r.m_angularOffset=Number.isFinite(i.angularOffset)?i.angularOffset:n.getAngle()-o.getAngle(),r.m_linearImpulse=y.zero(),r.m_angularImpulse=0,r.m_maxForce=i.maxForce,r.m_maxTorque=i.maxTorque,r.m_correctionFactor=i.correctionFactor,r):new e(i,o,n)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,maxForce:this.m_maxForce,maxTorque:this.m_maxTorque,correctionFactor:this.m_correctionFactor,linearOffset:this.m_linearOffset,angularOffset:this.m_angularOffset}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),new e(t)},e.prototype._reset=function(t){Number.isFinite(t.angularOffset)&&(this.m_angularOffset=t.angularOffset),Number.isFinite(t.maxForce)&&(this.m_maxForce=t.maxForce),Number.isFinite(t.maxTorque)&&(this.m_maxTorque=t.maxTorque),Number.isFinite(t.correctionFactor)&&(this.m_correctionFactor=t.correctionFactor),y.isValid(t.linearOffset)&&this.m_linearOffset.set(t.linearOffset)},e.prototype.setMaxForce=function(t){this.m_maxForce=t},e.prototype.getMaxForce=function(){return this.m_maxForce},e.prototype.setMaxTorque=function(t){this.m_maxTorque=t},e.prototype.getMaxTorque=function(){return this.m_maxTorque},e.prototype.setCorrectionFactor=function(t){this.m_correctionFactor=t},e.prototype.getCorrectionFactor=function(){return this.m_correctionFactor},e.prototype.setLinearOffset=function(t){t.x==this.m_linearOffset.x&&t.y==this.m_linearOffset.y||(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_linearOffset.set(t))},e.prototype.getLinearOffset=function(){return this.m_linearOffset},e.prototype.setAngularOffset=function(t){t!=this.m_angularOffset&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_angularOffset=t)},e.prototype.getAngularOffset=function(){return this.m_angularOffset},e.prototype.getAnchorA=function(){return this.m_bodyA.getPosition()},e.prototype.getAnchorB=function(){return this.m_bodyB.getPosition()},e.prototype.getReactionForce=function(t){return y.mulNumVec2(t,this.m_linearImpulse)},e.prototype.getReactionTorque=function(t){return t*this.m_angularImpulse},e.prototype.initVelocityConstraints=function(t){this.m_localCenterA=this.m_bodyA.m_sweep.localCenter,this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyA.c_velocity.v,s=this.m_bodyA.c_velocity.w,n=this.m_bodyB.c_position.c,r=this.m_bodyB.c_position.a,a=this.m_bodyB.c_velocity.v,m=this.m_bodyB.c_velocity.w,h=pt.neo(i),c=pt.neo(r);this.m_rA=pt.mulVec2(h,y.sub(this.m_linearOffset,this.m_localCenterA)),this.m_rB=pt.mulVec2(c,y.neg(this.m_localCenterB));var _=this.m_invMassA,l=this.m_invMassB,u=this.m_invIA,p=this.m_invIB,d=new oi;if(d.ex.x=_+l+u*this.m_rA.y*this.m_rA.y+p*this.m_rB.y*this.m_rB.y,d.ex.y=-u*this.m_rA.x*this.m_rA.y-p*this.m_rB.x*this.m_rB.y,d.ey.x=d.ex.y,d.ey.y=_+l+u*this.m_rA.x*this.m_rA.x+p*this.m_rB.x*this.m_rB.x,this.m_linearMass=d.getInverse(),this.m_angularMass=u+p,this.m_angularMass>0&&(this.m_angularMass=1/this.m_angularMass),this.m_linearError=y.zero(),this.m_linearError.addCombine(1,n,1,this.m_rB),this.m_linearError.subCombine(1,e,1,this.m_rA),this.m_angularError=r-i-this.m_angularOffset,t.warmStarting){this.m_linearImpulse.mul(t.dtRatio),this.m_angularImpulse*=t.dtRatio;var f=y.neo(this.m_linearImpulse.x,this.m_linearImpulse.y);o.subMul(_,f),s-=u*(y.crossVec2Vec2(this.m_rA,f)+this.m_angularImpulse),a.addMul(l,f),m+=p*(y.crossVec2Vec2(this.m_rB,f)+this.m_angularImpulse)}else this.m_linearImpulse.setZero(),this.m_angularImpulse=0;this.m_bodyA.c_velocity.v=o,this.m_bodyA.c_velocity.w=s,this.m_bodyB.c_velocity.v=a,this.m_bodyB.c_velocity.w=m},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyA.c_velocity.v,i=this.m_bodyA.c_velocity.w,o=this.m_bodyB.c_velocity.v,s=this.m_bodyB.c_velocity.w,n=this.m_invMassA,r=this.m_invMassB,a=this.m_invIA,m=this.m_invIB,c=t.dt,_=t.inv_dt,l=s-i+_*this.m_correctionFactor*this.m_angularError,u=-this.m_angularMass*l,p=this.m_angularImpulse,d=c*this.m_maxTorque;this.m_angularImpulse=h(this.m_angularImpulse+u,-d,d),i-=a*(u=this.m_angularImpulse-p),s+=m*u,(l=y.zero()).addCombine(1,o,1,y.crossNumVec2(s,this.m_rB)),l.subCombine(1,e,1,y.crossNumVec2(i,this.m_rA)),l.addMul(_*this.m_correctionFactor,this.m_linearError);u=y.neg(oi.mulVec2(this.m_linearMass,l)),p=y.clone(this.m_linearImpulse);this.m_linearImpulse.add(u);d=c*this.m_maxForce;this.m_linearImpulse.clamp(d),u=y.sub(this.m_linearImpulse,p),e.subMul(n,u),i-=a*y.crossVec2Vec2(this.m_rA,u),o.addMul(r,u),s+=m*y.crossVec2Vec2(this.m_rB,u),this.m_bodyA.c_velocity.v=e,this.m_bodyA.c_velocity.w=i,this.m_bodyB.c_velocity.v=o,this.m_bodyB.c_velocity.w=s},e.prototype.solvePositionConstraints=function(t){return!0},e.TYPE="motor-joint",e}(Jt),ss=Math.PI,ns={maxForce:0,frequencyHz:5,dampingRatio:.7},rs=function(t){function e(i,o,n,r){var a=this;return a instanceof e?(i=s(i,ns),o=(a=t.call(this,i,o,n)||this).m_bodyA,n=a.m_bodyB,a.m_type=e.TYPE,y.isValid(r)?a.m_targetA=y.clone(r):y.isValid(i.target)?a.m_targetA=y.clone(i.target):a.m_targetA=y.zero(),a.m_localAnchorB=xt.mulTVec2(n.getTransform(),a.m_targetA),a.m_maxForce=i.maxForce,a.m_impulse=y.zero(),a.m_frequencyHz=i.frequencyHz,a.m_dampingRatio=i.dampingRatio,a.m_beta=0,a.m_gamma=0,a.m_rB=y.zero(),a.m_localCenterB=y.zero(),a.m_invMassB=0,a.m_invIB=0,a.m_mass=new oi,a.m_C=y.zero(),a):new e(i,o,n,r)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,target:this.m_targetA,maxForce:this.m_maxForce,frequencyHz:this.m_frequencyHz,dampingRatio:this.m_dampingRatio,_localAnchorB:this.m_localAnchorB}},e._deserialize=function(t,i,s){(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),t.target=y.clone(t.target);var n=new e(t);return t._localAnchorB&&(n.m_localAnchorB=t._localAnchorB),n},e.prototype._reset=function(t){Number.isFinite(t.maxForce)&&(this.m_maxForce=t.maxForce),Number.isFinite(t.frequencyHz)&&(this.m_frequencyHz=t.frequencyHz),Number.isFinite(t.dampingRatio)&&(this.m_dampingRatio=t.dampingRatio)},e.prototype.setTarget=function(t){y.areEqual(t,this.m_targetA)||(this.m_bodyB.setAwake(!0),this.m_targetA.set(t))},e.prototype.getTarget=function(){return this.m_targetA},e.prototype.setMaxForce=function(t){this.m_maxForce=t},e.prototype.getMaxForce=function(){return this.m_maxForce},e.prototype.setFrequency=function(t){this.m_frequencyHz=t},e.prototype.getFrequency=function(){return this.m_frequencyHz},e.prototype.setDampingRatio=function(t){this.m_dampingRatio=t},e.prototype.getDampingRatio=function(){return this.m_dampingRatio},e.prototype.getAnchorA=function(){return y.clone(this.m_targetA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.mulNumVec2(t,this.m_impulse)},e.prototype.getReactionTorque=function(t){return 0*t},e.prototype.shiftOrigin=function(t){this.m_targetA.sub(t)},e.prototype.initVelocityConstraints=function(t){this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_bodyB.c_position,i=this.m_bodyB.c_velocity,o=e.c,s=e.a,n=i.v,r=i.w,a=pt.neo(s),m=this.m_bodyB.getMass(),h=2*ss*this.m_frequencyHz,c=2*m*this.m_dampingRatio*h,_=m*(h*h),l=t.dt;this.m_gamma=l*(c+l*_),0!=this.m_gamma&&(this.m_gamma=1/this.m_gamma),this.m_beta=l*_*this.m_gamma,this.m_rB=pt.mulVec2(a,y.sub(this.m_localAnchorB,this.m_localCenterB));var u=new oi;u.ex.x=this.m_invMassB+this.m_invIB*this.m_rB.y*this.m_rB.y+this.m_gamma,u.ex.y=-this.m_invIB*this.m_rB.x*this.m_rB.y,u.ey.x=u.ex.y,u.ey.y=this.m_invMassB+this.m_invIB*this.m_rB.x*this.m_rB.x+this.m_gamma,this.m_mass=u.getInverse(),this.m_C.setVec2(o),this.m_C.addCombine(1,this.m_rB,-1,this.m_targetA),this.m_C.mul(this.m_beta),r*=.98,t.warmStarting?(this.m_impulse.mul(t.dtRatio),n.addMul(this.m_invMassB,this.m_impulse),r+=this.m_invIB*y.crossVec2Vec2(this.m_rB,this.m_impulse)):this.m_impulse.setZero(),i.v.setVec2(n),i.w=r},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyB.c_velocity,i=y.clone(e.v),o=e.w,s=y.crossNumVec2(o,this.m_rB);s.add(i),s.addCombine(1,this.m_C,this.m_gamma,this.m_impulse),s.neg();var n=oi.mulVec2(this.m_mass,s),r=y.clone(this.m_impulse);this.m_impulse.add(n);var a=t.dt*this.m_maxForce;this.m_impulse.clamp(a),n=y.sub(this.m_impulse,r),i.addMul(this.m_invMassB,n),o+=this.m_invIB*y.crossVec2Vec2(this.m_rB,n),e.v.setVec2(i),e.w=o},e.prototype.solvePositionConstraints=function(t){return!0},e.TYPE="mouse-joint",e}(Jt),as=Math.abs,ms={collideConnected:!0},hs=function(t){function e(i,o,n,r,a,m,h,c){var _=this;return _ instanceof e?(i=s(i,ms),o=(_=t.call(this,i,o,n)||this).m_bodyA,n=_.m_bodyB,_.m_type=e.TYPE,_.m_groundAnchorA=y.clone(r||(i.groundAnchorA||y.neo(-1,1))),_.m_groundAnchorB=y.clone(a||(i.groundAnchorB||y.neo(1,1))),_.m_localAnchorA=y.clone(m?o.getLocalPoint(m):i.localAnchorA||y.neo(-1,0)),_.m_localAnchorB=y.clone(h?n.getLocalPoint(h):i.localAnchorB||y.neo(1,0)),_.m_lengthA=Number.isFinite(i.lengthA)?i.lengthA:y.distance(m,r),_.m_lengthB=Number.isFinite(i.lengthB)?i.lengthB:y.distance(h,a),_.m_ratio=Number.isFinite(c)?c:i.ratio,_.m_constant=_.m_lengthA+_.m_ratio*_.m_lengthB,_.m_impulse=0,_):new e(i,o,n,r,a,m,h,c)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,groundAnchorA:this.m_groundAnchorA,groundAnchorB:this.m_groundAnchorB,localAnchorA:this.m_localAnchorA,localAnchorB:this.m_localAnchorB,lengthA:this.m_lengthA,lengthB:this.m_lengthB,ratio:this.m_ratio}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),new e(t)},e.prototype._reset=function(t){y.isValid(t.groundAnchorA)&&this.m_groundAnchorA.set(t.groundAnchorA),y.isValid(t.groundAnchorB)&&this.m_groundAnchorB.set(t.groundAnchorB),y.isValid(t.localAnchorA)?this.m_localAnchorA.set(t.localAnchorA):y.isValid(t.anchorA)&&this.m_localAnchorA.set(this.m_bodyA.getLocalPoint(t.anchorA)),y.isValid(t.localAnchorB)?this.m_localAnchorB.set(t.localAnchorB):y.isValid(t.anchorB)&&this.m_localAnchorB.set(this.m_bodyB.getLocalPoint(t.anchorB)),Number.isFinite(t.lengthA)&&(this.m_lengthA=t.lengthA),Number.isFinite(t.lengthB)&&(this.m_lengthB=t.lengthB),Number.isFinite(t.ratio)&&(this.m_ratio=t.ratio)},e.prototype.getGroundAnchorA=function(){return this.m_groundAnchorA},e.prototype.getGroundAnchorB=function(){return this.m_groundAnchorB},e.prototype.getLengthA=function(){return this.m_lengthA},e.prototype.getLengthB=function(){return this.m_lengthB},e.prototype.getRatio=function(){return this.m_ratio},e.prototype.getCurrentLengthA=function(){var t=this.m_bodyA.getWorldPoint(this.m_localAnchorA),e=this.m_groundAnchorA;return y.distance(t,e)},e.prototype.getCurrentLengthB=function(){var t=this.m_bodyB.getWorldPoint(this.m_localAnchorB),e=this.m_groundAnchorB;return y.distance(t,e)},e.prototype.shiftOrigin=function(t){this.m_groundAnchorA.sub(t),this.m_groundAnchorB.sub(t)},e.prototype.getAnchorA=function(){return this.m_bodyA.getWorldPoint(this.m_localAnchorA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.mulNumVec2(this.m_impulse,this.m_uB).mul(t)},e.prototype.getReactionTorque=function(t){return 0},e.prototype.initVelocityConstraints=function(t){this.m_localCenterA=this.m_bodyA.m_sweep.localCenter,this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyA.c_velocity.v,s=this.m_bodyA.c_velocity.w,n=this.m_bodyB.c_position.c,r=this.m_bodyB.c_position.a,a=this.m_bodyB.c_velocity.v,m=this.m_bodyB.c_velocity.w,h=pt.neo(i),c=pt.neo(r);this.m_rA=pt.mulVec2(h,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=pt.mulVec2(c,y.sub(this.m_localAnchorB,this.m_localCenterB)),this.m_uA=y.sub(y.add(e,this.m_rA),this.m_groundAnchorA),this.m_uB=y.sub(y.add(n,this.m_rB),this.m_groundAnchorB);var _=this.m_uA.length(),l=this.m_uB.length();_>10*g.linearSlop?this.m_uA.mul(1/_):this.m_uA.setZero(),l>10*g.linearSlop?this.m_uB.mul(1/l):this.m_uB.setZero();var u=y.crossVec2Vec2(this.m_rA,this.m_uA),p=y.crossVec2Vec2(this.m_rB,this.m_uB),d=this.m_invMassA+this.m_invIA*u*u,f=this.m_invMassB+this.m_invIB*p*p;if(this.m_mass=d+this.m_ratio*this.m_ratio*f,this.m_mass>0&&(this.m_mass=1/this.m_mass),t.warmStarting){this.m_impulse*=t.dtRatio;var v=y.mulNumVec2(-this.m_impulse,this.m_uA),x=y.mulNumVec2(-this.m_ratio*this.m_impulse,this.m_uB);o.addMul(this.m_invMassA,v),s+=this.m_invIA*y.crossVec2Vec2(this.m_rA,v),a.addMul(this.m_invMassB,x),m+=this.m_invIB*y.crossVec2Vec2(this.m_rB,x)}else this.m_impulse=0;this.m_bodyA.c_velocity.v=o,this.m_bodyA.c_velocity.w=s,this.m_bodyB.c_velocity.v=a,this.m_bodyB.c_velocity.w=m},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyA.c_velocity.v,i=this.m_bodyA.c_velocity.w,o=this.m_bodyB.c_velocity.v,s=this.m_bodyB.c_velocity.w,n=y.add(e,y.crossNumVec2(i,this.m_rA)),r=y.add(o,y.crossNumVec2(s,this.m_rB)),a=-y.dot(this.m_uA,n)-this.m_ratio*y.dot(this.m_uB,r),m=-this.m_mass*a;this.m_impulse+=m;var h=y.mulNumVec2(-m,this.m_uA),c=y.mulNumVec2(-this.m_ratio*m,this.m_uB);e.addMul(this.m_invMassA,h),i+=this.m_invIA*y.crossVec2Vec2(this.m_rA,h),o.addMul(this.m_invMassB,c),s+=this.m_invIB*y.crossVec2Vec2(this.m_rB,c),this.m_bodyA.c_velocity.v=e,this.m_bodyA.c_velocity.w=i,this.m_bodyB.c_velocity.v=o,this.m_bodyB.c_velocity.w=s},e.prototype.solvePositionConstraints=function(t){var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyB.c_position.c,s=this.m_bodyB.c_position.a,n=pt.neo(i),r=pt.neo(s),a=pt.mulVec2(n,y.sub(this.m_localAnchorA,this.m_localCenterA)),m=pt.mulVec2(r,y.sub(this.m_localAnchorB,this.m_localCenterB)),h=y.sub(y.add(e,this.m_rA),this.m_groundAnchorA),c=y.sub(y.add(o,this.m_rB),this.m_groundAnchorB),_=h.length(),l=c.length();_>10*g.linearSlop?h.mul(1/_):h.setZero(),l>10*g.linearSlop?c.mul(1/l):c.setZero();var u=y.crossVec2Vec2(a,h),p=y.crossVec2Vec2(m,c),d=this.m_invMassA+this.m_invIA*u*u,f=this.m_invMassB+this.m_invIB*p*p,v=d+this.m_ratio*this.m_ratio*f;v>0&&(v=1/v);var x=this.m_constant-_-this.m_ratio*l,A=as(x),b=-v*x,B=y.mulNumVec2(-b,h),w=y.mulNumVec2(-this.m_ratio*b,c);return e.addMul(this.m_invMassA,B),i+=this.m_invIA*y.crossVec2Vec2(a,B),o.addMul(this.m_invMassB,w),s+=this.m_invIB*y.crossVec2Vec2(m,w),this.m_bodyA.c_position.c=e,this.m_bodyA.c_position.a=i,this.m_bodyB.c_position.c=o,this.m_bodyB.c_position.a=s,A<g.linearSlop},e.TYPE="pulley-joint",e}(Jt),cs=Math.min;!function(t){t[t.inactiveLimit=0]="inactiveLimit",t[t.atLowerLimit=1]="atLowerLimit",t[t.atUpperLimit=2]="atUpperLimit",t[t.equalLimits=3]="equalLimits"}(Go||(Go={}));var _s,ls={maxLength:0},us=function(t){function e(i,o,n,r){var a=this;return a instanceof e?(i=s(i,ls),o=(a=t.call(this,i,o,n)||this).m_bodyA,n=a.m_bodyB,a.m_type=e.TYPE,a.m_localAnchorA=y.clone(r?o.getLocalPoint(r):i.localAnchorA||y.neo(-1,0)),a.m_localAnchorB=y.clone(r?n.getLocalPoint(r):i.localAnchorB||y.neo(1,0)),a.m_maxLength=i.maxLength,a.m_mass=0,a.m_impulse=0,a.m_length=0,a.m_state=Go.inactiveLimit,a):new e(i,o,n,r)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,localAnchorA:this.m_localAnchorA,localAnchorB:this.m_localAnchorB,maxLength:this.m_maxLength}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),new e(t)},e.prototype._reset=function(t){Number.isFinite(t.maxLength)&&(this.m_maxLength=t.maxLength)},e.prototype.getLocalAnchorA=function(){return this.m_localAnchorA},e.prototype.getLocalAnchorB=function(){return this.m_localAnchorB},e.prototype.setMaxLength=function(t){this.m_maxLength=t},e.prototype.getMaxLength=function(){return this.m_maxLength},e.prototype.getLimitState=function(){return this.m_state},e.prototype.getAnchorA=function(){return this.m_bodyA.getWorldPoint(this.m_localAnchorA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.mulNumVec2(this.m_impulse,this.m_u).mul(t)},e.prototype.getReactionTorque=function(t){return 0},e.prototype.initVelocityConstraints=function(t){this.m_localCenterA=this.m_bodyA.m_sweep.localCenter,this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyA.c_velocity.v,s=this.m_bodyA.c_velocity.w,n=this.m_bodyB.c_position.c,r=this.m_bodyB.c_position.a,a=this.m_bodyB.c_velocity.v,m=this.m_bodyB.c_velocity.w,h=pt.neo(i),c=pt.neo(r);this.m_rA=pt.mulSub(h,this.m_localAnchorA,this.m_localCenterA),this.m_rB=pt.mulSub(c,this.m_localAnchorB,this.m_localCenterB),this.m_u=y.zero(),this.m_u.addCombine(1,n,1,this.m_rB),this.m_u.subCombine(1,e,1,this.m_rA),this.m_length=this.m_u.length();var _=this.m_length-this.m_maxLength;if(this.m_state=_>0?Go.atUpperLimit:Go.inactiveLimit,!(this.m_length>g.linearSlop))return this.m_u.setZero(),this.m_mass=0,void(this.m_impulse=0);this.m_u.mul(1/this.m_length);var l=y.crossVec2Vec2(this.m_rA,this.m_u),u=y.crossVec2Vec2(this.m_rB,this.m_u),p=this.m_invMassA+this.m_invIA*l*l+this.m_invMassB+this.m_invIB*u*u;if(this.m_mass=0!=p?1/p:0,t.warmStarting){this.m_impulse*=t.dtRatio;var d=y.mulNumVec2(this.m_impulse,this.m_u);o.subMul(this.m_invMassA,d),s-=this.m_invIA*y.crossVec2Vec2(this.m_rA,d),a.addMul(this.m_invMassB,d),m+=this.m_invIB*y.crossVec2Vec2(this.m_rB,d)}else this.m_impulse=0;this.m_bodyA.c_velocity.v.setVec2(o),this.m_bodyA.c_velocity.w=s,this.m_bodyB.c_velocity.v.setVec2(a),this.m_bodyB.c_velocity.w=m},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyA.c_velocity.v,i=this.m_bodyA.c_velocity.w,o=this.m_bodyB.c_velocity.v,s=this.m_bodyB.c_velocity.w,n=y.addCrossNumVec2(e,i,this.m_rA),r=y.addCrossNumVec2(o,s,this.m_rB),a=this.m_length-this.m_maxLength,m=y.dot(this.m_u,y.sub(r,n));a<0&&(m+=t.inv_dt*a);var h=-this.m_mass*m,c=this.m_impulse;this.m_impulse=cs(0,this.m_impulse+h),h=this.m_impulse-c;var _=y.mulNumVec2(h,this.m_u);e.subMul(this.m_invMassA,_),i-=this.m_invIA*y.crossVec2Vec2(this.m_rA,_),o.addMul(this.m_invMassB,_),s+=this.m_invIB*y.crossVec2Vec2(this.m_rB,_),this.m_bodyA.c_velocity.v=e,this.m_bodyA.c_velocity.w=i,this.m_bodyB.c_velocity.v=o,this.m_bodyB.c_velocity.w=s},e.prototype.solvePositionConstraints=function(t){var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyB.c_position.c,s=this.m_bodyB.c_position.a,n=pt.neo(i),r=pt.neo(s),a=pt.mulSub(n,this.m_localAnchorA,this.m_localCenterA),m=pt.mulSub(r,this.m_localAnchorB,this.m_localCenterB),c=y.zero();c.addCombine(1,o,1,m),c.subCombine(1,e,1,a);var _=c.normalize(),l=_-this.m_maxLength;l=h(l,0,g.maxLinearCorrection);var u=-this.m_mass*l,p=y.mulNumVec2(u,c);return e.subMul(this.m_invMassA,p),i-=this.m_invIA*y.crossVec2Vec2(a,p),o.addMul(this.m_invMassB,p),s+=this.m_invIB*y.crossVec2Vec2(m,p),this.m_bodyA.c_position.c.setVec2(e),this.m_bodyA.c_position.a=i,this.m_bodyB.c_position.c.setVec2(o),this.m_bodyB.c_position.a=s,_-this.m_maxLength<g.linearSlop},e.TYPE="rope-joint",e}(Jt),ps=Math.abs,ys=Math.PI,ds={frequencyHz:0,dampingRatio:0},fs=function(t){function e(i,o,n,r){var a=this;return a instanceof e?(i=s(i,ds),o=(a=t.call(this,i,o,n)||this).m_bodyA,n=a.m_bodyB,a.m_type=e.TYPE,a.m_localAnchorA=y.clone(r?o.getLocalPoint(r):i.localAnchorA||y.zero()),a.m_localAnchorB=y.clone(r?n.getLocalPoint(r):i.localAnchorB||y.zero()),a.m_referenceAngle=Number.isFinite(i.referenceAngle)?i.referenceAngle:n.getAngle()-o.getAngle(),a.m_frequencyHz=i.frequencyHz,a.m_dampingRatio=i.dampingRatio,a.m_impulse=new ro,a.m_bias=0,a.m_gamma=0,a.m_rA,a.m_rB,a.m_localCenterA,a.m_localCenterB,a.m_invMassA,a.m_invMassB,a.m_invIA,a.m_invIB,a.m_mass=new Do,a):new e(i,o,n,r)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,frequencyHz:this.m_frequencyHz,dampingRatio:this.m_dampingRatio,localAnchorA:this.m_localAnchorA,localAnchorB:this.m_localAnchorB,referenceAngle:this.m_referenceAngle}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),new e(t)},e.prototype._reset=function(t){t.anchorA?this.m_localAnchorA.setVec2(this.m_bodyA.getLocalPoint(t.anchorA)):t.localAnchorA&&this.m_localAnchorA.setVec2(t.localAnchorA),t.anchorB?this.m_localAnchorB.setVec2(this.m_bodyB.getLocalPoint(t.anchorB)):t.localAnchorB&&this.m_localAnchorB.setVec2(t.localAnchorB),Number.isFinite(t.frequencyHz)&&(this.m_frequencyHz=t.frequencyHz),Number.isFinite(t.dampingRatio)&&(this.m_dampingRatio=t.dampingRatio)},e.prototype.getLocalAnchorA=function(){return this.m_localAnchorA},e.prototype.getLocalAnchorB=function(){return this.m_localAnchorB},e.prototype.getReferenceAngle=function(){return this.m_referenceAngle},e.prototype.setFrequency=function(t){this.m_frequencyHz=t},e.prototype.getFrequency=function(){return this.m_frequencyHz},e.prototype.setDampingRatio=function(t){this.m_dampingRatio=t},e.prototype.getDampingRatio=function(){return this.m_dampingRatio},e.prototype.getAnchorA=function(){return this.m_bodyA.getWorldPoint(this.m_localAnchorA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.neo(this.m_impulse.x,this.m_impulse.y).mul(t)},e.prototype.getReactionTorque=function(t){return t*this.m_impulse.z},e.prototype.initVelocityConstraints=function(t){this.m_localCenterA=this.m_bodyA.m_sweep.localCenter,this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_bodyA.c_position.a,i=this.m_bodyA.c_velocity.v,o=this.m_bodyA.c_velocity.w,s=this.m_bodyB.c_position.a,n=this.m_bodyB.c_velocity.v,r=this.m_bodyB.c_velocity.w,a=pt.neo(e),m=pt.neo(s);this.m_rA=pt.mulVec2(a,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=pt.mulVec2(m,y.sub(this.m_localAnchorB,this.m_localCenterB));var h=this.m_invMassA,c=this.m_invMassB,_=this.m_invIA,l=this.m_invIB,u=new Do;if(u.ex.x=h+c+this.m_rA.y*this.m_rA.y*_+this.m_rB.y*this.m_rB.y*l,u.ey.x=-this.m_rA.y*this.m_rA.x*_-this.m_rB.y*this.m_rB.x*l,u.ez.x=-this.m_rA.y*_-this.m_rB.y*l,u.ex.y=u.ey.x,u.ey.y=h+c+this.m_rA.x*this.m_rA.x*_+this.m_rB.x*this.m_rB.x*l,u.ez.y=this.m_rA.x*_+this.m_rB.x*l,u.ex.z=u.ez.x,u.ey.z=u.ez.y,u.ez.z=_+l,this.m_frequencyHz>0){u.getInverse22(this.m_mass);var p=_+l,d=p>0?1/p:0,f=s-e-this.m_referenceAngle,v=2*ys*this.m_frequencyHz,x=2*d*this.m_dampingRatio*v,A=d*v*v,g=t.dt;this.m_gamma=g*(x+g*A),this.m_gamma=0!=this.m_gamma?1/this.m_gamma:0,this.m_bias=f*g*A*this.m_gamma,p+=this.m_gamma,this.m_mass.ez.z=0!=p?1/p:0}else 0==u.ez.z?(u.getInverse22(this.m_mass),this.m_gamma=0,this.m_bias=0):(u.getSymInverse33(this.m_mass),this.m_gamma=0,this.m_bias=0);if(t.warmStarting){this.m_impulse.mul(t.dtRatio);var b=y.neo(this.m_impulse.x,this.m_impulse.y);i.subMul(h,b),o-=_*(y.crossVec2Vec2(this.m_rA,b)+this.m_impulse.z),n.addMul(c,b),r+=l*(y.crossVec2Vec2(this.m_rB,b)+this.m_impulse.z)}else this.m_impulse.setZero();this.m_bodyA.c_velocity.v=i,this.m_bodyA.c_velocity.w=o,this.m_bodyB.c_velocity.v=n,this.m_bodyB.c_velocity.w=r},e.prototype.solveVelocityConstraints=function(t){var e=this.m_bodyA.c_velocity.v,i=this.m_bodyA.c_velocity.w,o=this.m_bodyB.c_velocity.v,s=this.m_bodyB.c_velocity.w,n=this.m_invMassA,r=this.m_invMassB,a=this.m_invIA,m=this.m_invIB;if(this.m_frequencyHz>0){var h=s-i,c=-this.m_mass.ez.z*(h+this.m_bias+this.m_gamma*this.m_impulse.z);this.m_impulse.z+=c,i-=a*c,s+=m*c,(u=y.zero()).addCombine(1,o,1,y.crossNumVec2(s,this.m_rB)),u.subCombine(1,e,1,y.crossNumVec2(i,this.m_rA));var _=y.neg(Do.mulVec2(this.m_mass,u));this.m_impulse.x+=_.x,this.m_impulse.y+=_.y;var l=y.clone(_);e.subMul(n,l),i-=a*y.crossVec2Vec2(this.m_rA,l),o.addMul(r,l),s+=m*y.crossVec2Vec2(this.m_rB,l)}else{var u;(u=y.zero()).addCombine(1,o,1,y.crossNumVec2(s,this.m_rB)),u.subCombine(1,e,1,y.crossNumVec2(i,this.m_rA));h=s-i;var p=new ro(u.x,u.y,h),d=ro.neg(Do.mulVec3(this.m_mass,p));this.m_impulse.add(d);l=y.neo(d.x,d.y);e.subMul(n,l),i-=a*(y.crossVec2Vec2(this.m_rA,l)+d.z),o.addMul(r,l),s+=m*(y.crossVec2Vec2(this.m_rB,l)+d.z)}this.m_bodyA.c_velocity.v=e,this.m_bodyA.c_velocity.w=i,this.m_bodyB.c_velocity.v=o,this.m_bodyB.c_velocity.w=s},e.prototype.solvePositionConstraints=function(t){var e,i,o=this.m_bodyA.c_position.c,s=this.m_bodyA.c_position.a,n=this.m_bodyB.c_position.c,r=this.m_bodyB.c_position.a,a=pt.neo(s),m=pt.neo(r),h=this.m_invMassA,c=this.m_invMassB,_=this.m_invIA,l=this.m_invIB,u=pt.mulVec2(a,y.sub(this.m_localAnchorA,this.m_localCenterA)),p=pt.mulVec2(m,y.sub(this.m_localAnchorB,this.m_localCenterB)),d=new Do;if(d.ex.x=h+c+u.y*u.y*_+p.y*p.y*l,d.ey.x=-u.y*u.x*_-p.y*p.x*l,d.ez.x=-u.y*_-p.y*l,d.ex.y=d.ey.x,d.ey.y=h+c+u.x*u.x*_+p.x*p.x*l,d.ez.y=u.x*_+p.x*l,d.ex.z=d.ez.x,d.ey.z=d.ez.y,d.ez.z=_+l,this.m_frequencyHz>0){(v=y.zero()).addCombine(1,n,1,p),v.subCombine(1,o,1,u),e=v.length(),i=0;var f=y.neg(d.solve22(v));o.subMul(h,f),s-=_*y.crossVec2Vec2(u,f),n.addMul(c,f),r+=l*y.crossVec2Vec2(p,f)}else{var v;(v=y.zero()).addCombine(1,n,1,p),v.subCombine(1,o,1,u);var x=r-s-this.m_referenceAngle;e=v.length(),i=ps(x);var A=new ro(v.x,v.y,x),b=new ro;if(d.ez.z>0)b=ro.neg(d.solve33(A));else{var B=y.neg(d.solve22(v));b.set(B.x,B.y,0)}f=y.neo(b.x,b.y);o.subMul(h,f),s-=_*(y.crossVec2Vec2(u,f)+b.z),n.addMul(c,f),r+=l*(y.crossVec2Vec2(p,f)+b.z)}return this.m_bodyA.c_position.c=o,this.m_bodyA.c_position.a=s,this.m_bodyB.c_position.c=n,this.m_bodyB.c_position.a=r,e<=g.linearSlop&&i<=g.angularSlop},e.TYPE="weld-joint",e}(Jt),vs=Math.abs,xs=Math.PI,As={enableMotor:!1,maxMotorTorque:0,motorSpeed:0,frequencyHz:2,dampingRatio:.7},gs=function(t){function e(i,o,n,r,a){var m=this;return m instanceof e?(i=s(i,As),o=(m=t.call(this,i,o,n)||this).m_bodyA,n=m.m_bodyB,m.m_ax=y.zero(),m.m_ay=y.zero(),m.m_type=e.TYPE,m.m_localAnchorA=y.clone(r?o.getLocalPoint(r):i.localAnchorA||y.zero()),m.m_localAnchorB=y.clone(r?n.getLocalPoint(r):i.localAnchorB||y.zero()),y.isValid(a)?m.m_localXAxisA=o.getLocalVector(a):y.isValid(i.localAxisA)?m.m_localXAxisA=y.clone(i.localAxisA):y.isValid(i.localAxis)?m.m_localXAxisA=y.clone(i.localAxis):m.m_localXAxisA=y.neo(1,0),m.m_localYAxisA=y.crossNumVec2(1,m.m_localXAxisA),m.m_mass=0,m.m_impulse=0,m.m_motorMass=0,m.m_motorImpulse=0,m.m_springMass=0,m.m_springImpulse=0,m.m_maxMotorTorque=i.maxMotorTorque,m.m_motorSpeed=i.motorSpeed,m.m_enableMotor=i.enableMotor,m.m_frequencyHz=i.frequencyHz,m.m_dampingRatio=i.dampingRatio,m.m_bias=0,m.m_gamma=0,m):new e(i,o,n,r,a)}return i(e,t),e.prototype._serialize=function(){return{type:this.m_type,bodyA:this.m_bodyA,bodyB:this.m_bodyB,collideConnected:this.m_collideConnected,enableMotor:this.m_enableMotor,maxMotorTorque:this.m_maxMotorTorque,motorSpeed:this.m_motorSpeed,frequencyHz:this.m_frequencyHz,dampingRatio:this.m_dampingRatio,localAnchorA:this.m_localAnchorA,localAnchorB:this.m_localAnchorB,localAxisA:this.m_localXAxisA}},e._deserialize=function(t,i,s){return(t=o({},t)).bodyA=s(Rt,t.bodyA,i),t.bodyB=s(Rt,t.bodyB,i),new e(t)},e.prototype._reset=function(t){t.anchorA?this.m_localAnchorA.setVec2(this.m_bodyA.getLocalPoint(t.anchorA)):t.localAnchorA&&this.m_localAnchorA.setVec2(t.localAnchorA),t.anchorB?this.m_localAnchorB.setVec2(this.m_bodyB.getLocalPoint(t.anchorB)):t.localAnchorB&&this.m_localAnchorB.setVec2(t.localAnchorB),t.localAxisA&&(this.m_localXAxisA.setVec2(t.localAxisA),this.m_localYAxisA.setVec2(y.crossNumVec2(1,t.localAxisA))),void 0!==t.enableMotor&&(this.m_enableMotor=t.enableMotor),Number.isFinite(t.maxMotorTorque)&&(this.m_maxMotorTorque=t.maxMotorTorque),Number.isFinite(t.motorSpeed)&&(this.m_motorSpeed=t.motorSpeed),Number.isFinite(t.frequencyHz)&&(this.m_frequencyHz=t.frequencyHz),Number.isFinite(t.dampingRatio)&&(this.m_dampingRatio=t.dampingRatio)},e.prototype.getLocalAnchorA=function(){return this.m_localAnchorA},e.prototype.getLocalAnchorB=function(){return this.m_localAnchorB},e.prototype.getLocalAxisA=function(){return this.m_localXAxisA},e.prototype.getJointTranslation=function(){var t=this.m_bodyA,e=this.m_bodyB,i=t.getWorldPoint(this.m_localAnchorA),o=e.getWorldPoint(this.m_localAnchorB),s=y.sub(o,i),n=t.getWorldVector(this.m_localXAxisA);return y.dot(s,n)},e.prototype.getJointSpeed=function(){var t=this.m_bodyA.m_angularVelocity;return this.m_bodyB.m_angularVelocity-t},e.prototype.isMotorEnabled=function(){return this.m_enableMotor},e.prototype.enableMotor=function(t){t!=this.m_enableMotor&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_enableMotor=t)},e.prototype.setMotorSpeed=function(t){t!=this.m_motorSpeed&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_motorSpeed=t)},e.prototype.getMotorSpeed=function(){return this.m_motorSpeed},e.prototype.setMaxMotorTorque=function(t){t!=this.m_maxMotorTorque&&(this.m_bodyA.setAwake(!0),this.m_bodyB.setAwake(!0),this.m_maxMotorTorque=t)},e.prototype.getMaxMotorTorque=function(){return this.m_maxMotorTorque},e.prototype.getMotorTorque=function(t){return t*this.m_motorImpulse},e.prototype.setSpringFrequencyHz=function(t){this.m_frequencyHz=t},e.prototype.getSpringFrequencyHz=function(){return this.m_frequencyHz},e.prototype.setSpringDampingRatio=function(t){this.m_dampingRatio=t},e.prototype.getSpringDampingRatio=function(){return this.m_dampingRatio},e.prototype.getAnchorA=function(){return this.m_bodyA.getWorldPoint(this.m_localAnchorA)},e.prototype.getAnchorB=function(){return this.m_bodyB.getWorldPoint(this.m_localAnchorB)},e.prototype.getReactionForce=function(t){return y.combine(this.m_impulse,this.m_ay,this.m_springImpulse,this.m_ax).mul(t)},e.prototype.getReactionTorque=function(t){return t*this.m_motorImpulse},e.prototype.initVelocityConstraints=function(t){this.m_localCenterA=this.m_bodyA.m_sweep.localCenter,this.m_localCenterB=this.m_bodyB.m_sweep.localCenter,this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;var e=this.m_invMassA,i=this.m_invMassB,o=this.m_invIA,s=this.m_invIB,n=this.m_bodyA.c_position.c,r=this.m_bodyA.c_position.a,a=this.m_bodyA.c_velocity.v,m=this.m_bodyA.c_velocity.w,h=this.m_bodyB.c_position.c,c=this.m_bodyB.c_position.a,_=this.m_bodyB.c_velocity.v,l=this.m_bodyB.c_velocity.w,u=pt.neo(r),p=pt.neo(c),d=pt.mulVec2(u,y.sub(this.m_localAnchorA,this.m_localCenterA)),f=pt.mulVec2(p,y.sub(this.m_localAnchorB,this.m_localCenterB)),v=y.zero();if(v.addCombine(1,h,1,f),v.subCombine(1,n,1,d),this.m_ay=pt.mulVec2(u,this.m_localYAxisA),this.m_sAy=y.crossVec2Vec2(y.add(v,d),this.m_ay),this.m_sBy=y.crossVec2Vec2(f,this.m_ay),this.m_mass=e+i+o*this.m_sAy*this.m_sAy+s*this.m_sBy*this.m_sBy,this.m_mass>0&&(this.m_mass=1/this.m_mass),this.m_springMass=0,this.m_bias=0,this.m_gamma=0,this.m_frequencyHz>0){this.m_ax=pt.mulVec2(u,this.m_localXAxisA),this.m_sAx=y.crossVec2Vec2(y.add(v,d),this.m_ax),this.m_sBx=y.crossVec2Vec2(f,this.m_ax);var x=e+i+o*this.m_sAx*this.m_sAx+s*this.m_sBx*this.m_sBx;if(x>0){this.m_springMass=1/x;var A=y.dot(v,this.m_ax),g=2*xs*this.m_frequencyHz,b=2*this.m_springMass*this.m_dampingRatio*g,B=this.m_springMass*g*g,w=t.dt;this.m_gamma=w*(b+w*B),this.m_gamma>0&&(this.m_gamma=1/this.m_gamma),this.m_bias=A*w*B*this.m_gamma,this.m_springMass=x+this.m_gamma,this.m_springMass>0&&(this.m_springMass=1/this.m_springMass)}}else this.m_springImpulse=0;if(this.m_enableMotor?(this.m_motorMass=o+s,this.m_motorMass>0&&(this.m_motorMass=1/this.m_motorMass)):(this.m_motorMass=0,this.m_motorImpulse=0),t.warmStarting){this.m_impulse*=t.dtRatio,this.m_springImpulse*=t.dtRatio,this.m_motorImpulse*=t.dtRatio;var V=y.combine(this.m_impulse,this.m_ay,this.m_springImpulse,this.m_ax),C=this.m_impulse*this.m_sAy+this.m_springImpulse*this.m_sAx+this.m_motorImpulse,M=this.m_impulse*this.m_sBy+this.m_springImpulse*this.m_sBx+this.m_motorImpulse;a.subMul(this.m_invMassA,V),m-=this.m_invIA*C,_.addMul(this.m_invMassB,V),l+=this.m_invIB*M}else this.m_impulse=0,this.m_springImpulse=0,this.m_motorImpulse=0;this.m_bodyA.c_velocity.v.setVec2(a),this.m_bodyA.c_velocity.w=m,this.m_bodyB.c_velocity.v.setVec2(_),this.m_bodyB.c_velocity.w=l},e.prototype.solveVelocityConstraints=function(t){var e=this.m_invMassA,i=this.m_invMassB,o=this.m_invIA,s=this.m_invIB,n=this.m_bodyA.c_velocity.v,r=this.m_bodyA.c_velocity.w,a=this.m_bodyB.c_velocity.v,m=this.m_bodyB.c_velocity.w,c=y.dot(this.m_ax,a)-y.dot(this.m_ax,n)+this.m_sBx*m-this.m_sAx*r,_=-this.m_springMass*(c+this.m_bias+this.m_gamma*this.m_springImpulse);this.m_springImpulse+=_;var l=y.mulNumVec2(_,this.m_ax),u=_*this.m_sAx,p=_*this.m_sBx;n.subMul(e,l),r-=o*u,a.addMul(i,l);c=(m+=s*p)-r-this.m_motorSpeed,_=-this.m_motorMass*c;var d=this.m_motorImpulse,f=t.dt*this.m_maxMotorTorque;this.m_motorImpulse=h(this.m_motorImpulse+_,-f,f),r-=o*(_=this.m_motorImpulse-d),m+=s*_;c=y.dot(this.m_ay,a)-y.dot(this.m_ay,n)+this.m_sBy*m-this.m_sAy*r,_=-this.m_mass*c;this.m_impulse+=_;l=y.mulNumVec2(_,this.m_ay),u=_*this.m_sAy,p=_*this.m_sBy;n.subMul(e,l),r-=o*u,a.addMul(i,l),m+=s*p,this.m_bodyA.c_velocity.v.setVec2(n),this.m_bodyA.c_velocity.w=r,this.m_bodyB.c_velocity.v.setVec2(a),this.m_bodyB.c_velocity.w=m},e.prototype.solvePositionConstraints=function(t){var e=this.m_bodyA.c_position.c,i=this.m_bodyA.c_position.a,o=this.m_bodyB.c_position.c,s=this.m_bodyB.c_position.a,n=pt.neo(i),r=pt.neo(s),a=pt.mulVec2(n,y.sub(this.m_localAnchorA,this.m_localCenterA)),m=pt.mulVec2(r,y.sub(this.m_localAnchorB,this.m_localCenterB)),h=y.zero();h.addCombine(1,o,1,m),h.subCombine(1,e,1,a);var c=pt.mulVec2(n,this.m_localYAxisA),_=y.crossVec2Vec2(y.add(h,a),c),l=y.crossVec2Vec2(m,c),u=y.dot(h,c),p=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_sAy*this.m_sAy+this.m_invIB*this.m_sBy*this.m_sBy,d=0!=p?-u/p:0,f=y.mulNumVec2(d,c),v=d*_,x=d*l;return e.subMul(this.m_invMassA,f),i-=this.m_invIA*v,o.addMul(this.m_invMassB,f),s+=this.m_invIB*x,this.m_bodyA.c_position.c.setVec2(e),this.m_bodyA.c_position.a=i,this.m_bodyB.c_position.c.setVec2(o),this.m_bodyB.c_position.a=s,vs(u)<=g.linearSlop},e.TYPE="wheel-joint",e}(Jt),bs=0,Bs={World:no,Body:Rt,Joint:Jt,Fixture:Tt,Shape:Vt},ws={Vec2:y,Vec3:ro,World:no,Body:Rt,Joint:Jt,Fixture:Tt,Shape:Vt},Vs=((_s={})[Rt.STATIC]=Rt,_s[Rt.DYNAMIC]=Rt,_s[Rt.KINEMATIC]=Rt,_s[uo.TYPE]=uo,_s[wo.TYPE]=wo,_s[ho.TYPE]=ho,_s[So.TYPE]=So,_s[qo.TYPE]=qo,_s[ko.TYPE]=ko,_s[es.TYPE]=es,_s[os.TYPE]=os,_s[rs.TYPE]=rs,_s[$o.TYPE]=$o,_s[hs.TYPE]=hs,_s[Uo.TYPE]=Uo,_s[us.TYPE]=us,_s[fs.TYPE]=fs,_s[gs.TYPE]=gs,_s),Cs={rootClass:no,preSerialize:function(t){return t},postSerialize:function(t,e){return t},preDeserialize:function(t){return t},postDeserialize:function(t,e){return t}},Ms=function(t){var e=this;this.toJson=function(t){var i=e.options.preSerialize,o=e.options.postSerialize,s=[],n=[t],r={};function a(t,e){if(t.__sid=t.__sid||++bs,!r[t.__sid]){n.push(t);var i={refIndex:s.length+n.length,refType:e};r[t.__sid]=i}return r[t.__sid]}function m(t,e){if(void 0===e&&(e=!1),"object"!=typeof t||null===t)return t;if("function"==typeof t._serialize){if(!e)for(var s in Bs)if(t instanceof Bs[s])return a(t,s);t=function(t){var e=(t=i(t))._serialize();return o(e,t)}(t)}if(Array.isArray(t)){for(var n=[],r=0;r<t.length;r++)n[r]=m(t[r]);t=n}else{for(var r in n={},t)t.hasOwnProperty(r)&&(n[r]=m(t[r]));t=n}return t}for(;n.length;){var h=m(n.shift(),!0);s.push(h)}return s},this.fromJson=function(t){var i=e.options.preDeserialize,o=e.options.postDeserialize,s=e.options.rootClass,n={};function r(t,e,s){if(t&&t._deserialize||(t=Vs[e.type]),t&&t._deserialize){e=i(e);var n=(0,t._deserialize)(e,s,a);return n=o(n,e)}}function a(e,i,o){if(!i.refIndex||!i.refType)return r(e,i,o);var s=i;ws[s.refType]&&(e=ws[s.refType]);var a=s.refIndex;if(!n[a]){var m=r(e,t[a],o);n[a]=m}return n[a]}return r(s,t[0],null)},this.options=o(o({},Cs),t)},Is=new Ms({rootClass:no});Ms.fromJson=Is.fromJson,Ms.toJson=Is.toJson;var Ps=function(){function t(){this.width=80,this.height=60,this.x=0,this.y=-10,this.scaleY=-1,this.hz=60,this.speed=1,this.background="#222222",this.activeKeys={},this.step=function(t,e){},this.keydown=function(t,e){},this.keyup=function(t,e){},this.statusText="",this.statusMap={}}return t.mount=function(t){throw new Error("Not implemented")},t.start=function(e){var i=t.mount();return i.start(e),i},t.prototype.status=function(t,e){if(void 0!==e){var i=t,o=e;"function"!=typeof o&&"object"!=typeof o&&(this.statusMap[i]=o)}else if(t&&"object"==typeof t)for(var s in t){var n=t[s];"function"!=typeof n&&"object"!=typeof n&&(this.statusMap[s]=n)}else"string"==typeof t&&(this.statusText=t);var r=this.statusText||"";for(var a in this.statusMap){var m=this.statusMap[a];"function"!=typeof m&&(r+=(r&&"\n")+a+": "+m)}this._status(r)},t.prototype.info=function(t){this._info(t)},t.prototype.color=function(t,e,i){return"rgb("+(t=256*t|0)+", "+(e=256*e|0)+", "+(i=256*i|0)+")"},t}();function Ss(t,e){var i,o;"function"==typeof t?(i=t,o=e):"function"==typeof e?(i=e,o=t):o=null!=t?t:e;var s=Ps.mount(o);if(!i)return s;var n=i(s)||s.world;s.start(n)}var Ts=function(t){function e(i,o,s,n){var r=this;return r instanceof e?((r=t.call(this)||this)._setAsBox(i,o,s,n),r):new e(i,o,s,n)}return i(e,t),e.TYPE="polygon",e}(wo),zs=Ts;oo.addType(So.TYPE,So.TYPE,(function(t,e,i,o,s,n,r){qs(t,i.getShape(),e,n.getShape(),s)}));var Fs=q(0,0),Ls=q(0,0),qs=function(e,i,o,s,n){e.pointCount=0,at(Fs,o,i.m_p),at(Ls,n,s.m_p);var r=it(Ls,Fs),a=i.m_radius+s.m_radius;r>a*a||(e.type=t.ManifoldType.e_circles,k(e.localPoint,i.m_p),D(e.localNormal),e.pointCount=1,k(e.points[0].localPoint,s.m_p),e.points[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,0,t.ContactFeatureType.e_vertex))};oo.addType(ho.TYPE,So.TYPE,(function(t,e,i,o,s,n,r){var a=i.getShape(),m=n.getShape();Es(t,a,e,m,s)})),oo.addType(uo.TYPE,So.TYPE,(function(t,e,i,o,s,n,r){var a=i.getShape(),m=new ho;a.getChildEdge(m,o);var h=m,c=n.getShape();Es(t,h,e,c,s)}));var Ns=q(0,0),ks=q(0,0),Ds=q(0,0),js=q(0,0),Os=q(0,0),Rs=q(0,0),Es=function(e,i,o,s,n){e.pointCount=0,ht(js,n,o,s.m_p);var r=i.m_vertex1,a=i.m_vertex2;E(Ns,a,r);var m=$(Ns,a)-$(Ns,js),h=$(Ns,js)-$(Ns,r),c=i.m_radius+s.m_radius;if(h<=0){if(k(Os,r),it(js,r)>c*c)return;if(i.m_hasVertex0){var _=i.m_vertex0,l=r;if(E(ks,l,_),$(ks,l)-$(ks,js)>0)return}return e.type=t.ManifoldType.e_circles,D(e.localNormal),k(e.localPoint,Os),e.pointCount=1,k(e.points[0].localPoint,s.m_p),void e.points[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,0,t.ContactFeatureType.e_vertex)}if(m<=0){if(k(Os,a),it(js,Os)>c*c)return;if(i.m_hasVertex3){var u=i.m_vertex3,p=a;if(E(Ds,u,p),$(Ds,js)-$(Ds,p)>0)return}return e.type=t.ManifoldType.e_circles,D(e.localNormal),k(e.localPoint,Os),e.pointCount=1,k(e.points[0].localPoint,s.m_p),void e.points[0].id.setFeatures(1,t.ContactFeatureType.e_vertex,0,t.ContactFeatureType.e_vertex)}var y=tt(Ns);U(Os,m/y,r,h/y,a),it(js,Os)>c*c||(G(Rs,1,Ns),$(Rs,js)-$(Rs,r)<0&&j(Rs),K(Rs),e.type=t.ManifoldType.e_faceA,k(e.localNormal,Rs),k(e.localPoint,r),e.pointCount=1,k(e.points[0].localPoint,s.m_p),e.points[0].id.setFeatures(0,t.ContactFeatureType.e_face,0,t.ContactFeatureType.e_vertex))},Js=[new ui,new ui],Ys=[new ui,new ui],Ws=[new ui,new ui],Hs=q(0,0),Us=q(0,0),Zs=q(0,0),Ks=nt(0,0,0),Xs=q(0,0),Gs=q(0,0),Qs=q(0,0),$s=q(0,0),tn=q(0,0),en=q(0,0),on=q(0,0),sn=q(0,0);function nn(t,e,i,o,s){var n=t.m_count,r=i.m_count,a=t.m_normals,m=t.m_vertices,h=i.m_vertices;ct(Ks,o,e);for(var c=0,_=-1/0,l=0;l<n;++l){ot(Zs,Ks.q,a[l]),at(Us,Ks,m[l]);for(var u=1/0,p=0;p<r;++p){var y=$(Zs,h[p])-$(Zs,Us);y<u&&(u=y)}u>_&&(_=u,c=l)}s.maxSeparation=_,s.bestIndex=c}oo.addType(wo.TYPE,wo.TYPE,(function(t,e,i,o,s,n,r){an(t,i.getShape(),e,n.getShape(),s)}));var rn={maxSeparation:0,bestIndex:0},an=function(e,i,o,s,n){e.pointCount=0;var r=i.m_radius+s.m_radius;nn(i,o,s,n,rn);var a=rn.bestIndex,m=rn.maxSeparation;if(!(m>r)){nn(s,n,i,o,rn);var h=rn.bestIndex,c=rn.maxSeparation;if(!(c>r)){var _,l,u,p,y,d;c>m+.1*g.linearSlop?(_=s,l=i,u=n,p=o,y=h,e.type=t.ManifoldType.e_faceB,d=!0):(_=i,l=s,u=o,p=n,y=a,e.type=t.ManifoldType.e_faceA,d=!1),Js[0].recycle(),Js[1].recycle(),function(e,i,o,s,n,r){var a=i.m_normals,m=n.m_count,h=n.m_vertices,c=n.m_normals;!function(t,e,i,o){var s=e.c*o.x+e.s*o.y,n=-e.s*o.x+e.c*o.y,r=i.c*s-i.s*n,a=i.s*s+i.c*n;t.x=r,t.y=a}(sn,r.q,o.q,a[s]);for(var _=0,l=1/0,u=0;u<m;++u){var p=$(sn,c[u]);p<l&&(l=p,_=u)}var y=_,d=y+1<m?y+1:0;at(e[0].v,r,h[y]),e[0].id.setFeatures(s,t.ContactFeatureType.e_face,y,t.ContactFeatureType.e_vertex),at(e[1].v,r,h[d]),e[1].id.setFeatures(s,t.ContactFeatureType.e_face,d,t.ContactFeatureType.e_vertex)}(Js,_,u,y,l,p);var f=_.m_count,v=_.m_vertices,x=y,A=y+1<f?y+1:0;k(Xs,v[x]),k(Gs,v[A]),E(Qs,Gs,Xs),K(Qs),X($s,Qs,1),U(tn,.5,Xs,.5,Gs),ot(en,u.q,Qs),X(on,en,1),at(Xs,u,Xs),at(Gs,u,Gs);var b=$(on,Xs),B=-$(en,Xs)+r,w=$(en,Gs)+r;if(Ys[0].recycle(),Ys[1].recycle(),Ws[0].recycle(),Ws[1].recycle(),N(Hs,-en.x,-en.y),!(xi(Ys,Js,Hs,B,x)<2))if(N(Hs,en.x,en.y),!(xi(Ws,Ys,Hs,w,A)<2)){k(e.localNormal,$s),k(e.localPoint,tn);for(var V=0,C=0;C<Ws.length;++C){if($(on,Ws[C].v)-b<=r){var M=e.points[V];mt(M.localPoint,p,Ws[C].v),M.id.set(Ws[C].id),d&&M.id.swapFeatures(),++V}}e.pointCount=V}}}};oo.addType(wo.TYPE,So.TYPE,(function(t,e,i,o,s,n,r){cn(t,i.getShape(),e,n.getShape(),s)}));var mn=q(0,0),hn=q(0,0),cn=function(e,i,o,s,n){e.pointCount=0,ht(mn,n,o,s.m_p);for(var a=0,m=-1/0,h=i.m_radius+s.m_radius,c=i.m_count,_=i.m_vertices,l=i.m_normals,u=0;u<c;++u){var p=$(l[u],mn)-$(l[u],_[u]);if(p>h)return;p>m&&(m=p,a=u)}var y=a,d=y+1<c?y+1:0,f=_[y],v=_[d];if(m<r)return e.pointCount=1,e.type=t.ManifoldType.e_faceA,k(e.localNormal,l[a]),U(e.localPoint,.5,f,.5,v),k(e.points[0].localPoint,s.m_p),void e.points[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,0,t.ContactFeatureType.e_vertex);var x=$(mn,v)-$(mn,f)-$(f,v)+$(f,f),A=$(mn,f)-$(mn,v)-$(v,f)+$(v,v);if(x<=0){if(it(mn,f)>h*h)return;e.pointCount=1,e.type=t.ManifoldType.e_faceA,E(e.localNormal,mn,f),K(e.localNormal),k(e.localPoint,f),k(e.points[0].localPoint,s.m_p),e.points[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,0,t.ContactFeatureType.e_vertex)}else if(A<=0){if(it(mn,v)>h*h)return;e.pointCount=1,e.type=t.ManifoldType.e_faceA,E(e.localNormal,mn,v),K(e.localNormal),k(e.localPoint,v),k(e.points[0].localPoint,s.m_p),e.points[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,0,t.ContactFeatureType.e_vertex)}else{if(U(hn,.5,f,.5,v),$(mn,l[y])-$(hn,l[y])>h)return;e.pointCount=1,e.type=t.ManifoldType.e_faceA,k(e.localNormal,l[y]),k(e.localPoint,hn),k(e.points[0].localPoint,s.m_p),e.points[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,0,t.ContactFeatureType.e_vertex)}},_n=Math.min;oo.addType(ho.TYPE,wo.TYPE,(function(t,e,i,o,s,n,r){Dn(t,i.getShape(),e,n.getShape(),s)})),oo.addType(uo.TYPE,wo.TYPE,(function(t,e,i,o,s,n,r){i.getShape().getChildEdge(pn,o),Dn(t,pn,e,n.getShape(),s)}));var ln,un,pn=new ho;!function(t){t[t.e_unknown=-1]="e_unknown",t[t.e_edgeA=1]="e_edgeA",t[t.e_edgeB=2]="e_edgeB"}(ln||(ln={})),function(t){t[t.e_isolated=0]="e_isolated",t[t.e_concave=1]="e_concave",t[t.e_convex=2]="e_convex"}(un||(un={}));var yn=function(){},dn=function(){this.vertices=[],this.normals=[],this.count=0;for(var t=0;t<g.maxPolygonVertices;t++)this.vertices.push(q(0,0)),this.normals.push(q(0,0))},fn=function(){function t(){this.v1=q(0,0),this.v2=q(0,0),this.normal=q(0,0),this.sideNormal1=q(0,0),this.sideNormal2=q(0,0)}return t.prototype.recycle=function(){D(this.v1),D(this.v2),D(this.normal),D(this.sideNormal1),D(this.sideNormal2)},t}(),vn=[new ui,new ui],xn=[new ui,new ui],An=[new ui,new ui],gn=new yn,bn=new yn,Bn=new dn,wn=new fn,Vn=q(0,0),Cn=q(0,0),Mn=q(0,0),In=q(0,0),Pn=nt(0,0,0),Sn=q(0,0),Tn=q(0,0),zn=q(0,0),Fn=q(0,0),Ln=q(0,0),qn=q(0,0),Nn=q(0,0),kn=q(0,0),Dn=function(e,i,o,s,n){ct(Pn,o,n),at(Vn,Pn,s.m_centroid);var r=i.m_vertex0,a=i.m_vertex1,m=i.m_vertex2,h=i.m_vertex3,c=i.m_hasVertex0,_=i.m_hasVertex3;E(Mn,m,a),K(Mn),N(zn,Mn.y,-Mn.x);var l,u=$(zn,Vn)-$(zn,a),p=0,d=0,f=!1,v=!1;D(Tn),D(Fn),c&&(E(Cn,a,r),K(Cn),N(Tn,Cn.y,-Cn.x),f=Q(Cn,Mn)>=0,p=y.dot(Tn,Vn)-y.dot(Tn,r)),_&&(E(In,h,m),K(In),N(Fn,In.y,-In.x),v=y.crossVec2Vec2(Mn,In)>0,d=y.dot(Fn,Vn)-y.dot(Fn,m)),D(Sn),D(Ln),D(qn),c&&_?f&&v?(l=p>=0||u>=0||d>=0)?(k(Sn,zn),k(Ln,Tn),k(qn,Fn)):(Y(Sn,-1,zn),Y(Ln,-1,zn),Y(qn,-1,zn)):f?(l=p>=0||u>=0&&d>=0)?(k(Sn,zn),k(Ln,Tn),k(qn,zn)):(Y(Sn,-1,zn),Y(Ln,-1,Fn),Y(qn,-1,zn)):v?(l=d>=0||p>=0&&u>=0)?(k(Sn,zn),k(Ln,zn),k(qn,Fn)):(Y(Sn,-1,zn),Y(Ln,-1,zn),Y(qn,-1,Tn)):(l=p>=0&&u>=0&&d>=0)?(k(Sn,zn),k(Ln,zn),k(qn,zn)):(Y(Sn,-1,zn),Y(Ln,-1,Fn),Y(qn,-1,Tn)):c?f?(l=p>=0||u>=0)?(k(Sn,zn),k(Ln,Tn),Y(qn,-1,zn)):(Y(Sn,-1,zn),k(Ln,zn),Y(qn,-1,zn)):(l=p>=0&&u>=0)?(k(Sn,zn),k(Ln,zn),Y(qn,-1,zn)):(Y(Sn,-1,zn),k(Ln,zn),Y(qn,-1,Tn)):_?v?(l=u>=0||d>=0)?(k(Sn,zn),Y(Ln,-1,zn),k(qn,Fn)):(Y(Sn,-1,zn),Y(Ln,-1,zn),k(qn,zn)):(l=u>=0&&d>=0)?(k(Sn,zn),Y(Ln,-1,zn),k(qn,zn)):(Y(Sn,-1,zn),Y(Ln,-1,Fn),k(qn,zn)):(l=u>=0)?(k(Sn,zn),Y(Ln,-1,zn),Y(qn,-1,zn)):(Y(Sn,-1,zn),k(Ln,zn),k(qn,zn)),Bn.count=s.m_count;for(var x=0;x<s.m_count;++x)at(Bn.vertices[x],Pn,s.m_vertices[x]),ot(Bn.normals[x],Pn.q,s.m_normals[x]);var A=s.m_radius+i.m_radius;e.pointCount=0,gn.type=ln.e_edgeA,gn.index=l?0:1,gn.separation=1/0;for(x=0;x<Bn.count;++x){var b=Bn.vertices[x];(B=$(Sn,b)-$(Sn,a))<gn.separation&&(gn.separation=B)}if(gn.type!=ln.e_unknown&&!(gn.separation>A)){bn.type=ln.e_unknown,bn.index=-1,bn.separation=-1/0,N(Nn,-Sn.y,Sn.x);for(x=0;x<Bn.count;++x){Y(kn,-1,Bn.normals[x]);var B,w=$(kn,Bn.vertices[x])-$(kn,a),V=$(kn,Bn.vertices[x])-$(kn,m);if((B=_n(w,V))>A){bn.type=ln.e_edgeB,bn.index=x,bn.separation=B;break}if($(kn,Nn)>=0){if($(kn,Sn)-$(qn,Sn)<-g.angularSlop)continue}else if($(kn,Sn)-$(Ln,Sn)<-g.angularSlop)continue;B>bn.separation&&(bn.type=ln.e_edgeB,bn.index=x,bn.separation=B)}if(!(bn.type!=ln.e_unknown&&bn.separation>A)){var C;if(C=bn.type==ln.e_unknown?gn:bn.separation>.98*gn.separation+.001?bn:gn,An[0].recycle(),An[1].recycle(),C.type==ln.e_edgeA){e.type=t.ManifoldType.e_faceA;var M=0,I=$(Sn,Bn.normals[0]);for(x=1;x<Bn.count;++x){var P=$(Sn,Bn.normals[x]);P<I&&(I=P,M=x)}var S=M,T=S+1<Bn.count?S+1:0;k(An[0].v,Bn.vertices[S]),An[0].id.setFeatures(0,t.ContactFeatureType.e_face,S,t.ContactFeatureType.e_vertex),k(An[1].v,Bn.vertices[T]),An[1].id.setFeatures(0,t.ContactFeatureType.e_face,T,t.ContactFeatureType.e_vertex),l?(wn.i1=0,wn.i2=1,k(wn.v1,a),k(wn.v2,m),k(wn.normal,zn)):(wn.i1=1,wn.i2=0,k(wn.v1,m),k(wn.v2,a),Y(wn.normal,-1,zn))}else e.type=t.ManifoldType.e_faceB,k(An[0].v,a),An[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,C.index,t.ContactFeatureType.e_face),k(An[1].v,m),An[1].id.setFeatures(0,t.ContactFeatureType.e_vertex,C.index,t.ContactFeatureType.e_face),wn.i1=C.index,wn.i2=wn.i1+1<Bn.count?wn.i1+1:0,k(wn.v1,Bn.vertices[wn.i1]),k(wn.v2,Bn.vertices[wn.i2]),k(wn.normal,Bn.normals[wn.i1]);if(N(wn.sideNormal1,wn.normal.y,-wn.normal.x),N(wn.sideNormal2,-wn.sideNormal1.x,-wn.sideNormal1.y),wn.sideOffset1=$(wn.sideNormal1,wn.v1),wn.sideOffset2=$(wn.sideNormal2,wn.v2),vn[0].recycle(),vn[1].recycle(),xn[0].recycle(),xn[1].recycle(),!(xi(vn,An,wn.sideNormal1,wn.sideOffset1,wn.i1)<g.maxManifoldPoints))if(!(xi(xn,vn,wn.sideNormal2,wn.sideOffset2,wn.i2)<g.maxManifoldPoints)){C.type==ln.e_edgeA?(k(e.localNormal,wn.normal),k(e.localPoint,wn.v1)):(k(e.localNormal,s.m_normals[wn.i1]),k(e.localPoint,s.m_vertices[wn.i1]));var z=0;for(x=0;x<g.maxManifoldPoints;++x){if($(wn.normal,xn[x].v)-$(wn.normal,wn.v1)<=A){var F=e.points[z];C.type==ln.e_edgeA?(mt(F.localPoint,Pn,xn[x].v),F.id.set(xn[x].id)):(k(F.localPoint,xn[x].v),F.id.set(xn[x].id),F.id.swapFeatures()),++z}}e.pointCount=z}}}},jn={CollidePolygons:an,Settings:g,Sweep:vt,Manifold:pi,Distance:se,TimeOfImpact:ke,DynamicTree:M,stats:Yt},On=Object.freeze({__proto__:null,Math:c,Serializer:Ms,Testbed:Ps,testbed:Ss,Vec2:y,Vec3:ro,Mat22:oi,Mat33:Do,Transform:xt,Rot:pt,AABB:v,Shape:Vt,FixtureProxy:St,Fixture:Tt,Body:Rt,ContactEdge:Ci,mixFriction:Mi,mixRestitution:Ii,VelocityConstraintPoint:Si,Contact:oo,JointEdge:Et,Joint:Jt,World:no,CircleShape:So,Circle:To,EdgeShape:ho,Edge:co,PolygonShape:wo,Polygon:Co,ChainShape:uo,Chain:po,BoxShape:Ts,Box:zs,CollideCircles:qs,CollideEdgeCircle:Es,CollidePolygons:an,CollidePolygonCircle:cn,CollideEdgePolygon:Dn,DistanceJoint:qo,FrictionJoint:ko,GearJoint:es,MotorJoint:os,MouseJoint:rs,PrismaticJoint:$o,PulleyJoint:hs,RevoluteJoint:Uo,RopeJoint:us,WeldJoint:fs,WheelJoint:gs,Settings:A,SettingsInternal:g,Sweep:vt,get ManifoldType(){return t.ManifoldType},get ContactFeatureType(){return t.ContactFeatureType},get PointState(){return t.PointState},ClipVertex:ui,Manifold:pi,ManifoldPoint:yi,ContactID:di,WorldManifold:fi,getPointStates:vi,clipSegmentToLine:xi,DistanceInput:ee,DistanceOutput:ie,SimplexCache:oe,Distance:se,DistanceProxy:ne,testOverlap:pe,ShapeCastInput:de,ShapeCastOutput:fe,ShapeCast:ve,TOIInput:ge,get TOIOutputState(){return t.TOIOutputState},TOIOutput:be,TimeOfImpact:ke,TreeNode:V,DynamicTree:M,stats:Yt,internal:jn});t.AABB=v,t.Body=Rt,t.Box=zs,t.BoxShape=Ts,t.Chain=po,t.ChainShape=uo,t.Circle=To,t.CircleShape=So,t.ClipVertex=ui,t.CollideCircles=qs,t.CollideEdgeCircle=Es,t.CollideEdgePolygon=Dn,t.CollidePolygonCircle=cn,t.CollidePolygons=an,t.Contact=oo,t.ContactEdge=Ci,t.ContactID=di,t.Distance=se,t.DistanceInput=ee,t.DistanceJoint=qo,t.DistanceOutput=ie,t.DistanceProxy=ne,t.DynamicTree=M,t.Edge=co,t.EdgeShape=ho,t.Fixture=Tt,t.FixtureProxy=St,t.FrictionJoint=ko,t.GearJoint=es,t.Joint=Jt,t.JointEdge=Et,t.Manifold=pi,t.ManifoldPoint=yi,t.Mat22=oi,t.Mat33=Do,t.Math=c,t.MotorJoint=os,t.MouseJoint=rs,t.Polygon=Co,t.PolygonShape=wo,t.PrismaticJoint=$o,t.PulleyJoint=hs,t.RevoluteJoint=Uo,t.RopeJoint=us,t.Rot=pt,t.Serializer=Ms,t.Settings=A,t.SettingsInternal=g,t.Shape=Vt,t.ShapeCast=ve,t.ShapeCastInput=de,t.ShapeCastOutput=fe,t.SimplexCache=oe,t.Sweep=vt,t.TOIInput=ge,t.TOIOutput=be,t.Testbed=Ps,t.TimeOfImpact=ke,t.Transform=xt,t.TreeNode=V,t.Vec2=y,t.Vec3=ro,t.VelocityConstraintPoint=Si,t.WeldJoint=fs,t.WheelJoint=gs,t.World=no,t.WorldManifold=fi,t.clipSegmentToLine=xi,t.default=On,t.getPointStates=vi,t.internal=jn,t.mixFriction=Mi,t.mixRestitution=Ii,t.stats=Yt,t.testOverlap=pe,t.testbed=Ss,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=planck.min.js.map