-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanck.min.js
39 lines (37 loc) · 205 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.0-beta.16
* @license The MIT license
* @copyright Copyright (c) 2021 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)return;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 k(t,e,i){return t.x=e,t.y=i,t}function N(t,e){return t.x=e.x,t.y=e.y,t}function j(t){return t.x=0,t.y=0,t}function D(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){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 K(t,e,i){var o=i*e.y,s=-i*e.x;return t.x=o,t.y=s,t}function X(t,e,i){var o=-e*i.y,s=e*i.x;return t.x=o,t.y=s,t}function G(t,e){return t.x*e.y-t.y*e.x}function Q(t,e){return t.x*e.x+t.y*e.y}function $(t){return t.x*t.x+t.y*t.y}function tt(t,e){var i=t.x-e.x,o=t.y-e.y;return L(i*i+o*o)}function et(t,e){var i=t.x-e.x,o=t.y-e.y;return i*i+o*o}function it(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 ot(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 st(t,e,i){return{p:q(t,e),q:(o=i,{s:z(o),c:F(o)})};var o}function nt(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 rt(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 at(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 mt(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 ht(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 ct=Math.sin,_t=Math.cos,lt=Math.atan2,ut=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=ct(t),this.c=_t(t))},t.prototype.setRot=function(t){this.s=t.s,this.c=t.c},t.prototype.setAngle=function(t){this.s=ct(t),this.c=_t(t)},t.prototype.getAngle=function(){return lt(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}(),pt=Math.atan2,yt=Math.PI,dt=q(0,0),ft=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(){j(this.localCenter),j(this.c),this.a=0,this.alpha0=0,j(this.c0),this.a0=0},t.prototype.setTransform=function(t){rt(dt,t,this.localCenter),N(this.c,dt),N(this.c0,dt),this.a=this.a0=pt(t.q.s,t.q.c)},t.prototype.setLocalCenter=function(t,e){N(this.localCenter,t),rt(dt,e,this.localCenter),N(this.c,dt),N(this.c0,dt)},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,it(dt,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,N(this.c0,this.c)},t.prototype.normalize=function(){var t=m(this.a0,-yt,+yt);this.a-=this.a0-t,this.a0=t},t.prototype.set=function(t){N(this.localCenter,t.localCenter),N(this.c,t.c),this.a=t.a,this.alpha0=t.alpha0,N(this.c0,t.c0),this.a0=t.a0},t}(),vt=function(){function t(e,i){if(!(this instanceof t))return new t(e,i);this.p=y.zero(),this.q=ut.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=ut.clone(e.q),i},t.neo=function(e,i){var o=Object.create(t.prototype);return o.p=y.clone(e),o.q=ut.clone(i),o},t.identity=function(){var e=Object.create(t.prototype);return e.p=y.zero(),e.q=ut.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)&&ut.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=ut.mulRot(e.q,i.q),o.p=y.add(ut.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(ut.mulTRot(e.q,i.q)),o.p.setVec2(ut.mulTVec2(e.q,y.sub(i.p,e.p))),o},t}(),xt=function(){this.v=y.zero(),this.w=0},At=Math.sin,gt=Math.cos,bt=function(){function t(){this.c=y.zero(),this.a=0}return t.prototype.getTransform=function(t,e){return t.q.c=gt(this.a),t.q.s=At(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 Bt(t,e,i,o){return t.q.c=gt(o),t.q.s=At(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 wt=function(){function t(){}return t.isValid=function(t){return null!=t&&("string"==typeof t.m_type&&"number"==typeof t.m_radius)},t}(),Vt=new v,Ct=new v,Mt=q(0,0),It={userData:null,friction:.2,restitution:0,density:0,isSensor:!1,filterGroupIndex:0,filterCategoryBits:1,filterMaskBits:65535},Pt=function(t,e){this.aabb=new v,this.fixture=t,this.childIndex=e,this.proxyId},St=function(){function t(t,e,i){e.shape?(i=e,e=e.shape):"number"==typeof i&&(i={density:i}),i=s(i,It),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 Pt(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 Pt(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(wt,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(Vt,e,s.childIndex),this.m_shape.computeAABB(Ct,i,s.childIndex),s.aabb.combine(Vt,Ct),E(Mt,i.p,e.p),t.moveProxy(s.proxyId,s.aabb,Mt)}},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}(),Tt="static",zt="kinematic",Ft="dynamic",Lt=q(0,0),qt=q(0,0),kt=q(0,0),Nt=q(0,0),jt=st(0,0,0),Dt={type:Tt,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},Ot=function(){function t(t,e){e=s(e,Dt),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==Ft?(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=vt.identity(),this.m_xf.p.setVec2(e.position),this.m_xf.q.setAngle(e.angle),this.m_sweep=new ft,this.m_sweep.setTransform(this.m_xf),this.c_velocity=new xt,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(St,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==Tt},t.prototype.isDynamic=function(){return this.m_type==Ft},t.prototype.isKinematic=function(){return this.m_type==zt},t.prototype.setStatic=function(){return this.setType(Tt),this},t.prototype.setDynamic=function(){return this.setType(Ft),this},t.prototype.setKinematic=function(){return this.setType(zt),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==Tt&&(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),N(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!=Tt&&(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!=Tt&&(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(),N(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,j(this.m_sweep.localCenter),this.isStatic()||this.isKinematic())return N(this.m_sweep.c0,this.m_xf.p),N(this.m_sweep.c,this.m_xf.p),void(this.m_sweep.a0=this.m_sweep.a);j(qt);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(qt,e.mass,e.center),this.m_I+=e.I}this.m_mass>0?(this.m_invMass=1/this.m_mass,Y(qt,this.m_invMass,qt)):(this.m_mass=1,this.m_invMass=1),this.m_I>0&&0==this.m_fixedRotationFlag?(this.m_I-=this.m_mass*Q(qt,qt),this.m_invI=1/this.m_I):(this.m_I=0,this.m_invI=0),N(Lt,this.m_sweep.c),this.m_sweep.setLocalCenter(qt,this.m_xf),E(kt,this.m_sweep.c,Lt),X(Nt,this.m_angularVelocity,kt),O(this.m_linearVelocity,Nt)},t.prototype.setMassData=function(t){1!=this.isWorldLocked()&&this.m_type==Ft&&(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*Q(t.center,t.center),this.m_invI=1/this.m_I),N(Lt,this.m_sweep.c),this.m_sweep.setLocalCenter(t.center,this.m_xf),E(kt,this.m_sweep.c,Lt),X(Nt,this.m_angularVelocity,kt),O(this.m_linearVelocity,Nt))},t.prototype.applyForce=function(t,e,i){void 0===i&&(i=!0),this.m_type==Ft&&(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==Ft&&(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==Ft&&(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==Ft&&(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==Ft&&(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!=Ft&&t.m_type!=Ft)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 St(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 vt.mulVec2(this.m_xf,t)},t.prototype.getWorldVector=function(t){return ut.mulVec2(this.m_xf.q,t)},t.prototype.getLocalPoint=function(t){return vt.mulTVec2(this.m_xf,t)},t.prototype.getLocalVector=function(t){return ut.mulTVec2(this.m_xf.q,t)},t.STATIC="static",t.KINEMATIC="kinematic",t.DYNAMIC="dynamic",t}(),Rt=function(){this.other=null,this.joint=null,this.prev=null,this.next=null},Et=function(){function t(t,e,i){this.m_type="unknown-joint",this.m_prev=null,this.m_next=null,this.m_edgeA=new Rt,this.m_edgeB=new Rt,this.m_islandFlag=!1,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}(),Jt={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}},Yt=function(){return Date.now()},Wt=function(t){return Date.now()-t},Ht=Math.max,Ut=q(0,0),Zt=q(0,0),Kt=q(0,0),Xt=q(0,0),Gt=q(0,0),Qt=q(0,0),$t=q(0,0);Jt.gjkCalls=0,Jt.gjkIters=0,Jt.gjkMaxIters=0;var te=function(){function t(){this.proxyA=new se,this.proxyB=new se,this.transformA=vt.identity(),this.transformB=vt.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}(),ee=function(){function t(){this.pointA=q(0,0),this.pointB=q(0,0),this.distance=0,this.iterations=0}return t.prototype.recycle=function(){j(this.pointA),j(this.pointB),this.distance=0,this.iterations=0},t}(),ie=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}(),oe=function(t,e,i){++Jt.gjkCalls;var o=i.proxyA,s=i.proxyB,n=i.transformA,a=i.transformB;he.recycle(),he.readCache(e,o,n,s,a);for(var m=he.m_v,h=g.maxDistanceIterations,c=[],_=[],l=0,u=0;u<h;){l=he.m_count;for(var p=0;p<l;++p)c[p]=m[p].indexA,_[p]=m[p].indexB;if(he.solve(),3===he.m_count)break;var y=he.getSearchDirection();if($(y)<1e-18)break;var d=m[he.m_count];d.indexA=o.getSupport(ot(Ut,n.q,Y(Ut,-1,y))),rt(d.wA,n,o.getVertex(d.indexA)),d.indexB=s.getSupport(ot(Ut,a.q,y)),rt(d.wB,a,s.getVertex(d.indexB)),E(d.w,d.wB,d.wA),++u,++Jt.gjkIters;var f=!1;for(p=0;p<l;++p)if(d.indexA===c[p]&&d.indexB===_[p]){f=!0;break}if(f)break;++he.m_count}if(Jt.gjkMaxIters=Ht(Jt.gjkMaxIters,u),he.getWitnessPoints(t.pointA,t.pointB),t.distance=tt(t.pointA,t.pointB),t.iterations=u,he.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(Zt,t.pointB,t.pointA),Z(Zt),W(t.pointA,v,Zt),H(t.pointB,x,Zt);else{var A=E(Ut,t.pointA,t.pointB);N(t.pointA,A),N(t.pointB,A),t.distance=0}}},se=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=Q(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}(),ne=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,j(this.wA),j(this.wB),j(this.w),this.a=0},t.prototype.set=function(t){this.indexA=t.indexA,this.indexB=t.indexB,N(this.wA,t.wA),N(this.wB,t.wB),N(this.w,t.w),this.a=t.a},t}(),re=q(0,0),ae=q(0,0),me=function(){function t(){this.m_v1=new ne,this.m_v2=new ne,this.m_v3=new ne,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);rt(_.wA,i,a),rt(_.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);rt(_.wA,i,a),rt(_.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 k(re,-t.w.x,-t.w.y);case 2:return E(Kt,e.w,t.w),-G(Kt,t.w)>0?k(re,-Kt.y,Kt.x):k(re,Kt.y,-Kt.x);default:return j(re)}},t.prototype.getClosestPoint=function(){var t=this.m_v1,e=this.m_v2;switch(this.m_v3,this.m_count){case 0:return j(ae);case 1:return N(ae,t.w);case 2:return U(ae,t.a,t.w,e.a,e.w);case 3:default:return j(ae)}},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:N(t,i.wA),N(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:e.x=t.x=i.a*i.wA.x+o.a*o.wA.x+s.a*s.wA.x,e.y=t.y=i.a*i.wA.y+o.a*o.wA.y+s.a*s.wA.y}},t.prototype.getMetric=function(){switch(this.m_count){case 0:case 1:return 0;case 2:return tt(this.m_v1.w,this.m_v2.w);case 3:return G(E(Qt,this.m_v2.w,this.m_v1.w),E($t,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(Kt,e,t);var i=-Q(t,Kt);if(i<=0)return this.m_v1.a=1,void(this.m_count=1);var o=Q(e,Kt);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(Kt,e,t);var o=Q(t,Kt),s=Q(e,Kt),n=-o;E(Xt,i,t);var r=Q(t,Xt),a=Q(i,Xt),m=-r;E(Gt,i,e);var h=Q(e,Gt),c=Q(i,Gt),_=-h,l=G(Kt,Xt),u=l*G(e,i),p=l*G(i,t),y=l*G(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}(),he=new me,ce=new te,_e=new ie,le=new ee,ue=function(t,e,i,o,s,n){return ce.recycle(),ce.proxyA.set(t,e),ce.proxyB.set(i,o),nt(ce.transformA,s),nt(ce.transformB,n),ce.useRadii=!0,le.recycle(),_e.recycle(),oe(le,_e,ce),le.distance<1e-8};oe.testOverlap=ue,oe.Input=te,oe.Output=ee,oe.Proxy=se,oe.Cache=ie;var pe,ye=function(){function t(){this.proxyA=new se,this.proxyB=new se,this.transformA=vt.identity(),this.transformB=vt.identity(),this.translationB=y.zero()}return t.prototype.recycle=function(){this.proxyA.recycle(),this.proxyB.recycle(),this.transformA.setIdentity(),this.transformB.setIdentity(),j(this.translationB)},t}(),de=function(){this.point=y.zero(),this.normal=y.zero(),this.lambda=1,this.iterations=0},fe=function(t,e){t.iterations=0,t.lambda=1,t.normal.setZero(),t.point.setZero();var i=e.proxyA,o=e.proxyB,s=Ht(i.m_radius,g.polygonRadius),n=s+Ht(o.m_radius,g.polygonRadius),r=e.transformA,a=e.transformB,m=e.translationB,h=y.zero(),c=0,_=new me;_.m_count=0;for(var l=_.m_v,u=i.getSupport(ut.mulTVec2(r.q,y.neg(m))),p=vt.mulVec2(r,i.getVertex(u)),d=o.getSupport(ut.mulTVec2(a.q,m)),f=vt.mulVec2(a,o.getVertex(d)),v=y.sub(p,f),x=Ht(g.polygonRadius,n-g.polygonRadius),A=.5*g.linearSlop,b=0;b<20&&v.length()-x>A;){t.iterations+=1,u=i.getSupport(ut.mulTVec2(r.q,y.neg(v))),p=vt.mulVec2(r,i.getVertex(u)),d=o.getSupport(ut.mulTVec2(a.q,v)),f=vt.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},ve=Math.abs,xe=Math.max,Ae=function(){function t(){this.proxyA=new se,this.proxyB=new se,this.sweepA=new ft,this.sweepB=new ft}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,(pe=t.TOIOutputState||(t.TOIOutputState={}))[pe.e_unset=-1]="e_unset",pe[pe.e_unknown=0]="e_unknown",pe[pe.e_failed=1]="e_failed",pe[pe.e_overlapped=2]="e_overlapped",pe[pe.e_touching=3]="e_touching",pe[pe.e_separated=4]="e_separated";var ge=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}();Jt.toiTime=0,Jt.toiMaxTime=0,Jt.toiCalls=0,Jt.toiIters=0,Jt.toiMaxIters=0,Jt.toiRootIters=0,Jt.toiMaxRootIters=0;var be,Be=new te,we=new ee,Ve=new ie,Ce=st(0,0,0),Me=st(0,0,0),Ie=q(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),ke=function(e,i){var o=Yt();++Jt.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=xe(g.linearSlop,h-3*g.linearSlop),_=.25*g.linearSlop,l=0,u=g.maxTOIIterations,p=0;for(Ve.recycle(),Be.proxyA.setVertices(s.m_vertices,s.m_count,s.m_radius),Be.proxyB.setVertices(n.m_vertices,n.m_count,n.m_radius),Be.useRadii=!1;;){if(r.getTransform(Ce,l),a.getTransform(Me,l),nt(Be.transformA,Ce),nt(Be.transformB,Me),oe(we,Ve,Be),we.distance<=0){e.state=t.TOIOutputState.e_overlapped,e.t=0;break}if(we.distance<c+_){e.state=t.TOIOutputState.e_touching,e.t=l;break}Ne.initialize(Ve,s,r,n,a,l);for(var y=!1,d=m,f=0;;){var v=Ne.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=Ne.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,++Jt.toiRootIters;var V=Ne.evaluate(w);if(ve(V-c)<_){d=w;break}if(V>c?(b=w,x=V):(B=w,v=V),50===A)break}if(Jt.toiMaxRootIters=xe(Jt.toiMaxRootIters,A),++f===g.maxPolygonVertices)break}if(++p,++Jt.toiIters,y)break;if(p===u){e.state=t.TOIOutputState.e_failed,e.t=l;break}}Jt.toiMaxIters=xe(Jt.toiMaxIters,p);var C=Wt(o);Jt.toiMaxTime=xe(Jt.toiMaxTime,C),Jt.toiTime+=C,Ne.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 Ne=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,j(this.m_localPoint),j(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(Ce,n),this.m_sweepB.getTransform(Me,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 rt(Pe,Ce,a),rt(Se,Me,m),E(this.m_axis,Se,Pe),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]);K(this.m_axis,E(Ie,c,h),1),Z(this.m_axis),it(Te,Me.q,this.m_axis),U(this.m_localPoint,.5,h,.5,c),rt(Se,Me,this.m_localPoint);var _=e.getVertex(t.indexA[0]);return(p=Q(vt.mulVec2(Ce,_),Te)-Q(Se,Te))<0&&(D(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]);K(this.m_axis,E(Ie,u,l),1),Z(this.m_axis),it(Te,Ce.q,this.m_axis),U(this.m_localPoint,.5,l,.5,u),rt(Pe,Ce,this.m_localPoint);var p,y=this.m_proxyB.getVertex(t.indexB[0]);return rt(Se,Me,y),(p=Q(Se,Te)-Q(Pe,Te))<0&&(D(this.m_axis),p=-p),p},t.prototype.compute=function(t,e){switch(this.m_sweepA.getTransform(Ce,e),this.m_sweepB.getTransform(Me,e),this.m_type){case be.e_points:return t&&(ot(ze,Ce.q,this.m_axis),ot(Fe,Me.q,Y(Ie,-1,this.m_axis)),this.indexA=this.m_proxyA.getSupport(ze),this.indexB=this.m_proxyB.getSupport(Fe)),N(Le,this.m_proxyA.getVertex(this.indexA)),N(qe,this.m_proxyB.getVertex(this.indexB)),rt(Pe,Ce,Le),rt(Se,Me,qe),Q(Se,this.m_axis)-Q(Pe,this.m_axis);case be.e_faceA:return it(Te,Ce.q,this.m_axis),rt(Pe,Ce,this.m_localPoint),t&&(ot(Fe,Me.q,Y(Ie,-1,Te)),this.indexA=-1,this.indexB=this.m_proxyB.getSupport(Fe)),N(qe,this.m_proxyB.getVertex(this.indexB)),rt(Se,Me,qe),Q(Se,Te)-Q(Pe,Te);case be.e_faceB:return it(Te,Me.q,this.m_axis),rt(Se,Me,this.m_localPoint),t&&(ot(ze,Ce.q,Y(Ie,-1,Te)),this.indexB=-1,this.indexA=this.m_proxyA.getSupport(ze)),N(Le,this.m_proxyA.getVertex(this.indexA)),rt(Pe,Ce,Le),Q(Pe,Te)-Q(Se,Te);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=Ae,ke.Output=ge;var je=Math.abs,De=Math.sqrt,Oe=Math.min,Re=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}(),Ee=new Re,Je=q(0,0),Ye=q(0,0),We=q(0,0),He=new Ae,Ue=new ge,Ze=new ft,Ke=new ft,Xe=new ft,Ge=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}(),Qe=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];N(Je,r.m_sweep.c);var a=r.m_sweep.a;N(Ye,r.m_linearVelocity);var m=r.m_angularVelocity;N(r.m_sweep.c0,r.m_sweep.c),r.m_sweep.a0=r.m_sweep.a,r.isDynamic()&&(W(Ye,s*r.m_gravityScale,i),W(Ye,s*r.m_invMass,r.m_force),m+=s*r.m_invI*r.m_torque,Y(Ye,1/(1+s*r.m_linearDamping),Ye),m*=1/(1+s*r.m_angularDamping)),N(r.c_position.c,Je),r.c_position.a=a,N(r.c_velocity.v,Ye),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];N(Je,r.c_position.c);a=r.c_position.a;N(Ye,r.c_velocity.v);m=r.c_velocity.w;Y(We,s,Ye);var c=$(We);if(c>g.maxTranslationSquared){var _=g.maxTranslation/De(c);J(Ye,_)}var l=s*m;if(l*l>g.maxRotationSquared)m*=_=g.maxRotation/je(l);W(Je,s,Ye),a+=s*m,N(r.c_position.c,Je),r.c_position.a=a,N(r.c_velocity.v,Ye),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=Oe(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){N((r=this.m_bodies[n]).m_sweep.c,r.c_position.c),r.m_sweep.a=r.c_position.a,N(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||$(r.m_linearVelocity)>A?(r.m_sleepTime=0,x=0):(r.m_sleepTime+=s,x=Oe(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,He.proxyA.set(h.getShape(),v),He.proxyB.set(c.getShape(),x),He.sweepA.set(_.m_sweep),He.sweepB.set(l.m_sweep),He.tMax=1,ke(Ue,He);var A=Ue.t;m=Ue.state==t.TOIOutputState.e_touching?Oe(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(Ke.set(w.m_sweep),Xe.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||(Ze.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(Ze),S.synchronizeTransform()))}}}}Ee.reset((1-r)*e.dt),Ee.dtRatio=1,Ee.positionIterations=20,Ee.velocityIterations=e.velocityIterations,Ee.warmStarting=!1,this.solveIslandTOI(Ee,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(Ke),V.m_sweep.set(Xe),w.synchronizeTransform(),V.synchronizeTransform()}},e.prototype.solveIslandTOI=function(t,e,i){for(var o=0;o<this.m_bodies.length;++o){N((m=this.m_bodies[o]).c_position.c,m.m_sweep.c),m.c_position.a=m.m_sweep.a,N(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=Oe(s,r)}if(s>=-1.5*g.linearSlop)break}N(e.m_sweep.c0,e.c_position.c),e.m_sweep.a0=e.c_position.a,N(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];N(Je,m.c_position.c);var h=m.c_position.a;N(Ye,m.c_velocity.v);var c=m.c_velocity.w;Y(We,a,Ye);var _=$(We);if(_>g.maxTranslationSquared){var l=g.maxTranslation/De(_);J(Ye,l)}var u=a*c;if(u*u>g.maxRotationSquared)c*=l=g.maxRotation/je(u);W(Je,a,Ye),h+=a*c,N(m.c_position.c,Je),m.c_position.a=h,N(m.c_velocity.v,Ye),m.c_velocity.w=c,N(m.m_sweep.c,Je),m.m_sweep.a=h,N(m.m_linearVelocity,Ye),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}();Qe.TimeStep=Re;var $e,ti,ei,ii=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}(),oi=Math.sqrt,si=q(0,0),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);t.ManifoldType=void 0,($e=t.ManifoldType||(t.ManifoldType={}))[$e.e_unset=-1]="e_unset",$e[$e.e_circles=0]="e_circles",$e[$e.e_faceA=1]="e_faceA",$e[$e.e_faceB=2]="e_faceB",t.ContactFeatureType=void 0,(ti=t.ContactFeatureType||(t.ContactFeatureType={}))[ti.e_unset=-1]="e_unset",ti[ti.e_vertex=0]="e_vertex",ti[ti.e_face=1]="e_face",t.PointState=void 0,(ei=t.PointState||(t.PointState={}))[ei.nullState=0]="nullState",ei[ei.addState=1]="addState",ei[ei.persistState=2]="persistState",ei[ei.removeState=3]="removeState";var li=function(){function t(){this.v=q(0,0),this.id=new yi}return t.prototype.set=function(t){N(this.v,t.v),this.id.set(t.id)},t.prototype.recycle=function(){j(this.v),this.id.recycle()},t}(),ui=function(){function e(){this.localNormal=q(0,0),this.localPoint=q(0,0),this.points=[new pi,new pi],this.pointCount=0}return e.prototype.set=function(t){this.type=t.type,N(this.localNormal,t.localNormal),N(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,j(this.localNormal),j(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 di).pointCount=this.pointCount;var r=e.normal,a=e.points,m=e.separations;switch(this.type){case t.ManifoldType.e_circles:k(r,1,0);var h=this.points[0];rt(si,i,this.localPoint),rt(ni,s,h.localPoint),E(hi,ni,si);var c=$(hi);if(c>1e-18)Y(r,1/oi(c),hi);U(ai,1,si,o,r),U(mi,1,ni,-n,r),U(a[0],.5,ai,.5,mi),m[0]=Q(E(ri,mi,ai),r);break;case t.ManifoldType.e_faceA:it(r,i.q,this.localNormal),rt(ci,i,this.localPoint);for(var _=0;_<this.pointCount;++_){h=this.points[_];rt(_i,s,h.localPoint),U(ai,1,_i,o-Q(E(ri,_i,ci),r),r),U(mi,1,_i,-n,r),U(a[_],.5,ai,.5,mi),m[_]=Q(E(ri,mi,ai),r)}break;case t.ManifoldType.e_faceB:it(r,s.q,this.localNormal),rt(ci,s,this.localPoint);for(_=0;_<this.pointCount;++_){h=this.points[_];rt(_i,i,h.localPoint),U(mi,1,_i,n-Q(E(ri,_i,ci),r),r),U(ai,1,_i,-o,r),U(a[_],.5,ai,.5,mi),m[_]=Q(E(ri,ai,mi),r)}D(r)}return e},e.clipSegmentToLine=vi,e.ClipVertex=li,e.getPointStates=fi,e.PointState=t.PointState,e}(),pi=function(){function t(){this.localPoint=q(0,0),this.normalImpulse=0,this.tangentImpulse=0,this.id=new yi}return t.prototype.set=function(t){N(this.localPoint,t.localPoint),this.normalImpulse=t.normalImpulse,this.tangentImpulse=t.tangentImpulse,this.id.set(t.id)},t.prototype.recycle=function(){j(this.localPoint),this.normalImpulse=0,this.tangentImpulse=0,this.id.recycle()},t}(),yi=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}(),di=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(){j(this.normal),j(this.points[0]),j(this.points[1]),this.separations[0]=0,this.separations[1]=0,this.pointCount=0},t}();function fi(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 vi(e,i,o,s,n){var r=0,a=Q(o,i[0].v)-s,m=Q(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 xi=Math.sqrt,Ai=Math.max,gi=Math.min,bi=new b({create:function(){return new io},release:function(t){t.recycle()}}),Bi=new ui,wi=new di,Vi=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 Ci(t,e){return xi(t*e)}function Mi(t,e){return t>e?t:e}var Ii=[],Pi=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(){j(this.rA),j(this.rB),this.normalImpulse=0,this.tangentImpulse=0,this.normalMass=0,this.tangentMass=0,this.velocityBias=0},t}(),Si=q(0,0),Ti=q(0,0),zi=q(0,0),Fi=q(0,0),Li=q(0,0),qi=st(0,0,0),ki=st(0,0,0),Ni=q(0,0),ji=q(0,0),Di=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=function(){function e(){this.m_nodeA=new Vi(this),this.m_nodeB=new Vi(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 ui,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 Ge(this),this.v_points=[new Pi,new Pi],this.v_normal=q(0,0),this.v_normalMass=new ii,this.v_K=new ii,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=Ci(this.m_fixtureA.m_friction,this.m_fixtureB.m_friction),this.m_restitution=Mi(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()}j(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++){j(s[o])}j(this.p_localNormal),j(this.p_localPoint),j(this.p_localCenterA),j(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,N(this.p_localCenterA,o.m_sweep.localCenter),N(this.p_localCenterB,s.m_sweep.localCenter),this.p_radiusA=n.m_radius,this.p_radiusB=r.m_radius,this.p_type=a.type,N(this.p_localNormal,a.localNormal),N(this.p_localPoint,a.localPoint),this.p_pointCount=m;for(var h=0;h<g.maxManifoldPoints;++h)this.v_points[h].recycle(),j(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),N(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=Ci(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=Mi(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=ue(n,this.m_indexA,r,this.m_indexB,l,u),this.m_manifold.pointCount=0;else{Bi.recycle(),Bi.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<Bi.pointCount;++d){var f=Bi.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&&Bi&&t.preSolve(this,Bi)}}}},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),N(Si,_.c);var x=_.a;N(zi,l.c);for(var A=l.a,b=0;b<this.p_pointCount;++b){Bt(qi,u,Si,x),Bt(ki,p,zi,A);var B=void 0;switch(this.p_type){case t.ManifoldType.e_circles:rt(Ni,qi,this.p_localPoint),rt(ji,ki,this.p_localPoints[0]),E(Yi,ji,Ni),Z(Yi),U(Wi,.5,Ni,.5,ji),B=Q(ji,Yi)-Q(Ni,Yi)-this.p_radiusA-this.p_radiusB;break;case t.ManifoldType.e_faceA:it(Yi,qi.q,this.p_localNormal),rt(Oi,qi,this.p_localPoint),rt(Di,ki,this.p_localPoints[b]),B=Q(Di,Yi)-Q(Oi,Yi)-this.p_radiusA-this.p_radiusB,N(Wi,Di);break;case t.ManifoldType.e_faceB:it(Yi,ki.q,this.p_localNormal),rt(Oi,ki,this.p_localPoint),rt(Di,qi,this.p_localPoints[b]),B=Q(Di,Yi)-Q(Oi,Yi)-this.p_radiusA-this.p_radiusB,N(Wi,Di),D(Yi);break;default:return n}E(Ri,Wi,Si),E(Ei,Wi,zi),n=gi(n,B);var w=h((s?g.toiBaugarte:g.baumgarte)*(B+g.linearSlop),-g.maxLinearCorrection,0),V=G(Ri,Yi),C=G(Ei,Yi),M=y+f+d*V*V+v*C*C;Y(Ji,M>0?-w/M:0,Yi),H(Si,y,Ji),x-=d*G(Ri,Ji),W(zi,f,Ji),A+=v*G(Ei,Ji)}return N(_.c,Si),_.a=x,N(l.c,zi),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;N(Si,a.c);var v=a.a;N(Ti,n.v);var x=n.w;N(zi,m.c);var A=m.a;N(Fi,r.v);var b=r.w;Bt(qi,d,Si,v),Bt(ki,f,zi,A),wi.recycle(),_.getWorldManifold(wi,qi,h,ki,c),N(this.v_normal,wi.normal);for(var B=0;B<this.v_pointCount;++B){var w=this.v_points[B],V=wi.points[B];E(w.rA,V,Si),E(w.rB,V,zi);var C=G(w.rA,this.v_normal),M=G(w.rB,this.v_normal),I=l+u+p*C*C+y*M*M;w.normalMass=I>0?1/I:0,K(Li,this.v_normal,1);var P=G(w.rA,Li),S=G(w.rB,Li),T=l+u+p*P*P+y*S*S;w.tangentMass=T>0?1/T:0,w.velocityBias=0;var z=0;z+=Q(this.v_normal,Fi),z+=Q(this.v_normal,X(eo,b,w.rB)),z-=Q(this.v_normal,Ti),(z-=Q(this.v_normal,X(eo,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=G(F.rA,this.v_normal),k=G(F.rB,this.v_normal),j=G(L.rA,this.v_normal),D=G(L.rB,this.v_normal),O=l+u+p*q*q+y*k*k,R=l+u+p*j*j+y*D*D,J=l+u+p*q*j+y*k*D;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}N(a.c,Si),a.a=v,N(n.v,Ti),n.w=x,N(m.c,zi),m.a=A,N(r.v,Fi),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;N(Ti,n.v);var _=n.w;N(Fi,r.v);var l=r.w;N(Yi,this.v_normal),K(Li,Yi,1);for(var u=0;u<this.v_pointCount;++u){var p=this.v_points[u];U(Ji,p.normalImpulse,Yi,p.tangentImpulse,Li),_-=m*G(p.rA,Ji),H(Ti,a,Ji),l+=c*G(p.rB,Ji),W(Fi,h,Ji)}N(n.v,Ti),n.w=_,N(r.v,Fi),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;N(Ti,n.v);var l=n.w;N(Fi,r.v);var u=r.w;N(Yi,this.v_normal),K(Li,Yi,1);for(var p=this.v_friction,y=0;y<this.v_pointCount;++y){var d=this.v_points[y];j(Hi),O(Hi,Fi),O(Hi,X(eo,u,d.rB)),R(Hi,Ti),R(Hi,X(eo,l,d.rA));var f=Q(Hi,Li)-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(Ji,v,Li),H(Ti,a,Ji),l-=m*G(d.rA,Ji),W(Fi,c,Ji),u+=_*G(d.rB,Ji)}if(1==this.v_pointCount||0==t.blockSolve)for(var A=0;A<this.v_pointCount;++A){d=this.v_points[A];j(Hi),O(Hi,Fi),O(Hi,X(eo,u,d.rB)),R(Hi,Ti),R(Hi,X(eo,l,d.rA));var g,b=Q(Hi,Yi);v=-d.normalMass*(b-d.velocityBias);v=(g=Ai(d.normalImpulse+v,0))-d.normalImpulse,d.normalImpulse=g,Y(Ji,v,Yi),H(Ti,a,Ji),l-=m*G(d.rA,Ji),W(Fi,c,Ji),u+=_*G(d.rB,Ji)}else{var B=this.v_points[0],w=this.v_points[1];k(Xi,B.normalImpulse,w.normalImpulse),j(Ui),O(Ui,Fi),O(Ui,X(eo,u,B.rB)),R(Ui,Ti),R(Ui,X(eo,l,B.rA)),j(Zi),O(Zi,Fi),O(Zi,X(eo,u,w.rB)),R(Zi,Ti),R(Zi,X(eo,l,w.rA));var V=Q(Ui,Yi),C=Q(Zi,Yi);for(k(Ki,V-B.velocityBias,C-w.velocityBias),Ki.x-=this.v_K.ex.x*Xi.x+this.v_K.ey.x*Xi.y,Ki.y-=this.v_K.ex.y*Xi.x+this.v_K.ey.y*Xi.y;;){if(j(Gi),Gi.x=-(this.v_normalMass.ex.x*Ki.x+this.v_normalMass.ey.x*Ki.y),Gi.y=-(this.v_normalMass.ex.y*Ki.x+this.v_normalMass.ey.y*Ki.y),Gi.x>=0&&Gi.y>=0){E(Qi,Gi,Xi),Y($i,Qi.x,Yi),Y(to,Qi.y,Yi),H(Ti,a,$i),H(Ti,a,to),l-=m*(G(B.rA,$i)+G(w.rA,to)),W(Fi,c,$i),W(Fi,c,to),u+=_*(G(B.rB,$i)+G(w.rB,to)),B.normalImpulse=Gi.x,w.normalImpulse=Gi.y;break}if(Gi.x=-B.normalMass*Ki.x,Gi.y=0,V=0,C=this.v_K.ex.y*Gi.x+Ki.y,Gi.x>=0&&C>=0){E(Qi,Gi,Xi),Y($i,Qi.x,Yi),Y(to,Qi.y,Yi),H(Ti,a,$i),H(Ti,a,to),l-=m*(G(B.rA,$i)+G(w.rA,to)),W(Fi,c,$i),W(Fi,c,to),u+=_*(G(B.rB,$i)+G(w.rB,to)),B.normalImpulse=Gi.x,w.normalImpulse=Gi.y;break}if(Gi.x=0,Gi.y=-w.normalMass*Ki.y,V=this.v_K.ey.x*Gi.y+Ki.x,C=0,Gi.y>=0&&V>=0){E(Qi,Gi,Xi),Y($i,Qi.x,Yi),Y(to,Qi.y,Yi),H(Ti,a,$i),H(Ti,a,to),l-=m*(G(B.rA,$i)+G(w.rA,to)),W(Fi,c,$i),W(Fi,c,to),u+=_*(G(B.rB,$i)+G(w.rB,to)),B.normalImpulse=Gi.x,w.normalImpulse=Gi.y;break}if(Gi.x=0,Gi.y=0,V=Ki.x,C=Ki.y,V>=0&&C>=0){E(Qi,Gi,Xi),Y($i,Qi.x,Yi),Y(to,Qi.y,Yi),H(Ti,a,$i),H(Ti,a,to),l-=m*(G(B.rA,$i)+G(w.rA,to)),W(Fi,c,$i),W(Fi,c,to),u+=_*(G(B.rB,$i)+G(w.rB,to)),B.normalImpulse=Gi.x,w.normalImpulse=Gi.y;break}break}}N(n.v,Ti),n.w=l,N(r.v,Fi),r.w=u}}},e.addType=function(t,e,i){Ii[t]=Ii[t]||{},Ii[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=Ii[n]&&Ii[n][r])a.initialize(t,e,i,o,s);else{if(!(s=Ii[r]&&Ii[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}(),oo={gravity:y.zero(),allowSleep:!0,warmStarting:!0,continuousPhysics:!0,subStepping:!1,blockSolve:!0,velocityIterations:8,positionIterations:3},so=function(){function t(e){if(!(this instanceof t))return new t(e);this.s_step=new Re,e&&y.isValid(e)&&(e={gravity:e}),e=s(e,oo),this.m_solver=new Qe(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(Ot,e.bodies[n],s));if(e.joints)for(n=e.joints.length-1;n>=0;n--)s.createJoint(o(Et,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=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 Ot(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=io.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),io.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}(),no=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}(),ro=q(0,0),ao=q(0,0),mo=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=ut.mulTVec2(i.q,y.sub(e.p1,i.p)),n=ut.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?ut.mulVec2(i.q,c).neg():ut.mulVec2(i.q,c),!0)},e.prototype.computeAABB=function(t,e,i){rt(ro,e,this.m_vertex1),rt(ao,e,this.m_vertex2),v.combinePoints(t,ro,ao),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}(wt),ho=mo,co=q(0,0),_o=q(0,0),lo=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=mo.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 mo(this.getVertex(o),this.getVertex(o+1)).rayCast(t,e,i,0)},e.prototype.computeAABB=function(t,e,i){rt(co,e,this.getVertex(i)),rt(_o,e,this.getVertex(i+1)),v.combinePoints(t,co,_o)},e.prototype.computeMass=function(t,e){t.mass=0,j(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}(wt),uo=lo,po=Math.max,yo=Math.min,fo=q(0,0),vo=q(0,0),xo=q(0,0),Ao=q(0,0),go=q(0,0),bo=q(0,0),Bo=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=yo(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,i.addMul(l*n,a),i.addMul(l*n,m),i.addMul(l*n,h)}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,N(this.m_centroid,i);var s=vt.identity();s.p.setVec2(i),s.q.setAngle(o);for(var n=0;n<this.m_count;++n)this.m_vertices[n]=vt.mulVec2(s,this.m_vertices[n]),this.m_normals[n]=ut.mulVec2(s.q,this.m_normals[n])}},e.prototype.testPoint=function(t,e){for(var i=at(fo,t,e),o=0;o<this.m_count;++o){if(Q(this.m_normals[o],i)-Q(this.m_normals[o],this.m_vertices[o])>0)return!1}return!0},e.prototype.rayCast=function(t,e,i,o){for(var s=ut.mulTVec2(i.q,y.sub(e.p1,i.p)),n=ut.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=ut.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=rt(fo,e,this.m_vertices[a]);o=yo(o,m.x),n=po(n,m.x),s=yo(s,m.y),r=po(r,m.y)}k(t.lowerBound,o-this.m_radius,s-this.m_radius),k(t.upperBound,n+this.m_radius,r+this.m_radius)},e.prototype.computeMass=function(t,e){j(go);var i=0,o=0;j(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(xo,this.m_vertices[s],bo),s+1<this.m_count?E(Ao,this.m_vertices[s+1],bo):E(Ao,this.m_vertices[0],bo);var r=G(xo,Ao),a=.5*r;i+=a,U(go,1,go,a*n,xo),U(go,1,go,a*n,Ao);var m=xo.x,h=xo.y,c=Ao.x,_=Ao.y;o+=.25*n*r*(m*m+c*m+c*c+(h*h+_*h+_*_))}t.mass=e*i,Y(go,1/i,go),function(t,e,i){t.x=e.x+i.x,t.y=e.x+i.y}(t.center,go,bo),t.I=e*o,t.I+=t.mass*(Q(t.center,t.center)-Q(go,go))},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(vo,this.m_vertices[i],o);for(var s=0;s<this.m_count;++s){if(s!=e&&s!=i)if(G(vo,E(fo,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}(wt);var wo,Vo=Bo,Co=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}(Bo),Mo=Co,Io=Math.sqrt,Po=Math.PI,So=q(0,0),To=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 et(e,rt(So,t,this.m_p))<=this.m_radius*this.m_radius},e.prototype.rayCast=function(t,e,i,o){var s=y.add(i.p,ut.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+Io(_));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=rt(So,e,this.m_p);k(t.lowerBound,o.x-this.m_radius,o.y-this.m_radius),k(t.upperBound,o.x+this.m_radius,o.y+this.m_radius)},e.prototype.computeMass=function(t,e){t.mass=e*Po*this.m_radius*this.m_radius,N(t.center,this.m_p),t.I=t.mass*(.5*this.m_radius*this.m_radius+$(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}(wt),zo=To,Fo=Math.abs,Lo=Math.PI,qo={frequencyHz:0,dampingRatio:0},ko=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,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(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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),new e(t)},e.prototype._setAnchors=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)))},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=ut.neo(i),c=ut.neo(r);this.m_rA=ut.mulVec2(h,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=ut.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*Lo*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=ut.neo(i),r=ut.neo(s),a=ut.mulSub(n,this.m_localAnchorA,this.m_localCenterA),m=ut.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,Fo(_)<g.linearSlop},e.TYPE="distance-joint",e}(Et),No={maxForce:0,maxTorque:0},jo=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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),new e(t)},e.prototype._setAnchors=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)},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=ut.neo(e),m=ut.neo(s);this.m_rA=ut.mulVec2(a,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=ut.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 ii;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(ii.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}(Et),Do=function(){function t(t,e,i){"object"==typeof t&&null!==t?(this.ex=no.clone(t),this.ey=no.clone(e),this.ez=no.clone(i)):(this.ex=no.zero(),this.ey=no.zero(),this.ez=no.zero())}return t.prototype.toString=function(){return JSON.stringify(this)},t.isValid=function(t){return null!=t&&(no.isValid(t.ex)&&no.isValid(t.ey)&&no.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 no;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=no.dot(this.ex,no.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 no(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 no(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(no.add(e.ex,i.ex),no.add(e.ey,i.ey),no.add(e.ez,i.ez))},t}(),Oo=Math.abs;!function(t){t[t.inactiveLimit=0]="inactiveLimit",t[t.atLowerLimit=1]="atLowerLimit",t[t.atUpperLimit=2]="atUpperLimit",t[t.equalLimits=3]="equalLimits"}(wo||(wo={}));var Ro,Eo=0,Jo=0,Yo=0,Wo=0,Ho=!1,Uo=!1,Zo=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=wo.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 no,l.m_motorImpulse=0,l.m_lowerAngle=null!==(r=i.lowerAngle)&&void 0!==r?r:Eo,l.m_upperAngle=null!==(a=i.upperAngle)&&void 0!==a?a:Jo,l.m_maxMotorTorque=null!==(m=i.maxMotorTorque)&&void 0!==m?m:Yo,l.m_motorSpeed=null!==(h=i.motorSpeed)&&void 0!==h?h:Wo,l.m_enableLimit=null!==(c=i.enableLimit)&&void 0!==c?c:Ho,l.m_enableMotor=null!==(_=i.enableMotor)&&void 0!==_?_:Uo,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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),new e(t)},e.prototype._setAnchors=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)},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=ut.neo(e),m=ut.neo(s);this.m_rA=ut.mulVec2(a,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=ut.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;Oo(this.m_upperAngle-this.m_lowerAngle)<2*g.angularSlop?this.m_limitState=wo.equalLimits:p<=this.m_lowerAngle?(this.m_limitState!=wo.atLowerLimit&&(this.m_impulse.z=0),this.m_limitState=wo.atLowerLimit):p>=this.m_upperAngle?(this.m_limitState!=wo.atUpperLimit&&(this.m_impulse.z=0),this.m_limitState=wo.atUpperLimit):(this.m_limitState=wo.inactiveLimit,this.m_impulse.z=0)}else this.m_limitState=wo.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!=wo.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!=wo.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 no(d.x,d.y,f),l=no.neg(this.m_mass.solve33(_));if(this.m_limitState==wo.equalLimits)this.m_impulse.add(l);else if(this.m_limitState==wo.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==wo.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=ut.neo(o),a=ut.neo(n),m=0,c=this.m_invIA+this.m_invIB==0;if(this.m_enableLimit&&this.m_limitState!=wo.inactiveLimit&&0==c){var _=n-o-this.m_referenceAngle,l=0;if(this.m_limitState==wo.equalLimits){var u=h(_-this.m_lowerAngle,-g.maxAngularCorrection,g.maxAngularCorrection);l=-this.m_motorMass*u,m=Oo(u)}else if(this.m_limitState==wo.atLowerLimit){m=-(u=_-this.m_lowerAngle),u=h(u+g.angularSlop,-g.maxAngularCorrection,0),l=-this.m_motorMass*u}else if(this.m_limitState==wo.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=ut.mulVec2(r,y.sub(this.m_localAnchorA,this.m_localCenterA)),d=ut.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 ii;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}(Et),Ko=Math.abs,Xo=Math.max,Go=Math.min;!function(t){t[t.inactiveLimit=0]="inactiveLimit",t[t.atLowerLimit=1]="atLowerLimit",t[t.atUpperLimit=2]="atUpperLimit",t[t.equalLimits=3]="equalLimits"}(Ro||(Ro={}));var Qo,$o={enableLimit:!1,lowerTranslation:0,upperTranslation:0,enableMotor:!1,maxMotorForce:0,motorSpeed:0},ts=function(t){function e(i,o,n,r,a){var m=this;return m instanceof e?(i=s(i,$o),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 no,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=Ro.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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),t.localAxisA=y.clone(t.localAxisA),new e(t)},e.prototype._setAnchors=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)))},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=ut.mulVec2(t.m_xf.q,y.sub(this.m_localAnchorA,t.m_sweep.localCenter)),o=ut.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=ut.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=ut.neo(i),c=ut.neo(r),_=ut.mulVec2(h,y.sub(this.m_localAnchorA,this.m_localCenterA)),l=ut.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=ut.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=ut.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);Ko(this.m_upperTranslation-this.m_lowerTranslation)<2*g.linearSlop?this.m_limitState=Ro.equalLimits:C<=this.m_lowerTranslation?this.m_limitState!=Ro.atLowerLimit&&(this.m_limitState=Ro.atLowerLimit,this.m_impulse.z=0):C>=this.m_upperTranslation?this.m_limitState!=Ro.atUpperLimit&&(this.m_limitState=Ro.atUpperLimit,this.m_impulse.z=0):(this.m_limitState=Ro.inactiveLimit,this.m_impulse.z=0)}else this.m_limitState=Ro.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!=Ro.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!=Ro.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 no(v.x,v.y,x);var A=no.clone(this.m_impulse),g=this.m_K.solve33(no.neg(c));this.m_impulse.add(g),this.m_limitState==Ro.atLowerLimit?this.m_impulse.z=Xo(this.m_impulse.z,0):this.m_limitState==Ro.atUpperLimit&&(this.m_impulse.z=Go(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=no.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=ut.neo(i),r=ut.neo(s),a=this.m_invMassA,m=this.m_invMassB,c=this.m_invIA,_=this.m_invIB,l=ut.mulVec2(n,y.sub(this.m_localAnchorA,this.m_localCenterA)),u=ut.mulVec2(r,y.sub(this.m_localAnchorB,this.m_localCenterB)),p=y.sub(y.add(o,u),y.add(e,l)),d=ut.mulVec2(n,this.m_localXAxisA),f=y.crossVec2Vec2(y.add(p,l),d),v=y.crossVec2Vec2(u,d),x=ut.mulVec2(n,this.m_localYAxisA),A=y.crossVec2Vec2(y.add(p,l),x),b=y.crossVec2Vec2(u,x),B=new no,w=y.zero();w.x=y.dot(x,p),w.y=s-i-this.m_referenceAngle;var V=Ko(w.x),C=Ko(w.y),M=g.linearSlop,I=g.maxLinearCorrection,P=!1,S=0;if(this.m_enableLimit){var T=y.dot(d,p);Ko(this.m_upperTranslation-this.m_lowerTranslation)<2*M?(S=h(T,-I,I),V=Xo(V,Ko(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==(j=c+_)&&(j=1);var q=c*f+_*v,k=a+m+c*f*f+_*v*v;(D=new Do).ex.set(z,F,L),D.ey.set(F,j,q),D.ez.set(L,q,k);var N=new no;N.x=w.x,N.y=w.y,N.z=S,B=D.solve33(no.neg(N))}else{var j,D;z=a+m+c*A*A+_*b*b,F=c*A+_*b;0==(j=c+_)&&(j=1),(D=new ii).ex.setNum(z,F),D.ey.setNum(F,j);var O=D.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}(Et),es={ratio:1},is=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,es),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===Zo.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=ut.mulTVec2(p.q,y.add(ut.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===Zo.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=ut.mulTVec2(B.q,y.add(ut.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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),t.joint1=s(Et,t.joint1,i),t.joint2=s(Et,t.joint2,i),new e(t)},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=ut.neo(e),p=ut.neo(s),d=ut.neo(a),f=ut.neo(c);if(this.m_mass=0,this.m_type1==Zo.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=ut.mulVec2(d,this.m_localAxisC),x=ut.mulSub(d,this.m_localAnchorC,this.m_lcC),A=ut.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==Zo.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=ut.mulVec2(f,this.m_localAxisD);var g=ut.mulSub(f,this.m_localAnchorD,this.m_lcD),b=ut.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=ut.neo(c),x=ut.neo(l),A=ut.neo(p),b=ut.neo(f),B=0;if(this.m_type1==Zo.TYPE)o=y.zero(),n=1,a=1,B+=this.m_iA+this.m_iC,e=c-p-this.m_referenceAngleA;else{var w=ut.mulVec2(A,this.m_localAxisC),V=ut.mulSub(A,this.m_localAnchorC,this.m_lcC),C=ut.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=ut.mulTVec2(A,y.add(C,y.sub(h,u)));e=y.dot(y.sub(I,M),this.m_localAxisC)}if(this.m_type2==Zo.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=ut.mulVec2(b,this.m_localAxisD);var P=ut.mulSub(b,this.m_localAnchorD,this.m_lcD),S=ut.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=ut.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}(Et),os={maxForce:1,maxTorque:1,correctionFactor:.3},ss=function(t){function e(i,o,n){var r=this;return r instanceof e?(i=s(i,os),o=(r=t.call(this,i,o,n)||this).m_bodyA,n=r.m_bodyB,r.m_type=e.TYPE,r.m_linearOffset=Number.isFinite(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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),new e(t)},e.prototype._setAnchors=function(t){},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=ut.neo(i),c=ut.neo(r);this.m_rA=ut.mulVec2(h,y.sub(this.m_linearOffset,this.m_localCenterA)),this.m_rB=ut.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 ii;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(ii.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}(Et),ns=Math.PI,rs={maxForce:0,frequencyHz:5,dampingRatio:.7},as=function(t){function e(i,o,n,r){var a=this;return a instanceof e?(i=s(i,rs),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=vt.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 ii,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(Ot,t.bodyA,i),t.bodyB=s(Ot,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.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=ut.neo(s),m=this.m_bodyB.getMass(),h=2*ns*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=ut.mulVec2(a,y.sub(this.m_localAnchorB,this.m_localCenterB));var u=new ii;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=ii.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}(Et),ms=Math.abs,hs={collideConnected:!0},cs=function(t){function e(i,o,n,r,a,m,h,c){var _=this;return _ instanceof e?(i=s(i,hs),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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),new e(t)},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=ut.neo(i),c=ut.neo(r);this.m_rA=ut.mulVec2(h,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=ut.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=ut.neo(i),r=ut.neo(s),a=ut.mulVec2(n,y.sub(this.m_localAnchorA,this.m_localCenterA)),m=ut.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=ms(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}(Et),_s=Math.min;!function(t){t[t.inactiveLimit=0]="inactiveLimit",t[t.atLowerLimit=1]="atLowerLimit",t[t.atUpperLimit=2]="atUpperLimit",t[t.equalLimits=3]="equalLimits"}(Qo||(Qo={}));var 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=Qo.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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),new e(t)},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=ut.neo(i),c=ut.neo(r);this.m_rA=ut.mulSub(h,this.m_localAnchorA,this.m_localCenterA),this.m_rB=ut.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?Qo.atUpperLimit:Qo.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=_s(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=ut.neo(i),r=ut.neo(s),a=ut.mulSub(n,this.m_localAnchorA,this.m_localCenterA),m=ut.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}(Et),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 no,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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),new e(t)},e.prototype._setAnchors=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)},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=ut.neo(e),m=ut.neo(s);this.m_rA=ut.mulVec2(a,y.sub(this.m_localAnchorA,this.m_localCenterA)),this.m_rB=ut.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 no(u.x,u.y,h),d=no.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=ut.neo(s),m=ut.neo(r),h=this.m_invMassA,c=this.m_invMassB,_=this.m_invIA,l=this.m_invIB,u=ut.mulVec2(a,y.sub(this.m_localAnchorA,this.m_localCenterA)),p=ut.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 no(v.x,v.y,x),b=new no;if(d.ez.z>0)b=no.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}(Et),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(Ot,t.bodyA,i),t.bodyB=s(Ot,t.bodyB,i),new e(t)},e.prototype._setAnchors=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)))},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=ut.neo(r),p=ut.neo(c),d=ut.mulVec2(u,y.sub(this.m_localAnchorA,this.m_localCenterA)),f=ut.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=ut.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=ut.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=ut.neo(i),r=ut.neo(s),a=ut.mulVec2(n,y.sub(this.m_localAnchorA,this.m_localCenterA)),m=ut.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=ut.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}(Et),bs=0;function Bs(t){var e,i=(t=t||{}).rootClass||so,s=t.preSerialize||function(t){return t},n=t.postSerialize||function(t,e){return t},r=t.preDeserialize||function(t){return t},a=t.postDeserialize||function(t,e){return t},m={World:so,Body:Ot,Joint:Et,Fixture:St,Shape:wt},h=o({Vec2:y,Vec3:no},m),c=((e={})[Ot.STATIC]=Ot,e[Ot.DYNAMIC]=Ot,e[Ot.KINEMATIC]=Ot,e[lo.TYPE]=lo,e[Co.TYPE]=Co,e[mo.TYPE]=mo,e[Bo.TYPE]=Bo,e[To.TYPE]=To,e[ko.TYPE]=ko,e[jo.TYPE]=jo,e[is.TYPE]=is,e[ss.TYPE]=ss,e[as.TYPE]=as,e[ts.TYPE]=ts,e[cs.TYPE]=cs,e[Zo.TYPE]=Zo,e[us.TYPE]=us,e[fs.TYPE]=fs,e[gs.TYPE]=gs,e);this.toJson=function(t){var e=[],i=[t],o={};function r(t,s){if(t.__sid=t.__sid||++bs,!o[t.__sid]){i.push(t);var n={refIndex:e.length+i.length,refType:s};o[t.__sid]=n}return o[t.__sid]}function a(t,e){if("object"!=typeof t||null===t)return t;if("function"==typeof t._serialize){if(t!==e)for(var i in m)if(t instanceof m[i])return r(t,i);t=function(t){var e=(t=s(t))._serialize();return n(e,t)}(t)}if(Array.isArray(t)){for(var o=[],h=0;h<t.length;h++)o[h]=a(t[h]);t=o}else{o={};for(var h in t)t.hasOwnProperty(h)&&(o[h]=a(t[h]));t=o}return t}for(;i.length;){var h=i.shift(),c=a(h,h);e.push(c)}return e},this.fromJson=function(t){var e={};function o(t,e,i){var o=function(t,e){return e&&e._deserialize||(e=c[t.type]),e&&e._deserialize}(e,t);if(o){var n=o(e=r(e),i,s);return n=a(n,e)}}function s(i,s,n){if(!s.refIndex)return i&&i._deserialize&&o(i,s,n);i=h[s.refType]||i;var r=s.refIndex;if(!e[r]){var a=o(i,t[r],n);e[r]=a}return e[r]}return i._deserialize(t[0],null,s)}}var ws=new Bs;Bs.toJson=ws.toJson,Bs.fromJson=ws.fromJson;var Vs=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.ratio=16,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.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 Cs(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=Vs.mount(o);if(!i)return s;var n=i(s)||s.world;s.start(n)}io.addType(To.TYPE,To.TYPE,(function(t,e,i,o,s,n,r){Ps(t,i.getShape(),e,n.getShape(),s)}));var Ms=q(0,0),Is=q(0,0),Ps=function(e,i,o,s,n){e.pointCount=0,rt(Ms,o,i.m_p),rt(Is,n,s.m_p);var r=et(Is,Ms),a=i.m_radius+s.m_radius;r>a*a||(e.type=t.ManifoldType.e_circles,N(e.localPoint,i.m_p),j(e.localNormal),e.pointCount=1,N(e.points[0].localPoint,s.m_p),e.points[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,0,t.ContactFeatureType.e_vertex))};io.addType(mo.TYPE,To.TYPE,(function(t,e,i,o,s,n,r){var a=i.getShape(),m=n.getShape();ks(t,a,e,m,s)})),io.addType(lo.TYPE,To.TYPE,(function(t,e,i,o,s,n,r){var a=i.getShape(),m=new mo;a.getChildEdge(m,o);var h=m,c=n.getShape();ks(t,h,e,c,s)}));var Ss=q(0,0),Ts=q(0,0),zs=q(0,0),Fs=q(0,0),Ls=q(0,0),qs=q(0,0),ks=function(e,i,o,s,n){e.pointCount=0,mt(Fs,n,o,s.m_p);var r=i.m_vertex1,a=i.m_vertex2;E(Ss,a,r);var m=Q(Ss,a)-Q(Ss,Fs),h=Q(Ss,Fs)-Q(Ss,r),c=i.m_radius+s.m_radius;if(h<=0){if(N(Ls,r),et(Fs,r)>c*c)return;if(i.m_hasVertex0){var _=i.m_vertex0,l=r;if(E(Ts,l,_),Q(Ts,l)-Q(Ts,Fs)>0)return}return e.type=t.ManifoldType.e_circles,j(e.localNormal),N(e.localPoint,Ls),e.pointCount=1,N(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(N(Ls,a),et(Fs,Ls)>c*c)return;if(i.m_hasVertex3){var u=i.m_vertex3,p=a;if(E(zs,u,p),Q(zs,Fs)-Q(zs,p)>0)return}return e.type=t.ManifoldType.e_circles,j(e.localNormal),N(e.localPoint,Ls),e.pointCount=1,N(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=$(Ss);U(Ls,m/y,r,h/y,a),et(Fs,Ls)>c*c||(X(qs,1,Ss),Q(qs,Fs)-Q(qs,r)<0&&D(qs),Z(qs),e.type=t.ManifoldType.e_faceA,N(e.localNormal,qs),N(e.localPoint,r),e.pointCount=1,N(e.points[0].localPoint,s.m_p),e.points[0].id.setFeatures(0,t.ContactFeatureType.e_face,0,t.ContactFeatureType.e_vertex))},Ns=[new li,new li],js=[new li,new li],Ds=[new li,new li],Os=q(0,0),Rs=q(0,0),Es=q(0,0),Js=st(0,0,0),Ys=q(0,0),Ws=q(0,0),Hs=q(0,0),Us=q(0,0),Zs=q(0,0),Ks=q(0,0),Xs=q(0,0),Gs=q(0,0);function Qs(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;ht(Js,o,e);for(var c=0,_=-1/0,l=0;l<n;++l){it(Es,Js.q,a[l]),rt(Rs,Js,m[l]);for(var u=1/0,p=0;p<r;++p){var y=Q(Es,h[p])-Q(Es,Rs);y<u&&(u=y)}u>_&&(_=u,c=l)}s.maxSeparation=_,s.bestIndex=c}io.addType(Bo.TYPE,Bo.TYPE,(function(t,e,i,o,s,n,r){tn(t,i.getShape(),e,n.getShape(),s)}));var $s={maxSeparation:0,bestIndex:0},tn=function(e,i,o,s,n){e.pointCount=0;var r=i.m_radius+s.m_radius;Qs(i,o,s,n,$s);var a=$s.bestIndex,m=$s.maxSeparation;if(!(m>r)){Qs(s,n,i,o,$s);var h=$s.bestIndex,c=$s.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),Ns[0].recycle(),Ns[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}(Gs,r.q,o.q,a[s]);for(var _=0,l=1/0,u=0;u<m;++u){var p=Q(Gs,c[u]);p<l&&(l=p,_=u)}var y=_,d=y+1<m?y+1:0;rt(e[0].v,r,h[y]),e[0].id.setFeatures(s,t.ContactFeatureType.e_face,y,t.ContactFeatureType.e_vertex),rt(e[1].v,r,h[d]),e[1].id.setFeatures(s,t.ContactFeatureType.e_face,d,t.ContactFeatureType.e_vertex)}(Ns,_,u,y,l,p);var f=_.m_count,v=_.m_vertices,x=y,A=y+1<f?y+1:0;N(Ys,v[x]),N(Ws,v[A]),E(Hs,Ws,Ys),Z(Hs),K(Us,Hs,1),U(Zs,.5,Ys,.5,Ws),it(Ks,u.q,Hs),K(Xs,Ks,1),rt(Ys,u,Ys),rt(Ws,u,Ws);var b=Q(Xs,Ys),B=-Q(Ks,Ys)+r,w=Q(Ks,Ws)+r;if(js[0].recycle(),js[1].recycle(),Ds[0].recycle(),Ds[1].recycle(),k(Os,-Ks.x,-Ks.y),!(vi(js,Ns,Os,B,x)<2))if(k(Os,Ks.x,Ks.y),!(vi(Ds,js,Os,w,A)<2)){N(e.localNormal,Us),N(e.localPoint,Zs);for(var V=0,C=0;C<Ds.length;++C){if(Q(Xs,Ds[C].v)-b<=r){var M=e.points[V];at(M.localPoint,p,Ds[C].v),M.id.set(Ds[C].id),d&&M.id.swapFeatures(),++V}}e.pointCount=V}}}};io.addType(Bo.TYPE,To.TYPE,(function(t,e,i,o,s,n,r){sn(t,i.getShape(),e,n.getShape(),s)}));var en=q(0,0),on=q(0,0),sn=function(e,i,o,s,n){e.pointCount=0,mt(en,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=Q(l[u],en)-Q(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,N(e.localNormal,l[a]),U(e.localPoint,.5,f,.5,v),N(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=Q(en,v)-Q(en,f)-Q(f,v)+Q(f,f),A=Q(en,f)-Q(en,v)-Q(v,f)+Q(v,v);if(x<=0){if(et(en,f)>h*h)return;e.pointCount=1,e.type=t.ManifoldType.e_faceA,E(e.localNormal,en,f),Z(e.localNormal),N(e.localPoint,f),N(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(et(en,v)>h*h)return;e.pointCount=1,e.type=t.ManifoldType.e_faceA,E(e.localNormal,en,v),Z(e.localNormal),N(e.localPoint,v),N(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(on,.5,f,.5,v),Q(en,l[y])-Q(on,l[y])>h)return;e.pointCount=1,e.type=t.ManifoldType.e_faceA,N(e.localNormal,l[y]),N(e.localPoint,on),N(e.points[0].localPoint,s.m_p),e.points[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,0,t.ContactFeatureType.e_vertex)}},nn=Math.min;io.addType(mo.TYPE,Bo.TYPE,(function(t,e,i,o,s,n,r){zn(t,i.getShape(),e,n.getShape(),s)})),io.addType(lo.TYPE,Bo.TYPE,(function(t,e,i,o,s,n,r){i.getShape().getChildEdge(mn,o),zn(t,mn,e,n.getShape(),s)}));var rn,an,mn=new mo;!function(t){t[t.e_unknown=-1]="e_unknown",t[t.e_edgeA=1]="e_edgeA",t[t.e_edgeB=2]="e_edgeB"}(rn||(rn={})),function(t){t[t.e_isolated=0]="e_isolated",t[t.e_concave=1]="e_concave",t[t.e_convex=2]="e_convex"}(an||(an={}));var hn=function(){},cn=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))},_n=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(){j(this.v1),j(this.v2),j(this.normal),j(this.sideNormal1),j(this.sideNormal2)},t}(),ln=[new li,new li],un=[new li,new li],pn=[new li,new li],yn=new hn,dn=new hn,fn=new cn,vn=new _n,xn=q(0,0),An=q(0,0),gn=q(0,0),bn=q(0,0),Bn=st(0,0,0),wn=q(0,0),Vn=q(0,0),Cn=q(0,0),Mn=q(0,0),In=q(0,0),Pn=q(0,0),Sn=q(0,0),Tn=q(0,0),zn=function(e,i,o,s,n){ht(Bn,o,n),rt(xn,Bn,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(gn,m,a),Z(gn),k(Cn,gn.y,-gn.x);var l,u=Q(Cn,xn)-Q(Cn,a),p=0,d=0,f=!1,v=!1;j(Vn),j(Mn),c&&(E(An,a,r),Z(An),k(Vn,An.y,-An.x),f=G(An,gn)>=0,p=y.dot(Vn,xn)-y.dot(Vn,r)),_&&(E(bn,h,m),Z(bn),k(Mn,bn.y,-bn.x),v=y.crossVec2Vec2(gn,bn)>0,d=y.dot(Mn,xn)-y.dot(Mn,m)),j(wn),j(In),j(Pn),c&&_?f&&v?(l=p>=0||u>=0||d>=0)?(N(wn,Cn),N(In,Vn),N(Pn,Mn)):(Y(wn,-1,Cn),Y(In,-1,Cn),Y(Pn,-1,Cn)):f?(l=p>=0||u>=0&&d>=0)?(N(wn,Cn),N(In,Vn),N(Pn,Cn)):(Y(wn,-1,Cn),Y(In,-1,Mn),Y(Pn,-1,Cn)):v?(l=d>=0||p>=0&&u>=0)?(N(wn,Cn),N(In,Cn),N(Pn,Mn)):(Y(wn,-1,Cn),Y(In,-1,Cn),Y(Pn,-1,Vn)):(l=p>=0&&u>=0&&d>=0)?(N(wn,Cn),N(In,Cn),N(Pn,Cn)):(Y(wn,-1,Cn),Y(In,-1,Mn),Y(Pn,-1,Vn)):c?f?(l=p>=0||u>=0)?(N(wn,Cn),N(In,Vn),Y(Pn,-1,Cn)):(Y(wn,-1,Cn),N(In,Cn),Y(Pn,-1,Cn)):(l=p>=0&&u>=0)?(N(wn,Cn),N(In,Cn),Y(Pn,-1,Cn)):(Y(wn,-1,Cn),N(In,Cn),Y(Pn,-1,Vn)):_?v?(l=u>=0||d>=0)?(N(wn,Cn),Y(In,-1,Cn),N(Pn,Mn)):(Y(wn,-1,Cn),Y(In,-1,Cn),N(Pn,Cn)):(l=u>=0&&d>=0)?(N(wn,Cn),Y(In,-1,Cn),N(Pn,Cn)):(Y(wn,-1,Cn),Y(In,-1,Mn),N(Pn,Cn)):(l=u>=0)?(N(wn,Cn),Y(In,-1,Cn),Y(Pn,-1,Cn)):(Y(wn,-1,Cn),N(In,Cn),N(Pn,Cn)),fn.count=s.m_count;for(var x=0;x<s.m_count;++x)rt(fn.vertices[x],Bn,s.m_vertices[x]),it(fn.normals[x],Bn.q,s.m_normals[x]);var A=s.m_radius+i.m_radius;e.pointCount=0,yn.type=rn.e_edgeA,yn.index=l?0:1,yn.separation=1/0;for(x=0;x<fn.count;++x){var b=fn.vertices[x];(B=Q(wn,b)-Q(wn,a))<yn.separation&&(yn.separation=B)}if(yn.type!=rn.e_unknown&&!(yn.separation>A)){dn.type=rn.e_unknown,dn.index=-1,dn.separation=-1/0,k(Sn,-wn.y,wn.x);for(x=0;x<fn.count;++x){Y(Tn,-1,fn.normals[x]);var B,w=Q(Tn,fn.vertices[x])-Q(Tn,a),V=Q(Tn,fn.vertices[x])-Q(Tn,m);if((B=nn(w,V))>A){dn.type=rn.e_edgeB,dn.index=x,dn.separation=B;break}if(Q(Tn,Sn)>=0){if(Q(Tn,wn)-Q(Pn,wn)<-g.angularSlop)continue}else if(Q(Tn,wn)-Q(In,wn)<-g.angularSlop)continue;B>dn.separation&&(dn.type=rn.e_edgeB,dn.index=x,dn.separation=B)}if(!(dn.type!=rn.e_unknown&&dn.separation>A)){var C;if(C=dn.type==rn.e_unknown?yn:dn.separation>.98*yn.separation+.001?dn:yn,pn[0].recycle(),pn[1].recycle(),C.type==rn.e_edgeA){e.type=t.ManifoldType.e_faceA;var M=0,I=Q(wn,fn.normals[0]);for(x=1;x<fn.count;++x){var P=Q(wn,fn.normals[x]);P<I&&(I=P,M=x)}var S=M,T=S+1<fn.count?S+1:0;N(pn[0].v,fn.vertices[S]),pn[0].id.setFeatures(0,t.ContactFeatureType.e_face,S,t.ContactFeatureType.e_vertex),N(pn[1].v,fn.vertices[T]),pn[1].id.setFeatures(0,t.ContactFeatureType.e_face,T,t.ContactFeatureType.e_vertex),l?(vn.i1=0,vn.i2=1,N(vn.v1,a),N(vn.v2,m),N(vn.normal,Cn)):(vn.i1=1,vn.i2=0,N(vn.v1,m),N(vn.v2,a),Y(vn.normal,-1,Cn))}else e.type=t.ManifoldType.e_faceB,N(pn[0].v,a),pn[0].id.setFeatures(0,t.ContactFeatureType.e_vertex,C.index,t.ContactFeatureType.e_face),N(pn[1].v,m),pn[1].id.setFeatures(0,t.ContactFeatureType.e_vertex,C.index,t.ContactFeatureType.e_face),vn.i1=C.index,vn.i2=vn.i1+1<fn.count?vn.i1+1:0,N(vn.v1,fn.vertices[vn.i1]),N(vn.v2,fn.vertices[vn.i2]),N(vn.normal,fn.normals[vn.i1]);if(k(vn.sideNormal1,vn.normal.y,-vn.normal.x),k(vn.sideNormal2,-vn.sideNormal1.x,-vn.sideNormal1.y),vn.sideOffset1=Q(vn.sideNormal1,vn.v1),vn.sideOffset2=Q(vn.sideNormal2,vn.v2),ln[0].recycle(),ln[1].recycle(),un[0].recycle(),un[1].recycle(),!(vi(ln,pn,vn.sideNormal1,vn.sideOffset1,vn.i1)<g.maxManifoldPoints))if(!(vi(un,ln,vn.sideNormal2,vn.sideOffset2,vn.i2)<g.maxManifoldPoints)){C.type==rn.e_edgeA?(N(e.localNormal,vn.normal),N(e.localPoint,vn.v1)):(N(e.localNormal,s.m_normals[vn.i1]),N(e.localPoint,s.m_vertices[vn.i1]));var z=0;for(x=0;x<g.maxManifoldPoints;++x){if(Q(vn.normal,un[x].v)-Q(vn.normal,vn.v1)<=A){var F=e.points[z];C.type==rn.e_edgeA?(at(F.localPoint,Bn,un[x].v),F.id.set(un[x].id)):(N(F.localPoint,un[x].v),F.id.set(un[x].id),F.id.swapFeatures()),++z}}e.pointCount=z}}}},Fn={CollidePolygons:tn,Settings:g,Sweep:ft,Manifold:ui,Distance:oe,TimeOfImpact:ke,DynamicTree:M,stats:Jt},Ln=Object.freeze({__proto__:null,Math:c,Serializer:Bs,Testbed:Vs,testbed:Cs,Vec2:y,Vec3:no,Mat22:ii,Mat33:Do,Transform:vt,Rot:ut,AABB:v,Shape:wt,FixtureProxy:Pt,Fixture:St,Body:Ot,ContactEdge:Vi,mixFriction:Ci,mixRestitution:Mi,VelocityConstraintPoint:Pi,Contact:io,JointEdge:Rt,Joint:Et,World:so,CircleShape:To,Circle:zo,EdgeShape:mo,Edge:ho,PolygonShape:Bo,Polygon:Vo,ChainShape:lo,Chain:uo,BoxShape:Co,Box:Mo,CollideCircles:Ps,CollideEdgeCircle:ks,CollidePolygons:tn,CollidePolygonCircle:sn,CollideEdgePolygon:zn,DistanceJoint:ko,FrictionJoint:jo,GearJoint:is,MotorJoint:ss,MouseJoint:as,PrismaticJoint:ts,PulleyJoint:cs,RevoluteJoint:Zo,RopeJoint:us,WeldJoint:fs,WheelJoint:gs,Settings:A,SettingsInternal:g,Sweep:ft,get ManifoldType(){return t.ManifoldType},get ContactFeatureType(){return t.ContactFeatureType},get PointState(){return t.PointState},ClipVertex:li,Manifold:ui,ManifoldPoint:pi,ContactID:yi,WorldManifold:di,getPointStates:fi,clipSegmentToLine:vi,DistanceInput:te,DistanceOutput:ee,SimplexCache:ie,Distance:oe,DistanceProxy:se,testOverlap:ue,ShapeCastInput:ye,ShapeCastOutput:de,ShapeCast:fe,TOIInput:Ae,get TOIOutputState(){return t.TOIOutputState},TOIOutput:ge,TimeOfImpact:ke,TreeNode:V,DynamicTree:M,stats:Jt,internal:Fn});t.AABB=v,t.Body=Ot,t.Box=Mo,t.BoxShape=Co,t.Chain=uo,t.ChainShape=lo,t.Circle=zo,t.CircleShape=To,t.ClipVertex=li,t.CollideCircles=Ps,t.CollideEdgeCircle=ks,t.CollideEdgePolygon=zn,t.CollidePolygonCircle=sn,t.CollidePolygons=tn,t.Contact=io,t.ContactEdge=Vi,t.ContactID=yi,t.Distance=oe,t.DistanceInput=te,t.DistanceJoint=ko,t.DistanceOutput=ee,t.DistanceProxy=se,t.DynamicTree=M,t.Edge=ho,t.EdgeShape=mo,t.Fixture=St,t.FixtureProxy=Pt,t.FrictionJoint=jo,t.GearJoint=is,t.Joint=Et,t.JointEdge=Rt,t.Manifold=ui,t.ManifoldPoint=pi,t.Mat22=ii,t.Mat33=Do,t.Math=c,t.MotorJoint=ss,t.MouseJoint=as,t.Polygon=Vo,t.PolygonShape=Bo,t.PrismaticJoint=ts,t.PulleyJoint=cs,t.RevoluteJoint=Zo,t.RopeJoint=us,t.Rot=ut,t.Serializer=Bs,t.Settings=A,t.SettingsInternal=g,t.Shape=wt,t.ShapeCast=fe,t.ShapeCastInput=ye,t.ShapeCastOutput=de,t.SimplexCache=ie,t.Sweep=ft,t.TOIInput=Ae,t.TOIOutput=ge,t.Testbed=Vs,t.TimeOfImpact=ke,t.Transform=vt,t.TreeNode=V,t.Vec2=y,t.Vec3=no,t.VelocityConstraintPoint=Pi,t.WeldJoint=fs,t.WheelJoint=gs,t.World=so,t.WorldManifold=di,t.clipSegmentToLine=vi,t.default=Ln,t.getPointStates=fi,t.internal=Fn,t.mixFriction=Ci,t.mixRestitution=Mi,t.stats=Jt,t.testOverlap=ue,t.testbed=Cs,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=planck.min.js.map