@newkrok/nape-js 3.8.2 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ConvexResult-CYFNMlT2.d.cts → ConvexResult-Hai2aEI-.d.cts} +0 -37
- package/dist/{ConvexResult-CYFNMlT2.d.ts → ConvexResult-Hai2aEI-.d.ts} +0 -37
- package/dist/chunk-7HUI2OS2.js +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -27
- package/dist/index.d.ts +2 -27
- package/dist/index.js +1 -1
- package/dist/serialization/index.cjs +1 -1
- package/dist/serialization/index.d.cts +78 -2
- package/dist/serialization/index.d.ts +78 -2
- package/dist/serialization/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3TXNIYBK.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var ql=Object.defineProperty;var zo=Object.getOwnPropertyDescriptor;var Po=Object.getOwnPropertyNames;var wo=Object.prototype.hasOwnProperty;var vo=(V,e)=>{for(var t in e)ql(V,t,{get:e[t],enumerable:!0})},go=(V,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of Po(e))!wo.call(V,l)&&l!==t&&ql(V,l,{get:()=>e[l],enumerable:!(n=zo(e,l))||n.enumerable});return V};var Co=V=>go(ql({},"__esModule",{value:!0}),V);var pr={};vo(pr,{SNAPSHOT_VERSION:()=>Is,spaceFromJSON:()=>fo,spaceToJSON:()=>to});module.exports=Co(pr);var Is=1;function mt(V){return{x:V.x,y:V.y}}function eo(V){if(V==null)return null;try{let e=JSON.stringify(V);return e==="{}"?null:JSON.parse(e)}catch{return null}}function Mo(V){return{elasticity:V.elasticity,dynamicFriction:V.dynamicFriction,staticFriction:V.staticFriction,density:V.density,rollingFriction:V.rollingFriction}}function Zo(V){return{collisionGroup:V.collisionGroup,collisionMask:V.collisionMask,sensorGroup:V.sensorGroup,sensorMask:V.sensorMask,fluidGroup:V.fluidGroup,fluidMask:V.fluidMask}}function ko(V){if(V==null)return null;let e=V.gravity;return{density:V.density,viscosity:V.viscosity,gravity:e!=null?mt(e):null}}function Eo(V){let e=Mo(V.material),t=Zo(V.filter),n=V.fluidEnabled,l=n?ko(V.fluidProperties):null,s=V.sensorEnabled;if(V.isCircle()){let i=V,o=V.localCOM;return{type:"circle",radius:i.radius,localCOM:mt(o),material:e,filter:t,sensorEnabled:s,fluidEnabled:n,fluidProperties:l}}else{let o=V.localVerts,r=[],a=o.length;for(let p=0;p<a;p++)r.push(mt(o.at(p)));return{type:"polygon",localVerts:r,material:e,filter:t,sensorEnabled:s,fluidEnabled:n,fluidProperties:l}}}var No={1:"STATIC",2:"DYNAMIC",3:"KINEMATIC"},Oo={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},So={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},Ao={0:"DEFAULT",1:"FIXED",2:"SCALED"};function Vo(V,e){let t=V.zpp_inner,n=Oo[t.massMode]??"DEFAULT",l=So[t.inertiaMode]??"DEFAULT",s=Ao[t.gravMassMode]??"DEFAULT",i=[],o=V.shapes,r=o.length;for(let a=0;a<r;a++)i.push(Eo(o.at(a)));return{id:e,type:No[t.type]??"DYNAMIC",position:mt(V.position),rotation:V.rotation,velocity:mt(V.velocity),angularVel:V.angularVel,kinematicVel:mt(V.kinematicVel),kinAngVel:V.kinAngVel,surfaceVel:mt(V.surfaceVel),force:mt(V.force),torque:t.type===2?V.torque:0,massMode:n,mass:n==="FIXED"?t.cmass:null,inertiaMode:l,inertia:l==="FIXED"?t.cinertia:null,gravMassMode:s,gravMassScale:t.gravMassScale,allowMovement:V.allowMovement,allowRotation:V.allowRotation,bullet:V.isBullet,shapes:i,userData:eo(t.userData)}}function Ri(V,e,t,n){let l=V.zpp_inner,s=t!=null?e.get(t.zpp_inner.id)??null:null,i=n!=null?e.get(n.zpp_inner.id)??null:null;return{body1Id:s,body2Id:i,active:l.active,ignore:l.ignore,stiff:l.stiff,frequency:l.frequency,damping:l.damping,maxForce:l.maxForce,maxError:l.maxError,breakUnderForce:l.breakUnderForce,breakUnderError:l.breakUnderError,removeOnBreak:l.removeOnBreak,userData:eo(l.userData)}}function Io(V,e){switch(V.constructor?.name??""){case"PivotJoint":{let n=V;return{...Ri(V,e,n.body1,n.body2),type:"PivotJoint",anchor1:mt(n.anchor1),anchor2:mt(n.anchor2)}}case"DistanceJoint":{let n=V;return{...Ri(V,e,n.body1,n.body2),type:"DistanceJoint",anchor1:mt(n.anchor1),anchor2:mt(n.anchor2),jointMin:n.jointMin,jointMax:n.jointMax}}case"AngleJoint":{let n=V;return{...Ri(V,e,n.body1,n.body2),type:"AngleJoint",jointMin:n.jointMin,jointMax:n.jointMax,ratio:n.ratio}}case"MotorJoint":{let n=V;return{...Ri(V,e,n.body1,n.body2),type:"MotorJoint",rate:n.rate,ratio:n.ratio}}case"LineJoint":{let n=V;return{...Ri(V,e,n.body1,n.body2),type:"LineJoint",anchor1:mt(n.anchor1),anchor2:mt(n.anchor2),direction:mt(n.direction),jointMin:n.jointMin,jointMax:n.jointMax}}case"PulleyJoint":{let n=V;return{...Ri(V,e,n.body1,n.body2),type:"PulleyJoint",anchor1:mt(n.anchor1),anchor2:mt(n.anchor2),anchor3:mt(n.anchor3),anchor4:mt(n.anchor4),jointMin:n.jointMin,jointMax:n.jointMax,ratio:n.ratio}}case"WeldJoint":{let n=V;return{...Ri(V,e,n.body1,n.body2),type:"WeldJoint",anchor1:mt(n.anchor1),anchor2:mt(n.anchor2),phase:n.phase}}default:return null}}function to(V){let e=[],t=new Map,n=new Map;function l(f){let m=f.zpp_inner.id;if(n.has(m))return;let z=e.length;t.set(f,z),n.set(m,z),e.push(Vo(f,z))}let s=V.bodies,i=s.length;for(let f=0;f<i;f++)l(s.at(f));let o=V.compounds,r=o.length;for(let f=0;f<r;f++){let z=o.at(f).bodies,Z=z.length;for(let y=0;y<Z;y++)l(z.at(y))}let a=[],p=new Map;function c(f){if(p.has(f))return;let m=Io(f,n);m!=null&&(p.set(f,a.length),a.push(m))}let u=V.constraints,h=u.length;for(let f=0;f<h;f++)c(u.at(f));for(let f=0;f<r;f++){let z=o.at(f).constraints,Z=z.length;for(let y=0;y<Z;y++)c(z.at(y))}let x=[];for(let f=0;f<r;f++){let m=o.at(f),z=[],Z=m.bodies,y=Z.length;for(let g=0;g<y;g++){let k=Z.at(g),N=t.get(k);N!=null&&z.push(N)}let w=[],v=m.constraints,P=v.length;for(let g=0;g<P;g++){let k=v.at(g),N=p.get(k);N!=null&&w.push(N)}x.push({bodyIds:z,constraintIndices:w,childIndices:[]})}let _=V.zpp_inner.bphase.is_sweep?"SWEEP_AND_PRUNE":"DYNAMIC_AABB_TREE",d=V.gravity;return{version:1,gravity:mt(d),worldLinearDrag:V.worldLinearDrag,worldAngularDrag:V.worldAngularDrag,sortContacts:V.sortContacts,broadphase:_,bodies:e,constraints:a,compounds:x}}var ni=class{static POSINF(){return 1/0}static NEGINF(){return-1/0}};ni.__name__=["zpp_nape","ZPP_Const"],ni.FMAX=1e100;var vt=class vt{static Constraint(){return vt._Constraint++}static Interactor(){return vt._Interactor++}static CbType(){return vt._CbType++}static CbSet(){return vt._CbSet++}static Listener(){return vt._Listener++}static ZPP_SimpleVert(){return vt._ZPP_SimpleVert++}static ZPP_SimpleSeg(){return vt._ZPP_SimpleSeg++}static Space(){return vt._Space++}static InteractionGroup(){return vt._InteractionGroup++}};vt.__name__=["zpp_nape","ZPP_ID"],vt._Constraint=0,vt._Interactor=0,vt._CbType=0,vt._CbSet=0,vt._Listener=0,vt._ZPP_SimpleVert=0,vt._ZPP_SimpleSeg=0,vt._Space=0,vt._InteractionGroup=0;var fn=vt;var $=class{};$.__name__=["zpp_nape","util","ZPP_Flags"],$.GravMassMode_DEFAULT=null,$.GravMassMode_FIXED=null,$.GravMassMode_SCALED=null,$.InertiaMode_DEFAULT=null,$.InertiaMode_FIXED=null,$.MassMode_DEFAULT=null,$.MassMode_FIXED=null,$.BodyType_STATIC=null,$.BodyType_DYNAMIC=null,$.BodyType_KINEMATIC=null,$.ListenerType_BODY=null,$.ListenerType_CONSTRAINT=null,$.ListenerType_INTERACTION=null,$.ListenerType_PRE=null,$.PreFlag_ACCEPT=null,$.PreFlag_IGNORE=null,$.PreFlag_ACCEPT_ONCE=null,$.PreFlag_IGNORE_ONCE=null,$.CbEvent_BEGIN=null,$.CbEvent_ONGOING=null,$.CbEvent_END=null,$.CbEvent_WAKE=null,$.CbEvent_SLEEP=null,$.CbEvent_BREAK=null,$.CbEvent_PRE=null,$.InteractionType_COLLISION=null,$.InteractionType_SENSOR=null,$.InteractionType_FLUID=null,$.InteractionType_ANY=null,$.Winding_UNDEFINED=null,$.Winding_CLOCKWISE=null,$.Winding_ANTICLOCKWISE=null,$.ValidationResult_VALID=null,$.ValidationResult_DEGENERATE=null,$.ValidationResult_CONCAVE=null,$.ValidationResult_SELF_INTERSECTING=null,$.ShapeType_CIRCLE=null,$.ShapeType_POLYGON=null,$.Broadphase_DYNAMIC_AABB_TREE=null,$.Broadphase_SWEEP_AND_PRUNE=null,$.ArbiterType_COLLISION=null,$.ArbiterType_SENSOR=null,$.ArbiterType_FLUID=null,$.internal=!1,$.id_ImmState_ACCEPT=1,$.id_ImmState_IGNORE=2,$.id_ImmState_ALWAYS=4,$.id_GravMassMode_DEFAULT=0,$.id_GravMassMode_FIXED=1,$.id_GravMassMode_SCALED=2,$.id_InertiaMode_DEFAULT=0,$.id_InertiaMode_FIXED=1,$.id_MassMode_DEFAULT=0,$.id_MassMode_FIXED=1,$.id_BodyType_STATIC=1,$.id_BodyType_DYNAMIC=2,$.id_BodyType_KINEMATIC=3,$.id_ListenerType_BODY=0,$.id_ListenerType_CONSTRAINT=1,$.id_ListenerType_INTERACTION=2,$.id_ListenerType_PRE=3,$.id_PreFlag_ACCEPT=1,$.id_PreFlag_IGNORE=2,$.id_PreFlag_ACCEPT_ONCE=3,$.id_PreFlag_IGNORE_ONCE=4,$.id_CbEvent_BEGIN=0,$.id_CbEvent_END=1,$.id_CbEvent_WAKE=2,$.id_CbEvent_SLEEP=3,$.id_CbEvent_BREAK=4,$.id_CbEvent_PRE=5,$.id_CbEvent_ONGOING=6,$.id_InteractionType_COLLISION=1,$.id_InteractionType_SENSOR=2,$.id_InteractionType_FLUID=4,$.id_InteractionType_ANY=7,$.id_Winding_UNDEFINED=0,$.id_Winding_CLOCKWISE=1,$.id_Winding_ANTICLOCKWISE=2,$.id_ValidationResult_VALID=0,$.id_ValidationResult_DEGENERATE=1,$.id_ValidationResult_CONCAVE=2,$.id_ValidationResult_SELF_INTERSECTING=3,$.id_ShapeType_CIRCLE=0,$.id_ShapeType_POLYGON=1,$.id_Broadphase_DYNAMIC_AABB_TREE=0,$.id_Broadphase_SWEEP_AND_PRUNE=1,$.id_ArbiterType_COLLISION=1,$.id_ArbiterType_SENSOR=2,$.id_ArbiterType_FLUID=4;var js=class{static sqrt(e){return Math.sqrt(e)}static invsqrt(e){return 1/Math.sqrt(e)}static sqr(e){return e*e}static clamp2(e,t){let n=-t;return e<n?n:e>t?t:e}static clamp(e,t,n){return e<t?t:e>n?n:e}};js.__name__=["zpp_nape","util","ZPP_Math"];var de=class{};de.__name__=["zpp_nape","util","ZPP_PubPool"],de.poolGeomPoly=null,de.nextGeomPoly=null,de.poolVec2=null,de.nextVec2=null,de.poolVec3=null,de.nextVec3=null;var Bs=class{constructor(e,t){this.list=[];this.width=0;this.width=e,this.list=[]}resize(e,t,n){this.width=e;let l=e*t;for(let s=0;s<l;s++)this.list[s]=n}get(e,t){return this.list[t*this.width+e]}set(e,t,n){return this.list[t*this.width+e]=n}},qi=class extends Bs{};qi.__name__=["zpp_nape","util","ZNPArray2_Float"];var Ji=class extends Bs{};Ji.__name__=["zpp_nape","util","ZNPArray2_ZPP_GeomVert"];var Ui=class extends Bs{};Ui.__name__=["zpp_nape","util","ZNPArray2_ZPP_MarchPair"];var hn=class hn{constructor(){this.value=!1;this.next=null;this.hnext=null;this.id=0;this.di=0;this.__class__=hn}static _alloc(){if(hn.zpp_pool==null)return new hn;let e=hn.zpp_pool;return hn.zpp_pool=e.next,e.next=null,e}static get(e,t,n){let l=hn._alloc();return l.id=e,l.di=t,l.value=n,l}static getpersist(e,t){let n=hn._alloc();return n.id=e,n.di=t,n}static ordered_get(e,t,n){if(e<=t){let l=hn._alloc();return l.id=e,l.di=t,l.value=n,l}else{let l=hn._alloc();return l.id=t,l.di=e,l.value=n,l}}static ordered_get_persist(e,t){if(e<=t){let n=hn._alloc();return n.id=e,n.di=t,n}else{let n=hn._alloc();return n.id=t,n.di=e,n}}free(){}alloc(){}};hn.__name__=["zpp_nape","util","Hashable2_Boolfalse"],hn.zpp_pool=null;var je=hn;var jo=1048576,Wi=1048575,Ki=106039,vl=class vl{constructor(){this.cnt=0;this.__class__=vl;this.cnt=0,this.table=new Array(jo).fill(null)}empty(){return this.cnt==0}clear(){for(let e=0;e<this.table.length;e++){let t=this.table[e];if(t!=null){for(;t!=null;){let n=t.hnext;t.hnext=null,t=n}this.table[e]=null}}}get(e,t){let n=this.table[e*Ki+t&Wi];if(n==null)return null;if(n.id==e&&n.di==t)return n;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n}ordered_get(e,t){if(e>t){let l=e;e=t,t=l}let n=this.table[e*Ki+t&Wi];if(n==null)return null;if(n.id==e&&n.di==t)return n;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n}has(e,t){let n=this.table[e*Ki+t&Wi];if(n==null)return!1;if(n.id==e&&n.di==t)return!0;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n!=null}maybeAdd(e){let t=e.id*Ki+e.di&Wi,n=this.table[t],l=!0;n==null?(this.table[t]=e,e.hnext=null):l&&(e.hnext=n.hnext,n.hnext=e),l&&this.cnt++}add(e){let t=e.id*Ki+e.di&Wi,n=this.table[t];n==null?(this.table[t]=e,e.hnext=null):(e.hnext=n.hnext,n.hnext=e),this.cnt++}remove(e){let t=e.id*Ki+e.di&Wi,n=this.table[t];if(n==e)this.table[t]=n.hnext;else if(n!=null){let l;for(;l=n,n=n.hnext,n!=null&&n!=e;);l.hnext=n.hnext}e.hnext=null,this.cnt--}hash(e,t){return e*Ki+t&Wi}};vl.__name__=["zpp_nape","util","FastHash2_Hashable2_Boolfalse"];var Yi=vl;var Ts=class{constructor(){this.elt=null;this.next=null}alloc(){}free(){this.elt=null}elem(){return this.elt}};Ts.zpp_pool=null;var bt=class{constructor(){this.head=null;this.length=0;this.modified=!1;this.pushmod=!1}_allocNode(){let e=this.constructor._NodeClass,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor._NodeClass;e.elt=null,e.next=t.zpp_pool,t.zpp_pool=e}begin(){return this.head}setbegin(e){this.head=e,this.modified=!0,this.pushmod=!0}add(e){let t=this._allocNode();return t.elt=e,t.next=this.head,this.head=t,this.modified=!0,this.length++,e}addAll(e){let t=e.head;for(;t!=null;)this.add(t.elt),t=t.next}insert(e,t){let n=this._allocNode();return n.elt=t,e==null?(n.next=this.head,this.head=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.head.elt;return this.pop(),e}erase(e){let t,n;return e==null?(t=this.head,n=t.next,this.head=n,this.head==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),this._freeNode(t),this.modified=!0,this.length--,this.pushmod=!0,n}remove(e){let t=null,n=this.head;for(;n!=null;){if(n.elt==e){this.erase(t);break}t=n,n=n.next}}try_remove(e){let t=null,n=this.head,l=!1;for(;n!=null;){if(n.elt==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){for(;this.head!=null;){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=!0),this.modified=!0,this.length--}this.pushmod=!0}reverse(){let e=this.head,t=null;for(;e!=null;){let n=e.next;e.next=t,this.head=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.head==null}size(){return this.length}has(e){let t=this.head;for(;t!=null;){if(t.elt==e)return!0;t=t.next}return!1}front(){return this.head.elt}back(){let e=this.head,t=e;for(;t!=null;)e=t,t=t.next;return e.elt}iterator_at(e){let t=this.head;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t!=null?t.elt:null}};bt.prototype.inlined_add=bt.prototype.add;bt.prototype.inlined_insert=bt.prototype.insert;bt.prototype.inlined_pop=bt.prototype.pop;bt.prototype.inlined_pop_unsafe=bt.prototype.pop_unsafe;bt.prototype.inlined_erase=bt.prototype.erase;bt.prototype.inlined_remove=bt.prototype.remove;bt.prototype.inlined_try_remove=bt.prototype.try_remove;bt.prototype.inlined_clear=bt.prototype.clear;bt.prototype.inlined_has=bt.prototype.has;var Ls=class{constructor(){this.colour=0;this.parent=null;this.next=null;this.prev=null;this.data=null;this.swapped=null;this.lt=null}_allocNode(){let e=this.constructor,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor;e.data=null,e.lt=null,e.swapped=null,e.next=t.zpp_pool,t.zpp_pool=e}free(){this.data=null,this.lt=null,this.swapped=null}alloc(){}verify(){if(!this.empty()){let e=this.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;){let t=e.data,n=!0;if(!this.empty()){let l=this.parent;for(;l.prev!=null;)l=l.prev;for(;l!=null;){let s=l.data;if(n){if(t==s)n=!1;else if(!this.lt(s,t)&&this.lt(t,s))return!1}else if(!this.lt(t,s)&&this.lt(s,t))return!1;if(l.next!=null)for(l=l.next;l.prev!=null;)l=l.prev;else{for(;l.parent!=null&&l==l.parent.next;)l=l.parent;l=l.parent}}}if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent}}}return!0}empty(){return this.parent==null}singular(){return this.parent!=null&&this.parent.prev==null?this.parent.next==null:!1}size(){let e=0;if(!this.empty()){let t=this.parent;for(;t.prev!=null;)t=t.prev;for(;t!=null;)if(++e,t.next!=null)for(t=t.next;t.prev!=null;)t=t.prev;else{for(;t.parent!=null&&t==t.parent.next;)t=t.parent;t=t.parent}}return e}has(e){return this.find(e)!=null}find(e){let t=this.parent;for(;t!=null&&t.data!=e;)this.lt(e,t.data)?t=t.prev:t=t.next;return t}has_weak(e){return this.find_weak(e)!=null}find_weak(e){let t=this.parent;for(;t!=null;)if(this.lt(e,t.data))t=t.prev;else if(this.lt(t.data,e))t=t.next;else break;return t}lower_bound(e){let t=null;if(!this.empty()){let n=this.parent;for(;n.prev!=null;)n=n.prev;for(;n!=null;){if(!this.lt(n.data,e)){t=n.data;break}if(n.next!=null)for(n=n.next;n.prev!=null;)n=n.prev;else{for(;n.parent!=null&&n==n.parent.next;)n=n.parent;n=n.parent}}}return t}first(){let e=this.parent;for(;e.prev!=null;)e=e.prev;return e.data}pop_front(){let e=this.parent;for(;e.prev!=null;)e=e.prev;let t=e.data;return this.remove_node(e),t}remove(e){this.remove_node(this.find(e))}successor_node(e){if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{let t=e;for(e=e.parent;e!=null&&e.prev!=t;)t=e,e=e.parent}return e}predecessor_node(e){if(e.prev!=null)for(e=e.prev;e.next!=null;)e=e.next;else{let t=e;for(e=e.parent;e!=null&&e.next!=t;)t=e,e=e.parent}return e}successor(e){let t=this.successor_node(this.find(e));return t==null?null:t.data}predecessor(e){let t=this.predecessor_node(this.find(e));return t==null?null:t.data}remove_node(e){if(e.next!=null&&e.prev!=null){let l=e.next;for(;l.prev!=null;)l=l.prev;let s=e.data;e.data=l.data,l.data=s,this.swapped!=null&&this.swapped(e.data,l.data),e=l}let t=e.prev==null?e.next:e.prev;if(e.colour==1){if(e.prev!=null||e.next!=null)t.colour=1;else if(e.parent!=null){let l=e.parent;for(;;){l.colour++,l.prev.colour--,l.next.colour--;let s=l.prev;if(s.colour==-1){this.__fix_neg_red(s);break}else if(s.colour==0){if(s.prev!=null&&s.prev.colour==0){this.__fix_dbl_red(s.prev);break}if(s.next!=null&&s.next.colour==0){this.__fix_dbl_red(s.next);break}}let i=l.next;if(i.colour==-1){this.__fix_neg_red(i);break}else if(i.colour==0){if(i.prev!=null&&i.prev.colour==0){this.__fix_dbl_red(i.prev);break}if(i.next!=null&&i.next.colour==0){this.__fix_dbl_red(i.next);break}}if(l.colour==2)if(l.parent==null)l.colour=1;else{l=l.parent;continue}break}}}let n=e.parent;n==null?this.parent=t:n.prev==e?n.prev=t:n.next=t,t!=null&&(t.parent=n),e.parent=e.prev=e.next=null,this._freeNode(e)}clear(){if(this.parent!=null){let e=this.parent;for(;e!=null;)if(e.prev!=null)e=e.prev;else if(e.next!=null)e=e.next;else{let t=e.parent;t!=null&&(e==t.prev?t.prev=null:t.next=null,e.parent=null),this._freeNode(e),e=t}this.parent=null}}clear_with(e){if(this.parent==null)return;let t=this.parent;for(;t!=null;)if(t.prev!=null)t=t.prev;else if(t.next!=null)t=t.next;else{e(t.data);let n=t.parent;n!=null&&(t==n.prev?n.prev=null:n.next=null,t.parent=null),this._freeNode(t),t=n}this.parent=null}clear_node(e,t){t(e.data);let n=e.parent;return n!=null&&(e==n.prev?n.prev=null:n.next=null,e.parent=null),this._freeNode(e),n}__fix_neg_red(e){let t=e.parent,n;if(t.prev==e){let l=e.prev,s=e.next,i=s.prev,o=s.next;l.colour=0,e.colour=t.colour=1,e.next=i,i!=null&&(i.parent=e);let r=t.data;t.data=s.data,s.data=r,this.swapped!=null&&this.swapped(t.data,s.data),s.prev=o,o!=null&&(o.parent=s),s.next=t.next,t.next!=null&&(t.next.parent=s),t.next=s,s!=null&&(s.parent=t),n=l}else{let l=e.next,s=e.prev,i=s.next,o=s.prev;l.colour=0,e.colour=t.colour=1,e.prev=i,i!=null&&(i.parent=e);let r=t.data;t.data=s.data,s.data=r,this.swapped!=null&&this.swapped(t.data,s.data),s.next=o,o!=null&&(o.parent=s),s.prev=t.prev,t.prev!=null&&(t.prev.parent=s),t.prev=s,s!=null&&(s.parent=t),n=l}n.prev!=null&&n.prev.colour==0?this.__fix_dbl_red(n.prev):n.next!=null&&n.next.colour==0&&this.__fix_dbl_red(n.next)}__fix_dbl_red(e){for(;;){let t=e.parent,n=t.parent;if(n==null){t.colour=1;break}let l,s,i,o,r,a,p;t==n.prev?(i=n,p=n.next,e==t.prev?(l=e,s=t,o=e.prev,r=e.next,a=t.next):(l=t,s=e,o=t.prev,r=e.prev,a=e.next)):(l=n,o=n.prev,e==t.prev?(s=e,i=t,r=e.prev,a=e.next,p=t.next):(s=t,i=e,r=t.prev,a=e.prev,p=e.next));let c=n.parent;if(c==null?this.parent=s:c.prev==n?c.prev=s:c.next=s,s!=null&&(s.parent=c),l.prev=o,o!=null&&(o.parent=l),l.next=r,r!=null&&(r.parent=l),s.prev=l,l!=null&&(l.parent=s),s.next=i,i!=null&&(i.parent=s),i.prev=a,a!=null&&(a.parent=i),i.next=p,p!=null&&(p.parent=i),s.colour=n.colour-1,l.colour=1,i.colour=1,s==this.parent)this.parent.colour=1;else if(s.colour==0&&s.parent.colour==0){e=s;continue}break}}try_insert_bool(e){let t=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else{let n=this.parent;for(;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break}return t==null?!1:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),!0)}try_insert(e){let t=null,n=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else for(n=this.parent;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break;return t==null?n:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t)}insert(e){let t=this._allocNode();if(t.data=e,this.parent==null)this.parent=t;else{let n=this.parent;for(;;)if(this.lt(t.data,n.data))if(n.prev==null){n.prev=t,t.parent=n;break}else n=n.prev;else if(n.next==null){n.next=t,t.parent=n;break}else n=n.next}return t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t}};Ls.zpp_pool=null;var zi=null,gl=null,ds=null,Jl=null,Bo=null,Ul=null,ys=null,en=null,ms=null,Wn=null,bs=null,fs=null,Wl=null,To=null,Lo=null,Do=null,Fo=null,Go=null,Ro=null,qo=null,Jo=null;function Je(V){let e=class extends Ts{};return e.__name__=["zpp_nape","util","ZNPNode_"+V],e.zpp_pool=null,e}function Ue(V,e){let t=class extends bt{};return t.__name__=["zpp_nape","util","ZNPList_"+V],t._NodeClass=e,t}function fi(V){let e=class extends Ls{};return e.__name__=["zpp_nape","util","ZPP_Set_"+V],e.zpp_pool=null,e}function no(V){V.util||(V.util={}),V.util.ZNPNode_ZPP_CbType=Je("ZPP_CbType"),V.util.ZNPNode_ZPP_CallbackSet=Je("ZPP_CallbackSet"),V.util.ZNPNode_ZPP_Shape=Je("ZPP_Shape"),V.util.ZNPNode_ZPP_Body=Je("ZPP_Body"),V.util.ZNPNode_ZPP_Constraint=Je("ZPP_Constraint"),V.util.ZNPNode_ZPP_Compound=Je("ZPP_Compound"),V.util.ZNPNode_ZPP_Arbiter=Je("ZPP_Arbiter"),V.util.ZNPNode_ZPP_InteractionListener=Je("ZPP_InteractionListener"),V.util.ZNPNode_ZPP_CbSet=Je("ZPP_CbSet"),V.util.ZNPNode_ZPP_Interactor=Je("ZPP_Interactor"),V.util.ZNPNode_ZPP_BodyListener=Je("ZPP_BodyListener"),V.util.ZNPNode_ZPP_CbSetPair=Je("ZPP_CbSetPair"),V.util.ZNPNode_ZPP_ConstraintListener=Je("ZPP_ConstraintListener"),V.util.ZNPNode_ZPP_CutInt=Je("ZPP_CutInt"),V.util.ZNPNode_ZPP_CutVert=Je("ZPP_CutVert"),V.util.ZNPNode_ZPP_PartitionVertex=Je("ZPP_PartitionVertex"),V.util.ZNPNode_ZPP_SimplifyP=Je("ZPP_SimplifyP"),V.util.ZNPNode_ZPP_PartitionedPoly=Je("ZPP_PartitionedPoly"),V.util.ZNPNode_ZPP_GeomVert=Je("ZPP_GeomVert"),V.util.ZNPNode_ZPP_SimpleVert=Je("ZPP_SimpleVert"),V.util.ZNPNode_ZPP_SimpleEvent=Je("ZPP_SimpleEvent"),V.util.ZNPNode_ZPP_Vec2=Je("ZPP_Vec2"),V.util.ZNPNode_ZPP_AABBPair=Je("ZPP_AABBPair"),V.util.ZNPNode_ZPP_Edge=Je("ZPP_Edge"),V.util.ZNPNode_ZPP_AABBNode=Je("ZPP_AABBNode"),V.util.ZNPNode_ZPP_Component=Je("ZPP_Component"),V.util.ZNPNode_ZPP_FluidArbiter=Je("ZPP_FluidArbiter"),V.util.ZNPNode_ZPP_SensorArbiter=Je("ZPP_SensorArbiter"),V.util.ZNPNode_ZPP_Listener=Je("ZPP_Listener"),V.util.ZNPNode_ZPP_ColArbiter=Je("ZPP_ColArbiter"),V.util.ZNPNode_ZPP_InteractionGroup=Je("ZPP_InteractionGroup"),V.util.ZNPNode_ZPP_ToiEvent=Je("ZPP_ToiEvent"),V.util.ZNPNode_ConvexResult=Je("ConvexResult"),V.util.ZNPNode_ZPP_GeomPoly=Je("ZPP_GeomPoly"),V.util.ZNPNode_RayResult=Je("RayResult");let e=V.util;Lo=V.util.ZNPList_ZPP_InteractionListener=Ue("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),Do=V.util.ZNPList_ZPP_BodyListener=Ue("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),Fo=V.util.ZNPList_ZPP_ConstraintListener=Ue("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),Go=V.util.ZNPList_ZPP_Constraint=Ue("ZPP_Constraint",e.ZNPNode_ZPP_Constraint),Ro=V.util.ZNPList_ZPP_Interactor=Ue("ZPP_Interactor",e.ZNPNode_ZPP_Interactor),qo=V.util.ZNPList_ZPP_CbSet=Ue("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),To=V.util.ZNPList_ZPP_CbType=Ue("ZPP_CbType",e.ZNPNode_ZPP_CbType),V.util.ZNPList_ZPP_Vec2=Ue("ZPP_Vec2",e.ZNPNode_ZPP_Vec2),Bo=V.util.ZNPList_ZPP_Vec2,V.util.ZNPList_ZPP_CallbackSet=Ue("ZPP_CallbackSet",e.ZNPNode_ZPP_CallbackSet),V.util.ZNPList_ZPP_Shape=Ue("ZPP_Shape",e.ZNPNode_ZPP_Shape),V.util.ZNPList_ZPP_Body=Ue("ZPP_Body",e.ZNPNode_ZPP_Body),V.util.ZNPList_ZPP_Compound=Ue("ZPP_Compound",e.ZNPNode_ZPP_Compound),V.util.ZNPList_ZPP_Arbiter=Ue("ZPP_Arbiter",e.ZNPNode_ZPP_Arbiter),Jo=V.util.ZNPList_ZPP_CbSetPair=Ue("ZPP_CbSetPair",e.ZNPNode_ZPP_CbSetPair),V.util.ZNPList_ZPP_CutInt=Ue("ZPP_CutInt",e.ZNPNode_ZPP_CutInt),V.util.ZNPList_ZPP_CutVert=Ue("ZPP_CutVert",e.ZNPNode_ZPP_CutVert),V.util.ZNPList_ZPP_PartitionVertex=Ue("ZPP_PartitionVertex",e.ZNPNode_ZPP_PartitionVertex),zi=V.util.ZNPList_ZPP_PartitionVertex,V.util.ZNPList_ZPP_SimplifyP=Ue("ZPP_SimplifyP",e.ZNPNode_ZPP_SimplifyP),Jl=V.util.ZNPList_ZPP_SimplifyP,V.util.ZNPList_ZPP_PartitionedPoly=Ue("ZPP_PartitionedPoly",e.ZNPNode_ZPP_PartitionedPoly),gl=V.util.ZNPList_ZPP_PartitionedPoly,V.util.ZNPList_ZPP_GeomVert=Ue("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),ds=V.util.ZNPList_ZPP_GeomVert,V.util.ZNPList_ZPP_SimpleVert=Ue("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),Wl=V.util.ZNPList_ZPP_SimpleEvent=Ue("ZPP_SimpleEvent",e.ZNPNode_ZPP_SimpleEvent),V.util.ZNPList_ZPP_AABBPair=Ue("ZPP_AABBPair",e.ZNPNode_ZPP_AABBPair),V.util.ZNPList_ZPP_Edge=Ue("ZPP_Edge",e.ZNPNode_ZPP_Edge),V.util.ZNPList_ZPP_AABBNode=Ue("ZPP_AABBNode",e.ZNPNode_ZPP_AABBNode),V.util.ZNPList_ZPP_Component=Ue("ZPP_Component",e.ZNPNode_ZPP_Component),V.util.ZNPList_ZPP_FluidArbiter=Ue("ZPP_FluidArbiter",e.ZNPNode_ZPP_FluidArbiter),V.util.ZNPList_ZPP_SensorArbiter=Ue("ZPP_SensorArbiter",e.ZNPNode_ZPP_SensorArbiter),V.util.ZNPList_ZPP_Listener=Ue("ZPP_Listener",e.ZNPNode_ZPP_Listener),V.util.ZNPList_ZPP_ColArbiter=Ue("ZPP_ColArbiter",e.ZNPNode_ZPP_ColArbiter),V.util.ZNPList_ZPP_InteractionGroup=Ue("ZPP_InteractionGroup",e.ZNPNode_ZPP_InteractionGroup),V.util.ZNPList_ZPP_ToiEvent=Ue("ZPP_ToiEvent",e.ZNPNode_ZPP_ToiEvent),V.util.ZNPList_ConvexResult=Ue("ConvexResult",e.ZNPNode_ConvexResult),V.util.ZNPList_ZPP_GeomPoly=Ue("ZPP_GeomPoly",e.ZNPNode_ZPP_GeomPoly),V.util.ZNPList_RayResult=Ue("RayResult",e.ZNPNode_RayResult),ys=V.util.ZNPNode_RayResult,Ul=V.util.ZNPList_ZPP_SimpleVert,V.util.ZPP_Set_ZPP_Body=fi("ZPP_Body"),V.util.ZPP_Set_ZPP_CbSetPair=fi("ZPP_CbSetPair"),V.util.ZPP_Set_ZPP_PartitionVertex=fi("ZPP_PartitionVertex"),bs=V.util.ZPP_Set_ZPP_PartitionVertex,V.util.ZPP_Set_ZPP_PartitionPair=fi("ZPP_PartitionPair"),fs=V.util.ZPP_Set_ZPP_PartitionPair,V.util.ZPP_Set_ZPP_SimpleVert=fi("ZPP_SimpleVert"),en=V.util.ZPP_Set_ZPP_SimpleVert,V.util.ZPP_Set_ZPP_SimpleSeg=fi("ZPP_SimpleSeg"),ms=V.util.ZPP_Set_ZPP_SimpleSeg,V.util.ZPP_Set_ZPP_SimpleEvent=fi("ZPP_SimpleEvent"),Wn=V.util.ZPP_Set_ZPP_SimpleEvent,V.util.ZPP_Set_ZPP_CbSet=fi("ZPP_CbSet")}var ft=class ft{constructor(){this.outer_body=null;this.outer_con=null;this.outer_int=null;this.event=0;this.listener=null;this.space=null;this.index=0;this.next=null;this.prev=null;this.length=0;this.int1=null;this.int2=null;this.set=null;this.wrap_arbiters=null;this.pre_arbiter=null;this.pre_swapped=!1;this.body=null;this.constraint=null}wrapper_body(){return this.outer_body==null&&(ft.internal=!0,this.outer_body=ft._createBodyCb(),ft.internal=!1,this.outer_body.zpp_inner=this),this.outer_body}wrapper_con(){return this.outer_con==null&&(ft.internal=!0,this.outer_con=ft._createConCb(),ft.internal=!1,this.outer_con.zpp_inner=this),this.outer_con}wrapper_int(){let e=ft._zpp;return this.outer_int==null&&(ft.internal=!0,this.outer_int=ft._createIntCb(),ft.internal=!1,this.outer_int.zpp_inner=this),this.wrap_arbiters==null?this.wrap_arbiters=e.util.ZPP_ArbiterList.get(this.set.arbiters,!0):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=!0,this.wrap_arbiters.zpp_inner.at_ite=null,this.outer_int}push(e){this.prev!=null?this.prev.next=e:this.next=e,e.prev=this.prev,e.next=null,this.prev=e,this.length++}push_rev(e){this.next!=null?this.next.prev=e:this.prev=e,e.next=this.next,e.prev=null,this.next=e,this.length++}pop(){let e=this.next;return this.next=e.next,this.next==null?this.prev=null:this.next.prev=null,this.length--,e}pop_rev(){let e=this.prev;return this.prev=e.prev,this.prev==null?this.next=null:this.prev.next=null,this.length--,e}empty(){return this.next==null}clear(){for(;!this.empty();)this.pop()}splice(e){let t=e.next;return e.prev==null?(this.next=e.next,this.next!=null?this.next.prev=null:this.prev=null):(e.prev.next=e.next,e.next!=null?e.next.prev=e.prev:this.prev=e.prev),this.length--,t}rotateL(){this.push(this.pop())}rotateR(){this.push_rev(this.pop_rev())}cycleNext(e){return e.next==null?this.next:e.next}cyclePrev(e){return e.prev==null?this.prev:e.prev}at(e){let t=this.next;for(;e--!=0;)t=t.next;return t}rev_at(e){let t=this.prev;for(;e--!=0;)t=t.prev;return t}free(){this.int1=this.int2=null,this.body=null,this.constraint=null,this.listener=null,this.wrap_arbiters!=null&&(this.wrap_arbiters.zpp_inner.inner=null),this.set=null}alloc(){}genarbs(){let e=ft._zpp;this.wrap_arbiters==null?this.wrap_arbiters=e.util.ZPP_ArbiterList.get(this.set.arbiters,!0):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=!0,this.wrap_arbiters.zpp_inner.at_ite=null}};ft.__name__=["zpp_nape","callbacks","ZPP_Callback"],ft._nape=null,ft._zpp=null,ft.internal=!1,ft.zpp_pool=null,ft._createBodyCb=null,ft._createConCb=null,ft._createIntCb=null,ft._createPreCb=null;var Gt=ft;var Rt=class Rt{constructor(){this.count=0;this.next=null;this.id=0;this.manager=null;this.cbpairs=null;this.zip_listeners=!1;this.zip_bodylisteners=!1;this.zip_conlisteners=!1;this.interactors=null;this.wrap_interactors=null;this.constraints=null;this.wrap_constraints=null;let e=Rt._zpp;this.cbTypes=new e.util.ZNPList_ZPP_CbType,this.listeners=new e.util.ZNPList_ZPP_InteractionListener,this.zip_listeners=!0,this.bodylisteners=new e.util.ZNPList_ZPP_BodyListener,this.zip_bodylisteners=!0,this.conlisteners=new e.util.ZNPList_ZPP_ConstraintListener,this.zip_conlisteners=!0,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.interactors=new e.util.ZNPList_ZPP_Interactor,this.id=e.ZPP_ID.CbSet(),this.cbpairs=new e.util.ZNPList_ZPP_CbSetPair}static setlt(e,t){let n=e.cbTypes.head,l=t.cbTypes.head;for(;n!=null&&l!=null;){let s=n.elt,i=l.elt;if(s.id<i.id)return!0;if(i.id<s.id)return!1;n=n.next,l=l.next}return l!=null?n==null:!1}static get(e){let t;Rt.zpp_pool==null?t=new Rt:(t=Rt.zpp_pool,Rt.zpp_pool=t.next,t.next=null);let n=null,l=e.head;for(;l!=null;){let s=l.elt;n=t.cbTypes.insert(n,s),s.cbsets.add(t),l=l.next}return t}static compatible(e,t,n){let l,s=e.options1,i=t.cbTypes;if(s.nonemptyintersection(i,s.includes)&&!s.nonemptyintersection(i,s.excludes)){let o=e.options2,r=n.cbTypes;l=o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)}else l=!1;if(l)return!0;{let o=e.options2,r=t.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=e.options1,p=n.cbTypes;return a.nonemptyintersection(p,a.includes)?!a.nonemptyintersection(p,a.excludes):!1}else return!1}}static findOrCreatePair(e,t){let n=Rt._zpp,l=null,i=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;i!=null;){let o=i.elt;if(o.a==e&&o.b==t||o.a==t&&o.b==e){l=o;break}i=i.next}if(l==null){let o;n.callbacks.ZPP_CbSetPair.zpp_pool==null?o=new n.callbacks.ZPP_CbSetPair:(o=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=o.next,o.next=null),o.zip_listeners=!0,Rt.setlt(e,t)?(o.a=e,o.b=t):(o.a=t,o.b=e),l=o,e.cbpairs.add(l),t!=e&&t.cbpairs.add(l)}return l.zip_listeners&&(l.zip_listeners=!1,l.__validate()),l}static empty_intersection(e,t){return Rt.findOrCreatePair(e,t).listeners.head==null}static single_intersection(e,t,n){let s=Rt.findOrCreatePair(e,t).listeners.head;return s!=null&&s.elt==n?s.next==null:!1}static find_all(e,t,n,l){let i=Rt.findOrCreatePair(e,t).listeners.head;for(;i!=null;){let o=i.elt;o.event==n&&l(o),i=i.next}}increment(){this.count++}decrement(){return--this.count==0}invalidate_pairs(){let e=this.cbpairs.head;for(;e!=null;){let t=e.elt;t.zip_listeners=!0,e=e.next}}invalidate_listeners(){this.zip_listeners=!0,this.invalidate_pairs()}validate_listeners(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners())}realvalidate_listeners(){let e=Rt._zpp;this.listeners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,l=null,s=this.listeners.head,i=n.listeners.head;for(;i!=null;){let o=i.elt;if(s!=null&&s.elt==o)i=i.next,l=s,s=s.next;else{let r;if(s!=null){let a=s.elt;r=o.precedence>a.precedence||o.precedence==a.precedence&&o.id>a.id}else r=!0;if(r){if(o.space==this.manager.space){let a=this.listeners,p;e.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?p=new e.util.ZNPNode_ZPP_InteractionListener:(p=e.util.ZNPNode_ZPP_InteractionListener.zpp_pool,e.util.ZNPNode_ZPP_InteractionListener.zpp_pool=p.next,p.next=null),p.elt=o;let c=p;l==null?(c.next=a.head,a.head=c):(c.next=l.next,l.next=c),a.pushmod=a.modified=!0,a.length++,l=c}i=i.next}else l=s,s=s.next}}t=t.next}}invalidate_bodylisteners(){this.zip_bodylisteners=!0}validate_bodylisteners(){this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners())}realvalidate_bodylisteners(){let e=Rt._zpp;this.bodylisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,l=null,s=this.bodylisteners.head,i=n.bodylisteners.head;for(;i!=null;){let o=i.elt;if(s!=null&&s.elt==o)i=i.next,l=s,s=s.next;else{let r;if(s!=null){let a=s.elt;r=o.precedence>a.precedence||o.precedence==a.precedence&&o.id>a.id}else r=!0;if(r){let a=o.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&o.space==this.manager.space){let p=this.bodylisteners,c;e.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_BodyListener:(c=e.util.ZNPNode_ZPP_BodyListener.zpp_pool,e.util.ZNPNode_ZPP_BodyListener.zpp_pool=c.next,c.next=null),c.elt=o;let u=c;l==null?(u.next=p.head,p.head=u):(u.next=l.next,l.next=u),p.pushmod=p.modified=!0,p.length++,l=u}i=i.next}else l=s,s=s.next}}t=t.next}}invalidate_conlisteners(){this.zip_conlisteners=!0}validate_conlisteners(){this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}realvalidate_conlisteners(){let e=Rt._zpp;this.conlisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,l=null,s=this.conlisteners.head,i=n.conlisteners.head;for(;i!=null;){let o=i.elt;if(s!=null&&s.elt==o)i=i.next,l=s,s=s.next;else{let r;if(s!=null){let a=s.elt;r=o.precedence>a.precedence||o.precedence==a.precedence&&o.id>a.id}else r=!0;if(r){let a=o.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&o.space==this.manager.space){let p=this.conlisteners,c;e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_ConstraintListener:(c=e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=c.next,c.next=null),c.elt=o;let u=c;l==null?(u.next=p.head,p.head=u):(u.next=l.next,l.next=u),p.pushmod=p.modified=!0,p.length++,l=u}i=i.next}else l=s,s=s.next}}t=t.next}}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners()),this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners()),this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}addConstraint(e){this.constraints.add(e)}addInteractor(e){this.interactors.add(e)}remConstraint(e){this.constraints.remove(e)}remInteractor(e){this.interactors.remove(e)}free(){for(this.listeners.clear(),this.zip_listeners=!0,this.bodylisteners.clear(),this.zip_bodylisteners=!0,this.conlisteners.clear(),this.zip_conlisteners=!0;this.cbTypes.head!=null;)this.cbTypes.pop_unsafe().cbsets.remove(this)}alloc(){}};Rt.__name__=["zpp_nape","callbacks","ZPP_CbSet"],Rt._zpp=null,Rt.zpp_pool=null;var zt=Rt;var Bn=class Bn{constructor(){this.a=null;this.b=null;this.next=null;this.zip_listeners=!1;this.listeners=null;let e=Bn._zpp;this.listeners=new e.util.ZNPList_ZPP_InteractionListener}static get(e,t){let n=Bn._zpp,l;return Bn.zpp_pool==null?l=new Bn:(l=Bn.zpp_pool,Bn.zpp_pool=l.next,l.next=null),l.zip_listeners=!0,n.callbacks.ZPP_CbSet.setlt(e,t)?(l.a=e,l.b=t):(l.a=t,l.b=e),l}static setlt(e,t){let n=Bn._zpp;return n.callbacks.ZPP_CbSet.setlt(e.a,t.a)?!0:e.a==t.a?n.callbacks.ZPP_CbSet.setlt(e.b,t.b):!1}free(){this.a=this.b=null,this.listeners.clear()}alloc(){this.zip_listeners=!0}compatible(e){let t,n=e.options1,l=this.a.cbTypes;if(n.nonemptyintersection(l,n.includes)&&!n.nonemptyintersection(l,n.excludes)){let s=e.options2,i=this.b.cbTypes;t=s.nonemptyintersection(i,s.includes)&&!s.nonemptyintersection(i,s.excludes)}else t=!1;if(t)return!0;{let s=e.options2,i=this.a.cbTypes;if(s.nonemptyintersection(i,s.includes)&&!s.nonemptyintersection(i,s.excludes)){let o=e.options1,r=this.b.cbTypes;return o.nonemptyintersection(r,o.includes)?!o.nonemptyintersection(r,o.excludes):!1}else return!1}}invalidate(){this.zip_listeners=!0}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.__validate())}__validate(){this.listeners.clear();let e=this.a.listeners.head,t=this.b.listeners.head;for(;e!=null&&t!=null;){let n=e.elt,l=t.elt;if(n==l){let s,i,o=n.options1,r=this.a.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=n.options2,p=this.b.cbTypes;i=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else i=!1;if(i)s=!0;else{let a=n.options2,p=this.a.cbTypes;if(a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)){let c=n.options1,u=this.b.cbTypes;s=c.nonemptyintersection(u,c.includes)&&!c.nonemptyintersection(u,c.excludes)}else s=!1}s&&this.listeners.add(n),e=e.next,t=t.next}else n.precedence>l.precedence||n.precedence==l.precedence&&n.id>l.id?e=e.next:t=t.next}}empty_intersection(){return this.listeners.head==null}single_intersection(e){let t=this.listeners.head;return t!=null&&t.elt==e?t.next==null:!1}forall(e,t){let n=this.listeners.head;for(;n!=null;){let l=n.elt;l.event==e&&t(l),n=n.next}}};Bn.__name__=["zpp_nape","callbacks","ZPP_CbSetPair"],Bn._zpp=null,Bn.zpp_pool=null;var Ne=Bn;var tn=class tn{constructor(){this.outer=null;this.userData=null;this.id=0;this.cbsets=null;this.interactors=null;this.wrap_interactors=null;this.constraints=null;this.wrap_constraints=null;this.listeners=null;this.bodylisteners=null;this.conlisteners=null;let e=tn._zpp;this.id=e.ZPP_ID.CbType(),this.listeners=new e.util.ZNPList_ZPP_InteractionListener,this.bodylisteners=new e.util.ZNPList_ZPP_BodyListener,this.conlisteners=new e.util.ZNPList_ZPP_ConstraintListener,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.interactors=new e.util.ZNPList_ZPP_Interactor,this.cbsets=new e.util.ZNPList_ZPP_CbSet}static _initEnums(e){tn.ANY_SHAPE=new e.callbacks.CbType,tn.ANY_BODY=new e.callbacks.CbType,tn.ANY_COMPOUND=new e.callbacks.CbType,tn.ANY_CONSTRAINT=new e.callbacks.CbType}static setlt(e,t){return e.id<t.id}addInteractor(e){this.interactors.add(e)}remInteractor(e){this.interactors.remove(e)}addConstraint(e){this.constraints.add(e)}remConstraint(e){this.constraints.remove(e)}addint(e){let t=tn._zpp,n=null,l=this.listeners.head;for(;l!=null;){let r=l.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.id)break;n=l,l=l.next}let s=this.listeners,i;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?i=new t.util.ZNPNode_ZPP_InteractionListener:(i=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=i.next,i.next=null),i.elt=e,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++;let o=this.cbsets.head;for(;o!=null;)o.elt.zip_listeners=!0,o.elt.invalidate_pairs(),o=o.next}removeint(e){this.listeners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_listeners=!0,t.elt.invalidate_pairs(),t=t.next}invalidateint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_listeners=!0,e.elt.invalidate_pairs(),e=e.next}addbody(e){let t=tn._zpp,n=null,l=this.bodylisteners.head;for(;l!=null;){let r=l.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.id)break;n=l,l=l.next}let s=this.bodylisteners,i;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?i=new t.util.ZNPNode_ZPP_BodyListener:(i=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=i.next,i.next=null),i.elt=e,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++;let o=this.cbsets.head;for(;o!=null;)o.elt.zip_bodylisteners=!0,o=o.next}removebody(e){this.bodylisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_bodylisteners=!0,t=t.next}invalidatebody(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_bodylisteners=!0,e=e.next}addconstraint(e){let t=tn._zpp,n=null,l=this.conlisteners.head;for(;l!=null;){let r=l.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.id)break;n=l,l=l.next}let s=this.conlisteners,i;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?i=new t.util.ZNPNode_ZPP_ConstraintListener:(i=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=i.next,i.next=null),i.elt=e,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++;let o=this.cbsets.head;for(;o!=null;)o.elt.zip_conlisteners=!0,o=o.next}removeconstraint(e){this.conlisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_conlisteners=!0,t=t.next}invalidateconstraint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_conlisteners=!0,e=e.next}};tn.__name__=["zpp_nape","callbacks","ZPP_CbType"],tn._zpp=null,tn.ANY_SHAPE=null,tn.ANY_BODY=null,tn.ANY_COMPOUND=null,tn.ANY_CONSTRAINT=null;var gn=tn;var Kn=class Kn{constructor(){this.space=null;this.interaction=null;this.constraint=null;this.body=null;this.precedence=0;this.event=0;this.type=0;this.id=0;this.outer=null;this.id=fn.Listener()}static setlt(e,t){return e.precedence<=t.precedence?e.precedence==t.precedence?e.id>t.id:!1:!0}swapEvent(e){}invalidate_precedence(){}addedToSpace(){}removedFromSpace(){}static _initEnums(e,t){let n=()=>{t.internal=!0;let s=new e.callbacks.ListenerType;return t.internal=!1,s};t.ListenerType_BODY==null&&(t.ListenerType_BODY=n()),t.ListenerType_CONSTRAINT==null&&(t.ListenerType_CONSTRAINT=n()),t.ListenerType_INTERACTION==null&&(t.ListenerType_INTERACTION=n()),t.ListenerType_PRE==null&&(t.ListenerType_PRE=n()),Kn.types=[t.ListenerType_BODY,t.ListenerType_CONSTRAINT,t.ListenerType_INTERACTION,t.ListenerType_PRE];let l=()=>{t.internal=!0;let s=new e.callbacks.CbEvent;return t.internal=!1,s};t.CbEvent_BEGIN==null&&(t.CbEvent_BEGIN=l()),t.CbEvent_END==null&&(t.CbEvent_END=l()),t.CbEvent_WAKE==null&&(t.CbEvent_WAKE=l()),t.CbEvent_SLEEP==null&&(t.CbEvent_SLEEP=l()),t.CbEvent_BREAK==null&&(t.CbEvent_BREAK=l()),t.CbEvent_PRE==null&&(t.CbEvent_PRE=l()),t.CbEvent_ONGOING==null&&(t.CbEvent_ONGOING=l()),Kn.events=[t.CbEvent_BEGIN,t.CbEvent_END,t.CbEvent_WAKE,t.CbEvent_SLEEP,t.CbEvent_BREAK,t.CbEvent_PRE,t.CbEvent_ONGOING]}};Kn.__name__=["zpp_nape","callbacks","ZPP_Listener"],Kn._nape=null,Kn._zpp=null,Kn.internal=!1,Kn.types=[],Kn.events=[];var qt=Kn;var Ds=class extends qt{constructor(t,n,l){super();this.handler=null;this.options=null;this.outer_zn=null;this.event=n,this.handler=l,this.body=this,this.type=0,this.options=t.zpp_inner}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=qt._zpp;this.options.handler=(l,s,i)=>this.cbtype_change(l,s,i);let n=this.options.includes.head;for(;n!=null;){let l=n.elt,s=null,i=l.bodylisteners.head;for(;i!=null;){let c=i.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;s=i,i=i.next}let o=l.bodylisteners,r;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?r=new t.util.ZNPNode_ZPP_BodyListener:(r=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=r.next,r.next=null),r.elt=this;let a=r;s==null?(a.next=o.head,o.head=a):(a.next=s.next,s.next=a),o.pushmod=o.modified=!0,o.length++;let p=l.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_bodylisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.bodylisteners.remove(this);let l=n.cbsets.head;for(;l!=null;){let s=l.elt;s.zip_bodylisteners=!0,l=l.next}t=t.next}this.options.handler=null}cbtype_change(t,n,l){this.removedFromSpace();let s=this.options;n?l?s.effect_change(t,!0,!0):s.includes.remove(t):l?s.effect_change(t,!1,!0):s.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3)throw new Error("Error: BodyListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};Ds.__name__=["zpp_nape","callbacks","ZPP_BodyListener"];var Fs=class extends qt{constructor(t,n,l){super();this.handler=null;this.options=null;this.outer_zn=null;this.event=n,this.handler=l,this.constraint=this,this.type=1,this.options=t.zpp_inner}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=qt._zpp;this.options.handler=(l,s,i)=>this.cbtype_change(l,s,i);let n=this.options.includes.head;for(;n!=null;){let l=n.elt,s=null,i=l.conlisteners.head;for(;i!=null;){let c=i.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;s=i,i=i.next}let o=l.conlisteners,r;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?r=new t.util.ZNPNode_ZPP_ConstraintListener:(r=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=r.next,r.next=null),r.elt=this;let a=r;s==null?(a.next=o.head,o.head=a):(a.next=s.next,s.next=a),o.pushmod=o.modified=!0,o.length++;let p=l.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_conlisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.conlisteners.remove(this);let l=n.cbsets.head;for(;l!=null;){let s=l.elt;s.zip_conlisteners=!0,l=l.next}t=t.next}this.options.handler=null}cbtype_change(t,n,l){this.removedFromSpace();let s=this.options;n?l?s.effect_change(t,!0,!0):s.includes.remove(t):l?s.effect_change(t,!1,!0):s.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3&&t!=4)throw new Error("Error: ConstraintListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};Fs.__name__=["zpp_nape","callbacks","ZPP_ConstraintListener"];var gt=class gt extends qt{constructor(t,n,l,s){super();this.outer_zni=null;this.outer_znp=null;this.itype=0;this.handleri=null;this.allowSleepingCallbacks=!1;this.pure=!1;this.handlerp=null;this.type=s,this.interaction=this,this.event=l,this.options1=t.zpp_inner,this.options2=n.zpp_inner,this.allowSleepingCallbacks=!1}setInteractionType(t){this.itype=t}wake(){let t=this.options1.includes.head,n=this.options2.includes.head;for(;t!=null&&n!=null;){let l=t.elt,s=n.elt;if(l==s){let i=l.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next;t=t.next,n=n.next}else if(l.id<s.id){let i=l.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next;t=t.next}else{let i=s.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next;n=n.next}}for(;t!=null;){let l=t.elt.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;t=t.next}for(;n!=null;){let l=n.elt.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;n=n.next}}CbSetset(t,n,l){let s=qt._zpp,i=gt.UCbSet,o=gt.VCbSet,r=gt.WCbSet,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,u=p.elt;if(c==u){let h=this._allocCbSetNode(s);h.elt=c,h.next=r.head,r.head=h,r.modified=!0,r.length++,a=a.next,p=p.next}else if(s.callbacks.ZPP_CbSet.setlt(c,u)){let h=this._allocCbSetNode(s);h.elt=c,h.next=i.head,i.head=h,i.modified=!0,i.length++,a=a.next}else{let h=this._allocCbSetNode(s);h.elt=u,h.next=o.head,o.head=h,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbSetNode(s);c.elt=a.elt,c.next=i.head,i.head=c,i.modified=!0,i.length++,a=a.next}for(;p!=null;){let c=this._allocCbSetNode(s);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.length++,p=p.next}for(;i.head!=null;){let c=i.pop_unsafe(),u=n.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;o.head!=null;){let c=o.pop_unsafe(),u=r.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;r.head!=null;){let c=r.pop_unsafe();l(c,c);let u=r.head;for(;u!=null;)l(c,u.elt),u=u.next}}CbTypeset(t,n,l){let s=qt._zpp,i=gt.UCbType,o=gt.VCbType,r=gt.WCbType,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,u=p.elt;if(c==u){let h=this._allocCbTypeNode(s);h.elt=c,h.next=r.head,r.head=h,r.modified=!0,r.length++,a=a.next,p=p.next}else if(c.id<u.id){let h=this._allocCbTypeNode(s);h.elt=c,h.next=i.head,i.head=h,i.modified=!0,i.length++,a=a.next}else{let h=this._allocCbTypeNode(s);h.elt=u,h.next=o.head,o.head=h,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbTypeNode(s);c.elt=a.elt,c.next=i.head,i.head=c,i.modified=!0,i.length++,a=a.next}for(;p!=null;){let c=this._allocCbTypeNode(s);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.length++,p=p.next}for(;i.head!=null;){let c=i.pop_unsafe(),u=n.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;o.head!=null;){let c=o.pop_unsafe(),u=r.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;r.head!=null;){let c=r.pop_unsafe();l(c,c);let u=r.head;for(;u!=null;)l(c,u.elt),u=u.next}}with_uniquesets(t){let n=qt._zpp,l;if(n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool==null?l=new n.util.ZPP_Set_ZPP_CbSetPair:(l=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=l.next,l.next=null),l.lt=n.callbacks.ZPP_CbSetPair.setlt,this.CbTypeset(this.options1.includes,this.options2.includes,(i,o)=>{this.CbSetset(i.cbsets,o.cbsets,(r,a)=>{if(r.validate(),a.validate(),n.callbacks.ZPP_CbSet.single_intersection(r,a,this)){let p;n.callbacks.ZPP_CbSetPair.zpp_pool==null?p=new n.callbacks.ZPP_CbSetPair:(p=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=p.next,p.next=null),p.zip_listeners=!0,n.callbacks.ZPP_CbSet.setlt(r,a)?(p.a=r,p.b=a):(p.a=a,p.b=r),l.try_insert(p)}})}),l.parent!=null){let i=l.parent;for(;i!=null;)if(i.prev!=null)i=i.prev;else if(i.next!=null)i=i.next;else{let o=i.data;t?this.space.freshListenerType(o.a,o.b):this.space.nullListenerType(o.a,o.b);let r=o;r.a=r.b=null,r.listeners.clear(),r.next=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=r;let a=i.parent;a!=null&&(i==a.prev?a.prev=null:a.next=null,i.parent=null);let p=i;p.data=null,p.lt=null,p.swapped=null,p.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=p,i=a}l.parent=null}let s=l;s.data=null,s.lt=null,s.swapped=null,s.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=s}with_union(t){let n=this.options1.includes.head,l=this.options2.includes.head;for(;n!=null&&l!=null;){let s=n.elt,i=l.elt;s==i?(t(s),n=n.next,l=l.next):s.id<i.id?(t(s),n=n.next):(t(i),l=l.next)}for(;n!=null;)t(n.elt),n=n.next;for(;l!=null;)t(l.elt),l=l.next}addedToSpace(){let t=qt._zpp,n=this.type==3;this.with_union(l=>{let s=null,i=l.listeners.head;for(;i!=null;){let c=i.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;s=i,i=i.next}let o=l.listeners,r;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?r=new t.util.ZNPNode_ZPP_InteractionListener:(r=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=r.next,r.next=null),r.elt=this;let a=r;s==null?(a.next=o.head,o.head=a):(a.next=s.next,s.next=a),o.pushmod=o.modified=!0,o.length++;let p=l.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_listeners=!0,c.invalidate_pairs(),p=p.next}if(n){let c=l.interactors.head;for(;c!=null;)c.elt.wake(),c=c.next}}),this.options1.handler=(l,s,i)=>this.cbtype_change1(l,s,i),this.options2.handler=(l,s,i)=>this.cbtype_change2(l,s,i),this.with_uniquesets(!0)}removedFromSpace(){this.with_uniquesets(!1);let t=this.type==3;this.with_union(n=>{n.listeners.remove(this);let l=n.cbsets.head;for(;l!=null;){let s=l.elt;s.zip_listeners=!0,s.invalidate_pairs(),l=l.next}if(t){let s=n.interactors.head;for(;s!=null;)s.elt.wake(),s=s.next}}),this.options1.handler=null,this.options2.handler=null}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}cbtype_change1(t,n,l){this.cbtype_change(this.options1,t,n,l)}cbtype_change2(t,n,l){this.cbtype_change(this.options2,t,n,l)}cbtype_change(t,n,l,s){this.removedFromSpace(),l?s?t.effect_change(n,!0,!0):t.includes.remove(n):s?t.effect_change(n,!1,!0):t.excludes.remove(n),this.addedToSpace()}swapEvent(t){if(this.type==3)throw new Error("Error: PreListener event can only be PRE");if(t!=0&&t!=1&&t!=6)throw new Error("Error: InteractionListener event must be either BEGIN, END, ONGOING");this.removedFromSpace(),this.event=t,this.addedToSpace()}_allocCbSetNode(t){let n;return t.util.ZNPNode_ZPP_CbSet.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbSet:(n=t.util.ZNPNode_ZPP_CbSet.zpp_pool,t.util.ZNPNode_ZPP_CbSet.zpp_pool=n.next,n.next=null),n}_allocCbTypeNode(t){let n;return t.util.ZNPNode_ZPP_CbType.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbType:(n=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=n.next,n.next=null),n}static _initStatics(t){gt.UCbSet=new t.util.ZNPList_ZPP_CbSet,gt.VCbSet=new t.util.ZNPList_ZPP_CbSet,gt.WCbSet=new t.util.ZNPList_ZPP_CbSet,gt.UCbType=new t.util.ZNPList_ZPP_CbType,gt.VCbType=new t.util.ZNPList_ZPP_CbType,gt.WCbType=new t.util.ZNPList_ZPP_CbType}};gt.__name__=["zpp_nape","callbacks","ZPP_InteractionListener"],gt.UCbSet=null,gt.VCbSet=null,gt.WCbSet=null,gt.UCbType=null,gt.VCbType=null,gt.WCbType=null;var Cl=gt;var Dn=class Dn{constructor(){this.outer=null;this.handler=null;this.includes=null;this.excludes=null;this.wrap_includes=null;this.wrap_excludes=null;let e=Dn._zpp;this.includes=new e.util.ZNPList_ZPP_CbType,this.excludes=new e.util.ZNPList_ZPP_CbType}static argument(e){let t=Dn._nape;return e==null?new t.callbacks.OptionType:e instanceof t.callbacks.OptionType?e:new t.callbacks.OptionType().including(e)}setup_includes(){let e=Dn._zpp;this.wrap_includes=e.util.ZPP_CbTypeList.get(this.includes,!0)}setup_excludes(){let e=Dn._zpp;this.wrap_excludes=e.util.ZPP_CbTypeList.get(this.excludes,!0)}excluded(e){return this.nonemptyintersection(e,this.excludes)}included(e){return this.nonemptyintersection(e,this.includes)}compatible(e){return this.nonemptyintersection(e,this.includes)?!this.nonemptyintersection(e,this.excludes):!1}nonemptyintersection(e,t){let n=!1,l=e.head,s=t.head;for(;s!=null&&l!=null;){let i=s.elt,o=l.elt;if(i===o){n=!0;break}else i.id<o.id?s=s.next:l=l.next}return n}insertOrdered(e,t){let n=Dn._zpp,l=null,s=e.head;for(;s!=null;){let o=s.elt;if(t.id<o.id)break;l=s,s=s.next}let i;n.util.ZNPNode_ZPP_CbType.zpp_pool==null?i=new n.util.ZNPNode_ZPP_CbType:(i=n.util.ZNPNode_ZPP_CbType.zpp_pool,n.util.ZNPNode_ZPP_CbType.zpp_pool=i.next,i.next=null),i.elt=t,l==null?(i.next=e.head,e.head=i):(i.next=l.next,l.next=i),e.pushmod=e.modified=!0,e.length++}effect_change(e,t,n){t?n?this.insertOrdered(this.includes,e):this.includes.remove(e):n?this.insertOrdered(this.excludes,e):this.excludes.remove(e)}append_type(e,t){e===this.includes?this.includes.has(t)||(this.excludes.has(t)?this.handler!=null?this.handler(t,!1,!1):this.excludes.remove(t):this.handler!=null?this.handler(t,!0,!0):this.insertOrdered(this.includes,t)):this.excludes.has(t)||(this.includes.has(t)?this.handler!=null?this.handler(t,!0,!1):this.includes.remove(t):this.handler!=null?this.handler(t,!1,!0):this.insertOrdered(this.excludes,t))}set(e){if(e!==this){for(;this.includes.head!=null;)this.append_type(this.excludes,this.includes.head.elt);for(;this.excludes.head!=null;)this.append_type(this.includes,this.excludes.head.elt);let t=e.excludes.head;for(;t!=null;){let l=t.elt;this.append_type(this.excludes,l),t=t.next}let n=e.includes.head;for(;n!=null;){let l=n.elt;this.append_type(this.includes,l),n=n.next}}return this}append(e,t){let n=Dn._nape;if(t==null)throw new Error("Error: Cannot append null, only CbType and CbType list values");if(t instanceof n.callbacks.CbType){let l=t;this.append_type(e,l.zpp_inner)}else if(t instanceof n.callbacks.CbTypeList){let l=t;l.zpp_inner.valmod();let s=n.callbacks.CbTypeIterator.get(l);for(;;){s.zpp_inner.zpp_inner.valmod();let i=s.zpp_inner;i.zpp_inner.valmod(),i.zpp_inner.zip_length&&(i.zpp_inner.zip_length=!1,i.zpp_inner.user_length=i.zpp_inner.inner.length);let o=i.zpp_inner.user_length;s.zpp_critical=!0;let r;if(s.zpp_i<o?r=!0:(s.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=s,s.zpp_inner=null,r=!1),!r)break;s.zpp_critical=!1;let a=s.zpp_inner.at(s.zpp_i++);this.append_type(e,a.zpp_inner)}}else if(t instanceof Array){let l=t,s=0;for(;s<l.length;){let i=l[s];if(++s,!(i instanceof n.callbacks.CbType))throw new Error("Error: Cannot append non-CbType or CbType list value");let o=i;this.append_type(e,o.zpp_inner)}}else throw new Error("Error: Cannot append non-CbType or CbType list value")}};Dn.__name__=["zpp_nape","callbacks","ZPP_OptionType"],Dn._nape=null,Dn._zpp=null;var zs=Dn;var un=class un{constructor(){this.outer=null;this.id=0;this.userData=null;this.compound=null;this.space=null;this.active=!1;this.stiff=!1;this.frequency=0;this.damping=0;this.maxForce=0;this.maxError=0;this.breakUnderForce=!1;this.breakUnderError=!1;this.removeOnBreak=!1;this.component=null;this.ignore=!1;this.__velocity=!1;this.cbTypes=null;this.cbSet=null;this.wrap_cbTypes=null;this.pre_dt=-1;this.__class__=un;this._initBase()}_initBase(){let e=un._zpp;this.id=fn.Constraint(),this.stiff=!0,this.active=!0,this.ignore=!1,this.frequency=10,this.damping=1,this.maxForce=1/0,this.maxError=1/0,this.breakUnderForce=!1,this.removeOnBreak=!0,this.pre_dt=-1,this.cbTypes=new e.util.ZNPList_ZPP_CbType}clear(){}activeBodies(){}inactiveBodies(){}clearcache(){}validate(){}wake_connected(){}forest(){}broken(){}warmStart(){}draw(e){}pair_exists(e,t){return!1}preStep(e){return!1}applyImpulseVel(){return!1}applyImpulsePos(){return!1}copy(e,t){return null}immutable_midstep(e){if(this.space!=null&&this.space.midstep)throw new Error("Error: Constraint::"+e+" cannot be set during space step()")}setupcbTypes(){let e=un._zpp;this.wrap_cbTypes=e.util.ZPP_CbTypeList.get(this.cbTypes),this.wrap_cbTypes.zpp_inner.adder=this.wrap_cbTypes_adder.bind(this),this.wrap_cbTypes.zpp_inner.subber=this.wrap_cbTypes_subber.bind(this),this.wrap_cbTypes.zpp_inner.dontremove=!0,this.wrap_cbTypes.zpp_inner._modifiable=this.immutable_cbTypes.bind(this)}immutable_cbTypes(){this.immutable_midstep("Constraint::cbTypes")}wrap_cbTypes_subber(e){let t=e.zpp_inner;this.cbTypes.has(t)&&(this.space!=null&&(this.dealloc_cbSet(),t.constraints.remove(this)),this.cbTypes.remove(t),this.space!=null&&(this.alloc_cbSet(),this.wake()))}wrap_cbTypes_adder(e){return this.insert_cbtype(e.zpp_inner),!1}insert_cbtype(e){let t=un._zpp;if(!this.cbTypes.has(e)){this.space!=null&&(this.dealloc_cbSet(),e.constraints.add(this));let n=null,l=this.cbTypes.head;for(;l!=null;){let r=l.elt;if(e.id<r.id)break;n=l,l=l.next}let s=this.cbTypes,i;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?i=new t.util.ZNPNode_ZPP_CbType:(i=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=i.next,i.next=null),i.elt=e;let o=i;n==null?(o.next=s.head,s.head=o):(o.next=n.next,n.next=o),s.pushmod=s.modified=!0,s.length++,this.space!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){(this.cbSet=this.space.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.constraints.add(this))}dealloc_cbSet(){let e=un._zpp;if(this.cbSet!=null){if(this.cbSet.constraints.remove(this),--this.cbSet.count==0){this.space.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=!0,t.bodylisteners.clear(),t.zip_bodylisteners=!0,t.conlisteners.clear(),t.zip_conlisteners=!0;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=e.callbacks.ZPP_CbSet.zpp_pool,e.callbacks.ZPP_CbSet.zpp_pool=t}this.cbSet=null}}activate(){this.space!=null&&this.activeInSpace()}deactivate(){this.space!=null&&this.inactiveOrOutSpace()}addedToSpace(){this.active&&this.activeInSpace(),this.activeBodies();let e=this.cbTypes.head;for(;e!=null;)e.elt.constraints.add(this),e=e.next}removedFromSpace(){this.active&&this.inactiveOrOutSpace(),this.inactiveBodies();let e=this.cbTypes.head;for(;e!=null;)e.elt.constraints.remove(this),e=e.next}activeInSpace(){let e=un._zpp;this.alloc_cbSet(),e.space.ZPP_Component.zpp_pool==null?this.component=new e.space.ZPP_Component:(this.component=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=this.component.next,this.component.next=null),this.component.isBody=!1,this.component.constraint=this}inactiveOrOutSpace(){let e=un._zpp;this.dealloc_cbSet();let t=this.component;t.body=null,t.constraint=null,t.next=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t,this.component=null}wake(){this.space!=null&&this.space.wake_constraint(this)}copyto(e){let t=un._nape,n=this.outer;n.zpp_inner.wrap_cbTypes==null&&n.zpp_inner.setupcbTypes();let l=n.zpp_inner.wrap_cbTypes;l.zpp_inner.valmod();let s=t.callbacks.CbTypeIterator.get(l);for(;;){s.zpp_inner.zpp_inner.valmod();let b=s.zpp_inner;b.zpp_inner.valmod(),b.zpp_inner.zip_length&&(b.zpp_inner.zip_length=!1,b.zpp_inner.user_length=b.zpp_inner.inner.length);let _=b.zpp_inner.user_length;s.zpp_critical=!0;let d;if(s.zpp_i<_?d=!0:(s.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=s,s.zpp_inner=null,d=!1),!d)break;s.zpp_critical=!1;let f=s.zpp_inner.at(s.zpp_i++);e.zpp_inner.wrap_cbTypes==null&&e.zpp_inner.setupcbTypes();let m=e.zpp_inner.wrap_cbTypes;m.zpp_inner.reverse_flag?m.push(f):m.unshift(f)}e.zpp_inner.removeOnBreak=n.zpp_inner.removeOnBreak;let i=n.zpp_inner.breakUnderError;e.zpp_inner.breakUnderError!=i&&(e.zpp_inner.breakUnderError=i,e.zpp_inner.wake());let o=n.zpp_inner.breakUnderForce;e.zpp_inner.breakUnderForce!=o&&(e.zpp_inner.breakUnderForce=o,e.zpp_inner.wake());let r=n.zpp_inner.maxError;if(r!==r)throw new Error("Error: Constraint::maxError cannot be NaN");if(r<0)throw new Error("Error: Constraint::maxError must be >=0");e.zpp_inner.maxError!=r&&(e.zpp_inner.maxError=r,e.zpp_inner.wake());let a=n.zpp_inner.maxForce;if(a!==a)throw new Error("Error: Constraint::maxForce cannot be NaN");if(a<0)throw new Error("Error: Constraint::maxForce must be >=0");e.zpp_inner.maxForce!=a&&(e.zpp_inner.maxForce=a,e.zpp_inner.wake());let p=n.zpp_inner.damping;if(p!==p)throw new Error("Error: Constraint::Damping cannot be Nan");if(p<0)throw new Error("Error: Constraint::Damping must be >=0");e.zpp_inner.damping!=p&&(e.zpp_inner.damping=p,e.zpp_inner.stiff||e.zpp_inner.wake());let c=n.zpp_inner.frequency;if(c!==c)throw new Error("Error: Constraint::Frequency cannot be NaN");if(c<=0)throw new Error("Error: Constraint::Frequency must be >0");e.zpp_inner.frequency!=c&&(e.zpp_inner.frequency=c,e.zpp_inner.stiff||e.zpp_inner.wake());let u=n.zpp_inner.stiff;e.zpp_inner.stiff!=u&&(e.zpp_inner.stiff=u,e.zpp_inner.wake());let h=n.zpp_inner.ignore;e.zpp_inner.ignore!=h&&(e.zpp_inner.ignore=h,e.zpp_inner.wake());let x=n.zpp_inner.active;e.zpp_inner.active!=x&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.woken=!1),e.zpp_inner.clearcache(),x?(e.zpp_inner.active=x,e.zpp_inner.activate(),e.zpp_inner.space!=null&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.sleeping=!0),e.zpp_inner.space.wake_constraint(e.zpp_inner,!0))):(e.zpp_inner.space!=null&&(e.zpp_inner.wake(),e.zpp_inner.space.live_constraints.remove(e.zpp_inner)),e.zpp_inner.active=x,e.zpp_inner.deactivate()))}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let l=t.parent;t.parent=n,n=t,t=l}for(;n!=null;){let l=n.parent;n.parent=t,n=l}return t}static _unionComponents(e,t){let n=un._findRoot(e),l=un._findRoot(t);n!=l&&(n.rank<l.rank?n.parent=l:n.rank>l.rank?l.parent=n:(l.parent=n,n.rank++))}};un.__name__=["zpp_nape","constraint","ZPP_Constraint"],un._nape=null,un._zpp=null;var ve=un;var Gs=class Gs{constructor(){this.id=0;this.bc=null;this.cb=null}static dict(e,t){let n=new Gs;return n.id=e,n.bc=t,n}static todo(e,t){let n=new Gs;return n.id=e,n.cb=t,n}};Gs.__name__=["zpp_nape","constraint","ZPP_CopyHelper"];var Fn=Gs;var Ps=class Ps extends ve{constructor(){super();this.outer_zn=null;this.ratio=0;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.scale=0;this.b1=null;this.b2=null;this.kMass=0;this.jAcc=0;this.jMax=0;this.gamma=0;this.bias=0;this.stepped=!1;this.ratio=1,this.jAcc=0,this.slack=!1,this.jMax=1/0,this.stepped=!1}is_slack(){let t=this.ratio*this.b2.rot-this.b1.rot;return this.equal?(this.scale=1,!1):t<this.jointMin?(this.scale=-1,!1):t>this.jointMax?(this.scale=1,!1):(this.scale=0,!0)}bodyImpulse(t){let n=me();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.scale*this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.scale*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let l=Ps._createFn(null,null,this.jointMin,this.jointMax,this.ratio);if(this.copyto(l),t!=null&&this.b1!=null){let s=null,i=0;for(;i<t.length;){let o=t[i];if(++i,o.id==this.b1.id){s=o.bc;break}}s!=null?l.zpp_inner.b1=s.zpp_inner:n.push(Fn.todo(this.b1.id,o=>{l.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let s=null,i=0;for(;i<t.length;){let o=t[i];if(++i,o.id==this.b2.id){s=o.bc;break}}s!=null?l.zpp_inner.b2=s.zpp_inner:n.push(Fn.todo(this.b2.id,o=>{l.zpp_inner.b2=o.zpp_inner}))}return l}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: AngleJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: AngleJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let l=this.b1.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let l=this.b2.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1,this.slack=!1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax;let l=this.ratio*this.b2.rot-this.b1.rot;this.equal?(l-=this.jointMax,this.slack=!1,this.scale=1):l<this.jointMin?(l=this.jointMin-l,this.scale=-1,this.slack=!1):l>this.jointMax?(l-=this.jointMax,this.scale=1,this.slack=!1):(this.scale=0,l=0,this.slack=!0);let s=l;if(!this.slack){if(this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&s*s>this.maxError*this.maxError)return!0;let i=2*Math.PI*this.frequency;this.gamma=1/(t*i*(2*this.damping+i*t));let o=1/(1+this.gamma),r=t*i*i*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-s*r,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){this.slack||(this.b1.angvel-=this.scale*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*this.jAcc)}applyImpulseVel(){if(this.slack)return!1;let t=this.scale*(this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel),n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,l=this.jAcc;return this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&(this.jAcc>this.jMax||this.jAcc<-this.jMax)?!0:(this.stiff||(this.jAcc>this.jMax?this.jAcc=this.jMax:this.jAcc<-this.jMax&&(this.jAcc=-this.jMax)),n=this.jAcc-l,this.b1.angvel-=this.scale*this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*n,!1)}applyImpulsePos(){let t=this.ratio*this.b2.rot-this.b1.rot,n;this.equal?(t-=this.jointMax,n=!1,this.scale=1):t<this.jointMin?(t=this.jointMin-t,this.scale=-1,n=!1):t>this.jointMax?(t-=this.jointMax,this.scale=1,n=!1):(this.scale=0,t=0,n=!0);let l=t;if(!n){if(this.breakUnderError&&l*l>this.maxError*this.maxError)return!0;let i=-(l*.5)*this.kMass;if(this.equal||i<0){let o=this.b1,r=-this.scale*i*this.b1.iinertia;if(o.rot+=r,r*r>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let c=r*r,u=1-.5*c,h=1-c*c/8,x=(u*o.axisx+r*o.axisy)*h;o.axisy=(u*o.axisy-r*o.axisx)*h,o.axisx=x}let a=this.b2,p=this.ratio*this.scale*i*this.b2.iinertia;if(a.rot+=p,p*p>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let c=p*p,u=1-.5*c,h=1-c*c/8,x=(u*a.axisx+p*a.axisy)*h;a.axisy=(u*a.axisy-p*a.axisx)*h,a.axisx=x}}}return!1}draw(t){}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let l=n*n,s=1-.5*l,i=1-l*l/8,o=(s*t.axisx+n*t.axisy)*i;t.axisy=(s*t.axisy-n*t.axisx)*i,t.axisx=o}}static _copyBody(t,n,l,s,i){if(t!=null&&l!=null){let o=null;for(let r=0;r<t.length;r++){let a=t[r];if(a.id==l.id){o=a.bc;break}}o!=null?s.zpp_inner_zn[i]=o.zpp_inner:n.push(Fn.todo(l.id,function(r){s.zpp_inner_zn[i]=r.zpp_inner}))}}};Ps.__name__=["zpp_nape","constraint","ZPP_AngleJoint"],Ps._wrapFn=null,Ps._createFn=null;var qe=Ps;var Et=class Et{constructor(){this.x=0;this.y=0;this.next=null;this.length=0;this.modified=!1;this.pushmod=!1;this._inuse=!1;this.weak=!1;this.outer=null;this._immutable=!1;this._isimmutable=null;this._validate=null;this._invalidate=null}static get(e,t,n){n==null&&(n=!1);let l;return Et.zpp_pool==null?l=new Et:(l=Et.zpp_pool,Et.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=n,l.x=e,l.y=t,l}validate(){this._validate!=null&&this._validate()}invalidate(){this._invalidate!=null&&this._invalidate(this)}immutable(){if(this._immutable)throw new Error("Error: Vec2 is immutable");this._isimmutable!=null&&this._isimmutable()}wrapper(){if(this.outer==null)if(Et._wrapFn)this.outer=Et._wrapFn(this);else{this.outer=new Et._nape.geom.Vec2;let e=this.outer.zpp_inner;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e._isimmutable=null,e._validate=null,e._invalidate=null,e.next=Et.zpp_pool,Et.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this._isimmutable=null,this._validate=null,this._invalidate=null}alloc(){this.weak=!1}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}inlined_add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;)this.add(t),t=t.next}insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}inlined_insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let l;t==null?(l=this.next,this.next=l.next,this.next==null&&(this.pushmod=!0)):(l=t.next,t.next=l.next,l.next==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e)return this.erase(t),!0;t=n,n=n.next}return!1}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let l;t==null?(l=this.next,this.next=l.next,this.next==null&&(this.pushmod=!0)):(l=t.next,t.next=l.next,l.next==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let l;return t==null?(l=this.next,this.next=l.next,this.next==null&&(this.pushmod=!0)):(l=t.next,t.next=l.next,l.next==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,!0}t=n,n=n.next}return!1}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=this.next;for(;t!=null;){if(t===e)return!0;t=t.next}return!1}inlined_has(e){let t=this.next;for(;t!=null;){if(t===e)return!0;t=t.next}return!1}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}copy(){let e=this.x,t=this.y,n;return Et.zpp_pool==null?n=new Et:(n=Et.zpp_pool,Et.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,n}toString(){return"{ x: "+this.x+" y: "+this.y+" }"}};Et.zpp_pool=null,Et.__name__=["zpp_nape","geom","ZPP_Vec2"],Et._nape=null,Et._zpp=null,Et._wrapFn=null;var le=Et;var ii=class ii extends ve{constructor(){super();this.outer_zn=null;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.nx=0;this.ny=0;this.cx1=0;this.cx2=0;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a1=null;this.wrap_a2=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),l=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),s=n*n+l*l;return s<ve._nape.Config.epsilon?t=!0:(s=Math.sqrt(s),this.equal||s<this.jointMin||s>this.jointMax?t=!1:t=!0),t}bodyImpulse(t){let n=ve._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAcc*this.nx,-this.jAcc*this.ny,-this.cx1*this.jAcc):n.geom.Vec3.get(this.jAcc*this.nx,this.jAcc*this.ny,this.cx2*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){this.wrap_a1=ii._setupAnchorVec2(this.a1localx,this.a1localy,this.validate_a1.bind(this),this.invalidate_a1.bind(this))}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){this.wrap_a2=ii._setupAnchorVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=ii._createFn(null,null,s,i.zpp_inner_zn.wrap_a2,this.jointMin,this.jointMax);return this.copyto(o),qe._copyBody(t,n,this.b1,o,"b1"),qe._copyBody(t,n,this.b2,o,"b2"),o}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: DistanceJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&ve._unionComponents(this.b1.component,this.component),this.b2.type==2&&ve._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.nx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.ny=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely);let l=this.nx*this.nx+this.ny*this.ny;if(l<ve._nape.Config.epsilon)this.nx=0,this.ny=0,l=0,this.slack=!0;else{l=Math.sqrt(l);let i=1/l;this.nx*=i,this.ny*=i,this.equal?(l-=this.jointMax,this.slack=!1):l<this.jointMin?(l=this.jointMin-l,this.nx=-this.nx,this.ny=-this.ny,this.slack=!1):l>this.jointMax?(l-=this.jointMax,this.slack=!1):(this.nx=0,this.ny=0,l=0,this.slack=!0)}let s=l;if(!this.slack){if(this.cx1=this.ny*this.a1relx-this.nx*this.a1rely,this.cx2=this.ny*this.a2relx-this.nx*this.a2rely,this.kMass=this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&s*s>this.maxError*this.maxError)return!0;let i=2*Math.PI*this.frequency;this.gamma=1/(t*i*(2*this.damping+i*t));let o=1/(1+this.gamma),r=t*i*i*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-s*r,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.nx*t,this.b1.vely-=this.ny*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.nx*n,this.b2.vely+=this.ny*n,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.nx*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.ny*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,l=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-l;let s=this.b1.imass*n;this.b1.velx-=this.nx*s,this.b1.vely-=this.ny*s;let i=this.b2.imass*n;return this.b2.velx+=this.nx*i,this.b2.vely+=this.ny*i,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,!1}applyImpulsePos(){let t,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,s=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,i=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o,r=this.b2.posx+s-(this.b1.posx+n),a=this.b2.posy+i-(this.b1.posy+l),p=r*r+a*a;if(p<ve._nape.Config.epsilon)r=0,a=0,p=0,o=!0;else{p=Math.sqrt(p);let u=1/p;r*=u,a*=u,this.equal?(p-=this.jointMax,o=!1):p<this.jointMin?(p=this.jointMin-p,r=-r,a=-a,o=!1):p>this.jointMax?(p-=this.jointMax,o=!1):(r=0,a=0,p=0,o=!0)}let c=p;if(!o){if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;if(c*c<ve._nape.Config.constraintLinearSlop*ve._nape.Config.constraintLinearSlop)return!1;if(c*=.5,c*c>6){let b=this.b1.smass+this.b2.smass;if(b>ve._nape.Config.epsilon){let _=.75/b;if(t=-c*_,this.equal||t<0){let d=t*this.b1.imass;this.b1.posx-=r*d,this.b1.posy-=a*d;let f=t*this.b2.imass;this.b2.posx+=r*f,this.b2.posy+=a*f,r=this.b2.posx+s-(this.b1.posx+n),a=this.b2.posy+i-(this.b1.posy+l);let m=r*r+a*a;if(m<ve._nape.Config.epsilon)r=0,a=0,m=0;else{m=Math.sqrt(m);let z=1/m;r*=z,a*=z,this.equal?m-=this.jointMax:m<this.jointMin?(m=this.jointMin-m,r=-r,a=-a):m>this.jointMax?m-=this.jointMax:(r=0,a=0,m=0)}c=m,c*=.5}}}let u=a*n-r*l,h=a*s-r*i,x=this.b1.smass+this.b2.smass+u*u*this.b1.sinertia+h*h*this.b2.sinertia;if(x!=0&&(x=1/x),t=-c*x,this.equal||t<0){let b=this.b1.imass*t;this.b1.posx-=r*b,this.b1.posy-=a*b;let _=this.b2.imass*t;this.b2.posx+=r*_,this.b2.posy+=a*_,qe._rotateBody(this.b1,-u*this.b1.iinertia*t),qe._rotateBody(this.b2,h*this.b2.iinertia*t)}}return!1}draw(t){}static _setupAnchorVec2(t,n,l,s){let i=ve._nape,o=t,r=n;if(r==null&&(r=0),o==null&&(o=0),o!=o||r!=r)throw new Error("Error: Vec2 components cannot be NaN");let a;if(de.poolVec2==null?a=new i.geom.Vec2:(a=de.poolVec2,de.poolVec2=a.zpp_pool,a.zpp_pool=null,a.zpp_disp=!1,a==de.nextVec2&&(de.nextVec2=null)),a.zpp_inner==null){let p;le.zpp_pool==null?p=new le:(p=le.zpp_pool,le.zpp_pool=p.next,p.next=null),p.weak=!1,p._immutable=!1,p.x=o,p.y=r,a.zpp_inner=p,a.zpp_inner.outer=a}else{if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=a.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),o!=o||r!=r)throw new Error("Error: Vec2 components cannot be NaN");let c;if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=a.zpp_inner;if(u._validate!=null&&u._validate(),a.zpp_inner.x==o){if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=a.zpp_inner;h._validate!=null&&h._validate(),c=a.zpp_inner.y==r}else c=!1;if(!c){a.zpp_inner.x=o,a.zpp_inner.y=r;let h=a.zpp_inner;h._invalidate!=null&&h._invalidate(h)}}return a.zpp_inner.weak=!1,a.zpp_inner._inuse=!0,a.zpp_inner._validate=l,a.zpp_inner._invalidate=s,a}};ii.__name__=["zpp_nape","constraint","ZPP_DistanceJoint"],ii.__super__=ve,ii._wrapFn=null,ii._createFn=null;var si=ii;var Xi=class Xi extends ve{constructor(){super();this.outer_zn=null;this.scale=0;this.jointMin=0;this.jointMax=0;this.equal=!1;this.dot1=0;this.dot2=0;this.cx1=0;this.cx2=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.zip_n=null;this.nlocalx=0;this.nlocaly=0;this.nrelx=0;this.nrely=0;this.wrap_n=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.jAccx=0;this.jAccy=0;this.jMax=null;this.gamma=null;this.biasx=0;this.biasy=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.nlocalx=0,this.nlocaly=0,this.nrelx=0,this.nrely=0,this.jAccx=0,this.jAccy=0,this.jMax=1/0,this.jointMin=-1/0,this.jointMax=1/0,this.stepped=!1}_setupVec2(t,n,l,s){let i=ve._nape,o=ve._zpp;if(n==null&&(n=0),t==null&&(t=0),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");let r;if(o.util.ZPP_PubPool.poolVec2==null?r=new i.geom.Vec2:(r=o.util.ZPP_PubPool.poolVec2,o.util.ZPP_PubPool.poolVec2=r.zpp_pool,r.zpp_pool=null,r.zpp_disp=!1,r==o.util.ZPP_PubPool.nextVec2&&(o.util.ZPP_PubPool.nextVec2=null)),r.zpp_inner==null){let a;o.geom.ZPP_Vec2.zpp_pool==null?a=new o.geom.ZPP_Vec2:(a=o.geom.ZPP_Vec2.zpp_pool,o.geom.ZPP_Vec2.zpp_pool=a.next,a.next=null),a.weak=!1,a._immutable=!1,a.x=t,a.y=n,r.zpp_inner=a,r.zpp_inner.outer=r}else{if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=r.zpp_inner;if(a._immutable)throw new Error("Error: Vec2 is immutable");if(a._isimmutable!=null&&a._isimmutable(),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=r.zpp_inner;p._validate!=null&&p._validate();let c;if(r.zpp_inner.x==t){if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=r.zpp_inner;u._validate!=null&&u._validate(),c=r.zpp_inner.y==n}else c=!1;if(!c){r.zpp_inner.x=t,r.zpp_inner.y=n;let u=r.zpp_inner;u._invalidate!=null&&u._invalidate(u)}}return r.zpp_inner.weak=!1,r.zpp_inner._inuse=!0,r.zpp_inner._validate=l,r.zpp_inner._invalidate=s,r}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){this.wrap_a1=this._setupVec2(this.a1localx,this.a1localy,this.validate_a1.bind(this),this.invalidate_a1.bind(this))}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){this.wrap_a2=this._setupVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}validate_n(){this.wrap_n.zpp_inner.x=this.nlocalx,this.wrap_n.zpp_inner.y=this.nlocaly}invalidate_n(t){this.immutable_midstep("Constraint::n"),this.nlocalx=t.x,this.nlocaly=t.y,this.zip_n=!0,this.wake()}setup_n(){this.wrap_n=this._setupVec2(this.nlocalx,this.nlocaly,this.validate_n.bind(this),this.invalidate_n.bind(this))}validate_norm(){if(this.zip_n){this.zip_n=!1;let t=this.nlocalx*this.nlocalx+this.nlocaly*this.nlocaly,l=1/Math.sqrt(t);this.nlocalx*=l,this.nlocaly*=l}}bodyImpulse(t){let n=ve._nape;if(this.stepped){let l=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,s=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy;return t==this.b1?n.geom.Vec3.get(-l,-s,this.scale*this.cx1*s-this.dot1*l):n.geom.Vec3.get(l,s,this.scale*this.cx1*s-this.dot1*l)}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=i.zpp_inner_zn.wrap_a2,r=this.outer_zn;r.zpp_inner_zn.wrap_n==null&&r.zpp_inner_zn.setup_n();let a=Xi._createFn(null,null,s,o,r.zpp_inner_zn.wrap_n,this.jointMin,this.jointMax);return this.copyto(a),qe._copyBody(t,n,this.b1,a,"b1"),qe._copyBody(t,n,this.b2,a,"b2"),a}validate(){let t=ve._nape;if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.nlocalx*this.nlocalx+this.nlocaly*this.nlocaly<t.Config.epsilon)throw new Error("Error: DistanceJoint direction must be non-degenerate");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&ve._unionComponents(this.b1.component,this.component),this.b2.type==2&&ve._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.equal=this.jointMin==this.jointMax,this.stepped=!0,this.validate_norm(),this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.nrelx=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,this.nrely=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let l=this.b2.posx+this.a2relx-this.b1.posx-this.a1relx,s=this.b2.posy+this.a2rely-this.b1.posy-this.a1rely,i=s*this.nrelx-l*this.nrely,o=this.nrelx*l+this.nrely*s;this.equal?(o-=this.jointMin,this.scale=1):o>this.jointMax?(o-=this.jointMax,this.scale=1):o<this.jointMin?(o=this.jointMin-o,this.scale=-1):(o=0,this.scale=0);let r=l+this.a1relx,a=s+this.a1rely;this.dot1=this.nrelx*r+this.nrely*a,this.cx1=a*this.nrelx-r*this.nrely,this.dot2=this.nrelx*this.a2relx+this.nrely*this.a2rely,this.cx2=this.a2rely*this.nrelx-this.a2relx*this.nrely,this.kMassa=this.b1.smass+this.b2.smass+this.dot1*this.dot1*this.b1.sinertia+this.dot2*this.dot2*this.b2.sinertia,this.kMassb=-this.scale*(this.dot1*this.cx1*this.b1.sinertia+this.dot2*this.cx2*this.b2.sinertia),this.kMassc=this.scale*this.scale*(this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia);let p=this.kMassa*this.kMassc-this.kMassb*this.kMassb,c;if(p!==p)this.kMassa=this.kMassb=this.kMassc=0,c=3;else if(p==0){let h=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,h|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,h|=2),this.kMassb=0,c=h}else{let h=1/p,x=this.kMassc*h;this.kMassc=this.kMassa*h,this.kMassa=x,this.kMassb*=-h,c=0}if((c&1)!=0&&(this.jAccx=0),(c&2)!=0&&(this.jAccy=0),this.stiff)this.gamma=0,this.biasx=0,this.biasy=0;else{if(this.breakUnderError&&i*i+o*o>this.maxError*this.maxError)return!0;let h=2*Math.PI*this.frequency;this.gamma=1/(t*h*(2*this.damping+h*t));let x=1/(1+this.gamma),b=t*h*h*this.gamma;this.gamma*=x;let _=x;this.kMassa*=_,this.kMassb*=_,this.kMassc*=_,this.biasx=i,this.biasy=o;let d=-b;this.biasx*=d,this.biasy*=d;let f=this.maxError,m=this.biasx*this.biasx+this.biasy*this.biasy;if(m>f*f){let z=f*(1/Math.sqrt(m));this.biasx*=z,this.biasy*=z}}let u=n;return this.jAccx*=u,this.jAccy*=u,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,n=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy,l=this.b1.imass;this.b1.velx-=t*l,this.b1.vely-=n*l;let s=this.b2.imass;this.b2.velx+=t*s,this.b2.vely+=n*s,this.b1.angvel+=(this.scale*this.cx1*this.jAccy-this.dot1*this.jAccx)*this.b1.iinertia,this.b2.angvel+=(this.dot2*this.jAccx-this.scale*this.cx2*this.jAccy)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx-this.b1.velx,n=this.b2.vely-this.b1.vely;t+=this.b2.kinvelx-this.b1.kinvelx,n+=this.b2.kinvely-this.b1.kinvely;let l=n*this.nrelx-t*this.nrely+(this.b2.angvel+this.b2.kinangvel)*this.dot2-(this.b1.angvel+this.b1.kinangvel)*this.dot1,s=this.scale*(this.nrelx*t+this.nrely*n-(this.b2.angvel+this.b2.kinangvel)*this.cx2+(this.b1.angvel+this.b1.kinangvel)*this.cx1),i=this.biasx-l,o=this.biasy-s,r=this.kMassa*i+this.kMassb*o;o=this.kMassb*i+this.kMassc*o,i=r;let a=this.gamma;i-=this.jAccx*a,o-=this.jAccy*a;let p=this.jAccx,c=this.jAccy;if(this.jAccx+=i,this.jAccy+=o,this.jAccy>0&&(this.jAccy=0),this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let f=this.jMax,m=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(m>f*f){let z=f*(1/Math.sqrt(m));this.jAccx*=z,this.jAccy*=z}}let u=this.jAccx-p,h=this.jAccy-c,x=this.scale*this.nrelx*h-this.nrely*u,b=this.nrelx*u+this.scale*this.nrely*h,_=this.b1.imass;this.b1.velx-=x*_,this.b1.vely-=b*_;let d=this.b2.imass;return this.b2.velx+=x*d,this.b2.vely+=b*d,this.b1.angvel+=(this.scale*this.cx1*h-this.dot1*u)*this.b1.iinertia,this.b2.angvel+=(this.dot2*u-this.scale*this.cx2*h)*this.b2.iinertia,!1}applyImpulsePos(){let t=ve._nape,n=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,l=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,s=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,i=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,o=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,r=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,a=this.b2.posx+o-this.b1.posx-s,p=this.b2.posy+r-this.b1.posy-i,c,u=p*n-a*l,h=n*a+l*p;if(this.equal?(h-=this.jointMin,c=1):h>this.jointMax?(h-=this.jointMax,c=1):h<this.jointMin?(h=this.jointMin-h,c=-1):(h=0,c=0),this.breakUnderError&&u*u+h*h>this.maxError*this.maxError)return!0;if(u*u+h*h<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let x,b,_=.5;if(u*=_,h*=_,u*u+h*h>6){let C=this.b1.smass+this.b2.smass;if(C>t.Config.epsilon){let D=.8/C,O=D*(l*u-c*n*h),j=D*(n*u*c-l*u),L=this.b1.imass;this.b1.posx-=O*L,this.b1.posy-=j*L;let U=this.b2.imass;this.b2.posx+=O*U,this.b2.posy+=j*U,a=this.b2.posx+o-this.b1.posx-s,p=this.b2.posy+r-this.b1.posy-i,u=p*n-a*l,h=n*a+l*p,this.equal?(h-=this.jointMin,c=1):h>this.jointMax?(h-=this.jointMax,c=1):h<this.jointMin?(h=this.jointMin-h,c=-1):(h=0,c=0);let q=.5;u*=q,h*=q}}let d=a+s,f=p+i,m=n*d+l*f,z=f*n-d*l,Z=n*o+l*r,y=r*n-o*l,w=this.b1.smass+this.b2.smass+m*m*this.b1.sinertia+Z*Z*this.b2.sinertia,v=-c*(m*z*this.b1.sinertia+Z*y*this.b2.sinertia),P=c*c*(this.b1.smass+this.b2.smass+z*z*this.b1.sinertia+y*y*this.b2.sinertia);x=-u,b=-h;let g=w*P-v*v;if(g!==g)b=0,x=b;else if(g==0)w!=0?x/=w:x=0,P!=0?b/=P:b=0;else{let C=1/g,D=C*(P*x-v*b);b=C*(w*b-v*x),x=D}b>0&&(b=0);let k=c*n*b-l*x,N=n*x+c*l*b,E=this.b1.imass;this.b1.posx-=k*E,this.b1.posy-=N*E;let M=this.b2.imass;return this.b2.posx+=k*M,this.b2.posy+=N*M,qe._rotateBody(this.b1,(c*z*b-m*x)*this.b1.iinertia),qe._rotateBody(this.b2,(Z*x-c*y*b)*this.b2.iinertia),!1}draw(t){}};Xi.__name__=["zpp_nape","constraint","ZPP_LineJoint"],Xi.__super__=ve,Xi._wrapFn=null,Xi._createFn=null;var li=Xi;var ws=class ws extends ve{constructor(){super();this.outer_zn=null;this.ratio=0;this.rate=0;this.b1=null;this.b2=null;this.kMass=0;this.jAcc=0;this.jMax=0;this.stepped=!1;this.jAcc=0,this.stepped=!1,this.__velocity=!0}bodyImpulse(t){let n=me();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let l=ws._createFn(null,null,this.rate,this.ratio);if(this.copyto(l),t!=null&&this.b1!=null){let s=null,i=0;for(;i<t.length;){let o=t[i];if(++i,o.id==this.b1.id){s=o.bc;break}}s!=null?l.zpp_inner.b1=s.zpp_inner:n.push(Fn.todo(this.b1.id,o=>{l.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let s=null,i=0;for(;i<t.length;){let o=t[i];if(++i,o.id==this.b2.id){s=o.bc;break}}s!=null?l.zpp_inner.b2=s.zpp_inner:n.push(Fn.todo(this.b2.id,o=>{l.zpp_inner.b2=o.zpp_inner}))}return l}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: MotorJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let l=this.b1.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let l=this.b2.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;return this.pre_dt=t,this.stepped=!0,this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass=1/this.kMass,this.jAcc*=n,this.jMax=this.maxForce*t,!1}warmStart(){this.b1.angvel-=this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.b2.iinertia*this.jAcc}applyImpulseVel(){let t=this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel-this.rate,n=-this.kMass*t,l=this.jAcc;if(this.jAcc+=n,this.breakUnderForce){if(this.jAcc>this.jMax||this.jAcc<-this.jMax)return!0}else this.jAcc<-this.jMax?this.jAcc=-this.jMax:this.jAcc>this.jMax&&(this.jAcc=this.jMax);return n=this.jAcc-l,this.b1.angvel-=this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.b2.iinertia*n,!1}applyImpulsePos(){return!1}};ws.__name__=["zpp_nape","constraint","ZPP_MotorJoint"],ws._wrapFn=null,ws._createFn=null;var oi=ws;var Hi=class Hi extends ve{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.jAccx=0;this.jAccy=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.stepped=!1;this.stepped=!1,this.jAccx=0,this.jAccy=0,this.jMax=1/0,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0}bodyImpulse(t){let n=ve._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAccx,-this.jAccy,-(this.jAccy*this.a1relx-this.jAccx*this.a1rely)):n.geom.Vec3.get(this.jAccx,this.jAccy,this.jAccy*this.a2relx-this.jAccx*this.a2rely):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){let t=ve._nape,n=ve._zpp,l=this.a1localx,s=this.a1localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a1=i,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=ve._nape,n=ve._zpp,l=this.a2localx,s=this.a2localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a2=i,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=Hi._createFn(null,null,s,i.zpp_inner_zn.wrap_a2);return this.copyto(o),qe._copyBody(t,n,this.b1,o,"b1"),qe._copyBody(t,n,this.b2,o,"b2"),o}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: PivotJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: PivotJoint cannot be simulated with body1 == body2 (body1=body2="+this.b1.outer.toString()+")");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&ve._unionComponents(this.b1.component,this.component),this.b2.type==2&&ve._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let l=this.b1.smass+this.b2.smass;if(this.kMassa=l,this.kMassb=0,this.kMassc=l,this.b1.sinertia!=0){let r=this.a1relx*this.b1.sinertia,a=this.a1rely*this.b1.sinertia;this.kMassa+=a*this.a1rely,this.kMassb+=-a*this.a1relx,this.kMassc+=r*this.a1relx}if(this.b2.sinertia!=0){let r=this.a2relx*this.b2.sinertia,a=this.a2rely*this.b2.sinertia;this.kMassa+=a*this.a2rely,this.kMassb+=-a*this.a2relx,this.kMassc+=r*this.a2relx}let s=this.kMassa*this.kMassc-this.kMassb*this.kMassb,i;if(s!=s)this.kMassa=this.kMassb=this.kMassc=0,i=3;else if(s==0){let r=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,r|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,r|=2),this.kMassb=0,i=r}else{let r=1/s,a=this.kMassc*r;this.kMassc=this.kMassa*r,this.kMassa=a,this.kMassb*=-r,i=0}if((i&1)!=0&&(this.jAccx=0),(i&2)!=0&&(this.jAccy=0),this.stiff)this.biasx=0,this.biasy=0,this.gamma=0;else{let r=2*Math.PI*this.frequency;this.gamma=1/(t*r*(2*this.damping+r*t));let a=1/(1+this.gamma),p=t*r*r*this.gamma;this.gamma*=a;let c=a;if(this.kMassa*=c,this.kMassb*=c,this.kMassc*=c,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy>this.maxError*this.maxError)return!0;let u=-p;this.biasx*=u,this.biasy*=u;let h=this.maxError,x=this.biasx*this.biasx+this.biasy*this.biasy;if(x>h*h){let b=h*(1/Math.sqrt(x));this.biasx*=b,this.biasy*=b}}let o=n;return this.jAccx*=o,this.jAccy*=o,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),l=this.biasx-t,s=this.biasy-n,i=this.kMassa*l+this.kMassb*s;s=this.kMassb*l+this.kMassc*s,l=i;let o=this.gamma;l-=this.jAccx*o,s-=this.jAccy*o;let r=this.jAccx,a=this.jAccy,p=1;if(this.jAccx+=l*p,this.jAccy+=s*p,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let h=this.jMax,x=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(x>h*h){let b=h*(1/Math.sqrt(x));this.jAccx*=b,this.jAccy*=b}}l=this.jAccx-r,s=this.jAccy-a;let c=this.b1.imass;this.b1.velx-=l*c,this.b1.vely-=s*c;let u=this.b2.imass;return this.b2.velx+=l*u,this.b2.vely+=s*u,this.b1.angvel-=(s*this.a1relx-l*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(s*this.a2relx-l*this.a2rely)*this.b2.iinertia,!1}applyImpulsePos(){let t=ve._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,s=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,i=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o=this.b2.posx+s-(this.b1.posx+n),r=this.b2.posy+i-(this.b1.posy+l);if(this.breakUnderError&&o*o+r*r>this.maxError*this.maxError)return!0;if(o*o+r*r<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let a=.5;o*=a,r*=a;let p,c;if(o*o+r*r>6){let w=this.b1.smass+this.b2.smass;if(w>t.Config.epsilon){let v=.75/w;p=-o*v,c=-r*v;let P=20,g=p*p+c*c;if(g>P*P){let M=P*(1/Math.sqrt(g));p*=M,c*=M}let k=this.b1.imass;this.b1.posx-=p*k,this.b1.posy-=c*k;let N=this.b2.imass;this.b2.posx+=p*N,this.b2.posy+=c*N,o=this.b2.posx+s-(this.b1.posx+n),r=this.b2.posy+i-(this.b1.posy+l);let E=.5;o*=E,r*=E}}let u=this.b1.smass+this.b2.smass,h=u,x=0,b=u;if(this.b1.sinertia!=0){let w=n*this.b1.sinertia,v=l*this.b1.sinertia;h+=v*l,x+=-v*n,b+=w*n}if(this.b2.sinertia!=0){let w=s*this.b2.sinertia,v=i*this.b2.sinertia;h+=v*i,x+=-v*s,b+=w*s}p=-o,c=-r;let _=6,d=p*p+c*c;if(d>_*_){let w=_*(1/Math.sqrt(d));p*=w,c*=w}let f=h*b-x*x;if(f!=f)c=0,p=0;else if(f==0)h!=0?p/=h:p=0,b!=0?c/=b:c=0;else{let w=1/f,v=w*(b*p-x*c);c=w*(h*c-x*p),p=v}let m=this.b1.imass;this.b1.posx-=p*m,this.b1.posy-=c*m;let z=this.b2.imass;this.b2.posx+=p*z,this.b2.posy+=c*z;let Z=-(c*n-p*l)*this.b1.iinertia;qe._rotateBody(this.b1,Z);let y=(c*s-p*i)*this.b2.iinertia;return qe._rotateBody(this.b2,y),!1}draw(t){}};Hi.__name__=["zpp_nape","constraint","ZPP_PivotJoint"],Hi.__super__=ve,Hi._wrapFn=null,Hi._createFn=null;var ri=Hi;var Qi=class Qi extends ve{constructor(){super();this.outer_zn=null;this.ratio=1;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.n12x=0;this.n12y=0;this.n34x=0;this.n34y=0;this.cx1=0;this.cx2=0;this.cx3=0;this.cx4=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.b3=null;this.a3localx=0;this.a3localy=0;this.a3relx=0;this.a3rely=0;this.wrap_a3=null;this.b4=null;this.a4localx=0;this.a4localy=0;this.a4relx=0;this.a4rely=0;this.wrap_a4=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.a3localx=0,this.a3localy=0,this.a3relx=0,this.a3rely=0,this.a4localx=0,this.a4localy=0,this.a4relx=0,this.a4rely=0,this.n12x=1,this.n12y=0,this.n34x=1,this.n34y=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=this.cx3=this.cx4=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),l=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),s=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),i=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),o=Math.sqrt(n*n+l*l),r=Math.sqrt(s*s+i*i),a=o+this.ratio*r;return this.equal||a<this.jointMin||a>this.jointMax?t=!1:t=!0,t}bodyImpulse(t){let n=ve._nape;if(this.stepped){let l=n.geom.Vec3.get();return t==this.b1&&(l.zpp_inner.x=l.zpp_inner.x-this.jAcc*this.n12x,l.zpp_inner.y=l.zpp_inner.y-this.jAcc*this.n12y,l.zpp_inner.z=l.zpp_inner.z-this.cx1*this.jAcc),t==this.b2&&(l.zpp_inner.x=l.zpp_inner.x+this.jAcc*this.n12x,l.zpp_inner.y=l.zpp_inner.y+this.jAcc*this.n12y,l.zpp_inner.z=l.zpp_inner.z+this.cx2*this.jAcc),t==this.b3&&(l.zpp_inner.x=l.zpp_inner.x-this.jAcc*this.n34x,l.zpp_inner.y=l.zpp_inner.y-this.jAcc*this.n34y,l.zpp_inner.z=l.zpp_inner.z-this.cx3*this.jAcc),t==this.b4&&(l.zpp_inner.x=l.zpp_inner.x+this.jAcc*this.n34x,l.zpp_inner.y=l.zpp_inner.y+this.jAcc*this.n34y,l.zpp_inner.z=l.zpp_inner.z+this.cx4*this.jAcc),l}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this),this.b3!=this.b1&&this.b3!=this.b2&&this.b3!=null&&this.b3.constraints.add(this),this.b4!=this.b1&&this.b4!=this.b2&&this.b4!=this.b3&&this.b4!=null&&this.b4.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this),this.b3!=this.b1&&this.b3!=this.b2&&this.b3!=null&&this.b3.constraints.remove(this),this.b4!=this.b1&&this.b4!=this.b2&&this.b4!=this.b3&&this.b4!=null&&this.b4.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){let t=ve._nape,n=ve._zpp,l=this.a1localx,s=this.a1localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a1=i,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=ve._nape,n=ve._zpp,l=this.a2localx,s=this.a2localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a2=i,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}validate_a3(){this.wrap_a3.zpp_inner.x=this.a3localx,this.wrap_a3.zpp_inner.y=this.a3localy}invalidate_a3(t){this.immutable_midstep("Constraint::a3"),this.a3localx=t.x,this.a3localy=t.y,this.wake()}setup_a3(){let t=ve._nape,n=ve._zpp,l=this.a3localx,s=this.a3localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a3=i,this.wrap_a3.zpp_inner._inuse=!0,this.wrap_a3.zpp_inner._validate=this.validate_a3.bind(this),this.wrap_a3.zpp_inner._invalidate=this.invalidate_a3.bind(this)}validate_a4(){this.wrap_a4.zpp_inner.x=this.a4localx,this.wrap_a4.zpp_inner.y=this.a4localy}invalidate_a4(t){this.immutable_midstep("Constraint::a4"),this.a4localx=t.x,this.a4localy=t.y,this.wake()}setup_a4(){let t=ve._nape,n=ve._zpp,l=this.a4localx,s=this.a4localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a4=i,this.wrap_a4.zpp_inner._inuse=!0,this.wrap_a4.zpp_inner._validate=this.validate_a4.bind(this),this.wrap_a4.zpp_inner._invalidate=this.invalidate_a4.bind(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=i.zpp_inner_zn.wrap_a2,r=this.outer_zn;r.zpp_inner_zn.wrap_a3==null&&r.zpp_inner_zn.setup_a3();let a=r.zpp_inner_zn.wrap_a3,p=this.outer_zn;p.zpp_inner_zn.wrap_a4==null&&p.zpp_inner_zn.setup_a4();let c=Qi._createFn(null,null,null,null,s,o,a,p.zpp_inner_zn.wrap_a4,this.jointMin,this.jointMax,this.ratio);return this.copyto(c),qe._copyBody(t,n,this.b1,c,"b1"),qe._copyBody(t,n,this.b2,c,"b2"),qe._copyBody(t,n,this.b3,c,"b3"),qe._copyBody(t,n,this.b4,c,"b4"),c}validate(){if(this.b1==null||this.b2==null||this.b3==null||this.b4==null)throw new Error("Error: PulleyJoint cannot be simulated with null bodies");if(this.b1==this.b2||this.b3==this.b4)throw new Error("Error: PulleyJoint cannot have body1==body2 or body3==body4");if(this.b1.space!=this.space||this.b2.space!=this.space||this.b3.space!=this.space||this.b4.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: PulleyJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: PulleyJoint cannot have both bodies in a linked pair non-dynamic");if(this.b3.type!=2&&this.b4.type!=2)throw new Error("Error: PulleyJoint cannot have both bodies in a linked pair non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake(),this.b3!=null&&this.b3.type==2&&this.b3.wake(),this.b4!=null&&this.b4.type==2&&this.b4.wake()}forest(){this.b1.type==2&&ve._unionComponents(this.b1.component,this.component),this.b2.type==2&&ve._unionComponents(this.b2.component,this.component),this.b3.type==2&&ve._unionComponents(this.b3.component,this.component),this.b4.type==2&&ve._unionComponents(this.b4.component,this.component)}pair_exists(t,n){return this.b1.id==t&&(this.b2.id==n||this.b3.id==n||this.b4.id==n)||this.b2.id==t&&(this.b3.id==n||this.b4.id==n||this.b1.id==n)||this.b3.id==t&&(this.b4.id==n||this.b1.id==n||this.b2.id==n)?!0:this.b4.id==t?this.b1.id==n||this.b2.id==n?!0:this.b3.id==n:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let l=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),o=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),r=Math.sqrt(l*l+s*s),a=Math.sqrt(i*i+o*o);if(r!=0){let u=1/r;this.n12x=l*u,this.n12y=s*u}if(a!=0){let u=1/a;this.n34x=i*u,this.n34y=o*u;let h=this.ratio;this.n34x*=h,this.n34y*=h}else{let u=this.ratio/Math.sqrt(this.n34x*this.n34x+this.n34y*this.n34y);this.n34x*=u,this.n34y*=u}let p=r+this.ratio*a;this.equal?(p-=this.jointMax,this.slack=!1):p<this.jointMin?(p=this.jointMin-p,this.n12x=-this.n12x,this.n12y=-this.n12y,this.n34x=-this.n34x,this.n34y=-this.n34y,this.slack=!1):p>this.jointMax?(p-=this.jointMax,this.slack=!1):(this.n12x=0,this.n12y=0,this.n34x=0,this.n34y=0,p=0,this.slack=!0);let c=p;if(!this.slack){this.cx1=this.n12y*this.a1relx-this.n12x*this.a1rely,this.cx2=this.n12y*this.a2relx-this.n12x*this.a2rely,this.cx3=this.n34y*this.a3relx-this.n34x*this.a3rely,this.cx4=this.n34y*this.a4relx-this.n34x*this.a4rely;let u=this.ratio*this.ratio,h=this.b1.smass+this.b2.smass+u*(this.b3.smass+this.b4.smass)+this.b1.sinertia*this.cx1*this.cx1+this.b2.sinertia*this.cx2*this.cx2+this.b3.sinertia*this.cx3*this.cx3+this.b4.sinertia*this.cx4*this.cx4;if(this.b1==this.b4&&(h-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx4*this.b1.sinertia)),this.b1==this.b3&&(h+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx3*this.b1.sinertia)),this.b2==this.b3&&(h-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx3*this.b2.sinertia)),this.b2==this.b4&&(h+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx4*this.b2.sinertia)),this.kMass=h,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;let x=2*Math.PI*this.frequency;this.gamma=1/(t*x*(2*this.damping+x*t));let b=1/(1+this.gamma),_=t*x*x*this.gamma;this.gamma*=b,this.kMass*=b,this.bias=-c*_,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.n12x*t,this.b1.vely-=this.n12y*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.n12x*n,this.b2.vely+=this.n12y*n;let l=this.b3.imass*this.jAcc;this.b3.velx-=this.n34x*l,this.b3.vely-=this.n34y*l;let s=this.b4.imass*this.jAcc;this.b4.velx+=this.n34x*s,this.b4.vely+=this.n34y*s,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc,this.b3.angvel-=this.cx3*this.b3.iinertia*this.jAcc,this.b4.angvel+=this.cx4*this.b4.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.n12x*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.n12y*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+this.n34x*(this.b4.velx+this.b4.kinvelx-this.b3.velx-this.b3.kinvelx)+this.n34y*(this.b4.vely+this.b4.kinvely-this.b3.vely-this.b3.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1+(this.b4.angvel+this.b4.kinangvel)*this.cx4-(this.b3.angvel+this.b3.kinangvel)*this.cx3,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,l=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-l;let s=this.b1.imass*n;this.b1.velx-=this.n12x*s,this.b1.vely-=this.n12y*s;let i=this.b2.imass*n;this.b2.velx+=this.n12x*i,this.b2.vely+=this.n12y*i;let o=this.b3.imass*n;this.b3.velx-=this.n34x*o,this.b3.vely-=this.n34y*o;let r=this.b4.imass*n;return this.b4.velx+=this.n34x*r,this.b4.vely+=this.n34y*r,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,this.b3.angvel-=this.cx3*this.b3.iinertia*n,this.b4.angvel+=this.cx4*this.b4.iinertia*n,!1}applyImpulsePos(){let t=ve._nape,n,l=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,o=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,a=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,p=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,c=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy,u,h=this.n12x,x=this.n12y,b=this.n34x,_=this.n34y,d=this.b2.posx+i-(this.b1.posx+l),f=this.b2.posy+o-(this.b1.posy+s),m=this.b4.posx+p-(this.b3.posx+r),z=this.b4.posy+c-(this.b3.posy+a),Z=Math.sqrt(d*d+f*f),y=Math.sqrt(m*m+z*z);if(Z!=0){let P=1/Z;h=d*P,x=f*P}if(y!=0){let P=1/y;b=m*P,_=z*P;let g=this.ratio;b*=g,_*=g}else{let P=this.ratio/Math.sqrt(b*b+_*_);b*=P,_*=P}let w=Z+this.ratio*y;this.equal?(w-=this.jointMax,u=!1):w<this.jointMin?(w=this.jointMin-w,h=-h,x=-x,b=-b,_=-_,u=!1):w>this.jointMax?(w-=this.jointMax,u=!1):(h=0,x=0,b=0,_=0,w=0,u=!0);let v=w;if(!u){if(this.breakUnderError&&v*v>this.maxError*this.maxError)return!0;if(v*v<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;if(v*=.5,v*v>6){let D=this.b1.smass+this.b2.smass;if(D>t.Config.epsilon){let O=.75/D;if(n=-v*O,this.equal||n<0){let j=n*this.b1.imass;this.b1.posx-=h*j,this.b1.posy-=x*j;let L=n*this.b2.imass;this.b2.posx+=h*L,this.b2.posy+=x*L;let U=n*this.b3.imass;this.b3.posx-=b*U,this.b3.posy-=_*U;let q=n*this.b4.imass;this.b4.posx+=b*q,this.b4.posy+=_*q;let R=this.b2.posx+i-(this.b1.posx+l),B=this.b2.posy+o-(this.b1.posy+s),S=this.b4.posx+p-(this.b3.posx+r),J=this.b4.posy+c-(this.b3.posy+a),Q=Math.sqrt(R*R+B*B),Y=Math.sqrt(S*S+J*J);if(Q!=0){let ee=1/Q;h=R*ee,x=B*ee}if(Y!=0){let ee=1/Y;b=S*ee,_=J*ee;let G=this.ratio;b*=G,_*=G}else{let ee=this.ratio/Math.sqrt(b*b+_*_);b*=ee,_*=ee}let X=Q+this.ratio*Y;this.equal?X-=this.jointMax:X<this.jointMin?(X=this.jointMin-X,h=-h,x=-x,b=-b,_=-_):X>this.jointMax?X-=this.jointMax:(h=0,x=0,b=0,_=0,X=0),v=X,v*=.5}}}let P=x*l-h*s,g=x*i-h*o,k=_*r-b*a,N=_*p-b*c,E=this.ratio*this.ratio,M=this.b1.smass+this.b2.smass+E*(this.b3.smass+this.b4.smass)+this.b1.sinertia*P*P+this.b2.sinertia*g*g+this.b3.sinertia*k*k+this.b4.sinertia*N*N;this.b1==this.b4&&(M-=2*((h*b+x*_)*this.b1.smass+P*N*this.b1.sinertia)),this.b1==this.b3&&(M+=2*((h*b+x*_)*this.b1.smass+P*k*this.b1.sinertia)),this.b2==this.b3&&(M-=2*((h*b+x*_)*this.b2.smass+g*k*this.b2.sinertia)),this.b2==this.b4&&(M+=2*((h*b+x*_)*this.b2.smass+g*N*this.b2.sinertia));let C=M;if(C!=0&&(C=1/C),n=-v*C,this.equal||n<0){let D=this.b1.imass*n;this.b1.posx-=h*D,this.b1.posy-=x*D;let O=this.b2.imass*n;this.b2.posx+=h*O,this.b2.posy+=x*O;let j=this.b3.imass*n;this.b3.posx-=b*j,this.b3.posy-=_*j;let L=this.b4.imass*n;this.b4.posx+=b*L,this.b4.posy+=_*L,qe._rotateBody(this.b1,-P*this.b1.iinertia*n),qe._rotateBody(this.b2,g*this.b2.iinertia*n),qe._rotateBody(this.b3,-k*this.b3.iinertia*n),qe._rotateBody(this.b4,N*this.b4.iinertia*n)}}return!1}draw(t){}};Qi.__name__=["zpp_nape","constraint","ZPP_PulleyJoint"],Qi.__super__=ve,Qi._wrapFn=null,Qi._createFn=null;var ai=Qi;var $i=class{constructor(e,t){this.cnt=0;this.body=null;this.cnt=e,this.body=t}};$i.__name__=["zpp_nape","constraint","ZPP_UserBody"];var Rs=class Rs extends ve{constructor(t,n){super();this.outer_zn=null;this.bodies=null;this.dim=0;this.jAcc=null;this.bias=null;this.stepped=!1;this.L=null;this.y=null;this.soft=0;this.gamma=0;this.velonly=!1;this.jMax=0;this.Keff=null;this.vec3=null;this.J=null;this.jOld=null;this.__class__=Rs;this.bodies=[],this.dim=t,this.velonly=n,this.jAcc=[],this.bias=[],this.L=[],this.J=[],this.jOld=[],this.y=[],this.Keff=[],this.vec3=ve._nape.geom.Vec3.get(0,0,0);for(let l=0;l<t;l++){let s=this.bias[l]=this.J[l]=this.jOld[l]=this.y[l]=0;this.jAcc[l]=s;for(let i=0;i<t;i++)this.L[l*t+i]=0}this.stepped=!1}bindVec2_invalidate(t){this.outer_zn.__invalidate()}addBody(t){let n=null;for(let l of this.bodies)if(l.body===t){n=l;break}n===null?(this.bodies.push(new $i(1,t)),this.active&&this.space!=null&&t?.constraints.add(this)):n.cnt++}remBody(t){let n=null,l=this.bodies.length|0,s=0;for(;s<l;){let i=this.bodies[s];if(i.body===t){i.cnt--,i.cnt===0&&(l>0&&(this.bodies[s]=this.bodies[l-1]),this.bodies.pop(),this.active&&this.space!=null&&t?.constraints.remove(this)),n=i;break}++s}return n!=null}bodyImpulse(t){for(let l=0;l<this.dim;l++)this.J[l]=this.jAcc[l];let n=ve._nape.geom.Vec3.get(0,0,0);return this.stepped&&this.outer_zn.__impulse(this.J,t.outer,n),n}activeBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.add(this)}inactiveBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.remove(this)}copy(t,n){let l=this.outer_zn.__copy();throw this.copyto(l),new Error("not done yet")}validate(){for(let t of this.bodies)if(t.body.space!==this.space)throw new Error("Error: Constraints must have each body within the same sapce to which the constraint has been assigned");this.outer_zn.__validate()}wake_connected(){for(let t of this.bodies)t.body.type===2&&t.body.wake()}forest(){for(let t of this.bodies)if(t.body.type===2){let n;if(t.body.component===t.body.component.parent)n=t.body.component;else{let s=t.body.component,i=null;for(;s!==s.parent;){let o=s.parent;s.parent=i,i=s,s=o}for(;i!=null;){let o=i.parent;i.parent=s,i=o}n=s}let l;if(this.component===this.component.parent)l=this.component;else{let s=this.component,i=null;for(;s!==s.parent;){let o=s.parent;s.parent=i,i=s,s=o}for(;i!=null;){let o=i.parent;i.parent=s,i=o}l=s}n!==l&&(n.rank<l.rank?n.parent=l:n.rank>l.rank?l.parent=n:(l.parent=n,n.rank++))}}pair_exists(t,n){let l=!1,s=this.bodies.length|0;for(let i=0;i<s;i++){let o=this.bodies[i].body;for(let r=i+1;r<s;r++){let a=this.bodies[r].body;if(o.id===t&&a.id===n||o.id===n&&a.id===t){l=!0;break}}if(l)break}return l}broken(){this.outer_zn.__broken()}clearcache(){for(let t=0;t<this.dim;t++)this.jAcc[t]=0;this.pre_dt=-1}lsq(t){let n=0;for(let l=0;l<this.dim;l++)n+=t[l]*t[l];return n}_clamp(t,n){let l=this.lsq(t);if(l>n*n){let s=n/Math.sqrt(l);for(let i=0;i<this.dim;i++)t[i]*=s}}solve(t){let n=0;for(let l=0;l<this.dim;l++){let s=0;for(let o=0;o<l-1;o++)s+=this.L[l*this.dim+o]*this.L[l*this.dim+o];let i=Math.sqrt(t[n++]-s);if(this.L[l*this.dim+l]=i,i!==0){i=1/i;for(let o=l+1;o<this.dim;o++){let r=0;for(let a=0;a<l-1;a++)r+=this.L[o*this.dim+a]*this.L[l*this.dim+a];this.L[o*this.dim+l]=i*(t[n++]-r)}}else{for(let o=l+1;o<this.dim;o++)this.L[o*this.dim+l]=0;n+=this.dim-l-1}}return this.L}transform(t,n){for(let l=0;l<this.dim;l++){let s=n[l],i=t[l*this.dim+l];if(i!==0){for(let o=0;o<l;o++)s-=t[l*this.dim+o]*this.y[o];this.y[l]=s/i}else this.y[l]=0}for(let l=0;l<this.dim;l++){let s=this.dim-1-l,i=t[s*this.dim+s];if(i!==0){let o=this.y[s];for(let r=s+1;r<this.dim;r++)o-=t[r*this.dim+s]*n[r];n[s]=o/i}else n[s]=0}}preStep(t){this.pre_dt===-1&&(this.pre_dt=t);let n=t/this.pre_dt;if(this.pre_dt=t,this.stepped=!0,this.outer_zn.__prepare(),this.outer_zn.__eff_mass(this.Keff),this.L=this.solve(this.Keff),!this.stiff&&!this.velonly){let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let s=1/(1+this.gamma),i=t*l*l*this.gamma;if(this.gamma*=s,this.soft=s,this.outer_zn.__position(this.bias),this.breakUnderError&&this.lsq(this.bias)>this.maxError*this.maxError)return!0;for(let o=0;o<this.dim;o++)this.bias[o]*=-i;this._clamp(this.bias,this.maxError)}else{for(let l=0;l<this.dim;l++)this.bias[l]=0;this.gamma=0,this.soft=1}for(let l=0;l<this.dim;l++)this.jAcc[l]*=n;return this.jMax=this.maxForce*t,!1}warmStart(){for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.jAcc,n.outer,this.vec3);let l=n.imass,s=n,i=s.velx,o=this.vec3;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let r=o.zpp_inner;r._validate!=null&&r._validate(),s.velx=i+o.zpp_inner.x*l;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let u=c.zpp_inner;u._validate!=null&&u._validate(),a.vely=p+c.zpp_inner.y*l;let h=n,x=h.angvel,b=this.vec3;if(b!=null&&b.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=b.zpp_inner;_._validate!=null&&_._validate(),h.angvel=x+b.zpp_inner.z*n.iinertia}}applyImpulseVel(){this.outer_zn.__velocity(this.J);for(let t=0;t<this.dim;t++)this.J[t]=this.bias[t]-this.J[t];this.transform(this.L,this.J);for(let t=0;t<this.dim;t++)this.jOld[t]=this.jAcc[t],this.jAcc[t]+=this.J[t]=this.J[t]*this.soft-this.jAcc[t]*this.gamma;if(this.outer_zn.__clamp(this.jAcc),(this.breakUnderForce||!this.stiff)&&this.lsq(this.jAcc)>this.jMax*this.jMax){if(this.breakUnderForce)return!0;this.stiff||this._clamp(this.jAcc,this.jMax)}for(let t=0;t<this.dim;t++)this.J[t]=this.jAcc[t]-this.jOld[t];for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.J,n.outer,this.vec3);let l=n.imass,s=n,i=s.velx,o=this.vec3;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let r=o.zpp_inner;r._validate!=null&&r._validate(),s.velx=i+o.zpp_inner.x*l;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let u=c.zpp_inner;u._validate!=null&&u._validate(),a.vely=p+c.zpp_inner.y*l;let h=n,x=h.angvel,b=this.vec3;if(b!=null&&b.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=b.zpp_inner;_._validate!=null&&_._validate(),h.angvel=x+b.zpp_inner.z*n.iinertia}return!1}applyImpulsePos(){if(this.velonly)return!1;this.outer_zn.__prepare(),this.outer_zn.__position(this.J);let t=this.lsq(this.J);if(this.breakUnderError&&t>this.maxError*this.maxError)return!0;if(t<ve._nape.Config.constraintLinearSlop*ve._nape.Config.constraintLinearSlop)return!1;for(let n=0;n<this.dim;n++)this.J[n]*=-1;this.outer_zn.__eff_mass(this.Keff),this.transform(this.solve(this.Keff),this.J),this.outer_zn.__clamp(this.J);for(let n of this.bodies){let l=n.body;this.outer_zn.__impulse(this.J,l.outer,this.vec3);let s=l.imass,i=l,o=i.posx,r=this.vec3;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let a=r.zpp_inner;a._validate!=null&&a._validate(),i.posx=o+r.zpp_inner.x*s;let p=l,c=p.posy,u=this.vec3;if(u!=null&&u.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let h=u.zpp_inner;h._validate!=null&&h._validate(),p.posy=c+u.zpp_inner.y*s;let x=this.vec3;if(x!=null&&x.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let b=x.zpp_inner;b._validate!=null&&b._validate();let _=x.zpp_inner.z*l.iinertia;if(l.rot+=_,_*_>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let d=_*_,f=1-.5*d,m=1-d*d/8,z=(f*l.axisx+_*l.axisy)*m;l.axisy=(f*l.axisy-_*l.axisx)*m,l.axisx=z}}return!1}draw(t){this.outer_zn.__draw(t)}};Rs.__name__=["zpp_nape","constraint","ZPP_UserConstraint"],Rs.__super__=ve;var qs=Rs;var es=class es extends ve{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.phase=0;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.kMassd=0;this.kMasse=0;this.kMassf=0;this.jAccx=0;this.jAccy=0;this.jAccz=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.biasz=0;this.stepped=!1;this.phase=0,this.jAccx=0,this.jAccy=0,this.jAccz=0,this.jMax=1/0,this.stepped=!1,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0}bodyImpulse(t){let n=ve._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAccx,-this.jAccy,-(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)):n.geom.Vec3.get(this.jAccx,this.jAccy,this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){let t=ve._nape,n=ve._zpp,l=this.a1localx,s=this.a1localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a1=i,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=ve._nape,n=ve._zpp,l=this.a2localx,s=this.a2localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a2=i,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=es._createFn(null,null,s,i.zpp_inner_zn.wrap_a2);return this.copyto(o),qe._copyBody(t,n,this.b1,o,"b1"),qe._copyBody(t,n,this.b2,o,"b2"),o}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: WeldJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&ve._unionComponents(this.b1.component,this.component),this.b2.type==2&&ve._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.jAccz=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let l=this.b1.smass+this.b2.smass;if(this.kMassa=l,this.kMassb=0,this.kMassd=l,this.kMassc=0,this.kMasse=0,this.kMassf=0,this.b1.sinertia!=0){let o=this.a1relx*this.b1.sinertia,r=this.a1rely*this.b1.sinertia;this.kMassa+=r*this.a1rely,this.kMassb+=-r*this.a1relx,this.kMassd+=o*this.a1relx,this.kMassc+=-r,this.kMasse+=o,this.kMassf+=this.b1.sinertia}if(this.b2.sinertia!=0){let o=this.a2relx*this.b2.sinertia,r=this.a2rely*this.b2.sinertia;this.kMassa+=r*this.a2rely,this.kMassb+=-r*this.a2relx,this.kMassd+=o*this.a2relx,this.kMassc+=-r,this.kMasse+=o,this.kMassf+=this.b2.sinertia}let s=this.kMassa*(this.kMassd*this.kMassf-this.kMasse*this.kMasse)+this.kMassb*(this.kMassc*this.kMasse-this.kMassb*this.kMassf)+this.kMassc*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),i;if(s!=s)this.kMassa=0,this.kMassb=0,this.kMassd=0,this.kMassc=0,this.kMasse=0,this.kMassf=0,i=7;else if(s==0){let o=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,o|=1),this.kMassd!=0?this.kMassd=1/this.kMassd:(this.kMassd=0,o|=2),this.kMassf!=0?this.kMassf=1/this.kMassf:(this.kMassf=0,o|=4),this.kMassb=this.kMassc=this.kMasse=0,i=o}else{let o=1/s,r=o*(this.kMassd*this.kMassf-this.kMasse*this.kMasse),a=o*(this.kMasse*this.kMassc-this.kMassb*this.kMassf),p=o*(this.kMassa*this.kMassf-this.kMassc*this.kMassc),c=o*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),u=o*(this.kMassb*this.kMassc-this.kMassa*this.kMasse),h=o*(this.kMassa*this.kMassd-this.kMassb*this.kMassb);this.kMassa=r,this.kMassb=a,this.kMassd=p,this.kMassc=c,this.kMasse=u,this.kMassf=h,i=0}if((i&1)!=0&&(this.jAccx=0),(i&2)!=0&&(this.jAccy=0),(i&4)!=0&&(this.jAccz=0),this.stiff)this.biasx=0,this.biasy=0,this.biasz=0,this.gamma=0;else{let o=2*Math.PI*this.frequency;this.gamma=1/(t*o*(2*this.damping+o*t));let r=1/(1+this.gamma),a=t*o*o*this.gamma;this.gamma*=r;let p=r;if(this.kMassa*=p,this.kMassb*=p,this.kMassd*=p,this.kMassc*=p,this.kMasse*=p,this.kMassf*=p,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.biasz=this.b2.rot-this.b1.rot-this.phase,this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz>this.maxError*this.maxError)return!0;let c=-a;this.biasx*=c,this.biasy*=c,this.biasz*=c;let u=this.maxError,h=this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz;if(h>u*u){let x=u*(1/Math.sqrt(h));this.biasx*=x,this.biasy*=x,this.biasz*=x}}return this.jAccx*=n,this.jAccy*=n,this.jAccz*=n,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),l=this.b2.angvel+this.b2.kinangvel-this.b1.angvel-this.b1.kinangvel,s=this.biasx-t,i=this.biasy-n,o=this.biasz-l,r=this.kMassa*s+this.kMassb*i+this.kMassc*o,a=this.kMassb*s+this.kMassd*i+this.kMasse*o;o=this.kMassc*s+this.kMasse*i+this.kMassf*o,s=r,i=a,s-=this.jAccx*this.gamma,i-=this.jAccy*this.gamma,o-=this.jAccz*this.gamma;let p=this.jAccx,c=this.jAccy,u=this.jAccz;if(this.jAccx+=s,this.jAccy+=i,this.jAccz+=o,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz>this.jMax*this.jMax)return!0}else if(!this.stiff){let b=this.jMax,_=this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz;if(_>b*b){let d=b*(1/Math.sqrt(_));this.jAccx*=d,this.jAccy*=d,this.jAccz*=d}}s=this.jAccx-p,i=this.jAccy-c,o=this.jAccz-u;let h=this.b1.imass;this.b1.velx-=s*h,this.b1.vely-=i*h;let x=this.b2.imass;return this.b2.velx+=s*x,this.b2.vely+=i*x,this.b1.angvel-=(i*this.a1relx-s*this.a1rely+o)*this.b1.iinertia,this.b2.angvel+=(i*this.a2relx-s*this.a2rely+o)*this.b2.iinertia,!1}applyImpulsePos(){let t=ve._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,s=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,i=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o=this.b2.posx+s-(this.b1.posx+n),r=this.b2.posy+i-(this.b1.posy+l),a=this.b2.rot-this.b1.rot-this.phase,p,c,u;if(this.breakUnderError&&o*o+r*r+a*a>this.maxError*this.maxError)return!0;let h=!0;o*o+r*r<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(h=!1,o=0,r=0);let x=t.Config.constraintAngularSlop;if(a*a<x*x)if(h)a=0;else return!1;if(o*=.5,r*=.5,a*=.5,o*o+r*r>6){let O=this.b1.smass+this.b2.smass;if(O>t.Config.epsilon){let j=.75/O;p=-o*j,c=-r*j;let L=20,U=p*p+c*c;if(U>L*L){let B=L*(1/Math.sqrt(U));p*=B,c*=B}let q=this.b1.imass;this.b1.posx-=p*q,this.b1.posy-=c*q;let R=this.b2.imass;this.b2.posx+=p*R,this.b2.posy+=c*R,o=this.b2.posx+s-(this.b1.posx+n),r=this.b2.posy+i-(this.b1.posy+l),a=this.b2.rot-this.b1.rot-this.phase,o*=.5,r*=.5,a*=.5}}let b=this.b1.smass+this.b2.smass,_=b,d=0,f=b,m=0,z=0,Z=0;if(this.b1.sinertia!=0){let O=n*this.b1.sinertia,j=l*this.b1.sinertia;_+=j*l,d+=-j*n,f+=O*n,m+=-j,z+=O,Z+=this.b1.sinertia}if(this.b2.sinertia!=0){let O=s*this.b2.sinertia,j=i*this.b2.sinertia;_+=j*i,d+=-j*s,f+=O*s,m+=-j,z+=O,Z+=this.b2.sinertia}p=-o,c=-r,u=-a;let y=6,w=p*p+c*c;if(w>y*y){let O=y*(1/Math.sqrt(w));p*=O,c*=O}let P=u<-.25,g=_*(f*Z-z*z)+d*(m*z-d*Z)+m*(d*z-m*f);if(g!=g)u=0,c=u,p=c;else if(g==0)_!=0?p/=_:p=0,f!=0?c/=f:c=0,Z!=0?u/=Z:u=0;else{let O=1/g,j=z*m-d*Z,L=d*z-m*f,U=d*m-_*z,q=O*(p*(f*Z-z*z)+c*j+u*L),R=O*(p*j+c*(_*Z-m*m)+u*U);u=O*(p*L+c*U+u*(_*f-d*d)),p=q,c=R}let k=this.b1.imass;this.b1.posx-=p*k,this.b1.posy-=c*k;let N=this.b2.imass;this.b2.posx+=p*N,this.b2.posy+=c*N;let E=this.b1,M=-(c*n-p*l+u)*this.b1.iinertia;qe._rotateBody(E,M);let C=this.b2,D=(c*s-p*i+u)*this.b2.iinertia;return qe._rotateBody(C,D),!1}draw(t){}};es.__name__=["zpp_nape","constraint","ZPP_WeldJoint"],es.__super__=ve,es._wrapFn=null,es._createFn=null;var pi=es;var it=class it{constructor(){this.outer=null;this.hnext=null;this.id=0;this.di=0;this.stamp=0;this.up_stamp=0;this.sleep_stamp=0;this.endGenerated=0;this.active=!1;this.cleared=!1;this.sleeping=!1;this.present=0;this.intchange=!1;this.presentable=!1;this.continuous=!1;this.fresh=!1;this.immState=0;this.invalidated=!1;this.b1=null;this.b2=null;this.ws1=null;this.ws2=null;this.pair=null;this.type=0;this.colarb=null;this.fluidarb=null;this.sensorarb=null;this.sensorarb=null,this.fluidarb=null,this.colarb=null,this.type=0,this.pair=null,this.ws2=null,this.ws1=null,this.b2=null,this.b1=null,this.invalidated=!1,this.immState=0,this.fresh=!1,this.continuous=!1,this.presentable=!1,this.intchange=!1,this.present=0,this.sleeping=!1,this.cleared=!1,this.active=!1,this.endGenerated=0,this.sleep_stamp=0,this.up_stamp=0,this.stamp=0,this.di=0,this.id=0,this.hnext=null,this.outer=null}static _initEnums(e,t){let n=()=>{t.internal=!0;let l=new e.dynamics.ArbiterType;return t.internal=!1,l};t.ArbiterType_COLLISION==null&&(t.ArbiterType_COLLISION=n()),t.ArbiterType_SENSOR==null&&(t.ArbiterType_SENSOR=n()),t.ArbiterType_FLUID==null&&(t.ArbiterType_FLUID=n()),it.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID]}wrapper(){if(this.outer==null){let e=it._nape;it.internal=!0,this.type==it.COL?(this.colarb.outer_zn=it._createColArb(),this.outer=this.colarb.outer_zn):this.type==it.FLUID?(this.fluidarb.outer_zn=it._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,it.internal=!1}return this.outer}inactiveme(){return!this.active}acting(){return this.active?(this.immState&1)!=0:!1}swap_features(){let e=this.b1;this.b1=this.b2,this.b2=e,e=this.ws1,this.ws1=this.ws2,this.ws2=e,e=this.colarb.s1,this.colarb.s1=this.colarb.s2,this.colarb.s2=e}lazyRetire(e,t){let n=it._zpp;this.cleared=!0,(t==null||this.b2==t)&&it._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&it._removeFromArbiterList(this.b2.arbiters,this,n),this.pair!=null&&(this.pair.arb=null,this.pair=null),this.active=!1,e.f_arbiters.modified=!0}sup_assign(e,t,n,l){let s=it._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=l,it._addToArbiterList(this.b1.arbiters,this,s),it._addToArbiterList(this.b2.arbiters,this,s),this.active=!0,this.present=0,this.cleared=!1,this.sleeping=!1,this.fresh=!1,this.presentable=!1}sup_retire(){let e=it._zpp;this.cleared||(it._removeFromArbiterList(this.b1.arbiters,this,e),it._removeFromArbiterList(this.b2.arbiters,this,e),this.pair!=null&&(this.pair.arb=null,this.pair=null)),this.b1=this.b2=null,this.active=!1,this.intchange=!1}static _removeFromArbiterList(e,t,n){let l=null,s=e.head;for(;s!=null;){if(s.elt==t){let i,o;l==null?(i=e.head,o=i.next,e.head=o,e.head==null&&(e.pushmod=!0)):(i=l.next,o=i.next,l.next=o,o==null&&(e.pushmod=!0));let r=i;r.elt=null,r.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=r,e.modified=!0,e.length--,e.pushmod=!0;break}l=s,s=s.next}}static _addToArbiterList(e,t,n){let l;n.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?l=new n.util.ZNPNode_ZPP_Arbiter:(l=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=l.next,l.next=null),l.elt=t;let s=l;s.next=e.head,e.head=s,e.modified=!0,e.length++}};it.__name__=["zpp_nape","dynamics","ZPP_Arbiter"],it._nape=null,it._zpp=null,it.internal=!1,it._createColArb=null,it._createFluidArb=null,it.COL=1,it.FLUID=4,it.SENSOR=2,it.types=[];var Ae=it;var ts=class ts extends Ae{constructor(){super(),this.next=null,this.type=Ae.SENSOR,this.sensorarb=this}alloc(){}free(){}assign(e,t,n,l){this.sup_assign(e,t,n,l)}retire(){this.sup_retire(),this.next=ts.zpp_pool,ts.zpp_pool=this}makemutable(){}makeimmutable(){}};ts.__name__=["zpp_nape","dynamics","ZPP_SensorArbiter"],ts.__super__=Ae,ts.zpp_pool=null;var jt=ts;var ns=class ns extends Ae{constructor(){super();this.outer_zn=null;this.centroidx=0;this.centroidy=0;this.overlap=0;this.r1x=0;this.r1y=0;this.r2x=0;this.r2y=0;this.nodrag=!1;this.wMass=0;this.adamp=0;this.agamma=0;this.vMassa=0;this.vMassb=0;this.vMassc=0;this.dampx=0;this.dampy=0;this.lgamma=0;this.nx=0;this.ny=0;this.buoyx=0;this.buoyy=0;this.wrap_position=null;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.wrap_position=null,this.buoyy=0,this.buoyx=0,this.ny=0,this.nx=0,this.lgamma=0,this.dampy=0,this.dampx=0,this.vMassc=0,this.vMassb=0,this.vMassa=0,this.agamma=0,this.adamp=0,this.wMass=0,this.nodrag=!1,this.r2y=0,this.r2x=0,this.r1y=0,this.r1x=0,this.overlap=0,this.centroidy=0,this.centroidx=0,this.next=null,this.outer_zn=null,this.type=Ae.FLUID,this.fluidarb=this,this.buoyx=0,this.buoyy=0,this.pre_dt=-1}alloc(){}free(){}position_validate(){if(!this.active)throw new Error("Error: Arbiter not currently in use");this.wrap_position.zpp_inner.x=this.centroidx,this.wrap_position.zpp_inner.y=this.centroidy}position_invalidate(t){this.centroidx=t.x,this.centroidy=t.y}getposition(){let t=Ae._zpp,n=Ae._nape,l;if(t.util.ZPP_PubPool.poolVec2==null?l=new n.geom.Vec2:(l=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let s;t.geom.ZPP_Vec2.zpp_pool==null?s=new t.geom.ZPP_Vec2:(s=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,l.zpp_inner=s,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==0){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;r._validate!=null&&r._validate(),i=l.zpp_inner.y==0}else i=!1;if(!i){l.zpp_inner.x=0,l.zpp_inner.y=0;let r=l.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}l.zpp_inner.weak=!1,this.wrap_position=l,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!this.mutable,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this),this.wrap_position.zpp_inner._invalidate=this.position_invalidate.bind(this)}assign(t,n,l,s){this.sup_assign(t,n,l,s),this.nx=0,this.ny=1,this.dampx=0,this.dampy=0,this.adamp=0}retire(){this.sup_retire(),this.next=ns.zpp_pool,ns.zpp_pool=this,this.pre_dt=-1}makemutable(){this.mutable=!0,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=!1)}makeimmutable(){this.mutable=!1,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=!0)}inject(t,n,l){this.overlap=t,this.centroidx=n,this.centroidy=l}preStep(t,n){let l=Ae._nape;this.pre_dt==-1&&(this.pre_dt=n);let s=n/this.pre_dt;this.pre_dt=n,this.r1x=this.centroidx-this.b1.posx,this.r1y=this.centroidy-this.b1.posy,this.r2x=this.centroidx-this.b2.posx,this.r2y=this.centroidy-this.b2.posy;let i,o;this.ws1.fluidEnabled&&this.ws1.fluidProperties.wrap_gravity!=null?(i=this.ws1.fluidProperties.gravityx,o=this.ws1.fluidProperties.gravityy):(i=t.gravityx,o=t.gravityy);let r,a;this.ws2.fluidEnabled&&this.ws2.fluidProperties.wrap_gravity!=null?(r=this.ws2.fluidProperties.gravityx,a=this.ws2.fluidProperties.gravityy):(r=t.gravityx,a=t.gravityy);let p=0,c=0;if(this.ws1.fluidEnabled&&this.ws2.fluidEnabled){let u=this.overlap*this.ws1.fluidProperties.density,h=this.overlap*this.ws2.fluidProperties.density;if(u>h){let x=u+h;p-=i*x,c-=o*x}else if(u<h){let x=u+h;p+=r*x,c+=a*x}else{let x=i+r,b=o+a,_=.5;if(x*=_,b*=_,this.ws1.worldCOMx*x+this.ws1.worldCOMy*b>this.ws2.worldCOMx*x+this.ws2.worldCOMy*b){let d=u+h;p-=x*d,c-=b*d}else{let d=u+h;p+=x*d,c+=b*d}}}else if(this.ws1.fluidEnabled){let u=this.overlap*this.ws1.fluidProperties.density;p-=i*u,c-=o*u}else if(this.ws2.fluidEnabled){let u=this.overlap*this.ws2.fluidProperties.density;p+=r*u,c+=a*u}if(p*=n,c*=n,this.buoyx=p,this.buoyy=c,this.b1.type==2&&(this.b1.velx-=p*this.b1.imass,this.b1.vely-=c*this.b1.imass,this.b1.angvel-=(c*this.r1x-p*this.r1y)*this.b1.iinertia),this.b2.type==2&&(this.b2.velx+=p*this.b2.imass,this.b2.vely+=c*this.b2.imass,this.b2.angvel+=(c*this.r2x-p*this.r2y)*this.b2.iinertia),(!this.ws1.fluidEnabled||this.ws1.fluidProperties.viscosity==0)&&(!this.ws2.fluidEnabled||this.ws2.fluidProperties.viscosity==0))this.nodrag=!0,this.dampx=0,this.dampy=0,this.adamp=0;else{this.nodrag=!1;let u=0;if(this.ws1.fluidEnabled&&(this.ws2.validate_angDrag(),u+=this.ws1.fluidProperties.viscosity*this.ws2.angDrag*this.overlap/this.ws2.area),this.ws2.fluidEnabled&&(this.ws1.validate_angDrag(),u+=this.ws2.fluidProperties.viscosity*this.ws1.angDrag*this.overlap/this.ws1.area),u!=0){let _=this.b1.sinertia+this.b2.sinertia;_!=0?this.wMass=1/_:this.wMass=0,u*=4e-4;let d=2*Math.PI*u;this.agamma=1/(n*d*(2+d*n));let f=1/(1+this.agamma);this.agamma*=f,this.wMass*=f}else this.wMass=0,this.agamma=0;let h=this.b2.velx+this.b2.kinvelx-this.r2y*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.r1y*(this.b2.angvel+this.b2.kinangvel)),x=this.b2.vely+this.b2.kinvely+this.r2x*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.r1x*(this.b1.angvel+this.b1.kinangvel));if(!(h*h+x*x<l.Config.epsilon*l.Config.epsilon)){let _=h*h+x*x,d=1/Math.sqrt(_);this.nx=h*d,this.ny=x*d}let b=0;if(this.ws1.fluidEnabled){let _=-this.ws1.fluidProperties.viscosity*this.overlap/this.ws2.area;if(this.ws2.type==0)b-=_*this.ws2.circle.radius*l.Config.fluidLinearDrag/(2*this.ws2.circle.radius*Math.PI);else{let d=this.ws2.polygon,f=0,m=0,z=d.edges.head;for(;z!=null;){let Z=z.elt;f+=Z.length;let y=_*Z.length*(Z.gnormx*this.nx+Z.gnormy*this.ny);y>0&&(y*=-l.Config.fluidVacuumDrag),m-=y*.5*l.Config.fluidLinearDrag,z=z.next}b+=m/f}}if(this.ws2.fluidEnabled){let _=-this.ws2.fluidProperties.viscosity*this.overlap/this.ws1.area;if(this.ws1.type==0)b-=_*this.ws1.circle.radius*l.Config.fluidLinearDrag/(2*this.ws1.circle.radius*Math.PI);else{let d=this.ws1.polygon,f=0,m=0,z=d.edges.head;for(;z!=null;){let Z=z.elt;f+=Z.length;let y=_*Z.length*(Z.gnormx*this.nx+Z.gnormy*this.ny);y>0&&(y*=-l.Config.fluidVacuumDrag),m-=y*.5*l.Config.fluidLinearDrag,z=z.next}b+=m/f}}if(b!=0){let _=this.b1.smass+this.b2.smass,d=_,f=0,m=_;if(this.b1.sinertia!=0){let w=this.r1x*this.b1.sinertia,v=this.r1y*this.b1.sinertia;d+=v*this.r1y,f+=-v*this.r1x,m+=w*this.r1x}if(this.b2.sinertia!=0){let w=this.r2x*this.b2.sinertia,v=this.r2y*this.b2.sinertia;d+=v*this.r2y,f+=-v*this.r2x,m+=w*this.r2x}let z=d*m-f*f;if(z!==z)m=0,f=m,d=f;else if(z==0)d!=0?d=1/d:d=0,m!=0?m=1/m:m=0,f=0;else{let w=1/z,v=m*w;m=d*w,d=v,f*=-w}this.vMassa=d,this.vMassb=f,this.vMassc=m;let Z=2*Math.PI*b;this.lgamma=1/(n*Z*(2+Z*n));let y=1/(1+this.lgamma);this.lgamma*=y,this.vMassa*=y,this.vMassb*=y,this.vMassc*=y}else this.vMassa=0,this.vMassb=0,this.vMassc=0,this.lgamma=0}this.dampx*=s,this.dampy*=s,this.adamp*=s}warmStart(){this.b1.velx-=this.dampx*this.b1.imass,this.b1.vely-=this.dampy*this.b1.imass,this.b2.velx+=this.dampx*this.b2.imass,this.b2.vely+=this.dampy*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(this.dampy*this.r1x-this.dampx*this.r1y),this.b2.angvel+=this.b2.iinertia*(this.dampy*this.r2x-this.dampx*this.r2y),this.b1.angvel-=this.adamp*this.b1.iinertia,this.b2.angvel+=this.adamp*this.b2.iinertia}applyImpulseVel(){if(!this.nodrag){let t=this.b1.angvel+this.b1.kinangvel,n=this.b2.angvel+this.b2.kinangvel,l=this.b1.velx+this.b1.kinvelx-this.r1y*t-(this.b2.velx+this.b2.kinvelx-this.r2y*n),s=this.b1.vely+this.b1.kinvely+this.r1x*t-(this.b2.vely+this.b2.kinvely+this.r2x*n),i=this.vMassa*l+this.vMassb*s;s=this.vMassb*l+this.vMassc*s,l=i,l-=this.dampx*this.lgamma,s-=this.dampy*this.lgamma,this.dampx+=l,this.dampy+=s,this.b1.velx-=l*this.b1.imass,this.b1.vely-=s*this.b1.imass,this.b2.velx+=l*this.b2.imass,this.b2.vely+=s*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(s*this.r1x-l*this.r1y),this.b2.angvel+=this.b2.iinertia*(s*this.r2x-l*this.r2y);let o=(t-n)*this.wMass-this.adamp*this.agamma;this.adamp+=o,this.b1.angvel-=o*this.b1.iinertia,this.b2.angvel+=o*this.b2.iinertia}}};ns.__name__=["zpp_nape","dynamics","ZPP_FluidArbiter"],ns.__super__=Ae,ns.zpp_pool=null;var Ct=ns;var ci=class{constructor(){this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.r1x=0;this.r1y=0;this.r2x=0;this.r2y=0;this.nMass=0;this.tMass=0;this.bounce=0;this.friction=0;this.jnAcc=0;this.jtAcc=0;this.lr1x=0;this.lr1y=0;this.lr2x=0;this.lr2y=0}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};ci.__name__=["zpp_nape","dynamics","ZPP_IContact"];var xn=class xn{constructor(){this.outer=null;this.px=0;this.py=0;this.wrap_position=null;this.arbiter=null;this.active=!1;this.posOnly=!1;this.stamp=0;this.hash=0;this.fresh=!1;this.dist=0;this.elasticity=0;this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.length=0,this.pushmod=!1,this.modified=!1,this._inuse=!1,this.next=null,this.elasticity=0,this.dist=0,this.fresh=!1,this.hash=0,this.stamp=0,this.posOnly=!1,this.active=!1,this.inner=null,this.arbiter=null,this.wrap_position=null,this.py=0,this.px=0,this.outer=null,this.inner=new ci}wrapper(){return this.outer==null&&(xn._wrapFn?this.outer=xn._wrapFn(this):(xn.internal=!0,this.outer=new xn._nape.dynamics.Contact,xn.internal=!1,this.outer.zpp_inner=this)),this.outer}position_validate(){if(this.inactiveme())throw new Error("Error: Contact not currently in use");this.wrap_position.zpp_inner.x=this.px,this.wrap_position.zpp_inner.y=this.py}getposition(){let e=xn._zpp,t=xn._nape,n;if(e.util.ZPP_PubPool.poolVec2==null?n=new t.geom.Vec2:(n=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=0,l.y=0,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");l._isimmutable!=null&&l._isimmutable();let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),s=n.zpp_inner.y==0}else s=!1;if(!s){n.zpp_inner.x=0,n.zpp_inner.y=0;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.wrap_position=n,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!0,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this)}inactiveme(){return!(this.active&&this.arbiter!=null&&this.arbiter.active)}free(){this.arbiter=null}alloc(){}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};xn.__name__=["zpp_nape","dynamics","ZPP_Contact"],xn._nape=null,xn._zpp=null,xn.zpp_pool=null,xn.internal=!1,xn._wrapFn=null;var we=xn;var ut=class ut extends Ae{constructor(){super();this.outer_zn=null;this.dyn_fric=0;this.stat_fric=0;this.restitution=0;this.rfric=0;this.userdef_dyn_fric=!1;this.userdef_stat_fric=!1;this.userdef_restitution=!1;this.userdef_rfric=!1;this.s1=null;this.s2=null;this.wrap_contacts=null;this.nx=0;this.ny=0;this.wrap_normal=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.Ka=0;this.Kb=0;this.Kc=0;this.rMass=0;this.jrAcc=0;this.rn1a=0;this.rt1a=0;this.rn1b=0;this.rt1b=0;this.rn2a=0;this.rt2a=0;this.rn2b=0;this.rt2b=0;this.k1x=0;this.k1y=0;this.k2x=0;this.k2y=0;this.surfacex=0;this.surfacey=0;this.ptype=null;this.lnormx=0;this.lnormy=0;this.lproj=0;this.radius=0;this.rev=!1;this.biasCoef=0;this.__ref_edge1=null;this.__ref_edge2=null;this.__ref_vertex=0;this.c1=null;this.oc1=null;this.c2=null;this.oc2=null;this.hc2=!1;this.hpc2=!1;this.stat=!1;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.stat=!1,this.next=null,this.hpc2=!1,this.hc2=!1,this.oc2=null,this.c2=null,this.oc1=null,this.c1=null,this.__ref_vertex=0,this.__ref_edge2=null,this.__ref_edge1=null,this.biasCoef=0,this.rev=!1,this.radius=0,this.lproj=0,this.lnormy=0,this.lnormx=0,this.surfacey=0,this.surfacex=0,this.k2y=0,this.k2x=0,this.k1y=0,this.k1x=0,this.rt2b=0,this.rn2b=0,this.rt2a=0,this.rn2a=0,this.rt1b=0,this.rn1b=0,this.rt1a=0,this.rn1a=0,this.jrAcc=0,this.rMass=0,this.Kc=0,this.Kb=0,this.Ka=0,this.kMassc=0,this.kMassb=0,this.kMassa=0,this.wrap_normal=null,this.ny=0,this.nx=0,this.innards=null,this.wrap_contacts=null,this.contacts=null,this.s2=null,this.s1=null,this.userdef_rfric=!1,this.userdef_restitution=!1,this.userdef_stat_fric=!1,this.userdef_dyn_fric=!1,this.rfric=0,this.restitution=0,this.stat_fric=0,this.dyn_fric=0,this.outer_zn=null,this.pre_dt=-1,this.contacts=new we,this.innards=new ci,this.type=Ae.COL,this.colarb=this}alloc(){}free(){this.userdef_dyn_fric=!1,this.userdef_stat_fric=!1,this.userdef_restitution=!1,this.userdef_rfric=!1,this.__ref_edge1=this.__ref_edge2=null}normal_validate(){if(this.cleared)throw new Error("Error: Arbiter not currently in use");this.wrap_normal.zpp_inner.x=this.nx,this.wrap_normal.zpp_inner.y=this.ny,this.ws1.id>this.ws2.id&&(this.wrap_normal.zpp_inner.x=-this.wrap_normal.zpp_inner.x,this.wrap_normal.zpp_inner.y=-this.wrap_normal.zpp_inner.y)}getnormal(){let t=Ae._zpp,n=Ae._nape,l=0,s=0,i;if(t.util.ZPP_PubPool.poolVec2==null?i=new n.geom.Vec2:(i=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;t.geom.ZPP_Vec2.zpp_pool==null?o=new t.geom.ZPP_Vec2:(o=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!==l||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_normal=i,this.wrap_normal.zpp_inner._immutable=!0,this.wrap_normal.zpp_inner._inuse=!0,this.wrap_normal.zpp_inner._validate=this.normal_validate.bind(this)}injectContact(t,n,l,s,i,o,r=!1){let a=null,p=this.contacts.next;for(;p!=null;){if(o==p.hash){a=p;break}p=p.next}if(a==null){we.zpp_pool==null?a=new we:(a=we.zpp_pool,we.zpp_pool=a.next,a.next=null);let c=a.inner;c.jnAcc=c.jtAcc=0,a.hash=o,a.fresh=!0,a.arbiter=this,this.jrAcc=0,a._inuse=!0,a.next=this.contacts.next,this.contacts.next=a,this.contacts.modified=!0,this.contacts.length++,this.innards.add(c)}else a.fresh=!1;return a.px=t,a.py=n,this.nx=l,this.ny=s,a.dist=i,a.stamp=this.stamp,a.posOnly=r,a}assign(t,n,l,s){this.sup_assign(t,n,l,s),this.s1=t,this.s2=n,this._calcFrictionRestitution()}calcProperties(){this._calcFrictionRestitution()}validate_props(){this.invalidated&&(this.invalidated=!1,this._calcFrictionRestitution())}_calcFrictionRestitution(){this.userdef_restitution||(this.s1.material.elasticity<=-1/0||this.s2.material.elasticity<=-1/0?this.restitution=0:this.s1.material.elasticity>=1/0||this.s2.material.elasticity>=1/0?this.restitution=1:this.restitution=(this.s1.material.elasticity+this.s2.material.elasticity)/2,this.restitution<0&&(this.restitution=0),this.restitution>1&&(this.restitution=1)),this.userdef_dyn_fric||(this.dyn_fric=Math.sqrt(this.s1.material.dynamicFriction*this.s2.material.dynamicFriction)),this.userdef_stat_fric||(this.stat_fric=Math.sqrt(this.s1.material.staticFriction*this.s2.material.staticFriction)),this.userdef_rfric||(this.rfric=Math.sqrt(this.s1.material.rollingFriction*this.s2.material.rollingFriction))}retire(){for(this.sup_retire();this.contacts.next!=null;){let t=this.contacts.next;this.contacts.pop(),t.arbiter=null,t.next=we.zpp_pool,we.zpp_pool=t;let n=this.innards.next;this.innards.next=n.next,n._inuse=!1,this.innards.next==null&&(this.innards.pushmod=!0),this.innards.modified=!0,this.innards.length--}this.free(),this.next=ut.zpp_pool,ut.zpp_pool=this,this.pre_dt=-1}makemutable(){this.mutable=!0,this.wrap_normal!=null&&(this.wrap_normal.zpp_inner._immutable=!1),this.wrap_contacts!=null&&(this.wrap_contacts.zpp_inner.immutable=!1)}makeimmutable(){this.mutable=!1,this.wrap_normal!=null&&(this.wrap_normal.zpp_inner._immutable=!0),this.wrap_contacts!=null&&(this.wrap_contacts.zpp_inner.immutable=!0)}contacts_adder(t){throw new Error("Error: Cannot add new contacts, information required is far too specific and detailed :)")}contacts_subber(t){let n=null,l=null,s=this.innards.next,i=this.contacts.next;for(;i!=null;){if(i==t.zpp_inner){this.contacts.erase(n),this.innards.erase(l),i.arbiter=null,i.next=we.zpp_pool,we.zpp_pool=i;break}n=i,l=s,s=s.next,i=i.next}}setupcontacts(){let t=Ae._zpp;this.wrap_contacts=t.util.ZPP_ContactList.get(this.contacts,!0),this.wrap_contacts.zpp_inner.immutable=!this.mutable,this.wrap_contacts.zpp_inner.adder=this.contacts_adder.bind(this),this.wrap_contacts.zpp_inner.dontremove=!0,this.wrap_contacts.zpp_inner.subber=this.contacts_subber.bind(this)}cleanupContacts(){let t=Ae._nape,n=!0,l=null,s=null,i=this.innards.next;this.hc2=!1;let o=this.contacts.next;for(;o!=null;){let r=o;if(r.stamp+t.Config.arbiterExpirationDelay<this.stamp){o=ut._eraseFromList(this.contacts,l),i=ut._eraseFromList(this.innards,s),r.arbiter=null,r.next=we.zpp_pool,we.zpp_pool=r;continue}let a=r.inner,p=r.active;r.active=r.stamp==this.stamp,r.active&&(n?(n=!1,this.c1=a,this.oc1=r):(this.hc2=!0,this.c2=a,this.oc2=r)),p!=r.active&&(this.contacts.modified=!0),l=o,s=i,i=i.next,o=o.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let r=this.c1;this.c1=this.c2,this.c2=r,r=this.oc1,this.oc1=this.oc2,this.oc2=r,this.hc2=!1}else this.oc2.posOnly&&(this.hc2=!1);this.oc1.posOnly&&(n=!0)}else this.hpc2=!1;return n}preStep(t){let n=Ae._nape;this.validate_props(),this.pre_dt==-1&&(this.pre_dt=t);let l=t/this.pre_dt;this.pre_dt=t;let s=this.b1.smass+this.b2.smass;this.hc2=!1;let i=!0,r=this.b1.type!=2||this.b2.type!=2?this.continuous?n.Config.contactContinuousStaticBiasCoef:n.Config.contactStaticBiasCoef:this.continuous?n.Config.contactContinuousBiasCoef:n.Config.contactBiasCoef;this.biasCoef=r,this.continuous=!1;let a=null,p=null,c=this.innards.next,u=this.contacts.next;for(;u!=null;){let h=u;if(h.stamp+n.Config.arbiterExpirationDelay<this.stamp){u=ut._eraseFromList(this.contacts,a),c=ut._eraseFromList(this.innards,p),h.arbiter=null,h.next=we.zpp_pool,we.zpp_pool=h;continue}let x=h.inner,b=h.active;if(h.active=h.stamp==this.stamp,h.active){i?(i=!1,this.c1=x,this.oc1=h):(this.hc2=!0,this.c2=x,this.oc2=h),x.r2x=h.px-this.b2.posx,x.r2y=h.py-this.b2.posy,x.r1x=h.px-this.b1.posx,x.r1y=h.py-this.b1.posy;let _=x.r2x*this.nx+x.r2y*this.ny,d=s+this.b2.sinertia*(_*_);_=x.r1x*this.nx+x.r1y*this.ny,d+=this.b1.sinertia*(_*_),x.tMass=d<n.Config.epsilon*n.Config.epsilon?0:1/d,_=this.ny*x.r2x-this.nx*x.r2y;let f=s+this.b2.sinertia*(_*_);_=this.ny*x.r1x-this.nx*x.r1y,f+=this.b1.sinertia*(_*_),x.nMass=f<n.Config.epsilon*n.Config.epsilon?0:1/f;let m=this.b2.angvel+this.b2.kinangvel,z=this.b2.velx+this.b2.kinvelx-x.r2y*m,Z=this.b2.vely+this.b2.kinvely+x.r2x*m;m=this.b1.angvel+this.b1.kinangvel,z-=this.b1.velx+this.b1.kinvelx-x.r1y*m,Z-=this.b1.vely+this.b1.kinvely+x.r1x*m;let y=this.nx*z+this.ny*Z;h.elasticity=this.restitution,x.bounce=y*h.elasticity,x.bounce>-n.Config.elasticThreshold&&(x.bounce=0);let w=Z*this.nx-z*this.ny,v=n.Config.staticFrictionThreshold;w*w>v*v?x.friction=this.dyn_fric:x.friction=this.stat_fric,x.jnAcc*=l,x.jtAcc*=l}b!=h.active&&(this.contacts.modified=!0),a=u,p=c,c=c.next,u=u.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let h=this.c1;this.c1=this.c2,this.c2=h,h=this.oc1,this.oc1=this.oc2,this.oc2=h,this.hc2=!1}else this.oc2.posOnly&&(this.hc2=!1);this.oc1.posOnly&&(i=!0)}else this.hpc2=!1;if(this.jrAcc*=l,i||(this.rn1a=this.ny*this.c1.r1x-this.nx*this.c1.r1y,this.rt1a=this.c1.r1x*this.nx+this.c1.r1y*this.ny,this.rn1b=this.ny*this.c1.r2x-this.nx*this.c1.r2y,this.rt1b=this.c1.r2x*this.nx+this.c1.r2y*this.ny,this.k1x=this.b2.kinvelx-this.c1.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c1.r1y*this.b1.kinangvel),this.k1y=this.b2.kinvely+this.c1.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c1.r1x*this.b1.kinangvel)),this.hc2)if(this.rn2a=this.ny*this.c2.r1x-this.nx*this.c2.r1y,this.rt2a=this.c2.r1x*this.nx+this.c2.r1y*this.ny,this.rn2b=this.ny*this.c2.r2x-this.nx*this.c2.r2y,this.rt2b=this.c2.r2x*this.nx+this.c2.r2y*this.ny,this.k2x=this.b2.kinvelx-this.c2.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c2.r1y*this.b1.kinangvel),this.k2y=this.b2.kinvely+this.c2.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c2.r1x*this.b1.kinangvel),this.kMassa=s+this.b1.sinertia*this.rn1a*this.rn1a+this.b2.sinertia*this.rn1b*this.rn1b,this.kMassb=s+this.b1.sinertia*this.rn1a*this.rn2a+this.b2.sinertia*this.rn1b*this.rn2b,this.kMassc=s+this.b1.sinertia*this.rn2a*this.rn2a+this.b2.sinertia*this.rn2b*this.rn2b,this.kMassa*this.kMassa+2*this.kMassb*this.kMassb+this.kMassc*this.kMassc<n.Config.illConditionedThreshold*(this.kMassa*this.kMassc-this.kMassb*this.kMassb)){this.Ka=this.kMassa,this.Kb=this.kMassb,this.Kc=this.kMassc;let x=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(x!==x)this.kMassa=this.kMassb=this.kMassc=0;else if(x==0)this.kMassa!=0?this.kMassa=1/this.kMassa:this.kMassa=0,this.kMassc!=0?this.kMassc=1/this.kMassc:this.kMassc=0,this.kMassb=0;else{let b=1/x,_=this.kMassc*b;this.kMassc=this.kMassa*b,this.kMassa=_,this.kMassb*=-b}}else{if(this.hc2=!1,this.oc2.dist<this.oc1.dist){let x=this.c1;this.c1=this.c2,this.c2=x}this.oc2.active=!1,this.contacts.modified=!0}return this.surfacex=this.b2.svelx,this.surfacey=this.b2.svely,this.surfacex+=this.b1.svelx,this.surfacey+=this.b1.svely,this.surfacex=-this.surfacex,this.surfacey=-this.surfacey,this.rMass=this.b1.sinertia+this.b2.sinertia,this.rMass!=0&&(this.rMass=1/this.rMass),i}warmStart(){let t=this.nx*this.c1.jnAcc-this.ny*this.c1.jtAcc,n=this.ny*this.c1.jnAcc+this.nx*this.c1.jtAcc;this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c1.r1x-t*this.c1.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c1.r2x-t*this.c1.r2y),this.hc2&&(t=this.nx*this.c2.jnAcc-this.ny*this.c2.jtAcc,n=this.ny*this.c2.jnAcc+this.nx*this.c2.jtAcc,this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c2.r1x-t*this.c2.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c2.r2x-t*this.c2.r2y)),this.b2.angvel+=this.jrAcc*this.b2.iinertia,this.b1.angvel-=this.jrAcc*this.b1.iinertia}applyImpulseVel(){let t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),l=(n*this.nx-t*this.ny+this.surfacex)*this.c1.tMass,s=this.c1.friction*this.c1.jnAcc,i=this.c1.jtAcc,o=i-l;o>s?o=s:o<-s&&(o=-s),l=o-i,this.c1.jtAcc=o;let r=-this.ny*l,a=this.nx*l;if(this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rt1b*l*this.b2.iinertia,this.b1.angvel-=this.rt1a*l*this.b1.iinertia,this.hc2){let p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);l=(c*this.nx-p*this.ny+this.surfacex)*this.c2.tMass,s=this.c2.friction*this.c2.jnAcc,i=this.c2.jtAcc,o=i-l,o>s?o=s:o<-s&&(o=-s),l=o-i,this.c2.jtAcc=o,r=-this.ny*l,a=this.nx*l,this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rt2b*l*this.b2.iinertia,this.b1.angvel-=this.rt2a*l*this.b1.iinertia,t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);let u=this.c1.jnAcc,h=this.c2.jnAcc,x=t*this.nx+n*this.ny+this.surfacey+this.c1.bounce-(this.Ka*u+this.Kb*h),b=p*this.nx+c*this.ny+this.surfacey+this.c2.bounce-(this.Kb*u+this.Kc*h),_=-(this.kMassa*x+this.kMassb*b),d=-(this.kMassb*x+this.kMassc*b);_>=0&&d>=0?(x=_-u,b=d-h,this.c1.jnAcc=_,this.c2.jnAcc=d):(_=-this.c1.nMass*x,_>=0&&this.Kb*_+b>=0?(x=_-u,b=-h,this.c1.jnAcc=_,this.c2.jnAcc=0):(d=-this.c2.nMass*b,d>=0&&this.Kb*d+x>=0?(x=-u,b=d-h,this.c1.jnAcc=0,this.c2.jnAcc=d):x>=0&&b>=0?(x=-u,b=-h,this.c1.jnAcc=this.c2.jnAcc=0):(x=0,b=0))),l=x+b,r=this.nx*l,a=this.ny*l,this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=(this.rn1b*x+this.rn2b*b)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*x+this.rn2a*b)*this.b1.iinertia}else this.radius!=0&&(l=(this.b2.angvel-this.b1.angvel)*this.rMass,s=this.rfric*this.c1.jnAcc,i=this.jrAcc,this.jrAcc-=l,this.jrAcc>s?this.jrAcc=s:this.jrAcc<-s&&(this.jrAcc=-s),l=this.jrAcc-i,this.b2.angvel+=l*this.b2.iinertia,this.b1.angvel-=l*this.b1.iinertia),t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),l=(this.c1.bounce+(this.nx*t+this.ny*n)+this.surfacey)*this.c1.nMass,i=this.c1.jnAcc,o=i-l,o<0&&(o=0),l=o-i,this.c1.jnAcc=o,r=this.nx*l,a=this.ny*l,this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rn1b*l*this.b2.iinertia,this.b1.angvel-=this.rn1a*l*this.b1.iinertia}applyImpulsePos(){let t=Ae._nape;this.ptype==2?this._applyImpulsePosCircle(t):this._applyImpulsePosEdge(t)}_applyImpulsePosCircle(t){let n=this.c1,l=this.b2.axisy*n.lr2x-this.b2.axisx*n.lr2y,s=n.lr2x*this.b2.axisx+n.lr2y*this.b2.axisy;l+=this.b2.posx,s+=this.b2.posy;let i=this.b1.axisy*n.lr1x-this.b1.axisx*n.lr1y,o=n.lr1x*this.b1.axisx+n.lr1y*this.b1.axisy;i+=this.b1.posx,o+=this.b1.posy;let r=l-i,a=s-o,p=Math.sqrt(r*r+a*a),c=this.radius-t.Config.collisionSlop,u=p-c;if(r*this.nx+a*this.ny<0&&(r=-r,a=-a,u-=this.radius),u<0)if(p<t.Config.epsilon)this.b1.smass!=0?this.b1.posx+=t.Config.epsilon*10:this.b2.posx+=t.Config.epsilon*10;else{let h=1/p;r*=h,a*=h;let x=.5*(i+l),b=.5*(o+s),_=p-c;i=x-this.b1.posx,o=b-this.b1.posy,l=x-this.b2.posx,s=b-this.b2.posy;let d=a*i-r*o,f=a*l-r*s,m=this.b2.smass+f*f*this.b2.sinertia+this.b1.smass+d*d*this.b1.sinertia;if(m!=0){let z=-this.biasCoef*_/m,Z=r*z,y=a*z;this.b1.posx-=Z*this.b1.imass,this.b1.posy-=y*this.b1.imass,ut._rotateBody(this.b1,-d*this.b1.iinertia*z),this.b2.posx+=Z*this.b2.imass,this.b2.posy+=y*this.b2.imass,ut._rotateBody(this.b2,f*this.b2.iinertia*z)}}}_applyImpulsePosEdge(t){let n,l,s,i,o,r=0,a=0;this.ptype==0?(n=this.b1.axisy*this.lnormx-this.b1.axisx*this.lnormy,l=this.lnormx*this.b1.axisx+this.lnormy*this.b1.axisy,s=this.lproj+(n*this.b1.posx+l*this.b1.posy),i=this.b2.axisy*this.c1.lr1x-this.b2.axisx*this.c1.lr1y,o=this.c1.lr1x*this.b2.axisx+this.c1.lr1y*this.b2.axisy,i+=this.b2.posx,o+=this.b2.posy,this.hpc2&&(r=this.b2.axisy*this.c2.lr1x-this.b2.axisx*this.c2.lr1y,a=this.c2.lr1x*this.b2.axisx+this.c2.lr1y*this.b2.axisy,r+=this.b2.posx,a+=this.b2.posy)):(n=this.b2.axisy*this.lnormx-this.b2.axisx*this.lnormy,l=this.lnormx*this.b2.axisx+this.lnormy*this.b2.axisy,s=this.lproj+(n*this.b2.posx+l*this.b2.posy),i=this.b1.axisy*this.c1.lr1x-this.b1.axisx*this.c1.lr1y,o=this.c1.lr1x*this.b1.axisx+this.c1.lr1y*this.b1.axisy,i+=this.b1.posx,o+=this.b1.posy,this.hpc2&&(r=this.b1.axisy*this.c2.lr1x-this.b1.axisx*this.c2.lr1y,a=this.c2.lr1x*this.b1.axisx+this.c2.lr1y*this.b1.axisy,r+=this.b1.posx,a+=this.b1.posy));let p=i*n+o*l-s-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=r*n+a*l-s-this.radius,c+=t.Config.collisionSlop),p<0||c<0){this.rev&&(n=-n,l=-l);let u=i-this.b1.posx,h=o-this.b1.posy,x=i-this.b2.posx,b=o-this.b2.posy;if(this.hpc2){let _=r-this.b1.posx,d=a-this.b1.posy,f=r-this.b2.posx,m=a-this.b2.posy,z=l*u-n*h,Z=l*x-n*b,y=l*_-n*d,w=l*f-n*m,v=this.b1.smass+this.b2.smass;this.kMassa=v+this.b1.sinertia*z*z+this.b2.sinertia*Z*Z,this.kMassb=v+this.b1.sinertia*z*y+this.b2.sinertia*Z*w,this.kMassc=v+this.b1.sinertia*y*y+this.b2.sinertia*w*w;let P=this.kMassa,g=this.kMassb,k=this.kMassc,N=p*this.biasCoef,E=c*this.biasCoef;for(;;){let M=-N,C=-E,D=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(D!==D)M=0,C=0;else if(D==0)this.kMassa!=0?M/=this.kMassa:M=0,this.kMassc!=0?C/=this.kMassc:C=0;else{let O=1/D,j=O*(this.kMassc*M-this.kMassb*C);C=O*(this.kMassa*C-this.kMassb*M),M=j}if(M>=0&&C>=0){ut._applyPosImpulse2(this.b1,this.b2,n,l,M,C,z,y,Z,w);break}if(M=-N/P,C=0,M>=0&&g*M+E>=0){ut._applyPosImpulse2(this.b1,this.b2,n,l,M,C,z,y,Z,w);break}if(M=0,C=-E/k,C>=0&&g*C+N>=0){ut._applyPosImpulse2(this.b1,this.b2,n,l,M,C,z,y,Z,w);break}break}}else{let _=l*u-n*h,d=l*x-n*b,f=this.b2.smass+d*d*this.b2.sinertia+this.b1.smass+_*_*this.b1.sinertia;if(f!=0){let m=-this.biasCoef*p/f,z=n*m,Z=l*m;this.b1.posx-=z*this.b1.imass,this.b1.posy-=Z*this.b1.imass,ut._rotateBody(this.b1,-_*this.b1.iinertia*m),this.b2.posx+=z*this.b2.imass,this.b2.posy+=Z*this.b2.imass,ut._rotateBody(this.b2,d*this.b2.iinertia*m)}}}}static _eraseFromList(t,n){let l,s;return n==null?(l=t.next,s=l.next,t.next=s,t.next==null&&(t.pushmod=!0)):(l=n.next,s=l.next,n.next=s,s==null&&(t.pushmod=!0)),l._inuse=!1,t.modified=!0,t.length--,t.pushmod=!0,s}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let l=n*n,s=1-.5*l,i=1-l*l/8,o=(s*t.axisx+n*t.axisy)*i;t.axisy=(s*t.axisy-n*t.axisx)*i,t.axisx=o}}static _applyPosImpulse2(t,n,l,s,i,o,r,a,p,c){let u=(i+o)*t.imass;t.posx-=l*u,t.posy-=s*u,ut._rotateBody(t,-t.iinertia*(r*i+a*o));let h=(i+o)*n.imass;n.posx+=l*h,n.posy+=s*h,ut._rotateBody(n,n.iinertia*(p*i+c*o))}};ut.__name__=["zpp_nape","dynamics","ZPP_ColArbiter"],ut.__super__=Ae,ut.FACE1=0,ut.FACE2=1,ut.CIRCLE=2,ut.zpp_pool=null;var xt=ut;var Jt=class Jt{constructor(){this.collisionGroup=1;this.collisionMask=-1;this.sensorGroup=1;this.sensorMask=-1;this.fluidGroup=1;this.fluidMask=-1;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new Jt._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Jt._wrapFn)this.outer=Jt._wrapFn(this);else{this.outer=new Jt._nape.dynamics.InteractionFilter;let e=this.outer.zpp_inner;e.outer=null,e.next=Jt.zpp_pool,Jt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Jt._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Jt.zpp_pool==null?e=new Jt:(e=Jt.zpp_pool,Jt.zpp_pool=e.next,e.next=null),e.collisionGroup=this.collisionGroup,e.collisionMask=this.collisionMask,e.sensorGroup=this.sensorGroup,e.sensorMask=this.sensorMask,e.fluidGroup=this.fluidGroup,e.fluidMask=this.fluidMask,e}shouldCollide(e){return(this.collisionMask&e.collisionGroup)!==0&&(e.collisionMask&this.collisionGroup)!==0}shouldSense(e){return(this.sensorMask&e.sensorGroup)!==0&&(e.sensorMask&this.sensorGroup)!==0}shouldFlow(e){return(this.fluidMask&e.fluidGroup)!==0&&(e.fluidMask&this.fluidGroup)!==0}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_filter(),e=e.next}};Jt.zpp_pool=null,Jt.__name__=["zpp_nape","dynamics","ZPP_InteractionFilter"],Jt._nape=null,Jt._zpp=null,Jt._wrapFn=null;var _t=Jt;var Pi=class Pi{constructor(){this.outer=null;this.ignore=!1;this.group=null;this.groups=null;this.wrap_groups=null;this.interactors=null;this.wrap_interactors=null;this.depth=0;let e=Pi._zpp;this.groups=new e.util.ZNPList_ZPP_InteractionGroup,this.interactors=new e.util.ZNPList_ZPP_Interactor}setGroup(e){this.group!==e&&(this.group!=null&&(this.group.groups.remove(this),this.depth=0,this.group.invalidate(!0)),this.group=e,e!=null?(e.groups.add(this),this.depth=e.depth+1,e.invalidate(!0)):this.invalidate(!0))}invalidate(e){if(e==null&&(e=!1),!(e||this.ignore))return;let t=this.interactors.head;for(;t!=null;){let l=t.elt;l.ibody!=null?l.ibody.wake():l.ishape!=null?l.ishape.body.wake():l.icompound.wake(),t=t.next}let n=this.groups.head;for(;n!=null;)n.elt.invalidate(e),n=n.next}addGroup(e){this.groups.add(e),e.depth=this.depth+1}remGroup(e){this.groups.remove(e),e.depth=0}addInteractor(e){this.interactors.add(e)}remInteractor(e,t){this.interactors.remove(e)}};Pi.SHAPE=1,Pi.BODY=2,Pi.__name__=["zpp_nape","dynamics","ZPP_InteractionGroup"],Pi._zpp=null,Pi._wrapFn=null;var Js=Pi;var Gn=class{constructor(){this.zpp_inner=null;this.space=null;this._length=0;this.zip_length=!1;this.lengths=[];this.ite_0=null;this.ite_1=null;this.ite_2=null;this.ite_3=null;this.at_index_0=0;this.at_index_1=0;this.at_index_2=0;this.at_index_3=0;this.at_index_0=0,this.at_index_1=0,this.at_index_2=0,this.at_index_3=0,this.zip_length=!0,this._length=0,this.lengths=[],this.lengths.push(0),this.lengths.push(0),this.lengths.push(0),this.lengths.push(0)}zpp_gl(){if(this.zpp_vm(),this.zip_length){this._length=0;let e=0,t=0,n=this.space.c_arbiters_true.head;for(;n!=null;)n.elt.active&&++t,n=n.next;this.lengths[e++]=t,this._length+=t;let l=0,s=this.space.c_arbiters_false.head;for(;s!=null;)s.elt.active&&++l,s=s.next;this.lengths[e++]=l,this._length+=l;let i=0,o=this.space.f_arbiters.head;for(;o!=null;)o.elt.active&&++i,o=o.next;this.lengths[e++]=i,this._length+=i;let r=0,a=this.space.s_arbiters.head;for(;a!=null;)a.elt.active&&++r,a=a.next;this.lengths[e++]=r,this._length+=r,this.zip_length=!1}return this._length}zpp_vm(){let e=!1;this.space.c_arbiters_true.modified&&(e=!0,this.space.c_arbiters_true.modified=!1),this.space.c_arbiters_false.modified&&(e=!0,this.space.c_arbiters_false.modified=!1),this.space.f_arbiters.modified&&(e=!0,this.space.f_arbiters.modified=!1),this.space.s_arbiters.modified&&(e=!0,this.space.s_arbiters.modified=!1),e&&(this.zip_length=!0,this._length=0,this.ite_0=null,this.ite_1=null,this.ite_2=null,this.ite_3=null)}push(e){throw new Error("Error: ArbiterList is immutable")}pop(){throw new Error("Error: ArbiterList is immutable")}unshift(e){throw new Error("Error: ArbiterList is immutable")}shift(){throw new Error("Error: ArbiterList is immutable")}remove(e){throw new Error("Error: ArbiterList is immutable")}clear(){throw new Error("Error: ArbiterList is immutable")}at(e){if(this.zpp_vm(),e<0||e>=this.zpp_gl())throw new Error("Error: Index out of bounds");let t=null,n=0;if(t==null)if(e<n+this.lengths[0]){let l=e-n;if(l<this.at_index_0||this.ite_0==null)for(this.at_index_0=0,this.ite_0=this.space.c_arbiters_true.head;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;for(;this.at_index_0!=l;)for(this.at_index_0++,this.ite_0=this.ite_0.next;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;t=this.ite_0.elt.wrapper()}else n+=this.lengths[0];if(t==null)if(e<n+this.lengths[1]){let l=e-n;if(l<this.at_index_1||this.ite_1==null)for(this.at_index_1=0,this.ite_1=this.space.c_arbiters_false.head;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;for(;this.at_index_1!=l;)for(this.at_index_1++,this.ite_1=this.ite_1.next;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;t=this.ite_1.elt.wrapper()}else n+=this.lengths[1];if(t==null)if(e<n+this.lengths[2]){let l=e-n;if(l<this.at_index_2||this.ite_2==null)for(this.at_index_2=0,this.ite_2=this.space.f_arbiters.head;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;for(;this.at_index_2!=l;)for(this.at_index_2++,this.ite_2=this.ite_2.next;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;t=this.ite_2.elt.wrapper()}else n+=this.lengths[2];if(t==null)if(e<n+this.lengths[3]){let l=e-n;if(l<this.at_index_3||this.ite_3==null)for(this.at_index_3=0,this.ite_3=this.space.s_arbiters.head;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;for(;this.at_index_3!=l;)for(this.at_index_3++,this.ite_3=this.ite_3.next;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;t=this.ite_3.elt.wrapper()}else n+=this.lengths[3];return t}};Gn.__name__=["zpp_nape","dynamics","ZPP_SpaceArbiterList"],Gn._nape=null,Gn._zpp=null;var Mt=class Mt{constructor(){this._invalidate=null;this._validate=null;this._immutable=!1;this.outer=null;this.next=null;this.minx=0;this.miny=0;this.maxx=0;this.maxy=0;this.wrap_min=null;this.wrap_max=null}static get(e,t,n,l){let s;return Mt.zpp_pool==null?s=new Mt:(s=Mt.zpp_pool,Mt.zpp_pool=s.next,s.next=null),s.minx=e,s.miny=t,s.maxx=n,s.maxy=l,s}validate(){this._validate!=null&&this._validate()}invalidate(){this._invalidate!=null&&this._invalidate(this)}wrapper(){if(this.outer==null)if(Mt._wrapFn)this.outer=Mt._wrapFn(this);else{this.outer=new Mt._nape.geom.AABB;let e=this.outer.zpp_inner;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e.wrap_min=e.wrap_max=null,e._invalidate=null,e._validate=null,e.next=Mt.zpp_pool,Mt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}alloc(){}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this.wrap_min=this.wrap_max=null,this._invalidate=null,this._validate=null}copy(){return Mt.get(this.minx,this.miny,this.maxx,this.maxy)}width(){return this.maxx-this.minx}height(){return this.maxy-this.miny}perimeter(){return(this.maxx-this.minx+(this.maxy-this.miny))*2}static _makeVec2Wrapper(e,t){let n=Mt._zpp,l=Mt._nape;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(n.util.ZPP_PubPool.poolVec2==null?s=new l.geom.Vec2:(s=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;n.geom.ZPP_Vec2.zpp_pool==null?i=new n.geom.ZPP_Vec2:(i=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=e,i.y=t,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");i._validate!=null&&i._validate(),(i.x!==e||i.y!==t)&&(i.x=e,i.y=t,i._invalidate!=null&&i._invalidate(i))}return s.zpp_inner.weak=!1,s}getmin(){this.wrap_min==null&&(this.wrap_min=Mt._makeVec2Wrapper(this.minx,this.miny),this.wrap_min.zpp_inner._inuse=!0,this._immutable?this.wrap_min.zpp_inner._immutable=!0:this.wrap_min.zpp_inner._invalidate=this.mod_min.bind(this),this.wrap_min.zpp_inner._validate=this.dom_min.bind(this))}dom_min(){this._validate!=null&&this._validate(),this.wrap_min.zpp_inner.x=this.minx,this.wrap_min.zpp_inner.y=this.miny}mod_min(e){(e.x!==this.minx||e.y!==this.miny)&&(this.minx=e.x,this.miny=e.y,this._invalidate!=null&&this._invalidate(this))}getmax(){this.wrap_max==null&&(this.wrap_max=Mt._makeVec2Wrapper(this.maxx,this.maxy),this.wrap_max.zpp_inner._inuse=!0,this._immutable?this.wrap_max.zpp_inner._immutable=!0:this.wrap_max.zpp_inner._invalidate=this.mod_max.bind(this),this.wrap_max.zpp_inner._validate=this.dom_max.bind(this))}dom_max(){this._validate!=null&&this._validate(),this.wrap_max.zpp_inner.x=this.maxx,this.wrap_max.zpp_inner.y=this.maxy}mod_max(e){(e.x!==this.maxx||e.y!==this.maxy)&&(this.maxx=e.x,this.maxy=e.y,this._invalidate!=null&&this._invalidate(this))}intersectX(e){return!(e.minx>this.maxx||this.minx>e.maxx)}intersectY(e){return!(e.miny>this.maxy||this.miny>e.maxy)}intersect(e){return e.miny<=this.maxy&&this.miny<=e.maxy&&e.minx<=this.maxx&&this.minx<=e.maxx}combine(e){e.minx<this.minx&&(this.minx=e.minx),e.maxx>this.maxx&&(this.maxx=e.maxx),e.miny<this.miny&&(this.miny=e.miny),e.maxy>this.maxy&&(this.maxy=e.maxy)}contains(e){return e.minx>=this.minx&&e.miny>=this.miny&&e.maxx<=this.maxx&&e.maxy<=this.maxy}containsPoint(e){return e.x>=this.minx&&e.x<=this.maxx&&e.y>=this.miny&&e.y<=this.maxy}setCombine(e,t){this.minx=e.minx<t.minx?e.minx:t.minx,this.miny=e.miny<t.miny?e.miny:t.miny,this.maxx=e.maxx>t.maxx?e.maxx:t.maxx,this.maxy=e.maxy>t.maxy?e.maxy:t.maxy}setExpand(e,t){this.minx=e.minx-t,this.miny=e.miny-t,this.maxx=e.maxx+t,this.maxy=e.maxy+t}setExpandPoint(e,t){e<this.minx&&(this.minx=e),e>this.maxx&&(this.maxx=e),t<this.miny&&(this.miny=t),t>this.maxy&&(this.maxy=t)}toString(){return"{ x: "+this.minx+" y: "+this.miny+" w: "+(this.maxx-this.minx)+" h: "+(this.maxy-this.miny)+" }"}};Mt.zpp_pool=null,Mt.__name__=["zpp_nape","geom","ZPP_AABB"],Mt._nape=null,Mt._zpp=null,Mt._wrapFn=null;var be=Mt;var Ce=class Ce{static _initStatics(e){Ce.flowpoly=new e.util.ZNPList_ZPP_Vec2,Ce.flowsegs=new e.util.ZNPList_ZPP_Vec2}static circleContains(e,t){let n=t.x-e.worldCOMx,l=t.y-e.worldCOMy;return n*n+l*l<e.radius*e.radius}static polyContains(e,t){let n;n=!0;let l=e.edges.head;for(;l!=null;){let s=l.elt;if(s.gnormx*t.x+s.gnormy*t.y<=s.gprojection){l=l.next;continue}else{n=!1;break}}return n}static shapeContains(e,t){return e.type==0?Ce.circleContains(e.circle,t):Ce.polyContains(e.polygon,t)}static bodyContains(e,t){let n;n=!1;let l=e.shapes.head;for(;l!=null;){let s=l.elt;if(Ce.shapeContains(s,t)){n=!0;break}l=l.next}return n}static containTest(e,t){let n=e.aabb,l=t.aabb;if(l.minx>=n.minx&&l.miny>=n.miny&&l.maxx<=n.maxx&&l.maxy<=n.maxy)if(e.type==0)if(t.type==0){let s=e.circle.radius+-t.circle.radius,i=t.circle.worldCOMx-e.circle.worldCOMx,o=t.circle.worldCOMy-e.circle.worldCOMy;return i*i+o*o<=s*s}else{let s;s=!0;let i=t.polygon.gverts.next;for(;i!=null;){let o=i,r=e.circle.radius,a=o.x-e.circle.worldCOMx,p=o.y-e.circle.worldCOMy;if(a*a+p*p<=r*r){i=i.next;continue}else{s=!1;break}}return s}else if(t.type==0){let s;s=!0;let i=e.polygon.edges.head;for(;i!=null;){let o=i.elt;if(o.gnormx*t.circle.worldCOMx+o.gnormy*t.circle.worldCOMy+t.circle.radius<=o.gprojection){i=i.next;continue}else{s=!1;break}}return s}else{let s;s=!0;let i=e.polygon.edges.head;for(;i!=null;){let o=i.elt,r=-1e100,a=t.polygon.gverts.next;for(;a!=null;){let p=a,c=o.gnormx*p.x+o.gnormy*p.y;c>r&&(r=c),a=a.next}if(r<=o.gprojection){i=i.next;continue}else{s=!1;break}}return s}else return!1}static contactCollide(e,t,n,l){let s=me();if(t.type==1)if(e.type==1){let i=!0,o=-1e100,r=-1e100,a=-1,p=null,c=null,u=e.polygon.edges.head;for(;u!=null;){let h=u.elt,x=1e100,b=t.polygon.gverts.next;for(;b!=null;){let _=b,d=h.gnormx*_.x+h.gnormy*_.y;if(d<x&&(x=d),x-h.gprojection<=o)break;b=b.next}if(x-=h.gprojection,x>=0){i=!1;break}x>o&&(o=x,p=h,a=1),u=u.next}if(i){let h=t.polygon.edges.head;for(;h!=null;){let x=h.elt,b=1e100,_=e.polygon.gverts.next;for(;_!=null;){let d=_,f=x.gnormx*d.x+x.gnormy*d.y;if(f<b&&(b=f),b-x.gprojection<=o)break;_=_.next}if(b-=x.gprojection,b>=0){i=!1;break}b>o&&(o=b,c=x,a=2),h=h.next}if(i){let x,b,_,d;a==1?(x=e.polygon,b=t.polygon,_=p,d=1):(x=t.polygon,b=e.polygon,_=c,d=-1);let f=null,m=1e100,z=b.edges.head;for(;z!=null;){let q=z.elt,R=_.gnormx*q.gnormx+_.gnormy*q.gnormy;R<m&&(m=R,f=q),z=z.next}let Z=f.gp0.x,y=f.gp0.y,w=f.gp1.x,v=f.gp1.y,P=w-Z,g=v-y,k=_.gnormy*Z-_.gnormx*y,N=_.gnormy*w-_.gnormx*v,E=1/(N-k),M=(-_.tp1-k)*E;if(M>s.Config.epsilon){let q=M;Z+=P*q,y+=g*q}let C=(-_.tp0-N)*E;if(C<-s.Config.epsilon){let q=C;w+=P*q,v+=g*q}let D=d,O=_.gnormx*D,j=_.gnormy*D;n.lnormx=_.lnormx,n.lnormy=_.lnormy,n.lproj=_.lprojection,n.radius=0,n.rev=l!=(d==-1),n.ptype=n.rev?1:0;let L=Z*_.gnormx+y*_.gnormy-_.gprojection,U=w*_.gnormx+v*_.gnormy-_.gprojection;if(L>0&&U>0)return!1;{l&&(O=-O,j=-j);let q=Z-_.gnormx*L*.5,R=y-_.gnormy*L*.5,B=n.rev?1:0,S=L>0;S==null&&(S=!1);let J=null,Q=n.contacts.next;for(;Q!=null;){let K=Q;if(B==K.hash){J=K;break}Q=Q.next}if(J==null){we.zpp_pool==null?J=new we:(J=we.zpp_pool,we.zpp_pool=J.next,J.next=null);let K=J.inner;K.jnAcc=K.jtAcc=0,J.hash=B,J.fresh=!0,J.arbiter=n,n.jrAcc=0;let ne=n.contacts;J._inuse=!0;let re=J;re.next=ne.next,ne.next=re,ne.modified=!0,ne.length++,n.innards.add(K)}else J.fresh=!1;J.px=q,J.py=R,n.nx=O,n.ny=j,J.dist=L,J.stamp=n.stamp,J.posOnly=S;let Y=J,X=1;Z-=b.body.posx*X,y-=b.body.posy*X,Y.inner.lr1x=Z*b.body.axisy+y*b.body.axisx,Y.inner.lr1y=y*b.body.axisy-Z*b.body.axisx;let ee=w-_.gnormx*U*.5,G=v-_.gnormy*U*.5,F=n.rev?0:1,T=U>0;T==null&&(T=!1);let A=null,W=n.contacts.next;for(;W!=null;){let K=W;if(F==K.hash){A=K;break}W=W.next}if(A==null){we.zpp_pool==null?A=new we:(A=we.zpp_pool,we.zpp_pool=A.next,A.next=null);let K=A.inner;K.jnAcc=K.jtAcc=0,A.hash=F,A.fresh=!0,A.arbiter=n,n.jrAcc=0;let ne=n.contacts;A._inuse=!0;let re=A;re.next=ne.next,ne.next=re,ne.modified=!0,ne.length++,n.innards.add(K)}else A.fresh=!1;A.px=ee,A.py=G,n.nx=O,n.ny=j,A.dist=U,A.stamp=n.stamp,A.posOnly=T,Y=A;let H=1;return w-=b.body.posx*H,v-=b.body.posy*H,Y.inner.lr1x=w*b.body.axisy+v*b.body.axisx,Y.inner.lr1y=v*b.body.axisy-w*b.body.axisx,a==1?(n.__ref_edge1=_,n.__ref_edge2=f):(n.__ref_edge2=_,n.__ref_edge1=f),!0}}else return!1}else return!1}else{let i=-1e100,o=-1e100,r=!0,a=null,p=null,c=t.polygon.gverts.next,u=t.polygon.edges.head;for(;u!=null;){let h=u.elt,x=h.gnormx*e.circle.worldCOMx+h.gnormy*e.circle.worldCOMy-h.gprojection-e.circle.radius;if(x>0){r=!1;break}x>i&&(i=x,a=h,p=c),c=c.next,u=u.next}if(r){let h=p,x=p.next==null?t.polygon.gverts.next:p.next,b=e.circle.worldCOMy*a.gnormx-e.circle.worldCOMx*a.gnormy;if(b<=h.y*a.gnormx-h.x*a.gnormy){let _=e.circle.radius,d=h.x-e.circle.worldCOMx,f=h.y-e.circle.worldCOMy,m=d*d+f*f,z;if(m>_*_)z=null;else if(m<s.Config.epsilon*s.Config.epsilon){let Z=e.circle.worldCOMx,y=e.circle.worldCOMy,w=null,v=n.contacts.next;for(;v!=null;){let P=v;if(P.hash==0){w=P;break}v=v.next}if(w==null){we.zpp_pool==null?w=new we:(w=we.zpp_pool,we.zpp_pool=w.next,w.next=null);let P=w.inner;P.jnAcc=P.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let k=w;k.next=g.next,g.next=k,g.modified=!0,g.length++,n.innards.add(P)}else w.fresh=!1;w.px=Z,w.py=y,n.nx=1,n.ny=0,w.dist=-_,w.stamp=n.stamp,w.posOnly=!1,z=w}else{let Z=1/Math.sqrt(m),y=Z<s.Config.epsilon?1e100:1/Z,w=.5+(e.circle.radius-.5*_)*Z;if(l){let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+f*w,g=null,k=n.contacts.next;for(;k!=null;){let N=k;if(N.hash==0){g=N;break}k=k.next}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let E=n.contacts;g._inuse=!0;let M=g;M.next=E.next,E.next=M,E.modified=!0,E.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=-d*Z,n.ny=-f*Z,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}else{let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+f*w,g=null,k=n.contacts.next;for(;k!=null;){let N=k;if(N.hash==0){g=N;break}k=k.next}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let E=n.contacts;g._inuse=!0;let M=g;M.next=E.next,E.next=M,E.modified=!0,E.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=d*Z,n.ny=f*Z,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}}if(z!=null){let Z=z.inner;n.ptype=2;let y=h.x-t.polygon.body.posx,w=h.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=-1,l?(Z.lr1x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,Z.lr1y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,Z.lr2x=e.circle.localCOMx,Z.lr2y=e.circle.localCOMy):(Z.lr2x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,Z.lr2y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,Z.lr1x=e.circle.localCOMx,Z.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return z!=null}else if(b>=x.y*a.gnormx-x.x*a.gnormy){let _=e.circle.radius,d=x.x-e.circle.worldCOMx,f=x.y-e.circle.worldCOMy,m=d*d+f*f,z;if(m>_*_)z=null;else if(m<s.Config.epsilon*s.Config.epsilon){let Z=e.circle.worldCOMx,y=e.circle.worldCOMy,w=null,v=n.contacts.next;for(;v!=null;){let P=v;if(P.hash==0){w=P;break}v=v.next}if(w==null){we.zpp_pool==null?w=new we:(w=we.zpp_pool,we.zpp_pool=w.next,w.next=null);let P=w.inner;P.jnAcc=P.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let k=w;k.next=g.next,g.next=k,g.modified=!0,g.length++,n.innards.add(P)}else w.fresh=!1;w.px=Z,w.py=y,n.nx=1,n.ny=0,w.dist=-_,w.stamp=n.stamp,w.posOnly=!1,z=w}else{let Z=1/Math.sqrt(m),y=Z<s.Config.epsilon?1e100:1/Z,w=.5+(e.circle.radius-.5*_)*Z;if(l){let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+f*w,g=null,k=n.contacts.next;for(;k!=null;){let N=k;if(N.hash==0){g=N;break}k=k.next}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let E=n.contacts;g._inuse=!0;let M=g;M.next=E.next,E.next=M,E.modified=!0,E.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=-d*Z,n.ny=-f*Z,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}else{let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+f*w,g=null,k=n.contacts.next;for(;k!=null;){let N=k;if(N.hash==0){g=N;break}k=k.next}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let E=n.contacts;g._inuse=!0;let M=g;M.next=E.next,E.next=M,E.modified=!0,E.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=d*Z,n.ny=f*Z,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}}if(z!=null){let Z=z.inner;n.ptype=2;let y=x.x-t.polygon.body.posx,w=x.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=1,l?(Z.lr1x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,Z.lr1y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,Z.lr2x=e.circle.localCOMx,Z.lr2y=e.circle.localCOMy):(Z.lr2x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,Z.lr2y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,Z.lr1x=e.circle.localCOMx,Z.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return z!=null}else{let _=e.circle.radius+i*.5,d=a.gnormx*_,f=a.gnormy*_,m=e.circle.worldCOMx-d,z=e.circle.worldCOMy-f,Z;if(l){let y=a.gnormx,w=a.gnormy,v=null,P=n.contacts.next;for(;P!=null;){let g=P;if(g.hash==0){v=g;break}P=P.next}if(v==null){we.zpp_pool==null?v=new we:(v=we.zpp_pool,we.zpp_pool=v.next,v.next=null);let g=v.inner;g.jnAcc=g.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let k=n.contacts;v._inuse=!0;let N=v;N.next=k.next,k.next=N,k.modified=!0,k.length++,n.innards.add(g)}else v.fresh=!1;v.px=m,v.py=z,n.nx=y,n.ny=w,v.dist=i,v.stamp=n.stamp,v.posOnly=!1,Z=v}else{let y=-a.gnormx,w=-a.gnormy,v=null,P=n.contacts.next;for(;P!=null;){let g=P;if(g.hash==0){v=g;break}P=P.next}if(v==null){we.zpp_pool==null?v=new we:(v=we.zpp_pool,we.zpp_pool=v.next,v.next=null);let g=v.inner;g.jnAcc=g.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let k=n.contacts;v._inuse=!0;let N=v;N.next=k.next,k.next=N,k.modified=!0,k.length++,n.innards.add(g)}else v.fresh=!1;v.px=m,v.py=z,n.nx=y,n.ny=w,v.dist=i,v.stamp=n.stamp,v.posOnly=!1,Z=v}return n.ptype=l?0:1,n.lnormx=a.lnormx,n.lnormy=a.lnormy,n.rev=!l,n.lproj=a.lprojection,n.radius=e.circle.radius,Z.inner.lr1x=e.circle.localCOMx,Z.inner.lr1y=e.circle.localCOMy,n.__ref_edge1=a,n.__ref_vertex=0,!0}}else return!1}else{let i=e.circle.radius+t.circle.radius,o=t.circle.worldCOMx-e.circle.worldCOMx,r=t.circle.worldCOMy-e.circle.worldCOMy,a=o*o+r*r,p;if(a>i*i)p=null;else if(a<s.Config.epsilon*s.Config.epsilon){let c=e.circle.worldCOMx,u=e.circle.worldCOMy,h=null,x=n.contacts.next;for(;x!=null;){let b=x;if(b.hash==0){h=b;break}x=x.next}if(h==null){we.zpp_pool==null?h=new we:(h=we.zpp_pool,we.zpp_pool=h.next,h.next=null);let b=h.inner;b.jnAcc=b.jtAcc=0,h.hash=0,h.fresh=!0,h.arbiter=n,n.jrAcc=0;let _=n.contacts;h._inuse=!0;let d=h;d.next=_.next,_.next=d,_.modified=!0,_.length++,n.innards.add(b)}else h.fresh=!1;h.px=c,h.py=u,n.nx=1,n.ny=0,h.dist=-i,h.stamp=n.stamp,h.posOnly=!1,p=h}else{let c=1/Math.sqrt(a),u=c<s.Config.epsilon?1e100:1/c,h=.5+(e.circle.radius-.5*i)*c;if(l){let x=e.circle.worldCOMx+o*h,b=e.circle.worldCOMy+r*h,_=null,d=n.contacts.next;for(;d!=null;){let f=d;if(f.hash==0){_=f;break}d=d.next}if(_==null){we.zpp_pool==null?_=new we:(_=we.zpp_pool,we.zpp_pool=_.next,_.next=null);let f=_.inner;f.jnAcc=f.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let m=n.contacts;_._inuse=!0;let z=_;z.next=m.next,m.next=z,m.modified=!0,m.length++,n.innards.add(f)}else _.fresh=!1;_.px=x,_.py=b,n.nx=-o*c,n.ny=-r*c,_.dist=u-i,_.stamp=n.stamp,_.posOnly=!1,p=_}else{let x=e.circle.worldCOMx+o*h,b=e.circle.worldCOMy+r*h,_=null,d=n.contacts.next;for(;d!=null;){let f=d;if(f.hash==0){_=f;break}d=d.next}if(_==null){we.zpp_pool==null?_=new we:(_=we.zpp_pool,we.zpp_pool=_.next,_.next=null);let f=_.inner;f.jnAcc=f.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let m=n.contacts;_._inuse=!0;let z=_;z.next=m.next,m.next=z,m.modified=!0,m.length++,n.innards.add(f)}else _.fresh=!1;_.px=x,_.py=b,n.nx=o*c,n.ny=r*c,_.dist=u-i,_.stamp=n.stamp,_.posOnly=!1,p=_}}if(p!=null){let c=p.inner;return l?(c.lr1x=t.circle.localCOMx,c.lr1y=t.circle.localCOMy,c.lr2x=e.circle.localCOMx,c.lr2y=e.circle.localCOMy):(c.lr1x=e.circle.localCOMx,c.lr1y=e.circle.localCOMy,c.lr2x=t.circle.localCOMx,c.lr2y=t.circle.localCOMy),n.radius=e.circle.radius+t.circle.radius,n.ptype=2,!0}else return!1}}static testCollide_safe(e,t){let n=me();if(t.type==0){let l=e;e=t,t=l}return Ce.testCollide(e,t)}static testCollide(e,t){let n=me();if(t.type==1)if(e.type==1){let l=!0,s=e.polygon.edges.head;for(;s!=null;){let i=s.elt,o=1e100,r=t.polygon.gverts.next;for(;r!=null;){let a=r,p=i.gnormx*a.x+i.gnormy*a.y;p<o&&(o=p),r=r.next}if(o-=i.gprojection,o>0){l=!1;break}s=s.next}if(l){let i=t.polygon.edges.head;for(;i!=null;){let o=i.elt,r=1e100,a=e.polygon.gverts.next;for(;a!=null;){let p=a,c=o.gnormx*p.x+o.gnormy*p.y;c<r&&(r=c),a=a.next}if(r-=o.gprojection,r>0){l=!1;break}i=i.next}return l}else return!1}else{let l=null,s=null,i=!0,o=-1e100,r=t.polygon.gverts.next,a=t.polygon.edges.head;for(;a!=null;){let p=a.elt,c=p.gnormx*e.circle.worldCOMx+p.gnormy*e.circle.worldCOMy-p.gprojection-e.circle.radius;if(c>0){i=!1;break}c>o&&(o=c,l=p,s=r),r=r.next,a=a.next}if(i){let p=s,c=s.next==null?t.polygon.gverts.next:s.next,u=e.circle.worldCOMy*l.gnormx-e.circle.worldCOMx*l.gnormy;if(u<=p.y*l.gnormx-p.x*l.gnormy){let h=e.circle.radius,x=p.x-e.circle.worldCOMx,b=p.y-e.circle.worldCOMy;return x*x+b*b<=h*h}else if(u>=c.y*l.gnormx-c.x*l.gnormy){let h=e.circle.radius,x=c.x-e.circle.worldCOMx,b=c.y-e.circle.worldCOMy;return x*x+b*b<=h*h}else return!0}else return!1}else{let l=e.circle.radius+t.circle.radius,s=t.circle.worldCOMx-e.circle.worldCOMx,i=t.circle.worldCOMy-e.circle.worldCOMy;return s*s+i*i<=l*l}}static flowCollide(e,t,n){let l=me();if(t.type==1)if(e.type==1){let s=[],i=[],o=!0,r=!0,a=e.polygon.edges.head;for(;a!=null;){let p=a.elt,c=1e100,u=0,h=t.polygon.gverts.next;for(;h!=null;){let x=h,b=p.gnormx*x.x+p.gnormy*x.y;b<c&&(c=b),b>=p.gprojection+l.Config.epsilon&&(i[u]=!0,r=!1),++u,h=h.next}if(c-=p.gprojection,c>0){o=!1;break}a=a.next}if(r){let p=t.polygon;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=!1,p.zip_localCOM){if(p.zip_localCOM=!1,p.type==1){let u=p.polygon;if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(u.lverts.next.next==null)u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;else if(u.lverts.next.next.next==null){u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;let h=1;u.localCOMx+=u.lverts.next.next.x*h,u.localCOMy+=u.lverts.next.next.y*h;let x=.5;u.localCOMx*=x,u.localCOMy*=x}else{u.localCOMx=0,u.localCOMy=0;let h=0,x=u.lverts.next,b=x;x=x.next;let _=x;for(x=x.next;x!=null;){let y=x;h+=_.x*(y.y-b.y);let w=y.y*_.x-y.x*_.y;u.localCOMx+=(_.x+y.x)*w,u.localCOMy+=(_.y+y.y)*w,b=_,_=y,x=x.next}x=u.lverts.next;let d=x;h+=_.x*(d.y-b.y);let f=d.y*_.x-d.x*_.y;u.localCOMx+=(_.x+d.x)*f,u.localCOMy+=(_.y+d.y)*f,b=_,_=d,x=x.next;let m=x;h+=_.x*(m.y-b.y);let z=m.y*_.x-m.x*_.y;u.localCOMx+=(_.x+m.x)*z,u.localCOMy+=(_.y+m.y)*z,h=1/(3*h);let Z=h;u.localCOMx*=Z,u.localCOMy*=Z}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let c=p.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else if(o){r=!0;let p=t.polygon.edges.head;for(;p!=null;){let c=p.elt,u=1e100,h=0,x=e.polygon.gverts.next;for(;x!=null;){let b=x,_=c.gnormx*b.x+c.gnormy*b.y;_<u&&(u=_),_>=c.gprojection+l.Config.epsilon&&(s[h]=!0,r=!1),++h,x=x.next}if(u-=c.gprojection,u>0){o=!1;break}p=p.next}if(r){let c=e.polygon;if(c.zip_worldCOM&&c.body!=null){if(c.zip_worldCOM=!1,c.zip_localCOM){if(c.zip_localCOM=!1,c.type==1){let h=c.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let x=1;h.localCOMx+=h.lverts.next.next.x*x,h.localCOMy+=h.lverts.next.next.y*x;let b=.5;h.localCOMx*=b,h.localCOMy*=b}else{h.localCOMx=0,h.localCOMy=0;let x=0,b=h.lverts.next,_=b;b=b.next;let d=b;for(b=b.next;b!=null;){let w=b;x+=d.x*(w.y-_.y);let v=w.y*d.x-w.x*d.y;h.localCOMx+=(d.x+w.x)*v,h.localCOMy+=(d.y+w.y)*v,_=d,d=w,b=b.next}b=h.lverts.next;let f=b;x+=d.x*(f.y-_.y);let m=f.y*d.x-f.x*d.y;h.localCOMx+=(d.x+f.x)*m,h.localCOMy+=(d.y+f.y)*m,_=d,d=f,b=b.next;let z=b;x+=d.x*(z.y-_.y);let Z=z.y*d.x-z.x*d.y;h.localCOMx+=(d.x+z.x)*Z,h.localCOMy+=(d.y+z.y)*Z,x=1/(3*x);let y=x;h.localCOMx*=y,h.localCOMy*=y}}c.wrap_localCOM!=null&&(c.wrap_localCOM.zpp_inner.x=c.localCOMx,c.wrap_localCOM.zpp_inner.y=c.localCOMy)}let u=c.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),c.worldCOMx=c.body.posx+(c.body.axisy*c.localCOMx-c.body.axisx*c.localCOMy),c.worldCOMy=c.body.posy+(c.localCOMx*c.body.axisx+c.localCOMy*c.body.axisy)}return n.overlap=e.polygon.area,n.centroidx=e.polygon.worldCOMx,n.centroidy=e.polygon.worldCOMy,!0}else if(o){for(;Ce.flowpoly.head!=null;){let z=Ce.flowpoly.pop_unsafe();if(!z._inuse){let Z=z;Z.outer!=null&&(Z.outer.zpp_inner=null,Z.outer=null),Z._isimmutable=null,Z._validate=null,Z._invalidate=null,Z.next=le.zpp_pool,le.zpp_pool=Z}}let c=null,u=!1,h=e.polygon.gverts.next,x=0,b=t.polygon.gverts.next,_=0,d=0,f=t.polygon.edgeCnt;for(;d<f;){let z=d++;if(i[z])b=b.next;else{_=z;break}}if(b==null){b=t.polygon.gverts.next,u=!0;let z=0,Z=e.polygon.edgeCnt;for(;z<Z;){let y=z++;if(s[y])h=h.next;else{x=y;break}}h==null?h=e.polygon.gverts.next:(Ce.flowpoly.add(h),c=Ce.flowpoly.head.elt)}else Ce.flowpoly.add(b),c=Ce.flowpoly.head.elt;let m=1;if(Ce.flowpoly.head==null){let z=!0,Z=e.polygon.gverts.next,y=Z,w=Z.next;for(;w!=null;){let v=w,P=2,g=!0,k=t.polygon.gverts.next,N=k,E=k.next;for(;E!=null;){let M=E,C=0,D=y.x-N.x,O=y.y-N.y,j=v.x-y.x,L=v.y-y.y,U=M.x-N.x,q=M.y-N.y,R=L*U-j*q,B;if(R*R>l.Config.epsilon*l.Config.epsilon){R=1/R;let S=(q*D-U*O)*R;if(S>l.Config.epsilon&&S<1-l.Config.epsilon){let J=(L*D-j*O)*R;J>l.Config.epsilon&&J<1-l.Config.epsilon?(C=S,B=!0):B=!1}else B=!1}else B=!1;B&&C<P&&(P=C,b=k),k=E,N=M,E=E.next}if(g)for(;;){E=t.polygon.gverts.next;let M=E,C=0,D=y.x-N.x,O=y.y-N.y,j=v.x-y.x,L=v.y-y.y,U=M.x-N.x,q=M.y-N.y,R=L*U-j*q,B;if(R*R>l.Config.epsilon*l.Config.epsilon){R=1/R;let S=(q*D-U*O)*R;if(S>l.Config.epsilon&&S<1-l.Config.epsilon){let J=(L*D-j*O)*R;J>l.Config.epsilon&&J<1-l.Config.epsilon?(C=S,B=!0):B=!1}else B=!1}else B=!1;B&&C<P&&(P=C,b=k);break}if(P!=2){let M=P,C=y.x+(v.x-y.x)*M,D=y.y+(v.y-y.y)*M,O;le.zpp_pool==null?O=new le:(O=le.zpp_pool,le.zpp_pool=O.next,O.next=null),O.weak=!1,O._immutable=!1,O.x=C,O.y=D,c=O,Ce.flowpoly.add(c),u=!0,h=Z,z=!1;break}Z=w,y=v,w=w.next}if(z)for(;;){w=e.polygon.gverts.next;let v=w,P=2,g=!0,k=t.polygon.gverts.next,N=k,E=k.next;for(;E!=null;){let M=E,C=0,D=y.x-N.x,O=y.y-N.y,j=v.x-y.x,L=v.y-y.y,U=M.x-N.x,q=M.y-N.y,R=L*U-j*q,B;if(R*R>l.Config.epsilon*l.Config.epsilon){R=1/R;let S=(q*D-U*O)*R;if(S>l.Config.epsilon&&S<1-l.Config.epsilon){let J=(L*D-j*O)*R;J>l.Config.epsilon&&J<1-l.Config.epsilon?(C=S,B=!0):B=!1}else B=!1}else B=!1;B&&C<P&&(P=C,b=k),k=E,N=M,E=E.next}if(g)for(;;){E=t.polygon.gverts.next;let M=E,C=0,D=y.x-N.x,O=y.y-N.y,j=v.x-y.x,L=v.y-y.y,U=M.x-N.x,q=M.y-N.y,R=L*U-j*q,B;if(R*R>l.Config.epsilon*l.Config.epsilon){R=1/R;let S=(q*D-U*O)*R;if(S>l.Config.epsilon&&S<1-l.Config.epsilon){let J=(L*D-j*O)*R;J>l.Config.epsilon&&J<1-l.Config.epsilon?(C=S,B=!0):B=!1}else B=!1}else B=!1;B&&C<P&&(P=C,b=k);break}if(P!=2){let M=P,C=y.x+(v.x-y.x)*M,D=y.y+(v.y-y.y)*M,O;le.zpp_pool==null?O=new le:(O=le.zpp_pool,le.zpp_pool=O.next,O.next=null),O.weak=!1,O._immutable=!1,O.x=C,O.y=D,c=O,Ce.flowpoly.add(c),u=!0,h=Z;break}break}m=2}for(;;)if(u)if(h=h.next,++x,h==null&&(h=e.polygon.gverts.next,x=0),s[x]){let z=Ce.flowpoly.head.elt,Z=h,y=b,w=b.next;w==null&&(w=t.polygon.gverts.next);let v=-1,P=null,g=0,k=0,N=w,E=w;for(;;){let B=E,S=0,J=y.x-z.x,Q=y.y-z.y,Y=B.x-y.x,X=B.y-y.y,ee=Z.x-z.x,G=Z.y-z.y,F=X*ee-Y*G,T;if(F*F>l.Config.epsilon*l.Config.epsilon){F=1/F;let A=(G*J-ee*Q)*F;if(A>l.Config.epsilon&&A<1-l.Config.epsilon){let W=(X*J-Y*Q)*F;W>l.Config.epsilon&&W<1-l.Config.epsilon?(S=A,T=!0):T=!1}else T=!1}else T=!1;if(T&&S>=v)if(P=b,g=_,++k==m){v=S,E=N;break}else v=S;y=B,b=E,++_,_>=t.polygon.edgeCnt&&(_=0),E=E.next,E==null&&(E=t.polygon.gverts.next);break}for(;E!=N;){let B=E,S=0,J=y.x-z.x,Q=y.y-z.y,Y=B.x-y.x,X=B.y-y.y,ee=Z.x-z.x,G=Z.y-z.y,F=X*ee-Y*G,T;if(F*F>l.Config.epsilon*l.Config.epsilon){F=1/F;let A=(G*J-ee*Q)*F;if(A>l.Config.epsilon&&A<1-l.Config.epsilon){let W=(X*J-Y*Q)*F;W>l.Config.epsilon&&W<1-l.Config.epsilon?(S=A,T=!0):T=!1}else T=!1}else T=!1;if(T&&S>=v)if(P=b,g=_,++k==m){v=S;break}else v=S;y=B,b=E,++_,_>=t.polygon.edgeCnt&&(_=0),E=E.next,E==null&&(E=t.polygon.gverts.next)}if(P==null)break;let M=P,C=P.next;C==null&&(C=t.polygon.gverts.next);let D=C,O=v,j=M.x+(D.x-M.x)*O,L=M.y+(D.y-M.y)*O,U;if(c!=null){let B=j-c.x,S=L-c.y;U=B*B+S*S<l.Config.epsilon}else U=!1;if(U)break;let q=Ce.flowpoly,R;le.zpp_pool==null?R=new le:(R=le.zpp_pool,le.zpp_pool=R.next,R.next=null),R.weak=!1,R._immutable=!1,R.x=j,R.y=L,q.add(R),c==null&&(c=Ce.flowpoly.head.elt),b=P,_=g,u=!u,m=2}else{let z=h,Z;if(c!=null){let y=z.x-c.x,w=z.y-c.y;Z=y*y+w*w<l.Config.epsilon}else Z=!1;if(Z)break;Ce.flowpoly.add(z),c==null&&(c=Ce.flowpoly.head.elt),m=1}else if(b=b.next,++_,b==null&&(b=t.polygon.gverts.next,_=0),i[_]){let z=Ce.flowpoly.head.elt,Z=b,y=h,w=h.next;w==null&&(w=e.polygon.gverts.next);let v=-1,P=null,g=0,k=0,N=w,E=w;for(;;){let B=E,S=0,J=y.x-z.x,Q=y.y-z.y,Y=B.x-y.x,X=B.y-y.y,ee=Z.x-z.x,G=Z.y-z.y,F=X*ee-Y*G,T;if(F*F>l.Config.epsilon*l.Config.epsilon){F=1/F;let A=(G*J-ee*Q)*F;if(A>l.Config.epsilon&&A<1-l.Config.epsilon){let W=(X*J-Y*Q)*F;W>l.Config.epsilon&&W<1-l.Config.epsilon?(S=A,T=!0):T=!1}else T=!1}else T=!1;if(T&&S>=v)if(P=h,g=x,++k==m){v=S,E=N;break}else v=S;y=B,h=E,++x,x>=e.polygon.edgeCnt&&(x=0),E=E.next,E==null&&(E=e.polygon.gverts.next);break}for(;E!=N;){let B=E,S=0,J=y.x-z.x,Q=y.y-z.y,Y=B.x-y.x,X=B.y-y.y,ee=Z.x-z.x,G=Z.y-z.y,F=X*ee-Y*G,T;if(F*F>l.Config.epsilon*l.Config.epsilon){F=1/F;let A=(G*J-ee*Q)*F;if(A>l.Config.epsilon&&A<1-l.Config.epsilon){let W=(X*J-Y*Q)*F;W>l.Config.epsilon&&W<1-l.Config.epsilon?(S=A,T=!0):T=!1}else T=!1}else T=!1;if(T&&S>=v)if(P=h,g=x,++k==m){v=S;break}else v=S;y=B,h=E,++x,x>=e.polygon.edgeCnt&&(x=0),E=E.next,E==null&&(E=e.polygon.gverts.next)}if(P==null)break;let M=P,C=P.next;C==null&&(C=e.polygon.gverts.next);let D=C,O=v,j=M.x+(D.x-M.x)*O,L=M.y+(D.y-M.y)*O,U;if(c!=null){let B=j-c.x,S=L-c.y;U=B*B+S*S<l.Config.epsilon}else U=!1;if(U)break;let q=Ce.flowpoly,R;le.zpp_pool==null?R=new le:(R=le.zpp_pool,le.zpp_pool=R.next,R.next=null),R.weak=!1,R._immutable=!1,R.x=j,R.y=L,q.add(R),c==null&&(c=Ce.flowpoly.head.elt),h=P,x=g,u=!u,m=2}else{let z=b,Z;if(c!=null){let y=z.x-c.x,w=z.y-c.y;Z=y*y+w*w<l.Config.epsilon}else Z=!1;if(Z)break;Ce.flowpoly.add(z),c==null&&(c=Ce.flowpoly.head.elt),m=1}if(Ce.flowpoly.head!=null&&Ce.flowpoly.head.next!=null&&Ce.flowpoly.head.next.next!=null){let z=0,Z=0,y=0,w=Ce.flowpoly.head,v=w.elt;w=w.next;let P=w.elt;for(w=w.next;w!=null;){let D=w.elt;z+=P.x*(D.y-v.y);let O=D.y*P.x-D.x*P.y;Z+=(P.x+D.x)*O,y+=(P.y+D.y)*O,v=P,P=D,w=w.next}w=Ce.flowpoly.head;let g=w.elt;z+=P.x*(g.y-v.y);let k=g.y*P.x-g.x*P.y;Z+=(P.x+g.x)*k,y+=(P.y+g.y)*k,v=P,P=g,w=w.next;let N=w.elt;z+=P.x*(N.y-v.y);let E=N.y*P.x-N.x*P.y;Z+=(P.x+N.x)*E,y+=(P.y+N.y)*E,z*=.5;let C=1/(6*z);return Z*=C,y*=C,n.overlap=-z,n.centroidx=Z,n.centroidy=y,!0}else return!1}else return!1}else return!1}else{let s=[],i=!0,o=null,r=null,a=-1e100,p=!0,c=t.polygon.gverts.next,u=0,h=t.polygon.edges.head;for(;h!=null;){let x=h.elt,b=x.gnormx*e.circle.worldCOMx+x.gnormy*e.circle.worldCOMy;if(b>x.gprojection+e.circle.radius){p=!1;break}else b+e.circle.radius>x.gprojection+l.Config.epsilon&&(i=!1,s[u]=!0);b-=x.gprojection+e.circle.radius,b>a&&(a=b,o=x,r=c),c=c.next,++u,h=h.next}if(p){if(i)return n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0;{let x=r,b=r.next==null?t.polygon.gverts.next:r.next,_=e.circle.worldCOMy*o.gnormx-e.circle.worldCOMx*o.gnormy,d;if(_<=x.y*o.gnormx-x.x*o.gnormy){let f=e.circle.radius,m=x.x-e.circle.worldCOMx,z=x.y-e.circle.worldCOMy;d=m*m+z*z<=f*f}else if(_>=b.y*o.gnormx-b.x*o.gnormy){let f=e.circle.radius,m=b.x-e.circle.worldCOMx,z=b.y-e.circle.worldCOMy;d=m*m+z*z<=f*f}else d=!0;if(d){let f=[],m=0,z=!0,Z=null,y=0,w=t.polygon.gverts.next;for(;w!=null;){let v=w,P=v.x-e.circle.worldCOMx,g=v.y-e.circle.worldCOMy,k=P*P+g*g;(f[m]=k<=e.circle.radius*e.circle.radius)?(y=m,Z=w):z=!1,++m,w=w.next}if(z){let v=t.polygon;if(v.zip_worldCOM&&v.body!=null){if(v.zip_worldCOM=!1,v.zip_localCOM){if(v.zip_localCOM=!1,v.type==1){let g=v.polygon;if(g.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(g.lverts.next.next==null)g.localCOMx=g.lverts.next.x,g.localCOMy=g.lverts.next.y;else if(g.lverts.next.next.next==null){g.localCOMx=g.lverts.next.x,g.localCOMy=g.lverts.next.y;let k=1;g.localCOMx+=g.lverts.next.next.x*k,g.localCOMy+=g.lverts.next.next.y*k;let N=.5;g.localCOMx*=N,g.localCOMy*=N}else{g.localCOMx=0,g.localCOMy=0;let k=0,N=g.lverts.next,E=N;N=N.next;let M=N;for(N=N.next;N!=null;){let U=N;k+=M.x*(U.y-E.y);let q=U.y*M.x-U.x*M.y;g.localCOMx+=(M.x+U.x)*q,g.localCOMy+=(M.y+U.y)*q,E=M,M=U,N=N.next}N=g.lverts.next;let C=N;k+=M.x*(C.y-E.y);let D=C.y*M.x-C.x*M.y;g.localCOMx+=(M.x+C.x)*D,g.localCOMy+=(M.y+C.y)*D,E=M,M=C,N=N.next;let O=N;k+=M.x*(O.y-E.y);let j=O.y*M.x-O.x*M.y;g.localCOMx+=(M.x+O.x)*j,g.localCOMy+=(M.y+O.y)*j,k=1/(3*k);let L=k;g.localCOMx*=L,g.localCOMy*=L}}v.wrap_localCOM!=null&&(v.wrap_localCOM.zpp_inner.x=v.localCOMx,v.wrap_localCOM.zpp_inner.y=v.localCOMy)}let P=v.body;P.zip_axis&&(P.zip_axis=!1,P.axisx=Math.sin(P.rot),P.axisy=Math.cos(P.rot)),v.worldCOMx=v.body.posx+(v.body.axisy*v.localCOMx-v.body.axisx*v.localCOMy),v.worldCOMy=v.body.posy+(v.localCOMx*v.body.axisx+v.localCOMy*v.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else{for(;Ce.flowpoly.head!=null;){let g=Ce.flowpoly.pop_unsafe();if(!g._inuse){let k=g;k.outer!=null&&(k.outer.zpp_inner=null,k.outer=null),k._isimmutable=null,k._validate=null,k._invalidate=null,k.next=le.zpp_pool,le.zpp_pool=k}}Ce.flowsegs.clear();let v=null,P=1;for(Z==null?(Z=t.polygon.gverts.next,P=2):(v=Z,Ce.flowpoly.add(v));P!=0;)if(P==1)if(Z=Z.next,Z==null&&(Z=t.polygon.gverts.next),++y,y>=t.polygon.edgeCnt&&(y=0),f[y]){let g=v.x-Z.x,k=v.y-Z.y;if(g*g+k*k<l.Config.epsilon)break;Ce.flowpoly.add(Z)}else{let g=Ce.flowpoly.head.elt,k=Z,N=k.x-g.x,E=k.y-g.y,M=g.x-e.circle.worldCOMx,C=g.y-e.circle.worldCOMy,D=N*N+E*E,O=2*(M*N+C*E),j=M*M+C*C-e.circle.radius*e.circle.radius,L=Math.sqrt(O*O-4*D*j);D=1/(2*D);let U=(-O-L)*D,q=U<l.Config.epsilon?(-O+L)*D:U,R=0,B=0,S=q;R=g.x+(k.x-g.x)*S,B=g.y+(k.y-g.y)*S;let J=v.x-R,Q=v.y-B;if(J*J+Q*Q<l.Config.epsilon)break;let Y=Ce.flowpoly,X;le.zpp_pool==null?X=new le:(X=le.zpp_pool,le.zpp_pool=X.next,X.next=null),X.weak=!1,X._immutable=!1,X.x=R,X.y=B,Y.add(X),P=2}else if(P==2){let g=Z.next;g==null&&(g=t.polygon.gverts.next);let k=Z;P=0;let N=g,E=g;for(;;){let M=E,C=y+1;if(C==t.polygon.edgeCnt&&(C=0),s[y])if(f[C]){let D=M.x-k.x,O=M.y-k.y,j=k.x-e.circle.worldCOMx,L=k.y-e.circle.worldCOMy,U=D*D+O*O,q=2*(j*D+L*O),R=j*j+L*L-e.circle.radius*e.circle.radius,B=Math.sqrt(q*q-4*U*R);U=1/(2*U);let S=(-q-B)*U,J=S<l.Config.epsilon?(-q+B)*U:S,Q=0,Y=0,X=J;Q=k.x+(M.x-k.x)*X,Y=k.y+(M.y-k.y)*X;let ee=v.x-Q,G=v.y-Y;if(ee*ee+G*G<l.Config.epsilon){P=0,E=N;break}let F;le.zpp_pool==null?F=new le:(F=le.zpp_pool,le.zpp_pool=F.next,F.next=null),F.weak=!1,F._immutable=!1,F.x=Q,F.y=Y;let T=F;Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(T),Ce.flowpoly.add(T),P=1,E=N;break}else{let D=0,O=0,j=M.x-k.x,L=M.y-k.y,U=k.x-e.circle.worldCOMx,q=k.y-e.circle.worldCOMy,R=j*j+L*L,B=2*(U*j+q*L),S=U*U+q*q-e.circle.radius*e.circle.radius,J=B*B-4*R*S,Q;if(J*J<l.Config.epsilon?(J<0?D=10:(O=-B/(2*R),D=O),Q=!1):(J=Math.sqrt(J),R=1/(2*R),D=(-B-J)*R,O=(-B+J)*R,Q=!0),D<1-l.Config.epsilon&&O>l.Config.epsilon){let Y=0,X=0,ee=D;Y=k.x+(M.x-k.x)*ee,X=k.y+(M.y-k.y)*ee;let G;if(v!=null){let A=v.x-Y,W=v.y-X;G=A*A+W*W<l.Config.epsilon}else G=!1;if(G){P=0,E=N;break}let F;le.zpp_pool==null?F=new le:(F=le.zpp_pool,le.zpp_pool=F.next,F.next=null),F.weak=!1,F._immutable=!1,F.x=Y,F.y=X;let T=F;if(Ce.flowpoly.head!=null&&(Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(T)),Ce.flowpoly.add(T),v==null&&(v=Ce.flowpoly.head.elt),Q){let A=0,W=0,H=O;A=k.x+(M.x-k.x)*H,W=k.y+(M.y-k.y)*H;let K=Ce.flowpoly,ne;le.zpp_pool==null?ne=new le:(ne=le.zpp_pool,le.zpp_pool=ne.next,ne.next=null),ne.weak=!1,ne._immutable=!1,ne.x=A,ne.y=W,K.add(ne)}}}k=M,Z=E,y=C,E=E.next,E==null&&(E=t.polygon.gverts.next);break}for(;E!=N;){let M=E,C=y+1;if(C==t.polygon.edgeCnt&&(C=0),s[y])if(f[C]){let D=M.x-k.x,O=M.y-k.y,j=k.x-e.circle.worldCOMx,L=k.y-e.circle.worldCOMy,U=D*D+O*O,q=2*(j*D+L*O),R=j*j+L*L-e.circle.radius*e.circle.radius,B=Math.sqrt(q*q-4*U*R);U=1/(2*U);let S=(-q-B)*U,J=S<l.Config.epsilon?(-q+B)*U:S,Q=0,Y=0,X=J;Q=k.x+(M.x-k.x)*X,Y=k.y+(M.y-k.y)*X;let ee=v.x-Q,G=v.y-Y;if(ee*ee+G*G<l.Config.epsilon){P=0,E=N;break}let F;le.zpp_pool==null?F=new le:(F=le.zpp_pool,le.zpp_pool=F.next,F.next=null),F.weak=!1,F._immutable=!1,F.x=Q,F.y=Y;let T=F;Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(T),Ce.flowpoly.add(T),P=1,E=N;break}else{let D=0,O=0,j=M.x-k.x,L=M.y-k.y,U=k.x-e.circle.worldCOMx,q=k.y-e.circle.worldCOMy,R=j*j+L*L,B=2*(U*j+q*L),S=U*U+q*q-e.circle.radius*e.circle.radius,J=B*B-4*R*S,Q;if(J*J<l.Config.epsilon?(J<0?D=10:(O=-B/(2*R),D=O),Q=!1):(J=Math.sqrt(J),R=1/(2*R),D=(-B-J)*R,O=(-B+J)*R,Q=!0),D<1-l.Config.epsilon&&O>l.Config.epsilon){let Y=0,X=0,ee=D;Y=k.x+(M.x-k.x)*ee,X=k.y+(M.y-k.y)*ee;let G;if(v!=null){let A=v.x-Y,W=v.y-X;G=A*A+W*W<l.Config.epsilon}else G=!1;if(G){P=0,E=N;break}let F;le.zpp_pool==null?F=new le:(F=le.zpp_pool,le.zpp_pool=F.next,F.next=null),F.weak=!1,F._immutable=!1,F.x=Y,F.y=X;let T=F;if(Ce.flowpoly.head!=null&&(Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(T)),Ce.flowpoly.add(T),v==null&&(v=Ce.flowpoly.head.elt),Q){let A=0,W=0,H=O;A=k.x+(M.x-k.x)*H,W=k.y+(M.y-k.y)*H;let K=Ce.flowpoly,ne;le.zpp_pool==null?ne=new le:(ne=le.zpp_pool,le.zpp_pool=ne.next,ne.next=null),ne.weak=!1,ne._immutable=!1,ne.x=A,ne.y=W,K.add(ne)}}}k=M,Z=E,y=C,E=E.next,E==null&&(E=t.polygon.gverts.next)}}if(Ce.flowpoly.head==null)return!1;if(Ce.flowpoly.head.next==null){let g=!0,k=t.polygon.edges.head;for(;k!=null;){let N=k.elt;if(N.gnormx*e.circle.worldCOMx+N.gnormy*e.circle.worldCOMy>N.gprojection){g=!1;break}k=k.next}return g?(n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0):!1}else{let g=0,k=0,N=0;if(Ce.flowpoly.head.next.next!=null){let M=0,C=0,D=0;M=0;let O=Ce.flowpoly.head,j=O.elt;O=O.next;let L=O.elt;for(O=O.next;O!=null;){let Y=O.elt;M+=L.x*(Y.y-j.y);let X=Y.y*L.x-Y.x*L.y;C+=(L.x+Y.x)*X,D+=(L.y+Y.y)*X,j=L,L=Y,O=O.next}O=Ce.flowpoly.head;let U=O.elt;M+=L.x*(U.y-j.y);let q=U.y*L.x-U.x*L.y;C+=(L.x+U.x)*q,D+=(L.y+U.y)*q,j=L,L=U,O=O.next;let R=O.elt;M+=L.x*(R.y-j.y);let B=R.y*L.x-R.x*L.y;C+=(L.x+R.x)*B,D+=(L.y+R.y)*B,M*=.5;let J=1/(6*M);C*=J,D*=J;let Q=-M;g+=C*Q,k+=D*Q,N-=M}else Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(Ce.flowpoly.head.next.elt);for(;Ce.flowsegs.head!=null;){let M=Ce.flowsegs.pop_unsafe(),C=Ce.flowsegs.pop_unsafe(),D=C.x-M.x,O=C.y-M.y,j=D,L=O,U=j*j+L*L,R=1/Math.sqrt(U);j*=R,L*=R;let B=j;j=-L,L=B;let S=M.x+C.x,J=M.y+C.y,Q=.5;S*=Q,J*=Q;let Y=1;S-=e.circle.worldCOMx*Y,J-=e.circle.worldCOMy*Y;let X=j*S+L*J,ee=0,G=0,F=X,T=F/e.circle.radius,A=Math.sqrt(1-T*T),W=Math.acos(T);ee=e.circle.radius*(e.circle.radius*W-F*A),G=.6666666666666666*e.circle.radius*A*A*A/(W-T*A),S=e.circle.worldCOMx,J=e.circle.worldCOMy;let H=G;S+=j*H,J+=L*H;let K=ee;g+=S*K,k+=J*K,N+=ee}let E=1/N;return g*=E,k*=E,n.overlap=N,n.centroidx=g,n.centroidy=k,!0}}}else return!1}}else return!1}else{let s=e.circle,i=t.circle,o=i.worldCOMx-s.worldCOMx,r=i.worldCOMy-s.worldCOMy,a=s.radius+i.radius,p=o*o+r*r;if(p>a*a)return!1;if(p<l.Config.epsilon*l.Config.epsilon)return s.radius<i.radius?(n.overlap=s.area,n.centroidx=s.worldCOMx,n.centroidy=s.worldCOMy):(n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy),!0;{let c=Math.sqrt(p),u=1/c,h=.5*(c-(i.radius*i.radius-s.radius*s.radius)*u);if(h<=-s.radius)n.overlap=s.area,n.centroidx=s.worldCOMx,n.centroidy=s.worldCOMy;else{let x=c-h;if(x<=-i.radius)n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy;else{let b=0,_=0,d=0,f=0,m=h,z=m/s.radius,Z=Math.sqrt(1-z*z),y=Math.acos(z);b=s.radius*(s.radius*y-m*Z),_=.6666666666666666*s.radius*Z*Z*Z/(y-z*Z);let w=x,v=w/i.radius,P=Math.sqrt(1-v*v),g=Math.acos(v);d=i.radius*(i.radius*g-w*P),f=.6666666666666666*i.radius*P*P*P/(g-v*P);let k=b+d,N=(_*b+(c-f)*d)/k*u;n.overlap=k,n.centroidx=s.worldCOMx+o*N,n.centroidy=s.worldCOMy+r*N}}return!0}}}};Ce.__name__=["zpp_nape","geom","ZPP_Collide"],Ce.flowpoly=null,Ce.flowsegs=null;var Ee=Ce;var Us=class Us{static isinner(e,t,n){let l=e.x-t.x,s=e.y-t.y,i=n.x-t.x;return(n.y-t.y)*l-i*s>=0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let i=t;for(;i.sort(),i=i.next,i!=n;);}let l=e.vertices,s=e.vertices;if(l!=null){let i=l;for(;;){let o=i,r=o.prev,a=null,p=o.diagonals.head;for(;p!=null;){let c=p.elt,u=p.next==null?o.next:p.next.elt;if(!Us.isinner(u,o,r)){a=p,r=c,p=p.next;continue}let h=!0,x=c,b=x.prev,_=null,d=x.diagonals.head;for(;d!=null;){let f=d.elt;if(f==o){let m=d.next==null?x.next:d.next.elt;h=Us.isinner(m,x,b);break}b=f,_=d,d=d.next}if(h){p=o.diagonals.erase(a),x.diagonals.erase(_);continue}r=c,a=p,p=p.next}if(i=i.next,i==s)break}}}};Us.__name__=["zpp_nape","geom","ZPP_Convex"];var Ml=Us;var nt=class nt{constructor(){this.normal=null;this.shape=null;this.convex=null;this.position=null;this.ray=null;this.inner=!1;this.next=null;this.toiDistance=0}static getRay(e,t,n,l){let s;nt.rayPool==null?(nt.internal=!0,s=nt._createRayResult(),s.zpp_inner=new nt,s.zpp_inner.ray=s,nt.internal=!1):(s=nt.rayPool.ray,nt.rayPool=nt.rayPool.next,s.zpp_inner.next=null);let i=s.zpp_inner;return i.normal=e,e.zpp_inner._immutable=!0,i.toiDistance=t,i.inner=n,i.shape=l,s}static getConvex(e,t,n,l){let s;nt.convexPool==null?(nt.internal=!0,s=nt._createConvexResult(),s.zpp_inner=new nt,s.zpp_inner.convex=s,nt.internal=!1):(s=nt.convexPool.convex,nt.convexPool=nt.convexPool.next,s.zpp_inner.next=null);let i=s.zpp_inner;return i.normal=e,i.position=t,e.zpp_inner._immutable=!0,t.zpp_inner._immutable=!0,i.toiDistance=n,i.shape=l,s}disposed(){if(this.next!=null)throw new Error("Error: This object has been disposed of and cannot be used")}free(){nt._disposeVec2(this.normal),this.position!=null&&nt._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=nt.convexPool,nt.convexPool=this):(this.next=nt.rayPool,nt.rayPool=this)}static _disposeVec2(e){if(e.zpp_inner._immutable=!1,e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=e.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");if(t._isimmutable!=null&&t._isimmutable(),t._inuse)throw new Error("Error: This Vec2 is not disposable");let n=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null,e.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=e:de.poolVec2=e,de.nextVec2=e,e.zpp_disp=!0,n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=le.zpp_pool,le.zpp_pool=n}};nt.__name__=["zpp_nape","geom","ZPP_ConvexRayResult"],nt.rayPool=null,nt.convexPool=null,nt.internal=!1,nt._createRayResult=null,nt._createConvexResult=null;var zn=nt;var wi=class wi{constructor(){this.prev=null;this.next=null;this.posx=0;this.posy=0;this.vert=null;this.value=0;this.positive=!1;this.parent=null;this.rank=0;this.used=!1}static path(e){let t;return wi.zpp_pool==null?t=new wi:(t=wi.zpp_pool,wi.zpp_pool=t.next,t.next=null),t.vert=e,t.parent=t,t.rank=0,t.used=!1,t}alloc(){}free(){this.vert=null,this.parent=null}};wi.__name__=["zpp_nape","geom","ZPP_CutVert"],wi.zpp_pool=null;var He=wi;var vi=class vi{constructor(){this.next=null;this.time=0;this.virtualint=!1;this.vertex=!1;this.path0=null;this.end=null;this.start=null;this.path1=null}static get(e,t,n,l,s,i=!1,o=!1){let r;return vi.zpp_pool==null?r=new vi:(r=vi.zpp_pool,vi.zpp_pool=r.next,r.next=null),r.virtualint=i,r.end=t,r.start=n,r.path0=l,r.path1=s,r.time=e,r.vertex=o,r}alloc(){}free(){this.end=this.start=null,this.path0=this.path1=null}};vi.__name__=["zpp_nape","geom","ZPP_CutInt"],vi.zpp_pool=null;var lt=vi;var Yn=class Yn{constructor(){this.x=0;this.y=0;this.prev=null;this.next=null;this.wrap=null;this.forced=!1}static get(e,t){let n;return Yn.zpp_pool==null?n=new Yn:(n=Yn.zpp_pool,Yn.zpp_pool=n.next,n.next=null),n.forced=!1,n.x=e,n.y=t,n}alloc(){this.forced=!1}free(){if(this.wrap!=null){this.wrap.zpp_inner._inuse=!1;let e=this.wrap;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=e.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");if(t._isimmutable!=null&&t._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let n=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let l=e;l.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=l:de.poolVec2=l,de.nextVec2=l,l.zpp_disp=!0;let s=n;s.outer!=null&&(s.outer.zpp_inner=null,s.outer=null),s._isimmutable=null,s._validate=null,s._invalidate=null,s.next=le.zpp_pool,le.zpp_pool=s,this.wrap=null}this.prev=this.next=null}wrapper(){if(this.wrap==null){let e=this.x,t=this.y;if(t==null&&(t=0),e==null&&(e=0),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(de.poolVec2==null?n=Yn._createVec2Fn():(n=de.poolVec2,de.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n===de.nextVec2&&(de.nextVec2=null)),n.zpp_inner==null){let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=e,l.y=t,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x===e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),s=n.zpp_inner.y===t}else s=!1;if(!s){n.zpp_inner.x=e,n.zpp_inner.y=t;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.wrap=n,this.wrap.zpp_inner._inuse=!0,this.wrap.zpp_inner._invalidate=l=>this.modwrap(l),this.wrap.zpp_inner._validate=()=>this.getwrap()}return this.wrap}modwrap(e){this.x=e.x,this.y=e.y}getwrap(){this.wrap.zpp_inner.x=this.x,this.wrap.zpp_inner.y=this.y}};Yn.__name__=["zpp_nape","geom","ZPP_GeomVert"],Yn.zpp_pool=null,Yn._createVec2Fn=null;var ge=Yn;var Qe=class Qe{static run(e,t,n,l,s,i){let o=me(),r=o.__zpp;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=t.zpp_inner;a._validate!=null&&a._validate();let p=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=t.zpp_inner;c._validate!=null&&c._validate();let u=t.zpp_inner.y;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=n.zpp_inner;h._validate!=null&&h._validate();let x=n.zpp_inner.x-p;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let b=n.zpp_inner;b._validate!=null&&b._validate();let _=n.zpp_inner.y-u,d=l?0:-1/0,f=s?1:1/0,m=-(u*x-p*_),z=null,Z=!1,y=e;for(;;){let B;He.zpp_pool==null?B=new He:(B=He.zpp_pool,He.zpp_pool=B.next,B.next=null),B.vert=y,B.posx=y.x,B.posy=y.y,B.value=B.posy*x-B.posx*_+m,B.positive=B.value>0,B.value==0&&(Z=!0);let S=B;if(z==null?S.prev=S.next=S:(S.prev=z,S.next=z.next,z.next.prev=S,z.next=S),z=S,y=y.next,y==e)break}if(Z){let B=null,S=z,J=z;if(S!=null){let W=S;for(;;){let H=W;if(H.value!=0){B=H;break}if(W=W.next,W==J)break}}let Q,Y;Q=x,Y=_;let X=Q*Q+Y*Y,G=1/Math.sqrt(X);Q*=G,Y*=G;let F=Q;Q=-Y,Y=F;let T=null,A=B;for(;;){if(A.value!=0&&(T==null||A==T.next)){if(T=A,A=A.next,A==B)break;continue}let W=T.value*A.value;if(W==0){if(A=A.next,A==B)break;continue}let H=T.next,K;if(W>0)K=T.positive;else{let se=H.next,ie,oe;ie=H.posx+se.posx,oe=H.posy+se.posy;let ce=.5;ie*=ce,oe*=ce;let pe=ie+Q*1e-8,ae=oe+Y*1e-8,xe=!1,te=e,he=e;if(te!=null){let ye=te;for(;;){let ue=ye,Pe=ue.prev;if((ue.y<ae&&Pe.y>=ae||Pe.y<ae&&ue.y>=ae)&&(ue.x<=pe||Pe.x<=pe)&&ue.x+(ae-ue.y)/(Pe.y-ue.y)*(Pe.x-ue.x)<pe&&(xe=!xe),ye=ye.next,ye==he)break}}K=xe}let ne=H,re=A;if(ne!=null){let se=ne;for(;;){let ie=se;if(ie.positive=K,se=se.next,se==re)break}}if(T=A,A=A.next,A==B)break}for(;!(A.value!=0&&(T==null||A==T.next));){let W=T.value*A.value;if(W==0)break;let H=T.next,K;if(W>0)K=T.positive;else{let se=H.next,ie,oe;ie=H.posx+se.posx,oe=H.posy+se.posy;let ce=.5;ie*=ce,oe*=ce;let pe=ie+Q*1e-8,ae=oe+Y*1e-8,xe=!1,te=e,he=e;if(te!=null){let ye=te;for(;;){let ue=ye,Pe=ue.prev;if((ue.y<ae&&Pe.y>=ae||Pe.y<ae&&ue.y>=ae)&&(ue.x<=pe||Pe.x<=pe)&&ue.x+(ae-ue.y)/(Pe.y-ue.y)*(Pe.x-ue.x)<pe&&(xe=!xe),ye=ye.next,ye==he)break}}K=xe}let ne=H,re=A;if(ne!=null){let se=ne;for(;;){let ie=se;if(ie.positive=K,se=se.next,se==re)break}}break}}Qe.ints==null&&(Qe.ints=new r.util.ZNPList_ZPP_CutInt),Qe.paths==null&&(Qe.paths=new r.util.ZNPList_ZPP_CutVert);let w=null,v=z.posx,P=z.posy,g;ge.zpp_pool==null?g=new ge:(g=ge.zpp_pool,ge.zpp_pool=g.next,g.next=null),g.forced=!1,g.x=v,g.y=P;let k=g;k.prev=k.next=k,w=k;let N=w,E;He.zpp_pool==null?E=new He:(E=He.zpp_pool,He.zpp_pool=E.next,E.next=null),E.vert=w,E.parent=E,E.rank=0,E.used=!1;let M=E;Qe.paths.add(M);let C=z;for(;;){let B=C.next,S=B.posx,J=B.posy,Q;ge.zpp_pool==null?Q=new ge:(Q=ge.zpp_pool,ge.zpp_pool=Q.next,Q.next=null),Q.forced=!1,Q.x=S,Q.y=J;let Y=Q;if(C.positive==B.positive){let X=Y;w==null?(X.prev=X.next=X,w=X):(X.next=w,X.prev=w.prev,w.prev.next=X,w.prev=X)}else{let X=B.posx-C.posx,ee=B.posy-C.posy,G=_*X-x*ee;G=1/G;let F=p-C.posx,T=u-C.posy,A=(ee*F-X*T)*G;if(A<d||A>f){let W=Qe.ints,H=!0;H==null&&(H=!1);let K;lt.zpp_pool==null?K=new lt:(K=lt.zpp_pool,lt.zpp_pool=K.next,K.next=null),K.virtualint=H,K.end=null,K.start=null,K.path0=null,K.path1=null,K.time=A,K.vertex=!1,W.add(K);let ne=Y;w==null?(ne.prev=ne.next=ne,w=ne):(ne.next=w,ne.prev=w.prev,w.prev.next=ne,w.prev=ne)}else if(C.value==0){let W=w.prev;w=null;let H=W.x,K=W.y,ne;ge.zpp_pool==null?ne=new ge:(ne=ge.zpp_pool,ge.zpp_pool=ne.next,ne.next=null),ne.forced=!1,ne.x=H,ne.y=K;let re=ne;re.prev=re.next=re,w=re;let se=Y;w==null?(se.prev=se.next=se,w=se):(se.next=w,se.prev=w.prev,w.prev.next=se,w.prev=se);let ie=Qe.paths.head.elt,oe=Qe.paths,ce;He.zpp_pool==null?ce=new He:(ce=He.zpp_pool,He.zpp_pool=ce.next,ce.next=null),ce.vert=w,ce.parent=ce,ce.rank=0,ce.used=!1,oe.add(ce);let pe=Qe.paths.head.elt,ae=Qe.ints,xe=!0;xe==null&&(xe=!1);let te;lt.zpp_pool==null?te=new lt:(te=lt.zpp_pool,lt.zpp_pool=te.next,te.next=null),te.virtualint=xe,te.end=W,te.start=w,te.path0=ie,te.path1=pe,te.time=A,te.vertex=!1,ae.add(te)}else if(B.value==0){let W=Y;w==null?(W.prev=W.next=W,w=W):(W.next=w,W.prev=w.prev,w.prev.next=W,w.prev=W);let H=w.prev;w=null;let K=B.posx,ne=B.posy,re;ge.zpp_pool==null?re=new ge:(re=ge.zpp_pool,ge.zpp_pool=re.next,re.next=null),re.forced=!1,re.x=K,re.y=ne;let se=re;se.prev=se.next=se,w=se;let ie=Qe.paths.head.elt,oe=Qe.paths,ce;He.zpp_pool==null?ce=new He:(ce=He.zpp_pool,He.zpp_pool=ce.next,ce.next=null),ce.vert=w,ce.parent=ce,ce.rank=0,ce.used=!1,oe.add(ce);let pe=Qe.paths.head.elt,ae=Qe.ints,xe=!0;xe==null&&(xe=!1);let te;lt.zpp_pool==null?te=new lt:(te=lt.zpp_pool,lt.zpp_pool=te.next,te.next=null),te.virtualint=xe,te.end=H,te.start=w,te.path0=ie,te.path1=pe,te.time=A,te.vertex=!1,ae.add(te)}else{let W=(_*F-x*T)*G,H,K;H=C.posx,K=C.posy;let ne=W;H+=X*ne,K+=ee*ne;let re;ge.zpp_pool==null?re=new ge:(re=ge.zpp_pool,ge.zpp_pool=re.next,re.next=null),re.forced=!1,re.x=H,re.y=K;let se=re;w==null?(se.prev=se.next=se,w=se):(se.next=w,se.prev=w.prev,w.prev.next=se,w.prev=se);let ie=w.prev;w=null;let oe;ge.zpp_pool==null?oe=new ge:(oe=ge.zpp_pool,ge.zpp_pool=oe.next,oe.next=null),oe.forced=!1,oe.x=H,oe.y=K;let ce=oe;ce.prev=ce.next=ce,w=ce;let pe=Y;w==null?(pe.prev=pe.next=pe,w=pe):(pe.next=w,pe.prev=w.prev,w.prev.next=pe,w.prev=pe);let ae=Qe.paths.head.elt,xe=Qe.paths,te;He.zpp_pool==null?te=new He:(te=He.zpp_pool,He.zpp_pool=te.next,te.next=null),te.vert=w,te.parent=te,te.rank=0,te.used=!1,xe.add(te);let he=Qe.paths.head.elt,ye=Qe.ints,ue=!1;ue==null&&(ue=!1);let Pe;lt.zpp_pool==null?Pe=new lt:(Pe=lt.zpp_pool,lt.zpp_pool=Pe.next,Pe.next=null),Pe.virtualint=ue,Pe.end=ie,Pe.start=w,Pe.path0=ae,Pe.path1=he,Pe.time=A,Pe.vertex=!1,ye.add(Pe)}}if(C=C.next,C==z)break}let D=w.prev;D.next.prev=N.prev,N.prev.next=D.next,D.next=N,N.prev=D;let O=Qe.paths.head.elt,j;if(M==M.parent)j=M;else{let B=M,S=null;for(;B!=B.parent;){let J=B.parent;B.parent=S,S=B,B=J}for(;S!=null;){let J=S.parent;S.parent=B,S=J}j=B}let L;if(O==O.parent)L=O;else{let B=O,S=null;for(;B!=B.parent;){let J=B.parent;B.parent=S,S=B,B=J}for(;S!=null;){let J=S.parent;S.parent=B,S=J}L=B}j!=L&&(j.rank<L.rank?j.parent=L:j.rank>L.rank?L.parent=j:(L.parent=j,j.rank++));let U=Qe.ints;if(U.head!=null&&U.head.next!=null){let B=U.head,S,J,Q,Y,X=1,ee,G,F;for(;;){for(ee=0,J=B,B=null,S=B;J!=null;){for(++ee,Q=J,G=0,F=X;Q!=null&&G<X;)++G,Q=Q.next;for(;G>0||F>0&&Q!=null;)G==0?(Y=Q,Q=Q.next,--F):F==0||Q==null||J.elt.time<Q.elt.time?(Y=J,J=J.next,--G):(Y=Q,Q=Q.next,--F),S!=null?S.next=Y:B=Y,S=Y;J=Q}if(S.next=null,X<<=1,!(ee>1))break}U.head=B,U.modified=!0,U.pushmod=!0}for(;Qe.ints.head!=null;){let B=Qe.ints.pop_unsafe(),S=Qe.ints.pop_unsafe();if(!B.virtualint&&!S.virtualint){B.end.next.prev=S.start.prev,S.start.prev.next=B.end.next,B.end.next=S.start,S.start.prev=B.end,S.end.next.prev=B.start.prev,B.start.prev.next=S.end.next,S.end.next=B.start,B.start.prev=S.end;let Y;if(B.path0==B.path0.parent)Y=B.path0;else{let F=B.path0,T=null;for(;F!=F.parent;){let A=F.parent;F.parent=T,T=F,F=A}for(;T!=null;){let A=T.parent;T.parent=F,T=A}Y=F}let X;if(S.path1==S.path1.parent)X=S.path1;else{let F=S.path1,T=null;for(;F!=F.parent;){let A=F.parent;F.parent=T,T=F,F=A}for(;T!=null;){let A=T.parent;T.parent=F,T=A}X=F}Y!=X&&(Y.rank<X.rank?Y.parent=X:Y.rank>X.rank?X.parent=Y:(X.parent=Y,Y.rank++));let ee;if(B.path1==B.path1.parent)ee=B.path1;else{let F=B.path1,T=null;for(;F!=F.parent;){let A=F.parent;F.parent=T,T=F,F=A}for(;T!=null;){let A=T.parent;T.parent=F,T=A}ee=F}let G;if(S.path0==S.path0.parent)G=S.path0;else{let F=S.path0,T=null;for(;F!=F.parent;){let A=F.parent;F.parent=T,T=F,F=A}for(;T!=null;){let A=T.parent;T.parent=F,T=A}G=F}ee!=G&&(ee.rank<G.rank?ee.parent=G:ee.rank>G.rank?G.parent=ee:(G.parent=ee,ee.rank++))}else if(B.virtualint&&!S.virtualint){let Y;if(S.end!=null&&S.end.prev==S.end){S.end.next=S.end.prev=null;let G=S.end;if(G.wrap!=null){G.wrap.zpp_inner._inuse=!1;let F=G.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let T=F.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let A=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let W=F;W.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=W:de.poolVec2=W,de.nextVec2=W,W.zpp_disp=!0;let H=A;H.outer!=null&&(H.outer.zpp_inner=null,H.outer=null),H._isimmutable=null,H._validate=null,H._invalidate=null,H.next=le.zpp_pool,le.zpp_pool=H,G.wrap=null}G.prev=G.next=null,G.next=ge.zpp_pool,ge.zpp_pool=G,Y=null}else{let G=S.end.prev;S.end.prev.next=S.end.next,S.end.next.prev=S.end.prev,S.end.next=S.end.prev=null;let F=S.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let T=F.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=T.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let W=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let H=T;H.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=H:de.poolVec2=H,de.nextVec2=H,H.zpp_disp=!0;let K=W;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,S.end=null,Y=G}if(S.end=Y,!S.vertex)if(S.end!=S.path0.vert){S.start.x=S.end.x,S.start.y=S.end.y;let G;if(S.end!=null&&S.end.prev==S.end){S.end.next=S.end.prev=null;let F=S.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let T=F.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=T.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let W=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let H=T;H.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=H:de.poolVec2=H,de.nextVec2=H,H.zpp_disp=!0;let K=W;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,G=null}else{let F=S.end.prev;S.end.prev.next=S.end.next,S.end.next.prev=S.end.prev,S.end.next=S.end.prev=null;let T=S.end;if(T.wrap!=null){T.wrap.zpp_inner._inuse=!1;let A=T.wrap;if(A!=null&&A.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let W=A.zpp_inner;if(W._immutable)throw new Error("Error: Vec2 is immutable");if(W._isimmutable!=null&&W._isimmutable(),A.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let H=A.zpp_inner;A.zpp_inner.outer=null,A.zpp_inner=null;let K=A;K.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=K:de.poolVec2=K,de.nextVec2=K,K.zpp_disp=!0;let ne=H;ne.outer!=null&&(ne.outer.zpp_inner=null,ne.outer=null),ne._isimmutable=null,ne._validate=null,ne._invalidate=null,ne.next=le.zpp_pool,le.zpp_pool=ne,T.wrap=null}T.prev=T.next=null,T.next=ge.zpp_pool,ge.zpp_pool=T,S.end=null,G=F}S.end=G}else{let G=S.start.next;if(S.start.x=G.x,S.start.y=G.y,G!=null&&G.prev==G){G.next=G.prev=null;let F=G;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let T=F.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=T.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let W=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let H=T;H.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=H:de.poolVec2=H,de.nextVec2=H,H.zpp_disp=!0;let K=W;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}else{G.prev.next=G.next,G.next.prev=G.prev,G.next=G.prev=null;let F=G;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let T=F.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=T.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let W=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let H=T;H.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=H:de.poolVec2=H,de.nextVec2=H,H.zpp_disp=!0;let K=W;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}}S.end.next.prev=S.start.prev,S.start.prev.next=S.end.next,S.end.next=S.start,S.start.prev=S.end;let X;if(S.path0==S.path0.parent)X=S.path0;else{let G=S.path0,F=null;for(;G!=G.parent;){let T=G.parent;G.parent=F,F=G,G=T}for(;F!=null;){let T=F.parent;F.parent=G,F=T}X=G}let ee;if(S.path1==S.path1.parent)ee=S.path1;else{let G=S.path1,F=null;for(;G!=G.parent;){let T=G.parent;G.parent=F,F=G,G=T}for(;F!=null;){let T=F.parent;F.parent=G,F=T}ee=G}X!=ee&&(X.rank<ee.rank?X.parent=ee:X.rank>ee.rank?ee.parent=X:(ee.parent=X,X.rank++))}else if(S.virtualint&&!B.virtualint){let Y;if(B.end!=null&&B.end.prev==B.end){B.end.next=B.end.prev=null;let G=B.end;if(G.wrap!=null){G.wrap.zpp_inner._inuse=!1;let F=G.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let T=F.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let A=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let W=F;W.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=W:de.poolVec2=W,de.nextVec2=W,W.zpp_disp=!0;let H=A;H.outer!=null&&(H.outer.zpp_inner=null,H.outer=null),H._isimmutable=null,H._validate=null,H._invalidate=null,H.next=le.zpp_pool,le.zpp_pool=H,G.wrap=null}G.prev=G.next=null,G.next=ge.zpp_pool,ge.zpp_pool=G,Y=null}else{let G=B.end.prev;B.end.prev.next=B.end.next,B.end.next.prev=B.end.prev,B.end.next=B.end.prev=null;let F=B.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let T=F.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=T.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let W=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let H=T;H.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=H:de.poolVec2=H,de.nextVec2=H,H.zpp_disp=!0;let K=W;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,B.end=null,Y=G}if(B.end=Y,!B.vertex)if(B.end!=B.path0.vert){B.start.x=B.end.x,B.start.y=B.end.y;let G;if(B.end!=null&&B.end.prev==B.end){B.end.next=B.end.prev=null;let F=B.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let T=F.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=T.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let W=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let H=T;H.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=H:de.poolVec2=H,de.nextVec2=H,H.zpp_disp=!0;let K=W;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,G=null}else{let F=B.end.prev;B.end.prev.next=B.end.next,B.end.next.prev=B.end.prev,B.end.next=B.end.prev=null;let T=B.end;if(T.wrap!=null){T.wrap.zpp_inner._inuse=!1;let A=T.wrap;if(A!=null&&A.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let W=A.zpp_inner;if(W._immutable)throw new Error("Error: Vec2 is immutable");if(W._isimmutable!=null&&W._isimmutable(),A.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let H=A.zpp_inner;A.zpp_inner.outer=null,A.zpp_inner=null;let K=A;K.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=K:de.poolVec2=K,de.nextVec2=K,K.zpp_disp=!0;let ne=H;ne.outer!=null&&(ne.outer.zpp_inner=null,ne.outer=null),ne._isimmutable=null,ne._validate=null,ne._invalidate=null,ne.next=le.zpp_pool,le.zpp_pool=ne,T.wrap=null}T.prev=T.next=null,T.next=ge.zpp_pool,ge.zpp_pool=T,B.end=null,G=F}B.end=G}else{let G=B.start.next;if(B.start.x=G.x,B.start.y=G.y,G!=null&&G.prev==G){G.next=G.prev=null;let F=G;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let T=F.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=T.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let W=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let H=T;H.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=H:de.poolVec2=H,de.nextVec2=H,H.zpp_disp=!0;let K=W;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}else{G.prev.next=G.next,G.next.prev=G.prev,G.next=G.prev=null;let F=G;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let T=F.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=T.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let W=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let H=T;H.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=H:de.poolVec2=H,de.nextVec2=H,H.zpp_disp=!0;let K=W;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}}B.end.next.prev=B.start.prev,B.start.prev.next=B.end.next,B.end.next=B.start,B.start.prev=B.end;let X;if(B.path0==B.path0.parent)X=B.path0;else{let G=B.path0,F=null;for(;G!=G.parent;){let T=G.parent;G.parent=F,F=G,G=T}for(;F!=null;){let T=F.parent;F.parent=G,F=T}X=G}let ee;if(B.path1==B.path1.parent)ee=B.path1;else{let G=B.path1,F=null;for(;G!=G.parent;){let T=G.parent;G.parent=F,F=G,G=T}for(;F!=null;){let T=F.parent;F.parent=G,F=T}ee=G}X!=ee&&(X.rank<ee.rank?X.parent=ee:X.rank>ee.rank?ee.parent=X:(ee.parent=X,X.rank++))}let J=B;J.end=J.start=null,J.path0=J.path1=null,J.next=lt.zpp_pool,lt.zpp_pool=J;let Q=S;Q.end=Q.start=null,Q.path0=Q.path1=null,Q.next=lt.zpp_pool,lt.zpp_pool=Q}let q=i??new o.geom.GeomPolyList,R=Qe.paths.head;for(;R!=null;){let B=R.elt,S;if(B==B.parent)S=B;else{let Y=B,X=null;for(;Y!=Y.parent;){let ee=Y.parent;Y.parent=X,X=Y,Y=ee}for(;X!=null;){let ee=X.parent;X.parent=Y,X=ee}S=Y}if(S.used){R=R.next;continue}S.used=!0;let J=S.vert,Q=!0;for(;S.vert!=null&&(Q||J!=S.vert);)if(Q=!1,J.x==J.next.x&&J.y==J.next.y)if(J==S.vert&&(S.vert=J.next==J?null:J.next,Q=!0),J!=null&&J.prev==J)J.next=J.prev=null,J=null;else{let Y=J.next;J.prev.next=J.next,J.next.prev=J.prev,J.next=J.prev=null,J=Y}else J=J.next;if(S.vert!=null){let Y=o.geom.GeomPoly.get();Y.zpp_inner.vertices=S.vert,q.zpp_inner.reverse_flag?q.push(Y):q.unshift(Y)}R=R.next}for(;Qe.paths.head!=null;){let S=Qe.paths.pop_unsafe();S.vert=null,S.parent=null,S.next=He.zpp_pool,He.zpp_pool=S}for(;z!=null;)if(z!=null&&z.prev==z){z.next=z.prev=null;let B=z;B.vert=null,B.parent=null,B.next=He.zpp_pool,He.zpp_pool=B,z=null}else{let B=z.next;z.prev.next=z.next,z.next.prev=z.prev,z.next=z.prev=null;let S=z;S.vert=null,S.parent=null,S.next=He.zpp_pool,He.zpp_pool=S,z=B}return q}};Qe.__name__=["zpp_nape","geom","ZPP_Cutter"],Qe.ints=null,Qe.paths=null;var Zl=Qe;var vs=class vs{static validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=t.body.posx+(t.body.axisy*h.x-t.body.axisx*h.y),u.y=t.body.posy+(h.x*t.body.axisx+h.y*t.body.axisy),c=c.next}}let l=t.edges.head,s=t.gverts.next,i=s;for(s=s.next;s!=null;){let a=s,p=l.elt;l=l.next,p.gp0=i,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,i=a,s=s.next}let o=t.gverts.next,r=l.elt;r.gp0=i,r.gp1=o,r.gnormx=t.body.axisy*r.lnormx-t.body.axisx*r.lnormy,r.gnormy=r.lnormx*t.body.axisx+r.lnormy*t.body.axisy,r.gprojection=t.body.posx*r.gnormx+t.body.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;vs._validateWorldCOM(t);let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=i;i=i.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type==1&&vs._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy));let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type==1&&vs._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy));let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}static _computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null){e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;let t=1;e.localCOMx+=e.lverts.next.next.x*t,e.localCOMy+=e.lverts.next.next.y*t;let n=.5;e.localCOMx*=n,e.localCOMy*=n}else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,l=n;n=n.next;let s=n;for(n=n.next;n!=null;){let c=n;t+=s.x*(c.y-l.y);let u=c.y*s.x-c.x*s.y;e.localCOMx+=(s.x+c.x)*u,e.localCOMy+=(s.y+c.y)*u,l=s,s=c,n=n.next}n=e.lverts.next;let i=n;t+=s.x*(i.y-l.y);let o=i.y*s.x-i.x*s.y;e.localCOMx+=(s.x+i.x)*o,e.localCOMy+=(s.y+i.y)*o,l=s,s=i,n=n.next;let r=n;t+=s.x*(r.y-l.y);let a=r.y*s.x-r.x*s.y;e.localCOMx+=(s.x+r.x)*a,e.localCOMy+=(s.y+r.y)*a,t=1/(3*t);let p=t;e.localCOMx*=p,e.localCOMy*=p}}};vs.__name__=["zpp_nape","geom","ZPP_Geom"];var gs=vs;var Ws=class{constructor(e=null){this.outer=null;this.vertices=null;this.outer=e}};Ws.__name__=["zpp_nape","geom","ZPP_GeomPoly"];var Cn=class{constructor(){this.rank=0;this.out=!1;this.next=null;this.parent=this}free(){this.parent=this}alloc(){this.out=!1,this.rank=0}};Cn.__name__=["zpp_nape","geom","ZPP_MarchSpan"],Cn.zpp_pool=null;var Mn=class{constructor(){this.p1=null;this.key1=0;this.okey1=0;this.p2=null;this.key2=0;this.okey2=0;this.pr=null;this.keyr=0;this.okeyr=0;this.pd=null;this.span1=null;this.span2=null;this.spanr=null;this.next=null}free(){this.p1=this.p2=this.pr=this.pd=null,this.span1=this.span2=this.spanr=null}alloc(){}};Mn.__name__=["zpp_nape","geom","ZPP_MarchPair"],Mn.zpp_pool=null;var ze=class ze{static _init(e,t){ze._zpp=e,ze._nape=t,ze.me=new ze,ze.look_march=[-1,224,56,216,14,-1,54,214,131,99,-1,91,141,109,181,85]}static _allocVert(e,t){let n;return ge.zpp_pool==null?n=new ge:(n=ge.zpp_pool,ge.zpp_pool=n.next,n.next=null),n.forced=!1,n.x=e,n.y=t,n}static _freeVert(e){if(e.wrap!=null){e.wrap.zpp_inner._inuse=!1;let t=e.wrap;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=t.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let l=t.zpp_inner;t.zpp_inner.outer=null,t.zpp_inner=null;let s=t;s.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=s:de.poolVec2=s,de.nextVec2=s,s.zpp_disp=!0;let i=l;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i._isimmutable=null,i._validate=null,i._invalidate=null,i.next=le.zpp_pool,le.zpp_pool=i,e.wrap=null}e.prev=e.next=null,e.next=ge.zpp_pool,ge.zpp_pool=e}static _allocSpan(){let e;return Cn.zpp_pool==null?e=new Cn:(e=Cn.zpp_pool,Cn.zpp_pool=e.next,e.next=null),e.out=!1,e.rank=0,e}static _allocPair(){let e;return Mn.zpp_pool==null?e=new Mn:(e=Mn.zpp_pool,Mn.zpp_pool=e.next,e.next=null),e}static _freePair(e){e.p1=e.p2=e.pr=e.pd=null,e.span1=e.span2=e.spanr=null,e.next=Mn.zpp_pool,Mn.zpp_pool=e}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let l=t.parent;t.parent=n,n=t,t=l}for(;n!=null;){let l=n.parent;n.parent=t,n=l}return t}static _union(e,t){let n=ze._findRoot(e),l=ze._findRoot(t);n!=l&&(n.rank<l.rank?n.parent=l:n.rank>l.rank?l.parent=n:(l.parent=n,n.rank++))}static _pushVert(e,t){return e==null?t.prev=t.next=t:(t.prev=e,t.next=e.next,e.next.prev=t,e.next=t),t}static _isDegenKey(e){return e==1||e==4||e==16||e==64||e==3||e==12||e==48||e==192||e==129||e==6||e==24||e==96||e==5||e==20||e==80||e==65||e==17||e==68}static ISO(e,t,n){return e(t,n)}static run(e,t,n,l,s,i,o,r,a){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate();let c=(l-t)/i.zpp_inner.x,u=c|0;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");p=i.zpp_inner,p._validate!=null&&p._validate();let h=(s-n)/i.zpp_inner.y,x=h|0;c!=u&&++u,h!=x&&++x,r&&(ze.map==null?ze.map=new Ui(u,x):ze.map.resize(u,x,null)),ze.isos==null?ze.isos=new qi(u+1,x+1):ze.isos.resize(u+1,x+1,0);for(let d=0;d<x+1;d++){let f;if(d==0)f=n;else if(d<=x){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let m=i.zpp_inner;m._validate!=null&&m._validate(),f=n+i.zpp_inner.y*d}else f=s;for(let m=0;m<u+1;m++){let z;if(m==0)z=t;else if(m<=u){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let w=i.zpp_inner;w._validate!=null&&w._validate(),z=t+i.zpp_inner.x*m}else z=l;let Z=ze.isos,y=e(z,f);Z.list[d*Z.width+m]=y}}ze.ints==null?ze.ints=new Ji(u+1,(x<<1)+1):ze.ints.resize(u+1,(x<<1)+1,null);let b=null;r&&(b=ze._allocSpan(),b.next=null);let _=n;for(let d=0;d<x;d++){let f=_,m;if(d==x-1)m=s;else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let y=i.zpp_inner;y._validate!=null&&y._validate(),m=n+i.zpp_inner.y*(d+1)}_=m;let z=t,Z=null;for(let y=0;y<u;y++){let w=z,v;if(y==u-1)v=l;else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let M=i.zpp_inner;M._validate!=null&&M._validate(),v=t+i.zpp_inner.x*(y+1)}z=v;let P=y==0||!r,g=d==0||!r,k=y==u-1||!r,N=d==x-1||!r,E=ze.me.marchSquare(e,ze.isos,ze.ints,w,f,v,m,y,d,P,g,k,N,o);if(E==null){Z=null;continue}if(r){let M=E.p2!=null&&E.okey2!=14?E.p2:E.p1;E.pd=((M==E.p2?E.okey2:E.okey1)&128)==0?M.prev:M.prev.prev;let C=ze.map;C.list[d*C.width+y]=E;let D;if(Z!=null){let L=E.key1,U=L&1|(L&192)>>5,q=0;(U&1)!=0&&++q,(U&2)!=0&&++q,(U&4)!=0&&++q,D=q>=2}else D=!1;D?(ze.me.combLR(Z,E),E.span1=Z.spanr):(E.span1=ze._allocSpan(),E.span1.next=b,b=E.span1),E.p2!=null?(E.span2=ze._allocSpan(),E.span2.next=b,b=E.span2,E.spanr=E.span2):E.spanr=E.span1;let O=(E.keyr&28)>>2,j=0;(O&1)!=0&&++j,(O&2)!=0&&++j,(O&4)!=0&&++j,j>=2?Z=E:Z=null}else ze.me.output(a,E.p1),E.p2!=null&&ze.me.output(a,E.p2),ze._freePair(E)}}if(r){for(let d=1;d<x;d++){let f=null;for(let m=0;m<u;m++){let z=ze.map,Z=z.list[d*z.width+m];if(Z==null){f=null;continue}let w=(Z.p2!=null&&Z.okey2==14?Z.okey2:Z.okey1)&7,v=0;if((w&1)!=0&&++v,(w&2)!=0&&++v,(w&4)!=0&&++v,v<2){f=null;continue}let P=ze.map,g=P.list[(d-1)*P.width+m];if(g==null){f=null;continue}let N=((g.p2!=null&&g.okey2==56?g.okey2:g.okey1)&112)>>4,E=0;if((N&1)!=0&&++E,(N&2)!=0&&++E,(N&4)!=0&&++E,E<2){f=null;continue}let M=g.p2!=null&&g.okey2==56?g.span2:g.span1,C=Z.p2!=null&&Z.okey2==14?Z.span2:Z.span1,D=ze._findRoot(M),O=ze._findRoot(C);D==O?f!=C&&ze.me.combUD_virtual(g,Z):(ze._union(M,C),ze.me.combUD(g,Z)),f=((C==Z.span2?Z.okey2:Z.okey1)&4)!=0?C:null}}for(let d=0;d<x;d++)for(let f=0;f<u;f++){let m=ze.map,z=m.list[d*m.width+f];if(z==null)continue;let Z=ze._findRoot(z.span1);Z.out||(Z.out=!0,ze.me.output(a,z.p1)),z.p2!=null&&(Z=ze._findRoot(z.span2),Z.out||(Z.out=!0,ze.me.output(a,z.p2))),ze._freePair(z),m.list[d*m.width+f]=null}for(;b!=null;){let d=b;b=d.next;let f=d;f.parent=f,f.next=Cn.zpp_pool,Cn.zpp_pool=f}}}output(e,t){let n=ze._nape,l;if(t==null||t.next==t||t.next==t.prev)l=!0;else{let o=0,r=t,a=t;if(r!=null){let c=r;for(;;){let u=c;if(o+=u.x*(u.next.y-u.prev.y),c=c.next,c==a)break}}let p=o*.5;l=p*p<n.Config.epsilon*n.Config.epsilon}if(l){for(;t!=null;)if(t!=null&&t.prev==t)t.next=t.prev=null,t=null;else{let o=t.next;t.prev.next=t.next,t.next.prev=t.prev,t.next=t.prev=null,t=o}return}let s=n.geom.GeomPoly.get();s.zpp_inner.vertices=t;let i=e;i.zpp_inner.reverse_flag?i.push(s):i.unshift(s)}linkright(e,t){let n=t&7;return n==0?e:n==3?e.next.next:e.next}linkleft(e,t){return(t&1)==0?e.prev:e}linkdown(e,t){return(t&128)==0?e.prev:e.prev.prev}linkup(e,t){return e}combLR(e,t){let n=e.pr,l=e.okeyr&7,s=l==0?n:l==3?n.next.next:n.next,i=t.p1,o=(t.okey1&1)==0?i.prev:i,r=s.next,a=o.prev;(e.keyr&4)!=0?(t.pr==t.p1&&(t.pr=s.prev),t.p1=s.prev,s.prev.next=o.next,o.next.prev=s.prev,ze._freeVert(s)):(s.next=o.next,o.next.prev=s),ze._freeVert(o),(e.keyr&16)!=0?(t.pd=r.next,r.next.prev=a.prev,a.prev.next=r.next,ze._freeVert(r)):(r.prev=a.prev,a.prev.next=r),ze._freeVert(a)}combUD(e,t){let n=e.pd,l=t.p2!=null&&t.key2==14?t.p2:t.p1,s=n.prev,i=l.next;l.next=n.next,n.next.prev=l,ze._freeVert(n),i.prev=s.prev,s.prev.next=i,s==e.p1&&(e.p1=i),ze._freeVert(s)}combUD_virtual(e,t){let n=e.pd,l=t.p2!=null&&t.key2==14?t.p2:t.p1,s=n.prev,i=l.next;n.forced=l.forced=s.forced=i.forced=!0}combLeft(e){let t=e&1|(e&192)>>5,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combRight(e){let t=(e&28)>>2,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combUp(e){let t=e&7,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combDown(e){let t=(e&112)>>4,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}comb(e){let t=0;return(e&1)!=0&&++t,(e&2)!=0&&++t,(e&4)!=0&&++t,t>=2}_buildPoly(e,t,n,l,s,i,o,r,a,p,c,u,h,x,b,_,d,f,m){let z=null;for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let y;if(Z==0)y=ze._allocVert(l,s),(x||b)&&(y.forced=!0);else if(Z==2)y=ze._allocVert(i,s),(_||b)&&(y.forced=!0);else if(Z==4)y=ze._allocVert(i,o),(_||d)&&(y.forced=!0);else if(Z==6)y=ze._allocVert(l,o),(x||d)&&(y.forced=!0);else if(Z==1){if(y=n.list[(a<<1)*n.width+r],y==null){let w=this.xlerp(l,i,s,p,c,f,m);y=ze._allocVert(w,s),n.list[(a<<1)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);b&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&1)!=0||y.x==i&&(e&4)!=0)&&(e^=2)}else if(Z==5){if(y=n.list[((a<<1)+2)*n.width+r],y==null){let w=this.xlerp(l,i,o,h,u,f,m);y=ze._allocVert(w,o),n.list[((a<<1)+2)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);d&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&64)!=0||y.x==i&&(e&16)!=0)&&(e^=32)}else if(Z==3){if(y=n.list[((a<<1)+1)*n.width+(r+1)],y==null){let w=this.ylerp(s,o,i,c,u,f,m);y=ze._allocVert(i,w),n.list[((a<<1)+1)*n.width+(r+1)]=y}else y=ze._allocVert(y.x,y.y);_&&(y.forced=!0),(y.y==s||y.y==o)&&(y.y==s&&(e&4)!=0||y.y==o&&(e&16)!=0)&&(e^=8)}else{if(y=n.list[((a<<1)+1)*n.width+r],y==null){let w=this.ylerp(s,o,l,p,h,f,m);y=ze._allocVert(l,w),n.list[((a<<1)+1)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);x&&(y.forced=!0),(y.y==s||y.y==o)&&(y.y==s&&(e&1)!=0||y.y==o&&(e&64)!=0)&&(e^=128)}z=ze._pushVert(z,y)}return z!=null&&(z=z.next),{head:z,val:e}}marchSquare(e,t,n,l,s,i,o,r,a,p,c,u,h,x){let b=0,_=t.list[a*t.width+r];_<0&&(b|=8);let d=t.list[a*t.width+(r+1)];d<0&&(b|=4);let f=t.list[(a+1)*t.width+(r+1)];f<0&&(b|=2);let m=t.list[(a+1)*t.width+r];if(m<0&&(b|=1),b==0)return null;let z=ze._allocPair();if(b!=10&&b!=5){let Z=ze.look_march[b];z.okey1=Z;let y=this._buildPoly(Z,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=y.head,Z=y.val,z.key1=Z,ze._isDegenKey(Z)&&(Z=0,z.key1=0,z.p1=null),Z==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}else{let Z=e(.5*(l+i),.5*(s+o))<0;if(b==10)if(Z){let y=187;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=w.head,y=w.val,z.key1=y,ze._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}else{let y=131;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);if(z.p1=w.head,y=w.val,z.key1=y,ze._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y!=0){let v=56;z.okey2=v,v=this._buildPoly2(v,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x,z).val,z.key2=v,ze._isDegenKey(v)&&(v=0,z.key2=0,z.p2=null),v==0?(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1):(z.pr=z.p2,z.okeyr=z.okey2,z.keyr=z.key2)}else{let v=56;z.okey1=v;let P=this._buildPoly(v,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=P.head,v=P.val,z.key1=v,ze._isDegenKey(v)&&(v=0,z.key1=0,z.p1=null),v==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}}else if(Z){let y=238;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=w.head,y=w.val,z.key1=y,ze._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}else{let y=224;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);if(z.p1=w.head,y=w.val,z.key1=y,ze._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y!=0){let v=14;z.okey2=v,v=this._buildPoly2(v,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x,z).val,z.key2=v,ze._isDegenKey(v)&&(v=0,z.key2=0,z.p2=null),v==0?(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1):(z.pr=z.p2,z.okeyr=z.okey2,z.keyr=z.key2)}else{let v=14;z.okey1=v;let P=this._buildPoly(v,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=P.head,v=P.val,z.key1=v,ze._isDegenKey(v)&&(v=0,z.key1=0,z.p1=null),v==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}}}return z}_buildPoly2(e,t,n,l,s,i,o,r,a,p,c,u,h,x,b,_,d,f,m,z){for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let y;if(Z==0)y=ze._allocVert(l,s),(x||b)&&(y.forced=!0);else if(Z==2)y=ze._allocVert(i,s),(_||b)&&(y.forced=!0);else if(Z==4)y=ze._allocVert(i,o),(_||d)&&(y.forced=!0);else if(Z==6)y=ze._allocVert(l,o),(x||d)&&(y.forced=!0);else if(Z==1){if(y=n.list[(a<<1)*n.width+r],y==null){let v=this.xlerp(l,i,s,p,c,f,m);y=ze._allocVert(v,s),n.list[(a<<1)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);b&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&1)!=0||y.x==i&&(e&4)!=0)&&(e^=2)}else if(Z==5){if(y=n.list[((a<<1)+2)*n.width+r],y==null){let v=this.xlerp(l,i,o,h,u,f,m);y=ze._allocVert(v,o),n.list[((a<<1)+2)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);d&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&64)!=0||y.x==i&&(e&16)!=0)&&(e^=32)}else if(Z==3){if(y=n.list[((a<<1)+1)*n.width+(r+1)],y==null){let v=this.ylerp(s,o,i,c,u,f,m);y=ze._allocVert(i,v),n.list[((a<<1)+1)*n.width+(r+1)]=y}else y=ze._allocVert(y.x,y.y);_&&(y.forced=!0),(y.y==s||y.y==o)&&(y.y==s&&(e&4)!=0||y.y==o&&(e&16)!=0)&&(e^=8)}else{if(y=n.list[((a<<1)+1)*n.width+r],y==null){let v=this.ylerp(s,o,l,p,h,f,m);y=ze._allocVert(l,v),n.list[((a<<1)+1)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);x&&(y.forced=!0),(y.y==s||y.y==o)&&(y.y==s&&(e&1)!=0||y.y==o&&(e&64)!=0)&&(e^=128)}let w=y;z.p2==null?z.p2=w.prev=w.next=w:(w.prev=z.p2,w.next=z.p2.next,z.p2.next.prev=w,z.p2.next=w),z.p2=w}return z.p2!=null&&(z.p2=z.p2.next),{val:e}}lerp(e,t,n,l){let s=ze._nape;if(n==0)return e;if(l==0)return t;{let i=n-l,o=i*i<s.Config.epsilon*s.Config.epsilon?.5:n/i;return o<0?o=0:o>1&&(o=1),e+o*(t-e)}}xlerp(e,t,n,l,s,i,o){let r=ze._nape,a;if(l==0)a=e;else if(s==0)a=t;else{let p=l-s,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:l/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=i(a,n);if(p==0)break;if(l*p<0?(t=a,s=p):(e=a,l=p),l==0)a=e;else if(s==0)a=t;else{let c=l-s,u=c*c<r.Config.epsilon*r.Config.epsilon?.5:l/c;u<0?u=0:u>1&&(u=1),a=e+u*(t-e)}}return a}ylerp(e,t,n,l,s,i,o){let r=ze._nape,a;if(l==0)a=e;else if(s==0)a=t;else{let p=l-s,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:l/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=i(n,a);if(p==0)break;if(l*p<0?(t=a,s=p):(e=a,l=p),l==0)a=e;else if(s==0)a=t;else{let c=l-s,u=c*c<r.Config.epsilon*r.Config.epsilon?.5:l/c;u<0?u=0:u>1&&(u=1),a=e+u*(t-e)}}return a}};ze.__name__=["zpp_nape","geom","ZPP_MarchingSquares"],ze.isos=null,ze.ints=null,ze.map=null,ze._zpp=null,ze._nape=null;var Ks=ze;var nn=class nn{constructor(){this.outer=null;this.a=0;this.b=0;this.c=0;this.d=0;this.tx=0;this.ty=0;this._invalidate=null;this.next=null}static get(){let e;return nn.zpp_pool==null?e=new nn:(e=nn.zpp_pool,nn.zpp_pool=e.next,e.next=null),e}static identity(){let e=nn.get();return e.setas(1,0,0,1,0,0),e}wrapper(){if(this.outer==null)if(nn._wrapFn)this.outer=nn._wrapFn(this);else{this.outer=new nn._nape.geom.Mat23;let e=this.outer.zpp_inner;e.next=nn.zpp_pool,nn.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}invalidate(){this._invalidate!=null&&this._invalidate()}set(e){this.setas(e.a,e.b,e.c,e.d,e.tx,e.ty)}setas(e,t,n,l,s,i){this.tx=s,this.ty=i,this.a=e,this.b=t,this.c=n,this.d=l}free(){}alloc(){}};nn.__name__=["zpp_nape","geom","ZPP_Mat23"],nn._nape=null,nn._wrapFn=null,nn.zpp_pool=null;var Ys=nn;var gi=class{constructor(e,t){this.outer=null;this.m=0;this.n=0;this.m=e,this.n=t,this.x=[];let n=0,l=e*t;for(;n<l;)n++,this.x.push(0)}};gi.__name__=["zpp_nape","geom","ZPP_MatMN"];var dt=class dt{constructor(){this.node=null;this.prev=null;this.next=null;this.rightchain=!1;this.helper=null;this.type=0;this.diagonals=null;this.forced=!1;this.y=0;this.x=0;this.mag=0;this.id=0;this.id=dt.nextId++,this.diagonals=new zi}static get(e){let t;return dt.zpp_pool==null?t=new dt:(t=dt.zpp_pool,dt.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t}static rightdistance(e,t){let n=e.next.y>e.y,l=e.next.x-e.x,s=e.next.y-e.y,i=t.x-e.x,o=t.y-e.y;return(n?-1:1)*(o*l-i*s)}static vert_lt(e,t){if(t==e||t==e.next)return!0;if(e.y==e.next.y){let n=e.x,l=e.next.x;return(n<l?n:l)<=t.x}else return dt.rightdistance(e,t)<=0}static edge_swap(e,t){let n=e.node;e.node=t.node,t.node=n}static edge_lt(e,t){if(e==t&&e.next==t.next)return!1;if(e==t.next)return!dt.vert_lt(e,t);if(t==e.next)return dt.vert_lt(t,e);if(e.y==e.next.y)if(t.y==t.next.y){let n=e.x,l=e.next.x,s=t.x,i=t.next.x;return(n>l?n:l)>(s>i?s:i)}else return dt.rightdistance(t,e)>0?!0:dt.rightdistance(t,e.next)>0;else{let n=dt.rightdistance(e,t),l=dt.rightdistance(e,t.next);if(n==0&&l==0){let o=e.x,r=e.next.x,a=t.x,p=t.next.x;return(o>r?o:r)>(a>p?a:p)}if(n*l>=0)return n<0?!0:l<0;let s=dt.rightdistance(t,e),i=dt.rightdistance(t,e.next);return s*i>=0?s>0?!0:i>0:!1}}alloc(){}free(){this.helper=null}copy(){let e;return dt.zpp_pool==null?e=new dt:(e=dt.zpp_pool,dt.zpp_pool=e.next,e.next=null),e.x=this.x,e.y=this.y,e.forced=this.forced,e}sort(){let e=this.prev.x-this.x,t=this.prev.y-this.y,n=this.next.x-this.x,l=this.next.y-this.y,s=l*e-n*t,i=s>0?-1:s==0?0:1,o=this.diagonals;if(o.head!=null&&o.head.next!=null){let r=o.head,a,p,c,u,h=1,x,b,_;for(;;){for(x=0,p=r,r=null,a=r;p!=null;){for(++x,c=p,b=0,_=h;c!=null&&b<h;)++b,c=c.next;for(;b>0||_>0&&c!=null;){if(b==0)u=c,c=c.next,--_;else if(_==0||c==null)u=p,p=p.next,--b;else{let d;if(i==1){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,l=c.elt.y-this.y;let f=l*e-n*t;d=(f>0?-1:f==0?0:1)==1}else{e=this.prev.x-this.x,t=this.prev.y-this.y,n=p.elt.x-this.x,l=p.elt.y-this.y;let f=l*e-n*t,m=f>0?-1:f==0?0:1;e=this.prev.x-this.x,t=this.prev.y-this.y,n=c.elt.x-this.x,l=c.elt.y-this.y;let z=l*e-n*t,Z=z>0?-1:z==0?0:1;if(m*Z==1||m*Z==0&&(m==1||Z==1)){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,l=c.elt.y-this.y;let y=l*e-n*t;d=(y>0?-1:y==0?0:1)==1}else if(m==-1||Z==-1)d=Z==-1;else if(m==0&&Z==0){e=this.x-this.prev.x,t=this.y-this.prev.y,n=p.elt.x-this.x,l=p.elt.y-this.y;let y=e*n+t*l;n=c.elt.x-this.x,l=c.elt.y-this.y;let w=e*n+t*l;d=y<0&&w>0?!0:!(w<0&&y>0)}else d=!0}d?(u=p,p=p.next,--b):(u=c,c=c.next,--_)}a!=null?a.next=u:r=u,a=u}p=c}if(a.next=null,h<<=1,!(x>1))break}o.head=r,o.modified=!0,o.pushmod=!0}}};dt.__name__=["zpp_nape","geom","ZPP_PartitionVertex"],dt.zpp_pool=null,dt.nextId=0;var Ge=dt;var sn=class sn{constructor(e){this.next=null;this.vertices=null;this.init(e)}static getSharedPP(){return sn.sharedPPList==null&&(sn.sharedPPList=new gl),sn.sharedPPList}static getShared(){return sn.sharedGVList==null&&(sn.sharedGVList=new ds),sn.sharedGVList}eq(e,t){let n=e.x-t.x,l=e.y-t.y;return n*n+l*l<me().Config.epsilon*me().Config.epsilon}alloc(){}free(){}init(e){if(e==null)return;let t=0,n=e,l=e;if(n!=null){let o=n;for(;;){let r=o;if(t+=r.x*(r.next.y-r.prev.y),o=o.next,o==l)break}}let s=t*.5>0,i=e;for(;;){let o;if(s){let r;Ge.zpp_pool==null?r=new Ge:(r=Ge.zpp_pool,Ge.zpp_pool=r.next,r.next=null),r.x=i.x,r.y=i.y;let a=r;this.vertices==null?this.vertices=a.prev=a.next=a:(a.prev=this.vertices,a.next=this.vertices.next,this.vertices.next.prev=a,this.vertices.next=a),o=a}else{let r;Ge.zpp_pool==null?r=new Ge:(r=Ge.zpp_pool,Ge.zpp_pool=r.next,r.next=null),r.x=i.x,r.y=i.y;let a=r;this.vertices==null?this.vertices=a.prev=a.next=a:(a.next=this.vertices,a.prev=this.vertices.prev,this.vertices.prev.next=a,this.vertices.prev=a),o=a}if(this.vertices=o,this.vertices.forced=i.forced,i=i.next,i==e)break}this.remove_collinear_vertices()}remove_collinear_vertices(){let e=this.vertices,t=!0;for(;t||e!=this.vertices;)if(t=!1,this.eq(e,e.next)){if(e==this.vertices&&(this.vertices=e.next,t=!0),e.forced&&(e.next.forced=!0),e!=null&&e.prev==e){e.next=e.prev=null;let l=e;l.helper=null,l.next=Ge.zpp_pool,Ge.zpp_pool=l,e=null,e=null}else{let l=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let s=e;s.helper=null,s.next=Ge.zpp_pool,Ge.zpp_pool=s,e=l}if(e==null){this.vertices=null;break}}else e=e.next;if(this.vertices==null)return!0;let n;for(;;){for(n=!1,e=this.vertices,t=!0;t||e!=this.vertices;){t=!1;let l=e.prev,s=e.x-l.x,i=e.y-l.y,o=e.next.x-e.x,a=(e.next.y-e.y)*s-o*i;if(a*a>=me().Config.epsilon*me().Config.epsilon)e=e.next;else{if(e==this.vertices&&(this.vertices=e.next,t=!0),e!=null&&e.prev==e){e.next=e.prev=null;let p=e;p.helper=null,p.next=Ge.zpp_pool,Ge.zpp_pool=p,e=null,e=null}else{let p=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let c=e;c.helper=null,c.next=Ge.zpp_pool,Ge.zpp_pool=c,e=p}if(n=!0,e==null){n=!1,this.vertices=null;break}}}if(!n)break}return this.vertices==null}add_diagonal(e,t){e.diagonals.add(t),t.diagonals.add(e),e.forced=t.forced=!0}extract_partitions(e){if(e==null&&(e=new gl),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let i=t;for(;i.sort(),i=i.next,i!=n;);}for(this.pull_partitions(this.vertices,e);this.vertices!=null;){let i;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let o=this.vertices;o.helper=null,o.next=Ge.zpp_pool,Ge.zpp_pool=o,i=this.vertices=null}else{let o=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let r=this.vertices;r.helper=null,r.next=Ge.zpp_pool,Ge.zpp_pool=r,this.vertices=null,i=o}this.vertices=i}let l=null,s=e.head;for(;s!=null;){if(s.elt.remove_collinear_vertices()){e.erase(l);continue}l=s,s=s.next}}return e}pull_partitions(e,t){let n;sn.zpp_pool==null?n=new sn:(n=sn.zpp_pool,sn.zpp_pool=n.next,n.next=null);let l=e;for(;;){let r;Ge.zpp_pool==null?r=new Ge:(r=Ge.zpp_pool,Ge.zpp_pool=r.next,r.next=null),r.x=l.x,r.y=l.y,r.forced=l.forced;let a=r;if(n.vertices==null?n.vertices=a.prev=a.next=a:(a.prev=n.vertices,a.next=n.vertices.next,n.vertices.next.prev=a,n.vertices.next=a),n.vertices=a,n.vertices.forced=l.forced,l.diagonals.head!=null){let p=l.diagonals,c=p.head.elt;if(p.pop(),c==e)break;l=this.pull_partitions(l,t)}else l=l.next;if(l==e)break}let s=0,i=n.vertices,o=n.vertices;if(i!=null){let r=i;for(;;){let a=r;if(s+=a.x*(a.next.y-a.prev.y),r=r.next,r==o)break}}return s*.5!=0&&t.add(n),l}extract(e){if(e==null&&(e=new ds),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}for(this.pull(this.vertices,e);this.vertices!=null;){let l;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let s=this.vertices;s.helper=null,s.next=Ge.zpp_pool,Ge.zpp_pool=s,l=this.vertices=null}else{let s=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let i=this.vertices;i.helper=null,i.next=Ge.zpp_pool,Ge.zpp_pool=i,this.vertices=null,l=s}this.vertices=l}}return e}pull(e,t){let n=null,l=e;for(;;){let a=l.x,p=l.y,c;ge.zpp_pool==null?c=new ge:(c=ge.zpp_pool,ge.zpp_pool=c.next,c.next=null),c.forced=!1,c.x=a,c.y=p;let u=c;if(n==null?u.prev=u.next=u:(u.prev=n,u.next=n.next,n.next.prev=u,n.next=u),n=u,n.forced=l.forced,l.diagonals.head!=null){let h=l.diagonals,x=h.head.elt;if(h.pop(),x==e)break;l=this.pull(l,t)}else l=l.next;if(l==e)break}let s=0,i=n,o=n;if(i!=null){let a=i;for(;;){let p=a;if(s+=p.x*(p.next.y-p.prev.y),a=a.next,a==o)break}}let r=s*.5;if(r*r>=me().Config.epsilon*me().Config.epsilon){let a=n,p=!0;for(;p||a!=n;){p=!1;let c=a.x-a.next.x,u=a.y-a.next.y;if(c*c+u*u<me().Config.epsilon*me().Config.epsilon){if(a==n&&(n=a.next,p=!0),a.forced&&(a.next.forced=!0),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else{let h=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=h}if(a==null){n=null;break}}else a=a.next}if(n!=null){let c;for(;;){for(c=!1,a=n,p=!0;p||a!=n;){p=!1;let u=a.prev,h=a.x-u.x,x=a.y-u.y,b=a.next.x-a.x,d=(a.next.y-a.y)*h-b*x;if(d*d>=me().Config.epsilon*me().Config.epsilon)a=a.next;else{if(a==n&&(n=a.next,p=!0),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else{let f=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=f}if(c=!0,a==null){c=!1,n=null;break}}}if(!c)break}}n!=null&&t.add(n)}return l}};sn.__name__=["zpp_nape","geom","ZPP_PartitionedPoly"],sn.zpp_pool=null,sn.sharedPPList=null,sn.sharedGVList=null;var is=sn;var De=class De{static bisector(e){let t=e.prev,n=e.next,l=e.x-t.x,s=e.y-t.y,i=n.x-e.x,o=n.y-e.y,r;le.zpp_pool==null?r=new le:(r=le.zpp_pool,le.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=-s-o,r.y=l+i;let a=r,p=a.x*a.x+a.y*a.y,u=1/Math.sqrt(p);return a.x*=u,a.y*=u,o*l-i*s<0&&(a.x=-a.x,a.y=-a.y),a}static below(e,t){if(e.y<t.y)return!0;if(e.y>t.y)return!1;if(e.x<t.x)return!0;if(e.x>t.x)return!1;{let n=De.bisector(e),l=De.bisector(t),s=1;n.x+=e.x*s,n.y+=e.y*s;let i=1;l.x+=t.x*i,l.y+=t.y*i;let o=n.x<l.x||n.x==l.x&&n.y<l.y;return n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=le.zpp_pool,le.zpp_pool=n,l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l._isimmutable=null,l._validate=null,l._invalidate=null,l.next=le.zpp_pool,le.zpp_pool=l,o}}static above(e,t){return De.below(t,e)}static left_vertex(e){let t=e.prev;return t.y>e.y?!0:t.y==e.y?e.next.y<e.y:!1}static isMonotone(e){let t=e,n=e,l=e.next,s=e;if(l!=null){let r=l;for(;;){let a=r;if(a.y<t.y&&(t=a),a.y>n.y&&(n=a),r=r.next,r==s)break}}let i=!0,o=t;if(n!=t.next){let r=t.next,a=n;if(r!=null){let p=r;for(;;){let c=p;if(c.y<o.y){i=!1;break}if(o=c,p=p.next,p==a)break}}}if(!i)return!1;if(o=t,n!=t.prev){let r=t.prev,a=n;if(r!=null){let p=r;for(;;){let c=p;if(c.y<o.y){i=!1;break}if(o=c,p=p.prev,p==a)break}}}return i}static getShared(){return De.sharedPPoly==null&&(De.sharedPPoly=new is),De.sharedPPoly}static decompose(e,t){if(t==null?t=new is(e):t.init(e),t.vertices==null)return t;De.queue==null&&(De.queue=new zi);let n=t.vertices,l=t.vertices;if(n!=null){let i=n;for(;;){let o=i;De.queue.add(o);let r=o.next.x-o.x,a=o.next.y-o.y,p=o.prev.x-o.x,u=(o.prev.y-o.y)*r-p*a>0;if(o.type=De.below(o.prev,o)?De.below(o.next,o)?u?0:3:4:De.below(o,o.next)?u?1:2:4,i=i.next,i==l)break}}let s=De.queue;if(s.head!=null&&s.head.next!=null){let i=s.head,o,r,a,p,c=1,u,h,x;for(;;){for(u=0,r=i,i=null,o=i;r!=null;){for(++u,a=r,h=0,x=c;a!=null&&h<c;)++h,a=a.next;for(;h>0||x>0&&a!=null;)h==0?(p=a,a=a.next,--x):x==0||a==null||De.above(r.elt,a.elt)?(p=r,r=r.next,--h):(p=a,a=a.next,--x),o!=null?o.next=p:i=p,o=p;r=a}if(o.next=null,c<<=1,!(u>1))break}s.head=i,s.modified=!0,s.pushmod=!0}for(De.edges==null&&(bs.zpp_pool==null?De.edges=new bs:(De.edges=bs.zpp_pool,bs.zpp_pool=De.edges.next,De.edges.next=null),De.edges.lt=Ge.edge_lt,De.edges.swapped=Ge.edge_swap);De.queue.head!=null;){let i=De.queue.pop_unsafe();switch(i.type){case 0:i.helper=i,i.node=De.edges.insert(i);break;case 1:{let o=i.prev;if(o.helper==null)throw new Error("Fatal error (1): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(i,o.helper),De.edges.remove_node(o.node),o.helper=null;break}case 2:{let o=i.prev;if(o.helper==null)throw new Error("Fatal error (3): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(i,o.helper),De.edges.remove_node(o.node),o.helper=null;let r=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,i)){r=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else{for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent}}}let a=r;if(a!=null){if(a.helper==null)throw new Error("Fatal error (4): Polygon is not weakly-simple and clockwise");a.helper.type==2&&t.add_diagonal(i,a.helper),a.helper=i}break}case 3:{let o=null;if(!De.edges.empty()){let a=De.edges.parent;for(;a.prev!=null;)a=a.prev;for(;a!=null;){let p=a.data;if(!Ge.vert_lt(p,i)){o=p;break}if(a.next!=null)for(a=a.next;a.prev!=null;)a=a.prev;else{for(;a.parent!=null&&a==a.parent.next;)a=a.parent;a=a.parent}}}let r=o;if(r!=null){if(r.helper==null)throw new Error("Fatal error (2): Polygon is not weakly-simple and clockwise");t.add_diagonal(i,r.helper),r.helper=i}i.node=De.edges.insert(i),i.helper=i;break}case 4:{let o=i.prev;if(De.left_vertex(i)){if(o.helper==null)throw new Error("Fatal error (5): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(i,o.helper),De.edges.remove_node(o.node),o.helper=null,i.node=De.edges.insert(i),i.helper=i}else{let r=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,i)){r=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else{for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent}}}let a=r;if(a==null||a.helper==null)throw new Error("Fatal error (6): Polygon is not weakly-simple and clockwise");a.helper.type==2&&t.add_diagonal(i,a.helper),a.helper=i}break}}}return t}};De.__name__=["zpp_nape","geom","ZPP_Monotone"],De.queue=null,De.edges=null,De.sharedPPoly=null;var kl=De;var Ci=class Ci{constructor(){this.node=null;this.di=0;this.id=0;this.b=null;this.a=null;this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null}static get(e,t){let n;return Ci.zpp_pool==null?n=new Ci:(n=Ci.zpp_pool,Ci.zpp_pool=n.next,n.next=null),n.a=e,n.b=t,e.id<t.id?(n.id=e.id,n.di=t.id):(n.id=t.id,n.di=e.id),n}static edge_swap(e,t){let n=e.node;e.node=t.node,t.node=n}static edge_lt(e,t){return e.id>=t.id?e.id==t.id?e.di<t.di:!1:!0}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){this.a=this.b=null,this.node=null}alloc(){}};Ci.__name__=["zpp_nape","geom","ZPP_PartitionPair"],Ci.zpp_pool=null;var Bt=Ci;var Nt=class Nt{constructor(){this.zip_dir=!1;this.absnormaly=0;this.absnormalx=0;this.normaly=0;this.normalx=0;this.idiry=0;this.idirx=0;this.diry=0;this.dirx=0;this.originy=0;this.originx=0;this.userData=null;this.maxdist=0;this.direction=null;this.origin=null;let e=me(),t;if(de.poolVec2==null?t=new e.geom.Vec2:(t=de.poolVec2,de.poolVec2=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t==de.nextVec2&&(de.nextVec2=null)),t.zpp_inner==null){let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=0,l.y=0,t.zpp_inner=l,t.zpp_inner.outer=t}else{if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=t.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");l._isimmutable!=null&&l._isimmutable();let s;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=t.zpp_inner;if(i._validate!=null&&i._validate(),t.zpp_inner.x==0){if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=t.zpp_inner;o._validate!=null&&o._validate(),s=t.zpp_inner.y==0}else s=!1;if(!s){t.zpp_inner.x=0,t.zpp_inner.y=0;let o=t.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}t.zpp_inner.weak=!1,this.origin=t,this.origin.zpp_inner._invalidate=l=>this.origin_invalidate(l);let n;if(de.poolVec2==null?n=new e.geom.Vec2:(n=de.poolVec2,de.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==de.nextVec2&&(de.nextVec2=null)),n.zpp_inner==null){let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=0,l.y=0,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");l._isimmutable!=null&&l._isimmutable();let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),s=n.zpp_inner.y==0}else s=!1;if(!s){n.zpp_inner.x=0,n.zpp_inner.y=0;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.direction=n,this.direction.zpp_inner._invalidate=l=>this.direction_invalidate(l),this.originx=0,this.originy=0,this.dirx=0,this.diry=0,this.zip_dir=!1}origin_invalidate(e){this.originx=e.x,this.originy=e.y}direction_invalidate(e){this.dirx=e.x,this.diry=e.y,this.zip_dir=!0}invalidate_dir(){this.zip_dir=!0}validate_dir(){if(this.zip_dir){this.zip_dir=!1;let e=me();if(this.dirx*this.dirx+this.diry*this.diry<e.Config.epsilon)throw new Error("Error: Ray::direction is degenerate");let t=this.dirx*this.dirx+this.diry*this.diry,n=1/Math.sqrt(t);this.dirx*=n,this.diry*=n,this.idirx=1/this.dirx,this.idiry=1/this.diry,this.normalx=-this.diry,this.normaly=this.dirx;let l=this.normalx;this.absnormalx=l<0?-l:l;let s=this.normaly;this.absnormaly=s<0?-s:s}}rayAABB(){let e=this.originx,t=e,n=this.originy,l=n;if(this.maxdist>=1/0?(this.dirx>0?t=1/0:this.dirx<0&&(t=-1/0),this.diry>0?l=1/0:this.diry<0&&(l=-1/0)):(t+=this.maxdist*this.dirx,l+=this.maxdist*this.diry),t<e){let i=e;e=t,t=i}if(l<n){let i=n;n=l,l=i}let s;return be.zpp_pool==null?s=new be:(s=be.zpp_pool,be.zpp_pool=s.next,s.next=null),s.minx=e,s.miny=n,s.maxx=t,s.maxy=l,s}aabbtest(e){let t=this.normalx*(this.originx-.5*(e.minx+e.maxx))+this.normaly*(this.originy-.5*(e.miny+e.maxy)),n=this.absnormalx*.5*(e.maxx-e.minx)+this.absnormaly*.5*(e.maxy-e.miny),l=t;return(l<0?-l:l)<n}aabbsect(e){let t=this.originx>=e.minx&&this.originx<=e.maxx,n=this.originy>=e.miny&&this.originy<=e.maxy;if(t&&n)return 0;{let l=-1;for(;!(this.dirx>=0&&this.originx>=e.maxx)&&!(this.dirx<=0&&this.originx<=e.minx||this.diry>=0&&this.originy>=e.maxy||this.diry<=0&&this.originy<=e.miny);){if(this.dirx>0){let s=(e.minx-this.originx)*this.idirx;if(s>=0&&s<=this.maxdist){let i=this.originy+s*this.diry;if(i>=e.miny&&i<=e.maxy){l=s;break}}}else if(this.dirx<0){let s=(e.maxx-this.originx)*this.idirx;if(s>=0&&s<=this.maxdist){let i=this.originy+s*this.diry;if(i>=e.miny&&i<=e.maxy){l=s;break}}}if(this.diry>0){let s=(e.miny-this.originy)*this.idiry;if(s>=0&&s<=this.maxdist){let i=this.originx+s*this.dirx;if(i>=e.minx&&i<=e.maxx){l=s;break}}}else if(this.diry<0){let s=(e.maxy-this.originy)*this.idiry;if(s>=0&&s<=this.maxdist){let i=this.originx+s*this.dirx;if(i>=e.minx&&i<=e.maxx){l=s;break}}}break}return l}}static _allocVec2(e,t){let n=me();if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;if(de.poolVec2==null?l=new n.geom.Vec2:(l=de.poolVec2,de.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==de.nextVec2&&(de.nextVec2=null)),l.zpp_inner==null){let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,l.zpp_inner=s,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let i;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x==e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),i=l.zpp_inner.y==t):i=!1,i||(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner._invalidate!=null&&l.zpp_inner._invalidate(l.zpp_inner))}return l.zpp_inner.weak=!1,l}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let l=1;n.localCOMx+=n.lverts.next.next.x*l,n.localCOMy+=n.lverts.next.next.y*l;let s=.5;n.localCOMx*=s,n.localCOMy*=s}else{n.localCOMx=0,n.localCOMy=0;let l=0,s=n.lverts.next,i=s;s=s.next;let o=s;for(s=s.next;s!=null;){let h=s;l+=o.x*(h.y-i.y);let x=h.y*o.x-h.x*o.y;n.localCOMx+=(o.x+h.x)*x,n.localCOMy+=(o.y+h.y)*x,i=o,o=h,s=s.next}s=n.lverts.next;let r=s;l+=o.x*(r.y-i.y);let a=r.y*o.x-r.x*o.y;n.localCOMx+=(o.x+r.x)*a,n.localCOMy+=(o.y+r.y)*a,i=o,o=r,s=s.next;let p=s;l+=o.x*(p.y-i.y);let c=p.y*o.x-p.x*o.y;n.localCOMx+=(o.x+p.x)*c,n.localCOMy+=(o.y+p.y)*c,l=1/(3*l);let u=l;n.localCOMx*=u,n.localCOMy*=u}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}_circleNormal(e,t,n){let l=this.originx+this.dirx*e,s=this.originy+this.diry*e;l-=t.worldCOMx,s-=t.worldCOMy;let i=l*l+s*s,o=1/Math.sqrt(i);return l*=o,s*=o,n&&(l=-l,s=-s),{nx:l,ny:s}}static _insertSorted(e,t){let n=null,l=e.zpp_inner.inner.head;for(;l!=null;){let o=l.elt;if(t.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(t.zpp_inner.toiDistance<o.zpp_inner.toiDistance)break;n=l,l=l.next}let s=e.zpp_inner.inner,i;ys.zpp_pool==null?i=new ys:(i=ys.zpp_pool,ys.zpp_pool=i.next,i.next=null),i.elt=t,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++}circlesect(e,t,n){Nt._validateWorldCOM(e);let l=this.originx-e.worldCOMx,s=this.originy-e.worldCOMy,i=this.dirx*this.dirx+this.diry*this.diry,o=2*(l*this.dirx+s*this.diry),r=l*l+s*s-e.radius*e.radius,a=o*o-4*i*r;if(a==0){let p=-o/2*i;if((!t||r>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),u=Nt._allocVec2(c.nx,c.ny);return zn.getRay(u,p,r<=0,e.outer)}else return null}else{a=Math.sqrt(a),i=1/(2*i);let p=(-o-a)*i,c=(-o+a)*i;if(p>0)if(p<n&&p<=this.maxdist){let u=this._circleNormal(p,e,!1),h=Nt._allocVec2(u.nx,u.ny);return zn.getRay(h,p,!1,e.outer)}else return null;else if(c>0&&t)if(c<n&&c<=this.maxdist){let u=this._circleNormal(c,e,!0),h=Nt._allocVec2(u.nx,u.ny);return zn.getRay(h,c,!0,e.outer)}else return null;else return null}}circlesect2(e,t,n){Nt._validateWorldCOM(e);let l=this.originx-e.worldCOMx,s=this.originy-e.worldCOMy,i=this.dirx*this.dirx+this.diry*this.diry,o=2*(l*this.dirx+s*this.diry),r=l*l+s*s-e.radius*e.radius,a=o*o-4*i*r;if(a==0){let p=-o/2*i;if((!t||r>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),u=Nt._allocVec2(c.nx,c.ny),h=zn.getRay(u,p,r<=0,e.outer);Nt._insertSorted(n,h)}}else{a=Math.sqrt(a),i=1/(2*i);let p=(-o-a)*i,c=(-o+a)*i;if(p>0&&p<=this.maxdist){let u=this._circleNormal(p,e,!1),h=Nt._allocVec2(u.nx,u.ny),x=zn.getRay(h,p,!1,e.outer);Nt._insertSorted(n,x)}if(c>0&&c<=this.maxdist&&t){let u=this._circleNormal(c,e,!0),h=Nt._allocVec2(u.nx,u.ny),x=zn.getRay(h,c,!0,e.outer);Nt._insertSorted(n,x)}}}polysect(e,t,n){let l=me(),s=n,i=null,o=e.edges.head,r=!0,a=e.gverts.next,p=a,c=a.next;for(;c!=null;){let u=c,h=o.elt;if(t||h.gnormx*this.dirx+h.gnormy*this.diry<0){let x=u.x-p.x,b=u.y-p.y,_=p.x-this.originx,d=p.y-this.originy,f=b*this.dirx-x*this.diry;if(f*f>l.Config.epsilon){f=1/f;let m=(b*_-x*d)*f;if(m>0&&m<s&&m<=this.maxdist){let z=(this.diry*_-this.dirx*d)*f;z>-l.Config.epsilon&&z<1+l.Config.epsilon&&(s=m,i=o.elt)}}}o=o.next,p=u,c=c.next}if(r){c=e.gverts.next;let u=c,h=o.elt;if(t||h.gnormx*this.dirx+h.gnormy*this.diry<0){let x=u.x-p.x,b=u.y-p.y,_=p.x-this.originx,d=p.y-this.originy,f=b*this.dirx-x*this.diry;if(f*f>l.Config.epsilon){f=1/f;let m=(b*_-x*d)*f;if(m>0&&m<s&&m<=this.maxdist){let z=(this.diry*_-this.dirx*d)*f;z>-l.Config.epsilon&&z<1+l.Config.epsilon&&(s=m,i=o.elt)}}}}if(i!=null){let u=i.gnormx,h=i.gnormy,x=u*this.dirx+h*this.diry>0;x&&(u=-u,h=-h);let b=Nt._allocVec2(u,h);return zn.getRay(b,s,x,e.outer)}else return null}polysect2(e,t,n){let l=me(),s=1/0,i=-1,o=null,r=null,a=e.edges.head,p=!0,c=e.gverts.next,u=c,h=c.next;for(;h!=null;){let x=h,b=a.elt;if(t||b.gnormx*this.dirx+b.gnormy*this.diry<0){let _=x.x-u.x,d=x.y-u.y,f=u.x-this.originx,m=u.y-this.originy,z=d*this.dirx-_*this.diry;if(z*z>l.Config.epsilon){z=1/z;let Z=(d*f-_*m)*z;if(Z>0&&Z<=this.maxdist&&(Z<s||Z>i)){let y=(this.diry*f-this.dirx*m)*z;y>-l.Config.epsilon&&y<1+l.Config.epsilon&&(Z<s&&(s=Z,o=a.elt),Z>i&&(i=Z,r=a.elt))}}}a=a.next,u=x,h=h.next}if(p){h=e.gverts.next;let x=h,b=a.elt;if(t||b.gnormx*this.dirx+b.gnormy*this.diry<0){let _=x.x-u.x,d=x.y-u.y,f=u.x-this.originx,m=u.y-this.originy,z=d*this.dirx-_*this.diry;if(z*z>l.Config.epsilon){z=1/z;let Z=(d*f-_*m)*z;if(Z>0&&Z<=this.maxdist&&(Z<s||Z>i)){let y=(this.diry*f-this.dirx*m)*z;y>-l.Config.epsilon&&y<1+l.Config.epsilon&&(Z<s&&(s=Z,o=a.elt),Z>i&&(i=Z,r=a.elt))}}}}if(o!=null){let x=o.gnormx,b=o.gnormy,_=x*this.dirx+b*this.diry>0;_&&(x=-x,b=-b);let d=Nt._allocVec2(x,b),f=zn.getRay(d,s,_,e.outer);Nt._insertSorted(n,f)}if(r!=null&&o!=r){let x=r.gnormx,b=r.gnormy,_=x*this.dirx+b*this.diry>0;_&&(x=-x,b=-b);let d=Nt._allocVec2(x,b),f=zn.getRay(d,i,_,e.outer);Nt._insertSorted(n,f)}}};Nt.__name__=["zpp_nape","geom","ZPP_Ray"],Nt.internal=!1;var El=Nt;var hi=class hi{constructor(){this.forced=!1;this.x=0;this.y=0;this.links=null;this.id=0;this.next=null;this.node=null;this.id=fn.ZPP_SimpleVert(),en.zpp_pool==null?this.links=new en:(this.links=en.zpp_pool,en.zpp_pool=this.links.next,this.links.next=null),this.links.lt=hi.less_xy}static less_xy(e,t){return e.y<t.y?!0:e.y==t.y?e.x<t.x:!1}static swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}static get(e,t){let n;return hi.zpp_pool==null?n=new hi:(n=hi.zpp_pool,hi.zpp_pool=n.next,n.next=null),n.x=e,n.y=t,n}free(){this.links.clear(),this.node=null,this.forced=!1}alloc(){}};hi.__name__=["zpp_nape","geom","ZPP_SimpleVert"],hi.zpp_pool=null;var ke=hi;var Mi=class Mi{constructor(){this.left=null;this.right=null;this.vertices=null;this.id=0;this.next=null;this.prev=null;this.node=null;this.id=fn.ZPP_SimpleSeg(),en.zpp_pool==null?this.vertices=new en:(this.vertices=en.zpp_pool,en.zpp_pool=this.vertices.next,this.vertices.next=null),this.vertices.lt=(e,t)=>this.less_xy(e,t)}static get(e,t){let n;return Mi.zpp_pool==null?n=new Mi:(n=Mi.zpp_pool,Mi.zpp_pool=n.next,n.next=null),n.left=e,n.right=t,n.vertices.insert(e),n.vertices.insert(t),n}free(){this.left=this.right=null,this.prev=null,this.node=null,this.vertices.clear()}alloc(){}less_xy(e,t){return e.x<t.x?!0:e.x==t.x?e.y<t.y:!1}};Mi.__name__=["zpp_nape","geom","ZPP_SimpleSeg"],Mi.zpp_pool=null;var Tt=Mi;var Zi=class Zi{constructor(){this.type=0;this.vertex=null;this.segment=null;this.segment2=null;this.node=null;this.next=null}static swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}static less_xy(e,t){return e.vertex.x<t.vertex.x?!0:e.vertex.x>t.vertex.x?!1:e.vertex.y<t.vertex.y?!0:e.vertex.y>t.vertex.y?!1:e.type<t.type}static get(e){let t;return Zi.zpp_pool==null?t=new Zi:(t=Zi.zpp_pool,Zi.zpp_pool=t.next,t.next=null),t.vertex=e,t}free(){this.vertex=null,this.segment=this.segment2=null,this.node=null}alloc(){}};Zi.__name__=["zpp_nape","geom","ZPP_SimpleEvent"],Zi.zpp_pool=null;var Me=Zi;var ki=class{constructor(){this.sweepx=0;this.tree=null;ms.zpp_pool==null?this.tree=new ms:(this.tree=ms.zpp_pool,ms.zpp_pool=this.tree.next,this.tree.next=null),this.tree.lt=(e,t)=>this.edge_lt(e,t),this.tree.swapped=(e,t)=>this.swap_nodes(e,t)}swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}edge_lt(e,t){let n=e.left,l=e.right,s=t.left,i=t.right,o,r,a,p,c;if(e.left==t.left&&e.right==t.right)return!1;if(e.left==t.right)return n.x==l.x?n.y<l.y?n.y>s.y:l.y>s.y:(c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=s.x-n.x,p=s.y-n.y,(c?r*a-o*p:p*o-a*r)<0);if(e.right==t.left){let u;return s.x==i.x?u=s.y<i.y?s.y>n.y:i.y>n.y:(c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=n.x-s.x,p=n.y-s.y,u=(c?r*a-o*p:p*o-a*r)<0),!u}else{if(e.left==t.left)return n.x==l.x?n.y<l.y?n.y>i.y:l.y>i.y:(c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?r*a-o*p:p*o-a*r)<0);if(e.right==t.right)return n.x==l.x?n.y<l.y?n.y>s.y:l.y>s.y:(c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=s.x-n.x,p=s.y-n.y,(c?r*a-o*p:p*o-a*r)<0)}if(n.x==l.x)if(s.x==i.x){let u=n.y<l.y?l:n,h=s.y<i.y?i:s;return u.y>h.y}else{c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=n.x-s.x,p=n.y-s.y;let u=c?r*a-o*p:p*o-a*r;c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=l.x-s.x,p=l.y-s.y;let h=c?r*a-o*p:p*o-a*r;return u*h>=0?u>=0:this.sweepx>=n.x}else if(s.x==i.x){c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=s.x-n.x,p=s.y-n.y;let u=c?r*a-o*p:p*o-a*r;c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=c?r*a-o*p:p*o-a*r;return u*h>=0?u<0:this.sweepx<s.x}else{c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=s.x-n.x,p=s.y-n.y;let u=(c?r*a-o*p:p*o-a*r)<0;c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=(c?r*a-o*p:p*o-a*r)<0;if(u==h)return u;{c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=n.x-s.x,p=n.y-s.y;let x=(c?r*a-o*p:p*o-a*r)>=0;c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=l.x-s.x,p=l.y-s.y;let b=(c?r*a-o*p:p*o-a*r)>=0;if(x==b)return x;let _=(this.sweepx-n.x)/(l.x-n.x)*(l.y-n.y)+n.y,d=(this.sweepx-s.x)/(i.x-s.x)*(i.y-s.y)+s.y;return _>d}}}clear(){this.tree.clear()}add(e){e.node=this.tree.insert(e);let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);return t!=null&&(e.next=t.data,t.data.prev=e),n!=null&&(e.prev=n.data,n.data.next=e),e}remove(e){let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);t!=null&&(t.data.prev=e.prev),n!=null&&(n.data.next=e.next),this.tree.remove_node(e.node),e.node=null}intersect(e,t){if(e==null||t==null)return!1;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return!1;{let n=e.left,l=e.right,s=t.left,i=t.right,o=(s.x-n.x)*(l.y-n.y)-(l.x-n.x)*(s.y-n.y),r=(i.x-n.x)*(l.y-n.y)-(l.x-n.x)*(i.y-n.y);if(o*r>0)return!1;{let a=(n.x-s.x)*(i.y-s.y)-(i.x-s.x)*(n.y-s.y),p=(l.x-s.x)*(i.y-s.y)-(i.x-s.x)*(l.y-s.y);return!(a*p>0)}}}intersection(e,t){if(e==null||t==null)return null;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return null;{let n=e.left,l=e.right,s=t.left,i=t.right,o=l.x-n.x,r=l.y-n.y,a=i.x-s.x,p=i.y-s.y,c=p*o-a*r;if(c==0)return null;c=1/c;let u=s.x-n.x,h=s.y-n.y,x=(p*u-a*h)*c;if(x<0||x>1)return null;let b=(r*u-o*h)*c;if(b<0||b>1)return null;let _;if(b==0||b==1||x==0||x==1){let m=b==0;if(b==1&&m)throw new Error("corner case 1a");if(b==1&&(m=!0),x==0&&m)throw new Error("corner case 1b");if(x==0&&(m=!0),x==1&&m)throw new Error("corner case 1c");_=b==0?s:b==1?i:x==0?n:l}else{let m=.5*(n.x+o*x+s.x+a*b),z=.5*(n.y+r*x+s.y+p*b),Z;ke.zpp_pool==null?Z=new ke:(Z=ke.zpp_pool,ke.zpp_pool=Z.next,Z.next=null),Z.x=m,Z.y=z,_=Z}let d;Me.zpp_pool==null?d=new Me:(d=Me.zpp_pool,Me.zpp_pool=d.next,d.next=null),d.vertex=_;let f=d;return f.type=0,f.segment=e,f.segment2=t,f}}};ki.__name__=["zpp_nape","geom","ZPP_SimpleSweep"];var _e=class _e{static decompose(e,t){_e.sweep==null&&(_e.sweep=new ki,_e.inthash=new Yi),_e.vertices==null&&(en.zpp_pool==null?_e.vertices=new en:(_e.vertices=en.zpp_pool,en.zpp_pool=_e.vertices.next,_e.vertices.next=null),_e.vertices.lt=ke.less_xy,_e.vertices.swapped=ke.swap_nodes),_e.queue==null&&(Wn.zpp_pool==null?_e.queue=new Wn:(_e.queue=Wn.zpp_pool,Wn.zpp_pool=_e.queue.next,_e.queue.next=null),_e.queue.lt=Me.less_xy,_e.queue.swapped=Me.swap_nodes);let n=null,l=null,s=e,i=e;if(s!=null){let x=s;for(;;){let b=x,_=b.x,d=b.y,f;ke.zpp_pool==null?f=new ke:(f=ke.zpp_pool,ke.zpp_pool=f.next,f.next=null),f.x=_,f.y=d;let m=f,z=_e.vertices.parent;for(;z!=null;)if(_e.vertices.lt(m,z.data))z=z.prev;else if(_e.vertices.lt(z.data,m))z=z.next;else break;let Z=z;if(Z!=null){let y=m;y.links.clear(),y.node=null,y.forced=!1,y.next=ke.zpp_pool,ke.zpp_pool=y,m=Z.data}else m.node=_e.vertices.insert(m);if(l!=null){let y;Me.zpp_pool==null?y=new Me:(y=Me.zpp_pool,Me.zpp_pool=y.next,y.next=null),y.vertex=l;let w=y,v;Me.zpp_pool==null?v=new Me:(v=Me.zpp_pool,Me.zpp_pool=v.next,v.next=null),v.vertex=m;let P=v,g;Me.less_xy(w,P)?(w.type=1,P.type=2,g=Tt.get(l,m)):(w.type=2,P.type=1,g=Tt.get(m,l)),w.segment=P.segment=g,_e.queue.insert(w),_e.queue.insert(P),l.links.insert(m),m.links.insert(l)}if(l=m,n==null&&(n=m),x=x.next,x==i)break}}let o;Me.zpp_pool==null?o=new Me:(o=Me.zpp_pool,Me.zpp_pool=o.next,o.next=null),o.vertex=l;let r=o,a;Me.zpp_pool==null?a=new Me:(a=Me.zpp_pool,Me.zpp_pool=a.next,a.next=null),a.vertex=n;let p=a,c;for(Me.less_xy(r,p)?(r.type=1,p.type=2,c=Tt.get(l,n)):(r.type=2,p.type=1,c=Tt.get(n,l)),r.segment=p.segment=c,_e.queue.insert(r),_e.queue.insert(p),l.links.insert(n),n.links.insert(l),_e.ints==null&&(Wn.zpp_pool==null?_e.ints=new Wn:(_e.ints=Wn.zpp_pool,Wn.zpp_pool=_e.ints.next,_e.ints.next=null),_e.ints.lt=Me.less_xy);!_e.queue.empty();){let x=_e.queue.pop_front();if(_e.sweep.sweepx=x.vertex.x,x.type==1){let _=x.segment;if(_e.sweep.add(_),_.next!=null&&_!=null&&!(_.next.id<_.id?_e.inthash.has(_.next.id,_.id):_e.inthash.has(_.id,_.next.id))){let d=_e.sweep.intersection(_.next,_);if(d!=null)if(d.vertex.x>=_e.sweep.sweepx){let f=_e.queue.parent;for(;f!=null;)if(_e.queue.lt(d,f.data))f=f.prev;else if(_e.queue.lt(f.data,d))f=f.next;else break;let m=f;if(m==null){let z=_e.ints.parent;for(;z!=null;)if(_e.ints.lt(d,z.data))z=z.prev;else if(_e.ints.lt(z.data,d))z=z.next;else break;let Z=z;if(Z!=null){let y=d.vertex;y.links.clear(),y.node=null,y.forced=!1,y.next=ke.zpp_pool,ke.zpp_pool=y,d.vertex=Z.data.vertex,Z.data=d,_e.queue.insert(d)}else _e.queue.insert(d),_e.ints.insert(d);if(_.next.id<_.id){let y=_e.inthash,w=_.next.id,v=_.id,P;je.zpp_pool==null?P=new je:(P=je.zpp_pool,je.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}else{let y=_e.inthash,w=_.id,v=_.next.id,P;je.zpp_pool==null?P=new je:(P=je.zpp_pool,je.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}}else{let z=m.data;if(z.segment!=d.segment||d.segment2!=z.segment2)throw new Error("corner case 2, shiiiit.");let Z=d.vertex;Z.links.clear(),Z.node=null,Z.forced=!1,Z.next=ke.zpp_pool,ke.zpp_pool=Z;let y=d;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Me.zpp_pool,Me.zpp_pool=y}}else{let f=d.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f;let m=d;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Me.zpp_pool,Me.zpp_pool=m}}if(_!=null&&_.prev!=null&&!(_.id<_.prev.id?_e.inthash.has(_.id,_.prev.id):_e.inthash.has(_.prev.id,_.id))){let d=_e.sweep.intersection(_,_.prev);if(d!=null)if(d.vertex.x>=_e.sweep.sweepx){let f=_e.queue.parent;for(;f!=null;)if(_e.queue.lt(d,f.data))f=f.prev;else if(_e.queue.lt(f.data,d))f=f.next;else break;let m=f;if(m==null){let z=_e.ints.parent;for(;z!=null;)if(_e.ints.lt(d,z.data))z=z.prev;else if(_e.ints.lt(z.data,d))z=z.next;else break;let Z=z;if(Z!=null){let y=d.vertex;y.links.clear(),y.node=null,y.forced=!1,y.next=ke.zpp_pool,ke.zpp_pool=y,d.vertex=Z.data.vertex,Z.data=d,_e.queue.insert(d)}else _e.queue.insert(d),_e.ints.insert(d);if(_.id<_.prev.id){let y=_e.inthash,w=_.id,v=_.prev.id,P;je.zpp_pool==null?P=new je:(P=je.zpp_pool,je.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}else{let y=_e.inthash,w=_.prev.id,v=_.id,P;je.zpp_pool==null?P=new je:(P=je.zpp_pool,je.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}}else{let z=m.data;if(z.segment!=d.segment||d.segment2!=z.segment2)throw new Error("corner case 2, shiiiit.");let Z=d.vertex;Z.links.clear(),Z.node=null,Z.forced=!1,Z.next=ke.zpp_pool,ke.zpp_pool=Z;let y=d;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Me.zpp_pool,Me.zpp_pool=y}}else{let f=d.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f;let m=d;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Me.zpp_pool,Me.zpp_pool=m}}}else if(x.type==2){let _=x.segment;if(_.node!=null){let d=_.next,f=_.prev;_e.sweep.remove(_);let m=_;if(m.left=m.right=null,m.prev=null,m.node=null,m.vertices.clear(),m.next=Tt.zpp_pool,Tt.zpp_pool=m,d!=null&&f!=null&&!(d.id<f.id?_e.inthash.has(d.id,f.id):_e.inthash.has(f.id,d.id))){let z=_e.sweep.intersection(d,f);if(z!=null)if(z.vertex.x>=_e.sweep.sweepx){let Z=_e.queue.parent;for(;Z!=null;)if(_e.queue.lt(z,Z.data))Z=Z.prev;else if(_e.queue.lt(Z.data,z))Z=Z.next;else break;let y=Z;if(y==null){let w=_e.ints.parent;for(;w!=null;)if(_e.ints.lt(z,w.data))w=w.prev;else if(_e.ints.lt(w.data,z))w=w.next;else break;let v=w;if(v!=null){let P=z.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.zpp_pool=P,z.vertex=v.data.vertex,v.data=z,_e.queue.insert(z)}else _e.queue.insert(z),_e.ints.insert(z);if(d.id<f.id){let P=_e.inthash,g=d.id,k=f.id,N;je.zpp_pool==null?N=new je:(N=je.zpp_pool,je.zpp_pool=N.next,N.next=null),N.id=g,N.di=k;let E=N;E.value=!0,P.add(E)}else{let P=_e.inthash,g=f.id,k=d.id,N;je.zpp_pool==null?N=new je:(N=je.zpp_pool,je.zpp_pool=N.next,N.next=null),N.id=g,N.di=k;let E=N;E.value=!0,P.add(E)}}else{let w=y.data;if(w.segment!=z.segment||z.segment2!=w.segment2)throw new Error("corner case 2, shiiiit.");let v=z.vertex;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v;let P=z;P.vertex=null,P.segment=P.segment2=null,P.node=null,P.next=Me.zpp_pool,Me.zpp_pool=P}}else{let Z=z.vertex;Z.links.clear(),Z.node=null,Z.forced=!1,Z.next=ke.zpp_pool,ke.zpp_pool=Z;let y=z;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Me.zpp_pool,Me.zpp_pool=y}}}}else{let _=x.vertex,d=_.node==null,f=x.segment,m=x.segment2;if(m.next!=f){let v=f;f=m,m=v}let z=f.vertices.parent;for(;z!=null;)if(f.vertices.lt(_,z.data))z=z.prev;else if(f.vertices.lt(z.data,_))z=z.next;else break;let Z=z==null,y=m.vertices.parent;for(;y!=null;)if(m.vertices.lt(_,y.data))y=y.prev;else if(m.vertices.lt(y.data,_))y=y.next;else break;let w=y==null;if(Z){let v=f.vertices.insert(_),P=_==f.left?_:f.vertices.predecessor_node(v).data,g=_==f.right?_:f.vertices.successor_node(v).data;P.links.remove(g),_!=P&&P.links.insert(_),g.links.remove(P),_!=g&&g.links.insert(_),_!=P&&_.links.insert(P),_!=g&&_.links.insert(g)}if(w){let v=m.vertices.insert(_),P=_==m.left?_:m.vertices.predecessor_node(v).data,g=_==m.right?_:m.vertices.successor_node(v).data;P.links.remove(g),_!=P&&P.links.insert(_),g.links.remove(P),_!=g&&g.links.insert(_),_!=P&&_.links.insert(P),_!=g&&_.links.insert(g)}if(d&&(_.node=_e.vertices.insert(_)),_.forced=!0,d){let v=f.node,P=m.node;v.data=m,P.data=f,f.node=P,m.node=v,m.next=f.next,f.next=m,f.prev=m.prev,m.prev=f,f.prev!=null&&(f.prev.next=f),m.next!=null&&(m.next.prev=m)}if(m.next!=null&&m!=null&&!(m.next.id<m.id?_e.inthash.has(m.next.id,m.id):_e.inthash.has(m.id,m.next.id))){let v=_e.sweep.intersection(m.next,m);if(v!=null)if(v.vertex.x>=_e.sweep.sweepx){let P=_e.queue.parent;for(;P!=null;)if(_e.queue.lt(v,P.data))P=P.prev;else if(_e.queue.lt(P.data,v))P=P.next;else break;let g=P;if(g==null){let k=_e.ints.parent;for(;k!=null;)if(_e.ints.lt(v,k.data))k=k.prev;else if(_e.ints.lt(k.data,v))k=k.next;else break;let N=k;if(N!=null){let E=v.vertex;E.links.clear(),E.node=null,E.forced=!1,E.next=ke.zpp_pool,ke.zpp_pool=E,v.vertex=N.data.vertex,N.data=v,_e.queue.insert(v)}else _e.queue.insert(v),_e.ints.insert(v);if(m.next.id<m.id){let E=_e.inthash,M=m.next.id,C=m.id,D;je.zpp_pool==null?D=new je:(D=je.zpp_pool,je.zpp_pool=D.next,D.next=null),D.id=M,D.di=C;let O=D;O.value=!0,E.add(O)}else{let E=_e.inthash,M=m.id,C=m.next.id,D;je.zpp_pool==null?D=new je:(D=je.zpp_pool,je.zpp_pool=D.next,D.next=null),D.id=M,D.di=C;let O=D;O.value=!0,E.add(O)}}else{let k=g.data;if(k.segment!=v.segment||v.segment2!=k.segment2)throw new Error("corner case 2, shiiiit.");let N=v.vertex;N.links.clear(),N.node=null,N.forced=!1,N.next=ke.zpp_pool,ke.zpp_pool=N;let E=v;E.vertex=null,E.segment=E.segment2=null,E.node=null,E.next=Me.zpp_pool,Me.zpp_pool=E}}else{let P=v.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.zpp_pool=P;let g=v;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Me.zpp_pool,Me.zpp_pool=g}}if(f!=null&&f.prev!=null&&!(f.id<f.prev.id?_e.inthash.has(f.id,f.prev.id):_e.inthash.has(f.prev.id,f.id))){let v=_e.sweep.intersection(f,f.prev);if(v!=null)if(v.vertex.x>=_e.sweep.sweepx){let P=_e.queue.parent;for(;P!=null;)if(_e.queue.lt(v,P.data))P=P.prev;else if(_e.queue.lt(P.data,v))P=P.next;else break;let g=P;if(g==null){let k=_e.ints.parent;for(;k!=null;)if(_e.ints.lt(v,k.data))k=k.prev;else if(_e.ints.lt(k.data,v))k=k.next;else break;let N=k;if(N!=null){let E=v.vertex;E.links.clear(),E.node=null,E.forced=!1,E.next=ke.zpp_pool,ke.zpp_pool=E,v.vertex=N.data.vertex,N.data=v,_e.queue.insert(v)}else _e.queue.insert(v),_e.ints.insert(v);if(f.id<f.prev.id){let E=_e.inthash,M=f.id,C=f.prev.id,D;je.zpp_pool==null?D=new je:(D=je.zpp_pool,je.zpp_pool=D.next,D.next=null),D.id=M,D.di=C;let O=D;O.value=!0,E.add(O)}else{let E=_e.inthash,M=f.prev.id,C=f.id,D;je.zpp_pool==null?D=new je:(D=je.zpp_pool,je.zpp_pool=D.next,D.next=null),D.id=M,D.di=C;let O=D;O.value=!0,E.add(O)}}else{let k=g.data;if(k.segment!=v.segment||v.segment2!=k.segment2)throw new Error("corner case 2, shiiiit.");let N=v.vertex;N.links.clear(),N.node=null,N.forced=!1,N.next=ke.zpp_pool,ke.zpp_pool=N;let E=v;E.vertex=null,E.segment=E.segment2=null,E.node=null,E.next=Me.zpp_pool,Me.zpp_pool=E}}else{let P=v.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.zpp_pool=P;let g=v;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Me.zpp_pool,Me.zpp_pool=g}}_e.ints.remove(x)}let b=x;b.vertex=null,b.segment=b.segment2=null,b.node=null,b.next=Me.zpp_pool,Me.zpp_pool=b}let u=0,h=_e.inthash.table.length;for(;u<h;){let x=u++,b=_e.inthash.table[x];if(b!=null){for(;b!=null;){let _=b.hnext;b.hnext=null;let d=b;d.next=je.zpp_pool,je.zpp_pool=d,b=_}_e.inthash.table[x]=null}}for(t==null&&(t=new ds);!_e.vertices.empty();)_e.clip_polygon(_e.vertices,t);return t}static clip_polygon(e,t){let n=null,l=e.first(),s=l,i=l.links.parent,o=i.prev==null?i.next:i.prev,r=i.data,a=o.data,p=l.x-r.x,c=l.y-r.y,u=a.x-l.x;(a.y-l.y)*p-u*c<0&&(a=r);let x=l.x,b=l.y,_;ge.zpp_pool==null?_=new ge:(_=ge.zpp_pool,ge.zpp_pool=_.next,_.next=null),_.forced=!1,_.x=x,_.y=b;let d=_;if(n==null)d.prev=d.next=d;else{let m=n,z=m.next;d.prev=m,d.next=z,z.prev=d,m.next=d}for(n=d,n.forced=l.forced;;){if(l.links.remove(a),a.links.remove(l),a==s){if(l.links.empty()){e.remove(l);let w=l;w.links.clear(),w.node=null,w.forced=!1,w.next=ke.zpp_pool,ke.zpp_pool=w}break}let m=a.x,z=a.y,Z;ge.zpp_pool==null?Z=new ge:(Z=ge.zpp_pool,ge.zpp_pool=Z.next,Z.next=null),Z.forced=!1,Z.x=m,Z.y=z;let y=Z;if(n==null)y.prev=y.next=y;else{let w=n,v=w.next;y.prev=w,y.next=v,v.prev=y,w.next=y}if(n=y,n.forced=a.forced,a.links.singular()){if(l.links.empty()){e.remove(l);let w=l;w.links.clear(),w.node=null,w.forced=!1,w.next=ke.zpp_pool,ke.zpp_pool=w}l=a,a=a.links.parent.data}else{let w=null,v=0;if(!a.links.empty()){let P=a.links.parent;for(;P.prev!=null;)P=P.prev;for(;P!=null;){let g=P.data;if(w==null){w=g;let k=a.x-l.x,N=a.y-l.y,E=g.x-a.x;v=(g.y-a.y)*k-E*N}else{let k=a.x-l.x,N=a.y-l.y,E=g.x-a.x,C=(g.y-a.y)*k-E*N;if(C>0&&v<=0)w=g,v=C;else if(v*C>=0){let D=a.x-g.x,O=a.y-g.y,j=w.x-a.x;(w.y-a.y)*D-j*O>0&&(w=g,v=C)}}if(P.next!=null)for(P=P.next;P.prev!=null;)P=P.prev;else{for(;P.parent!=null&&P==P.parent.next;)P=P.parent;P=P.parent}}}if(l.links.empty()){e.remove(l);let P=l;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.zpp_pool=P}l=a,a=w}}e.remove(s);let f=s;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f,t.add(n)}static isSimple(e){_e.sweep==null&&(_e.sweep=new ki,_e.inthash=new Yi);let t=_e.list_vertices;t==null&&(t=_e.list_vertices=new Ul);let n=e,l=e;if(n!=null){let _=n;for(;;){let d=_,f=d.x,m=d.y,z;if(ke.zpp_pool==null?z=new ke:(z=ke.zpp_pool,ke.zpp_pool=z.next,z.next=null),z.x=f,z.y=m,t.add(z),_=_.next,_==l)break}}let s=_e.list_queue;s==null&&(s=_e.list_queue=new Wl);let i=t.head,o=i.elt;for(i=i.next;i!=null;){let _=i.elt,d;Me.zpp_pool==null?d=new Me:(d=Me.zpp_pool,Me.zpp_pool=d.next,d.next=null),d.vertex=o;let f=s.add(d),m;Me.zpp_pool==null?m=new Me:(m=Me.zpp_pool,Me.zpp_pool=m.next,m.next=null),m.vertex=_;let z=s.add(m),Z;Me.less_xy(f,z)?(f.type=1,z.type=2,Z=Tt.get(o,_)):(f.type=2,z.type=1,Z=Tt.get(_,o)),f.segment=z.segment=Z,o=_,i=i.next}let r=t.head.elt,a;Me.zpp_pool==null?a=new Me:(a=Me.zpp_pool,Me.zpp_pool=a.next,a.next=null),a.vertex=o;let p=s.add(a),c;Me.zpp_pool==null?c=new Me:(c=Me.zpp_pool,Me.zpp_pool=c.next,c.next=null),c.vertex=r;let u=s.add(c),h;Me.less_xy(p,u)?(p.type=1,u.type=2,h=Tt.get(o,r)):(p.type=2,u.type=1,h=Tt.get(r,o)),p.segment=u.segment=h;let x=s;if(x.head!=null&&x.head.next!=null){let _=x.head,d,f,m,z,Z=1,y,w,v;for(;;){for(y=0,f=_,_=null,d=null;f!=null;){for(++y,m=f,w=0,v=Z;m!=null&&w<Z;)++w,m=m.next;for(;w>0||v>0&&m!=null;)w==0?(z=m,m=m.next,--v):v==0||m==null||Me.less_xy(f.elt,m.elt)?(z=f,f=f.next,--w):(z=m,m=m.next,--v),d!=null?d.next=z:_=z,d=z;f=m}if(d.next=null,Z<<=1,!(y>1))break}x.head=_,x.modified=!0,x.pushmod=!0}let b=!0;for(;s.head!=null;){let _=s.pop_unsafe(),d=_.segment;if(_.type==1){if(_e.sweep.add(d),_e.sweep.intersect(d,d.next)||_e.sweep.intersect(d,d.prev)){b=!1;break}}else if(_.type==2){if(_e.sweep.intersect(d.prev,d.next)){b=!1;break}_e.sweep.remove(d);let m=d;m.left=m.right=null,m.prev=null,m.node=null,m.vertices.clear(),m.next=Tt.zpp_pool,Tt.zpp_pool=m}let f=_;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Me.zpp_pool,Me.zpp_pool=f}for(;s.head!=null;){let _=s.pop_unsafe();if(_.type==2){let f=_.segment;f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=Tt.zpp_pool,Tt.zpp_pool=f}let d=_;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Me.zpp_pool,Me.zpp_pool=d}for(_e.sweep.clear();t.head!=null;){let _=t.pop_unsafe();_.links.clear(),_.node=null,_.forced=!1,_.next=ke.zpp_pool,ke.zpp_pool=_}return b}};_e.__name__=["zpp_nape","geom","ZPP_Simple"],_e.sweep=null,_e.inthash=null,_e.vertices=null,_e.queue=null,_e.ints=null,_e.list_vertices=null,_e.list_queue=null;var Nl=_e;var Ei=class Ei{constructor(){this.x=0;this.y=0;this.next=null;this.prev=null;this.flag=!1;this.forced=!1}static get(e){let t;return Ei.zpp_pool==null?t=new Ei:(t=Ei.zpp_pool,Ei.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t.flag=!1,t}free(){}alloc(){}};Ei.__name__=["zpp_nape","geom","ZPP_SimplifyV"],Ei.zpp_pool=null;var Zn=Ei;var Ni=class Ni{constructor(){this.next=null;this.min=null;this.max=null}static get(e,t){let n;return Ni.zpp_pool==null?n=new Ni:(n=Ni.zpp_pool,Ni.zpp_pool=n.next,n.next=null),n.min=e,n.max=t,n}free(){this.min=null,this.max=null}alloc(){}};Ni.__name__=["zpp_nape","geom","ZPP_SimplifyP"],Ni.zpp_pool=null;var Be=Ni;var Ot=class Ot{static lessval(e,t){return e.x-t.x+(e.y-t.y)}static less(e,t){return e.x-t.x+(e.y-t.y)<0}static distance(e,t,n){let l=n.x-t.x,s=n.y-t.y,i=e.x-t.x,o=e.y-t.y;if(l*l+s*s==0)return i*i+o*o;{let a=(i*l+o*s)/(l*l+s*s);if(a<=0)return i*i+o*o;if(a>=1){let p=e.x-n.x,c=e.y-n.y;return p*p+c*c}else{let p=a;return i-=l*p,o-=s*p,i*i+o*o}}}static simplify(e,t){let n=null,l=null,s=null;t*=t,Ot.stack==null&&(Ot.stack=new Jl);let i=null,o=null,r=e;for(;;){let p;Zn.zpp_pool==null?p=new Zn:(p=Zn.zpp_pool,Zn.zpp_pool=p.next,p.next=null),p.x=r.x,p.y=r.y,p.flag=!1;let c=p;if(c.forced=r.forced,c.forced){if(c.flag=!0,i!=null){let h=Ot.stack,x;Be.zpp_pool==null?x=new Be:(x=Be.zpp_pool,Be.zpp_pool=x.next,x.next=null),x.min=i,x.max=c,h.add(x)}else o=c;i=c}let u=c;if(n==null?u.prev=u.next=u:(u.prev=n,u.next=n.next,n.next.prev=u,n.next=u),n=u,l==null?(l=n,s=n):(n.x-l.x+(n.y-l.y)<0&&(l=n),s.x-n.x+(s.y-n.y)<0&&(s=n)),r=r.next,r==e)break}if(Ot.stack.head==null)if(o==null){l.flag=s.flag=!0;let p=Ot.stack,c;Be.zpp_pool==null?c=new Be:(c=Be.zpp_pool,Be.zpp_pool=c.next,c.next=null),c.min=l,c.max=s,p.add(c);let u=Ot.stack,h;Be.zpp_pool==null?h=new Be:(h=Be.zpp_pool,Be.zpp_pool=h.next,h.next=null),h.min=s,h.max=l,u.add(h)}else{let p=l.x-o.x+(l.y-o.y);p<0&&(p=-p);let c=s.x-o.x+(s.y-o.y);if(c<0&&(c=-c),p>c){l.flag=o.flag=!0;let u=Ot.stack,h;Be.zpp_pool==null?h=new Be:(h=Be.zpp_pool,Be.zpp_pool=h.next,h.next=null),h.min=l,h.max=o,u.add(h);let x=Ot.stack,b;Be.zpp_pool==null?b=new Be:(b=Be.zpp_pool,Be.zpp_pool=b.next,b.next=null),b.min=o,b.max=l,x.add(b)}else{s.flag=o.flag=!0;let u=Ot.stack,h;Be.zpp_pool==null?h=new Be:(h=Be.zpp_pool,Be.zpp_pool=h.next,h.next=null),h.min=s,h.max=o,u.add(h);let x=Ot.stack,b;Be.zpp_pool==null?b=new Be:(b=Be.zpp_pool,Be.zpp_pool=b.next,b.next=null),b.min=o,b.max=s,x.add(b)}}else{let p=Ot.stack,c;Be.zpp_pool==null?c=new Be:(c=Be.zpp_pool,Be.zpp_pool=c.next,c.next=null),c.min=i,c.max=o,p.add(c)}for(;Ot.stack.head!=null;){let p=Ot.stack.pop_unsafe(),c=p.min,u=p.max,h=p;h.min=h.max=null,h.next=Be.zpp_pool,Be.zpp_pool=h;let x=t,b=null,_=c.next;for(;_!=u;){let d=Ot.distance(_,c,u);d>x&&(x=d,b=_),_=_.next}if(b!=null){b.flag=!0;let d=Ot.stack,f;Be.zpp_pool==null?f=new Be:(f=Be.zpp_pool,Be.zpp_pool=f.next,f.next=null),f.min=c,f.max=b,d.add(f);let m=Ot.stack,z;Be.zpp_pool==null?z=new Be:(z=Be.zpp_pool,Be.zpp_pool=z.next,z.next=null),z.min=b,z.max=u,m.add(z)}}let a=null;for(;n!=null;){if(n.flag){let p=n.x,c=n.y,u;ge.zpp_pool==null?u=new ge:(u=ge.zpp_pool,ge.zpp_pool=u.next,u.next=null),u.forced=!1,u.x=p,u.y=c;let h=u;a==null?h.prev=h.next=h:(h.prev=a,h.next=a.next,a.next.prev=h,a.next=h),a=h,a.forced=n.forced}if(n!=null&&n.prev==n)n.next=n.prev=null,n.next=Zn.zpp_pool,Zn.zpp_pool=n,n=null;else{let p=n.next;n.prev.next=n.next,n.next.prev=n.prev,n.next=n.prev=null,n.next=Zn.zpp_pool,Zn.zpp_pool=n,n=p}}return a}};Ot.__name__=["zpp_nape","geom","ZPP_Simplify"],Ot.stack=null;var Ol=Ot;var Cs=class{constructor(){this.next=null;this.toi=0;this.s1=null;this.s2=null;this.arbiter=null;this.frozen1=!1;this.frozen2=!1;this.slipped=!1;this.failed=!1;this.kinematic=!1;this.c1=new le,this.c2=new le,this.axis=new le}alloc(){this.failed=!1,this.s1=this.s2=null,this.arbiter=null}free(){}};Cs.__name__=["zpp_nape","geom","ZPP_ToiEvent"],Cs.zpp_pool=null;var Pn=class{static dynamicSweep(e,t,n,l,s){let i=me();s==null&&(s=!1);let o=e.s1,r=e.s2,a=o.body,p=r.body,c=0,u=0;c=p.velx-a.velx,u=p.vely-a.vely;let h=a.angvel;h<0&&(h=-h);let x=p.angvel;x<0&&(x=-x);let b=o.sweepCoef*h+r.sweepCoef*x;if(!s&&!e.kinematic&&c*c+u*u<i.Config.dynamicSweepLinearThreshold*i.Config.dynamicSweepLinearThreshold&&b<i.Config.dynamicSweepAngularThreshold){e.toi=-1,e.failed=!0;return}let _=e.c1,d=e.c2,f=e.axis,m=n,z=0;for(;;){let C=m*t,D=C-a.sweepTime;if(D!=0){a.sweepTime=C;let Y=D;if(a.posx+=a.velx*Y,a.posy+=a.vely*Y,a.angvel!=0){let X=a.sweep_angvel*D;if(a.rot+=X,X*X>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let ee=X*X,G=1-.5*ee,F=1-ee*ee/8,T=(G*a.axisx+X*a.axisy)*F;a.axisy=(G*a.axisy-X*a.axisx)*F,a.axisx=T}}}if(o.type==0)o.worldCOMx=a.posx+(a.axisy*o.localCOMx-a.axisx*o.localCOMy),o.worldCOMy=a.posy+(o.localCOMx*a.axisx+o.localCOMy*a.axisy);else{let Y=o.polygon,X=Y.lverts.next,ee=Y.gverts.next;for(;ee!=null;){let H=ee,K=X;X=X.next,H.x=a.posx+(a.axisy*K.x-a.axisx*K.y),H.y=a.posy+(K.x*a.axisx+K.y*a.axisy),ee=ee.next}let G=Y.edges.head,F=Y.gverts.next,T=F;for(F=F.next;F!=null;){let H=F,K=G.elt;G=G.next,K.gnormx=a.axisy*K.lnormx-a.axisx*K.lnormy,K.gnormy=K.lnormx*a.axisx+K.lnormy*a.axisy,K.gprojection=a.posx*K.gnormx+a.posy*K.gnormy+K.lprojection,K.tp0=T.y*K.gnormx-T.x*K.gnormy,K.tp1=H.y*K.gnormx-H.x*K.gnormy,T=H,F=F.next}let A=Y.gverts.next,W=G.elt;G=G.next,W.gnormx=a.axisy*W.lnormx-a.axisx*W.lnormy,W.gnormy=W.lnormx*a.axisx+W.lnormy*a.axisy,W.gprojection=a.posx*W.gnormx+a.posy*W.gnormy+W.lprojection,W.tp0=T.y*W.gnormx-T.x*W.gnormy,W.tp1=A.y*W.gnormx-A.x*W.gnormy}let O=m*t,j=O-p.sweepTime;if(j!=0){p.sweepTime=O;let Y=j;if(p.posx+=p.velx*Y,p.posy+=p.vely*Y,p.angvel!=0){let X=p.sweep_angvel*j;if(p.rot+=X,X*X>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let ee=X*X,G=1-.5*ee,F=1-ee*ee/8,T=(G*p.axisx+X*p.axisy)*F;p.axisy=(G*p.axisy-X*p.axisx)*F,p.axisx=T}}}if(r.type==0)r.worldCOMx=p.posx+(p.axisy*r.localCOMx-p.axisx*r.localCOMy),r.worldCOMy=p.posy+(r.localCOMx*p.axisx+r.localCOMy*p.axisy);else{let Y=r.polygon,X=Y.lverts.next,ee=Y.gverts.next;for(;ee!=null;){let H=ee,K=X;X=X.next,H.x=p.posx+(p.axisy*K.x-p.axisx*K.y),H.y=p.posy+(K.x*p.axisx+K.y*p.axisy),ee=ee.next}let G=Y.edges.head,F=Y.gverts.next,T=F;for(F=F.next;F!=null;){let H=F,K=G.elt;G=G.next,K.gnormx=p.axisy*K.lnormx-p.axisx*K.lnormy,K.gnormy=K.lnormx*p.axisx+K.lnormy*p.axisy,K.gprojection=p.posx*K.gnormx+p.posy*K.gnormy+K.lprojection,K.tp0=T.y*K.gnormx-T.x*K.gnormy,K.tp1=H.y*K.gnormx-H.x*K.gnormy,T=H,F=F.next}let A=Y.gverts.next,W=G.elt;G=G.next,W.gnormx=p.axisy*W.lnormx-p.axisx*W.lnormy,W.gnormy=W.lnormx*p.axisx+W.lnormy*p.axisy,W.gprojection=p.posx*W.gnormx+p.posy*W.gnormy+W.lprojection,W.tp0=T.y*W.gnormx-T.x*W.gnormy,W.tp1=A.y*W.gnormx-A.x*W.gnormy}let L=o,U=r,q=_,R=d;var Z;if(L.type==0&&U.type==0){let Y=L.circle,X=U.circle;var y;let ee=0,G=0;ee=X.worldCOMx-Y.worldCOMx,G=X.worldCOMy-Y.worldCOMy;let F=Math.sqrt(ee*ee+G*G);if(y=F-(Y.radius+X.radius),y<1e100){if(F==0)ee=1,G=0;else{let W=1/F;ee*=W,G*=W}let T=Y.radius;q.x=Y.worldCOMx+ee*T,q.y=Y.worldCOMy+G*T;let A=-X.radius;R.x=X.worldCOMx+ee*A,R.y=X.worldCOMy+G*A,f.x=ee,f.y=G}Z=y}else{let Y=!1;if(L.type==0&&U.type==1){let X=L;L=U,U=X;let ee=q;q=R,R=ee,Y=!0}if(L.type==1&&U.type==0){let X=L.polygon,ee=U.circle,G=-1e100,F=null,T=X.edges.head;for(;T!=null;){let A=T.elt,W=A.gnormx*ee.worldCOMx+A.gnormy*ee.worldCOMy-A.gprojection-ee.radius;if(W>1e100){G=W;break}W>0?W>G&&(G=W,F=A):G<0&&W>G&&(G=W,F=A),T=T.next}if(G<1e100){let A=F.gp0,W=F.gp1,H=ee.worldCOMy*F.gnormx-ee.worldCOMx*F.gnormy;if(H<=A.y*F.gnormx-A.x*F.gnormy){let K=0,ne=0;K=ee.worldCOMx-A.x,ne=ee.worldCOMy-A.y;let re=Math.sqrt(K*K+ne*ne);if(G=re-ee.radius,G<1e100){if(re==0)K=1,ne=0;else{let oe=1/re;K*=oe,ne*=oe}let se=0;q.x=A.x+K*se,q.y=A.y+ne*se;let ie=-ee.radius;R.x=ee.worldCOMx+K*ie,R.y=ee.worldCOMy+ne*ie,f.x=K,f.y=ne}}else if(H>=W.y*F.gnormx-W.x*F.gnormy){let K=0,ne=0;K=ee.worldCOMx-W.x,ne=ee.worldCOMy-W.y;let re=Math.sqrt(K*K+ne*ne);if(G=re-ee.radius,G<1e100){if(re==0)K=1,ne=0;else{let oe=1/re;K*=oe,ne*=oe}let se=0;q.x=W.x+K*se,q.y=W.y+ne*se;let ie=-ee.radius;R.x=ee.worldCOMx+K*ie,R.y=ee.worldCOMy+ne*ie,f.x=K,f.y=ne}}else{let K=-ee.radius;R.x=ee.worldCOMx+F.gnormx*K,R.y=ee.worldCOMy+F.gnormy*K;let ne=-G;q.x=R.x+F.gnormx*ne,q.y=R.y+F.gnormy*ne,f.x=F.gnormx,f.y=F.gnormy}}Y&&(f.x=-f.x,f.y=-f.y),Z=G}else{let X=L.polygon,ee=U.polygon,G=-1e100,F=null,T=null,A=0,W=X.edges.head;for(;W!=null;){let H=W.elt,K=1e100,ne=ee.gverts.next;for(;ne!=null;){let re=ne,se=H.gnormx*re.x+H.gnormy*re.y;se<K&&(K=se),ne=ne.next}if(K-=H.gprojection,K>1e100){G=K;break}K>0?K>G&&(G=K,F=H,A=1):G<0&&K>G&&(G=K,F=H,A=1),W=W.next}if(G<1e100){let H=ee.edges.head;for(;H!=null;){let K=H.elt,ne=1e100,re=X.gverts.next;for(;re!=null;){let se=re,ie=K.gnormx*se.x+K.gnormy*se.y;ie<ne&&(ne=ie),re=re.next}if(ne-=K.gprojection,ne>1e100){G=ne;break}ne>0?ne>G&&(G=ne,T=K,A=2):G<0&&ne>G&&(G=ne,T=K,A=2),H=H.next}if(G<1e100){var w,v,P;if(A==1)w=X,v=ee,P=F;else{w=ee,v=X,P=T;let se=q;q=R,R=se,Y=!Y}let K=null,ne=1e100,re=v.edges.head;for(;re!=null;){let se=re.elt,ie=P.gnormx*se.gnormx+P.gnormy*se.gnormy;ie<ne&&(ne=ie,K=se),re=re.next}if(Y?(f.x=-P.gnormx,f.y=-P.gnormy):(f.x=P.gnormx,f.y=P.gnormy),G>=0){let se=P.gp0,ie=P.gp1,oe=K.gp0,ce=K.gp1,pe=0,ae=0,xe=0,te=0;pe=ie.x-se.x,ae=ie.y-se.y,xe=ce.x-oe.x,te=ce.y-oe.y;let he=1/(pe*pe+ae*ae),ye=1/(xe*xe+te*te),ue=-(pe*(se.x-oe.x)+ae*(se.y-oe.y))*he,Pe=-(pe*(se.x-ce.x)+ae*(se.y-ce.y))*he,Se=-(xe*(oe.x-se.x)+te*(oe.y-se.y))*ye,Te=-(xe*(oe.x-ie.x)+te*(oe.y-ie.y))*ye;ue<0?ue=0:ue>1&&(ue=1),Pe<0?Pe=0:Pe>1&&(Pe=1),Se<0?Se=0:Se>1&&(Se=1),Te<0?Te=0:Te>1&&(Te=1);let We=0,Ye=0,Xe=ue;We=se.x+pe*Xe,Ye=se.y+ae*Xe;let Fe=0,Pt=0,kt=Pe;Fe=se.x+pe*kt,Pt=se.y+ae*kt;let ct=0,ht=0,pt=Se;ct=oe.x+xe*pt,ht=oe.y+te*pt;let Ke=0,wt=0,Ft=Te;Ke=oe.x+xe*Ft,wt=oe.y+te*Ft;let Ut=0,Vt=0;Ut=We-oe.x,Vt=Ye-oe.y;let It=Ut*Ut+Vt*Vt,wn=0,Xt=0;wn=Fe-ce.x,Xt=Pt-ce.y;let yn=wn*wn+Xt*Xt,pn=0,mn=0;pn=ct-se.x,mn=ht-se.y;let Ht=pn*pn+mn*mn,vn=0,Qt=0;vn=Ke-ie.x,Qt=wt-ie.y;let bn=vn*vn+Qt*Qt,Wt=0,$t=0,cn=null;It<yn?(Wt=We,$t=Ye,cn=oe):(Wt=Fe,$t=Pt,cn=ce,It=yn);let ti=0,Ln=0,In=null;if(Ht<bn?(ti=ct,Ln=ht,In=se):(ti=Ke,Ln=wt,In=ie,Ht=bn),It<Ht?(q.x=Wt,q.y=$t,R.x=cn.x,R.y=cn.y,G=Math.sqrt(It)):(R.x=ti,R.y=Ln,q.x=In.x,q.y=In.y,G=Math.sqrt(Ht)),G!=0){f.x=R.x-q.x,f.y=R.y-q.y;let jn=1/G;f.x*=jn,f.y*=jn,Y&&(f.x=-f.x,f.y=-f.y)}Z=G}else{let se=0,ie=0;se=K.gp0.x,ie=K.gp0.y;let oe=0,ce=0;oe=K.gp1.x,ce=K.gp1.y;let pe=0,ae=0;pe=oe-se,ae=ce-ie;let xe=P.gnormy*se-P.gnormx*ie,te=P.gnormy*oe-P.gnormx*ce,he=1/(te-xe),ye=(-P.tp1-xe)*he;if(ye>i.Config.epsilon){let Te=ye;se+=pe*Te,ie+=ae*Te}let ue=(-P.tp0-te)*he;if(ue<-i.Config.epsilon){let Te=ue;oe+=pe*Te,ce+=ae*Te}let Pe=se*P.gnormx+ie*P.gnormy-P.gprojection,Se=oe*P.gnormx+ce*P.gnormy-P.gprojection;if(Pe<Se){R.x=se,R.y=ie;let Te=-Pe;q.x=R.x+P.gnormx*Te,q.y=R.y+P.gnormy*Te,Z=Pe}else{R.x=oe,R.y=ce;let Te=-Se;q.x=R.x+P.gnormx*Te,q.y=R.y+P.gnormy*Te,Z=Se}}}else Z=1e100}else Z=1e100}}let B=Z+l,S=c*f.x+u*f.y;if(B<i.Config.distanceThresholdCCD){if(s)break;let Y=0,X=0;Y=_.x-a.posx,X=_.y-a.posy;let ee=0,G=0;ee=d.x-p.posx,G=d.y-p.posy;let F=S-a.sweep_angvel*(f.y*Y-f.x*X)+p.sweep_angvel*(f.y*ee-f.x*G);if(F>0&&(e.slipped=!0),F<=0||B<i.Config.distanceThresholdCCD*.5)break}let J=(b-S)*t;if(J<=0){m=-1;break}let Q=B/J;if(Q<1e-6&&(Q=1e-6),m+=Q,m>=1){m=1;let Y=m*t,X=Y-a.sweepTime;if(X!=0){a.sweepTime=Y;let ne=X;if(a.posx+=a.velx*ne,a.posy+=a.vely*ne,a.angvel!=0){let re=a.sweep_angvel*X;if(a.rot+=re,re*re>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let se=re*re,ie=1-.5*se,oe=1-se*se/8,ce=(ie*a.axisx+re*a.axisy)*oe;a.axisy=(ie*a.axisy-re*a.axisx)*oe,a.axisx=ce}}}if(o.type==0)o.worldCOMx=a.posx+(a.axisy*o.localCOMx-a.axisx*o.localCOMy),o.worldCOMy=a.posy+(o.localCOMx*a.axisx+o.localCOMy*a.axisy);else{let ne=o.polygon,re=ne.lverts.next,se=ne.gverts.next;for(;se!=null;){let xe=se,te=re;re=re.next,xe.x=a.posx+(a.axisy*te.x-a.axisx*te.y),xe.y=a.posy+(te.x*a.axisx+te.y*a.axisy),se=se.next}let ie=ne.edges.head,oe=ne.gverts.next,ce=oe;for(oe=oe.next;oe!=null;){let xe=oe,te=ie.elt;ie=ie.next,te.gnormx=a.axisy*te.lnormx-a.axisx*te.lnormy,te.gnormy=te.lnormx*a.axisx+te.lnormy*a.axisy,te.gprojection=a.posx*te.gnormx+a.posy*te.gnormy+te.lprojection,te.tp0=ce.y*te.gnormx-ce.x*te.gnormy,te.tp1=xe.y*te.gnormx-xe.x*te.gnormy,ce=xe,oe=oe.next}let pe=ne.gverts.next,ae=ie.elt;ie=ie.next,ae.gnormx=a.axisy*ae.lnormx-a.axisx*ae.lnormy,ae.gnormy=ae.lnormx*a.axisx+ae.lnormy*a.axisy,ae.gprojection=a.posx*ae.gnormx+a.posy*ae.gnormy+ae.lprojection,ae.tp0=ce.y*ae.gnormx-ce.x*ae.gnormy,ae.tp1=pe.y*ae.gnormx-pe.x*ae.gnormy}let ee=m*t,G=ee-p.sweepTime;if(G!=0){p.sweepTime=ee;let ne=G;if(p.posx+=p.velx*ne,p.posy+=p.vely*ne,p.angvel!=0){let re=p.sweep_angvel*G;if(p.rot+=re,re*re>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let se=re*re,ie=1-.5*se,oe=1-se*se/8,ce=(ie*p.axisx+re*p.axisy)*oe;p.axisy=(ie*p.axisy-re*p.axisx)*oe,p.axisx=ce}}}if(r.type==0)r.worldCOMx=p.posx+(p.axisy*r.localCOMx-p.axisx*r.localCOMy),r.worldCOMy=p.posy+(r.localCOMx*p.axisx+r.localCOMy*p.axisy);else{let ne=r.polygon,re=ne.lverts.next,se=ne.gverts.next;for(;se!=null;){let xe=se,te=re;re=re.next,xe.x=p.posx+(p.axisy*te.x-p.axisx*te.y),xe.y=p.posy+(te.x*p.axisx+te.y*p.axisy),se=se.next}let ie=ne.edges.head,oe=ne.gverts.next,ce=oe;for(oe=oe.next;oe!=null;){let xe=oe,te=ie.elt;ie=ie.next,te.gnormx=p.axisy*te.lnormx-p.axisx*te.lnormy,te.gnormy=te.lnormx*p.axisx+te.lnormy*p.axisy,te.gprojection=p.posx*te.gnormx+p.posy*te.gnormy+te.lprojection,te.tp0=ce.y*te.gnormx-ce.x*te.gnormy,te.tp1=xe.y*te.gnormx-xe.x*te.gnormy,ce=xe,oe=oe.next}let pe=ne.gverts.next,ae=ie.elt;ie=ie.next,ae.gnormx=p.axisy*ae.lnormx-p.axisx*ae.lnormy,ae.gnormy=ae.lnormx*p.axisx+ae.lnormy*p.axisy,ae.gprojection=p.posx*ae.gnormx+p.posy*ae.gnormy+ae.lprojection,ae.tp0=ce.y*ae.gnormx-ce.x*ae.gnormy,ae.tp1=pe.y*ae.gnormx-pe.x*ae.gnormy}let F=o,T=r,A=_,W=d;var g;if(F.type==0&&T.type==0){let ne=F.circle,re=T.circle;var k;let se=0,ie=0;se=re.worldCOMx-ne.worldCOMx,ie=re.worldCOMy-ne.worldCOMy;let oe=Math.sqrt(se*se+ie*ie);if(k=oe-(ne.radius+re.radius),k<1e100){if(oe==0)se=1,ie=0;else{let ae=1/oe;se*=ae,ie*=ae}let ce=ne.radius;A.x=ne.worldCOMx+se*ce,A.y=ne.worldCOMy+ie*ce;let pe=-re.radius;W.x=re.worldCOMx+se*pe,W.y=re.worldCOMy+ie*pe,f.x=se,f.y=ie}g=k}else{let ne=!1;if(F.type==0&&T.type==1){let re=F;F=T,T=re;let se=A;A=W,W=se,ne=!0}if(F.type==1&&T.type==0){let re=F.polygon,se=T.circle,ie=-1e100,oe=null,ce=re.edges.head;for(;ce!=null;){let pe=ce.elt,ae=pe.gnormx*se.worldCOMx+pe.gnormy*se.worldCOMy-pe.gprojection-se.radius;if(ae>1e100){ie=ae;break}ae>0?ae>ie&&(ie=ae,oe=pe):ie<0&&ae>ie&&(ie=ae,oe=pe),ce=ce.next}if(ie<1e100){let pe=oe.gp0,ae=oe.gp1,xe=se.worldCOMy*oe.gnormx-se.worldCOMx*oe.gnormy;if(xe<=pe.y*oe.gnormx-pe.x*oe.gnormy){let te=0,he=0;te=se.worldCOMx-pe.x,he=se.worldCOMy-pe.y;let ye=Math.sqrt(te*te+he*he);if(ie=ye-se.radius,ie<1e100){if(ye==0)te=1,he=0;else{let Se=1/ye;te*=Se,he*=Se}let ue=0;A.x=pe.x+te*ue,A.y=pe.y+he*ue;let Pe=-se.radius;W.x=se.worldCOMx+te*Pe,W.y=se.worldCOMy+he*Pe,f.x=te,f.y=he}}else if(xe>=ae.y*oe.gnormx-ae.x*oe.gnormy){let te=0,he=0;te=se.worldCOMx-ae.x,he=se.worldCOMy-ae.y;let ye=Math.sqrt(te*te+he*he);if(ie=ye-se.radius,ie<1e100){if(ye==0)te=1,he=0;else{let Se=1/ye;te*=Se,he*=Se}let ue=0;A.x=ae.x+te*ue,A.y=ae.y+he*ue;let Pe=-se.radius;W.x=se.worldCOMx+te*Pe,W.y=se.worldCOMy+he*Pe,f.x=te,f.y=he}}else{let te=-se.radius;W.x=se.worldCOMx+oe.gnormx*te,W.y=se.worldCOMy+oe.gnormy*te;let he=-ie;A.x=W.x+oe.gnormx*he,A.y=W.y+oe.gnormy*he,f.x=oe.gnormx,f.y=oe.gnormy}}ne&&(f.x=-f.x,f.y=-f.y),g=ie}else{let re=F.polygon,se=T.polygon,ie=-1e100,oe=null,ce=null,pe=0,ae=re.edges.head;for(;ae!=null;){let xe=ae.elt,te=1e100,he=se.gverts.next;for(;he!=null;){let ye=he,ue=xe.gnormx*ye.x+xe.gnormy*ye.y;ue<te&&(te=ue),he=he.next}if(te-=xe.gprojection,te>1e100){ie=te;break}te>0?te>ie&&(ie=te,oe=xe,pe=1):ie<0&&te>ie&&(ie=te,oe=xe,pe=1),ae=ae.next}if(ie<1e100){let xe=se.edges.head;for(;xe!=null;){let te=xe.elt,he=1e100,ye=re.gverts.next;for(;ye!=null;){let ue=ye,Pe=te.gnormx*ue.x+te.gnormy*ue.y;Pe<he&&(he=Pe),ye=ye.next}if(he-=te.gprojection,he>1e100){ie=he;break}he>0?he>ie&&(ie=he,ce=te,pe=2):ie<0&&he>ie&&(ie=he,ce=te,pe=2),xe=xe.next}if(ie<1e100){var N,E,M;if(pe==1)N=re,E=se,M=oe;else{N=se,E=re,M=ce;let ue=A;A=W,W=ue,ne=!ne}let te=null,he=1e100,ye=E.edges.head;for(;ye!=null;){let ue=ye.elt,Pe=M.gnormx*ue.gnormx+M.gnormy*ue.gnormy;Pe<he&&(he=Pe,te=ue),ye=ye.next}if(ne?(f.x=-M.gnormx,f.y=-M.gnormy):(f.x=M.gnormx,f.y=M.gnormy),ie>=0){let ue=M.gp0,Pe=M.gp1,Se=te.gp0,Te=te.gp1,We=0,Ye=0,Xe=0,Fe=0;We=Pe.x-ue.x,Ye=Pe.y-ue.y,Xe=Te.x-Se.x,Fe=Te.y-Se.y;let Pt=1/(We*We+Ye*Ye),kt=1/(Xe*Xe+Fe*Fe),ct=-(We*(ue.x-Se.x)+Ye*(ue.y-Se.y))*Pt,ht=-(We*(ue.x-Te.x)+Ye*(ue.y-Te.y))*Pt,pt=-(Xe*(Se.x-ue.x)+Fe*(Se.y-ue.y))*kt,Ke=-(Xe*(Se.x-Pe.x)+Fe*(Se.y-Pe.y))*kt;ct<0?ct=0:ct>1&&(ct=1),ht<0?ht=0:ht>1&&(ht=1),pt<0?pt=0:pt>1&&(pt=1),Ke<0?Ke=0:Ke>1&&(Ke=1);let wt=0,Ft=0,Ut=ct;wt=ue.x+We*Ut,Ft=ue.y+Ye*Ut;let Vt=0,It=0,wn=ht;Vt=ue.x+We*wn,It=ue.y+Ye*wn;let Xt=0,yn=0,pn=pt;Xt=Se.x+Xe*pn,yn=Se.y+Fe*pn;let mn=0,Ht=0,vn=Ke;mn=Se.x+Xe*vn,Ht=Se.y+Fe*vn;let Qt=0,bn=0;Qt=wt-Se.x,bn=Ft-Se.y;let Wt=Qt*Qt+bn*bn,$t=0,cn=0;$t=Vt-Te.x,cn=It-Te.y;let ti=$t*$t+cn*cn,Ln=0,In=0;Ln=Xt-ue.x,In=yn-ue.y;let jn=Ln*Ln+In*In,Di=0,Fi=0;Di=mn-Pe.x,Fi=Ht-Pe.y;let Gi=Di*Di+Fi*Fi,_s=0,Fl=0,Pl=null;Wt<ti?(_s=wt,Fl=Ft,Pl=Se):(_s=Vt,Fl=It,Pl=Te,Wt=ti);let Gl=0,Rl=0,wl=null;if(jn<Gi?(Gl=Xt,Rl=yn,wl=ue):(Gl=mn,Rl=Ht,wl=Pe,jn=Gi),Wt<jn?(A.x=_s,A.y=Fl,W.x=Pl.x,W.y=Pl.y,ie=Math.sqrt(Wt)):(W.x=Gl,W.y=Rl,A.x=wl.x,A.y=wl.y,ie=Math.sqrt(jn)),ie!=0){f.x=W.x-A.x,f.y=W.y-A.y;let $l=1/ie;f.x*=$l,f.y*=$l,ne&&(f.x=-f.x,f.y=-f.y)}g=ie}else{let ue=0,Pe=0;ue=te.gp0.x,Pe=te.gp0.y;let Se=0,Te=0;Se=te.gp1.x,Te=te.gp1.y;let We=0,Ye=0;We=Se-ue,Ye=Te-Pe;let Xe=M.gnormy*ue-M.gnormx*Pe,Fe=M.gnormy*Se-M.gnormx*Te,Pt=1/(Fe-Xe),kt=(-M.tp1-Xe)*Pt;if(kt>i.Config.epsilon){let Ke=kt;ue+=We*Ke,Pe+=Ye*Ke}let ct=(-M.tp0-Fe)*Pt;if(ct<-i.Config.epsilon){let Ke=ct;Se+=We*Ke,Te+=Ye*Ke}let ht=ue*M.gnormx+Pe*M.gnormy-M.gprojection,pt=Se*M.gnormx+Te*M.gnormy-M.gprojection;if(ht<pt){W.x=ue,W.y=Pe;let Ke=-ht;A.x=W.x+M.gnormx*Ke,A.y=W.y+M.gnormy*Ke,g=ht}else{W.x=Se,W.y=Te;let Ke=-pt;A.x=W.x+M.gnormx*Ke,A.y=W.y+M.gnormy*Ke,g=pt}}}else g=1e100}else g=1e100}}let H=g+l,K=c*f.x+u*f.y;if(H<i.Config.distanceThresholdCCD){if(s)break;let ne=0,re=0;ne=_.x-a.posx,re=_.y-a.posy;let se=0,ie=0;se=d.x-p.posx,ie=d.y-p.posy;let oe=K-a.sweep_angvel*(f.y*ne-f.x*re)+p.sweep_angvel*(f.y*se-f.x*ie);if(oe>0&&(e.slipped=!0),oe<=0||H<i.Config.distanceThresholdCCD*.5)break}m=-1;break}if(++z>=40){B>l&&(e.failed=!0);break}}e.toi=m}static staticSweep(e,t,n,l){let s=me(),i=e.s1,o=e.s2,r=i.body,a=o.body,p=0,c=0;p=-r.velx,c=-r.vely;let u=r.sweep_angvel;u<0&&(u=-u);let h=i.sweepCoef*u,x=e.c1,b=e.c2,_=e.axis,d=n,f=0;for(;;){let E=d*t,M=E-r.sweepTime;if(M!=0){r.sweepTime=E;let B=M;if(r.posx+=r.velx*B,r.posy+=r.vely*B,r.angvel!=0){let S=r.sweep_angvel*M;if(r.rot+=S,S*S>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let J=S*S,Q=1-.5*J,Y=1-J*J/8,X=(Q*r.axisx+S*r.axisy)*Y;r.axisy=(Q*r.axisy-S*r.axisx)*Y,r.axisx=X}}}if(i.type==0)i.worldCOMx=r.posx+(r.axisy*i.localCOMx-r.axisx*i.localCOMy),i.worldCOMy=r.posy+(i.localCOMx*r.axisx+i.localCOMy*r.axisy);else{let B=i.polygon,S=B.lverts.next,J=B.gverts.next;for(;J!=null;){let F=J,T=S;S=S.next,F.x=r.posx+(r.axisy*T.x-r.axisx*T.y),F.y=r.posy+(T.x*r.axisx+T.y*r.axisy),J=J.next}let Q=B.edges.head,Y=B.gverts.next,X=Y;for(Y=Y.next;Y!=null;){let F=Y,T=Q.elt;Q=Q.next,T.gnormx=r.axisy*T.lnormx-r.axisx*T.lnormy,T.gnormy=T.lnormx*r.axisx+T.lnormy*r.axisy,T.gprojection=r.posx*T.gnormx+r.posy*T.gnormy+T.lprojection,T.tp0=X.y*T.gnormx-X.x*T.gnormy,T.tp1=F.y*T.gnormx-F.x*T.gnormy,X=F,Y=Y.next}let ee=B.gverts.next,G=Q.elt;Q=Q.next,G.gnormx=r.axisy*G.lnormx-r.axisx*G.lnormy,G.gnormy=G.lnormx*r.axisx+G.lnormy*r.axisy,G.gprojection=r.posx*G.gnormx+r.posy*G.gnormy+G.lprojection,G.tp0=X.y*G.gnormx-X.x*G.gnormy,G.tp1=ee.y*G.gnormx-ee.x*G.gnormy}let C=i,D=o,O=x,j=b;var m;if(C.type==0&&D.type==0){let B=C.circle,S=D.circle;var z;let J=0,Q=0;J=S.worldCOMx-B.worldCOMx,Q=S.worldCOMy-B.worldCOMy;let Y=Math.sqrt(J*J+Q*Q);if(z=Y-(B.radius+S.radius),z<1e100){if(Y==0)J=1,Q=0;else{let G=1/Y;J*=G,Q*=G}let X=B.radius;O.x=B.worldCOMx+J*X,O.y=B.worldCOMy+Q*X;let ee=-S.radius;j.x=S.worldCOMx+J*ee,j.y=S.worldCOMy+Q*ee,_.x=J,_.y=Q}m=z}else{let B=!1;if(C.type==0&&D.type==1){let S=C;C=D,D=S;let J=O;O=j,j=J,B=!0}if(C.type==1&&D.type==0){let S=C.polygon,J=D.circle,Q=-1e100,Y=null,X=S.edges.head;for(;X!=null;){let ee=X.elt,G=ee.gnormx*J.worldCOMx+ee.gnormy*J.worldCOMy-ee.gprojection-J.radius;if(G>1e100){Q=G;break}G>0?G>Q&&(Q=G,Y=ee):Q<0&&G>Q&&(Q=G,Y=ee),X=X.next}if(Q<1e100){let ee=Y.gp0,G=Y.gp1,F=J.worldCOMy*Y.gnormx-J.worldCOMx*Y.gnormy;if(F<=ee.y*Y.gnormx-ee.x*Y.gnormy){let T=0,A=0;T=J.worldCOMx-ee.x,A=J.worldCOMy-ee.y;let W=Math.sqrt(T*T+A*A);if(Q=W-J.radius,Q<1e100){if(W==0)T=1,A=0;else{let ne=1/W;T*=ne,A*=ne}let H=0;O.x=ee.x+T*H,O.y=ee.y+A*H;let K=-J.radius;j.x=J.worldCOMx+T*K,j.y=J.worldCOMy+A*K,_.x=T,_.y=A}}else if(F>=G.y*Y.gnormx-G.x*Y.gnormy){let T=0,A=0;T=J.worldCOMx-G.x,A=J.worldCOMy-G.y;let W=Math.sqrt(T*T+A*A);if(Q=W-J.radius,Q<1e100){if(W==0)T=1,A=0;else{let ne=1/W;T*=ne,A*=ne}let H=0;O.x=G.x+T*H,O.y=G.y+A*H;let K=-J.radius;j.x=J.worldCOMx+T*K,j.y=J.worldCOMy+A*K,_.x=T,_.y=A}}else{let T=-J.radius;j.x=J.worldCOMx+Y.gnormx*T,j.y=J.worldCOMy+Y.gnormy*T;let A=-Q;O.x=j.x+Y.gnormx*A,O.y=j.y+Y.gnormy*A,_.x=Y.gnormx,_.y=Y.gnormy}}B&&(_.x=-_.x,_.y=-_.y),m=Q}else{let S=C.polygon,J=D.polygon,Q=-1e100,Y=null,X=null,ee=0,G=S.edges.head;for(;G!=null;){let F=G.elt,T=1e100,A=J.gverts.next;for(;A!=null;){let W=A,H=F.gnormx*W.x+F.gnormy*W.y;H<T&&(T=H),A=A.next}if(T-=F.gprojection,T>1e100){Q=T;break}T>0?T>Q&&(Q=T,Y=F,ee=1):Q<0&&T>Q&&(Q=T,Y=F,ee=1),G=G.next}if(Q<1e100){let F=J.edges.head;for(;F!=null;){let T=F.elt,A=1e100,W=S.gverts.next;for(;W!=null;){let H=W,K=T.gnormx*H.x+T.gnormy*H.y;K<A&&(A=K),W=W.next}if(A-=T.gprojection,A>1e100){Q=A;break}A>0?A>Q&&(Q=A,X=T,ee=2):Q<0&&A>Q&&(Q=A,X=T,ee=2),F=F.next}if(Q<1e100){var Z,y,w;if(ee==1)Z=S,y=J,w=Y;else{Z=J,y=S,w=X;let H=O;O=j,j=H,B=!B}let T=null,A=1e100,W=y.edges.head;for(;W!=null;){let H=W.elt,K=w.gnormx*H.gnormx+w.gnormy*H.gnormy;K<A&&(A=K,T=H),W=W.next}if(B?(_.x=-w.gnormx,_.y=-w.gnormy):(_.x=w.gnormx,_.y=w.gnormy),Q>=0){let H=w.gp0,K=w.gp1,ne=T.gp0,re=T.gp1,se=0,ie=0,oe=0,ce=0;se=K.x-H.x,ie=K.y-H.y,oe=re.x-ne.x,ce=re.y-ne.y;let pe=1/(se*se+ie*ie),ae=1/(oe*oe+ce*ce),xe=-(se*(H.x-ne.x)+ie*(H.y-ne.y))*pe,te=-(se*(H.x-re.x)+ie*(H.y-re.y))*pe,he=-(oe*(ne.x-H.x)+ce*(ne.y-H.y))*ae,ye=-(oe*(ne.x-K.x)+ce*(ne.y-K.y))*ae;xe<0?xe=0:xe>1&&(xe=1),te<0?te=0:te>1&&(te=1),he<0?he=0:he>1&&(he=1),ye<0?ye=0:ye>1&&(ye=1);let ue=0,Pe=0,Se=xe;ue=H.x+se*Se,Pe=H.y+ie*Se;let Te=0,We=0,Ye=te;Te=H.x+se*Ye,We=H.y+ie*Ye;let Xe=0,Fe=0,Pt=he;Xe=ne.x+oe*Pt,Fe=ne.y+ce*Pt;let kt=0,ct=0,ht=ye;kt=ne.x+oe*ht,ct=ne.y+ce*ht;let pt=0,Ke=0;pt=ue-ne.x,Ke=Pe-ne.y;let wt=pt*pt+Ke*Ke,Ft=0,Ut=0;Ft=Te-re.x,Ut=We-re.y;let Vt=Ft*Ft+Ut*Ut,It=0,wn=0;It=Xe-H.x,wn=Fe-H.y;let Xt=It*It+wn*wn,yn=0,pn=0;yn=kt-K.x,pn=ct-K.y;let mn=yn*yn+pn*pn,Ht=0,vn=0,Qt=null;wt<Vt?(Ht=ue,vn=Pe,Qt=ne):(Ht=Te,vn=We,Qt=re,wt=Vt);let bn=0,Wt=0,$t=null;if(Xt<mn?(bn=Xe,Wt=Fe,$t=H):(bn=kt,Wt=ct,$t=K,Xt=mn),wt<Xt?(O.x=Ht,O.y=vn,j.x=Qt.x,j.y=Qt.y,Q=Math.sqrt(wt)):(j.x=bn,j.y=Wt,O.x=$t.x,O.y=$t.y,Q=Math.sqrt(Xt)),Q!=0){_.x=j.x-O.x,_.y=j.y-O.y;let cn=1/Q;_.x*=cn,_.y*=cn,B&&(_.x=-_.x,_.y=-_.y)}m=Q}else{let H=0,K=0;H=T.gp0.x,K=T.gp0.y;let ne=0,re=0;ne=T.gp1.x,re=T.gp1.y;let se=0,ie=0;se=ne-H,ie=re-K;let oe=w.gnormy*H-w.gnormx*K,ce=w.gnormy*ne-w.gnormx*re,pe=1/(ce-oe),ae=(-w.tp1-oe)*pe;if(ae>s.Config.epsilon){let ye=ae;H+=se*ye,K+=ie*ye}let xe=(-w.tp0-ce)*pe;if(xe<-s.Config.epsilon){let ye=xe;ne+=se*ye,re+=ie*ye}let te=H*w.gnormx+K*w.gnormy-w.gprojection,he=ne*w.gnormx+re*w.gnormy-w.gprojection;if(te<he){j.x=H,j.y=K;let ye=-te;O.x=j.x+w.gnormx*ye,O.y=j.y+w.gnormy*ye,m=te}else{j.x=ne,j.y=re;let ye=-he;O.x=j.x+w.gnormx*ye,O.y=j.y+w.gnormy*ye,m=he}}}else m=1e100}else m=1e100}}let L=m+l,U=p*_.x+c*_.y;if(L<s.Config.distanceThresholdCCD){let B=0,S=0;B=x.x-r.posx,S=x.y-r.posy;let J=U-r.sweep_angvel*(_.y*B-_.x*S);if(J>0&&(e.slipped=!0),J<=0||L<s.Config.distanceThresholdCCD*.5)break}let q=(h-U)*t;if(q<=0){d=-1;break}let R=L/q;if(R<1e-6&&(R=1e-6),d+=R,d>=1){d=1;let B=d*t,S=B-r.sweepTime;if(S!=0){r.sweepTime=B;let F=S;if(r.posx+=r.velx*F,r.posy+=r.vely*F,r.angvel!=0){let T=r.sweep_angvel*S;if(r.rot+=T,T*T>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let A=T*T,W=1-.5*A,H=1-A*A/8,K=(W*r.axisx+T*r.axisy)*H;r.axisy=(W*r.axisy-T*r.axisx)*H,r.axisx=K}}}if(i.type==0)i.worldCOMx=r.posx+(r.axisy*i.localCOMx-r.axisx*i.localCOMy),i.worldCOMy=r.posy+(i.localCOMx*r.axisx+i.localCOMy*r.axisy);else{let F=i.polygon,T=F.lverts.next,A=F.gverts.next;for(;A!=null;){let se=A,ie=T;T=T.next,se.x=r.posx+(r.axisy*ie.x-r.axisx*ie.y),se.y=r.posy+(ie.x*r.axisx+ie.y*r.axisy),A=A.next}let W=F.edges.head,H=F.gverts.next,K=H;for(H=H.next;H!=null;){let se=H,ie=W.elt;W=W.next,ie.gnormx=r.axisy*ie.lnormx-r.axisx*ie.lnormy,ie.gnormy=ie.lnormx*r.axisx+ie.lnormy*r.axisy,ie.gprojection=r.posx*ie.gnormx+r.posy*ie.gnormy+ie.lprojection,ie.tp0=K.y*ie.gnormx-K.x*ie.gnormy,ie.tp1=se.y*ie.gnormx-se.x*ie.gnormy,K=se,H=H.next}let ne=F.gverts.next,re=W.elt;W=W.next,re.gnormx=r.axisy*re.lnormx-r.axisx*re.lnormy,re.gnormy=re.lnormx*r.axisx+re.lnormy*r.axisy,re.gprojection=r.posx*re.gnormx+r.posy*re.gnormy+re.lprojection,re.tp0=K.y*re.gnormx-K.x*re.gnormy,re.tp1=ne.y*re.gnormx-ne.x*re.gnormy}let J=i,Q=o,Y=x,X=b;var v;if(J.type==0&&Q.type==0){let F=J.circle,T=Q.circle;var P;let A=0,W=0;A=T.worldCOMx-F.worldCOMx,W=T.worldCOMy-F.worldCOMy;let H=Math.sqrt(A*A+W*W);if(P=H-(F.radius+T.radius),P<1e100){if(H==0)A=1,W=0;else{let re=1/H;A*=re,W*=re}let K=F.radius;Y.x=F.worldCOMx+A*K,Y.y=F.worldCOMy+W*K;let ne=-T.radius;X.x=T.worldCOMx+A*ne,X.y=T.worldCOMy+W*ne,_.x=A,_.y=W}v=P}else{let F=!1;if(J.type==0&&Q.type==1){let T=J;J=Q,Q=T;let A=Y;Y=X,X=A,F=!0}if(J.type==1&&Q.type==0){let T=J.polygon,A=Q.circle,W=-1e100,H=null,K=T.edges.head;for(;K!=null;){let ne=K.elt,re=ne.gnormx*A.worldCOMx+ne.gnormy*A.worldCOMy-ne.gprojection-A.radius;if(re>1e100){W=re;break}re>0?re>W&&(W=re,H=ne):W<0&&re>W&&(W=re,H=ne),K=K.next}if(W<1e100){let ne=H.gp0,re=H.gp1,se=A.worldCOMy*H.gnormx-A.worldCOMx*H.gnormy;if(se<=ne.y*H.gnormx-ne.x*H.gnormy){let ie=0,oe=0;ie=A.worldCOMx-ne.x,oe=A.worldCOMy-ne.y;let ce=Math.sqrt(ie*ie+oe*oe);if(W=ce-A.radius,W<1e100){if(ce==0)ie=1,oe=0;else{let xe=1/ce;ie*=xe,oe*=xe}let pe=0;Y.x=ne.x+ie*pe,Y.y=ne.y+oe*pe;let ae=-A.radius;X.x=A.worldCOMx+ie*ae,X.y=A.worldCOMy+oe*ae,_.x=ie,_.y=oe}}else if(se>=re.y*H.gnormx-re.x*H.gnormy){let ie=0,oe=0;ie=A.worldCOMx-re.x,oe=A.worldCOMy-re.y;let ce=Math.sqrt(ie*ie+oe*oe);if(W=ce-A.radius,W<1e100){if(ce==0)ie=1,oe=0;else{let xe=1/ce;ie*=xe,oe*=xe}let pe=0;Y.x=re.x+ie*pe,Y.y=re.y+oe*pe;let ae=-A.radius;X.x=A.worldCOMx+ie*ae,X.y=A.worldCOMy+oe*ae,_.x=ie,_.y=oe}}else{let ie=-A.radius;X.x=A.worldCOMx+H.gnormx*ie,X.y=A.worldCOMy+H.gnormy*ie;let oe=-W;Y.x=X.x+H.gnormx*oe,Y.y=X.y+H.gnormy*oe,_.x=H.gnormx,_.y=H.gnormy}}F&&(_.x=-_.x,_.y=-_.y),v=W}else{let T=J.polygon,A=Q.polygon,W=-1e100,H=null,K=null,ne=0,re=T.edges.head;for(;re!=null;){let se=re.elt,ie=1e100,oe=A.gverts.next;for(;oe!=null;){let ce=oe,pe=se.gnormx*ce.x+se.gnormy*ce.y;pe<ie&&(ie=pe),oe=oe.next}if(ie-=se.gprojection,ie>1e100){W=ie;break}ie>0?ie>W&&(W=ie,H=se,ne=1):W<0&&ie>W&&(W=ie,H=se,ne=1),re=re.next}if(W<1e100){let se=A.edges.head;for(;se!=null;){let ie=se.elt,oe=1e100,ce=T.gverts.next;for(;ce!=null;){let pe=ce,ae=ie.gnormx*pe.x+ie.gnormy*pe.y;ae<oe&&(oe=ae),ce=ce.next}if(oe-=ie.gprojection,oe>1e100){W=oe;break}oe>0?oe>W&&(W=oe,K=ie,ne=2):W<0&&oe>W&&(W=oe,K=ie,ne=2),se=se.next}if(W<1e100){var g,k,N;if(ne==1)g=T,k=A,N=H;else{g=A,k=T,N=K;let pe=Y;Y=X,X=pe,F=!F}let ie=null,oe=1e100,ce=k.edges.head;for(;ce!=null;){let pe=ce.elt,ae=N.gnormx*pe.gnormx+N.gnormy*pe.gnormy;ae<oe&&(oe=ae,ie=pe),ce=ce.next}if(F?(_.x=-N.gnormx,_.y=-N.gnormy):(_.x=N.gnormx,_.y=N.gnormy),W>=0){let pe=N.gp0,ae=N.gp1,xe=ie.gp0,te=ie.gp1,he=0,ye=0,ue=0,Pe=0;he=ae.x-pe.x,ye=ae.y-pe.y,ue=te.x-xe.x,Pe=te.y-xe.y;let Se=1/(he*he+ye*ye),Te=1/(ue*ue+Pe*Pe),We=-(he*(pe.x-xe.x)+ye*(pe.y-xe.y))*Se,Ye=-(he*(pe.x-te.x)+ye*(pe.y-te.y))*Se,Xe=-(ue*(xe.x-pe.x)+Pe*(xe.y-pe.y))*Te,Fe=-(ue*(xe.x-ae.x)+Pe*(xe.y-ae.y))*Te;We<0?We=0:We>1&&(We=1),Ye<0?Ye=0:Ye>1&&(Ye=1),Xe<0?Xe=0:Xe>1&&(Xe=1),Fe<0?Fe=0:Fe>1&&(Fe=1);let Pt=0,kt=0,ct=We;Pt=pe.x+he*ct,kt=pe.y+ye*ct;let ht=0,pt=0,Ke=Ye;ht=pe.x+he*Ke,pt=pe.y+ye*Ke;let wt=0,Ft=0,Ut=Xe;wt=xe.x+ue*Ut,Ft=xe.y+Pe*Ut;let Vt=0,It=0,wn=Fe;Vt=xe.x+ue*wn,It=xe.y+Pe*wn;let Xt=0,yn=0;Xt=Pt-xe.x,yn=kt-xe.y;let pn=Xt*Xt+yn*yn,mn=0,Ht=0;mn=ht-te.x,Ht=pt-te.y;let vn=mn*mn+Ht*Ht,Qt=0,bn=0;Qt=wt-pe.x,bn=Ft-pe.y;let Wt=Qt*Qt+bn*bn,$t=0,cn=0;$t=Vt-ae.x,cn=It-ae.y;let ti=$t*$t+cn*cn,Ln=0,In=0,jn=null;pn<vn?(Ln=Pt,In=kt,jn=xe):(Ln=ht,In=pt,jn=te,pn=vn);let Di=0,Fi=0,Gi=null;if(Wt<ti?(Di=wt,Fi=Ft,Gi=pe):(Di=Vt,Fi=It,Gi=ae,Wt=ti),pn<Wt?(Y.x=Ln,Y.y=In,X.x=jn.x,X.y=jn.y,W=Math.sqrt(pn)):(X.x=Di,X.y=Fi,Y.x=Gi.x,Y.y=Gi.y,W=Math.sqrt(Wt)),W!=0){_.x=X.x-Y.x,_.y=X.y-Y.y;let _s=1/W;_.x*=_s,_.y*=_s,F&&(_.x=-_.x,_.y=-_.y)}v=W}else{let pe=0,ae=0;pe=ie.gp0.x,ae=ie.gp0.y;let xe=0,te=0;xe=ie.gp1.x,te=ie.gp1.y;let he=0,ye=0;he=xe-pe,ye=te-ae;let ue=N.gnormy*pe-N.gnormx*ae,Pe=N.gnormy*xe-N.gnormx*te,Se=1/(Pe-ue),Te=(-N.tp1-ue)*Se;if(Te>s.Config.epsilon){let Fe=Te;pe+=he*Fe,ae+=ye*Fe}let We=(-N.tp0-Pe)*Se;if(We<-s.Config.epsilon){let Fe=We;xe+=he*Fe,te+=ye*Fe}let Ye=pe*N.gnormx+ae*N.gnormy-N.gprojection,Xe=xe*N.gnormx+te*N.gnormy-N.gprojection;if(Ye<Xe){X.x=pe,X.y=ae;let Fe=-Ye;Y.x=X.x+N.gnormx*Fe,Y.y=X.y+N.gnormy*Fe,v=Ye}else{X.x=xe,X.y=te;let Fe=-Xe;Y.x=X.x+N.gnormx*Fe,Y.y=X.y+N.gnormy*Fe,v=Xe}}}else v=1e100}else v=1e100}}let ee=v+l,G=p*_.x+c*_.y;if(ee<s.Config.distanceThresholdCCD){let F=0,T=0;F=x.x-r.posx,T=x.y-r.posy;let A=G-r.sweep_angvel*(_.y*F-_.x*T);if(A>0&&(e.slipped=!0),A<=0||ee<s.Config.distanceThresholdCCD*.5)break}d=-1;break}if(++f>=40){L>l&&(e.failed=!0);break}}e.toi=d}static distanceBody(e,t,n,l){let s=me(),i;le.zpp_pool==null?i=new le:(i=le.zpp_pool,le.zpp_pool=i.next,i.next=null),i.weak=!1;let o;le.zpp_pool==null?o=new le:(o=le.zpp_pool,le.zpp_pool=o.next,o.next=null),o.weak=!1;let r;le.zpp_pool==null?r=new le:(r=le.zpp_pool,le.zpp_pool=r.next,r.next=null),r.weak=!1;let a=1e100,p=e.shapes.head;for(;p!=null;){let m=p.elt,z=t.shapes.head;for(;z!=null;){let Z=z.elt,y=m,w=Z,v=i,P=o,g=a;g==null&&(g=1e100);var c;if(y.type==0&&w.type==0){let k=y.circle,N=w.circle;var u;let E=0,M=0;E=N.worldCOMx-k.worldCOMx,M=N.worldCOMy-k.worldCOMy;let C=Math.sqrt(E*E+M*M);if(u=C-(k.radius+N.radius),u<g){if(C==0)E=1,M=0;else{let j=1/C;E*=j,M*=j}let D=k.radius;v.x=k.worldCOMx+E*D,v.y=k.worldCOMy+M*D;let O=-N.radius;P.x=N.worldCOMx+E*O,P.y=N.worldCOMy+M*O,r.x=E,r.y=M}c=u}else{let k=!1;if(y.type==0&&w.type==1){let N=y;y=w,w=N;let E=v;v=P,P=E,k=!0}if(y.type==1&&w.type==0){let N=y.polygon,E=w.circle,M=-1e100,C=null,D=N.edges.head;for(;D!=null;){let O=D.elt,j=O.gnormx*E.worldCOMx+O.gnormy*E.worldCOMy-O.gprojection-E.radius;if(j>g){M=j;break}j>0?j>M&&(M=j,C=O):M<0&&j>M&&(M=j,C=O),D=D.next}if(M<g){let O=C.gp0,j=C.gp1,L=E.worldCOMy*C.gnormx-E.worldCOMx*C.gnormy;if(L<=O.y*C.gnormx-O.x*C.gnormy){let U=0,q=0;U=E.worldCOMx-O.x,q=E.worldCOMy-O.y;let R=Math.sqrt(U*U+q*q);if(M=R-E.radius,M<g){if(R==0)U=1,q=0;else{let J=1/R;U*=J,q*=J}let B=0;v.x=O.x+U*B,v.y=O.y+q*B;let S=-E.radius;P.x=E.worldCOMx+U*S,P.y=E.worldCOMy+q*S,r.x=U,r.y=q}}else if(L>=j.y*C.gnormx-j.x*C.gnormy){let U=0,q=0;U=E.worldCOMx-j.x,q=E.worldCOMy-j.y;let R=Math.sqrt(U*U+q*q);if(M=R-E.radius,M<g){if(R==0)U=1,q=0;else{let J=1/R;U*=J,q*=J}let B=0;v.x=j.x+U*B,v.y=j.y+q*B;let S=-E.radius;P.x=E.worldCOMx+U*S,P.y=E.worldCOMy+q*S,r.x=U,r.y=q}}else{let U=-E.radius;P.x=E.worldCOMx+C.gnormx*U,P.y=E.worldCOMy+C.gnormy*U;let q=-M;v.x=P.x+C.gnormx*q,v.y=P.y+C.gnormy*q,r.x=C.gnormx,r.y=C.gnormy}}k&&(r.x=-r.x,r.y=-r.y),c=M}else{let N=y.polygon,E=w.polygon,M=-1e100,C=null,D=null,O=0,j=N.edges.head;for(;j!=null;){let L=j.elt,U=1e100,q=E.gverts.next;for(;q!=null;){let R=q,B=L.gnormx*R.x+L.gnormy*R.y;B<U&&(U=B),q=q.next}if(U-=L.gprojection,U>g){M=U;break}U>0?U>M&&(M=U,C=L,O=1):M<0&&U>M&&(M=U,C=L,O=1),j=j.next}if(M<g){let L=E.edges.head;for(;L!=null;){let U=L.elt,q=1e100,R=N.gverts.next;for(;R!=null;){let B=R,S=U.gnormx*B.x+U.gnormy*B.y;S<q&&(q=S),R=R.next}if(q-=U.gprojection,q>g){M=q;break}q>0?q>M&&(M=q,D=U,O=2):M<0&&q>M&&(M=q,D=U,O=2),L=L.next}if(M<g){var h,x,b;if(O==1)h=N,x=E,b=C;else{h=E,x=N,b=D;let B=v;v=P,P=B,k=!k}let U=null,q=1e100,R=x.edges.head;for(;R!=null;){let B=R.elt,S=b.gnormx*B.gnormx+b.gnormy*B.gnormy;S<q&&(q=S,U=B),R=R.next}if(k?(r.x=-b.gnormx,r.y=-b.gnormy):(r.x=b.gnormx,r.y=b.gnormy),M>=0){let B=b.gp0,S=b.gp1,J=U.gp0,Q=U.gp1,Y=0,X=0,ee=0,G=0;Y=S.x-B.x,X=S.y-B.y,ee=Q.x-J.x,G=Q.y-J.y;let F=1/(Y*Y+X*X),T=1/(ee*ee+G*G),A=-(Y*(B.x-J.x)+X*(B.y-J.y))*F,W=-(Y*(B.x-Q.x)+X*(B.y-Q.y))*F,H=-(ee*(J.x-B.x)+G*(J.y-B.y))*T,K=-(ee*(J.x-S.x)+G*(J.y-S.y))*T;A<0?A=0:A>1&&(A=1),W<0?W=0:W>1&&(W=1),H<0?H=0:H>1&&(H=1),K<0?K=0:K>1&&(K=1);let ne=0,re=0,se=A;ne=B.x+Y*se,re=B.y+X*se;let ie=0,oe=0,ce=W;ie=B.x+Y*ce,oe=B.y+X*ce;let pe=0,ae=0,xe=H;pe=J.x+ee*xe,ae=J.y+G*xe;let te=0,he=0,ye=K;te=J.x+ee*ye,he=J.y+G*ye;let ue=0,Pe=0;ue=ne-J.x,Pe=re-J.y;let Se=ue*ue+Pe*Pe,Te=0,We=0;Te=ie-Q.x,We=oe-Q.y;let Ye=Te*Te+We*We,Xe=0,Fe=0;Xe=pe-B.x,Fe=ae-B.y;let Pt=Xe*Xe+Fe*Fe,kt=0,ct=0;kt=te-S.x,ct=he-S.y;let ht=kt*kt+ct*ct,pt=0,Ke=0,wt=null;Se<Ye?(pt=ne,Ke=re,wt=J):(pt=ie,Ke=oe,wt=Q,Se=Ye);let Ft=0,Ut=0,Vt=null;if(Pt<ht?(Ft=pe,Ut=ae,Vt=B):(Ft=te,Ut=he,Vt=S,Pt=ht),Se<Pt?(v.x=pt,v.y=Ke,P.x=wt.x,P.y=wt.y,M=Math.sqrt(Se)):(P.x=Ft,P.y=Ut,v.x=Vt.x,v.y=Vt.y,M=Math.sqrt(Pt)),M!=0){r.x=P.x-v.x,r.y=P.y-v.y;let It=1/M;r.x*=It,r.y*=It,k&&(r.x=-r.x,r.y=-r.y)}c=M}else{let B=0,S=0;B=U.gp0.x,S=U.gp0.y;let J=0,Q=0;J=U.gp1.x,Q=U.gp1.y;let Y=0,X=0;Y=J-B,X=Q-S;let ee=b.gnormy*B-b.gnormx*S,G=b.gnormy*J-b.gnormx*Q,F=1/(G-ee),T=(-b.tp1-ee)*F;if(T>s.Config.epsilon){let K=T;B+=Y*K,S+=X*K}let A=(-b.tp0-G)*F;if(A<-s.Config.epsilon){let K=A;J+=Y*K,Q+=X*K}let W=B*b.gnormx+S*b.gnormy-b.gprojection,H=J*b.gnormx+Q*b.gnormy-b.gprojection;if(W<H){P.x=B,P.y=S;let K=-W;v.x=P.x+b.gnormx*K,v.y=P.y+b.gnormy*K,c=W}else{P.x=J,P.y=Q;let K=-H;v.x=P.x+b.gnormx*K,v.y=P.y+b.gnormy*K,c=H}}}else c=g}else c=g}}c<a&&(a=c,n.x=i.x,n.y=i.y,l.x=o.x,l.y=o.y),z=z.next}p=p.next}let _=i;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=le.zpp_pool,le.zpp_pool=_;let d=o;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=le.zpp_pool,le.zpp_pool=d;let f=r;return f.outer!=null&&(f.outer.zpp_inner=null,f.outer=null),f._isimmutable=null,f._validate=null,f._invalidate=null,f.next=le.zpp_pool,le.zpp_pool=f,a}static distance(e,t,n,l,s,i){let o=me();if(i==null&&(i=1e100),e.type==0&&t.type==0){let r=e.circle,a=t.circle,p,c=0,u=0;c=a.worldCOMx-r.worldCOMx,u=a.worldCOMy-r.worldCOMy;let h=Math.sqrt(c*c+u*u);if(p=h-(r.radius+a.radius),p<i){if(h==0)c=1,u=0;else{let _=1/h;c*=_,u*=_}let x=r.radius;n.x=r.worldCOMx+c*x,n.y=r.worldCOMy+u*x;let b=-a.radius;l.x=a.worldCOMx+c*b,l.y=a.worldCOMy+u*b,s.x=c,s.y=u}return p}else{let r=!1;if(e.type==0&&t.type==1){let a=e;e=t,t=a;let p=n;n=l,l=p,r=!0}if(e.type==1&&t.type==0){let a=e.polygon,p=t.circle,c=-1e100,u=null,h=a.edges.head;for(;h!=null;){let x=h.elt,b=x.gnormx*p.worldCOMx+x.gnormy*p.worldCOMy-x.gprojection-p.radius;if(b>i){c=b;break}b>0?b>c&&(c=b,u=x):c<0&&b>c&&(c=b,u=x),h=h.next}if(c<i){let x=u.gp0,b=u.gp1,_=p.worldCOMy*u.gnormx-p.worldCOMx*u.gnormy;if(_<=x.y*u.gnormx-x.x*u.gnormy){let d=0,f=0;d=p.worldCOMx-x.x,f=p.worldCOMy-x.y;let m=Math.sqrt(d*d+f*f);if(c=m-p.radius,c<i){if(m==0)d=1,f=0;else{let y=1/m;d*=y,f*=y}let z=0;n.x=x.x+d*z,n.y=x.y+f*z;let Z=-p.radius;l.x=p.worldCOMx+d*Z,l.y=p.worldCOMy+f*Z,s.x=d,s.y=f}}else if(_>=b.y*u.gnormx-b.x*u.gnormy){let d=0,f=0;d=p.worldCOMx-b.x,f=p.worldCOMy-b.y;let m=Math.sqrt(d*d+f*f);if(c=m-p.radius,c<i){if(m==0)d=1,f=0;else{let y=1/m;d*=y,f*=y}let z=0;n.x=b.x+d*z,n.y=b.y+f*z;let Z=-p.radius;l.x=p.worldCOMx+d*Z,l.y=p.worldCOMy+f*Z,s.x=d,s.y=f}}else{let d=-p.radius;l.x=p.worldCOMx+u.gnormx*d,l.y=p.worldCOMy+u.gnormy*d;let f=-c;n.x=l.x+u.gnormx*f,n.y=l.y+u.gnormy*f,s.x=u.gnormx,s.y=u.gnormy}}return r&&(s.x=-s.x,s.y=-s.y),c}else{let a=e.polygon,p=t.polygon,c=-1e100,u=null,h=null,x=0,b=a.edges.head;for(;b!=null;){let _=b.elt,d=1e100,f=p.gverts.next;for(;f!=null;){let m=f,z=_.gnormx*m.x+_.gnormy*m.y;z<d&&(d=z),f=f.next}if(d-=_.gprojection,d>i){c=d;break}d>0?d>c&&(c=d,u=_,x=1):c<0&&d>c&&(c=d,u=_,x=1),b=b.next}if(c<i){let _=p.edges.head;for(;_!=null;){let d=_.elt,f=1e100,m=a.gverts.next;for(;m!=null;){let z=m,Z=d.gnormx*z.x+d.gnormy*z.y;Z<f&&(f=Z),m=m.next}if(f-=d.gprojection,f>i){c=f;break}f>0?f>c&&(c=f,h=d,x=2):c<0&&f>c&&(c=f,h=d,x=2),_=_.next}if(c<i){let d,f,m;if(x==1)d=a,f=p,m=u;else{d=p,f=a,m=h;let w=n;n=l,l=w,r=!r}let z=null,Z=1e100,y=f.edges.head;for(;y!=null;){let w=y.elt,v=m.gnormx*w.gnormx+m.gnormy*w.gnormy;v<Z&&(Z=v,z=w),y=y.next}if(r?(s.x=-m.gnormx,s.y=-m.gnormy):(s.x=m.gnormx,s.y=m.gnormy),c>=0){let w=m.gp0,v=m.gp1,P=z.gp0,g=z.gp1,k=0,N=0,E=0,M=0;k=v.x-w.x,N=v.y-w.y,E=g.x-P.x,M=g.y-P.y;let C=1/(k*k+N*N),D=1/(E*E+M*M),O=-(k*(w.x-P.x)+N*(w.y-P.y))*C,j=-(k*(w.x-g.x)+N*(w.y-g.y))*C,L=-(E*(P.x-w.x)+M*(P.y-w.y))*D,U=-(E*(P.x-v.x)+M*(P.y-v.y))*D;O<0?O=0:O>1&&(O=1),j<0?j=0:j>1&&(j=1),L<0?L=0:L>1&&(L=1),U<0?U=0:U>1&&(U=1);let q=0,R=0,B=O;q=w.x+k*B,R=w.y+N*B;let S=0,J=0,Q=j;S=w.x+k*Q,J=w.y+N*Q;let Y=0,X=0,ee=L;Y=P.x+E*ee,X=P.y+M*ee;let G=0,F=0,T=U;G=P.x+E*T,F=P.y+M*T;let A=0,W=0;A=q-P.x,W=R-P.y;let H=A*A+W*W,K=0,ne=0;K=S-g.x,ne=J-g.y;let re=K*K+ne*ne,se=0,ie=0;se=Y-w.x,ie=X-w.y;let oe=se*se+ie*ie,ce=0,pe=0;ce=G-v.x,pe=F-v.y;let ae=ce*ce+pe*pe,xe=0,te=0,he=null;H<re?(xe=q,te=R,he=P):(xe=S,te=J,he=g,H=re);let ye=0,ue=0,Pe=null;if(oe<ae?(ye=Y,ue=X,Pe=w):(ye=G,ue=F,Pe=v,oe=ae),H<oe?(n.x=xe,n.y=te,l.x=he.x,l.y=he.y,c=Math.sqrt(H)):(l.x=ye,l.y=ue,n.x=Pe.x,n.y=Pe.y,c=Math.sqrt(oe)),c!=0){s.x=l.x-n.x,s.y=l.y-n.y;let Se=1/c;s.x*=Se,s.y*=Se,r&&(s.x=-s.x,s.y=-s.y)}return c}else{let w=0,v=0;w=z.gp0.x,v=z.gp0.y;let P=0,g=0;P=z.gp1.x,g=z.gp1.y;let k=0,N=0;k=P-w,N=g-v;let E=m.gnormy*w-m.gnormx*v,M=m.gnormy*P-m.gnormx*g,C=1/(M-E),D=(-m.tp1-E)*C;if(D>o.Config.epsilon){let U=D;w+=k*U,v+=N*U}let O=(-m.tp0-M)*C;if(O<-o.Config.epsilon){let U=O;P+=k*U,g+=N*U}let j=w*m.gnormx+v*m.gnormy-m.gprojection,L=P*m.gnormx+g*m.gnormy-m.gprojection;if(j<L){l.x=w,l.y=v;let U=-j;return n.x=l.x+m.gnormx*U,n.y=l.y+m.gnormy*U,j}else{l.x=P,l.y=g;let U=-L;return n.x=l.x+m.gnormx*U,n.y=l.y+m.gnormy*U,L}}}else return i}else return i}}}};Pn.__name__=["zpp_nape","geom","ZPP_SweepDistance"];var Le=class Le{static lt(e,t){return e.y<t.y?!0:e.y==t.y?e.x<t.x:!1}static right_turn(e,t,n){let l=n.x-t.x,s=n.y-t.y,i=t.x-e.x;return(t.y-e.y)*l-i*s}static delaunay(e,t,n,l){let s=n.x-t.x,i=n.y-t.y,o=t.x-e.x,r=t.y-e.y,a,p,c;return r*s-o*i>=0?c=!0:(s=l.x-n.x,i=l.y-n.y,o=n.x-t.x,r=n.y-t.y,c=r*s-o*i>=0),c?p=!0:(s=e.x-l.x,i=e.y-l.y,o=l.x-n.x,r=l.y-n.y,p=r*s-o*i>=0),p?a=!0:(s=t.x-e.x,i=t.y-e.y,o=e.x-l.x,r=e.y-l.y,a=r*s-o*i>=0),a?!0:t.x*(n.y*l.mag-n.mag*l.y)-n.x*(t.y*l.mag-t.mag*l.y)+l.x*(t.y*n.mag-t.mag*n.y)-(e.x*(n.y*l.mag-n.mag*l.y)-n.x*(e.y*l.mag-e.mag*l.y)+l.x*(e.y*n.mag-e.mag*n.y))+(e.x*(t.y*l.mag-t.mag*l.y)-t.x*(e.y*l.mag-e.mag*l.y)+l.x*(e.y*t.mag-e.mag*t.y))-(e.x*(t.y*n.mag-t.mag*n.y)-t.x*(e.y*n.mag-e.mag*n.y)+n.x*(e.y*t.mag-e.mag*t.y))>0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let r=t;for(;;){let a=r;if(a.sort(),a.mag=a.x*a.x+a.y*a.y,r=r.next,r==n)break}}Le.edgeSet==null&&(fs.zpp_pool==null?Le.edgeSet=new fs:(Le.edgeSet=fs.zpp_pool,fs.zpp_pool=Le.edgeSet.next,Le.edgeSet.next=null),Le.edgeSet.lt=Bt.edge_lt,Le.edgeSet.swapped=Bt.edge_swap);let l;Bt.zpp_pool==null?l=new Bt:(l=Bt.zpp_pool,Bt.zpp_pool=l.next,l.next=null);let s=e.vertices,i=e.vertices;if(s!=null){let r=s;for(;;){let a=r,p=a.next;a.diagonals.reverse();let c=a.diagonals.head;for(;c!=null;){let u=c.elt;if(u.id<a.id){p=u,c=c.next;continue}let h=c.next==null?a.prev:c.next.elt;if(!Le.delaunay(a,p,u,h)){let x;Bt.zpp_pool==null?x=new Bt:(x=Bt.zpp_pool,Bt.zpp_pool=x.next,x.next=null),x.a=a,x.b=u,a.id<u.id?(x.id=a.id,x.di=u.id):(x.id=u.id,x.di=a.id);let b=x;l.add(b),b.node=Le.edgeSet.insert(b)}p=u,c=c.next}if(r=r.next,r==i)break}}for(;l.next!=null;){let r=l.pop_unsafe(),a=r.a,p=r.b,c=a.next,u=null,h=a.diagonals.head;for(;h!=null;){let b=h.elt;if(b==p){h=h.next,u=h==null?a.prev:h.elt;break}c=b,h=h.next}if(a.diagonals.remove(p),p.diagonals.remove(a),p==c.next)c.diagonals.add(u);else{let b=c.diagonals.head;for(;b!=null;){if(b.elt==p){c.diagonals.insert(b,u);break}b=b.next}}if(a==u.next)u.diagonals.add(c);else{let b=u.diagonals.head;for(;b!=null;){if(b.elt==a){u.diagonals.insert(b,c);break}b=b.next}}Le.edgeSet.remove_node(r.node);let x=r;x.a=x.b=null,x.node=null,x.next=Bt.zpp_pool,Bt.zpp_pool=x}let o=l;o.a=o.b=null,o.node=null,o.next=Bt.zpp_pool,Bt.zpp_pool=o}static triangulate(e){let t=e.vertices,n=e.vertices,l=e.vertices.next,s=e.vertices;if(l!=null){let a=l;for(;;){let p=a;if((p.y<t.y||p.y==t.y&&p.x<t.x)&&(t=p),(n.y<p.y||n.y==p.y&&n.x<p.x)&&(n=p),a=a.next,a==s)break}}Le.queue==null&&(Le.queue=new zi);let i=n.prev,o=n.next;for(Le.queue.add(n);i!=t||o!=t;)i==t||o!=t&&(i.y<o.y||i.y==o.y&&i.x<o.x)?(Le.queue.add(o),o.rightchain=!1,o=o.next):(Le.queue.add(i),i.rightchain=!0,i=i.prev);Le.queue.add(t),Le.stack==null&&(Le.stack=new zi),Le.stack.add(Le.queue.pop_unsafe());let r=Le.queue.pop_unsafe();for(Le.stack.add(r);;){let a=Le.queue.pop_unsafe();if(Le.queue.head==null)break;if(a.rightchain!=Le.stack.head.elt.rightchain){for(;;){let p=Le.stack.pop_unsafe();if(Le.stack.head==null)break;e.add_diagonal(p,a)}Le.stack.add(r)}else{let p=Le.stack.pop_unsafe();for(;Le.stack.head!=null;){let c=Le.stack.head.elt,u=a.x-p.x,h=a.y-p.y,x=p.x-c.x,_=(p.y-c.y)*u-x*h;if(a.rightchain&&_>=0||!a.rightchain&&_<=0)break;e.add_diagonal(c,a),p=c,Le.stack.pop()}Le.stack.add(p)}Le.stack.add(a),r=a}if(Le.stack.head!=null)for(Le.stack.pop();Le.stack.head!=null;){let a=Le.stack.pop_unsafe();if(Le.stack.head==null)break;e.add_diagonal(n,a)}return e}};Le.__name__=["zpp_nape","geom","ZPP_Triangular"],Le.queue=null,Le.stack=null,Le.edgeSet=null;var Sl=Le;var ss=class ss{constructor(){this.outer=null;this.x=0;this.y=0;this.z=0;this.immutable=!1;this._validate=null}validate(){this._validate!=null&&this._validate()}wrapper(){return this.outer==null&&ss._wrapFn&&(this.outer=ss._wrapFn(this)),this.outer}};ss.__name__=["zpp_nape","geom","ZPP_Vec3"],ss._zpp=null,ss._wrapFn=null;var ui=ss;var Xs=class{static vec_dsq(e,t,n,l){let s=e-n,i=t-l;return s*s+i*i}static vec_distance(e,t,n,l){let s=e-n,i=t-l;return Math.sqrt(s*s+i*i)}};Xs.__name__=["zpp_nape","geom","ZPP_VecMath"];var _n=class _n{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;_n.initFields(this)}static initFields(e){let t=_n._zpp;e.wrap_cbTypes=null,e.cbSet=null,e.cbTypes=null,e.group=null,e.cbsets=null,e.icompound=null,e.ibody=null,e.ishape=null,e.userData=null,e.id=0,e.outer_i=null,e.id=fn.Interactor(),e.cbsets=new t.util.ZNPList_ZPP_CallbackSet,e.cbTypes=new t.util.ZNPList_ZPP_CbType}static get(e,t){let n=e.id<t.id?e.id:t.id,l=e.id<t.id?t.id:e.id,s=e.cbsets.length<t.cbsets.length?e.cbsets:t.cbsets,i=null,o=s.head;for(;o!=null;){let r=o.elt;if(r.id==n&&r.di==l){i=r;break}o=o.next}return i}static int_callback(e,t,n){let l=e.int1,s=e.int2,i,o=t.options1,r=l.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=t.options2,p=s.cbTypes;i=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else i=!1;i?(n.int1=l,n.int2=s):(n.int1=s,n.int2=l)}isShape(){return this.ishape!=null}isBody(){return this.ibody!=null}isCompound(){return this.icompound!=null}__iaddedToSpace(){this.group!=null&&this.group.interactors.add(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.add(this),e=e.next;this.alloc_cbSet()}__iremovedFromSpace(){this.group!=null&&this.group.interactors.remove(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.remove(this),e=e.next;this.dealloc_cbSet()}wake(){if(this.ishape!=null){let e=this.ishape.body;e!=null&&e.space!=null&&e.space.non_inlined_wake(e)}else this.ibody!=null?this.ibody.space!=null&&this.ibody.space.non_inlined_wake(this.ibody):this.icompound.space!=null&&this.icompound.space.wakeCompound(this.icompound)}_getSpace(){return this.ishape!=null?this.ishape.body==null?null:this.ishape.body.space:this.ibody!=null?this.ibody.space:this.icompound.space}getSpace(){return this._getSpace()}setupcbTypes(){let e=_n._zpp;this.wrap_cbTypes=e.util.ZPP_CbTypeList.get(this.cbTypes),this.wrap_cbTypes.zpp_inner.adder=this.wrap_cbTypes_adder.bind(this),this.wrap_cbTypes.zpp_inner.subber=this.wrap_cbTypes_subber.bind(this),this.wrap_cbTypes.zpp_inner.dontremove=!0,this.wrap_cbTypes.zpp_inner._modifiable=this.immutable_cbTypes.bind(this)}immutable_cbTypes(){this.immutable_midstep("Interactor::cbTypes")}wrap_cbTypes_subber(e){let t=e.zpp_inner;if(this.cbTypes.has(t)){let n=this._getSpace();n!=null&&(this.dealloc_cbSet(),t.interactors.remove(this)),this.cbTypes.remove(t),n!=null&&(this.alloc_cbSet(),this.wake())}}wrap_cbTypes_adder(e){return this.insert_cbtype(e.zpp_inner),!1}insert_cbtype(e){let t=_n._zpp;if(!this.cbTypes.has(e)){let n=this._getSpace();n!=null&&(this.dealloc_cbSet(),e.interactors.add(this));let l=null,s=this.cbTypes.head;for(;s!=null;){let a=s.elt;if(e.id<a.id)break;l=s,s=s.next}let i=this.cbTypes,o;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?o=new t.util.ZNPNode_ZPP_CbType:(o=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=o.next,o.next=null),o.elt=e;let r=o;l==null?(r.next=i.head,i.head=r):(r.next=l.next,l.next=r),i.pushmod=i.modified=!0,i.length++,n!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){let e=this._getSpace();(this.cbSet=e.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.interactors.add(this),this.cbSet.validate(),e.freshInteractorType(this))}dealloc_cbSet(){let e=this._getSpace();if(this.cbSet!=null){if(this.cbSet.interactors.remove(this),e.nullInteractorType(this),--this.cbSet.count==0){e.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=!0,t.bodylisteners.clear(),t.zip_bodylisteners=!0,t.conlisteners.clear(),t.zip_conlisteners=!0;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=zt.zpp_pool,zt.zpp_pool=t}this.cbSet=null}}setGroup(e){if(this.group!=e){let t=this._getSpace()!=null;t&&this.group!=null&&this.group.interactors.remove(this),this.group=e,t&&e!=null&&e.interactors.add(this),t&&(this.ishape!=null?this.ishape.body.wake():this.ibody!=null?this.ibody.wake():this.icompound.wake())}}immutable_midstep(e){if(this.ibody!=null){let t=this.ibody;if(t.space!=null&&t.space.midstep)throw new Error("Error: "+e+" cannot be set during a space step()")}else this.ishape!=null?this.ishape.__immutable_midstep(e):this.icompound.__imutable_midstep(e)}lookup_group(){let e=this;for(;e!=null&&e.group==null;)e.ishape!=null?e=e.ishape.body:e.icompound!=null?e=e.icompound.compound:e=e.ibody.compound;return e==null?null:e.group}copyto(e){let t=_n._nape;e.zpp_inner_i.group=this.group;let n=this.outer_i;n.zpp_inner_i.wrap_cbTypes==null&&n.zpp_inner_i.setupcbTypes();let l=n.zpp_inner_i.wrap_cbTypes;l.zpp_inner.valmod();let s=t.callbacks.CbTypeIterator.get(l);for(;;){s.zpp_inner.zpp_inner.valmod();let i=s.zpp_inner;i.zpp_inner.valmod(),i.zpp_inner.zip_length&&(i.zpp_inner.zip_length=!1,i.zpp_inner.user_length=i.zpp_inner.inner.length);let o=i.zpp_inner.user_length;s.zpp_critical=!0;let r;if(s.zpp_i<o?r=!0:(s.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=s,s.zpp_inner=null,r=!1),!r)break;s.zpp_critical=!1;let a=s.zpp_inner.at(s.zpp_i++);e.zpp_inner_i.wrap_cbTypes==null&&e.zpp_inner_i.setupcbTypes();let p=e.zpp_inner_i.wrap_cbTypes;p.zpp_inner.reverse_flag?p.push(a):p.unshift(a)}this.userData!=null&&(e.zpp_inner_i.userData=Object.assign({},this.userData))}static _init(e,t){_n._initialized||(_n._initialized=!0,_n._zpp=e,_n._nape=t)}};_n.__name__=["zpp_nape","phys","ZPP_Interactor"],_n._nape=null,_n._zpp=null,_n._initialized=!1;var St=_n;var Ie=class Ie{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.world=!1;this.type=0;this.compound=null;this.shapes=null;this.wrap_shapes=null;this.space=null;this.arbiters=null;this.wrap_arbiters=null;this.constraints=null;this.wrap_constraints=null;this.component=null;this.graph_depth=0;this.sweepTime=0;this.sweep_angvel=0;this.sweepFrozen=!1;this.sweepRadius=0;this.bullet=!1;this.bulletEnabled=!1;this.disableCCD=!1;this.pre_posx=0;this.pre_posy=0;this.posx=0;this.posy=0;this.wrap_pos=null;this.velx=0;this.vely=0;this.wrap_vel=null;this.forcex=0;this.forcey=0;this.wrap_force=null;this.kinvelx=0;this.kinvely=0;this.wrap_kinvel=null;this.svelx=0;this.svely=0;this.wrap_svel=null;this.wrapcvel=null;this.angvel=0;this.torque=0;this.kinangvel=0;this.pre_rot=0;this.rot=0;this.axisx=0;this.axisy=0;this.zip_axis=!1;this.kinematicDelaySleep=!1;this.mass=0;this.zip_mass=!1;this.massMode=0;this.imass=0;this.smass=0;this.cmass=0;this.nomove=!1;this.gravMass=0;this.zip_gravMass=!1;this.gravMassMode=0;this.gravMassScale=0;this.zip_gravMassScale=!1;this.inertiaMode=0;this.inertia=0;this.zip_inertia=!1;this.cinertia=0;this.iinertia=0;this.sinertia=0;this.norotate=!1;this.aabb=null;this.zip_aabb=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;let e=Ie._zpp;St.initFields(this),this.ibody=this,this.world=!1,this.bulletEnabled=!1,this.sweepTime=0,this.sweep_angvel=0,this.norotate=this.nomove=!1,this.disableCCD=!1,this.posx=0,this.posy=0,this.rot=0,this.axisx=0,this.axisy=1,this.svelx=0,this.svely=0,this.velx=0,this.vely=0,this.kinvelx=0,this.kinvely=0,this.forcex=0,this.forcey=0,this.torque=this.angvel=this.kinangvel=0,this.pre_posx=1/0,this.pre_posy=1/0,this.pre_rot=1/0,this.localCOMx=0,this.localCOMy=0,this.worldCOMx=0,this.worldCOMy=0,this.zip_aabb=!0;let t;be.zpp_pool==null?t=new be:(t=be.zpp_pool,be.zpp_pool=t.next,t.next=null),t.minx=0,t.miny=0,t.maxx=0,t.maxy=0,this.aabb=t,this.aabb._immutable=!0,this.aabb._validate=this.aabb_validate.bind(this),this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.arbiters=new e.util.ZNPList_ZPP_Arbiter,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.shapes=new e.util.ZNPList_ZPP_Shape,this.wrap_shapes=e.util.ZPP_ShapeList.get(this.shapes),this.wrap_shapes.zpp_inner.adder=this.shapes_adder.bind(this),this.wrap_shapes.zpp_inner.subber=this.shapes_subber.bind(this),this.wrap_shapes.zpp_inner._invalidate=this.shapes_invalidate.bind(this),this.wrap_shapes.zpp_inner._modifiable=this.shapes_modifiable.bind(this),this.kinematicDelaySleep=!1}static bodysetlt(e,t){return e.id<t.id}static __static(){let e=Ie._nape,t=Ie._zpp;t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new e.phys.BodyType,t.util.ZPP_Flags.internal=!1);let n=new e.phys.Body(t.util.ZPP_Flags.BodyType_STATIC),l=n.zpp_inner;return l.world=!0,l.wrap_shapes.zpp_inner.immutable=!0,l.smass=l.imass=l.cmass=l.mass=l.gravMass=0,l.sinertia=l.iinertia=l.cinertia=l.inertia=0,l.cbTypes.clear(),n}isStatic(){return this.type===1}isDynamic(){return this.type===2}isKinematic(){return this.type===3}invalidate_type(){this.invalidate_mass(),this.invalidate_inertia()}invalidate_shapes(){this.zip_aabb=!0,this.zip_localCOM=!0,this.zip_worldCOM=!0,this.invalidate_mass(),this.invalidate_inertia()}init_bodysetlist(){if(Ie.bodyset==null){let e=Ie._zpp;Ie.bodyset=new e.util.ZPP_Set_ZPP_Body,Ie.bodyset.lt=Ie.bodysetlt,Ie.bodystack=new e.util.ZNPList_ZPP_Body}}connectedBodies_cont(e){Ie.bodyset.try_insert_bool(e.zpp_inner)&&(Ie.bodystack.add(e.zpp_inner),e.zpp_inner.graph_depth=Ie.cur_graph_depth+1)}connectedBodies(e,t){let n=Ie._nape;Ie.bodyset==null&&this.init_bodysetlist();let l=t??new n.phys.BodyList;for(Ie.bodystack.add(this),Ie.bodyset.insert(this),this.graph_depth=0;Ie.bodystack.head!=null;){let i=Ie.bodystack.pop_unsafe();if(i.graph_depth===e)continue;Ie.cur_graph_depth=i.graph_depth;let o=i.constraints.head;for(;o!=null;)o.elt.outer.visitBodies(this.connectedBodies_cont.bind(this)),o=o.next}let s=Ie.bodyset;if(s.parent!=null){let i=s.parent;for(;i!=null;)if(i.prev!=null)i=i.prev;else if(i.next!=null)i=i.next;else{let o=i.data;if(o!==this){let p=o.outer;l.zpp_inner.reverse_flag?l.push(p):l.unshift(p)}let r=i.parent;r!=null&&(i===r.prev?r.prev=null:r.next=null,i.parent=null);let a=i;a.data=null,a.lt=null,a.next=Ie._zpp.util.ZPP_Set_ZPP_Body.zpp_pool,Ie._zpp.util.ZPP_Set_ZPP_Body.zpp_pool=a,i=r}s.parent=null}return l}interactingBodies(e,t){let n=Ie._nape,l=Ie._zpp;Ie.bodyset==null&&this.init_bodysetlist();let s=t??new n.phys.BodyList,i=this.arbiters.head;for(;i!=null;){let r=i.elt;if(!r.sleeping&&(e===4||r.type===e)){let a=r.b1===this?r.b2:r.b1;if(Ie.bodyset.try_insert_bool(a)){let p=a.outer;s.zpp_inner.reverse_flag?s.push(p):s.unshift(p)}}i=i.next}let o=Ie.bodyset;if(o.parent!=null){let r=o.parent;for(;r!=null;)if(r.prev!=null)r=r.prev;else if(r.next!=null)r=r.next;else{let a=r.parent;a!=null&&(r===a.prev?a.prev=null:a.next=null,r.parent=null);let p=r;p.data=null,p.lt=null,p.next=l.util.ZPP_Set_ZPP_Body.zpp_pool,l.util.ZPP_Set_ZPP_Body.zpp_pool=p,r=a}o.parent=null}return s}atRest(e){let t=Ie._nape;if(this.type!==2)return this.component.sleeping;let n=t.Config.linearSleepThreshold*t.Config.linearSleepThreshold,l;if(this.velx*this.velx+this.vely*this.vely>n)l=!1;else{let s=this.posx-this.pre_posx,i=this.posy-this.pre_posy;if(s*s+i*i>.25*n*e*e)l=!1;else{let o=this.aabb.maxx-this.aabb.minx,r=this.aabb.maxy-this.aabb.miny,a=o*o+r*r,p=t.Config.angularSleepThreshold*t.Config.angularSleepThreshold;if(4*this.angvel*this.angvel*a>p)l=!1;else{let c=this.rot-this.pre_rot;l=!(c*c*a>p*e*e)}}}return l||(this.component.waket=this.space.stamp),this.component.waket+t.Config.sleepDelay<this.space.stamp}refreshArbiters(){let e=this.arbiters.head;for(;e!=null;){let t=e.elt;t.invalidated=!0,e=e.next}}sweepIntegrate(e){let t=e-this.sweepTime;if(t!==0&&(this.sweepTime=e,this.posx+=this.velx*t,this.posy+=this.vely*t,this.angvel!==0)){let n=this.sweep_angvel*t;if(this.rot+=n,n*n>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let l=n*n,s=1-.5*l,i=1-l*l/8,o=(s*this.axisx+n*this.axisy)*i;this.axisy=(s*this.axisy-n*this.axisx)*i,this.axisx=o}}}sweepValidate(e){if(e.type===0)e.worldCOMx=this.posx+(this.axisy*e.localCOMx-this.axisx*e.localCOMy),e.worldCOMy=this.posy+(e.localCOMx*this.axisx+e.localCOMy*this.axisy);else{let t=e.polygon,n=t.lverts.next,l=t.gverts.next;for(;l!=null;){let p=l,c=n;n=n.next,p.x=this.posx+(this.axisy*c.x-this.axisx*c.y),p.y=this.posy+(c.x*this.axisx+c.y*this.axisy),l=l.next}let s=t.edges.head,i=t.gverts.next,o=i;for(i=i.next;i!=null;){let p=i,c=s.elt;s=s.next,c.gnormx=this.axisy*c.lnormx-this.axisx*c.lnormy,c.gnormy=c.lnormx*this.axisx+c.lnormy*this.axisy,c.gprojection=this.posx*c.gnormx+this.posy*c.gnormy+c.lprojection,c.tp0=o.y*c.gnormx-o.x*c.gnormy,c.tp1=p.y*c.gnormx-p.x*c.gnormy,o=p,i=i.next}let r=t.gverts.next,a=s.elt;a.gnormx=this.axisy*a.lnormx-this.axisx*a.lnormy,a.gnormy=a.lnormx*this.axisx+a.lnormy*this.axisy,a.gprojection=this.posx*a.gnormx+this.posy*a.gnormy+a.lprojection,a.tp0=o.y*a.gnormx-o.x*a.gnormy,a.tp1=r.y*a.gnormx-r.x*a.gnormy}}invalidate_pos(){let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}pos_invalidate(e){if(this.immutable_midstep("Body::position"),this.type===1&&this.space!=null)throw new Error("Error: Cannot move a static object once inside a Space");this.posx===e.x&&this.posy===e.y||(this.posx=e.x,this.posy=e.y,this.invalidate_pos(),this.wake())}pos_validate(){this.wrap_pos.zpp_inner.x=this.posx,this.wrap_pos.zpp_inner.y=this.posy}vel_invalidate(e){if(this.type===1)throw new Error("Error: Static body cannot have its velocity set.");this.velx=e.x,this.vely=e.y,this.wake()}vel_validate(){this.wrap_vel.zpp_inner.x=this.velx,this.wrap_vel.zpp_inner.y=this.vely}kinvel_invalidate(e){this.kinvelx=e.x,this.kinvely=e.y,this.wake()}kinvel_validate(){this.wrap_kinvel.zpp_inner.x=this.kinvelx,this.wrap_kinvel.zpp_inner.y=this.kinvely}svel_invalidate(e){this.svelx=e.x,this.svely=e.y,this.wake()}svel_validate(){this.wrap_svel.zpp_inner.x=this.svelx,this.wrap_svel.zpp_inner.y=this.svely}force_invalidate(e){if(this.type!==2)throw new Error("Error: Non-dynamic body cannot have force applied.");this.forcex=e.x,this.forcey=e.y,this.wake()}force_validate(){this.wrap_force.zpp_inner.x=this.forcex,this.wrap_force.zpp_inner.y=this.forcey}_setupVec2Wrapper(e,t,n,l){let s=Ie._nape;if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(de.poolVec2==null?i=new s.geom.Vec2:(i=de.poolVec2,de.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i===de.nextVec2&&(de.nextVec2=null)),i.zpp_inner==null){let o;le.zpp_pool==null?o=new le:(o=le.zpp_pool,le.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=e,o.y=t,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let r;i.zpp_inner._validate!=null&&i.zpp_inner._validate(),i.zpp_inner.x===e?(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),r=i.zpp_inner.y===t):r=!1,r||(i.zpp_inner.x=e,i.zpp_inner.y=t,i.zpp_inner._invalidate!=null&&i.zpp_inner._invalidate(i.zpp_inner))}return i.zpp_inner.weak=!1,i}setupPosition(){this.wrap_pos=this._setupVec2Wrapper(this.posx,this.posy,null,null),this.wrap_pos.zpp_inner._inuse=!0,this.world?this.wrap_pos.zpp_inner._immutable=!0:(this.wrap_pos.zpp_inner._invalidate=this.pos_invalidate.bind(this),this.wrap_pos.zpp_inner._validate=this.pos_validate.bind(this))}setupVelocity(){this.wrap_vel=this._setupVec2Wrapper(this.velx,this.vely,null,null),this.wrap_vel.zpp_inner._inuse=!0,this.world?this.wrap_vel.zpp_inner._immutable=!0:(this.wrap_vel.zpp_inner._invalidate=this.vel_invalidate.bind(this),this.wrap_vel.zpp_inner._validate=this.vel_validate.bind(this))}setupkinvel(){this.wrap_kinvel=this._setupVec2Wrapper(this.kinvelx,this.kinvely,null,null),this.wrap_kinvel.zpp_inner._inuse=!0,this.world?this.wrap_kinvel.zpp_inner._immutable=!0:(this.wrap_kinvel.zpp_inner._invalidate=this.kinvel_invalidate.bind(this),this.wrap_kinvel.zpp_inner._validate=this.kinvel_validate.bind(this))}setupsvel(){this.wrap_svel=this._setupVec2Wrapper(this.svelx,this.svely,null,null),this.wrap_svel.zpp_inner._inuse=!0,this.world?this.wrap_svel.zpp_inner._immutable=!0:(this.wrap_svel.zpp_inner._invalidate=this.svel_invalidate.bind(this),this.wrap_svel.zpp_inner._validate=this.svel_validate.bind(this))}setupForce(){this.wrap_force=this._setupVec2Wrapper(this.forcex,this.forcey,null,null),this.wrap_force.zpp_inner._inuse=!0,this.world?this.wrap_force.zpp_inner._immutable=!0:(this.wrap_force.zpp_inner._invalidate=this.force_invalidate.bind(this),this.wrap_force.zpp_inner._validate=this.force_validate.bind(this))}cvel_validate(){this.wrapcvel.zpp_inner.x=this.velx+this.kinvelx,this.wrapcvel.zpp_inner.y=this.vely+this.kinvely}setup_cvel(){this.wrapcvel=this._setupVec2Wrapper(this.velx+this.kinvelx,this.vely+this.kinvely,null,null),this.wrapcvel.zpp_inner._inuse=!0,this.wrapcvel.zpp_inner._immutable=!0,this.wrapcvel.zpp_inner._validate=this.cvel_validate.bind(this)}invalidate_rot(){this.zip_axis=!0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}validate_axis(){this.zip_axis&&(this.zip_axis=!1,this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}quick_validate_axis(){this.zip_axis&&(this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}delta_rot(e){if(e*e>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let t=e*e,n=1-.5*t,l=1-t*t/8,s=(n*this.axisx+e*this.axisy)*l;this.axisy=(n*this.axisy-e*this.axisx)*l,this.axisx=s}this.zip_axis=!1}invalidate_mass(){this.zip_mass=!0,this.invalidate_gravMass()}validate_mass(){if(this.zip_mass||this.massMode===0&&!1){if(this.zip_mass=!1,this.massMode===0){this.cmass=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cmass+=n.area*n.material.density,t=t.next}}this.type===2&&!this.nomove?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0)}}invalidate_gravMass(){this.gravMassMode!==1&&(this.zip_gravMass=!0),this.gravMassMode!==2&&(this.zip_gravMassScale=!0),this.wake()}validate_gravMass(){this.zip_gravMass&&(this.zip_gravMass=!1,this.validate_mass(),this.gravMassMode===0?(this.validate_mass(),this.gravMass=this.cmass):this.gravMassMode===2&&(this.validate_mass(),this.gravMass=this.cmass*this.gravMassScale))}invalidate_gravMassScale(){this.gravMassMode!==2?this.zip_gravMassScale=!0:this.invalidate_gravMass()}validate_gravMassScale(){this.zip_gravMassScale&&(this.zip_gravMassScale=!1,this.gravMassMode===0?this.gravMassScale=1:this.gravMassMode===1&&(this.validate_mass(),this.gravMassScale=this.gravMass/this.cmass))}invalidate_inertia(){this.zip_inertia=!0,this.wake()}validate_inertia(){if(this.zip_inertia||this.inertiaMode===0&&!1){if(this.zip_inertia=!1,this.inertiaMode===0){this.cinertia=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cinertia+=n.inertia*n.area*n.material.density,t=t.next}}this.type===2&&!this.norotate?(this.inertia=this.cinertia,this.sinertia=this.iinertia=1/this.inertia):(this.inertia=1/0,this.sinertia=this.iinertia=0)}}invalidate_wake(){this.wake()}invalidate_aabb(){this.zip_aabb=!0}validate_aabb(){if(this.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(this.zip_aabb){this.zip_aabb=!1,this.aabb.minx=1/0,this.aabb.miny=1/0,this.aabb.maxx=-1/0,this.aabb.maxy=-1/0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.zip_aabb&&t.body!=null&&(t.zip_aabb=!1,t.type===0?this._validateCircleAABB(t.circle):this._validatePolygonAABB(t.polygon)),t.aabb.minx<this.aabb.minx&&(this.aabb.minx=t.aabb.minx),t.aabb.maxx>this.aabb.maxx&&(this.aabb.maxx=t.aabb.maxx),t.aabb.miny<this.aabb.miny&&(this.aabb.miny=t.aabb.miny),t.aabb.maxy>this.aabb.maxy&&(this.aabb.maxy=t.aabb.maxy),e=e.next}}}_validateCircleAABB(e){e.zip_worldCOM&&e.body!=null&&(e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type===1&&this._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)),this.validate_axis(),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy));let t=e.radius;e.aabb.minx=e.worldCOMx-t,e.aabb.miny=e.worldCOMy-t,e.aabb.maxx=e.worldCOMx+t,e.aabb.maxy=e.worldCOMy+t}_validatePolygonAABB(e){if(e.zip_gverts&&e.body!=null){e.zip_gverts=!1,e.validate_lverts(),this.validate_axis();let l=e.lverts.next,s=e.gverts.next;for(;s!=null;){let i=s,o=l;l=l.next,i.x=e.body.posx+(e.body.axisy*o.x-e.body.axisx*o.y),i.y=e.body.posy+(o.x*e.body.axisx+o.y*e.body.axisy),s=s.next}}if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let t=e.gverts.next;e.aabb.minx=t.x,e.aabb.miny=t.y,e.aabb.maxx=t.x,e.aabb.maxy=t.y;let n=e.gverts.next.next;for(;n!=null;){let l=n;l.x<e.aabb.minx&&(e.aabb.minx=l.x),l.x>e.aabb.maxx&&(e.aabb.maxx=l.x),l.y<e.aabb.miny&&(e.aabb.miny=l.y),l.y>e.aabb.maxy&&(e.aabb.maxy=l.y),n=n.next}}aabb_validate(){if(this.shapes.head==null)throw new Error("Error: bounds only makes sense when Body has shapes");this.validate_aabb()}invalidate_localCOM(){this.zip_localCOM=!0,this.zip_worldCOM=!0}invalidate_worldCOM(){this.zip_worldCOM=!0}_computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y,e.localCOMx+=e.lverts.next.next.x,e.localCOMy+=e.lverts.next.next.y,e.localCOMx*=.5,e.localCOMy*=.5;else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,l=n;n=n.next;let s=n;for(n=n.next;n!=null;){let p=n;t+=s.x*(p.y-l.y);let c=p.y*s.x-p.x*s.y;e.localCOMx+=(s.x+p.x)*c,e.localCOMy+=(s.y+p.y)*c,l=s,s=p,n=n.next}n=e.lverts.next;let i=n;t+=s.x*(i.y-l.y);let o=i.y*s.x-i.x*s.y;e.localCOMx+=(s.x+i.x)*o,e.localCOMy+=(s.y+i.y)*o,l=s,s=i,n=n.next;let r=n;t+=s.x*(r.y-l.y);let a=r.y*s.x-r.x*s.y;e.localCOMx+=(s.x+r.x)*a,e.localCOMy+=(s.y+r.y)*a,t=1/(3*t),e.localCOMx*=t,e.localCOMy*=t}}validate_localCOM(){if(this.zip_localCOM){this.zip_localCOM=!1;let e=0,t=0,n=0,l=this.shapes.head;for(;l!=null;){let s=l.elt;s.zip_localCOM&&(s.zip_localCOM=!1,s.type===1&&this._computePolygonLocalCOM(s.polygon),s.wrap_localCOM!=null&&(s.wrap_localCOM.zpp_inner.x=s.localCOMx,s.wrap_localCOM.zpp_inner.y=s.localCOMy)),s.validate_area_inertia();let i=s.area*s.material.density;e+=s.localCOMx*i,t+=s.localCOMy*i,n+=s.area*s.material.density,l=l.next}if(n!==0){let s=1/n;this.localCOMx=e*s,this.localCOMy=t*s}this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy),this.zip_mass&&this.massMode===0&&(this.zip_mass=!1,this.cmass=n,this.type===2?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0))}}validate_worldCOM(){this.zip_worldCOM&&(this.zip_worldCOM=!1,this.validate_localCOM(),this.validate_axis(),this.worldCOMx=this.posx+(this.axisy*this.localCOMx-this.axisx*this.localCOMy),this.worldCOMy=this.posy+(this.localCOMx*this.axisx+this.localCOMy*this.axisy)),this.wrap_worldCOM!=null&&(this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy)}getlocalCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its localCOM");this.validate_localCOM()}getworldCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its worldCOM");this.validate_worldCOM()}__immutable_midstep(){if(this.world)throw new Error("Error: Space::world is immutable")}clear(){if(this.space!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a Space!");if(this.constraints.head!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a constraint!");for(;this.shapes.head!=null;){let t=this.shapes.pop_unsafe();t.removedFromBody(),t.body=null}this.invalidate_shapes(),this.pre_posx=0,this.pre_posy=0,this.posx=0,this.posy=0,this.velx=0,this.vely=0,this.forcex=0,this.forcey=0,this.kinvelx=0,this.kinvely=0,this.svelx=0,this.svely=0,this.angvel=this.torque=this.kinangvel=this.pre_rot=this.rot=0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}for(this.zip_worldCOM=!0,this.zip_axis=!0,e=this.shapes.head;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0,this.axisx=0,this.axisy=1,this.zip_axis=!1,this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.norotate=!1,this.nomove=!1}shapes_adder(e){if(e.zpp_inner.body!==this){if(e.zpp_inner.body!=null&&e.zpp_inner.body.wrap_shapes.remove(e),e.zpp_inner.body=this,e.zpp_inner.addedToBody(),this.space!=null){let t=this.space,n=e.zpp_inner,l=n.body;l.world||(l.component.waket=t.stamp+(t.midstep?0:1),l.type===3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&t.really_wake(l,!1)),t.bphase.insert(n),n.addedToSpace()}return e.zpp_inner.type===1&&(e.zpp_inner.polygon.invalidate_gaxi(),e.zpp_inner.polygon.invalidate_gverts()),!0}else return!1}shapes_subber(e){this.space!=null&&this.space.removed_shape(e.zpp_inner),e.zpp_inner.body=null,e.zpp_inner.removedFromBody()}shapes_invalidate(e){this.invalidate_shapes()}shapes_modifiable(){if(this.immutable_midstep("Body::shapes"),this.type===1&&this.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}addedToSpace(){let e=Ie._zpp,t;e.space.ZPP_Component.zpp_pool==null?t=new e.space.ZPP_Component:(t=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t.next,t.next=null),t.isBody=!0,t.body=this,this.component=t,this.__iaddedToSpace()}removedFromSpace(){let e=Ie._zpp;for(;this.arbiters.head!=null;){let n=this.arbiters.pop_unsafe(),l=this.space;n.cleared=!0,n.b2===this&&this._removeArbiterFromList(n.b1.arbiters,n,e),n.b1===this&&this._removeArbiterFromList(n.b2.arbiters,n,e),n.pair!=null&&(n.pair.arb=null,n.pair=null),n.active=!1,l.f_arbiters.modified=!0}let t=this.component;t.body=null,t.constraint=null,t.next=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t,this.component=null,this.__iremovedFromSpace()}_removeArbiterFromList(e,t,n){let l=null,s=e.head;for(;s!=null;){if(s.elt===t){let i;l==null?(i=e.head,e.head=i.next,e.head==null&&(e.pushmod=!0)):(i=l.next,l.next=i.next,i.next==null&&(e.pushmod=!0));let o=i;o.elt=null,o.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=o,e.modified=!0,e.length--,e.pushmod=!0;break}l=s,s=s.next}}copy(){let e=Ie._nape,t=new e.phys.Body().zpp_inner;t.type=this.type,t.bulletEnabled=this.bulletEnabled,t.disableCCD=this.disableCCD;let n=this.shapes.head;for(;n!=null;){let l=n.elt,s=t.outer.zpp_inner.wrap_shapes,i=l.outer.copy();s.zpp_inner.reverse_flag?s.push(i):s.unshift(i),n=n.next}if(t.posx=this.posx,t.posy=this.posy,t.velx=this.velx,t.vely=this.vely,t.forcex=this.forcex,t.forcey=this.forcey,t.rot=this.rot,t.angvel=this.angvel,t.torque=this.torque,t.kinvelx=this.kinvelx,t.kinvely=this.kinvely,t.kinangvel=this.kinangvel,t.svelx=this.svelx,t.svely=this.svely,!this.zip_axis)t.axisx=this.axisx,t.axisy=this.axisy;else{t.zip_axis=!0;let l=t.shapes.head;for(;l!=null;){let s=l.elt;s.type===1&&(s.polygon.invalidate_gverts(),s.polygon.invalidate_gaxi()),s.invalidate_worldCOM(),l=l.next}t.zip_worldCOM=!0}return t.rot=this.rot,t.massMode=this.massMode,t.gravMassMode=this.gravMassMode,t.inertiaMode=this.inertiaMode,t.norotate=this.norotate,t.nomove=this.nomove,t.cmass=this.cmass,t.cinertia=this.cinertia,this.zip_mass?t.invalidate_mass():t.mass=this.mass,this.zip_gravMass?t.invalidate_gravMass():t.gravMass=this.gravMass,this.zip_gravMassScale?t.invalidate_gravMassScale():t.gravMassScale=this.gravMassScale,this.zip_inertia?t.invalidate_inertia():t.inertia=this.inertia,this.zip_aabb?t.zip_aabb=!0:(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy),this.zip_localCOM?(t.zip_localCOM=!0,t.zip_worldCOM=!0):(t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy),this.zip_worldCOM?t.zip_worldCOM=!0:(t.worldCOMx=this.worldCOMx,t.worldCOMy=this.worldCOMy),this.copyto(t.outer),t.outer}static _init(e,t){if(!Ie._initialized){Ie._initialized=!0,Ie._zpp=e,Ie._nape=t,Ie.__super__=St;for(let n of Object.getOwnPropertyNames(St.prototype))n!=="constructor"&&n!=="__class__"&&!(n in Ie.prototype)&&(Ie.prototype[n]=St.prototype[n])}}static _initEnums(e,t){let n=()=>{t.internal=!0;let l=new e.phys.BodyType;return t.internal=!1,l};t.BodyType_STATIC==null&&(t.BodyType_STATIC=n()),t.BodyType_DYNAMIC==null&&(t.BodyType_DYNAMIC=n()),t.BodyType_KINEMATIC==null&&(t.BodyType_KINEMATIC=n()),Ie.types=[null,t.BodyType_STATIC,t.BodyType_DYNAMIC,t.BodyType_KINEMATIC]}};Ie.__name__=["zpp_nape","phys","ZPP_Body"],Ie.__super__=null,Ie._nape=null,Ie._zpp=null,Ie.types=[],Ie.bodystack=null,Ie.bodyset=null,Ie.cur_graph_depth=0,Ie._initialized=!1;var kn=Ie;var Lt=class Lt{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.bodies=null;this.constraints=null;this.compounds=null;this.wrap_bodies=null;this.wrap_constraints=null;this.wrap_compounds=null;this.depth=0;this.compound=null;this.space=null;let e=Lt._zpp;St.initFields(this),this.icompound=this,this.depth=1,this.bodies=new e.util.ZNPList_ZPP_Body,this.wrap_bodies=e.util.ZPP_BodyList.get(this.bodies),this.wrap_bodies.zpp_inner.adder=this.bodies_adder.bind(this),this.wrap_bodies.zpp_inner.subber=this.bodies_subber.bind(this),this.wrap_bodies.zpp_inner._modifiable=this.bodies_modifiable.bind(this),this.constraints=new e.util.ZNPList_ZPP_Constraint,this.wrap_constraints=e.util.ZPP_ConstraintList.get(this.constraints),this.wrap_constraints.zpp_inner.adder=this.constraints_adder.bind(this),this.wrap_constraints.zpp_inner.subber=this.constraints_subber.bind(this),this.wrap_constraints.zpp_inner._modifiable=this.constraints_modifiable.bind(this),this.compounds=new e.util.ZNPList_ZPP_Compound,this.wrap_compounds=e.util.ZPP_CompoundList.get(this.compounds),this.wrap_compounds.zpp_inner.adder=this.compounds_adder.bind(this),this.wrap_compounds.zpp_inner.subber=this.compounds_subber.bind(this),this.wrap_compounds.zpp_inner._modifiable=this.compounds_modifiable.bind(this)}__imutable_midstep(e){if(this.space!=null&&this.space.midstep)throw new Error("Error: "+e+" cannot be set during space step()")}addedToSpace(){this.__iaddedToSpace()}removedFromSpace(){this.__iremovedFromSpace()}breakApart(){for(this.space!=null&&(this.__iremovedFromSpace(),this.space.nullInteractorType(this)),this.compound!=null?this.compound.compounds.remove(this):this.space!=null&&this.space.compounds.remove(this);this.bodies.head!=null;){let e=this.bodies.pop_unsafe();(e.compound=this.compound)!=null?this.compound.bodies.add(e):this.space!=null&&this.space.bodies.add(e),this.space!=null&&this.space.freshInteractorType(e)}for(;this.constraints.head!=null;){let e=this.constraints.pop_unsafe();(e.compound=this.compound)!=null?this.compound.constraints.add(e):this.space!=null&&this.space.constraints.add(e)}for(;this.compounds.head!=null;){let e=this.compounds.pop_unsafe();(e.compound=this.compound)!=null?this.compound.compounds.add(e):this.space!=null&&this.space.compounds.add(e),this.space!=null&&this.space.freshInteractorType(e)}this.compound=null,this.space=null}static _zppOf(e){return e.zpp_inner??e._inner?.zpp_inner??e._inner}bodies_adder(e){let t=Lt._zppOf(e);return t.compound!==this?(t.compound!=null?t.compound.wrap_bodies.remove(e):t.space!=null&&t.space.wrap_bodies.remove(e),t.compound=this,this.space!=null&&this.space.addBody(t),!0):!1}bodies_subber(e){let t=Lt._zppOf(e);t.compound=null,this.space!=null&&this.space.remBody(t)}bodies_modifiable(){this.immutable_midstep("Compound::bodies")}constraints_adder(e){let t=Lt._zppOf(e);return t.compound!==this?(t.compound!=null?t.compound.wrap_constraints.remove(e):t.space!=null&&t.space.wrap_constraints.remove(e),t.compound=this,this.space!=null&&this.space.addConstraint(t),!0):!1}constraints_subber(e){let t=Lt._zppOf(e);t.compound=null,this.space!=null&&this.space.remConstraint(t)}constraints_modifiable(){this.immutable_midstep("Compound::constraints")}compounds_adder(e){let t=Lt._zppOf(e),n=this;for(;n!=null&&n!==t;)n=n.compound;if(n===t)throw new Error("Error: Assignment would cause a cycle in the Compound tree: assigning "+e.toString()+".compound = "+this.outer.toString());return t.compound!==this?(t.compound!=null?t.compound.wrap_compounds.remove(e):t.space!=null&&t.space.wrap_compounds.remove(e),t.compound=this,t.depth=this.depth+1,this.space!=null&&this.space.addCompound(t),!0):!1}compounds_subber(e){let t=Lt._zppOf(e);t.compound=null,t.depth=1,this.space!=null&&this.space.remCompound(t)}compounds_modifiable(){this.immutable_midstep("Compound::compounds")}copy(e,t){let n=Lt._nape,l=Lt._zpp,s=e==null;e==null&&(e=[]),t==null&&(t=[]);let i=new n.phys.Compound,o=this.compounds.head;for(;o!=null;){let c=o.elt.copy(e,t);if(c.zpp_inner.immutable_midstep("Compound::compound"),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==i&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_compounds.remove(c),i!=null)){let u=i.zpp_inner.wrap_compounds;u.zpp_inner.reverse_flag?u.push(c):u.unshift(c)}o=o.next}let r=this.bodies.head;for(;r!=null;){let p=r.elt,c=p.outer.copy();if(e.push(l.constraint.ZPP_CopyHelper.dict(p.id,c)),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==i&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_bodies.remove(c),i!=null)){let u=i.zpp_inner.wrap_bodies;u.zpp_inner.reverse_flag?u.push(c):u.unshift(c)}r=r.next}let a=this.constraints.head;for(;a!=null;){let c=a.elt.copy(e,t);if((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==i&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_constraints.remove(c),i!=null)){let u=i.zpp_inner.wrap_constraints;u.zpp_inner.reverse_flag?u.push(c):u.unshift(c)}a=a.next}if(s)for(;t.length>0;){let p=t.pop();for(let c=0;c<e.length;c++){let u=e[c];if(u.id===p.id){p.cb(u.bc);break}}}return this.copyto(i),i}static _init(){Lt.__super__=St;for(let e of Object.getOwnPropertyNames(St.prototype))e!=="constructor"&&e!=="__class__"&&!Object.prototype.hasOwnProperty.call(Lt.prototype,e)&&(Lt.prototype[e]=St.prototype[e])}};Lt.__name__=["zpp_nape","phys","ZPP_Compound"],Lt.__super__=null,Lt._nape=null,Lt._zpp=null,Lt._wrapFn=null;var Rn=Lt;var At=class At{constructor(){this.viscosity=1;this.density=1;this.gravityx=0;this.gravityy=0;this.wrap_gravity=null;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new At._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(At._wrapFn)this.outer=At._wrapFn(this);else{this.outer=new At._nape.phys.FluidProperties;let e=this.outer.zpp_inner;e.outer=null,e.next=At.zpp_pool,At.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new At._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return At.zpp_pool==null?e=new At:(e=At.zpp_pool,At.zpp_pool=e.next,e.next=null),e.viscosity=this.viscosity,e.density=this.density,e}gravity_invalidate(e){this.gravityx=e.x,this.gravityy=e.y,this.invalidate()}gravity_validate(){this.wrap_gravity.zpp_inner.x=this.gravityx,this.wrap_gravity.zpp_inner.y=this.gravityy}getgravity(){let e=At._zpp,t=At._nape,n=this.gravityx??0,l=this.gravityy??0;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let o=!1;i._validate!=null&&i._validate(),(i.x!==n||i.y!==l)&&(o=!0),o&&(i.x=n,i.y=l,i._invalidate!=null&&i._invalidate(i))}s.zpp_inner.weak=!1,this.wrap_gravity=s,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=this.gravity_invalidate.bind(this),this.wrap_gravity.zpp_inner._validate=this.gravity_validate.bind(this)}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_fluidprops(),e=e.next}};At.zpp_pool=null,At.__name__=["zpp_nape","phys","ZPP_FluidProperties"],At._nape=null,At._zpp=null,At._wrapFn=null;var En=At;var Dt=class Dt{constructor(){this.elasticity=0;this.dynamicFriction=1;this.staticFriction=2;this.density=.001;this.rollingFriction=.01;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new Dt._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Dt._wrapFn)this.outer=Dt._wrapFn(this);else{this.outer=new Dt._nape.phys.Material;let e=this.outer.zpp_inner;e.outer=null,e.next=Dt.zpp_pool,Dt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Dt._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e=new Dt;return e.dynamicFriction=this.dynamicFriction,e.staticFriction=this.staticFriction,e.density=this.density,e.elasticity=this.elasticity,e.rollingFriction=this.rollingFriction,e}set(e){this.dynamicFriction=e.dynamicFriction,this.staticFriction=e.staticFriction,this.density=e.density,this.elasticity=e.elasticity,this.rollingFriction=e.rollingFriction}invalidate(e){let t=this.shapes.head;for(;t!=null;)t.elt.invalidate_material(e),t=t.next}};Dt.zpp_pool=null,Dt.WAKE=1,Dt.PROPS=2,Dt.ANGDRAG=4,Dt.ARBITERS=8,Dt.__name__=["zpp_nape","phys","ZPP_Material"],Dt._nape=null,Dt._zpp=null,Dt._wrapFn=null;var Ve=Dt;var ln=class ln{constructor(e){this.outer=null;this.body=null;this.type=0;this.area=0;this.zip_area_inertia=!1;this.inertia=0;this.angDrag=0;this.zip_angDrag=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;this.sweepRadius=0;this.zip_sweepRadius=!1;this.sweepCoef=0;this.circle=null;this.polygon=null;this.refmaterial=null;this.material=null;this.filter=null;this.fluidProperties=null;this.fluidEnabled=!1;this.sensorEnabled=!1;this.sweep=null;this.node=null;this.pairs=null;this.aabb=null;this.zip_aabb=!1;this.ishape=null;this.userData=null;e!==void 0&&this._initShape(e)}static _initEnums(e,t){let n=()=>{t.internal=!0;let l=new e.shape.ShapeType;return t.internal=!1,l};t.ShapeType_CIRCLE==null&&(t.ShapeType_CIRCLE=n()),t.ShapeType_POLYGON==null&&(t.ShapeType_POLYGON=n()),ln.types=[t.ShapeType_CIRCLE,t.ShapeType_POLYGON]}_initShape(e){let t=ln._zpp;St.initFields(this),this.pairs=new t.util.ZNPList_ZPP_AABBPair,this.ishape=this,this.type=e;let n;be.zpp_pool==null?n=new be:(n=be.zpp_pool,be.zpp_pool=n.next,n.next=null),n.minx=0,n.miny=0,n.maxx=0,n.maxy=0,this.aabb=n,this.aabb._immutable=!0,this.aabb._validate=this.aabb_validate.bind(this),this.zip_area_inertia=this.zip_angDrag=this.zip_localCOM=this.zip_sweepRadius=!0,this.localCOMx=0,this.localCOMy=0,this.worldCOMx=0,this.worldCOMy=0,this.fluidEnabled=!1,this.sensorEnabled=!1,this.fluidProperties=null,this.body=null,this.refmaterial=new Ve,this.sweepRadius=this.sweepCoef=0}static _init(){if(!ln._initialized){ln._initialized=!0,ln.__super__=St;for(let e of Object.getOwnPropertyNames(St.prototype))e!=="constructor"&&e!=="__class__"&&!Object.prototype.hasOwnProperty.call(ln.prototype,e)&&(ln.prototype[e]=St.prototype[e])}}isCircle(){return this.type===0}isPolygon(){return this.type===1}invalidate_sweepRadius(){this.zip_sweepRadius=!0}validate_sweepRadius(){this.zip_sweepRadius&&(this.zip_sweepRadius=!1,this.type===0?this.circle.__validate_sweepRadius():this.polygon.__validate_sweepRadius())}clear(){this.type===0?this.circle.__clear():this.polygon.__clear()}validate_aabb(){this.zip_aabb&&this.body!=null&&(this.zip_aabb=!1,this.type===0?this.circle.__validate_aabb():this.polygon.__validate_aabb())}force_validate_aabb(){this.type===0?this.circle._force_validate_aabb():this.polygon._force_validate_aabb()}invalidate_aabb(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}validate_area_inertia(){this.zip_area_inertia&&(this.zip_area_inertia=!1,this.type===0?this.circle.__validate_area_inertia():this.polygon.__validate_area_inertia())}validate_angDrag(){(this.zip_angDrag||this.refmaterial.dynamicFriction!==this.material.dynamicFriction)&&(this.zip_angDrag=!1,this.refmaterial.dynamicFriction=this.material.dynamicFriction,this.type===0?this.circle.__validate_angDrag():this.polygon.__validate_angDrag())}validate_localCOM(){this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy))}validate_worldCOM(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.validate_localCOM();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy)}}getworldCOM(){if(this.body==null)throw new Error("Error: worldCOM only makes sense when Shape belongs to a Body");this.validate_worldCOM(),this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy}invalidate_area_inertia(){this.zip_area_inertia=!0,this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia())}invalidate_angDrag(){this.zip_angDrag=!0}invalidate_localCOM(){this.zip_localCOM=!0,this.invalidate_area_inertia(),this.type===0&&(this.zip_sweepRadius=!0),this.invalidate_angDrag(),this.invalidate_worldCOM(),this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0)}invalidate_worldCOM(){this.zip_worldCOM=!0,this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}invalidate_material(e){(e&Ve.WAKE)!==0&&this.wake(),(e&Ve.ARBITERS)!==0&&this.body!=null&&this.body.refreshArbiters(),(e&Ve.PROPS)!==0&&this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia()),(e&Ve.ANGDRAG)!==0&&this.invalidate_angDrag(),this.refmaterial.set(this.material)}invalidate_filter(){this.wake()}invalidate_fluidprops(){this.fluidEnabled&&this.wake()}aabb_validate(){if(this.body==null)throw new Error("Error: bounds only makes sense when Shape belongs to a Body");this.validate_aabb()}setMaterial(e){this.material!==e&&(this.body!=null&&this.body.space!=null&&this.material!=null&&this.material.shapes.remove(this),this.material=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake(),this.body!=null&&this.body.refreshArbiters())}setFilter(e){this.filter!==e&&(this.body!=null&&this.body.space!=null&&this.filter!=null&&this.filter.shapes.remove(this),this.filter=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake())}setFluid(e){this.fluidProperties!==e&&(this.body!=null&&this.body.space!=null&&this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this),this.fluidProperties=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.fluidEnabled&&this.wake())}__immutable_midstep(e){if(this.body!=null&&this.body.space!=null&&this.body.space.midstep)throw new Error("Error: "+e+" cannot be set during a space step()")}addedToBody(){this.invalidate_worldCOM(),this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}removedFromBody(){}addedToSpace(){this.__iaddedToSpace(),this.material.shapes.add(this),this.filter.shapes.add(this),this.fluidProperties!=null&&this.fluidProperties.shapes.add(this)}removedFromSpace(){this.__iremovedFromSpace(),this.material.shapes.remove(this),this.filter.shapes.remove(this),this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this)}copy(){let e=ln._zpp,t=this.type===0?this.circle.__copy():this.polygon.__copy();this.zip_area_inertia?t.invalidate_area_inertia():(t.area=this.area,t.inertia=this.inertia),this.zip_sweepRadius?t.zip_sweepRadius=!0:(t.sweepRadius=this.sweepRadius,t.sweepCoef=this.sweepCoef),this.zip_angDrag?t.invalidate_angDrag():t.angDrag=this.angDrag,this.zip_aabb?(t.zip_aabb=!0,t.body!=null&&(t.body.zip_aabb=!0)):(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy);let n=t.material;n.outer=null,n.next=Ve.zpp_pool,Ve.zpp_pool=n;let l=t.filter;return l.outer=null,l.next=e.dynamics.ZPP_InteractionFilter.zpp_pool,e.dynamics.ZPP_InteractionFilter.zpp_pool=l,t.material=this.material,t.filter=this.filter,this.fluidProperties!=null&&(t.fluidProperties=this.fluidProperties),t.fluidEnabled=this.fluidEnabled,t.sensorEnabled=this.sensorEnabled,this.userData!=null&&(t.userData=Object.assign({},this.userData)),this.copyto(t.outer),t.outer}};ln.__name__=["zpp_nape","shape","ZPP_Shape"],ln.__super__=null,ln._nape=null,ln._zpp=null,ln.types=[],ln._initialized=!1;var xi=ln;var on=class on{constructor(){this.radius=0;this.outer_zn=null;this.radius=0,this.outer_zn=null,this._initShape(0),this.circle=this,this.zip_localCOM=!1}static _init(){if(on._initialized)return;on._initialized=!0;let e=on._zpp;on.__super__=e.shape.ZPP_Shape;let t=e.shape.ZPP_Shape.prototype,n=on.prototype;for(let l in t)l!=="__class__"&&!Object.prototype.hasOwnProperty.call(n,l)&&(n[l]=t[l]);for(let l of Object.getOwnPropertyNames(t))l!=="constructor"&&l!=="__class__"&&!Object.prototype.hasOwnProperty.call(n,l)&&(n[l]=t[l])}__clear(){}invalidate_radius(){this.invalidate_area_inertia(),this.invalidate_angDrag(),this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0),this.body!=null&&this.body.wake()}localCOM_validate(){this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy}localCOM_invalidate(e){this.localCOMx=e.x,this.localCOMy=e.y,this.invalidate_localCOM(),this.body!=null&&this.body.wake()}localCOM_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify localCOM of Circle added to a static Body whilst within a Space")}setupLocalCOM(){let e=on._zpp,t=on._nape,n=this.localCOMx,l=this.localCOMy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,this.wrap_localCOM=s,this.wrap_localCOM.zpp_inner._inuse=!0,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this),this.wrap_localCOM.zpp_inner._isimmutable=this.localCOM_immutable.bind(this)}__validate_aabb(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy));let n=this.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),this.worldCOMx=n.posx+(n.axisy*this.localCOMx-n.axisx*this.localCOMy),this.worldCOMy=n.posy+(this.localCOMx*n.axisx+this.localCOMy*n.axisy)}let e=this.radius,t=this.radius;this.aabb.minx=this.worldCOMx-e,this.aabb.miny=this.worldCOMy-t,this.aabb.maxx=this.worldCOMx+e,this.aabb.maxy=this.worldCOMy+t}_force_validate_aabb(){let e=this.body;this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy),this.aabb.minx=this.worldCOMx-this.radius,this.aabb.miny=this.worldCOMy-this.radius,this.aabb.maxx=this.worldCOMx+this.radius,this.aabb.maxy=this.worldCOMy+this.radius}__validate_sweepRadius(){this.sweepCoef=Math.sqrt(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy),this.sweepRadius=this.sweepCoef+this.radius}__validate_area_inertia(){let e=this.radius*this.radius;this.area=e*Math.PI,this.inertia=e*.5+(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy)}__validate_angDrag(){let e=on._nape,t=this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy,n=this.radius*this.radius,l=this.material.dynamicFriction*e.Config.fluidAngularDragFriction;this.angDrag=(t+2*n)*l+.5*e.Config.fluidAngularDrag*(1+e.Config.fluidVacuumDrag)*t,this.angDrag/=2*(t+.5*n)}__scale(e,t){let n=((e<0?-e:e)+(t<0?-t:t))/2;this.radius*=n<0?-n:n,this.invalidate_radius(),this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0&&(this.localCOMx*=e,this.localCOMy*=t,this.invalidate_localCOM())}__translate(e,t){this.localCOMx+=e,this.localCOMy+=t,this.invalidate_localCOM()}__rotate(e,t){if(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0){let n=t*this.localCOMx-e*this.localCOMy,l=this.localCOMx*e+this.localCOMy*t;this.localCOMx=n,this.localCOMy=l,this.invalidate_localCOM()}}__transform(e){let t=e.zpp_inner.a*e.zpp_inner.d-e.zpp_inner.b*e.zpp_inner.c;t<0&&(t=-t),this.radius*=Math.sqrt(t);let n=e.zpp_inner.a*this.localCOMx+e.zpp_inner.b*this.localCOMy+e.zpp_inner.tx;this.localCOMy=e.zpp_inner.c*this.localCOMx+e.zpp_inner.d*this.localCOMy+e.zpp_inner.ty,this.localCOMx=n,this.invalidate_radius(),this.invalidate_localCOM()}__copy(){let e=on._nape,t=new e.shape.Circle(this.radius).zpp_inner_zn;return t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy,t.zip_localCOM=!1,t}};on.__name__=["zpp_nape","shape","ZPP_Circle"],on.__super__=null,on._nape=null,on._zpp=null,on._initialized=!1;var Xn=on;var Kt=class Kt{constructor(){this.next=null;this.polygon=null;this.outer=null;this.lnormx=0;this.lnormy=0;this.wrap_lnorm=null;this.gnormx=0;this.gnormy=0;this.wrap_gnorm=null;this.length=0;this.lprojection=0;this.gprojection=0;this.lp0=null;this.gp0=null;this.lp1=null;this.gp1=null;this.tp0=0;this.tp1=0;this.lnormx=0,this.lnormy=0,this.gnormx=0,this.gnormy=0,this.length=0,this.lprojection=0,this.gprojection=0}free(){this.polygon=null}alloc(){}wrapper(){return this.outer==null&&(Kt._wrapFn?this.outer=Kt._wrapFn(this):(Kt.internal=!0,this.outer=new Kt._nape.shape.Edge,Kt.internal=!1,this.outer.zpp_inner=this)),this.outer}lnorm_validate(){if(this.polygon==null)throw new Error("Error: Edge not currently in use");this.polygon.validate_laxi(),this.wrap_lnorm.zpp_inner.x=this.lnormx,this.wrap_lnorm.zpp_inner.y=this.lnormy}gnorm_validate(){if(this.polygon==null)throw new Error("Error: Edge not currently in use");if(this.polygon.body==null)throw new Error("Error: Edge worldNormal only makes sense if the parent Polygon is contained within a rigid body");this.polygon.validate_gaxi(),this.wrap_gnorm.zpp_inner.x=this.gnormx,this.wrap_gnorm.zpp_inner.y=this.gnormy}getlnorm(){let e=Kt._zpp,t=Kt._nape,n=this.lnormx,l=this.lnormy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,this.wrap_lnorm=s,this.wrap_lnorm.zpp_inner._immutable=!0,this.wrap_lnorm.zpp_inner._validate=this.lnorm_validate.bind(this)}getgnorm(){let e=Kt._zpp,t=Kt._nape,n=this.gnormx,l=this.gnormy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,this.wrap_gnorm=s,this.wrap_gnorm.zpp_inner._immutable=!0,this.wrap_gnorm.zpp_inner._validate=this.gnorm_validate.bind(this)}};Kt.__name__=["zpp_nape","shape","ZPP_Edge"],Kt.zpp_pool=null,Kt.internal=!1,Kt._nape=null,Kt._zpp=null,Kt._wrapFn=null;var ot=Kt;var rt=class rt{constructor(){this.outer_zn=null;this.lverts=null;this.wrap_lverts=null;this.gverts=null;this.wrap_gverts=null;this.edges=null;this.wrap_edges=null;this.edgeCnt=0;this.reverse_flag=!1;this.zip_lverts=!1;this.zip_laxi=!1;this.zip_gverts=!1;this.zip_gaxi=!1;this.zip_valid=!1;this.zip_sanitation=!1;this.validation=null;this.zip_sanitation=!1,this.zip_valid=!1,this.zip_gaxi=!1,this.zip_gverts=!1,this.zip_laxi=!1,this.zip_lverts=!1,this.reverse_flag=!1,this.edgeCnt=0,this.wrap_edges=null,this.edges=null,this.wrap_gverts=null,this.gverts=null,this.wrap_lverts=null,this.lverts=null,this.outer_zn=null;let e=rt._zpp;this._initShape(1),this.polygon=this,this.lverts=new e.geom.ZPP_Vec2,this.gverts=new e.geom.ZPP_Vec2,this.edges=new e.util.ZNPList_ZPP_Edge,this.edgeCnt=0}static _init(){if(rt._initialized)return;rt._initialized=!0;let e=rt._zpp;rt.__super__=e.shape.ZPP_Shape;let t=e.shape.ZPP_Shape.prototype,n=rt.prototype;for(let l in t)l!=="__class__"&&!Object.prototype.hasOwnProperty.call(n,l)&&(n[l]=t[l]);for(let l of Object.getOwnPropertyNames(t))l!=="constructor"&&l!=="__class__"&&!Object.prototype.hasOwnProperty.call(n,l)&&(n[l]=t[l])}__clear(){}lverts_pa_invalidate(e){this.invalidate_lverts()}lverts_pa_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify local vertex of Polygon added to a static body whilst within a Space")}gverts_pa_validate(){if(this.body==null)throw new Error("Error: World vertex only makes sense when Polygon is contained in a rigid body");this._validateGverts()}lverts_post_adder(e){let t=rt._zpp;e.zpp_inner._invalidate=this.lverts_pa_invalidate.bind(this),e.zpp_inner._isimmutable=this.lverts_pa_immutable.bind(this);let n=null,l=null,s=this.lverts.next;for(;s!=null&&s!==e.zpp_inner;)n=n==null?this.gverts.next:n.next,l=l==null?this.edges.head:l.next,s=s.next;let i;if(t.geom.ZPP_Vec2.zpp_pool==null?i=new t.geom.ZPP_Vec2:(i=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!0,i.x=0,i.y=0,this.gverts.insert(n,i),this.lverts.next.next!=null)if(this.lverts.next.next.next==null){let o;ot.zpp_pool==null?o=new ot:(o=ot.zpp_pool,ot.zpp_pool=o.next,o.next=null),o.polygon=this,this.edges.add(o);let r;ot.zpp_pool==null?r=new ot:(r=ot.zpp_pool,ot.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.add(r),this.edgeCnt+=2}else{let o;ot.zpp_pool==null?o=new ot:(o=ot.zpp_pool,ot.zpp_pool=o.next,o.next=null),o.polygon=this,this.edges.insert(l,o),this.edgeCnt++}i._validate=this.gverts_pa_validate.bind(this)}lverts_subber(e){this.cleanup_lvert(e.zpp_inner)}lverts_invalidate(e){this.invalidate_lverts()}lverts_validate(){this.validate_lverts()}lverts_modifiable(){if(this.immutable_midstep("Polygon::localVerts"),this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}gverts_validate(){this._validateGverts()}edges_validate(){this.validate_lverts()}getlverts(){let e=rt._zpp;this.wrap_lverts=e.util.ZPP_MixVec2List.get(this.lverts),this.wrap_lverts.zpp_inner.post_adder=this.lverts_post_adder.bind(this),this.wrap_lverts.zpp_inner.subber=this.lverts_subber.bind(this),this.wrap_lverts.zpp_inner._invalidate=this.lverts_invalidate.bind(this),this.wrap_lverts.zpp_inner._validate=this.lverts_validate.bind(this),this.wrap_lverts.zpp_inner._modifiable=this.lverts_modifiable.bind(this),this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag}getgverts(){let e=rt._zpp;this.wrap_gverts=e.util.ZPP_MixVec2List.get(this.gverts,!0),this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag,this.wrap_gverts.zpp_inner._validate=this.gverts_validate.bind(this)}getedges(){let e=rt._zpp;this.wrap_edges=e.util.ZPP_EdgeList.get(this.edges,!0),this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag,this.wrap_edges.zpp_inner._validate=this.edges_validate.bind(this)}invalidate_lverts(){this.invalidate_laxi(),this.invalidate_area_inertia(),this.invalidate_angDrag(),this.invalidate_localCOM(),this.invalidate_gverts(),this.zip_lverts=!0,this.zip_valid=!0,this.zip_sanitation=!0,this.body!=null&&this.body.wake()}invalidate_laxi(){this.invalidate_gaxi(),this.zip_sweepRadius=!0,this.zip_laxi=!0}invalidate_gverts(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0),this.zip_gverts=!0}invalidate_gaxi(){this.zip_gaxi=!0}validate_lverts(){this.zip_lverts&&(this.zip_lverts=!1,this.lverts.length>2&&(this.validate_area_inertia(),this.area<0&&(this.reverse_vertices(),this.area=-this.area)))}validate_laxi(){if(this.zip_laxi){this.zip_laxi=!1,this.validate_lverts();let t=this.edges.head,n=this.lverts.next,l=n;for(n=n.next;n!=null;){let u=n,h=t.elt;t=t.next,h.lp0=l,h.lp1=u;let x=l.x-u.x,b=l.y-u.y,_=Math.sqrt(x*x+b*b);h.length=_;let d=1/_;x*=d,b*=d;let f=x;x=-b,b=f,h.lprojection=x*l.x+b*l.y,h.lnormx=x,h.lnormy=b,h.wrap_lnorm!=null&&(h.wrap_lnorm.zpp_inner.x=x,h.wrap_lnorm.zpp_inner.y=b),l=u,n=n.next}let s=this.lverts.next,i=t.elt;i.lp0=l,i.lp1=s;let o=l.x-s.x,r=l.y-s.y,a=Math.sqrt(o*o+r*r);i.length=a;let p=1/a;o*=p,r*=p;let c=o;o=-r,r=c,i.lprojection=o*l.x+r*l.y,i.lnormx=o,i.lnormy=r,i.wrap_lnorm!=null&&(i.wrap_lnorm.zpp_inner.x=o,i.wrap_lnorm.zpp_inner.y=r)}}validate_gverts(){this._validateGverts()}validate_gaxi(){if(this.zip_gaxi&&this.body!=null){this.zip_gaxi=!1,this.validate_laxi();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this._validateGverts();let t=this.edges.head,n=this.gverts.next,l=n;for(n=n.next;n!=null;){let o=n,r=t.elt;t=t.next,r.gp0=l,r.gp1=o,r.gnormx=e.axisy*r.lnormx-e.axisx*r.lnormy,r.gnormy=r.lnormx*e.axisx+r.lnormy*e.axisy,r.gprojection=e.posx*r.gnormx+e.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy,l=o,n=n.next}let s=this.gverts.next,i=t.elt;i.gp0=l,i.gp1=s,i.gnormx=e.axisy*i.lnormx-e.axisx*i.lnormy,i.gnormy=i.lnormx*e.axisx+i.lnormy*e.axisy,i.gprojection=e.posx*i.gnormx+e.posy*i.gnormy+i.lprojection,i.wrap_gnorm!=null&&(i.wrap_gnorm.zpp_inner.x=i.gnormx,i.wrap_gnorm.zpp_inner.y=i.gnormy),i.tp0=i.gp0.y*i.gnormx-i.gp0.x*i.gnormy,i.tp1=i.gp1.y*i.gnormx-i.gp1.x*i.gnormy}}_validateGverts(){if(this.zip_gverts&&this.body!=null){this.zip_gverts=!1,this.validate_lverts();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let t=this.lverts.next,n=this.gverts.next;for(;n!=null;){let l=n,s=t;t=t.next,l.x=e.posx+(e.axisy*s.x-e.axisx*s.y),l.y=e.posy+(s.x*e.axisx+s.y*e.axisy),n=n.next}}}cleanup_lvert(e){let t=rt._zpp,n=null,l=null,s=this.lverts.next;for(;s!=null&&s!==e;)n=n==null?this.gverts.next:n.next,l=l==null?this.edges.head:l.next,s=s.next;let i=n==null?this.gverts.next:n.next;this.gverts.erase(n);let o=i;if(o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=o,this.edgeCnt===2){let r=this.edges.pop_unsafe();r.polygon=null,r.next=ot.zpp_pool,ot.zpp_pool=r,r=this.edges.pop_unsafe(),r.polygon=null,r.next=ot.zpp_pool,ot.zpp_pool=r,this.edgeCnt=0}else if(this.edgeCnt!==0){let r=l==null?this.edges.head.elt:l.next.elt;this.edges.erase(l),r.polygon=null,r.next=ot.zpp_pool,ot.zpp_pool=r,this.edgeCnt--}}splice_collinear(){this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real())}splice_collinear_real(){let e=rt._nape;if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)return;let t=null,n=this.lverts.next;for(;n!=null;){let s=n.next==null?this.lverts.next:n.next,i=n.x-s.x,o=n.y-s.y;i*i+o*o<e.Config.epsilon*e.Config.epsilon?(this.cleanup_lvert(n),n=this.lverts.erase(t)):(t=n,n=n.next)}if(this.lverts.next==null)return;let l;for(;;){l=!1;let s=this.lverts.next;for(;s!=null;){let i=s.next==null?this.lverts.next:s.next,o=i.next==null?this.lverts.next:i.next,r=i.x-s.x,a=i.y-s.y,p=o.x-i.x,u=(o.y-i.y)*r-p*a;u*u>=e.Config.epsilon*e.Config.epsilon||(this.cleanup_lvert(i),this.lverts.erase(s.next==null?null:s),l=!0),s=s.next}if(!l)break}}reverse_vertices(){this.lverts.reverse(),this.gverts.reverse(),this.edges.reverse();let e=this.edges.iterator_at(this.edgeCnt-1),t=this.edges.pop_unsafe();this.edges.insert(e,t),this.reverse_flag=!this.reverse_flag,this.wrap_lverts!=null&&(this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_gverts!=null&&(this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_edges!=null&&(this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag)}valid(){let e=rt._nape,t=rt._zpp;if(this.zip_valid){if(this.zip_valid=!1,this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real()),this.lverts.length<3)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;if(this.validate_lverts(),this.validate_area_inertia(),this.area<e.Config.epsilon)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;{let n=!1,l=!1,s=!0,i=this.lverts.next,o=i;i=i.next;let r=i;for(i=i.next;i!=null;){let a=i,p=a.x-r.x,c=a.y-r.y,u=r.x-o.x,x=(r.y-o.y)*p-u*c;if(x>e.Config.epsilon?l=!0:x<-e.Config.epsilon&&(n=!0),l&&n){s=!1;break}o=r,r=a,i=i.next}if(s){i=this.lverts.next;let a=i,p=a.x-r.x,c=a.y-r.y,u=r.x-o.x,x=(r.y-o.y)*p-u*c;if(x>e.Config.epsilon?l=!0:x<-e.Config.epsilon&&(n=!0),!(l&&n)){o=r,r=a,i=i.next;let b=i,_=b.x-r.x,d=b.y-r.y,f=r.x-o.x,z=(r.y-o.y)*_-f*d;z>e.Config.epsilon?l=!0:z<-e.Config.epsilon&&(n=!0)}}if(l&&n)return t.util.ZPP_Flags.ValidationResult_CONCAVE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_CONCAVE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_CONCAVE;{let a=!0,p=this.lverts.next,c=p;for(p=p.next;p!=null&&a;){let u=p,h=this.lverts.next,x=h.next;for(;x!=null&&a;){let b=x;c!==h&&c!==b&&u!==h&&u!==b&&(a=this._checkNoIntersection(c,u,h,b,e)),h=b,x=x.next}if(a){let b=this.lverts.next;c!==h&&c!==b&&u!==h&&u!==b&&(a=this._checkNoIntersection(c,u,h,b,e))}c=u,p=p.next}if(a){let u=this.lverts.next,h=this.lverts.next,x=h.next;for(;x!=null&&a;){let b=x;c!==h&&c!==b&&u!==h&&u!==b&&(a=this._checkNoIntersection(c,u,h,b,e)),h=b,x=x.next}if(a){let b=this.lverts.next;c!==h&&c!==b&&u!==h&&u!==b&&(a=this._checkNoIntersection(c,u,h,b,e))}}return a?(t.util.ZPP_Flags.ValidationResult_VALID==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_VALID=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_VALID):(t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING)}}}else return this.validation}_checkNoIntersection(e,t,n,l,s){let i=e.x-n.x,o=e.y-n.y,r=t.x-e.x,a=t.y-e.y,p=l.x-n.x,c=l.y-n.y,u=a*p-r*c;if(u*u>s.Config.epsilon){u=1/u;let h=(c*i-p*o)*u;if(h>s.Config.epsilon&&h<1-s.Config.epsilon){let x=(a*i-r*o)*u;if(x>s.Config.epsilon&&x<1-s.Config.epsilon)return!1}}return!0}__validate_aabb(){if(this._validateGverts(),this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let e=this.gverts.next;this.aabb.minx=e.x,this.aabb.miny=e.y,this.aabb.maxx=e.x,this.aabb.maxy=e.y;let t=this.gverts.next.next;for(;t!=null;){let n=t;n.x<this.aabb.minx&&(this.aabb.minx=n.x),n.x>this.aabb.maxx&&(this.aabb.maxx=n.x),n.y<this.aabb.miny&&(this.aabb.miny=n.y),n.y>this.aabb.maxy&&(this.aabb.maxy=n.y),t=t.next}}_force_validate_aabb(){let e=this.body,t=this.lverts.next,n=this.gverts.next,l=t;t=t.next,n.x=e.posx+(e.axisy*l.x-e.axisx*l.y),n.y=e.posy+(l.x*e.axisx+l.y*e.axisy),this.aabb.minx=n.x,this.aabb.miny=n.y,this.aabb.maxx=n.x,this.aabb.maxy=n.y;let s=this.gverts.next.next;for(;s!=null;){let i=s,o=t;t=t.next,i.x=e.posx+(e.axisy*o.x-e.axisx*o.y),i.y=e.posy+(o.x*e.axisx+o.y*e.axisy),i.x<this.aabb.minx&&(this.aabb.minx=i.x),i.x>this.aabb.maxx&&(this.aabb.maxx=i.x),i.y<this.aabb.miny&&(this.aabb.miny=i.y),i.y>this.aabb.maxy&&(this.aabb.maxy=i.y),s=s.next}}__validate_sweepRadius(){let e=0,t=0;this.validate_laxi();let n=this.lverts.next;for(;n!=null;){let s=n,i=s.x*s.x+s.y*s.y;i>e&&(e=i),n=n.next}let l=this.edges.head;for(;l!=null;){let s=l.elt;if(s.lprojection<t&&(t=s.lprojection,t<0))break;l=l.next}t<0&&(t=0),this.sweepRadius=Math.sqrt(e),this.sweepCoef=this.sweepRadius-t}__validate_area_inertia(){if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)this.area=0,this.inertia=0;else{this.area=0;let e=0,t=0,n=this.lverts.next,l=n;n=n.next;let s=n;for(n=n.next;n!=null;){let p=n,c=s.y*l.x-s.x*l.y,u=s.x*s.x+s.y*s.y+(s.x*l.x+s.y*l.y)+(l.x*l.x+l.y*l.y);e+=c*u,t+=c,this.area+=s.x*(p.y-l.y),l=s,s=p,n=n.next}n=this.lverts.next;let i=n,o=s.y*l.x-s.x*l.y,r=s.x*s.x+s.y*s.y+(s.x*l.x+s.y*l.y)+(l.x*l.x+l.y*l.y);e+=o*r,t+=o,this.area+=s.x*(i.y-l.y),l=s,s=i,n=n.next;let a=n;o=s.y*l.x-s.x*l.y,r=s.x*s.x+s.y*s.y+(s.x*l.x+s.y*l.y)+(l.x*l.x+l.y*l.y),e+=o*r,t+=o,this.area+=s.x*(a.y-l.y),this.inertia=e/(6*t),this.area*=.5,this.area<0&&(this.area=-this.area,this.reverse_vertices())}}__validate_angDrag(){let e=rt._nape;if(this.lverts.length<3)throw new Error("Error: Polygon's with less than 3 vertices have no meaningful angDrag");this.validate_area_inertia(),this.validate_laxi();let t=0,n=this.edges.head,l=0,s=this.lverts.next,i=s,o=s.next;for(;o!=null;){let r=o,a=n.elt;n=n.next,l+=a.length;let p=r.x-i.x,c=r.y-i.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let u=-(i.y*a.lnormx-i.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(u>0){let h=u>1?1:u,x=i.x,b=i.y;x+=p*h,b+=c*h;let _=a.lnormy*i.x-a.lnormx*i.y,d=a.lnormy*x-a.lnormx*b,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*h*a.length*e.Config.fluidAngularDrag}if(u<1){let h=u<0?0:u,x=i.x,b=i.y;x+=p*h,b+=c*h;let _=a.lnormy*x-a.lnormx*b,d=a.lnormy*r.x-a.lnormx*r.y,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*e.Config.fluidVacuumDrag*(1-h)*a.length*e.Config.fluidAngularDrag}i=r,o=o.next}{let r=this.lverts.next,a=n.elt;l+=a.length;let p=r.x-i.x,c=r.y-i.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let u=-(i.y*a.lnormx-i.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(u>0){let h=u>1?1:u,x=i.x,b=i.y;x+=p*h,b+=c*h;let _=a.lnormy*i.x-a.lnormx*i.y,d=a.lnormy*x-a.lnormx*b,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*h*a.length*e.Config.fluidAngularDrag}if(u<1){let h=u<0?0:u,x=i.x,b=i.y;x+=p*h,b+=c*h;let _=a.lnormy*x-a.lnormx*b,d=a.lnormy*r.x-a.lnormx*r.y,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*e.Config.fluidVacuumDrag*(1-h)*a.length*e.Config.fluidAngularDrag}}this.angDrag=t/(this.inertia*l)}__validate_localCOM(){if(this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(this.lverts.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y;else if(this.lverts.next.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y,this.localCOMx+=this.lverts.next.next.x,this.localCOMy+=this.lverts.next.next.y,this.localCOMx*=.5,this.localCOMy*=.5;else{this.localCOMx=0,this.localCOMy=0;let e=0,t=this.lverts.next,n=t;t=t.next;let l=t;for(t=t.next;t!=null;){let r=t;e+=l.x*(r.y-n.y);let a=r.y*l.x-r.x*l.y;this.localCOMx+=(l.x+r.x)*a,this.localCOMy+=(l.y+r.y)*a,n=l,l=r,t=t.next}t=this.lverts.next;let s=t;e+=l.x*(s.y-n.y);let i=s.y*l.x-s.x*l.y;this.localCOMx+=(l.x+s.x)*i,this.localCOMy+=(l.y+s.y)*i,n=l,l=s,t=t.next;let o=t;e+=l.x*(o.y-n.y),i=o.y*l.x-o.x*l.y,this.localCOMx+=(l.x+o.x)*i,this.localCOMy+=(l.y+o.y)*i,e=1/(3*e),this.localCOMx*=e,this.localCOMy*=e}}localCOM_validate(){if(this.lverts.next==null)throw new Error("Error: An empty polygon does not have any meaningful localCOM");this.validate_localCOM()}localCOM_invalidate(e){this.validate_localCOM();let t=e.x-this.localCOMx,n=e.y-this.localCOMy,l=this.lverts.next;for(;l!=null;)l.x+=t,l.y+=n,l=l.next;this.invalidate_lverts()}setupLocalCOM(){let e=rt._zpp,t=rt._nape,n=this.localCOMx,l=this.localCOMy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,this.wrap_localCOM=s,this.wrap_localCOM.zpp_inner._inuse=!0,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this)}__translate(e,t){let n=this.lverts.next;for(;n!=null;)n.x+=e,n.y+=t,n=n.next;this.invalidate_lverts()}__scale(e,t){let n=this.lverts.next;for(;n!=null;)n.x*=e,n.y*=t,n=n.next;this.invalidate_lverts()}__rotate(e,t){let n=this.lverts.next;for(;n!=null;){let l=t*n.x-e*n.y,s=n.x*e+n.y*t;n.x=l,n.y=s,n=n.next}this.invalidate_lverts()}__transform(e){let t=this.lverts.next;for(;t!=null;){let n=e.zpp_inner.a*t.x+e.zpp_inner.b*t.y+e.zpp_inner.tx;t.y=e.zpp_inner.c*t.x+e.zpp_inner.d*t.y+e.zpp_inner.ty,t.x=n,t=t.next}this.invalidate_lverts()}__copy(){let e=rt._nape;this.outer_zn.zpp_inner_zn.wrap_lverts==null&&this.outer_zn.zpp_inner_zn.getlverts();let t=this.outer_zn.zpp_inner_zn.wrap_lverts,n=[],l=t.iterator();for(;l.hasNext();)n.push(l.next());return new e.shape.Polygon(n).zpp_inner_zn}};rt.__name__=["zpp_nape","shape","ZPP_Polygon"],rt.__super__=null,rt._nape=null,rt._zpp=null,rt._initialized=!1;var Hn=rt;var _i=class _i{constructor(){this.space=null;this.is_sweep=!1;this.sweep=null;this.dynab=null;this.aabbShape=null;this.matrix=null;this.circShape=null}static _initFields(e){e.space=null,e.is_sweep=!1,e.sweep=null,e.dynab=null,e.aabbShape=null,e.matrix=null,e.circShape=null}insert(e){this.is_sweep?this.sweep.__insert(e):this.dynab.__insert(e)}remove(e){this.is_sweep?this.sweep.__remove(e):this.dynab.__remove(e)}sync(e){if(this.is_sweep){if(!this.sweep.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let i=t.polygon;if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(i.lverts.next.next==null)i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;else if(i.lverts.next.next.next==null){i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;let o=1;i.localCOMx+=i.lverts.next.next.x*o,i.localCOMy+=i.lverts.next.next.y*o;let r=.5;i.localCOMx*=r,i.localCOMy*=r}else{i.localCOMx=0,i.localCOMy=0;let o=0,r=i.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let _=r;o+=p.x*(_.y-a.y);let d=_.y*p.x-_.x*p.y;i.localCOMx+=(p.x+_.x)*d,i.localCOMy+=(p.y+_.y)*d,a=p,p=_,r=r.next}r=i.lverts.next;let c=r;o+=p.x*(c.y-a.y);let u=c.y*p.x-c.x*p.y;i.localCOMx+=(p.x+c.x)*u,i.localCOMy+=(p.y+c.y)*u,a=p,p=c,r=r.next;let h=r;o+=p.x*(h.y-a.y);let x=h.y*p.x-h.x*p.y;i.localCOMx+=(p.x+h.x)*x,i.localCOMy+=(p.y+h.y)*x,o=1/(3*o);let b=o;i.localCOMx*=b,i.localCOMy*=b}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=i;i=i.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}}else{let t=this.dynab,n=e.node;if(!n.synced){if(!t.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let s=e.circle;if(s.zip_worldCOM&&s.body!=null){if(s.zip_worldCOM=!1,s.zip_localCOM){if(s.zip_localCOM=!1,s.type==1){let a=s.polygon;if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(a.lverts.next.next==null)a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;else if(a.lverts.next.next.next==null){a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;let p=1;a.localCOMx+=a.lverts.next.next.x*p,a.localCOMy+=a.lverts.next.next.y*p;let c=.5;a.localCOMx*=c,a.localCOMy*=c}else{a.localCOMx=0,a.localCOMy=0;let p=0,c=a.lverts.next,u=c;c=c.next;let h=c;for(c=c.next;c!=null;){let m=c;p+=h.x*(m.y-u.y);let z=m.y*h.x-m.x*h.y;a.localCOMx+=(h.x+m.x)*z,a.localCOMy+=(h.y+m.y)*z,u=h,h=m,c=c.next}c=a.lverts.next;let x=c;p+=h.x*(x.y-u.y);let b=x.y*h.x-x.x*h.y;a.localCOMx+=(h.x+x.x)*b,a.localCOMy+=(h.y+x.y)*b,u=h,h=x,c=c.next;let _=c;p+=h.x*(_.y-u.y);let d=_.y*h.x-_.x*h.y;a.localCOMx+=(h.x+_.x)*d,a.localCOMy+=(h.y+_.y)*d,p=1/(3*p);let f=p;a.localCOMx*=f,a.localCOMy*=f}}s.wrap_localCOM!=null&&(s.wrap_localCOM.zpp_inner.x=s.localCOMx,s.wrap_localCOM.zpp_inner.y=s.localCOMy)}let r=s.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),s.worldCOMx=s.body.posx+(s.body.axisy*s.localCOMx-s.body.axisx*s.localCOMy),s.worldCOMy=s.body.posy+(s.localCOMx*s.body.axisx+s.localCOMy*s.body.axisy)}let i=s.radius,o=s.radius;s.aabb.minx=s.worldCOMx-i,s.aabb.miny=s.worldCOMy-o,s.aabb.maxx=s.worldCOMx+i,s.aabb.maxy=s.worldCOMy+o}else{let s=e.polygon;if(s.zip_gverts&&s.body!=null){s.zip_gverts=!1,s.validate_lverts();let r=s.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let a=s.lverts.next,p=s.gverts.next;for(;p!=null;){let c=p,u=a;a=a.next,c.x=s.body.posx+(s.body.axisy*u.x-s.body.axisx*u.y),c.y=s.body.posy+(u.x*s.body.axisx+u.y*s.body.axisy),p=p.next}}if(s.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let i=s.gverts.next;s.aabb.minx=i.x,s.aabb.miny=i.y,s.aabb.maxx=i.x,s.aabb.maxy=i.y;let o=s.gverts.next.next;for(;o!=null;){let r=o;r.x<s.aabb.minx&&(s.aabb.minx=r.x),r.x>s.aabb.maxx&&(s.aabb.maxx=r.x),r.y<s.aabb.miny&&(s.aabb.miny=r.y),r.y>s.aabb.maxy&&(s.aabb.maxy=r.y),o=o.next}}let l;if(n.dyn==(e.body.type==1?!1:!e.body.component.sleeping)){let s=n.aabb,i=e.aabb;l=!(i.minx>=s.minx&&i.miny>=s.miny&&i.maxx<=s.maxx&&i.maxy<=s.maxy)}else l=!0;l&&(n.synced=!0,n.snext=t.syncs,t.syncs=n)}}}broadphase(e,t){}clear(){}shapesUnderPoint(e,t,n,l){return null}bodiesUnderPoint(e,t,n,l){return null}updateAABBShape(e){let t=_i._zpp,n=_i._nape;if(this.aabbShape==null){t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new n.phys.BodyType,t.util.ZPP_Flags.internal=!1);let o=new n.phys.Body(t.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,r=this.aabbShape=new n.shape.Polygon(n.shape.Polygon.rect(e.minx,e.miny,e.maxx-e.minx,e.maxy-e.miny));o.zpp_inner.reverse_flag?o.push(r):o.unshift(r)}else{let i=this.aabbShape.zpp_inner.aabb,o=(e.maxx-e.minx)/(i.maxx-i.minx),r=(e.maxy-e.miny)/(i.maxy-i.miny);this.matrix==null&&(this.matrix=new n.geom.Mat23);let a=this.matrix;if(o!==o)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=o;let p=a.zpp_inner;p._invalidate!=null&&p._invalidate();let c=this.matrix,u=this.matrix;u.zpp_inner.c=0;let h=u.zpp_inner;h._invalidate!=null&&h._invalidate();let x=u.zpp_inner.c;if(x!==x)throw new Error("Error: Mat23::b cannot be NaN");c.zpp_inner.b=x;let b=c.zpp_inner;b._invalidate!=null&&b._invalidate();let _=this.matrix;if(r!==r)throw new Error("Error: Mat23::d cannot be NaN");_.zpp_inner.d=r;let d=_.zpp_inner;d._invalidate!=null&&d._invalidate();let f=this.matrix,m=e.minx-o*i.minx;if(m!==m)throw new Error("Error: Mat23::tx cannot be NaN");f.zpp_inner.tx=m;let z=f.zpp_inner;z._invalidate!=null&&z._invalidate();let Z=this.matrix,y=e.miny-r*i.miny;if(y!==y)throw new Error("Error: Mat23::ty cannot be NaN");Z.zpp_inner.ty=y;let w=Z.zpp_inner;w._invalidate!=null&&w._invalidate(),this.aabbShape.transform(this.matrix)}let l=this.aabbShape.zpp_inner;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let i=l.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=!1,i.zip_localCOM){if(i.zip_localCOM=!1,i.type==1){let p=i.polygon;if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(p.lverts.next.next==null)p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;else if(p.lverts.next.next.next==null){p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;let c=1;p.localCOMx+=p.lverts.next.next.x*c,p.localCOMy+=p.lverts.next.next.y*c;let u=.5;p.localCOMx*=u,p.localCOMy*=u}else{p.localCOMx=0,p.localCOMy=0;let c=0,u=p.lverts.next,h=u;u=u.next;let x=u;for(u=u.next;u!=null;){let z=u;c+=x.x*(z.y-h.y);let Z=z.y*x.x-z.x*x.y;p.localCOMx+=(x.x+z.x)*Z,p.localCOMy+=(x.y+z.y)*Z,h=x,x=z,u=u.next}u=p.lverts.next;let b=u;c+=x.x*(b.y-h.y);let _=b.y*x.x-b.x*x.y;p.localCOMx+=(x.x+b.x)*_,p.localCOMy+=(x.y+b.y)*_,h=x,x=b,u=u.next;let d=u;c+=x.x*(d.y-h.y);let f=d.y*x.x-d.x*x.y;p.localCOMx+=(x.x+d.x)*f,p.localCOMy+=(x.y+d.y)*f,c=1/(3*c);let m=c;p.localCOMx*=m,p.localCOMy*=m}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let o=i.radius,r=i.radius;i.aabb.minx=i.worldCOMx-o,i.aabb.miny=i.worldCOMy-r,i.aabb.maxx=i.worldCOMx+o,i.aabb.maxy=i.worldCOMy+r}else{let i=l.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=i.lverts.next,c=i.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=i.body.posx+(i.body.axisy*h.x-i.body.axisx*h.y),u.y=i.body.posy+(h.x*i.body.axisx+h.y*i.body.axisy),c=c.next}}if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let o=i.gverts.next;i.aabb.minx=o.x,i.aabb.miny=o.y,i.aabb.maxx=o.x,i.aabb.maxy=o.y;let r=i.gverts.next.next;for(;r!=null;){let a=r;a.x<i.aabb.minx&&(i.aabb.minx=a.x),a.x>i.aabb.maxx&&(i.aabb.maxx=a.x),a.y<i.aabb.miny&&(i.aabb.miny=a.y),a.y>i.aabb.maxy&&(i.aabb.maxy=a.y),r=r.next}}let s=this.aabbShape.zpp_inner.polygon;if(s.zip_gaxi&&s.body!=null){s.zip_gaxi=!1,s.validate_laxi();let i=s.body;if(i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),s.zip_gverts&&s.body!=null){s.zip_gverts=!1,s.validate_lverts();let u=s.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let h=s.lverts.next,x=s.gverts.next;for(;x!=null;){let b=x,_=h;h=h.next,b.x=s.body.posx+(s.body.axisy*_.x-s.body.axisx*_.y),b.y=s.body.posy+(_.x*s.body.axisx+_.y*s.body.axisy),x=x.next}}let o=s.edges.head,r=s.gverts.next,a=r;for(r=r.next;r!=null;){let u=r,h=o.elt;o=o.next,h.gp0=a,h.gp1=u,h.gnormx=s.body.axisy*h.lnormx-s.body.axisx*h.lnormy,h.gnormy=h.lnormx*s.body.axisx+h.lnormy*s.body.axisy,h.gprojection=s.body.posx*h.gnormx+s.body.posy*h.gnormy+h.lprojection,h.wrap_gnorm!=null&&(h.wrap_gnorm.zpp_inner.x=h.gnormx,h.wrap_gnorm.zpp_inner.y=h.gnormy),h.tp0=h.gp0.y*h.gnormx-h.gp0.x*h.gnormy,h.tp1=h.gp1.y*h.gnormx-h.gp1.x*h.gnormy,a=u,r=r.next}let p=s.gverts.next,c=o.elt;o=o.next,c.gp0=a,c.gp1=p,c.gnormx=s.body.axisy*c.lnormx-s.body.axisx*c.lnormy,c.gnormy=c.lnormx*s.body.axisx+c.lnormy*s.body.axisy,c.gprojection=s.body.posx*c.gnormx+s.body.posy*c.gnormy+c.lprojection,c.wrap_gnorm!=null&&(c.wrap_gnorm.zpp_inner.x=c.gnormx,c.wrap_gnorm.zpp_inner.y=c.gnormy),c.tp0=c.gp0.y*c.gnormx-c.gp0.x*c.gnormy,c.tp1=c.gp1.y*c.gnormx-c.gp1.x*c.gnormy}}shapesInAABB(e,t,n,l,s){return null}bodiesInAABB(e,t,n,l,s){return null}updateCircShape(e,t,n){let l=_i._zpp,s=_i._nape;if(this.circShape==null){l.util.ZPP_Flags.BodyType_STATIC==null&&(l.util.ZPP_Flags.internal=!0,l.util.ZPP_Flags.BodyType_STATIC=new s.phys.BodyType,l.util.ZPP_Flags.internal=!1);let r=new s.phys.Body(l.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,a=e,p=t;if(p==null&&(p=0),a==null&&(a=0),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let c;if(l.util.ZPP_PubPool.poolVec2==null?c=new s.geom.Vec2:(c=l.util.ZPP_PubPool.poolVec2,l.util.ZPP_PubPool.poolVec2=c.zpp_pool,c.zpp_pool=null,c.zpp_disp=!1,c==l.util.ZPP_PubPool.nextVec2&&(l.util.ZPP_PubPool.nextVec2=null)),c.zpp_inner==null){let h;l.geom.ZPP_Vec2.zpp_pool==null?h=new l.geom.ZPP_Vec2:(h=l.geom.ZPP_Vec2.zpp_pool,l.geom.ZPP_Vec2.zpp_pool=h.next,h.next=null),h.weak=!1,h._immutable=!1,h.x=a,h.y=p,c.zpp_inner=h,c.zpp_inner.outer=c}else{if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=c.zpp_inner;if(h._immutable)throw new Error("Error: Vec2 is immutable");if(h._isimmutable!=null&&h._isimmutable(),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let x;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let b=c.zpp_inner;if(b._validate!=null&&b._validate(),c.zpp_inner.x==a){if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let _=c.zpp_inner;_._validate!=null&&_._validate(),x=c.zpp_inner.y==p}else x=!1;if(!x){c.zpp_inner.x=a,c.zpp_inner.y=p;let _=c.zpp_inner;_._invalidate!=null&&_._invalidate(_)}}c.zpp_inner.weak=!1;let u=this.circShape=new s.shape.Circle(n,c);r.zpp_inner.reverse_flag?r.push(u):r.unshift(u)}else{let o=this.circShape.zpp_inner.circle,r=n/o.radius;this.matrix==null&&(this.matrix=new s.geom.Mat23);let a=this.matrix,p=this.matrix;if(r!==r)throw new Error("Error: Mat23::d cannot be NaN");p.zpp_inner.d=r;let c=p.zpp_inner;c._invalidate!=null&&c._invalidate();let u=p.zpp_inner.d;if(u!==u)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=u;let h=a.zpp_inner;h._invalidate!=null&&h._invalidate();let x=this.matrix,b=this.matrix;b.zpp_inner.c=0;let _=b.zpp_inner;_._invalidate!=null&&_._invalidate();let d=b.zpp_inner.c;if(d!==d)throw new Error("Error: Mat23::b cannot be NaN");x.zpp_inner.b=d;let f=x.zpp_inner;f._invalidate!=null&&f._invalidate();let m=this.matrix,z=e-r*o.localCOMx;if(z!==z)throw new Error("Error: Mat23::tx cannot be NaN");m.zpp_inner.tx=z;let Z=m.zpp_inner;Z._invalidate!=null&&Z._invalidate();let y=this.matrix,w=t-r*o.localCOMy;if(w!==w)throw new Error("Error: Mat23::ty cannot be NaN");y.zpp_inner.ty=w;let v=y.zpp_inner;v._invalidate!=null&&v._invalidate(),this.circShape.transform(this.matrix)}let i=this.circShape.zpp_inner;if(i.zip_aabb&&i.body!=null)if(i.zip_aabb=!1,i.type==0){let o=i.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let b=h;for(h=h.next;h!=null;){let Z=h;u+=b.x*(Z.y-x.y);let y=Z.y*b.x-Z.x*b.y;c.localCOMx+=(b.x+Z.x)*y,c.localCOMy+=(b.y+Z.y)*y,x=b,b=Z,h=h.next}h=c.lverts.next;let _=h;u+=b.x*(_.y-x.y);let d=_.y*b.x-_.x*b.y;c.localCOMx+=(b.x+_.x)*d,c.localCOMy+=(b.y+_.y)*d,x=b,b=_,h=h.next;let f=h;u+=b.x*(f.y-x.y);let m=f.y*b.x-f.x*b.y;c.localCOMx+=(b.x+f.x)*m,c.localCOMy+=(b.y+f.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else{let o=i.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,u=o.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),h.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}}shapesInCircle(e,t,n,l,s,i){return null}bodiesInCircle(e,t,n,l,s,i){return null}validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=t.body.posx+(t.body.axisy*h.x-t.body.axisx*h.y),u.y=t.body.posy+(h.x*t.body.axisx+h.y*t.body.axisy),c=c.next}}let l=t.edges.head,s=t.gverts.next,i=s;for(s=s.next;s!=null;){let a=s,p=l.elt;l=l.next,p.gp0=i,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,i=a,s=s.next}let o=t.gverts.next,r=l.elt;l=l.next,r.gp0=i,r.gp1=o,r.gnormx=t.body.axisy*r.lnormx-t.body.axisx*r.lnormy,r.gnormy=r.lnormx*t.body.axisx+r.lnormy*t.body.axisy,r.gprojection=t.body.posx*r.gnormx+t.body.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let i=t.polygon;if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(i.lverts.next.next==null)i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;else if(i.lverts.next.next.next==null){i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;let o=1;i.localCOMx+=i.lverts.next.next.x*o,i.localCOMy+=i.lverts.next.next.y*o;let r=.5;i.localCOMx*=r,i.localCOMy*=r}else{i.localCOMx=0,i.localCOMy=0;let o=0,r=i.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let _=r;o+=p.x*(_.y-a.y);let d=_.y*p.x-_.x*p.y;i.localCOMx+=(p.x+_.x)*d,i.localCOMy+=(p.y+_.y)*d,a=p,p=_,r=r.next}r=i.lverts.next;let c=r;o+=p.x*(c.y-a.y);let u=c.y*p.x-c.x*p.y;i.localCOMx+=(p.x+c.x)*u,i.localCOMy+=(p.y+c.y)*u,a=p,p=c,r=r.next;let h=r;o+=p.x*(h.y-a.y);let x=h.y*p.x-h.x*p.y;i.localCOMx+=(p.x+h.x)*x,i.localCOMy+=(p.y+h.y)*x,o=1/(3*o);let b=o;i.localCOMx*=b,i.localCOMy*=b}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=i;i=i.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let l=1;n.localCOMx+=n.lverts.next.next.x*l,n.localCOMy+=n.lverts.next.next.y*l;let s=.5;n.localCOMx*=s,n.localCOMy*=s}else{n.localCOMx=0,n.localCOMy=0;let l=0,s=n.lverts.next,i=s;s=s.next;let o=s;for(s=s.next;s!=null;){let h=s;l+=o.x*(h.y-i.y);let x=h.y*o.x-h.x*o.y;n.localCOMx+=(o.x+h.x)*x,n.localCOMy+=(o.y+h.y)*x,i=o,o=h,s=s.next}s=n.lverts.next;let r=s;l+=o.x*(r.y-i.y);let a=r.y*o.x-r.x*o.y;n.localCOMx+=(o.x+r.x)*a,n.localCOMy+=(o.y+r.y)*a,i=o,o=r,s=s.next;let p=s;l+=o.x*(p.y-i.y);let c=p.y*o.x-p.x*o.y;n.localCOMx+=(o.x+p.x)*c,n.localCOMy+=(o.y+p.y)*c,l=1/(3*l);let u=l;n.localCOMx*=u,n.localCOMy*=u}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}shapesInShape(e,t,n,l){return null}bodiesInShape(e,t,n,l){return null}rayCast(e,t,n){return null}rayMultiCast(e,t,n,l){return null}};_i.__name__=["zpp_nape","space","ZPP_Broadphase"],_i._zpp=null,_i._nape=null;var Oi=_i;var Oe=class{constructor(){this.aabb=null;this.shape=null;this.dyn=!1;this.parent=null;this.child1=null;this.child2=null;this.height=-1;this.rayt=0;this.next=null;this.mnext=null;this.moved=!1;this.snext=null;this.synced=!1;this.first_sync=!1}alloc(){be.zpp_pool==null?this.aabb=new be:(this.aabb=be.zpp_pool,be.zpp_pool=this.aabb.next,this.aabb.next=null),this.moved=!1,this.synced=!1,this.first_sync=!1}free(){this.height=-1;let e=this.aabb;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e.wrap_min=e.wrap_max=null,e._invalidate=null,e._validate=null,e.next=be.zpp_pool,be.zpp_pool=e,this.child1=this.child2=this.parent=null,this.next=null,this.snext=null,this.mnext=null}isLeaf(){return this.child1==null}};Oe.__name__=["zpp_nape","space","ZPP_AABBNode"],Oe.zpp_pool=null;var $e=class{constructor(){this.n1=null;this.n2=null;this.first=!1;this.sleeping=!1;this.id=0;this.di=0;this.arb=null;this.next=null}alloc(){}free(){this.n1=this.n2=null,this.sleeping=!1}};$e.__name__=["zpp_nape","space","ZPP_AABBPair"],$e.zpp_pool=null;var Zt=class Zt{constructor(){this.root=null}static _initStatics(){Zt.tmpaabb=new be}clear(){if(this.root==null)return;let e=null;for(this.root.next=e,e=this.root;e!=null;){let t=e;e=t.next,t.next=null;let n=t;n.child1==null?(n.shape.node=null,n.shape.removedFromSpace(),n.shape=null):(n.child1!=null&&(n.child1.next=e,e=n.child1),n.child2!=null&&(n.child2.next=e,e=n.child2));let l=n;l.height=-1;let s=l.aabb;s.outer!=null&&(s.outer.zpp_inner=null,s.outer=null),s.wrap_min=s.wrap_max=null,s._invalidate=null,s._validate=null,s.next=be.zpp_pool,be.zpp_pool=s,l.child1=l.child2=l.parent=null,l.next=null,l.snext=null,l.mnext=null,l.next=Oe.zpp_pool,Oe.zpp_pool=l}this.root=null}insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else{let t=e.aabb,n=this.root;for(;n.child1!=null;){let a=n.child1,p=n.child2,c=n.aabb,u=(c.maxx-c.minx+(c.maxy-c.miny))*2,h=Zt.tmpaabb,x=n.aabb;h.minx=x.minx<t.minx?x.minx:t.minx,h.miny=x.miny<t.miny?x.miny:t.miny,h.maxx=x.maxx>t.maxx?x.maxx:t.maxx,h.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let b=Zt.tmpaabb,_=(b.maxx-b.minx+(b.maxy-b.miny))*2,d=2*_,f=2*(_-u),m=Zt.tmpaabb,z=a.aabb;m.minx=t.minx<z.minx?t.minx:z.minx,m.miny=t.miny<z.miny?t.miny:z.miny,m.maxx=t.maxx>z.maxx?t.maxx:z.maxx,m.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let Z;if(a.child1==null){let P=Zt.tmpaabb;Z=(P.maxx-P.minx+(P.maxy-P.miny))*2+f}else{let P=a.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,k=Zt.tmpaabb;Z=(k.maxx-k.minx+(k.maxy-k.miny))*2-g+f}let y=Zt.tmpaabb,w=p.aabb;y.minx=t.minx<w.minx?t.minx:w.minx,y.miny=t.miny<w.miny?t.miny:w.miny,y.maxx=t.maxx>w.maxx?t.maxx:w.maxx,y.maxy=t.maxy>w.maxy?t.maxy:w.maxy;let v;if(p.child1==null){let P=Zt.tmpaabb;v=(P.maxx-P.minx+(P.maxy-P.miny))*2+f}else{let P=p.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,k=Zt.tmpaabb;v=(k.maxx-k.minx+(k.maxy-k.miny))*2-g+f}if(d<Z&&d<v)break;n=Z<v?a:p}let l=n,s=l.parent,i;Oe.zpp_pool==null?i=new Oe:(i=Oe.zpp_pool,Oe.zpp_pool=i.next,i.next=null),be.zpp_pool==null?i.aabb=new be:(i.aabb=be.zpp_pool,be.zpp_pool=i.aabb.next,i.aabb.next=null),i.moved=!1,i.synced=!1,i.first_sync=!1,i.parent=s;let o=i.aabb,r=l.aabb;for(o.minx=t.minx<r.minx?t.minx:r.minx,o.miny=t.miny<r.miny?t.miny:r.miny,o.maxx=t.maxx>r.maxx?t.maxx:r.maxx,o.maxy=t.maxy>r.maxy?t.maxy:r.maxy,i.height=l.height+1,s!=null?(s.child1==l?s.child1=i:s.child2=i,i.child1=l,i.child2=e,l.parent=i,e.parent=i):(i.child1=l,i.child2=e,l.parent=i,e.parent=i,this.root=i),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let _=n.child1,d=n.child2,f=d.height-_.height;if(f>1){let m=d.child1,z=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,n.child2=z,z.parent=n;let Z=n.aabb,y=_.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=z.height;n.height=1+(k>N?k:N);let E=n.height,M=m.height;d.height=1+(E>M?E:M)}else{d.child2=z,n.child2=m,m.parent=n;let Z=n.aabb,y=_.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=m.height;n.height=1+(k>N?k:N);let E=n.height,M=z.height;d.height=1+(E>M?E:M)}n=d}else if(f<-1){let m=_.child1,z=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,n.child1=z,z.parent=n;let Z=n.aabb,y=d.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=z.height;n.height=1+(k>N?k:N);let E=n.height,M=m.height;_.height=1+(E>M?E:M)}else{_.child2=z,n.child1=m,m.parent=n;let Z=n.aabb,y=d.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=m.height;n.height=1+(k>N?k:N);let E=n.height,M=z.height;_.height=1+(E>M?E:M)}n=_}else n=n}let a=n.child1,p=n.child2,c=a.height,u=p.height;n.height=1+(c>u?c:u);let h=n.aabb,x=a.aabb,b=p.aabb;h.minx=x.minx<b.minx?x.minx:b.minx,h.miny=x.miny<b.miny?x.miny:b.miny,h.maxx=x.maxx>b.maxx?x.maxx:b.maxx,h.maxy=x.maxy>b.maxy?x.maxy:b.maxy,n=n.parent}}}inlined_insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else{let t=e.aabb,n=this.root;for(;n.child1!=null;){let a=n.child1,p=n.child2,c=n.aabb,u=(c.maxx-c.minx+(c.maxy-c.miny))*2,h=Zt.tmpaabb,x=n.aabb;h.minx=x.minx<t.minx?x.minx:t.minx,h.miny=x.miny<t.miny?x.miny:t.miny,h.maxx=x.maxx>t.maxx?x.maxx:t.maxx,h.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let b=Zt.tmpaabb,_=(b.maxx-b.minx+(b.maxy-b.miny))*2,d=2*_,f=2*(_-u),m=Zt.tmpaabb,z=a.aabb;m.minx=t.minx<z.minx?t.minx:z.minx,m.miny=t.miny<z.miny?t.miny:z.miny,m.maxx=t.maxx>z.maxx?t.maxx:z.maxx,m.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let Z;if(a.child1==null){let P=Zt.tmpaabb;Z=(P.maxx-P.minx+(P.maxy-P.miny))*2+f}else{let P=a.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,k=Zt.tmpaabb;Z=(k.maxx-k.minx+(k.maxy-k.miny))*2-g+f}let y=Zt.tmpaabb,w=p.aabb;y.minx=t.minx<w.minx?t.minx:w.minx,y.miny=t.miny<w.miny?t.miny:w.miny,y.maxx=t.maxx>w.maxx?t.maxx:w.maxx,y.maxy=t.maxy>w.maxy?t.maxy:w.maxy;let v;if(p.child1==null){let P=Zt.tmpaabb;v=(P.maxx-P.minx+(P.maxy-P.miny))*2+f}else{let P=p.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,k=Zt.tmpaabb;v=(k.maxx-k.minx+(k.maxy-k.miny))*2-g+f}if(d<Z&&d<v)break;n=Z<v?a:p}let l=n,s=l.parent,i;Oe.zpp_pool==null?i=new Oe:(i=Oe.zpp_pool,Oe.zpp_pool=i.next,i.next=null),be.zpp_pool==null?i.aabb=new be:(i.aabb=be.zpp_pool,be.zpp_pool=i.aabb.next,i.aabb.next=null),i.moved=!1,i.synced=!1,i.first_sync=!1,i.parent=s;let o=i.aabb,r=l.aabb;for(o.minx=t.minx<r.minx?t.minx:r.minx,o.miny=t.miny<r.miny?t.miny:r.miny,o.maxx=t.maxx>r.maxx?t.maxx:r.maxx,o.maxy=t.maxy>r.maxy?t.maxy:r.maxy,i.height=l.height+1,s!=null?(s.child1==l?s.child1=i:s.child2=i,i.child1=l,i.child2=e,l.parent=i,e.parent=i):(i.child1=l,i.child2=e,l.parent=i,e.parent=i,this.root=i),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let _=n.child1,d=n.child2,f=d.height-_.height;if(f>1){let m=d.child1,z=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,n.child2=z,z.parent=n;let Z=n.aabb,y=_.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=z.height;n.height=1+(k>N?k:N);let E=n.height,M=m.height;d.height=1+(E>M?E:M)}else{d.child2=z,n.child2=m,m.parent=n;let Z=n.aabb,y=_.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=m.height;n.height=1+(k>N?k:N);let E=n.height,M=z.height;d.height=1+(E>M?E:M)}n=d}else if(f<-1){let m=_.child1,z=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,n.child1=z,z.parent=n;let Z=n.aabb,y=d.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=z.height;n.height=1+(k>N?k:N);let E=n.height,M=m.height;_.height=1+(E>M?E:M)}else{_.child2=z,n.child1=m,m.parent=n;let Z=n.aabb,y=d.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=m.height;n.height=1+(k>N?k:N);let E=n.height,M=z.height;_.height=1+(E>M?E:M)}n=_}else n=n}let a=n.child1,p=n.child2,c=a.height,u=p.height;n.height=1+(c>u?c:u);let h=n.aabb,x=a.aabb,b=p.aabb;h.minx=x.minx<b.minx?x.minx:b.minx,h.miny=x.miny<b.miny?x.miny:b.miny,h.maxx=x.maxx>b.maxx?x.maxx:b.maxx,h.maxy=x.maxy>b.maxy?x.maxy:b.maxy,n=n.parent}}}removeLeaf(e){if(e==this.root)this.root=null;else{let t=e.parent,n=t.parent,l=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=l:n.child2=l,l.parent=n;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let _=o.child1,d=o.child2,f=d.height-_.height;if(f>1){let m=d.child1,z=d.child2;if(d.child1=o,d.parent=o.parent,o.parent=d,d.parent!=null?d.parent.child1==o?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,o.child2=z,z.parent=o;let Z=o.aabb,y=_.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=o.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=z.height;o.height=1+(k>N?k:N);let E=o.height,M=m.height;d.height=1+(E>M?E:M)}else{d.child2=z,o.child2=m,m.parent=o;let Z=o.aabb,y=_.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=o.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=m.height;o.height=1+(k>N?k:N);let E=o.height,M=z.height;d.height=1+(E>M?E:M)}o=d}else if(f<-1){let m=_.child1,z=_.child2;if(_.child1=o,_.parent=o.parent,o.parent=_,_.parent!=null?_.parent.child1==o?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,o.child1=z,z.parent=o;let Z=o.aabb,y=d.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=o.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=z.height;o.height=1+(k>N?k:N);let E=o.height,M=m.height;_.height=1+(E>M?E:M)}else{_.child2=z,o.child1=m,m.parent=o;let Z=o.aabb,y=d.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=o.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=m.height;o.height=1+(k>N?k:N);let E=o.height,M=z.height;_.height=1+(E>M?E:M)}o=_}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,u=a.aabb,h=p.aabb;c.minx=u.minx<h.minx?u.minx:h.minx,c.miny=u.miny<h.miny?u.miny:h.miny,c.maxx=u.maxx>h.maxx?u.maxx:h.maxx,c.maxy=u.maxy>h.maxy?u.maxy:h.maxy;let x=a.height,b=p.height;r.height=1+(x>b?x:b),o=r.parent}}else{this.root=l,l.parent=null;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s}}}inlined_removeLeaf(e){if(e==this.root){this.root=null;return}else{let t=e.parent,n=t.parent,l=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=l:n.child2=l,l.parent=n;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let _=o.child1,d=o.child2,f=d.height-_.height;if(f>1){let m=d.child1,z=d.child2;if(d.child1=o,d.parent=o.parent,o.parent=d,d.parent!=null?d.parent.child1==o?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,o.child2=z,z.parent=o;let Z=o.aabb,y=_.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=o.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=z.height;o.height=1+(k>N?k:N);let E=o.height,M=m.height;d.height=1+(E>M?E:M)}else{d.child2=z,o.child2=m,m.parent=o;let Z=o.aabb,y=_.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=o.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=m.height;o.height=1+(k>N?k:N);let E=o.height,M=z.height;d.height=1+(E>M?E:M)}o=d}else if(f<-1){let m=_.child1,z=_.child2;if(_.child1=o,_.parent=o.parent,o.parent=_,_.parent!=null?_.parent.child1==o?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,o.child1=z,z.parent=o;let Z=o.aabb,y=d.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=o.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=z.height;o.height=1+(k>N?k:N);let E=o.height,M=m.height;_.height=1+(E>M?E:M)}else{_.child2=z,o.child1=m,m.parent=o;let Z=o.aabb,y=d.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=o.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=m.height;o.height=1+(k>N?k:N);let E=o.height,M=z.height;_.height=1+(E>M?E:M)}o=_}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,u=a.aabb,h=p.aabb;c.minx=u.minx<h.minx?u.minx:h.minx,c.miny=u.miny<h.miny?u.miny:h.miny,c.maxx=u.maxx>h.maxx?u.maxx:h.maxx,c.maxy=u.maxy>h.maxy?u.maxy:h.maxy;let x=a.height,b=p.height;r.height=1+(x>b?x:b),o=r.parent}}else{this.root=l,l.parent=null;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s}}}balance(e){if(e.child1==null||e.height<2)return e;{let t=e.child1,n=e.child2,l=n.height-t.height;if(l>1){let s=n.child1,i=n.child2;if(n.child1=e,n.parent=e.parent,e.parent=n,n.parent!=null?n.parent.child1==e?n.parent.child1=n:n.parent.child2=n:this.root=n,s.height>i.height){n.child2=s,e.child2=i,i.parent=e;let o=e.aabb,r=t.aabb,a=i.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=n.aabb,c=e.aabb,u=s.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=t.height,x=i.height;e.height=1+(h>x?h:x);let b=e.height,_=s.height;n.height=1+(b>_?b:_)}else{n.child2=i,e.child2=s,s.parent=e;let o=e.aabb,r=t.aabb,a=s.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=n.aabb,c=e.aabb,u=i.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=t.height,x=s.height;e.height=1+(h>x?h:x);let b=e.height,_=i.height;n.height=1+(b>_?b:_)}return n}else if(l<-1){let s=t.child1,i=t.child2;if(t.child1=e,t.parent=e.parent,e.parent=t,t.parent!=null?t.parent.child1==e?t.parent.child1=t:t.parent.child2=t:this.root=t,s.height>i.height){t.child2=s,e.child1=i,i.parent=e;let o=e.aabb,r=n.aabb,a=i.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=t.aabb,c=e.aabb,u=s.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=n.height,x=i.height;e.height=1+(h>x?h:x);let b=e.height,_=s.height;t.height=1+(b>_?b:_)}else{t.child2=i,e.child1=s,s.parent=e;let o=e.aabb,r=n.aabb,a=s.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=t.aabb,c=e.aabb,u=i.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=n.height,x=s.height;e.height=1+(h>x?h:x);let b=e.height,_=i.height;t.height=1+(b>_?b:_)}return t}else return e}}};Zt.__name__=["zpp_nape","space","ZPP_AABBTree"],Zt.tmpaabb=null;var et=Zt;var fe=class fe{constructor(e){this.pairs=null;this.syncs=null;this.moves=null;this.treeStack=null;this.treeStack2=null;this.failed=null;this.openlist=null;this.space=null;this.is_sweep=!1;this.sweep=null;this.dynab=null;this.aabbShape=null;this.matrix=null;this.circShape=null;this.__class__=fe;Oi._initFields(this),this.space=e,this.is_sweep=!1,this.dynab=this,this.stree=new et,this.dtree=new et}static _init(){fe.__super__=fe._zpp.space.ZPP_Broadphase;let e=fe._zpp.space.ZPP_Broadphase.prototype;Object.getOwnPropertyNames(e).forEach(t=>{t!=="constructor"&&!(t in fe.prototype)&&(fe.prototype[t]=e[t])})}dyn(e){return e.body.type==1?!1:!e.body.component.sleeping}__insert(e){let t;Oe.zpp_pool==null?t=new Oe:(t=Oe.zpp_pool,Oe.zpp_pool=t.next,t.next=null),be.zpp_pool==null?t.aabb=new be:(t.aabb=be.zpp_pool,be.zpp_pool=t.aabb.next,t.aabb.next=null),t.moved=!1,t.synced=!1,t.first_sync=!1,t.shape=e,e.node=t,t.synced=!0,t.first_sync=!0,t.snext=this.syncs,this.syncs=t}__remove(e){let t=e.node;if(t.first_sync||(t.dyn?this.dtree.removeLeaf(t):this.stree.removeLeaf(t)),e.node=null,t.synced){let o=null,r=this.syncs;for(;r!=null&&r!=t;)o=r,r=r.snext;o==null?this.syncs=r.snext:o.snext=r.snext,r.snext=null,t.synced=!1}if(t.moved){let o=null,r=this.moves;for(;r!=null&&r!=t;)o=r,r=r.mnext;o==null?this.moves=r.mnext:o.mnext=r.mnext,r.mnext=null,t.moved=!1}let n=null,l=this.pairs;for(;l!=null;){let o=l.next;if(l.n1==t||l.n2==t){n==null?this.pairs=o:n.next=o,l.arb!=null&&(l.arb.pair=null),l.arb=null,l.n1.shape.pairs.remove(l),l.n2.shape.pairs.remove(l);let r=l;r.n1=r.n2=null,r.sleeping=!1,r.next=$e.zpp_pool,$e.zpp_pool=r,l=o;continue}n=l,l=o}for(;e.pairs.head!=null;){let o=e.pairs.pop_unsafe();o.n1==t?o.n2.shape.pairs.remove(o):o.n1.shape.pairs.remove(o),o.arb!=null&&(o.arb.pair=null),o.arb=null;let r=o;r.n1=r.n2=null,r.sleeping=!1,r.next=$e.zpp_pool,$e.zpp_pool=r}let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s}__sync(e){let t=e.node;if(!t.synced){if(!this.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let l=e.circle;if(l.zip_worldCOM&&l.body!=null){if(l.zip_worldCOM=!1,l.zip_localCOM){if(l.zip_localCOM=!1,l.type==1){let r=l.polygon;if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(r.lverts.next.next==null)r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;else if(r.lverts.next.next.next==null){r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;let a=1;r.localCOMx+=r.lverts.next.next.x*a,r.localCOMy+=r.lverts.next.next.y*a;let p=.5;r.localCOMx*=p,r.localCOMy*=p}else{r.localCOMx=0,r.localCOMy=0;let a=0,p=r.lverts.next,c=p;p=p.next;let u=p;for(p=p.next;p!=null;){let f=p;a+=u.x*(f.y-c.y);let m=f.y*u.x-f.x*u.y;r.localCOMx+=(u.x+f.x)*m,r.localCOMy+=(u.y+f.y)*m,c=u,u=f,p=p.next}p=r.lverts.next;let h=p;a+=u.x*(h.y-c.y);let x=h.y*u.x-h.x*u.y;r.localCOMx+=(u.x+h.x)*x,r.localCOMy+=(u.y+h.y)*x,c=u,u=h,p=p.next;let b=p;a+=u.x*(b.y-c.y);let _=b.y*u.x-b.x*u.y;r.localCOMx+=(u.x+b.x)*_,r.localCOMy+=(u.y+b.y)*_,a=1/(3*a);let d=a;r.localCOMx*=d,r.localCOMy*=d}}l.wrap_localCOM!=null&&(l.wrap_localCOM.zpp_inner.x=l.localCOMx,l.wrap_localCOM.zpp_inner.y=l.localCOMy)}let o=l.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),l.worldCOMx=l.body.posx+(l.body.axisy*l.localCOMx-l.body.axisx*l.localCOMy),l.worldCOMy=l.body.posy+(l.localCOMx*l.body.axisx+l.localCOMy*l.body.axisy)}let s=l.radius,i=l.radius;l.aabb.minx=l.worldCOMx-s,l.aabb.miny=l.worldCOMy-i,l.aabb.maxx=l.worldCOMx+s,l.aabb.maxy=l.worldCOMy+i}else{let l=e.polygon;if(l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let o=l.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot));let r=l.lverts.next,a=l.gverts.next;for(;a!=null;){let p=a,c=r;r=r.next,p.x=l.body.posx+(l.body.axisy*c.x-l.body.axisx*c.y),p.y=l.body.posy+(c.x*l.body.axisx+c.y*l.body.axisy),a=a.next}}if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let s=l.gverts.next;l.aabb.minx=s.x,l.aabb.miny=s.y,l.aabb.maxx=s.x,l.aabb.maxy=s.y;let i=l.gverts.next.next;for(;i!=null;){let o=i;o.x<l.aabb.minx&&(l.aabb.minx=o.x),o.x>l.aabb.maxx&&(l.aabb.maxx=o.x),o.y<l.aabb.miny&&(l.aabb.miny=o.y),o.y>l.aabb.maxy&&(l.aabb.maxy=o.y),i=i.next}}let n;if(t.dyn==(e.body.type==1?!1:!e.body.component.sleeping)){let l=t.aabb,s=e.aabb;n=!(s.minx>=l.minx&&s.miny>=l.miny&&s.maxx<=l.maxx&&s.maxy<=l.maxy)}else n=!0;n&&(t.synced=!0,t.snext=this.syncs,this.syncs=t)}}sync_broadphase(){if(this.space.validation(),this.syncs!=null)if(this.moves==null){let e=this.syncs;for(;e!=null;){let n=e.shape;if(e.first_sync)e.first_sync=!1;else{let o=e.dyn?this.dtree:this.stree;if(e==o.root)o.root=null;else{let r=e.parent,a=r.parent,p=r.child1==e?r.child2:r.child1;if(a!=null){a.child1==r?a.child1=p:a.child2=p,p.parent=a;let c=r;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Oe.zpp_pool,Oe.zpp_pool=c;let h=a;for(;h!=null;){if(h.child1==null||h.height<2)h=h;else{let Z=h.child1,y=h.child2,w=y.height-Z.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=h,y.parent=h.parent,h.parent=y,y.parent!=null?y.parent.child1==h?y.parent.child1=y:y.parent.child2=y:o.root=y,v.height>P.height){y.child2=v,h.child2=P,P.parent=h;let g=h.aabb,k=Z.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=h.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=Z.height,O=P.height;h.height=1+(D>O?D:O);let j=h.height,L=v.height;y.height=1+(j>L?j:L)}else{y.child2=P,h.child2=v,v.parent=h;let g=h.aabb,k=Z.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=h.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=Z.height,O=v.height;h.height=1+(D>O?D:O);let j=h.height,L=P.height;y.height=1+(j>L?j:L)}h=y}else if(w<-1){let v=Z.child1,P=Z.child2;if(Z.child1=h,Z.parent=h.parent,h.parent=Z,Z.parent!=null?Z.parent.child1==h?Z.parent.child1=Z:Z.parent.child2=Z:o.root=Z,v.height>P.height){Z.child2=v,h.child1=P,P.parent=h;let g=h.aabb,k=y.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=h.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=y.height,O=P.height;h.height=1+(D>O?D:O);let j=h.height,L=v.height;Z.height=1+(j>L?j:L)}else{Z.child2=P,h.child1=v,v.parent=h;let g=h.aabb,k=y.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=h.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=y.height,O=v.height;h.height=1+(D>O?D:O);let j=h.height,L=P.height;Z.height=1+(j>L?j:L)}h=Z}else h=h}let x=h.child1,b=h.child2,_=h.aabb,d=x.aabb,f=b.aabb;_.minx=d.minx<f.minx?d.minx:f.minx,_.miny=d.miny<f.miny?d.miny:f.miny,_.maxx=d.maxx>f.maxx?d.maxx:f.maxx,_.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let m=x.height,z=b.height;h.height=1+(m>z?m:z),h=h.parent}}else{o.root=p,p.parent=null;let c=r;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Oe.zpp_pool,Oe.zpp_pool=c}}}let l=e.aabb;if(!this.space.continuous&&n.zip_aabb&&n.body!=null)if(n.zip_aabb=!1,n.type==0){let o=n.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let b=h;for(h=h.next;h!=null;){let Z=h;u+=b.x*(Z.y-x.y);let y=Z.y*b.x-Z.x*b.y;c.localCOMx+=(b.x+Z.x)*y,c.localCOMy+=(b.y+Z.y)*y,x=b,b=Z,h=h.next}h=c.lverts.next;let _=h;u+=b.x*(_.y-x.y);let d=_.y*b.x-_.x*b.y;c.localCOMx+=(b.x+_.x)*d,c.localCOMy+=(b.y+_.y)*d,x=b,b=_,h=h.next;let f=h;u+=b.x*(f.y-x.y);let m=f.y*b.x-f.x*b.y;c.localCOMx+=(b.x+f.x)*m,c.localCOMy+=(b.y+f.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else{let o=n.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,u=o.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),h.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}let s=n.aabb;l.minx=s.minx-3,l.miny=s.miny-3,l.maxx=s.maxx+3,l.maxy=s.maxy+3;let i=(e.dyn=n.body.type==1?!1:!n.body.component.sleeping)?this.dtree:this.stree;if(i.root==null)i.root=e,i.root.parent=null;else{let o=e.aabb,r=i.root;for(;r.child1!=null;){let x=r.child1,b=r.child2,_=r.aabb,d=(_.maxx-_.minx+(_.maxy-_.miny))*2,f=et.tmpaabb,m=r.aabb;f.minx=m.minx<o.minx?m.minx:o.minx,f.miny=m.miny<o.miny?m.miny:o.miny,f.maxx=m.maxx>o.maxx?m.maxx:o.maxx,f.maxy=m.maxy>o.maxy?m.maxy:o.maxy;let z=et.tmpaabb,Z=(z.maxx-z.minx+(z.maxy-z.miny))*2,y=2*Z,w=2*(Z-d),v=et.tmpaabb,P=x.aabb;v.minx=o.minx<P.minx?o.minx:P.minx,v.miny=o.miny<P.miny?o.miny:P.miny,v.maxx=o.maxx>P.maxx?o.maxx:P.maxx,v.maxy=o.maxy>P.maxy?o.maxy:P.maxy;let g;if(x.child1==null){let M=et.tmpaabb;g=(M.maxx-M.minx+(M.maxy-M.miny))*2+w}else{let M=x.aabb,C=(M.maxx-M.minx+(M.maxy-M.miny))*2,D=et.tmpaabb;g=(D.maxx-D.minx+(D.maxy-D.miny))*2-C+w}let k=et.tmpaabb,N=b.aabb;k.minx=o.minx<N.minx?o.minx:N.minx,k.miny=o.miny<N.miny?o.miny:N.miny,k.maxx=o.maxx>N.maxx?o.maxx:N.maxx,k.maxy=o.maxy>N.maxy?o.maxy:N.maxy;let E;if(b.child1==null){let M=et.tmpaabb;E=(M.maxx-M.minx+(M.maxy-M.miny))*2+w}else{let M=b.aabb,C=(M.maxx-M.minx+(M.maxy-M.miny))*2,D=et.tmpaabb;E=(D.maxx-D.minx+(D.maxy-D.miny))*2-C+w}if(y<g&&y<E)break;r=g<E?x:b}let a=r,p=a.parent,c;Oe.zpp_pool==null?c=new Oe:(c=Oe.zpp_pool,Oe.zpp_pool=c.next,c.next=null),be.zpp_pool==null?c.aabb=new be:(c.aabb=be.zpp_pool,be.zpp_pool=c.aabb.next,c.aabb.next=null),c.moved=!1,c.synced=!1,c.first_sync=!1,c.parent=p;let u=c.aabb,h=a.aabb;for(u.minx=o.minx<h.minx?o.minx:h.minx,u.miny=o.miny<h.miny?o.miny:h.miny,u.maxx=o.maxx>h.maxx?o.maxx:h.maxx,u.maxy=o.maxy>h.maxy?o.maxy:h.maxy,c.height=a.height+1,p!=null?(p.child1==a?p.child1=c:p.child2=c,c.child1=a,c.child2=e,a.parent=c,e.parent=c):(c.child1=a,c.child2=e,a.parent=c,e.parent=c,i.root=c),r=e.parent;r!=null;){if(r.child1==null||r.height<2)r=r;else{let Z=r.child1,y=r.child2,w=y.height-Z.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=r,y.parent=r.parent,r.parent=y,y.parent!=null?y.parent.child1==r?y.parent.child1=y:y.parent.child2=y:i.root=y,v.height>P.height){y.child2=v,r.child2=P,P.parent=r;let g=r.aabb,k=Z.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=r.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=Z.height,O=P.height;r.height=1+(D>O?D:O);let j=r.height,L=v.height;y.height=1+(j>L?j:L)}else{y.child2=P,r.child2=v,v.parent=r;let g=r.aabb,k=Z.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=r.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=Z.height,O=v.height;r.height=1+(D>O?D:O);let j=r.height,L=P.height;y.height=1+(j>L?j:L)}r=y}else if(w<-1){let v=Z.child1,P=Z.child2;if(Z.child1=r,Z.parent=r.parent,r.parent=Z,Z.parent!=null?Z.parent.child1==r?Z.parent.child1=Z:Z.parent.child2=Z:i.root=Z,v.height>P.height){Z.child2=v,r.child1=P,P.parent=r;let g=r.aabb,k=y.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=r.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=y.height,O=P.height;r.height=1+(D>O?D:O);let j=r.height,L=v.height;Z.height=1+(j>L?j:L)}else{Z.child2=P,r.child1=v,v.parent=r;let g=r.aabb,k=y.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=r.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=y.height,O=v.height;r.height=1+(D>O?D:O);let j=r.height,L=P.height;Z.height=1+(j>L?j:L)}r=Z}else r=r}let x=r.child1,b=r.child2,_=x.height,d=b.height;r.height=1+(_>d?_:d);let f=r.aabb,m=x.aabb,z=b.aabb;f.minx=m.minx<z.minx?m.minx:z.minx,f.miny=m.miny<z.miny?m.miny:z.miny,f.maxx=m.maxx>z.maxx?m.maxx:z.maxx,f.maxy=m.maxy>z.maxy?m.maxy:z.maxy,r=r.parent}}e.synced=!1,e.moved=!0,e.mnext=e.snext,e.snext=null,e=e.mnext}let t=this.syncs;this.syncs=this.moves,this.moves=t}else for(;this.syncs!=null;){let e=this.syncs;this.syncs=e.snext,e.snext=null;let t=e,n=t.shape;if(t.first_sync)t.first_sync=!1;else{let o=t.dyn?this.dtree:this.stree;if(t==o.root)o.root=null;else{let r=t.parent,a=r.parent,p=r.child1==t?r.child2:r.child1;if(a!=null){a.child1==r?a.child1=p:a.child2=p,p.parent=a;let c=r;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Oe.zpp_pool,Oe.zpp_pool=c;let h=a;for(;h!=null;){if(h.child1==null||h.height<2)h=h;else{let Z=h.child1,y=h.child2,w=y.height-Z.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=h,y.parent=h.parent,h.parent=y,y.parent!=null?y.parent.child1==h?y.parent.child1=y:y.parent.child2=y:o.root=y,v.height>P.height){y.child2=v,h.child2=P,P.parent=h;let g=h.aabb,k=Z.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=h.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=Z.height,O=P.height;h.height=1+(D>O?D:O);let j=h.height,L=v.height;y.height=1+(j>L?j:L)}else{y.child2=P,h.child2=v,v.parent=h;let g=h.aabb,k=Z.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=h.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=Z.height,O=v.height;h.height=1+(D>O?D:O);let j=h.height,L=P.height;y.height=1+(j>L?j:L)}h=y}else if(w<-1){let v=Z.child1,P=Z.child2;if(Z.child1=h,Z.parent=h.parent,h.parent=Z,Z.parent!=null?Z.parent.child1==h?Z.parent.child1=Z:Z.parent.child2=Z:o.root=Z,v.height>P.height){Z.child2=v,h.child1=P,P.parent=h;let g=h.aabb,k=y.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=h.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=y.height,O=P.height;h.height=1+(D>O?D:O);let j=h.height,L=v.height;Z.height=1+(j>L?j:L)}else{Z.child2=P,h.child1=v,v.parent=h;let g=h.aabb,k=y.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=h.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=y.height,O=v.height;h.height=1+(D>O?D:O);let j=h.height,L=P.height;Z.height=1+(j>L?j:L)}h=Z}else h=h}let x=h.child1,b=h.child2,_=h.aabb,d=x.aabb,f=b.aabb;_.minx=d.minx<f.minx?d.minx:f.minx,_.miny=d.miny<f.miny?d.miny:f.miny,_.maxx=d.maxx>f.maxx?d.maxx:f.maxx,_.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let m=x.height,z=b.height;h.height=1+(m>z?m:z),h=h.parent}}else{o.root=p,p.parent=null;let c=r;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Oe.zpp_pool,Oe.zpp_pool=c}}}let l=t.aabb;if(!this.space.continuous&&n.zip_aabb&&n.body!=null)if(n.zip_aabb=!1,n.type==0){let o=n.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let b=h;for(h=h.next;h!=null;){let Z=h;u+=b.x*(Z.y-x.y);let y=Z.y*b.x-Z.x*b.y;c.localCOMx+=(b.x+Z.x)*y,c.localCOMy+=(b.y+Z.y)*y,x=b,b=Z,h=h.next}h=c.lverts.next;let _=h;u+=b.x*(_.y-x.y);let d=_.y*b.x-_.x*b.y;c.localCOMx+=(b.x+_.x)*d,c.localCOMy+=(b.y+_.y)*d,x=b,b=_,h=h.next;let f=h;u+=b.x*(f.y-x.y);let m=f.y*b.x-f.x*b.y;c.localCOMx+=(b.x+f.x)*m,c.localCOMy+=(b.y+f.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else{let o=n.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,u=o.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),h.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}let s=n.aabb;l.minx=s.minx-3,l.miny=s.miny-3,l.maxx=s.maxx+3,l.maxy=s.maxy+3;let i=(t.dyn=n.body.type==1?!1:!n.body.component.sleeping)?this.dtree:this.stree;if(i.root==null)i.root=t,i.root.parent=null;else{let o=t.aabb,r=i.root;for(;r.child1!=null;){let x=r.child1,b=r.child2,_=r.aabb,d=(_.maxx-_.minx+(_.maxy-_.miny))*2,f=et.tmpaabb,m=r.aabb;f.minx=m.minx<o.minx?m.minx:o.minx,f.miny=m.miny<o.miny?m.miny:o.miny,f.maxx=m.maxx>o.maxx?m.maxx:o.maxx,f.maxy=m.maxy>o.maxy?m.maxy:o.maxy;let z=et.tmpaabb,Z=(z.maxx-z.minx+(z.maxy-z.miny))*2,y=2*Z,w=2*(Z-d),v=et.tmpaabb,P=x.aabb;v.minx=o.minx<P.minx?o.minx:P.minx,v.miny=o.miny<P.miny?o.miny:P.miny,v.maxx=o.maxx>P.maxx?o.maxx:P.maxx,v.maxy=o.maxy>P.maxy?o.maxy:P.maxy;let g;if(x.child1==null){let M=et.tmpaabb;g=(M.maxx-M.minx+(M.maxy-M.miny))*2+w}else{let M=x.aabb,C=(M.maxx-M.minx+(M.maxy-M.miny))*2,D=et.tmpaabb;g=(D.maxx-D.minx+(D.maxy-D.miny))*2-C+w}let k=et.tmpaabb,N=b.aabb;k.minx=o.minx<N.minx?o.minx:N.minx,k.miny=o.miny<N.miny?o.miny:N.miny,k.maxx=o.maxx>N.maxx?o.maxx:N.maxx,k.maxy=o.maxy>N.maxy?o.maxy:N.maxy;let E;if(b.child1==null){let M=et.tmpaabb;E=(M.maxx-M.minx+(M.maxy-M.miny))*2+w}else{let M=b.aabb,C=(M.maxx-M.minx+(M.maxy-M.miny))*2,D=et.tmpaabb;E=(D.maxx-D.minx+(D.maxy-D.miny))*2-C+w}if(y<g&&y<E)break;r=g<E?x:b}let a=r,p=a.parent,c;Oe.zpp_pool==null?c=new Oe:(c=Oe.zpp_pool,Oe.zpp_pool=c.next,c.next=null),be.zpp_pool==null?c.aabb=new be:(c.aabb=be.zpp_pool,be.zpp_pool=c.aabb.next,c.aabb.next=null),c.moved=!1,c.synced=!1,c.first_sync=!1,c.parent=p;let u=c.aabb,h=a.aabb;for(u.minx=o.minx<h.minx?o.minx:h.minx,u.miny=o.miny<h.miny?o.miny:h.miny,u.maxx=o.maxx>h.maxx?o.maxx:h.maxx,u.maxy=o.maxy>h.maxy?o.maxy:h.maxy,c.height=a.height+1,p!=null?(p.child1==a?p.child1=c:p.child2=c,c.child1=a,c.child2=t,a.parent=c,t.parent=c):(c.child1=a,c.child2=t,a.parent=c,t.parent=c,i.root=c),r=t.parent;r!=null;){if(r.child1==null||r.height<2)r=r;else{let Z=r.child1,y=r.child2,w=y.height-Z.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=r,y.parent=r.parent,r.parent=y,y.parent!=null?y.parent.child1==r?y.parent.child1=y:y.parent.child2=y:i.root=y,v.height>P.height){y.child2=v,r.child2=P,P.parent=r;let g=r.aabb,k=Z.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=r.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=Z.height,O=P.height;r.height=1+(D>O?D:O);let j=r.height,L=v.height;y.height=1+(j>L?j:L)}else{y.child2=P,r.child2=v,v.parent=r;let g=r.aabb,k=Z.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=r.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=Z.height,O=v.height;r.height=1+(D>O?D:O);let j=r.height,L=P.height;y.height=1+(j>L?j:L)}r=y}else if(w<-1){let v=Z.child1,P=Z.child2;if(Z.child1=r,Z.parent=r.parent,r.parent=Z,Z.parent!=null?Z.parent.child1==r?Z.parent.child1=Z:Z.parent.child2=Z:i.root=Z,v.height>P.height){Z.child2=v,r.child1=P,P.parent=r;let g=r.aabb,k=y.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=r.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=y.height,O=P.height;r.height=1+(D>O?D:O);let j=r.height,L=v.height;Z.height=1+(j>L?j:L)}else{Z.child2=P,r.child1=v,v.parent=r;let g=r.aabb,k=y.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=r.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=y.height,O=v.height;r.height=1+(D>O?D:O);let j=r.height,L=P.height;Z.height=1+(j>L?j:L)}r=Z}else r=r}let x=r.child1,b=r.child2,_=x.height,d=b.height;r.height=1+(_>d?_:d);let f=r.aabb,m=x.aabb,z=b.aabb;f.minx=m.minx<z.minx?m.minx:z.minx,f.miny=m.miny<z.miny?m.miny:z.miny,f.maxx=m.maxx>z.maxx?m.maxx:z.maxx,f.maxy=m.maxy>z.maxy?m.maxy:z.maxy,r=r.parent}}t.synced=!1,t.moved||(t.moved=!0,t.mnext=this.moves,this.moves=t)}}broadphase(e,t){let n=this.syncs;for(;n!=null;){let i=n.shape;if(n.first_sync)n.first_sync=!1;else{let p=n.dyn?this.dtree:this.stree;if(n==p.root)p.root=null;else{let c=n.parent,u=c.parent,h=c.child1==n?c.child2:c.child1;if(u!=null){u.child1==c?u.child1=h:u.child2=h,h.parent=u;let x=c;x.height=-1;let b=x.aabb;b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b.wrap_min=b.wrap_max=null,b._invalidate=null,b._validate=null,b.next=be.zpp_pool,be.zpp_pool=b,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Oe.zpp_pool,Oe.zpp_pool=x;let _=u;for(;_!=null;){if(_.child1==null||_.height<2)_=_;else{let v=_.child1,P=_.child2,g=P.height-v.height;if(g>1){let k=P.child1,N=P.child2;if(P.child1=_,P.parent=_.parent,_.parent=P,P.parent!=null?P.parent.child1==_?P.parent.child1=P:P.parent.child2=P:p.root=P,k.height>N.height){P.child2=k,_.child2=N,N.parent=_;let E=_.aabb,M=v.aabb,C=N.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=P.aabb,O=_.aabb,j=k.aabb;D.minx=O.minx<j.minx?O.minx:j.minx,D.miny=O.miny<j.miny?O.miny:j.miny,D.maxx=O.maxx>j.maxx?O.maxx:j.maxx,D.maxy=O.maxy>j.maxy?O.maxy:j.maxy;let L=v.height,U=N.height;_.height=1+(L>U?L:U);let q=_.height,R=k.height;P.height=1+(q>R?q:R)}else{P.child2=N,_.child2=k,k.parent=_;let E=_.aabb,M=v.aabb,C=k.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=P.aabb,O=_.aabb,j=N.aabb;D.minx=O.minx<j.minx?O.minx:j.minx,D.miny=O.miny<j.miny?O.miny:j.miny,D.maxx=O.maxx>j.maxx?O.maxx:j.maxx,D.maxy=O.maxy>j.maxy?O.maxy:j.maxy;let L=v.height,U=k.height;_.height=1+(L>U?L:U);let q=_.height,R=N.height;P.height=1+(q>R?q:R)}_=P}else if(g<-1){let k=v.child1,N=v.child2;if(v.child1=_,v.parent=_.parent,_.parent=v,v.parent!=null?v.parent.child1==_?v.parent.child1=v:v.parent.child2=v:p.root=v,k.height>N.height){v.child2=k,_.child1=N,N.parent=_;let E=_.aabb,M=P.aabb,C=N.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=v.aabb,O=_.aabb,j=k.aabb;D.minx=O.minx<j.minx?O.minx:j.minx,D.miny=O.miny<j.miny?O.miny:j.miny,D.maxx=O.maxx>j.maxx?O.maxx:j.maxx,D.maxy=O.maxy>j.maxy?O.maxy:j.maxy;let L=P.height,U=N.height;_.height=1+(L>U?L:U);let q=_.height,R=k.height;v.height=1+(q>R?q:R)}else{v.child2=N,_.child1=k,k.parent=_;let E=_.aabb,M=P.aabb,C=k.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=v.aabb,O=_.aabb,j=N.aabb;D.minx=O.minx<j.minx?O.minx:j.minx,D.miny=O.miny<j.miny?O.miny:j.miny,D.maxx=O.maxx>j.maxx?O.maxx:j.maxx,D.maxy=O.maxy>j.maxy?O.maxy:j.maxy;let L=P.height,U=k.height;_.height=1+(L>U?L:U);let q=_.height,R=N.height;v.height=1+(q>R?q:R)}_=v}else _=_}let d=_.child1,f=_.child2,m=_.aabb,z=d.aabb,Z=f.aabb;m.minx=z.minx<Z.minx?z.minx:Z.minx,m.miny=z.miny<Z.miny?z.miny:Z.miny,m.maxx=z.maxx>Z.maxx?z.maxx:Z.maxx,m.maxy=z.maxy>Z.maxy?z.maxy:Z.maxy;let y=d.height,w=f.height;_.height=1+(y>w?y:w),_=_.parent}}else{p.root=h,h.parent=null;let x=c;x.height=-1;let b=x.aabb;b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b.wrap_min=b.wrap_max=null,b._invalidate=null,b._validate=null,b.next=be.zpp_pool,be.zpp_pool=b,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Oe.zpp_pool,Oe.zpp_pool=x}}}let o=n.aabb;if(!e.continuous&&i.zip_aabb&&i.body!=null)if(i.zip_aabb=!1,i.type==0){let p=i.circle;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=!1,p.zip_localCOM){if(p.zip_localCOM=!1,p.type==1){let x=p.polygon;if(x.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(x.lverts.next.next==null)x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;else if(x.lverts.next.next.next==null){x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;let b=1;x.localCOMx+=x.lverts.next.next.x*b,x.localCOMy+=x.lverts.next.next.y*b;let _=.5;x.localCOMx*=_,x.localCOMy*=_}else{x.localCOMx=0,x.localCOMy=0;let b=0,_=x.lverts.next,d=_;_=_.next;let f=_;for(_=_.next;_!=null;){let v=_;b+=f.x*(v.y-d.y);let P=v.y*f.x-v.x*f.y;x.localCOMx+=(f.x+v.x)*P,x.localCOMy+=(f.y+v.y)*P,d=f,f=v,_=_.next}_=x.lverts.next;let m=_;b+=f.x*(m.y-d.y);let z=m.y*f.x-m.x*f.y;x.localCOMx+=(f.x+m.x)*z,x.localCOMy+=(f.y+m.y)*z,d=f,f=m,_=_.next;let Z=_;b+=f.x*(Z.y-d.y);let y=Z.y*f.x-Z.x*f.y;x.localCOMx+=(f.x+Z.x)*y,x.localCOMy+=(f.y+Z.y)*y,b=1/(3*b);let w=b;x.localCOMx*=w,x.localCOMy*=w}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let h=p.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy)}let c=p.radius,u=p.radius;p.aabb.minx=p.worldCOMx-c,p.aabb.miny=p.worldCOMy-u,p.aabb.maxx=p.worldCOMx+c,p.aabb.maxy=p.worldCOMy+u}else{let p=i.polygon;if(p.zip_gverts&&p.body!=null){p.zip_gverts=!1,p.validate_lverts();let h=p.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot));let x=p.lverts.next,b=p.gverts.next;for(;b!=null;){let _=b,d=x;x=x.next,_.x=p.body.posx+(p.body.axisy*d.x-p.body.axisx*d.y),_.y=p.body.posy+(d.x*p.body.axisx+d.y*p.body.axisy),b=b.next}}if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let c=p.gverts.next;p.aabb.minx=c.x,p.aabb.miny=c.y,p.aabb.maxx=c.x,p.aabb.maxy=c.y;let u=p.gverts.next.next;for(;u!=null;){let h=u;h.x<p.aabb.minx&&(p.aabb.minx=h.x),h.x>p.aabb.maxx&&(p.aabb.maxx=h.x),h.y<p.aabb.miny&&(p.aabb.miny=h.y),h.y>p.aabb.maxy&&(p.aabb.maxy=h.y),u=u.next}}let r=i.aabb;o.minx=r.minx-3,o.miny=r.miny-3,o.maxx=r.maxx+3,o.maxy=r.maxy+3;let a=(n.dyn=i.body.type==1?!1:!i.body.component.sleeping)?this.dtree:this.stree;if(a.root==null)a.root=n,a.root.parent=null;else{let p=n.aabb,c=a.root;for(;c.child1!=null;){let d=c.child1,f=c.child2,m=c.aabb,z=(m.maxx-m.minx+(m.maxy-m.miny))*2,Z=et.tmpaabb,y=c.aabb;Z.minx=y.minx<p.minx?y.minx:p.minx,Z.miny=y.miny<p.miny?y.miny:p.miny,Z.maxx=y.maxx>p.maxx?y.maxx:p.maxx,Z.maxy=y.maxy>p.maxy?y.maxy:p.maxy;let w=et.tmpaabb,v=(w.maxx-w.minx+(w.maxy-w.miny))*2,P=2*v,g=2*(v-z),k=et.tmpaabb,N=d.aabb;k.minx=p.minx<N.minx?p.minx:N.minx,k.miny=p.miny<N.miny?p.miny:N.miny,k.maxx=p.maxx>N.maxx?p.maxx:N.maxx,k.maxy=p.maxy>N.maxy?p.maxy:N.maxy;let E;if(d.child1==null){let O=et.tmpaabb;E=(O.maxx-O.minx+(O.maxy-O.miny))*2+g}else{let O=d.aabb,j=(O.maxx-O.minx+(O.maxy-O.miny))*2,L=et.tmpaabb;E=(L.maxx-L.minx+(L.maxy-L.miny))*2-j+g}let M=et.tmpaabb,C=f.aabb;M.minx=p.minx<C.minx?p.minx:C.minx,M.miny=p.miny<C.miny?p.miny:C.miny,M.maxx=p.maxx>C.maxx?p.maxx:C.maxx,M.maxy=p.maxy>C.maxy?p.maxy:C.maxy;let D;if(f.child1==null){let O=et.tmpaabb;D=(O.maxx-O.minx+(O.maxy-O.miny))*2+g}else{let O=f.aabb,j=(O.maxx-O.minx+(O.maxy-O.miny))*2,L=et.tmpaabb;D=(L.maxx-L.minx+(L.maxy-L.miny))*2-j+g}if(P<E&&P<D)break;c=E<D?d:f}let u=c,h=u.parent,x;Oe.zpp_pool==null?x=new Oe:(x=Oe.zpp_pool,Oe.zpp_pool=x.next,x.next=null),be.zpp_pool==null?x.aabb=new be:(x.aabb=be.zpp_pool,be.zpp_pool=x.aabb.next,x.aabb.next=null),x.moved=!1,x.synced=!1,x.first_sync=!1,x.parent=h;let b=x.aabb,_=u.aabb;for(b.minx=p.minx<_.minx?p.minx:_.minx,b.miny=p.miny<_.miny?p.miny:_.miny,b.maxx=p.maxx>_.maxx?p.maxx:_.maxx,b.maxy=p.maxy>_.maxy?p.maxy:_.maxy,x.height=u.height+1,h!=null?(h.child1==u?h.child1=x:h.child2=x,x.child1=u,x.child2=n,u.parent=x,n.parent=x):(x.child1=u,x.child2=n,u.parent=x,n.parent=x,a.root=x),c=n.parent;c!=null;){if(c.child1==null||c.height<2)c=c;else{let v=c.child1,P=c.child2,g=P.height-v.height;if(g>1){let k=P.child1,N=P.child2;if(P.child1=c,P.parent=c.parent,c.parent=P,P.parent!=null?P.parent.child1==c?P.parent.child1=P:P.parent.child2=P:a.root=P,k.height>N.height){P.child2=k,c.child2=N,N.parent=c;let E=c.aabb,M=v.aabb,C=N.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=P.aabb,O=c.aabb,j=k.aabb;D.minx=O.minx<j.minx?O.minx:j.minx,D.miny=O.miny<j.miny?O.miny:j.miny,D.maxx=O.maxx>j.maxx?O.maxx:j.maxx,D.maxy=O.maxy>j.maxy?O.maxy:j.maxy;let L=v.height,U=N.height;c.height=1+(L>U?L:U);let q=c.height,R=k.height;P.height=1+(q>R?q:R)}else{P.child2=N,c.child2=k,k.parent=c;let E=c.aabb,M=v.aabb,C=k.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=P.aabb,O=c.aabb,j=N.aabb;D.minx=O.minx<j.minx?O.minx:j.minx,D.miny=O.miny<j.miny?O.miny:j.miny,D.maxx=O.maxx>j.maxx?O.maxx:j.maxx,D.maxy=O.maxy>j.maxy?O.maxy:j.maxy;let L=v.height,U=k.height;c.height=1+(L>U?L:U);let q=c.height,R=N.height;P.height=1+(q>R?q:R)}c=P}else if(g<-1){let k=v.child1,N=v.child2;if(v.child1=c,v.parent=c.parent,c.parent=v,v.parent!=null?v.parent.child1==c?v.parent.child1=v:v.parent.child2=v:a.root=v,k.height>N.height){v.child2=k,c.child1=N,N.parent=c;let E=c.aabb,M=P.aabb,C=N.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=v.aabb,O=c.aabb,j=k.aabb;D.minx=O.minx<j.minx?O.minx:j.minx,D.miny=O.miny<j.miny?O.miny:j.miny,D.maxx=O.maxx>j.maxx?O.maxx:j.maxx,D.maxy=O.maxy>j.maxy?O.maxy:j.maxy;let L=P.height,U=N.height;c.height=1+(L>U?L:U);let q=c.height,R=k.height;v.height=1+(q>R?q:R)}else{v.child2=N,c.child1=k,k.parent=c;let E=c.aabb,M=P.aabb,C=k.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let D=v.aabb,O=c.aabb,j=N.aabb;D.minx=O.minx<j.minx?O.minx:j.minx,D.miny=O.miny<j.miny?O.miny:j.miny,D.maxx=O.maxx>j.maxx?O.maxx:j.maxx,D.maxy=O.maxy>j.maxy?O.maxy:j.maxy;let L=P.height,U=k.height;c.height=1+(L>U?L:U);let q=c.height,R=N.height;v.height=1+(q>R?q:R)}c=v}else c=c}let d=c.child1,f=c.child2,m=d.height,z=f.height;c.height=1+(m>z?m:z);let Z=c.aabb,y=d.aabb,w=f.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy,c=c.parent}}n.synced=!1,n=n.snext}for(;this.syncs!=null;){let i=this.syncs;this.syncs=i.snext,i.snext=null;let o=i;if(o.moved)continue;o.moved=!1;let r=o.shape;if(r.body.component.sleeping)continue;let p=o.aabb,c=null;for(this.dtree.root!=null&&(this.dtree.root.next=c,c=this.dtree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=o)if(h.child1==null){let x=h.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let b=h.aabb;if(b.miny<=p.maxy&&p.miny<=b.maxy&&b.minx<=p.maxx&&p.minx<=b.maxx){let _,d;r.id<x.id?(_=r.id,d=x.id):(_=x.id,d=r.id);let f=r.pairs.length<x.pairs.length?r:x,m=null,z=f.pairs.head;for(;z!=null;){let k=z.elt;if(k.id==_&&k.di==d){m=k;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}$e.zpp_pool==null?m=new $e:(m=$e.zpp_pool,$e.zpp_pool=m.next,m.next=null),m.n1=o,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let Z=r.pairs,y;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(y=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++;let v=x.pairs,P;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(P=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=o)if(h.child1==null){let x=h.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let b=h.aabb;if(b.miny<=p.maxy&&p.miny<=b.maxy&&b.minx<=p.maxx&&p.minx<=b.maxx){let _,d;r.id<x.id?(_=r.id,d=x.id):(_=x.id,d=r.id);let f=r.pairs.length<x.pairs.length?r:x,m=null,z=f.pairs.head;for(;z!=null;){let k=z.elt;if(k.id==_&&k.di==d){m=k;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}$e.zpp_pool==null?m=new $e:(m=$e.zpp_pool,$e.zpp_pool=m.next,m.next=null),m.n1=o,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let Z=r.pairs,y;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(y=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++;let v=x.pairs,P;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(P=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}}for(;this.moves!=null;){let i=this.moves;this.moves=i.mnext,i.mnext=null;let o=i;o.moved=!1;let r=o.shape;if(r.body.component.sleeping)continue;let p=o.aabb,c=null;for(this.dtree.root!=null&&(this.dtree.root.next=c,c=this.dtree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=o)if(h.child1==null){let x=h.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let b=h.aabb;if(b.miny<=p.maxy&&p.miny<=b.maxy&&b.minx<=p.maxx&&p.minx<=b.maxx){let _,d;r.id<x.id?(_=r.id,d=x.id):(_=x.id,d=r.id);let f=r.pairs.length<x.pairs.length?r:x,m=null,z=f.pairs.head;for(;z!=null;){let k=z.elt;if(k.id==_&&k.di==d){m=k;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}$e.zpp_pool==null?m=new $e:(m=$e.zpp_pool,$e.zpp_pool=m.next,m.next=null),m.n1=o,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let Z=r.pairs,y;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(y=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++;let v=x.pairs,P;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(P=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=o)if(h.child1==null){let x=h.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let b=h.aabb;if(b.miny<=p.maxy&&p.miny<=b.maxy&&b.minx<=p.maxx&&p.minx<=b.maxx){let _,d;r.id<x.id?(_=r.id,d=x.id):(_=x.id,d=r.id);let f=r.pairs.length<x.pairs.length?r:x,m=null,z=f.pairs.head;for(;z!=null;){let k=z.elt;if(k.id==_&&k.di==d){m=k;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}$e.zpp_pool==null?m=new $e:(m=$e.zpp_pool,$e.zpp_pool=m.next,m.next=null),m.n1=o,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let Z=r.pairs,y;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(y=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++;let v=x.pairs,P;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(P=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}}let l=null,s=this.pairs;for(;s!=null;){let i;if(s.first)i=!1;else{let h=s.n1.aabb,x=s.n2.aabb;i=!(x.miny<=h.maxy&&h.miny<=x.maxy&&x.minx<=h.maxx&&h.minx<=x.maxx)}if(i){l==null?this.pairs=s.next:l.next=s.next;let h=s.n1.shape.pairs,x=null,b=h.head,_=!1;for(;b!=null;){if(b.elt==s){let w,v;x==null?(w=h.head,v=w.next,h.head=v,h.head==null&&(h.pushmod=!0)):(w=x.next,v=w.next,x.next=v,v==null&&(h.pushmod=!0));let P=w;P.elt=null,P.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P,h.modified=!0,h.length--,h.pushmod=!0,_=!0;break}x=b,b=b.next}let d=s.n2.shape.pairs,f=null,m=d.head,z=!1;for(;m!=null;){if(m.elt==s){let w,v;f==null?(w=d.head,v=w.next,d.head=v,d.head==null&&(d.pushmod=!0)):(w=f.next,v=w.next,f.next=v,v==null&&(d.pushmod=!0));let P=w;P.elt=null,P.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P,d.modified=!0,d.length--,d.pushmod=!0,z=!0;break}f=m,m=m.next}let Z=s.next;s.arb!=null&&(s.arb.pair=null),s.arb=null;let y=s;y.n1=y.n2=null,y.sleeping=!1,y.next=$e.zpp_pool,$e.zpp_pool=y,s=Z;continue}let o=s.n1.shape,r=o.body,a=s.n2.shape,p=a.body;if(!s.first&&(r.component.sleeping||r.type==1)&&(p.component.sleeping||p.type==1)){s.sleeping=!0,l==null?this.pairs=s.next:l.next=s.next,s=s.next;continue}s.first=!1;let c=o.aabb,u=a.aabb;if(u.miny<=c.maxy&&c.miny<=u.maxy&&u.minx<=c.maxx&&c.minx<=u.maxx){let h=s.arb;t?s.arb=e.narrowPhase(o,a,r.type!=2||p.type!=2,s.arb,!1):s.arb=e.continuousEvent(o,a,r.type!=2||p.type!=2,s.arb,!1),s.arb==null?h!=null&&(h.pair=null):s.arb.pair=s}l=s,s=s.next}}clear(){for(;this.syncs!=null;){let e=this.syncs.snext;this.syncs.snext=null,this.syncs.first_sync&&(this.syncs.shape.node=null,this.syncs.shape.removedFromSpace(),this.syncs.shape=null),this.syncs=e}for(;this.moves!=null;){let e=this.moves.mnext;this.moves.mnext=null,this.moves.first_sync&&(this.moves.shape.node=null,this.moves.shape.removedFromSpace(),this.moves.shape=null),this.moves=e}for(;this.pairs!=null;){let e=this.pairs.next;this.pairs.arb!=null&&(this.pairs.arb.pair=null),this.pairs.arb=null;let t=this.pairs.n1.shape.pairs,n=this.pairs,l=null,s=t.head,i=!1;for(;s!=null;){if(s.elt==n){let h,x;l==null?(h=t.head,x=h.next,t.head=x,t.head==null&&(t.pushmod=!0)):(h=l.next,x=h.next,l.next=x,x==null&&(t.pushmod=!0));let b=h;b.elt=null,b.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b,t.modified=!0,t.length--,t.pushmod=!0,i=!0;break}l=s,s=s.next}let o=this.pairs.n2.shape.pairs,r=this.pairs,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==r){let h,x;a==null?(h=o.head,x=h.next,o.head=x,o.head==null&&(o.pushmod=!0)):(h=a.next,x=h.next,a.next=x,x==null&&(o.pushmod=!0));let b=h;b.elt=null,b.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b,o.modified=!0,o.length--,o.pushmod=!0,c=!0;break}a=p,p=p.next}let u=this.pairs;u.n1=u.n2=null,u.sleeping=!1,u.next=$e.zpp_pool,$e.zpp_pool=u,this.pairs=e}this.dtree.clear(),this.stree.clear()}shapesUnderPoint(e,t,n,l){this.sync_broadphase();let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,o=l??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c;if(n!=null){let u=a.shape.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(a.shape.type==0?Ee.circleContains(a.shape.circle,i)&&o.push(a.shape.outer):Ee.polyContains(a.shape.polygon,i)&&o.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c;if(n!=null){let u=a.shape.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(a.shape.type==0?Ee.circleContains(a.shape.circle,i)&&o.push(a.shape.outer):Ee.polyContains(a.shape.polygon,i)&&o.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}let r=i;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=le.zpp_pool,le.zpp_pool=r,o}bodiesUnderPoint(e,t,n,l){this.sync_broadphase();let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,o=l??new fe._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c=a.shape.body.outer;if(!o.has(c)){let u;if(n!=null){let h=a.shape.filter;u=(h.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(a.shape.type==0?Ee.circleContains(a.shape.circle,i)&&o.push(c):Ee.polyContains(a.shape.polygon,i)&&o.push(c))}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c=a.shape.body.outer;if(!o.has(c)){let u;if(n!=null){let h=a.shape.filter;u=(h.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(a.shape.type==0?Ee.circleContains(a.shape.circle,i)&&o.push(c):Ee.polyContains(a.shape.polygon,i)&&o.push(c))}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}let r=i;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=le.zpp_pool,le.zpp_pool=r,o}shapesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,o=s??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(r.child1==null){let p;if(l!=null){let c=r.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;p&&o.push(r.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;c&&o.push(p.shape.outer)}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=r.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(r.child1==null){let c;if(l!=null){let u=r.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c)if(t)if(n)Ee.containTest(this.aabbShape.zpp_inner,r.shape)&&o.push(r.shape.outer);else{let u=r.shape.aabb;(u.minx>=i.minx&&u.miny>=i.miny&&u.maxx<=i.maxx&&u.maxy<=i.maxy||Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner))&&o.push(r.shape.outer)}else{let u;if(n){let h=r.shape.aabb;u=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy}else u=!0;u&&o.push(r.shape.outer)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(r.child1==null){let p;if(l!=null){let c=r.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;p&&o.push(r.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;c&&o.push(p.shape.outer)}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=r.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(r.child1==null){let c;if(l!=null){let u=r.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c)if(t)if(n)Ee.containTest(this.aabbShape.zpp_inner,r.shape)&&o.push(r.shape.outer);else{let u=r.shape.aabb;(u.minx>=i.minx&&u.miny>=i.miny&&u.maxx<=i.maxx&&u.maxy<=i.maxy||Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner))&&o.push(r.shape.outer)}else{let u;if(n){let h=r.shape.aabb;u=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy}else u=!0;u&&o.push(r.shape.outer)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}return o}bodiesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,o=s??new fe._nape.phys.BodyList;if(this.failed==null&&(this.failed=new fe._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(r.child1==null){let p;if(l!=null){let c=r.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;if(p){let c=r.shape.body.outer;o.has(c)||o.push(c)}}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c){let u=p.shape.body.outer;o.has(u)||o.push(u)}}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=r.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(r.child1==null){let c=r.shape.body.outer,u;if(l!=null){let h=r.shape.filter;u=(h.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(t)if(n){if(!this.failed.has(c)){let h=Ee.containTest(this.aabbShape.zpp_inner,r.shape);!o.has(c)&&h?o.push(c):h||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner)&&o.push(c);else if(n){if(!this.failed.has(c)){let h=r.shape.aabb,x=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy;!o.has(c)&&x?o.push(c):x||(o.remove(c),this.failed.push(c))}}else{let h;if(o.has(c))h=!1;else{let x=r.shape.aabb;h=x.minx>=i.minx&&x.miny>=i.miny&&x.maxx<=i.maxx&&x.maxy<=i.maxy}h&&o.push(c)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(r.child1==null){let p;if(l!=null){let c=r.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;if(p){let c=r.shape.body.outer;o.has(c)||o.push(c)}}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c){let u=p.shape.body.outer;o.has(u)||o.push(u)}}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=r.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(r.child1==null){let c=r.shape.body.outer,u;if(l!=null){let h=r.shape.filter;u=(h.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(t)if(n){if(!this.failed.has(c)){let h=Ee.containTest(this.aabbShape.zpp_inner,r.shape);!o.has(c)&&h?o.push(c):h||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner)&&o.push(c);else if(n){if(!this.failed.has(c)){let h=r.shape.aabb,x=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy;!o.has(c)&&x?o.push(c):x||(o.remove(c),this.failed.push(c))}}else{let h;if(o.has(c))h=!1;else{let x=r.shape.aabb;h=x.minx>=i.minx&&x.miny>=i.miny&&x.maxx<=i.maxx&&x.maxy<=i.maxy}h&&o.push(c)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}return this.failed.clear(),o}shapesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let o=this.circShape.zpp_inner.aabb,r=i??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx)if(a.child1==null){let c;if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(l?Ee.containTest(this.circShape.zpp_inner,a.shape)&&r.push(a.shape.outer):Ee.testCollide_safe(a.shape,this.circShape.zpp_inner)&&r.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx)if(a.child1==null){let c;if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(l?Ee.containTest(this.circShape.zpp_inner,a.shape)&&r.push(a.shape.outer):Ee.testCollide_safe(a.shape,this.circShape.zpp_inner)&&r.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return r}bodiesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let o=this.circShape.zpp_inner.aabb,r=i??new fe._nape.phys.BodyList;if(this.failed==null&&(this.failed=new fe._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx)if(a.child1==null){let c=a.shape.body.outer,u;if(s!=null){let h=a.shape.filter;u=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(l){if(!this.failed.has(c)){let h=Ee.containTest(this.circShape.zpp_inner,a.shape);!r.has(c)&&h?r.push(c):h||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ee.testCollide_safe(a.shape,this.circShape.zpp_inner)&&r.push(c)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx)if(a.child1==null){let c=a.shape.body.outer,u;if(s!=null){let h=a.shape.filter;u=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(l){if(!this.failed.has(c)){let h=Ee.containTest(this.circShape.zpp_inner,a.shape);!r.has(c)&&h?r.push(c):h||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ee.testCollide_safe(a.shape,this.circShape.zpp_inner)&&r.push(c)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return this.failed.clear(),r}shapesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx)if(o.child1==null){let a;if(n!=null){let p=o.shape.filter;a=(p.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&p.collisionGroup)!=0}else a=!0;a&&(t?Ee.containTest(e,o.shape)&&i.push(o.shape.outer):Ee.testCollide_safe(o.shape,e)&&i.push(o.shape.outer))}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx)if(o.child1==null){let a;if(n!=null){let p=o.shape.filter;a=(p.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&p.collisionGroup)!=0}else a=!0;a&&(t?Ee.containTest(e,o.shape)&&i.push(o.shape.outer):Ee.testCollide_safe(o.shape,e)&&i.push(o.shape.outer))}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}return i}bodiesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new fe._nape.phys.BodyList;if(this.failed==null&&(this.failed=new fe._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx)if(o.child1==null){let a=o.shape.body.outer,p;if(n!=null){let c=o.shape.filter;p=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else p=!0;if(p)if(t){if(!this.failed.has(a)){let c=Ee.containTest(e,o.shape);!i.has(a)&&c?i.push(a):c||(i.remove(a),this.failed.push(a))}}else!i.has(a)&&Ee.testCollide_safe(o.shape,e)&&i.push(a)}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx)if(o.child1==null){let a=o.shape.body.outer,p;if(n!=null){let c=o.shape.filter;p=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else p=!0;if(p)if(t){if(!this.failed.has(a)){let c=Ee.containTest(e,o.shape);!i.has(a)&&c?i.push(a):c||(i.remove(a),this.failed.push(a))}}else!i.has(a)&&Ee.testCollide_safe(o.shape,e)&&i.push(a)}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}return this.failed.clear(),i}rayCast(e,t,n){this.openlist==null&&(this.openlist=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),e.validate_dir();let l=e.maxdist;if(this.dtree.root!=null&&e.aabbtest(this.dtree.root.aabb)){let i=e.aabbsect(this.dtree.root.aabb);if(i>=0&&i<l){this.dtree.root.rayt=i;let o=null,r=this.openlist.head;for(;r!=null;){let h=r.elt;if(this.dtree.root.rayt<h.rayt)break;o=r,r=r.next}let a=this.openlist,p=this.dtree.root,c;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?c=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(c=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=c.next,c.next=null),c.elt=p;let u=c;o==null?(u.next=a.head,a.head=u):(u.next=o.next,o.next=u),a.pushmod=a.modified=!0,a.length++}}if(this.stree.root!=null&&e.aabbtest(this.stree.root.aabb)){let i=e.aabbsect(this.stree.root.aabb);if(i>=0&&i<l){this.stree.root.rayt=i;let o=null,r=this.openlist.head;for(;r!=null;){let h=r.elt;if(this.stree.root.rayt<h.rayt)break;o=r,r=r.next}let a=this.openlist,p=this.stree.root,c;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?c=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(c=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=c.next,c.next=null),c.elt=p;let u=c;o==null?(u.next=a.head,a.head=u):(u.next=o.next,o.next=u),a.pushmod=a.modified=!0,a.length++}}let s=null;for(;this.openlist.head!=null;){let i=this.openlist.pop_unsafe();if(i.rayt>=l)break;if(i.child1==null){let o=i.shape,r;if(n!=null){let a=o.filter;r=(a.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&a.collisionGroup)!=0}else r=!0;if(r){let a=o.type==0?e.circlesect(o.circle,t,l):e.aabbtest(o.aabb)?e.polysect(o.polygon,t,l):null;if(a!=null){if(a.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=a.zpp_inner.toiDistance,s!=null){if(s.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");s.zpp_inner.free()}s=a}}}else{if(i.child1!=null&&e.aabbtest(i.child1.aabb)){let o=e.aabbsect(i.child1.aabb);if(o>=0&&o<l){i.child1.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(i.child1.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=i.child1,u;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(u=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=c;let h=u;r==null?(h.next=p.head,p.head=h):(h.next=r.next,r.next=h),p.pushmod=p.modified=!0,p.length++}}if(i.child2!=null&&e.aabbtest(i.child2.aabb)){let o=e.aabbsect(i.child2.aabb);if(o>=0&&o<l){i.child2.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(i.child2.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=i.child2,u;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(u=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=c;let h=u;r==null?(h.next=p.head,p.head=h):(h.next=r.next,r.next=h),p.pushmod=p.modified=!0,p.length++}}}}return this.openlist.clear(),s}rayMultiCast(e,t,n,l){this.openlist==null&&(this.openlist=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),e.validate_dir();let s=e.maxdist>=1/0,i=l??new fe._nape.geom.RayResultList;if(this.dtree.root!=null&&e.aabbtest(this.dtree.root.aabb))if(s)this.openlist.add(this.dtree.root);else{let o=e.aabbsect(this.dtree.root.aabb);o>=0&&o<e.maxdist&&this.openlist.add(this.dtree.root)}if(this.stree.root!=null&&e.aabbtest(this.stree.root.aabb))if(s)this.openlist.add(this.stree.root);else{let o=e.aabbsect(this.stree.root.aabb);o>=0&&o<e.maxdist&&this.openlist.add(this.stree.root)}for(;this.openlist.head!=null;){let o=this.openlist.pop_unsafe();if(o.child1==null){let r=o.shape,a;if(n!=null){let p=r.filter;a=(p.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&p.collisionGroup)!=0}else a=!0;a&&(r.type==0?e.circlesect2(r.circle,t,i):e.aabbtest(r.aabb)&&e.polysect2(r.polygon,t,i))}else{if(o.child1!=null&&e.aabbtest(o.child1.aabb))if(s)this.openlist.add(o.child1);else{let r=e.aabbsect(o.child1.aabb);r>=0&&r<e.maxdist&&this.openlist.add(o.child1)}if(o.child2!=null&&e.aabbtest(o.child2.aabb))if(s)this.openlist.add(o.child2);else{let r=e.aabbsect(o.child2.aabb);r>=0&&r<e.maxdist&&this.openlist.add(o.child2)}}}return this.openlist.clear(),i}};fe.__name__=["zpp_nape","space","ZPP_DynAABBPhase"],fe.__super__=null,fe._zpp=null,fe._nape=null,fe.FATTEN=3,fe.VEL_STEPS=2;var ls=fe;var Ms=class Ms{constructor(){this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.comps=null;this.sleep=!1;this.waket=0;this.comps=new Ms._zpp.util.ZNPList_ZPP_Component}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){}alloc(){this.waket=0}};Ms.__name__=["zpp_nape","space","ZPP_Island"],Ms.zpp_pool=null,Ms._zpp=null;var yt=Ms;var Zs=class{constructor(){this.next=null;this.parent=this;this.rank=0;this.isBody=!1;this.body=null;this.constraint=null;this.island=null;this.sleeping=!1;this.waket=0;this.woken=!1;this._inuse=!1}free(){this.body=null,this.constraint=null}alloc(){}reset(){this.sleeping=!1,this.island=null,this.parent=this,this.rank=0}};Zs.__name__=["zpp_nape","space","ZPP_Component"],Zs.zpp_pool=null;var Nn=class Nn{constructor(){this.id=0;this.di=0;this.int1=null;this.int2=null;this.arbiters=null;this.COLLISIONstate=null;this.COLLISIONstamp=null;this.SENSORstate=null;this.SENSORstamp=null;this.FLUIDstate=null;this.FLUIDstamp=null;this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.freed=!1;this.lazydel=!1;this.arbiters=new Nn._zpp.util.ZNPList_ZPP_Arbiter}static get(e,t){let n;return Nn.zpp_pool==null?n=new Nn:(n=Nn.zpp_pool,Nn.zpp_pool=n.next,n.next=null),n.freed=!1,n.lazydel=!1,n.COLLISIONstate=1,n.COLLISIONstamp=0,n.SENSORstate=1,n.SENSORstamp=0,n.FLUIDstate=1,n.FLUIDstamp=0,e.id<t.id?(n.int1=e,n.int2=t):(n.int1=t,n.int2=e),n.id=n.int1.id,n.di=n.int2.id,n}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){this.int1=this.int2=null,this.id=this.di=-1,this.freed=!0}alloc(){this.freed=!1,this.lazydel=!1,this.COLLISIONstate=1,this.COLLISIONstamp=0,this.SENSORstate=1,this.SENSORstamp=0,this.FLUIDstate=1,this.FLUIDstamp=0}add_arb(e){let t=!1,n=this.arbiters.head;for(;n!=null;){if(n.elt==e){t=!0;break}n=n.next}if(t)return!1;{let l=this.arbiters,s,i=Nn._zpp.util.ZNPNode_ZPP_Arbiter;i.zpp_pool==null?s=new i:(s=i.zpp_pool,i.zpp_pool=s.next,s.next=null),s.elt=e;let o=s;return o.next=l.head,l.head=o,l.modified=!0,l.length++,!0}}try_remove_arb(e){let t=this.arbiters,n=null,l=t.head,s=!1;for(;l!=null;){if(l.elt==e){let i,o;n==null?(i=t.head,o=i.next,t.head=o,t.head==null&&(t.pushmod=!0)):(i=n.next,o=i.next,n.next=o,o==null&&(t.pushmod=!0));let r=i;r.elt=null;let a=Nn._zpp.util.ZNPNode_ZPP_Arbiter;r.next=a.zpp_pool,a.zpp_pool=r,t.modified=!0,t.length--,t.pushmod=!0,s=!0;break}n=l,l=l.next}return s}remove_arb(e){let t=this.arbiters,n=null,l=t.head;for(;l!=null;){if(l.elt==e){let s,i;n==null?(s=t.head,i=s.next,t.head=i,t.head==null&&(t.pushmod=!0)):(s=n.next,i=s.next,n.next=i,i==null&&(t.pushmod=!0));let o=s;o.elt=null;let r=Nn._zpp.util.ZNPNode_ZPP_Arbiter;o.next=r.zpp_pool,r.zpp_pool=o,t.modified=!0,t.length--,t.pushmod=!0;break}n=l,l=l.next}}empty_arb(e){let t=!0,n=this.arbiters.head;for(;n!=null;)if((n.elt.type&e)==0){n=n.next;continue}else{t=!1;break}return t}really_empty(){return this.arbiters.head==null}sleeping(){let e=!0,t=this.arbiters.head;for(;t!=null;)if(t.elt.sleeping){t=t.next;continue}else{e=!1;break}return e}};Nn.__name__=["zpp_nape","space","ZPP_CallbackSet"],Nn.zpp_pool=null,Nn._zpp=null;var Yt=Nn;var Qn=class Qn{constructor(e){this.cbsets=null;this.space=null;let t=Qn._zpp.util.ZPP_Set_ZPP_CbSet;t.zpp_pool==null?this.cbsets=new t:(this.cbsets=t.zpp_pool,t.zpp_pool=this.cbsets.next,this.cbsets.next=null),this.cbsets.lt=Qn._zpp.callbacks.ZPP_CbSet.setlt,this.space=e}get(e){if(e.head==null)return null;let t=Qn._zpp.callbacks.ZPP_CbSet,n;t.zpp_pool==null?n=new t:(n=t.zpp_pool,t.zpp_pool=n.next,n.next=null);let l=n.cbTypes;n.cbTypes=e;let s=this.cbsets.find_weak(n),i;if(s!=null)i=s.data;else{let r=t.get(e);this.cbsets.insert(r),r.manager=this,i=r}n.cbTypes=l;let o=n;for(o.listeners.clear(),o.zip_listeners=!0,o.bodylisteners.clear(),o.zip_bodylisteners=!0,o.conlisteners.clear(),o.zip_conlisteners=!0;o.cbTypes.head!=null;)o.cbTypes.pop_unsafe().cbsets.remove(o);return o.next=t.zpp_pool,t.zpp_pool=o,i}remove(e){let t=Qn._zpp.callbacks.ZPP_CbSetPair;for(this.cbsets.remove(e);e.cbpairs.head!=null;){let n=e.cbpairs.pop_unsafe();n.a!=n.b&&(e==n.a?n.b.cbpairs.remove(n):n.a.cbpairs.remove(n));let l=n;l.a=l.b=null,l.listeners.clear(),l.next=t.zpp_pool,t.zpp_pool=l}e.manager=null}clear(){}validate(){if(!this.cbsets.empty()){let e=this.cbsets.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;)if(e.data.validate(),e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent}}}pair(e,t){let n=Qn._zpp.callbacks.ZPP_CbSet,l=Qn._zpp.callbacks.ZPP_CbSetPair,s=null,o=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;o!=null;){let r=o.elt;if(r.a==e&&r.b==t||r.a==t&&r.b==e){s=r;break}o=o.next}if(s==null){let r;l.zpp_pool==null?r=new l:(r=l.zpp_pool,l.zpp_pool=r.next,r.next=null),r.zip_listeners=!0,n.setlt(e,t)?(r.a=e,r.b=t):(r.a=t,r.b=e),s=r,e.cbpairs.add(s),t!=e&&t.cbpairs.add(s)}return s.zip_listeners&&(s.zip_listeners=!1,s.__validate()),s}valid_listener(e){return e.space==this.space}};Qn.__name__=["zpp_nape","space","ZPP_CbSetManager"],Qn._zpp=null;var os=Qn;var I=class I{constructor(e,t){this.outer=null;this.userData=null;this.gravityx=null;this.gravityy=null;this.wrap_gravity=null;this.bodies=null;this.wrap_bodies=null;this.compounds=null;this.wrap_compounds=null;this.constraints=null;this.wrap_constraints=null;this.kinematics=null;this.bphase=null;this.__static=null;this.global_lin_drag=null;this.global_ang_drag=null;this.stamp=null;this.midstep=null;this.time=null;this.sortcontacts=null;this.c_arbiters_true=null;this.c_arbiters_false=null;this.f_arbiters=null;this.s_arbiters=null;this.wrap_arbiters=null;this.live=null;this.wrap_live=null;this.live_constraints=null;this.wrap_livecon=null;this.staticsleep=null;this.islands=null;this.listeners=null;this.wrap_listeners=null;this.callbacks=null;this.callbackset_list=null;this.cbsets=null;this.convexShapeList=null;this.pre_dt=null;this.toiEvents=null;this.continuous=null;this.precb=null;this.prelisteners=null;this.mrca1=null;this.mrca2=null;this.__class__=I;this.prelisteners=null,this.precb=null,this.continuous=!1,this.toiEvents=null,this.pre_dt=0,this.convexShapeList=null,this.cbsets=null,this.callbackset_list=null,this.callbacks=null,this.wrap_listeners=null,this.listeners=null,this.islands=null,this.staticsleep=null,this.wrap_livecon=null,this.live_constraints=null,this.wrap_live=null,this.live=null,this.wrap_arbiters=null,this.s_arbiters=null,this.f_arbiters=null,this.c_arbiters_false=null,this.c_arbiters_true=null,this.sortcontacts=!1,this.time=0,this.midstep=!1,this.stamp=0,this.global_ang_drag=0,this.global_lin_drag=0,this.__static=null,this.bphase=null,this.kinematics=null,this.wrap_constraints=null,this.constraints=null,this.wrap_compounds=null,this.compounds=null,this.wrap_bodies=null,this.bodies=null,this.wrap_gravity=null,this.gravityy=0,this.gravityx=0,this.userData=null,this.outer=null,this.toiEvents=new I._zpp.util.ZNPList_ZPP_ToiEvent,this.global_lin_drag=.015,this.global_ang_drag=.015,Gt.internal=!0,this.precb=Gt._createPreCb(),this.precb.zpp_inner=new Gt,Gt.internal=!1,this.sortcontacts=!0,this.pre_dt=0;let n;t!=null?($.Broadphase_DYNAMIC_AABB_TREE==null&&($.internal=!0,$.Broadphase_DYNAMIC_AABB_TREE=new I._nape.space.Broadphase,$.internal=!1),n=t==$.Broadphase_DYNAMIC_AABB_TREE):n=!0,n?this.bphase=new I._zpp.space.ZPP_DynAABBPhase(this):($.Broadphase_SWEEP_AND_PRUNE==null&&($.internal=!0,$.Broadphase_SWEEP_AND_PRUNE=new I._nape.space.Broadphase,$.internal=!1),t==$.Broadphase_SWEEP_AND_PRUNE&&(this.bphase=new I._zpp.space.ZPP_SweepPhase(this))),this.time=0;let l=this;e!=null?(this.gravityx=e.x,this.gravityy=e.y):(this.gravityx=0,this.gravityy=0),this.bodies=new I._zpp.util.ZNPList_ZPP_Body,this.wrap_bodies=I._zpp.util.ZPP_BodyList.get(this.bodies),this.wrap_bodies.zpp_inner.adder=s=>this.bodies_adder(s),this.wrap_bodies.zpp_inner.subber=s=>this.bodies_subber(s),this.wrap_bodies.zpp_inner._modifiable=()=>this.bodies_modifiable(),this.compounds=new I._zpp.util.ZNPList_ZPP_Compound,this.wrap_compounds=I._zpp.util.ZPP_CompoundList.get(this.compounds),this.wrap_compounds.zpp_inner.adder=s=>this.compounds_adder(s),this.wrap_compounds.zpp_inner.subber=s=>this.compounds_subber(s),this.wrap_compounds.zpp_inner._modifiable=()=>this.compounds_modifiable(),this.kinematics=new I._zpp.util.ZNPList_ZPP_Body,this.c_arbiters_true=new I._zpp.util.ZNPList_ZPP_ColArbiter,this.c_arbiters_false=new I._zpp.util.ZNPList_ZPP_ColArbiter,this.f_arbiters=new I._zpp.util.ZNPList_ZPP_FluidArbiter,this.s_arbiters=new I._zpp.util.ZNPList_ZPP_SensorArbiter,this.islands=new yt,this.live=new I._zpp.util.ZNPList_ZPP_Body,this.wrap_live=I._zpp.util.ZPP_BodyList.get(this.live,!0),this.staticsleep=new I._zpp.util.ZNPList_ZPP_Body,this.constraints=new I._zpp.util.ZNPList_ZPP_Constraint,this.wrap_constraints=I._zpp.util.ZPP_ConstraintList.get(this.constraints),this.wrap_constraints.zpp_inner.adder=s=>this.constraints_adder(s),this.wrap_constraints.zpp_inner.subber=s=>this.constraints_subber(s),this.wrap_constraints.zpp_inner._modifiable=()=>this.constraints_modifiable(),this.live_constraints=new I._zpp.util.ZNPList_ZPP_Constraint,this.wrap_livecon=I._zpp.util.ZPP_ConstraintList.get(this.live_constraints,!0),this.__static=kn.__static(),this.__static.zpp_inner.space=this,this.callbacks=new Gt,this.midstep=!1,this.listeners=new I._zpp.util.ZNPList_ZPP_Listener,this.wrap_listeners=I._zpp.util.ZPP_ListenerList.get(this.listeners),this.wrap_listeners.zpp_inner.adder=s=>this.listeners_adder(s),this.wrap_listeners.zpp_inner.subber=s=>this.listeners_subber(s),this.wrap_listeners.zpp_inner._modifiable=()=>this.listeners_modifiable(),this.callbackset_list=new Yt,this.mrca1=new I._zpp.util.ZNPList_ZPP_Interactor,this.mrca2=new I._zpp.util.ZNPList_ZPP_Interactor,this.prelisteners=new I._zpp.util.ZNPList_ZPP_InteractionListener,this.cbsets=new os(this)}getgravity(){let e=this.gravityx,t=this.gravityy;if(t==null&&(t=0),e==null&&(e=0),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(I._zpp.util.ZPP_PubPool.poolVec2==null?n=new I._nape.geom.Vec2:(n=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=e,l.y=t,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x==e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),s=n.zpp_inner.y==t}else s=!1;if(!s){n.zpp_inner.x=e,n.zpp_inner.y=t;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.wrap_gravity=n,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=l=>this.gravity_invalidate(l),this.wrap_gravity.zpp_inner._validate=()=>this.gravity_validate()}gravity_invalidate(e){if(this.midstep)throw new Error("Error: Space::gravity cannot be set during space step");this.gravityx=e.x,this.gravityy=e.y;let t=new I._zpp.util.ZNPList_ZPP_Compound,n=this.bodies.head;for(;n!=null;){let i=n.elt;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1)),n=n.next}let l=this.compounds.head;for(;l!=null;){let s=l.elt;t.add(s),l=l.next}for(;t.head!=null;){let s=t.pop_unsafe(),i=s.bodies.head;for(;i!=null;){let a=i.elt;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1)),i=i.next}let o=s.compounds.head;for(;o!=null;){let r=o.elt;t.add(r),o=o.next}}}gravity_validate(){this.wrap_gravity.zpp_inner.x=this.gravityx,this.wrap_gravity.zpp_inner.y=this.gravityy}clear(){for(;this.listeners.head!=null;){let t=this.listeners.pop_unsafe();this.remListener(t)}for(;this.callbackset_list.next!=null;){let t=this.callbackset_list.pop_unsafe();t.arbiters.clear();let n=t;n.int1=n.int2=null,n.id=n.di=-1,n.freed=!0,n.next=Yt.zpp_pool,Yt.zpp_pool=n}for(;this.c_arbiters_true.head!=null;){let t=this.c_arbiters_true.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,o=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,o=!0;break}s=i,i=i.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=r.head,h=u.next,r.head=h,r.head==null&&(r.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(r.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let l=t.contacts,s=l.next;l.pop();let i=s;i.arbiter=null,i.next=we.zpp_pool,we.zpp_pool=i;let o=t.innards,r=o.next;o.next=r.next,r._inuse=!1,o.next==null&&(o.pushmod=!0),o.modified=!0,o.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=xt.zpp_pool,xt.zpp_pool=n,t.pre_dt=-1}for(;this.c_arbiters_false.head!=null;){let t=this.c_arbiters_false.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,o=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,o=!0;break}s=i,i=i.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=r.head,h=u.next,r.head=h,r.head==null&&(r.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(r.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let l=t.contacts,s=l.next;l.pop();let i=s;i.arbiter=null,i.next=we.zpp_pool,we.zpp_pool=i;let o=t.innards,r=o.next;o.next=r.next,r._inuse=!1,o.next==null&&(o.pushmod=!0),o.modified=!0,o.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=xt.zpp_pool,xt.zpp_pool=n,t.pre_dt=-1}for(;this.s_arbiters.head!=null;){let t=this.s_arbiters.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,o=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,o=!0;break}s=i,i=i.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=r.head,h=u.next,r.head=h,r.head==null&&(r.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(r.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}t.b1=t.b2=null,t.active=!1,t.intchange=!1;let n=t;n.next=jt.zpp_pool,jt.zpp_pool=n}for(;this.f_arbiters.head!=null;){let t=this.f_arbiters.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,o=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,o=!0;break}s=i,i=i.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=r.head,h=u.next,r.head=h,r.head==null&&(r.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(r.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}t.b1=t.b2=null,t.active=!1,t.intchange=!1;let n=t;n.next=Ct.zpp_pool,Ct.zpp_pool=n,t.pre_dt=-1}for(this.bphase.clear();this.bodies.head!=null;){let t=this.bodies.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let s=n.comps.pop_unsafe();s.sleeping=!1,s.island=null,s.parent=s,s.rank=0}let l=n;l.next=yt.zpp_pool,yt.zpp_pool=l}}t.removedFromSpace(),t.space=null}for(;this.constraints.head!=null;){let t=this.constraints.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let s=n.comps.pop_unsafe();s.sleeping=!1,s.island=null,s.parent=s,s.rank=0}let l=n;l.next=yt.zpp_pool,yt.zpp_pool=l}}t.removedFromSpace(),t.space=null}this.kinematics.clear();let e=new I._zpp.util.ZNPList_ZPP_Compound;for(;this.compounds.head!=null;){let t=this.compounds.pop_unsafe();e.add(t)}for(;e.head!=null;){let t=e.pop_unsafe();t.removedFromSpace(),t.space=null;let n=t.bodies.head;for(;n!=null;){let i=n.elt;if(i.component!=null){let o=i.component.island;if(o!=null){for(;o.comps.head!=null;){let a=o.comps.pop_unsafe();a.sleeping=!1,a.island=null,a.parent=a,a.rank=0}let r=o;r.next=yt.zpp_pool,yt.zpp_pool=r}}i.removedFromSpace(),i.space=null,n=n.next}let l=t.constraints.head;for(;l!=null;){let i=l.elt;if(i.component!=null){let o=i.component.island;if(o!=null){for(;o.comps.head!=null;){let a=o.comps.pop_unsafe();a.sleeping=!1,a.island=null,a.parent=a,a.rank=0}let r=o;r.next=yt.zpp_pool,yt.zpp_pool=r}}i.removedFromSpace(),i.space=null,l=l.next}let s=t.compounds.head;for(;s!=null;){let i=s.elt;e.add(i),s=s.next}}this.staticsleep.clear(),this.live.clear(),this.live_constraints.clear(),this.stamp=0,this.time=0,this.mrca1.clear(),this.mrca2.clear(),this.prelisteners.clear(),this.cbsets.clear()}bodies_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_bodies.remove(e),this.addBody(e.zpp_inner),!0):!1}bodies_subber(e){this.remBody(e.zpp_inner)}bodies_modifiable(){if(this.midstep)throw new Error("Error: Space::bodies cannot be set during space step()")}compounds_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.wrap_compounds.remove(e),this.addCompound(e.zpp_inner),!0):!1}compounds_subber(e){this.remCompound(e.zpp_inner)}compounds_modifiable(){if(this.midstep)throw new Error("Error: Space::compounds cannot be set during space step()")}constraints_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_constraints.remove(e),this.addConstraint(e.zpp_inner),!0):!1}constraints_subber(e){this.remConstraint(e.zpp_inner)}constraints_modifiable(){if(this.midstep)throw new Error("Error: Space::constraints cannot be set during space step()")}listeners_adder(e){return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_listeners.remove(e),this.addListener(e.zpp_inner),!0):!1}listeners_subber(e){this.remListener(e.zpp_inner)}listeners_modifiable(){if(this.midstep)throw new Error("Error: Space::listeners cannot be set during space step()")}revoke_listener(e){}unrevoke_listener(e){}addListener(e){e.space=this,e.addedToSpace();let t=e.interaction!=null}remListener(e){let t=e.interaction!=null;e.removedFromSpace(),e.space=null}add_callbackset(e){let t=e.int1.cbsets,n;I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?n=new I._zpp.util.ZNPNode_ZPP_CallbackSet:(n=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=n.next,n.next=null),n.elt=e;let l=n;l.next=t.head,t.head=l,t.modified=!0,t.length++;let s=e.int2.cbsets,i;I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?i=new I._zpp.util.ZNPNode_ZPP_CallbackSet:(i=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=i.next,i.next=null),i.elt=e;let o=i;o.next=s.head,s.head=o,s.modified=!0,s.length++;let r=this.callbackset_list;e._inuse=!0;let a=e;a.next=r.next,r.next=a,r.modified=!0,r.length++}remove_callbackset(e){e.lazydel=!0;let t=e.int1.cbsets,n=null,l=t.head,s=!1;for(;l!=null;){if(l.elt==e){let p,c;n==null?(p=t.head,c=p.next,t.head=c,t.head==null&&(t.pushmod=!0)):(p=n.next,c=p.next,n.next=c,c==null&&(t.pushmod=!0));let u=p;u.elt=null,u.next=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=u,t.modified=!0,t.length--,t.pushmod=!0,s=!0;break}n=l,l=l.next}let i=e.int2.cbsets,o=null,r=i.head,a=!1;for(;r!=null;){if(r.elt==e){let p,c;o==null?(p=i.head,c=p.next,i.head=c,i.head==null&&(i.pushmod=!0)):(p=o.next,c=p.next,o.next=c,c==null&&(i.pushmod=!0));let u=p;u.elt=null,u.next=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=u,i.modified=!0,i.length--,i.pushmod=!0,a=!0;break}o=r,r=r.next}}transmitType(e,t){let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!1)),e.type==2?this.live.remove(e):e.type==3?(this.kinematics.remove(e),this.staticsleep.remove(e)):e.type==1&&this.staticsleep.remove(e),e.type=t,e.type==3&&this.kinematics.add(e),e.type==1&&this.static_validation(e),e.component.sleeping=!0;let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0))}added_shape(e,t){if(t==null&&(t=!1),!t){let n=e.body;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!1))}this.bphase.insert(e),e.addedToSpace()}removed_shape(e,t){t==null&&(t=!1);let n=this,l=e.body;t||l.wake();let s=null,i=l.arbiters.head;for(;i!=null;){let o=i.elt;if(o.ws1==e||o.ws2==e){if(o.present!=0){this.MRCA_chains(o.ws1,o.ws2);let a=this.mrca1.head;for(;a!=null;){let p=a.elt,c=this.mrca2.head;for(;c!=null;){let u=c.elt,h=p.cbSet,x=u.cbSet;h.validate(),x.validate();let b=h.manager,_=null,f=(h.cbpairs.length<x.cbpairs.length?h.cbpairs:x.cbpairs).head;for(;f!=null;){let P=f.elt;if(P.a==h&&P.b==x||P.a==x&&P.b==h){_=P;break}f=f.next}if(_==null){let P;Ne.zpp_pool==null?P=new Ne:(P=Ne.zpp_pool,Ne.zpp_pool=P.next,P.next=null),P.zip_listeners=!0,zt.setlt(h,x)?(P.a=h,P.b=x):(P.a=x,P.b=h),_=P,h.cbpairs.add(_),x!=h&&x.cbpairs.add(_)}if(_.zip_listeners&&(_.zip_listeners=!1,_.__validate()),_.listeners.head==null){c=c.next;continue}let m=I._zpp.phys.ZPP_Interactor.get(p,u);m.remove_arb(o),o.present--;let z=h.manager,Z=null,w=(h.cbpairs.length<x.cbpairs.length?h.cbpairs:x.cbpairs).head;for(;w!=null;){let P=w.elt;if(P.a==h&&P.b==x||P.a==x&&P.b==h){Z=P;break}w=w.next}if(Z==null){let P;Ne.zpp_pool==null?P=new Ne:(P=Ne.zpp_pool,Ne.zpp_pool=P.next,P.next=null),P.zip_listeners=!0,zt.setlt(h,x)?(P.a=h,P.b=x):(P.a=x,P.b=h),Z=P,h.cbpairs.add(Z),x!=h&&x.cbpairs.add(Z)}Z.zip_listeners&&(Z.zip_listeners=!1,Z.__validate());let v=Z.listeners.head;for(;v!=null;){let P=v.elt;if(P.event==1&&(P.itype&o.type)!=0&&m.empty_arb(P.itype)){let g=n.push_callback(P);g.event=1;let k=m.int1,N=m.int2,E,M=P.options1,C=k.cbTypes;if(M.nonemptyintersection(C,M.includes)&&!M.nonemptyintersection(C,M.excludes)){let D=P.options2,O=N.cbTypes;E=D.nonemptyintersection(O,D.includes)&&!D.nonemptyintersection(O,D.excludes)}else E=!1;E?(g.int1=k,g.int2=N):(g.int1=N,g.int2=k),g.set=m}v=v.next}m.arbiters.head==null&&this.remove_callbackset(m),c=c.next}a=a.next}}if(o.b1!=l&&o.b1.type==2){let a=o.b1;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(o.b2!=l&&o.b2.type==2){let a=o.b2;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(o.cleared=!0,l==null||o.b2==l){let a=o.b1.arbiters,p=null,c=a.head,u=!1;for(;c!=null;){if(c.elt==o){let h,x;p==null?(h=a.head,x=h.next,a.head=x,a.head==null&&(a.pushmod=!0)):(h=p.next,x=h.next,p.next=x,x==null&&(a.pushmod=!0));let b=h;b.elt=null,b.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,a.modified=!0,a.length--,a.pushmod=!0,u=!0;break}p=c,c=c.next}}if(l==null||o.b1==l){let a=o.b2.arbiters,p=null,c=a.head,u=!1;for(;c!=null;){if(c.elt==o){let h,x;p==null?(h=a.head,x=h.next,a.head=x,a.head==null&&(a.pushmod=!0)):(h=p.next,x=h.next,p.next=x,x==null&&(a.pushmod=!0));let b=h;b.elt=null,b.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,a.modified=!0,a.length--,a.pushmod=!0,u=!0;break}p=c,c=c.next}}o.pair!=null&&(o.pair.arb=null,o.pair=null),o.active=!1,this.f_arbiters.modified=!0,i=l.arbiters.erase(s);continue}s=i,i=i.next}this.bphase.remove(e),e.removedFromSpace()}addConstraint(e){e.space=this,e.addedToSpace(),e.active&&(e.component.sleeping=!0,this.wake_constraint(e,!0))}remConstraint(e){e.active&&(this.wake_constraint(e,!0),this.live_constraints.remove(e)),e.removedFromSpace(),e.space=null}addCompound(e){e.space=this,e.addedToSpace();let t=e.bodies.head;for(;t!=null;){let s=t.elt;this.addBody(s),t=t.next}let n=e.constraints.head;for(;n!=null;){let s=n.elt;this.addConstraint(s),n=n.next}let l=e.compounds.head;for(;l!=null;){let s=l.elt;this.addCompound(s),l=l.next}}remCompound(e){let t=e.bodies.head;for(;t!=null;){let s=t.elt;this.remBody(s),t=t.next}let n=e.constraints.head;for(;n!=null;){let s=n.elt;this.remConstraint(s),n=n.next}let l=e.compounds.head;for(;l!=null;){let s=l.elt;this.remCompound(s),l=l.next}e.removedFromSpace(),e.space=null}addBody(e,t){t==null&&(t=-1),e.space=this,e.addedToSpace(),e.component.sleeping=!0;let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!0));let l=e.shapes.head;for(;l!=null;){let s=l.elt,i=!0;if(i==null&&(i=!1),!i){let o=s.body;o.world||(o.component.waket=this.stamp+(this.midstep?0:1),o.type==3&&(o.kinematicDelaySleep=!0),o.component.sleeping&&this.really_wake(o,!1))}this.bphase.insert(s),s.addedToSpace(),l=l.next}e.type==1?this.static_validation(e):e.type!=2&&t!=3&&this.kinematics.add(e)}remBody(e,t){if(t==null&&(t=-1),e.type==1){let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0)),this.staticsleep.remove(e)}else if(e.type==2){let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0)),this.live.remove(e)}else{t!=3&&this.kinematics.remove(e);let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0)),this.staticsleep.remove(e)}let n=e.shapes.head;for(;n!=null;){let l=n.elt;this.removed_shape(l,!0),n=n.next}e.removedFromSpace(),e.space=null}shapesUnderPoint(e,t,n,l){return this.bphase.shapesUnderPoint(e,t,n,l)}bodiesUnderPoint(e,t,n,l){return this.bphase.bodiesUnderPoint(e,t,n,l)}shapesInAABB(e,t,n,l,s){return this.bphase.shapesInAABB(e.zpp_inner,t,n,l,s)}bodiesInAABB(e,t,n,l,s){return this.bphase.bodiesInAABB(e.zpp_inner,t,n,l,s)}shapesInCircle(e,t,n,l,s){let i=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;o._validate!=null&&o._validate();let r=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=e.zpp_inner;return a._validate!=null&&a._validate(),i.shapesInCircle(r,e.zpp_inner.y,t,n,l,s)}bodiesInCircle(e,t,n,l,s){let i=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;o._validate!=null&&o._validate();let r=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=e.zpp_inner;return a._validate!=null&&a._validate(),i.bodiesInCircle(r,e.zpp_inner.y,t,n,l,s)}shapesInShape(e,t,n,l){return this.bphase.shapesInShape(e,t,n,l)}bodiesInShape(e,t,n,l){return this.bphase.bodiesInShape(e,t,n,l)}rayCast(e,t,n){return this.bphase.rayCast(e.zpp_inner,t,n==null?null:n.zpp_inner)}rayMultiCast(e,t,n,l){return this.bphase.rayMultiCast(e.zpp_inner,t,n==null?null:n.zpp_inner,l)}convexCast(e,t,n,l){let s;if(I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?s=new I._zpp.geom.ZPP_ToiEvent:(s=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=s.next,s.next=null),s.failed=!1,s.s1=s.s2=null,s.arbiter=null,e.type==0){let O=e.circle;if(O.zip_worldCOM&&O.body!=null){if(O.zip_worldCOM=!1,O.zip_localCOM){if(O.zip_localCOM=!1,O.type==1){let L=O.polygon;if(L.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(L.lverts.next.next==null)L.localCOMx=L.lverts.next.x,L.localCOMy=L.lverts.next.y;else if(L.lverts.next.next.next==null){L.localCOMx=L.lverts.next.x,L.localCOMy=L.lverts.next.y;let U=1;L.localCOMx+=L.lverts.next.next.x*U,L.localCOMy+=L.lverts.next.next.y*U;let q=.5;L.localCOMx*=q,L.localCOMy*=q}else{L.localCOMx=0,L.localCOMy=0;let U=0,q=L.lverts.next,R=q;q=q.next;let B=q;for(q=q.next;q!=null;){let ee=q;U+=B.x*(ee.y-R.y);let G=ee.y*B.x-ee.x*B.y;L.localCOMx+=(B.x+ee.x)*G,L.localCOMy+=(B.y+ee.y)*G,R=B,B=ee,q=q.next}q=L.lverts.next;let S=q;U+=B.x*(S.y-R.y);let J=S.y*B.x-S.x*B.y;L.localCOMx+=(B.x+S.x)*J,L.localCOMy+=(B.y+S.y)*J,R=B,B=S,q=q.next;let Q=q;U+=B.x*(Q.y-R.y);let Y=Q.y*B.x-Q.x*B.y;L.localCOMx+=(B.x+Q.x)*Y,L.localCOMy+=(B.y+Q.y)*Y,U=1/(3*U);let X=U;L.localCOMx*=X,L.localCOMy*=X}}O.wrap_localCOM!=null&&(O.wrap_localCOM.zpp_inner.x=O.localCOMx,O.wrap_localCOM.zpp_inner.y=O.localCOMy)}let j=O.body;j.zip_axis&&(j.zip_axis=!1,j.axisx=Math.sin(j.rot),j.axisy=Math.cos(j.rot)),O.worldCOMx=O.body.posx+(O.body.axisy*O.localCOMx-O.body.axisx*O.localCOMy),O.worldCOMy=O.body.posy+(O.localCOMx*O.body.axisx+O.localCOMy*O.body.axisy)}}else{let O=e.polygon;if(O.zip_gaxi&&O.body!=null){O.zip_gaxi=!1,O.validate_laxi();let j=O.body;if(j.zip_axis&&(j.zip_axis=!1,j.axisx=Math.sin(j.rot),j.axisy=Math.cos(j.rot)),O.zip_gverts&&O.body!=null){O.zip_gverts=!1,O.validate_lverts();let S=O.body;S.zip_axis&&(S.zip_axis=!1,S.axisx=Math.sin(S.rot),S.axisy=Math.cos(S.rot));let J=O.lverts.next,Q=O.gverts.next;for(;Q!=null;){let Y=Q,X=J;J=J.next,Y.x=O.body.posx+(O.body.axisy*X.x-O.body.axisx*X.y),Y.y=O.body.posy+(X.x*O.body.axisx+X.y*O.body.axisy),Q=Q.next}}let L=O.edges.head,U=O.gverts.next,q=U;for(U=U.next;U!=null;){let S=U,J=L.elt;L=L.next,J.gp0=q,J.gp1=S,J.gnormx=O.body.axisy*J.lnormx-O.body.axisx*J.lnormy,J.gnormy=J.lnormx*O.body.axisx+J.lnormy*O.body.axisy,J.gprojection=O.body.posx*J.gnormx+O.body.posy*J.gnormy+J.lprojection,J.wrap_gnorm!=null&&(J.wrap_gnorm.zpp_inner.x=J.gnormx,J.wrap_gnorm.zpp_inner.y=J.gnormy),J.tp0=J.gp0.y*J.gnormx-J.gp0.x*J.gnormy,J.tp1=J.gp1.y*J.gnormx-J.gp1.x*J.gnormy,q=S,U=U.next}let R=O.gverts.next,B=L.elt;L=L.next,B.gp0=q,B.gp1=R,B.gnormx=O.body.axisy*B.lnormx-O.body.axisx*B.lnormy,B.gnormy=B.lnormx*O.body.axisx+B.lnormy*O.body.axisy,B.gprojection=O.body.posx*B.gnormx+O.body.posy*B.gnormy+B.lprojection,B.wrap_gnorm!=null&&(B.wrap_gnorm.zpp_inner.x=B.gnormx,B.wrap_gnorm.zpp_inner.y=B.gnormy),B.tp0=B.gp0.y*B.gnormx-B.gp0.x*B.gnormy,B.tp1=B.gp1.y*B.gnormx-B.gp1.x*B.gnormy}}let i=e.body,o=i.posx,r=i.posy;i.sweepTime=0,i.sweep_angvel=i.angvel;let a=t-i.sweepTime;if(a!=0){i.sweepTime=t;let O=a;if(i.posx+=i.velx*O,i.posy+=i.vely*O,i.angvel!=0){let j=i.sweep_angvel*a;if(i.rot+=j,j*j>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let L=j*j,U=1-.5*L,q=1-L*L/8,R=(U*i.axisx+j*i.axisy)*q;i.axisy=(U*i.axisy-j*i.axisx)*q,i.axisx=R}}}let p=i.posx,c=i.posy;e.validate_sweepRadius();let u=e.sweepRadius,h;be.zpp_pool==null?h=new be:(h=be.zpp_pool,be.zpp_pool=h.next,h.next=null);let x=o,b=p;h.minx=(x<b?x:b)-u;let _=o,d=p;h.maxx=(_>d?_:d)+u;let f=r,m=c;h.miny=(f<m?f:m)-u;let z=r,Z=c;h.maxy=(z>Z?z:Z)+u;let y=this.convexShapeList=this.bphase.shapesInAABB(h,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),w=h;w.outer!=null&&(w.outer.zpp_inner=null,w.outer=null),w.wrap_min=w.wrap_max=null,w._invalidate=null,w._validate=null,w.next=be.zpp_pool,be.zpp_pool=w;let v=0,P=0;v=0,P=0;let g=0,k=0;g=0,k=0;let N=null,E=t+1;y.zpp_inner.valmod();let M=I._nape.shape.ShapeIterator.get(y);for(;;){M.zpp_inner.zpp_inner.valmod();let O=M.zpp_inner;O.zpp_inner.valmod(),O.zpp_inner.zip_length&&(O.zpp_inner.zip_length=!1,O.zpp_inner.user_length=O.zpp_inner.inner.length);let j=O.zpp_inner.user_length;M.zpp_critical=!0;let L;if(M.zpp_i<j?L=!0:(M.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=M,M.zpp_inner=null,L=!1),!L)break;M.zpp_critical=!1;let U=M.zpp_inner.at(M.zpp_i++);if(U!=e.outer&&(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null)!=i.outer){if(s.s1=e,s.s2=U.zpp_inner,l){U.zpp_inner.validate_sweepRadius(),(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner.angvel,(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,Pn.dynamicSweep(s,t,0,0,!0);let q=(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner,R=0-q.sweepTime;if(R!=0){q.sweepTime=0;let J=R;if(q.posx+=q.velx*J,q.posy+=q.vely*J,q.angvel!=0){let Q=q.sweep_angvel*R;if(q.rot+=Q,Q*Q>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else{let Y=Q*Q,X=1-.5*Y,ee=1-Y*Y/8,G=(X*q.axisx+Q*q.axisy)*ee;q.axisy=(X*q.axisy-Q*q.axisx)*ee,q.axisx=G}}}let B=(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner,S=U.zpp_inner;if(S.type==0)S.worldCOMx=B.posx+(B.axisy*S.localCOMx-B.axisx*S.localCOMy),S.worldCOMy=B.posy+(S.localCOMx*B.axisx+S.localCOMy*B.axisy);else{let J=S.polygon,Q=J.lverts.next,Y=J.gverts.next;for(;Y!=null;){let A=Y,W=Q;Q=Q.next,A.x=B.posx+(B.axisy*W.x-B.axisx*W.y),A.y=B.posy+(W.x*B.axisx+W.y*B.axisy),Y=Y.next}let X=J.edges.head,ee=J.gverts.next,G=ee;for(ee=ee.next;ee!=null;){let A=ee,W=X.elt;X=X.next,W.gnormx=B.axisy*W.lnormx-B.axisx*W.lnormy,W.gnormy=W.lnormx*B.axisx+W.lnormy*B.axisy,W.gprojection=B.posx*W.gnormx+B.posy*W.gnormy+W.lprojection,W.tp0=G.y*W.gnormx-G.x*W.gnormy,W.tp1=A.y*W.gnormx-A.x*W.gnormy,G=A,ee=ee.next}let F=J.gverts.next,T=X.elt;X=X.next,T.gnormx=B.axisy*T.lnormx-B.axisx*T.lnormy,T.gnormy=T.lnormx*B.axisx+T.lnormy*B.axisy,T.gprojection=B.posx*T.gnormx+B.posy*T.gnormy+T.lprojection,T.tp0=G.y*T.gnormx-G.x*T.gnormy,T.tp1=F.y*T.gnormx-F.x*T.gnormy}}else Pn.staticSweep(s,t,0,0);s.toi*=t,s.toi>0&&s.toi<E&&(E=s.toi,v=s.axis.x,P=s.axis.y,g=s.c2.x,k=s.c2.y,N=U)}}y.clear();let C=s;C.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=C;let D=0-i.sweepTime;if(D!=0){i.sweepTime=0;let O=D;if(i.posx+=i.velx*O,i.posy+=i.vely*O,i.angvel!=0){let j=i.sweep_angvel*D;if(i.rot+=j,j*j>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let L=j*j,U=1-.5*L,q=1-L*L/8,R=(U*i.axisx+j*i.axisy)*q;i.axisy=(U*i.axisy-j*i.axisx)*q,i.axisx=R}}}if(e.type==0)e.worldCOMx=i.posx+(i.axisy*e.localCOMx-i.axisx*e.localCOMy),e.worldCOMy=i.posy+(e.localCOMx*i.axisx+e.localCOMy*i.axisy);else{let O=e.polygon,j=O.lverts.next,L=O.gverts.next;for(;L!=null;){let J=L,Q=j;j=j.next,J.x=i.posx+(i.axisy*Q.x-i.axisx*Q.y),J.y=i.posy+(Q.x*i.axisx+Q.y*i.axisy),L=L.next}let U=O.edges.head,q=O.gverts.next,R=q;for(q=q.next;q!=null;){let J=q,Q=U.elt;U=U.next,Q.gnormx=i.axisy*Q.lnormx-i.axisx*Q.lnormy,Q.gnormy=Q.lnormx*i.axisx+Q.lnormy*i.axisy,Q.gprojection=i.posx*Q.gnormx+i.posy*Q.gnormy+Q.lprojection,Q.tp0=R.y*Q.gnormx-R.x*Q.gnormy,Q.tp1=J.y*Q.gnormx-J.x*Q.gnormy,R=J,q=q.next}let B=O.gverts.next,S=U.elt;U=U.next,S.gnormx=i.axisy*S.lnormx-i.axisx*S.lnormy,S.gnormy=S.lnormx*i.axisx+S.lnormy*i.axisy,S.gprojection=i.posx*S.gnormx+i.posy*S.gnormy+S.lprojection,S.tp0=R.y*S.gnormx-R.x*S.gnormy,S.tp1=B.y*S.gnormx-B.x*S.gnormy}if(E<=t){let O=-v,j=-P;if(j==null&&(j=0),O==null&&(O=0),O!=O||j!=j)throw new Error("Error: Vec2 components cannot be NaN");let L;if(I._zpp.util.ZPP_PubPool.poolVec2==null?L=new I._nape.geom.Vec2:(L=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=L.zpp_pool,L.zpp_pool=null,L.zpp_disp=!1,L==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),L.zpp_inner==null){let B;le.zpp_pool==null?B=new le:(B=le.zpp_pool,le.zpp_pool=B.next,B.next=null),B.weak=!1,B._immutable=!1,B.x=O,B.y=j,L.zpp_inner=B,L.zpp_inner.outer=L}else{if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let B=L.zpp_inner;if(B._immutable)throw new Error("Error: Vec2 is immutable");if(B._isimmutable!=null&&B._isimmutable(),O!=O||j!=j)throw new Error("Error: Vec2 components cannot be NaN");let S;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let J=L.zpp_inner;if(J._validate!=null&&J._validate(),L.zpp_inner.x==O){if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Q=L.zpp_inner;Q._validate!=null&&Q._validate(),S=L.zpp_inner.y==j}else S=!1;if(!S){L.zpp_inner.x=O,L.zpp_inner.y=j;let Q=L.zpp_inner;Q._invalidate!=null&&Q._invalidate(Q)}}L.zpp_inner.weak=!1;let U=g,q=k;if(q==null&&(q=0),U==null&&(U=0),U!=U||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let R;if(I._zpp.util.ZPP_PubPool.poolVec2==null?R=new I._nape.geom.Vec2:(R=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=R.zpp_pool,R.zpp_pool=null,R.zpp_disp=!1,R==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),R.zpp_inner==null){let B;le.zpp_pool==null?B=new le:(B=le.zpp_pool,le.zpp_pool=B.next,B.next=null),B.weak=!1,B._immutable=!1,B.x=U,B.y=q,R.zpp_inner=B,R.zpp_inner.outer=R}else{if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let B=R.zpp_inner;if(B._immutable)throw new Error("Error: Vec2 is immutable");if(B._isimmutable!=null&&B._isimmutable(),U!=U||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let S;if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let J=R.zpp_inner;if(J._validate!=null&&J._validate(),R.zpp_inner.x==U){if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Q=R.zpp_inner;Q._validate!=null&&Q._validate(),S=R.zpp_inner.y==q}else S=!1;if(!S){R.zpp_inner.x=U,R.zpp_inner.y=q;let Q=R.zpp_inner;Q._invalidate!=null&&Q._invalidate(Q)}}return R.zpp_inner.weak=!1,I._zpp.geom.ZPP_ConvexRayResult.getConvex(L,R,E,N)}else return null}prepareCast(e){if(e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let s=1;l.localCOMx+=l.lverts.next.next.x*s,l.localCOMy+=l.lverts.next.next.y*s;let i=.5;l.localCOMx*=i,l.localCOMy*=i}else{l.localCOMx=0,l.localCOMy=0;let s=0,i=l.lverts.next,o=i;i=i.next;let r=i;for(i=i.next;i!=null;){let x=i;s+=r.x*(x.y-o.y);let b=x.y*r.x-x.x*r.y;l.localCOMx+=(r.x+x.x)*b,l.localCOMy+=(r.y+x.y)*b,o=r,r=x,i=i.next}i=l.lverts.next;let a=i;s+=r.x*(a.y-o.y);let p=a.y*r.x-a.x*r.y;l.localCOMx+=(r.x+a.x)*p,l.localCOMy+=(r.y+a.y)*p,o=r,r=a,i=i.next;let c=i;s+=r.x*(c.y-o.y);let u=c.y*r.x-c.x*r.y;l.localCOMx+=(r.x+c.x)*u,l.localCOMy+=(r.y+c.y)*u,s=1/(3*s);let h=s;l.localCOMx*=h,l.localCOMy*=h}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let n=t.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}}else{let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=t.body.posx+(t.body.axisy*h.x-t.body.axisx*h.y),u.y=t.body.posy+(h.x*t.body.axisx+h.y*t.body.axisy),c=c.next}}let l=t.edges.head,s=t.gverts.next,i=s;for(s=s.next;s!=null;){let a=s,p=l.elt;l=l.next,p.gp0=i,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,i=a,s=s.next}let o=t.gverts.next,r=l.elt;l=l.next,r.gp0=i,r.gp1=o,r.gnormx=t.body.axisy*r.lnormx-t.body.axisx*r.lnormy,r.gnormy=r.lnormx*t.body.axisx+r.lnormy*t.body.axisy,r.gprojection=t.body.posx*r.gnormx+t.body.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy}}}convexMultiCast(e,t,n,l,s){let i;if(I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?i=new I._zpp.geom.ZPP_ToiEvent:(i=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=i.next,i.next=null),i.failed=!1,i.s1=i.s2=null,i.arbiter=null,e.type==0){let E=e.circle;if(E.zip_worldCOM&&E.body!=null){if(E.zip_worldCOM=!1,E.zip_localCOM){if(E.zip_localCOM=!1,E.type==1){let C=E.polygon;if(C.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(C.lverts.next.next==null)C.localCOMx=C.lverts.next.x,C.localCOMy=C.lverts.next.y;else if(C.lverts.next.next.next==null){C.localCOMx=C.lverts.next.x,C.localCOMy=C.lverts.next.y;let D=1;C.localCOMx+=C.lverts.next.next.x*D,C.localCOMy+=C.lverts.next.next.y*D;let O=.5;C.localCOMx*=O,C.localCOMy*=O}else{C.localCOMx=0,C.localCOMy=0;let D=0,O=C.lverts.next,j=O;O=O.next;let L=O;for(O=O.next;O!=null;){let J=O;D+=L.x*(J.y-j.y);let Q=J.y*L.x-J.x*L.y;C.localCOMx+=(L.x+J.x)*Q,C.localCOMy+=(L.y+J.y)*Q,j=L,L=J,O=O.next}O=C.lverts.next;let U=O;D+=L.x*(U.y-j.y);let q=U.y*L.x-U.x*L.y;C.localCOMx+=(L.x+U.x)*q,C.localCOMy+=(L.y+U.y)*q,j=L,L=U,O=O.next;let R=O;D+=L.x*(R.y-j.y);let B=R.y*L.x-R.x*L.y;C.localCOMx+=(L.x+R.x)*B,C.localCOMy+=(L.y+R.y)*B,D=1/(3*D);let S=D;C.localCOMx*=S,C.localCOMy*=S}}E.wrap_localCOM!=null&&(E.wrap_localCOM.zpp_inner.x=E.localCOMx,E.wrap_localCOM.zpp_inner.y=E.localCOMy)}let M=E.body;M.zip_axis&&(M.zip_axis=!1,M.axisx=Math.sin(M.rot),M.axisy=Math.cos(M.rot)),E.worldCOMx=E.body.posx+(E.body.axisy*E.localCOMx-E.body.axisx*E.localCOMy),E.worldCOMy=E.body.posy+(E.localCOMx*E.body.axisx+E.localCOMy*E.body.axisy)}}else{let E=e.polygon;if(E.zip_gaxi&&E.body!=null){E.zip_gaxi=!1,E.validate_laxi();let M=E.body;if(M.zip_axis&&(M.zip_axis=!1,M.axisx=Math.sin(M.rot),M.axisy=Math.cos(M.rot)),E.zip_gverts&&E.body!=null){E.zip_gverts=!1,E.validate_lverts();let U=E.body;U.zip_axis&&(U.zip_axis=!1,U.axisx=Math.sin(U.rot),U.axisy=Math.cos(U.rot));let q=E.lverts.next,R=E.gverts.next;for(;R!=null;){let B=R,S=q;q=q.next,B.x=E.body.posx+(E.body.axisy*S.x-E.body.axisx*S.y),B.y=E.body.posy+(S.x*E.body.axisx+S.y*E.body.axisy),R=R.next}}let C=E.edges.head,D=E.gverts.next,O=D;for(D=D.next;D!=null;){let U=D,q=C.elt;C=C.next,q.gp0=O,q.gp1=U,q.gnormx=E.body.axisy*q.lnormx-E.body.axisx*q.lnormy,q.gnormy=q.lnormx*E.body.axisx+q.lnormy*E.body.axisy,q.gprojection=E.body.posx*q.gnormx+E.body.posy*q.gnormy+q.lprojection,q.wrap_gnorm!=null&&(q.wrap_gnorm.zpp_inner.x=q.gnormx,q.wrap_gnorm.zpp_inner.y=q.gnormy),q.tp0=q.gp0.y*q.gnormx-q.gp0.x*q.gnormy,q.tp1=q.gp1.y*q.gnormx-q.gp1.x*q.gnormy,O=U,D=D.next}let j=E.gverts.next,L=C.elt;C=C.next,L.gp0=O,L.gp1=j,L.gnormx=E.body.axisy*L.lnormx-E.body.axisx*L.lnormy,L.gnormy=L.lnormx*E.body.axisx+L.lnormy*E.body.axisy,L.gprojection=E.body.posx*L.gnormx+E.body.posy*L.gnormy+L.lprojection,L.wrap_gnorm!=null&&(L.wrap_gnorm.zpp_inner.x=L.gnormx,L.wrap_gnorm.zpp_inner.y=L.gnormy),L.tp0=L.gp0.y*L.gnormx-L.gp0.x*L.gnormy,L.tp1=L.gp1.y*L.gnormx-L.gp1.x*L.gnormy}}let o=e.body,r=o.posx,a=o.posy;o.sweepTime=0,o.sweep_angvel=o.angvel;let p=t-o.sweepTime;if(p!=0){o.sweepTime=t;let E=p;if(o.posx+=o.velx*E,o.posy+=o.vely*E,o.angvel!=0){let M=o.sweep_angvel*p;if(o.rot+=M,M*M>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let C=M*M,D=1-.5*C,O=1-C*C/8,j=(D*o.axisx+M*o.axisy)*O;o.axisy=(D*o.axisy-M*o.axisx)*O,o.axisx=j}}}let c=o.posx,u=o.posy;e.validate_sweepRadius();let h=e.sweepRadius,x;be.zpp_pool==null?x=new be:(x=be.zpp_pool,be.zpp_pool=x.next,x.next=null);let b=r,_=c;x.minx=(b<_?b:_)-h;let d=r,f=c;x.maxx=(d>f?d:f)+h;let m=a,z=u;x.miny=(m<z?m:z)-h;let Z=a,y=u;x.maxy=(Z>y?Z:y)+h;let w=this.convexShapeList=this.bphase.shapesInAABB(x,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),v=x;v.outer!=null&&(v.outer.zpp_inner=null,v.outer=null),v.wrap_min=v.wrap_max=null,v._invalidate=null,v._validate=null,v.next=be.zpp_pool,be.zpp_pool=v;let P=s??new I._nape.geom.ConvexResultList;w.zpp_inner.valmod();let g=I._nape.shape.ShapeIterator.get(w);for(;;){g.zpp_inner.zpp_inner.valmod();let E=g.zpp_inner;E.zpp_inner.valmod(),E.zpp_inner.zip_length&&(E.zpp_inner.zip_length=!1,E.zpp_inner.user_length=E.zpp_inner.inner.length);let M=E.zpp_inner.user_length;g.zpp_critical=!0;let C;if(g.zpp_i<M?C=!0:(g.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=g,g.zpp_inner=null,C=!1),!C)break;g.zpp_critical=!1;let D=g.zpp_inner.at(g.zpp_i++);if(D!=e.outer&&(D.zpp_inner.body!=null?D.zpp_inner.body.outer:null)!=o.outer){if(i.s1=e,i.s2=D.zpp_inner,l){D.zpp_inner.validate_sweepRadius(),(D.zpp_inner.body!=null?D.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(D.zpp_inner.body!=null?D.zpp_inner.body.outer:null).zpp_inner.angvel,(D.zpp_inner.body!=null?D.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,Pn.dynamicSweep(i,t,0,0,!0);let O=(D.zpp_inner.body!=null?D.zpp_inner.body.outer:null).zpp_inner,j=0-O.sweepTime;if(j!=0){O.sweepTime=0;let q=j;if(O.posx+=O.velx*q,O.posy+=O.vely*q,O.angvel!=0){let R=O.sweep_angvel*j;if(O.rot+=R,R*R>1e-4)O.axisx=Math.sin(O.rot),O.axisy=Math.cos(O.rot);else{let B=R*R,S=1-.5*B,J=1-B*B/8,Q=(S*O.axisx+R*O.axisy)*J;O.axisy=(S*O.axisy-R*O.axisx)*J,O.axisx=Q}}}let L=(D.zpp_inner.body!=null?D.zpp_inner.body.outer:null).zpp_inner,U=D.zpp_inner;if(U.type==0)U.worldCOMx=L.posx+(L.axisy*U.localCOMx-L.axisx*U.localCOMy),U.worldCOMy=L.posy+(U.localCOMx*L.axisx+U.localCOMy*L.axisy);else{let q=U.polygon,R=q.lverts.next,B=q.gverts.next;for(;B!=null;){let ee=B,G=R;R=R.next,ee.x=L.posx+(L.axisy*G.x-L.axisx*G.y),ee.y=L.posy+(G.x*L.axisx+G.y*L.axisy),B=B.next}let S=q.edges.head,J=q.gverts.next,Q=J;for(J=J.next;J!=null;){let ee=J,G=S.elt;S=S.next,G.gnormx=L.axisy*G.lnormx-L.axisx*G.lnormy,G.gnormy=G.lnormx*L.axisx+G.lnormy*L.axisy,G.gprojection=L.posx*G.gnormx+L.posy*G.gnormy+G.lprojection,G.tp0=Q.y*G.gnormx-Q.x*G.gnormy,G.tp1=ee.y*G.gnormx-ee.x*G.gnormy,Q=ee,J=J.next}let Y=q.gverts.next,X=S.elt;S=S.next,X.gnormx=L.axisy*X.lnormx-L.axisx*X.lnormy,X.gnormy=X.lnormx*L.axisx+X.lnormy*L.axisy,X.gprojection=L.posx*X.gnormx+L.posy*X.gnormy+X.lprojection,X.tp0=Q.y*X.gnormx-Q.x*X.gnormy,X.tp1=Y.y*X.gnormx-Y.x*X.gnormy}}else Pn.staticSweep(i,t,0,0);if(i.toi*=t,i.toi>0){let O=-i.axis.x,j=-i.axis.y;if(j==null&&(j=0),O==null&&(O=0),O!=O||j!=j)throw new Error("Error: Vec2 components cannot be NaN");let L;if(I._zpp.util.ZPP_PubPool.poolVec2==null?L=new I._nape.geom.Vec2:(L=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=L.zpp_pool,L.zpp_pool=null,L.zpp_disp=!1,L==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),L.zpp_inner==null){let ee;le.zpp_pool==null?ee=new le:(ee=le.zpp_pool,le.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=O,ee.y=j,L.zpp_inner=ee,L.zpp_inner.outer=L}else{if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=L.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),O!=O||j!=j)throw new Error("Error: Vec2 components cannot be NaN");let G;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=L.zpp_inner;if(F._validate!=null&&F._validate(),L.zpp_inner.x==O){if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let T=L.zpp_inner;T._validate!=null&&T._validate(),G=L.zpp_inner.y==j}else G=!1;if(!G){L.zpp_inner.x=O,L.zpp_inner.y=j;let T=L.zpp_inner;T._invalidate!=null&&T._invalidate(T)}}L.zpp_inner.weak=!1;let U=i.c2.x,q=i.c2.y;if(q==null&&(q=0),U==null&&(U=0),U!=U||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let R;if(I._zpp.util.ZPP_PubPool.poolVec2==null?R=new I._nape.geom.Vec2:(R=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=R.zpp_pool,R.zpp_pool=null,R.zpp_disp=!1,R==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),R.zpp_inner==null){let ee;le.zpp_pool==null?ee=new le:(ee=le.zpp_pool,le.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=U,ee.y=q,R.zpp_inner=ee,R.zpp_inner.outer=R}else{if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=R.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),U!=U||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let G;if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=R.zpp_inner;if(F._validate!=null&&F._validate(),R.zpp_inner.x==U){if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let T=R.zpp_inner;T._validate!=null&&T._validate(),G=R.zpp_inner.y==q}else G=!1;if(!G){R.zpp_inner.x=U,R.zpp_inner.y=q;let T=R.zpp_inner;T._invalidate!=null&&T._invalidate(T)}}R.zpp_inner.weak=!1;let B=I._zpp.geom.ZPP_ConvexRayResult.getConvex(L,R,i.toi,D),S=null,J=P.zpp_inner.inner.head;for(;J!=null;){let ee=J.elt;if(B.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(ee.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(B.zpp_inner.toiDistance<ee.zpp_inner.toiDistance)break;S=J,J=J.next}let Q=P.zpp_inner.inner,Y;I._zpp.util.ZNPNode_ConvexResult.zpp_pool==null?Y=new I._zpp.util.ZNPNode_ConvexResult:(Y=I._zpp.util.ZNPNode_ConvexResult.zpp_pool,I._zpp.util.ZNPNode_ConvexResult.zpp_pool=Y.next,Y.next=null),Y.elt=B;let X=Y;S==null?(X.next=Q.head,Q.head=X):(X.next=S.next,S.next=X),Q.pushmod=Q.modified=!0,Q.length++}}}w.clear();let k=i;k.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=k;let N=0-o.sweepTime;if(N!=0){o.sweepTime=0;let E=N;if(o.posx+=o.velx*E,o.posy+=o.vely*E,o.angvel!=0){let M=o.sweep_angvel*N;if(o.rot+=M,M*M>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let C=M*M,D=1-.5*C,O=1-C*C/8,j=(D*o.axisx+M*o.axisy)*O;o.axisy=(D*o.axisy-M*o.axisx)*O,o.axisx=j}}}if(e.type==0)e.worldCOMx=o.posx+(o.axisy*e.localCOMx-o.axisx*e.localCOMy),e.worldCOMy=o.posy+(e.localCOMx*o.axisx+e.localCOMy*o.axisy);else{let E=e.polygon,M=E.lverts.next,C=E.gverts.next;for(;C!=null;){let q=C,R=M;M=M.next,q.x=o.posx+(o.axisy*R.x-o.axisx*R.y),q.y=o.posy+(R.x*o.axisx+R.y*o.axisy),C=C.next}let D=E.edges.head,O=E.gverts.next,j=O;for(O=O.next;O!=null;){let q=O,R=D.elt;D=D.next,R.gnormx=o.axisy*R.lnormx-o.axisx*R.lnormy,R.gnormy=R.lnormx*o.axisx+R.lnormy*o.axisy,R.gprojection=o.posx*R.gnormx+o.posy*R.gnormy+R.lprojection,R.tp0=j.y*R.gnormx-j.x*R.gnormy,R.tp1=q.y*R.gnormx-q.x*R.gnormy,j=q,O=O.next}let L=E.gverts.next,U=D.elt;D=D.next,U.gnormx=o.axisy*U.lnormx-o.axisx*U.lnormy,U.gnormy=U.lnormx*o.axisx+U.lnormy*o.axisy,U.gprojection=o.posx*U.gnormx+o.posy*U.gnormy+U.lprojection,U.tp0=j.y*U.gnormx-j.x*U.gnormy,U.tp1=L.y*U.gnormx-L.x*U.gnormy}return P}push_callback(e){let t;return Gt.zpp_pool==null?t=new Gt:(t=Gt.zpp_pool,Gt.zpp_pool=t.next,t.next=null),this.callbacks.push(t),t.listener=e,t}step(e,t,n){let l=this;if(this.midstep)throw new Error("Error: ... REALLY?? you're going to call space.step() inside of space.step()? COME ON!!");if(this.time+=e,this.pre_dt=e,this.midstep=!0,this.stamp++,this.validation(),this.bphase.broadphase(this,!0),this.prestep(e),this.sortcontacts){let h=this.c_arbiters_false;if(h.head!=null&&h.head.next!=null){let x=h.head,b=null,_=null,d=null,f=null,m=1,z,Z,y;for(;;){for(z=0,_=x,x=null,b=x;_!=null;){for(++z,d=_,Z=0,y=m;d!=null&&Z<m;)++Z,d=d.next;for(;Z>0||y>0&&d!=null;)Z==0?(f=d,d=d.next,--y):y==0||d==null||!(_.elt.active&&d.elt.active)||_.elt.oc1.dist<d.elt.oc1.dist?(f=_,_=_.next,--Z):(f=d,d=d.next,--y),b!=null?b.next=f:x=f,b=f;_=d}if(b.next=null,m<<=1,!(z>1))break}h.head=x,h.modified=!0,h.pushmod=!0}}this.updateVel(e),this.warmStart(),this.iterateVel(t);let s=this.kinematics.head;for(;s!=null;){let h=s.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,s=s.next}let i=this.live.head;for(;i!=null;){let h=i.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,i=i.next}this.updatePos(e),this.continuous=!0,this.continuousCollisions(e),this.continuous=!1,this.iteratePos(n);let o=this.kinematics.head;for(;o!=null;){let h=o.elt,x=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),b=h.pre_rot!=h.rot;if(x){let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}if(b){h.zip_axis=!0;let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}o=o.next}let r=this.live.head;for(;r!=null;){let h=r.elt,x=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),b=h.pre_rot!=h.rot;if(x){let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}if(b){h.zip_axis=!0;let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}r=r.next}let a=null,p=this.staticsleep.head;for(;p!=null;){let h=p.elt;if(h.type!=3||h.velx==0&&h.vely==0&&h.angvel==0){if(h.kinematicDelaySleep){h.kinematicDelaySleep=!1,p=p.next;continue}h.component.sleeping=!0;let x=this.staticsleep,b,_;a==null?(b=x.head,_=b.next,x.head=_,x.head==null&&(x.pushmod=!0)):(b=a.next,_=b.next,a.next=_,_==null&&(x.pushmod=!0));let d=b;d.elt=null,d.next=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=d,x.modified=!0,x.length--,x.pushmod=!0,p=_;continue}a=p,p=p.next}this.doForests(e),this.sleepArbiters(),this.midstep=!1;let c=null,u=this.callbackset_list.next;for(;u!=null;){let h=u;if(h.arbiters.head==null){let v=this.callbackset_list,P,g;c==null?(P=v.next,g=P.next,v.next=g,v.next==null&&(v.pushmod=!0)):(P=c.next,g=P.next,c.next=g,g==null&&(v.pushmod=!0)),P._inuse=!1,v.modified=!0,v.length--,v.pushmod=!0,u=g;let k=h;k.int1=k.int2=null,k.id=k.di=-1,k.freed=!0,k.next=Yt.zpp_pool,Yt.zpp_pool=k;continue}let x;x=!0;let b=h.arbiters.head;for(;b!=null;)if(b.elt.sleeping){b=b.next;continue}else{x=!1;break}let _=x,d=h.int1.cbSet,f=h.int2.cbSet,m=d.manager,z=null,y=(d.cbpairs.length<f.cbpairs.length?d.cbpairs:f.cbpairs).head;for(;y!=null;){let v=y.elt;if(v.a==d&&v.b==f||v.a==f&&v.b==d){z=v;break}y=y.next}if(z==null){let v;Ne.zpp_pool==null?v=new Ne:(v=Ne.zpp_pool,Ne.zpp_pool=v.next,v.next=null),v.zip_listeners=!0,zt.setlt(d,f)?(v.a=d,v.b=f):(v.a=f,v.b=d),z=v,d.cbpairs.add(z),f!=d&&f.cbpairs.add(z)}z.zip_listeners&&(z.zip_listeners=!1,z.__validate());let w=z.listeners.head;for(;w!=null;){let v=w.elt;if(v.event==6&&(!_||v.allowSleepingCallbacks)&&!h.empty_arb(v.itype)){let P=l.push_callback(v);P.event=6;let g=h.int1,k=h.int2,N,E=v.options1,M=g.cbTypes;if(E.nonemptyintersection(M,E.includes)&&!E.nonemptyintersection(M,E.excludes)){let C=v.options2,D=k.cbTypes;N=C.nonemptyintersection(D,C.includes)&&!C.nonemptyintersection(D,C.excludes)}else N=!1;N?(P.int1=g,P.int2=k):(P.int1=k,P.int2=g),P.set=h}w=w.next}c=u,u=u.next}for(;!this.callbacks.empty();){let h=this.callbacks.pop();h.listener.type==0?h.listener.body.handler(h.wrapper_body()):h.listener.type==1?h.listener.constraint.handler(h.wrapper_con()):h.listener.type==2&&h.listener.interaction.handleri(h.wrapper_int());let x=h;x.int1=x.int2=null,x.body=null,x.constraint=null,x.listener=null,x.wrap_arbiters!=null&&(x.wrap_arbiters.zpp_inner.inner=null),x.set=null,x.next=Gt.zpp_pool,Gt.zpp_pool=x}}continuousCollisions(e){let t=2*Math.PI/e;this.bphase.broadphase(this,!1);let n=0;for(;n<1&&this.toiEvents.head!=null;){let i=null,o=2,r=!1,a=null,p=null,c=this.toiEvents.head;for(;c!=null;){let d=c.elt,f=d.s1.body,m=d.s2.body;if(f.sweepFrozen&&m.sweepFrozen)if(d.toi!=0&&Ee.testCollide_safe(d.s1,d.s2))d.toi=0;else{c=this.toiEvents.erase(p);let z=d;z.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=z;continue}if(d.frozen1!=f.sweepFrozen||d.frozen2!=m.sweepFrozen)if(d.kinematic){c=this.toiEvents.erase(p);let z=d;z.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=z;continue}else{if(d.frozen1=f.sweepFrozen,d.frozen2=m.sweepFrozen,d.frozen1){let z=d.s1;d.s1=d.s2,d.s2=z,d.frozen1=!1,d.frozen2=!0}if(Pn.staticSweep(d,e,0,I._nape.Config.collisionSlopCCD),d.toi<0){c=this.toiEvents.erase(p);let z=d;z.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=z;continue}}d.toi>=0&&(d.toi<o||!r&&d.kinematic)&&(i=d,o=d.toi,r=d.kinematic,a=p),p=c,c=c.next}if(i==null)break;this.toiEvents.erase(a),n=i.toi;let u=i.s1.body,h=i.s2.body;if(!u.sweepFrozen){let d=n*e,f=d-u.sweepTime;if(f!=0){u.sweepTime=d;let z=f;if(u.posx+=u.velx*z,u.posy+=u.vely*z,u.angvel!=0){let Z=u.sweep_angvel*f;if(u.rot+=Z,Z*Z>1e-4)u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot);else{let y=Z*Z,w=1-.5*y,v=1-y*y/8,P=(w*u.axisx+Z*u.axisy)*v;u.axisy=(w*u.axisy-Z*u.axisx)*v,u.axisx=P}}}let m=i.s1;if(m.type==0)m.worldCOMx=u.posx+(u.axisy*m.localCOMx-u.axisx*m.localCOMy),m.worldCOMy=u.posy+(m.localCOMx*u.axisx+m.localCOMy*u.axisy);else{let z=m.polygon,Z=z.lverts.next,y=z.gverts.next;for(;y!=null;){let N=y,E=Z;Z=Z.next,N.x=u.posx+(u.axisy*E.x-u.axisx*E.y),N.y=u.posy+(E.x*u.axisx+E.y*u.axisy),y=y.next}let w=z.edges.head,v=z.gverts.next,P=v;for(v=v.next;v!=null;){let N=v,E=w.elt;w=w.next,E.gnormx=u.axisy*E.lnormx-u.axisx*E.lnormy,E.gnormy=E.lnormx*u.axisx+E.lnormy*u.axisy,E.gprojection=u.posx*E.gnormx+u.posy*E.gnormy+E.lprojection,E.tp0=P.y*E.gnormx-P.x*E.gnormy,E.tp1=N.y*E.gnormx-N.x*E.gnormy,P=N,v=v.next}let g=z.gverts.next,k=w.elt;w=w.next,k.gnormx=u.axisy*k.lnormx-u.axisx*k.lnormy,k.gnormy=k.lnormx*u.axisx+k.lnormy*u.axisy,k.gprojection=u.posx*k.gnormx+u.posy*k.gnormy+k.lprojection,k.tp0=P.y*k.gnormx-P.x*k.gnormy,k.tp1=g.y*k.gnormx-g.x*k.gnormy}}if(!h.sweepFrozen){let d=n*e,f=d-h.sweepTime;if(f!=0){h.sweepTime=d;let z=f;if(h.posx+=h.velx*z,h.posy+=h.vely*z,h.angvel!=0){let Z=h.sweep_angvel*f;if(h.rot+=Z,Z*Z>1e-4)h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot);else{let y=Z*Z,w=1-.5*y,v=1-y*y/8,P=(w*h.axisx+Z*h.axisy)*v;h.axisy=(w*h.axisy-Z*h.axisx)*v,h.axisx=P}}}let m=i.s2;if(m.type==0)m.worldCOMx=h.posx+(h.axisy*m.localCOMx-h.axisx*m.localCOMy),m.worldCOMy=h.posy+(m.localCOMx*h.axisx+m.localCOMy*h.axisy);else{let z=m.polygon,Z=z.lverts.next,y=z.gverts.next;for(;y!=null;){let N=y,E=Z;Z=Z.next,N.x=h.posx+(h.axisy*E.x-h.axisx*E.y),N.y=h.posy+(E.x*h.axisx+E.y*h.axisy),y=y.next}let w=z.edges.head,v=z.gverts.next,P=v;for(v=v.next;v!=null;){let N=v,E=w.elt;w=w.next,E.gnormx=h.axisy*E.lnormx-h.axisx*E.lnormy,E.gnormy=E.lnormx*h.axisx+E.lnormy*h.axisy,E.gprojection=h.posx*E.gnormx+h.posy*E.gnormy+E.lprojection,E.tp0=P.y*E.gnormx-P.x*E.gnormy,E.tp1=N.y*E.gnormx-N.x*E.gnormy,P=N,v=v.next}let g=z.gverts.next,k=w.elt;w=w.next,k.gnormx=h.axisy*k.lnormx-h.axisx*k.lnormy,k.gnormy=k.lnormx*h.axisx+k.lnormy*h.axisy,k.gprojection=h.posx*k.gnormx+h.posy*k.gnormy+k.lprojection,k.tp0=P.y*k.gnormx-P.x*k.gnormy,k.tp1=g.y*k.gnormx-g.x*k.gnormy}}let x=i.arbiter==null,b=this.narrowPhase(i.s1,i.s2,!0,i.arbiter,!0);if(b==null)i.arbiter!=null&&i.arbiter.pair!=null&&(i.arbiter.pair.arb=null,i.arbiter.pair=null);else if(!this.presteparb(b,e,!0)&&b.type==Ae.COL&&b.active&&(b.immState&1)!=0){let d=b.colarb,f=d.nx*d.c1.jnAcc-d.ny*d.c1.jtAcc,m=d.ny*d.c1.jnAcc+d.nx*d.c1.jtAcc,z=d.b1.imass;d.b1.velx-=f*z,d.b1.vely-=m*z,d.b1.angvel-=d.b1.iinertia*(m*d.c1.r1x-f*d.c1.r1y);let Z=d.b2.imass;if(d.b2.velx+=f*Z,d.b2.vely+=m*Z,d.b2.angvel+=d.b2.iinertia*(m*d.c1.r2x-f*d.c1.r2y),d.hc2){let ce=d.nx*d.c2.jnAcc-d.ny*d.c2.jtAcc,pe=d.ny*d.c2.jnAcc+d.nx*d.c2.jtAcc,ae=d.b1.imass;d.b1.velx-=ce*ae,d.b1.vely-=pe*ae,d.b1.angvel-=d.b1.iinertia*(pe*d.c2.r1x-ce*d.c2.r1y);let xe=d.b2.imass;d.b2.velx+=ce*xe,d.b2.vely+=pe*xe,d.b2.angvel+=d.b2.iinertia*(pe*d.c2.r2x-ce*d.c2.r2y)}d.b2.angvel+=d.jrAcc*d.b2.iinertia,d.b1.angvel-=d.jrAcc*d.b1.iinertia;let y=b.colarb,w=y.k1x+y.b2.velx-y.c1.r2y*y.b2.angvel-(y.b1.velx-y.c1.r1y*y.b1.angvel),v=y.k1y+y.b2.vely+y.c1.r2x*y.b2.angvel-(y.b1.vely+y.c1.r1x*y.b1.angvel),P=(v*y.nx-w*y.ny+y.surfacex)*y.c1.tMass,g=y.c1.friction*y.c1.jnAcc,k=y.c1.jtAcc,N=k-P;N>g?N=g:N<-g&&(N=-g),P=N-k,y.c1.jtAcc=N;let E=-y.ny*P,M=y.nx*P;if(y.b2.velx+=E*y.b2.imass,y.b2.vely+=M*y.b2.imass,y.b1.velx-=E*y.b1.imass,y.b1.vely-=M*y.b1.imass,y.b2.angvel+=y.rt1b*P*y.b2.iinertia,y.b1.angvel-=y.rt1a*P*y.b1.iinertia,y.hc2){let ce=y.k2x+y.b2.velx-y.c2.r2y*y.b2.angvel-(y.b1.velx-y.c2.r1y*y.b1.angvel),pe=y.k2y+y.b2.vely+y.c2.r2x*y.b2.angvel-(y.b1.vely+y.c2.r1x*y.b1.angvel);P=(pe*y.nx-ce*y.ny+y.surfacex)*y.c2.tMass,g=y.c2.friction*y.c2.jnAcc,k=y.c2.jtAcc,N=k-P,N>g?N=g:N<-g&&(N=-g),P=N-k,y.c2.jtAcc=N,E=-y.ny*P,M=y.nx*P,y.b2.velx+=E*y.b2.imass,y.b2.vely+=M*y.b2.imass,y.b1.velx-=E*y.b1.imass,y.b1.vely-=M*y.b1.imass,y.b2.angvel+=y.rt2b*P*y.b2.iinertia,y.b1.angvel-=y.rt2a*P*y.b1.iinertia,w=y.k1x+y.b2.velx-y.c1.r2y*y.b2.angvel-(y.b1.velx-y.c1.r1y*y.b1.angvel),v=y.k1y+y.b2.vely+y.c1.r2x*y.b2.angvel-(y.b1.vely+y.c1.r1x*y.b1.angvel),ce=y.k2x+y.b2.velx-y.c2.r2y*y.b2.angvel-(y.b1.velx-y.c2.r1y*y.b1.angvel),pe=y.k2y+y.b2.vely+y.c2.r2x*y.b2.angvel-(y.b1.vely+y.c2.r1x*y.b1.angvel);let ae=y.c1.jnAcc,xe=y.c2.jnAcc,te=w*y.nx+v*y.ny+y.surfacey+y.c1.bounce-(y.Ka*ae+y.Kb*xe),he=ce*y.nx+pe*y.ny+y.surfacey+y.c2.bounce-(y.Kb*ae+y.Kc*xe),ye=-(y.kMassa*te+y.kMassb*he),ue=-(y.kMassb*te+y.kMassc*he);ye>=0&&ue>=0?(te=ye-ae,he=ue-xe,y.c1.jnAcc=ye,y.c2.jnAcc=ue):(ye=-y.c1.nMass*te,ye>=0&&y.Kb*ye+he>=0?(te=ye-ae,he=-xe,y.c1.jnAcc=ye,y.c2.jnAcc=0):(ue=-y.c2.nMass*he,ue>=0&&y.Kb*ue+te>=0?(te=-ae,he=ue-xe,y.c1.jnAcc=0,y.c2.jnAcc=ue):te>=0&&he>=0?(te=-ae,he=-xe,y.c1.jnAcc=y.c2.jnAcc=0):(te=0,he=0))),P=te+he,E=y.nx*P,M=y.ny*P,y.b2.velx+=E*y.b2.imass,y.b2.vely+=M*y.b2.imass,y.b1.velx-=E*y.b1.imass,y.b1.vely-=M*y.b1.imass,y.b2.angvel+=(y.rn1b*te+y.rn2b*he)*y.b2.iinertia,y.b1.angvel-=(y.rn1a*te+y.rn2a*he)*y.b1.iinertia}else y.radius!=0&&(P=(y.b2.angvel-y.b1.angvel)*y.rMass,g=y.rfric*y.c1.jnAcc,k=y.jrAcc,y.jrAcc-=P,y.jrAcc>g?y.jrAcc=g:y.jrAcc<-g&&(y.jrAcc=-g),P=y.jrAcc-k,y.b2.angvel+=P*y.b2.iinertia,y.b1.angvel-=P*y.b1.iinertia),w=y.k1x+y.b2.velx-y.c1.r2y*y.b2.angvel-(y.b1.velx-y.c1.r1y*y.b1.angvel),v=y.k1y+y.b2.vely+y.c1.r2x*y.b2.angvel-(y.b1.vely+y.c1.r1x*y.b1.angvel),P=(y.c1.bounce+(y.nx*w+y.ny*v)+y.surfacey)*y.c1.nMass,k=y.c1.jnAcc,N=k-P,N<0&&(N=0),P=N-k,y.c1.jnAcc=N,E=y.nx*P,M=y.ny*P,y.b2.velx+=E*y.b2.imass,y.b2.vely+=M*y.b2.imass,y.b1.velx-=E*y.b1.imass,y.b1.vely-=M*y.b1.imass,y.b2.angvel+=y.rn1b*P*y.b2.iinertia,y.b1.angvel-=y.rn1a*P*y.b1.iinertia;let C=b.colarb,D=C.k1x+C.b2.velx-C.c1.r2y*C.b2.angvel-(C.b1.velx-C.c1.r1y*C.b1.angvel),O=C.k1y+C.b2.vely+C.c1.r2x*C.b2.angvel-(C.b1.vely+C.c1.r1x*C.b1.angvel),j=(O*C.nx-D*C.ny+C.surfacex)*C.c1.tMass,L=C.c1.friction*C.c1.jnAcc,U=C.c1.jtAcc,q=U-j;q>L?q=L:q<-L&&(q=-L),j=q-U,C.c1.jtAcc=q;let R=-C.ny*j,B=C.nx*j;if(C.b2.velx+=R*C.b2.imass,C.b2.vely+=B*C.b2.imass,C.b1.velx-=R*C.b1.imass,C.b1.vely-=B*C.b1.imass,C.b2.angvel+=C.rt1b*j*C.b2.iinertia,C.b1.angvel-=C.rt1a*j*C.b1.iinertia,C.hc2){let ce=C.k2x+C.b2.velx-C.c2.r2y*C.b2.angvel-(C.b1.velx-C.c2.r1y*C.b1.angvel),pe=C.k2y+C.b2.vely+C.c2.r2x*C.b2.angvel-(C.b1.vely+C.c2.r1x*C.b1.angvel);j=(pe*C.nx-ce*C.ny+C.surfacex)*C.c2.tMass,L=C.c2.friction*C.c2.jnAcc,U=C.c2.jtAcc,q=U-j,q>L?q=L:q<-L&&(q=-L),j=q-U,C.c2.jtAcc=q,R=-C.ny*j,B=C.nx*j,C.b2.velx+=R*C.b2.imass,C.b2.vely+=B*C.b2.imass,C.b1.velx-=R*C.b1.imass,C.b1.vely-=B*C.b1.imass,C.b2.angvel+=C.rt2b*j*C.b2.iinertia,C.b1.angvel-=C.rt2a*j*C.b1.iinertia,D=C.k1x+C.b2.velx-C.c1.r2y*C.b2.angvel-(C.b1.velx-C.c1.r1y*C.b1.angvel),O=C.k1y+C.b2.vely+C.c1.r2x*C.b2.angvel-(C.b1.vely+C.c1.r1x*C.b1.angvel),ce=C.k2x+C.b2.velx-C.c2.r2y*C.b2.angvel-(C.b1.velx-C.c2.r1y*C.b1.angvel),pe=C.k2y+C.b2.vely+C.c2.r2x*C.b2.angvel-(C.b1.vely+C.c2.r1x*C.b1.angvel);let ae=C.c1.jnAcc,xe=C.c2.jnAcc,te=D*C.nx+O*C.ny+C.surfacey+C.c1.bounce-(C.Ka*ae+C.Kb*xe),he=ce*C.nx+pe*C.ny+C.surfacey+C.c2.bounce-(C.Kb*ae+C.Kc*xe),ye=-(C.kMassa*te+C.kMassb*he),ue=-(C.kMassb*te+C.kMassc*he);ye>=0&&ue>=0?(te=ye-ae,he=ue-xe,C.c1.jnAcc=ye,C.c2.jnAcc=ue):(ye=-C.c1.nMass*te,ye>=0&&C.Kb*ye+he>=0?(te=ye-ae,he=-xe,C.c1.jnAcc=ye,C.c2.jnAcc=0):(ue=-C.c2.nMass*he,ue>=0&&C.Kb*ue+te>=0?(te=-ae,he=ue-xe,C.c1.jnAcc=0,C.c2.jnAcc=ue):te>=0&&he>=0?(te=-ae,he=-xe,C.c1.jnAcc=C.c2.jnAcc=0):(te=0,he=0))),j=te+he,R=C.nx*j,B=C.ny*j,C.b2.velx+=R*C.b2.imass,C.b2.vely+=B*C.b2.imass,C.b1.velx-=R*C.b1.imass,C.b1.vely-=B*C.b1.imass,C.b2.angvel+=(C.rn1b*te+C.rn2b*he)*C.b2.iinertia,C.b1.angvel-=(C.rn1a*te+C.rn2a*he)*C.b1.iinertia}else C.radius!=0&&(j=(C.b2.angvel-C.b1.angvel)*C.rMass,L=C.rfric*C.c1.jnAcc,U=C.jrAcc,C.jrAcc-=j,C.jrAcc>L?C.jrAcc=L:C.jrAcc<-L&&(C.jrAcc=-L),j=C.jrAcc-U,C.b2.angvel+=j*C.b2.iinertia,C.b1.angvel-=j*C.b1.iinertia),D=C.k1x+C.b2.velx-C.c1.r2y*C.b2.angvel-(C.b1.velx-C.c1.r1y*C.b1.angvel),O=C.k1y+C.b2.vely+C.c1.r2x*C.b2.angvel-(C.b1.vely+C.c1.r1x*C.b1.angvel),j=(C.c1.bounce+(C.nx*D+C.ny*O)+C.surfacey)*C.c1.nMass,U=C.c1.jnAcc,q=U-j,q<0&&(q=0),j=q-U,C.c1.jnAcc=q,R=C.nx*j,B=C.ny*j,C.b2.velx+=R*C.b2.imass,C.b2.vely+=B*C.b2.imass,C.b1.velx-=R*C.b1.imass,C.b1.vely-=B*C.b1.imass,C.b2.angvel+=C.rn1b*j*C.b2.iinertia,C.b1.angvel-=C.rn1a*j*C.b1.iinertia;let S=b.colarb,J=S.k1x+S.b2.velx-S.c1.r2y*S.b2.angvel-(S.b1.velx-S.c1.r1y*S.b1.angvel),Q=S.k1y+S.b2.vely+S.c1.r2x*S.b2.angvel-(S.b1.vely+S.c1.r1x*S.b1.angvel),Y=(Q*S.nx-J*S.ny+S.surfacex)*S.c1.tMass,X=S.c1.friction*S.c1.jnAcc,ee=S.c1.jtAcc,G=ee-Y;G>X?G=X:G<-X&&(G=-X),Y=G-ee,S.c1.jtAcc=G;let F=-S.ny*Y,T=S.nx*Y;if(S.b2.velx+=F*S.b2.imass,S.b2.vely+=T*S.b2.imass,S.b1.velx-=F*S.b1.imass,S.b1.vely-=T*S.b1.imass,S.b2.angvel+=S.rt1b*Y*S.b2.iinertia,S.b1.angvel-=S.rt1a*Y*S.b1.iinertia,S.hc2){let ce=S.k2x+S.b2.velx-S.c2.r2y*S.b2.angvel-(S.b1.velx-S.c2.r1y*S.b1.angvel),pe=S.k2y+S.b2.vely+S.c2.r2x*S.b2.angvel-(S.b1.vely+S.c2.r1x*S.b1.angvel);Y=(pe*S.nx-ce*S.ny+S.surfacex)*S.c2.tMass,X=S.c2.friction*S.c2.jnAcc,ee=S.c2.jtAcc,G=ee-Y,G>X?G=X:G<-X&&(G=-X),Y=G-ee,S.c2.jtAcc=G,F=-S.ny*Y,T=S.nx*Y,S.b2.velx+=F*S.b2.imass,S.b2.vely+=T*S.b2.imass,S.b1.velx-=F*S.b1.imass,S.b1.vely-=T*S.b1.imass,S.b2.angvel+=S.rt2b*Y*S.b2.iinertia,S.b1.angvel-=S.rt2a*Y*S.b1.iinertia,J=S.k1x+S.b2.velx-S.c1.r2y*S.b2.angvel-(S.b1.velx-S.c1.r1y*S.b1.angvel),Q=S.k1y+S.b2.vely+S.c1.r2x*S.b2.angvel-(S.b1.vely+S.c1.r1x*S.b1.angvel),ce=S.k2x+S.b2.velx-S.c2.r2y*S.b2.angvel-(S.b1.velx-S.c2.r1y*S.b1.angvel),pe=S.k2y+S.b2.vely+S.c2.r2x*S.b2.angvel-(S.b1.vely+S.c2.r1x*S.b1.angvel);let ae=S.c1.jnAcc,xe=S.c2.jnAcc,te=J*S.nx+Q*S.ny+S.surfacey+S.c1.bounce-(S.Ka*ae+S.Kb*xe),he=ce*S.nx+pe*S.ny+S.surfacey+S.c2.bounce-(S.Kb*ae+S.Kc*xe),ye=-(S.kMassa*te+S.kMassb*he),ue=-(S.kMassb*te+S.kMassc*he);ye>=0&&ue>=0?(te=ye-ae,he=ue-xe,S.c1.jnAcc=ye,S.c2.jnAcc=ue):(ye=-S.c1.nMass*te,ye>=0&&S.Kb*ye+he>=0?(te=ye-ae,he=-xe,S.c1.jnAcc=ye,S.c2.jnAcc=0):(ue=-S.c2.nMass*he,ue>=0&&S.Kb*ue+te>=0?(te=-ae,he=ue-xe,S.c1.jnAcc=0,S.c2.jnAcc=ue):te>=0&&he>=0?(te=-ae,he=-xe,S.c1.jnAcc=S.c2.jnAcc=0):(te=0,he=0))),Y=te+he,F=S.nx*Y,T=S.ny*Y,S.b2.velx+=F*S.b2.imass,S.b2.vely+=T*S.b2.imass,S.b1.velx-=F*S.b1.imass,S.b1.vely-=T*S.b1.imass,S.b2.angvel+=(S.rn1b*te+S.rn2b*he)*S.b2.iinertia,S.b1.angvel-=(S.rn1a*te+S.rn2a*he)*S.b1.iinertia}else S.radius!=0&&(Y=(S.b2.angvel-S.b1.angvel)*S.rMass,X=S.rfric*S.c1.jnAcc,ee=S.jrAcc,S.jrAcc-=Y,S.jrAcc>X?S.jrAcc=X:S.jrAcc<-X&&(S.jrAcc=-X),Y=S.jrAcc-ee,S.b2.angvel+=Y*S.b2.iinertia,S.b1.angvel-=Y*S.b1.iinertia),J=S.k1x+S.b2.velx-S.c1.r2y*S.b2.angvel-(S.b1.velx-S.c1.r1y*S.b1.angvel),Q=S.k1y+S.b2.vely+S.c1.r2x*S.b2.angvel-(S.b1.vely+S.c1.r1x*S.b1.angvel),Y=(S.c1.bounce+(S.nx*J+S.ny*Q)+S.surfacey)*S.c1.nMass,ee=S.c1.jnAcc,G=ee-Y,G<0&&(G=0),Y=G-ee,S.c1.jnAcc=G,F=S.nx*Y,T=S.ny*Y,S.b2.velx+=F*S.b2.imass,S.b2.vely+=T*S.b2.imass,S.b1.velx-=F*S.b1.imass,S.b1.vely-=T*S.b1.imass,S.b2.angvel+=S.rn1b*Y*S.b2.iinertia,S.b1.angvel-=S.rn1a*Y*S.b1.iinertia;let A=b.colarb,W=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),H=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),K=(H*A.nx-W*A.ny+A.surfacex)*A.c1.tMass,ne=A.c1.friction*A.c1.jnAcc,re=A.c1.jtAcc,se=re-K;se>ne?se=ne:se<-ne&&(se=-ne),K=se-re,A.c1.jtAcc=se;let ie=-A.ny*K,oe=A.nx*K;if(A.b2.velx+=ie*A.b2.imass,A.b2.vely+=oe*A.b2.imass,A.b1.velx-=ie*A.b1.imass,A.b1.vely-=oe*A.b1.imass,A.b2.angvel+=A.rt1b*K*A.b2.iinertia,A.b1.angvel-=A.rt1a*K*A.b1.iinertia,A.hc2){let ce=A.k2x+A.b2.velx-A.c2.r2y*A.b2.angvel-(A.b1.velx-A.c2.r1y*A.b1.angvel),pe=A.k2y+A.b2.vely+A.c2.r2x*A.b2.angvel-(A.b1.vely+A.c2.r1x*A.b1.angvel);K=(pe*A.nx-ce*A.ny+A.surfacex)*A.c2.tMass,ne=A.c2.friction*A.c2.jnAcc,re=A.c2.jtAcc,se=re-K,se>ne?se=ne:se<-ne&&(se=-ne),K=se-re,A.c2.jtAcc=se,ie=-A.ny*K,oe=A.nx*K,A.b2.velx+=ie*A.b2.imass,A.b2.vely+=oe*A.b2.imass,A.b1.velx-=ie*A.b1.imass,A.b1.vely-=oe*A.b1.imass,A.b2.angvel+=A.rt2b*K*A.b2.iinertia,A.b1.angvel-=A.rt2a*K*A.b1.iinertia,W=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),H=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),ce=A.k2x+A.b2.velx-A.c2.r2y*A.b2.angvel-(A.b1.velx-A.c2.r1y*A.b1.angvel),pe=A.k2y+A.b2.vely+A.c2.r2x*A.b2.angvel-(A.b1.vely+A.c2.r1x*A.b1.angvel);let ae=A.c1.jnAcc,xe=A.c2.jnAcc,te=W*A.nx+H*A.ny+A.surfacey+A.c1.bounce-(A.Ka*ae+A.Kb*xe),he=ce*A.nx+pe*A.ny+A.surfacey+A.c2.bounce-(A.Kb*ae+A.Kc*xe),ye=-(A.kMassa*te+A.kMassb*he),ue=-(A.kMassb*te+A.kMassc*he);ye>=0&&ue>=0?(te=ye-ae,he=ue-xe,A.c1.jnAcc=ye,A.c2.jnAcc=ue):(ye=-A.c1.nMass*te,ye>=0&&A.Kb*ye+he>=0?(te=ye-ae,he=-xe,A.c1.jnAcc=ye,A.c2.jnAcc=0):(ue=-A.c2.nMass*he,ue>=0&&A.Kb*ue+te>=0?(te=-ae,he=ue-xe,A.c1.jnAcc=0,A.c2.jnAcc=ue):te>=0&&he>=0?(te=-ae,he=-xe,A.c1.jnAcc=A.c2.jnAcc=0):(te=0,he=0))),K=te+he,ie=A.nx*K,oe=A.ny*K,A.b2.velx+=ie*A.b2.imass,A.b2.vely+=oe*A.b2.imass,A.b1.velx-=ie*A.b1.imass,A.b1.vely-=oe*A.b1.imass,A.b2.angvel+=(A.rn1b*te+A.rn2b*he)*A.b2.iinertia,A.b1.angvel-=(A.rn1a*te+A.rn2a*he)*A.b1.iinertia}else A.radius!=0&&(K=(A.b2.angvel-A.b1.angvel)*A.rMass,ne=A.rfric*A.c1.jnAcc,re=A.jrAcc,A.jrAcc-=K,A.jrAcc>ne?A.jrAcc=ne:A.jrAcc<-ne&&(A.jrAcc=-ne),K=A.jrAcc-re,A.b2.angvel+=K*A.b2.iinertia,A.b1.angvel-=K*A.b1.iinertia),W=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),H=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),K=(A.c1.bounce+(A.nx*W+A.ny*H)+A.surfacey)*A.c1.nMass,re=A.c1.jnAcc,se=re-K,se<0&&(se=0),K=se-re,A.c1.jnAcc=se,ie=A.nx*K,oe=A.ny*K,A.b2.velx+=ie*A.b2.imass,A.b2.vely+=oe*A.b2.imass,A.b1.velx-=ie*A.b1.imass,A.b1.vely-=oe*A.b1.imass,A.b2.angvel+=A.rn1b*K*A.b2.iinertia,A.b1.angvel-=A.rn1a*K*A.b1.iinertia;u.sweep_angvel=u.angvel%t,h.sweep_angvel=h.angvel%t}if(b!=null&&b.active&&(b.immState&1)!=0&&b.type==Ae.COL){if(!u.sweepFrozen&&u.type!=3)if(u.sweepFrozen=!0,i.failed)u.angvel=u.sweep_angvel=0;else if(i.slipped){let d=u;d.sweep_angvel*=I._nape.Config.angularCCDSlipScale,u.angvel=d.sweep_angvel}else u.angvel=u.sweep_angvel;if(!h.sweepFrozen&&h.type!=3)if(h.sweepFrozen=!0,i.failed)h.angvel=h.sweep_angvel=0;else if(i.slipped){let d=h;d.sweep_angvel*=I._nape.Config.angularCCDSlipScale,h.angvel=d.sweep_angvel}else h.angvel=h.sweep_angvel}let _=i;_.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=_}for(;this.toiEvents.head!=null;){let o=this.toiEvents.pop_unsafe();o.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=o}let l=this.kinematics.head;for(;l!=null;){let i=l.elt,o=e-i.sweepTime;if(o!=0){i.sweepTime=e;let r=o;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let a=i.sweep_angvel*o;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let p=a*a,c=1-.5*p,u=1-p*p/8,h=(c*i.axisx+a*i.axisy)*u;i.axisy=(c*i.axisy-a*i.axisx)*u,i.axisx=h}}}i.sweepTime=0,l=l.next}let s=this.live.head;for(;s!=null;){let i=s.elt;if(!i.sweepFrozen){let o=e-i.sweepTime;if(o!=0){i.sweepTime=e;let r=o;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let a=i.sweep_angvel*o;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let p=a*a,c=1-.5*p,u=1-p*p/8,h=(c*i.axisx+a*i.axisy)*u;i.axisy=(c*i.axisy-a*i.axisx)*u,i.axisx=h}}}}i.sweepTime=0,s=s.next}}continuousEvent(e,t,n,l,s){if(e.body.sweepFrozen&&t.body.sweepFrozen||e.body.disableCCD||t.body.disableCCD)return l;let i;if(l!=null&&l.colarb==null)i=!0;else{let a=e.body,p=t.body,c;c=!1;let u=a.constraints.head;for(;u!=null;){let b=u.elt;if(b.ignore&&b.pair_exists(a.id,p.id)){c=!0;break}u=u.next}let h,x;if(c)x=!1;else{let b=e;for(;b!=null&&b.group==null;)b.ishape!=null?b=b.ishape.body:b.icompound!=null?b=b.icompound.compound:b=b.ibody.compound;let _=b==null?null:b.group,d;if(_==null)d=!1;else{let f=t;for(;f!=null&&f.group==null;)f.ishape!=null?f=f.ishape.body:f.icompound!=null?f=f.icompound.compound:f=f.ibody.compound;let m=f==null?null:f.group;if(m==null)d=!1;else{let z=!1;for(;_!=null&&m!=null;){if(_==m){z=_.ignore;break}_.depth<m.depth?m=m.group:_=_.group}d=z}}x=!d}if(x){let b;if(e.sensorEnabled||t.sensorEnabled){let _=e.filter,d=t.filter;b=(_.sensorMask&d.sensorGroup)!=0&&(d.sensorMask&_.sensorGroup)!=0}else b=!1;if(b)h=2;else{let _;if(e.fluidEnabled||t.fluidEnabled){let d=e.filter,f=t.filter;_=(d.fluidMask&f.fluidGroup)!=0&&(f.fluidMask&d.fluidGroup)!=0}else _=!1;if(_&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0))h=0;else{let d=e.filter,f=t.filter;h=(d.collisionMask&f.collisionGroup)!=0&&(f.collisionMask&d.collisionGroup)!=0&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0)?1:-1}}}else h=-1;i=h<=0}if(i)return l;let o=e.body,r=t.body;if(n||o.bullet||r.bullet){let a;I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?a=new I._zpp.geom.ZPP_ToiEvent:(a=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=a.next,a.next=null),a.failed=!1,a.s1=a.s2=null,a.arbiter=null;let p=o.type==3||r.type==3;if(n&&!p)e.body.type!=2?(a.s2=e,a.s1=t):(a.s1=e,a.s2=t),a.kinematic=!1,Pn.staticSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD);else if(a.s1=e,a.s2=t,a.kinematic=p,a.s1.body.sweepFrozen||a.s2.body.sweepFrozen){if(a.s1.body.sweepFrozen){let c=a.s1;a.s1=a.s2,a.s2=c,a.frozen1=!1,a.frozen2=!0}Pn.staticSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD)}else Pn.dynamicSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD,!1);if(n&&a.toi<0||a.failed){let c=a;c.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=c}else this.toiEvents.add(a),a.frozen1=a.s1.body.sweepFrozen,a.frozen2=a.s2.body.sweepFrozen,a.arbiter=l!=null?l.colarb:null}return l}bodyCbWake(e){if(e.type==2&&e.cbSet!=null)if(this.midstep){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let l=this.push_callback(n);l.event=2,l.body=e,t=t.next}}else e.component.woken=!0}bodyCbSleep(e){if(e.type==2&&e.cbSet!=null){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let l=this.push_callback(n);l.event=3,l.body=e,t=t.next}}}constraintCbWake(e){if(e.cbSet!=null)if(this.midstep){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let l=this.push_callback(n);l.event=2,l.constraint=e,t=t.next}}else e.component.woken=!0}constraintCbSleep(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let l=this.push_callback(n);l.event=3,l.constraint=e,t=t.next}}}constraintCbBreak(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=4){t=t.next;continue}let l=this.push_callback(n);l.event=4,l.constraint=e,t=t.next}}}nullListenerType(e,t){let n=new I._zpp.util.ZNPList_ZPP_Interactor,l=e.interactors.head;for(;l!=null;){let s=l.elt;n.add(s),l=l.next}if(e!=t){let s=t.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next}}for(;n.head!=null;){let s=n.pop_unsafe();if(s.icompound!=null){let i=s.icompound,o=i.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=i.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let i=s.ibody!=null?s.ibody:s.ishape.body,o=s.ishape!=null?s.ishape:null,r=i.arbiters.head;for(;r!=null;){let a=r.elt;if(a.present==0){r=r.next;continue}if(o!=null&&!(a.ws1==o||a.ws2==o)){r=r.next;continue}this.MRCA_chains(a.ws1,a.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let u=this.mrca2.head;for(;u!=null;){let h=u.elt;if(c.cbSet==e&&h.cbSet!=t||c.cbSet==t&&h.cbSet!=e){u=u.next;continue}let x=I._zpp.phys.ZPP_Interactor.get(c,h);if(x!=null){for(;x.arbiters.head!=null;){let b=x.arbiters.pop_unsafe();b.present--}this.remove_callbackset(x)}u=u.next}p=p.next}r=r.next}}}}nullInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,l=n.bodies.head;for(;l!=null;){let i=l.elt;this.nullInteractorType(i,t),l=l.next}let s=n.compounds.head;for(;s!=null;){let i=s.elt;this.nullInteractorType(i,t),s=s.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,l=e.ishape!=null?e.ishape:null,s=n.arbiters.head;for(;s!=null;){let i=s.elt;if(i.present==0){s=s.next;continue}if(l!=null&&!(i.ws1==l||i.ws2==l)){s=s.next;continue}this.MRCA_chains(i.ws1,i.ws2);let o=this.mrca1.head;for(;o!=null;){let r=o.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(r!=t&&p!=t){a=a.next;continue}let c=I._zpp.phys.ZPP_Interactor.get(r,p);c!=null&&(i.present--,c.remove_arb(i),c.arbiters.head==null&&this.remove_callbackset(c)),a=a.next}o=o.next}s=s.next}}}freshListenerType(e,t){let n=new I._zpp.util.ZNPList_ZPP_Interactor,l=e.interactors.head;for(;l!=null;){let s=l.elt;n.add(s),l=l.next}if(e!=t){let s=t.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next}}for(;n.head!=null;){let s=n.pop_unsafe();if(s.icompound!=null){let i=s.icompound,o=i.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=i.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let i=s.ibody!=null?s.ibody:s.ishape.body,o=s.ishape!=null?s.ishape:null,r=i.arbiters.head;for(;r!=null;){let a=r.elt;if(!a.presentable){r=r.next;continue}if(o!=null&&!(a.ws1==o||a.ws2==o)){r=r.next;continue}this.MRCA_chains(a.ws1,a.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let u=this.mrca2.head;for(;u!=null;){let h=u.elt;if(c.cbSet==e&&h.cbSet!=t||c.cbSet==t&&h.cbSet!=e){u=u.next;continue}let x=I._zpp.phys.ZPP_Interactor.get(c,h);x==null&&(x=Yt.get(c,h),this.add_callbackset(x));let b,_;_=!1;let d=x.arbiters.head;for(;d!=null;){if(d.elt==a){_=!0;break}d=d.next}if(_)b=!1;else{let f=x.arbiters,m;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?m=new I._zpp.util.ZNPNode_ZPP_Arbiter:(m=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=m.next,m.next=null),m.elt=a;let z=m;z.next=f.head,f.head=z,f.modified=!0,f.length++,b=!0}b&&a.present++,u=u.next}p=p.next}r=r.next}}}}freshInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,l=n.bodies.head;for(;l!=null;){let i=l.elt;this.freshInteractorType(i,t),l=l.next}let s=n.compounds.head;for(;s!=null;){let i=s.elt;this.freshInteractorType(i,t),s=s.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,l=e.ishape!=null?e.ishape:null,s=n.arbiters.head;for(;s!=null;){let i=s.elt;if(!i.presentable){s=s.next;continue}if(l!=null&&!(i.ws1==l||i.ws2==l)){s=s.next;continue}this.MRCA_chains(i.ws1,i.ws2);let o=this.mrca1.head;for(;o!=null;){let r=o.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(r!=t&&p!=t){a=a.next;continue}let c=r.cbSet,u=p.cbSet;c.validate(),u.validate();let h=c.manager,x=null,_=(c.cbpairs.length<u.cbpairs.length?c.cbpairs:u.cbpairs).head;for(;_!=null;){let d=_.elt;if(d.a==c&&d.b==u||d.a==u&&d.b==c){x=d;break}_=_.next}if(x==null){let d;Ne.zpp_pool==null?d=new Ne:(d=Ne.zpp_pool,Ne.zpp_pool=d.next,d.next=null),d.zip_listeners=!0,zt.setlt(c,u)?(d.a=c,d.b=u):(d.a=u,d.b=c),x=d,c.cbpairs.add(x),u!=c&&u.cbpairs.add(x)}if(x.zip_listeners&&(x.zip_listeners=!1,x.__validate()),x.listeners.head!=null){let d=I._zpp.phys.ZPP_Interactor.get(r,p);d==null&&(d=Yt.get(r,p),this.add_callbackset(d));let f,m;m=!1;let z=d.arbiters.head;for(;z!=null;){if(z.elt==i){m=!0;break}z=z.next}if(m)f=!1;else{let Z=d.arbiters,y;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?y=new I._zpp.util.ZNPNode_ZPP_Arbiter:(y=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y.next,y.next=null),y.elt=i;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++,f=!0}f&&i.present++}a=a.next}o=o.next}s=s.next}}}wakeCompound(e){let t=e.bodies.head;for(;t!=null;){let i=t.elt;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1)),t=t.next}let n=e.constraints.head;for(;n!=null;){let s=n.elt;this.wake_constraint(s),n=n.next}let l=e.compounds.head;for(;l!=null;){let s=l.elt;this.wakeCompound(s),l=l.next}}wakeIsland(e){for(;e.comps.head!=null;){let n=e.comps.pop_unsafe();if(n.waket=this.stamp+(this.midstep?0:1),n.isBody){let l=n.body;this.live.add(l);let s=l.arbiters.head;for(;s!=null;){let i=s.elt;if(i.sleeping)if(i.sleeping=!1,i.up_stamp+=this.stamp-i.sleep_stamp,i.type==Ae.COL){let o=i.colarb;if(o.stat){let r=this.c_arbiters_true,a;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(a=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}else{let r=this.c_arbiters_false,a;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(a=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}}else if(i.type==Ae.FLUID){let o=this.f_arbiters,r=i.fluidarb,a;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(a=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}else{let o=this.s_arbiters,r=i.sensorarb,a;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(a=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}s=s.next}if(this.bodyCbWake(l),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0,l.type!=1){let i=l.shapes.head;for(;i!=null;){let o=i.elt;o.node!=null&&this.bphase.sync(o),i=i.next}}}else{let l=n.constraint,s=this.live_constraints,i;I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?i=new I._zpp.util.ZNPNode_ZPP_Constraint:(i=I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=i.next,i.next=null),i.elt=l;let o=i;o.next=s.head,s.head=o,s.modified=!0,s.length++,this.constraintCbWake(l),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0}}let t=e;t.next=yt.zpp_pool,yt.zpp_pool=t}non_inlined_wake(e,t){t==null&&(t=!1);let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,t))}really_wake(e,t){if(t==null&&(t=!1),e.component.island==null){if(e.component.sleeping=!1,e.type==3||e.type==1){let s=this.staticsleep,i;I._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?i=new I._zpp.util.ZNPNode_ZPP_Body:(i=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=i.next,i.next=null),i.elt=e;let o=i;o.next=s.head,s.head=o,s.modified=!0,s.length++}else{let s=this.live,i;I._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?i=new I._zpp.util.ZNPNode_ZPP_Body:(i=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=i.next,i.next=null),i.elt=e;let o=i;o.next=s.head,s.head=o,s.modified=!0,s.length++}let n=e.constraints.head;for(;n!=null;){let s=n.elt;s.space==this&&this.wake_constraint(s),n=n.next}let l=e.arbiters.head;for(;l!=null;){let s=l.elt;if(s.sleeping)if(s.sleeping=!1,s.up_stamp+=this.stamp+(this.midstep?0:1)-s.sleep_stamp,s.type==Ae.COL){let i=s.colarb;if(i.stat){let o=this.c_arbiters_true,r;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(r=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=i;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}else{let o=this.c_arbiters_false,r;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(r=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=i;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}}else if(s.type==Ae.FLUID){let i=this.f_arbiters,o=s.fluidarb,r;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(r=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=i.head,i.head=a,i.modified=!0,i.length++}else{let i=this.s_arbiters,o=s.sensorarb,r;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(r=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=i.head,i.head=a,i.modified=!0,i.length++}if(s.type!=Ae.SENSOR&&!s.cleared&&s.up_stamp>=this.stamp&&(s.immState&1)!=0){if(s.b1.type==2&&s.b1.component.sleeping){let i=s.b1;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1))}if(s.b2.type==2&&s.b2.component.sleeping){let i=s.b2;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1))}}l=l.next}if(!t&&e.type==2&&this.bodyCbWake(e),!t&&!this.bphase.is_sweep&&e.type!=1){let s=e.shapes.head;for(;s!=null;){let i=s.elt;i.node!=null&&this.bphase.sync(i),s=s.next}}}else this.wakeIsland(e.component.island)}wake_constraint(e,t){if(t==null&&(t=!1),e.active)if(e.component.waket=this.stamp+(this.midstep?0:1),e.component.sleeping){if(e.component.island==null){e.component.sleeping=!1;let n=this.live_constraints,l;I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?l=new I._zpp.util.ZNPNode_ZPP_Constraint:(l=I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=l.next,l.next=null),l.elt=e;let s=l;s.next=n.head,n.head=s,n.modified=!0,n.length++,e.wake_connected(),t||this.constraintCbWake(e)}else this.wakeIsland(e.component.island);return!0}else return!1;else return!1}doForests(e){let t=this.c_arbiters_false.head;for(;t!=null;){let s=t.elt;if(!s.cleared&&s.up_stamp==this.stamp&&(s.immState&1)!=0&&s.b1.type==2&&s.b2.type==2){let i;if(s.b1.component==s.b1.component.parent)i=s.b1.component;else{let r=s.b1.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}i=r}let o;if(s.b2.component==s.b2.component.parent)o=s.b2.component;else{let r=s.b2.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}o=r}i!=o&&(i.rank<o.rank?i.parent=o:i.rank>o.rank?o.parent=i:(o.parent=i,i.rank++))}t=t.next}let n=this.f_arbiters.head;for(;n!=null;){let s=n.elt;if(!s.cleared&&s.up_stamp==this.stamp&&(s.immState&1)!=0&&s.b1.type==2&&s.b2.type==2){let i;if(s.b1.component==s.b1.component.parent)i=s.b1.component;else{let r=s.b1.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}i=r}let o;if(s.b2.component==s.b2.component.parent)o=s.b2.component;else{let r=s.b2.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}o=r}i!=o&&(i.rank<o.rank?i.parent=o:i.rank>o.rank?o.parent=i:(o.parent=i,i.rank++))}n=n.next}let l=this.live_constraints.head;for(;l!=null;)l.elt.forest(),l=l.next;for(;this.live.head!=null;){let s=this.live,i=s.head.elt;s.pop();let o=i,r=o.component,a;if(r==r.parent)a=r;else{let x=r,b=null;for(;x!=x.parent;){let _=x.parent;x.parent=b,b=x,x=_}for(;b!=null;){let _=b.parent;b.parent=x,b=_}a=x}if(a.island==null){yt.zpp_pool==null?a.island=new yt:(a.island=yt.zpp_pool,yt.zpp_pool=a.island.next,a.island.next=null),a.island.waket=0;let x=this.islands,b=a.island;b._inuse=!0;let _=b;_.next=x.next,x.next=_,x.modified=!0,x.length++,a.island.sleep=!0}r.island=a.island;let p=r.island.comps,c;I._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new I._zpp.util.ZNPNode_ZPP_Component:(c=I._zpp.util.ZNPNode_ZPP_Component.zpp_pool,I._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=r;let u=c;u.next=p.head,p.head=u,p.modified=!0,p.length++;let h=o.atRest(e);r.island.sleep=r.island.sleep&&h,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.live_constraints.head!=null;){let s=this.live_constraints,i=s.head.elt;s.pop();let r=i.component,a;if(r==r.parent)a=r;else{let h=r,x=null;for(;h!=h.parent;){let b=h.parent;h.parent=x,x=h,h=b}for(;x!=null;){let b=x.parent;x.parent=h,x=b}a=h}r.island=a.island;let p=r.island.comps,c;I._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new I._zpp.util.ZNPNode_ZPP_Component:(c=I._zpp.util.ZNPNode_ZPP_Component.zpp_pool,I._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=r;let u=c;u.next=p.head,p.head=u,p.modified=!0,p.length++,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.islands.next!=null;){let s=this.islands,i=s.next;s.pop();let o=i;if(o.sleep){let r=o.comps.head;for(;r!=null;){let a=r.elt;if(a.isBody){let p=a.body;p.velx=0,p.vely=0,p.angvel=0,a.sleeping=!0;let c=p.shapes.head;for(;c!=null;){let u=c.elt;this.bphase.sync(u),c=c.next}this.bodyCbSleep(p)}else{let p=a.constraint;this.constraintCbSleep(p),a.sleeping=!0}r=r.next}}else{for(;o.comps.head!=null;){let a=o.comps,p=a.head.elt;a.pop();let c=p;if(c.waket=o.waket,c.isBody){let u=this.live,h=c.body,x;I._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?x=new I._zpp.util.ZNPNode_ZPP_Body:(x=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=x.next,x.next=null),x.elt=h;let b=x;b.next=u.head,u.head=b,u.modified=!0,u.length++}else{let u=this.live_constraints,h=c.constraint,x;I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?x=new I._zpp.util.ZNPNode_ZPP_Constraint:(x=I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=x.next,x.next=null),x.elt=h;let b=x;b.next=u.head,u.head=b,u.modified=!0,u.length++}c.sleeping=!1,c.island=null,c.parent=c,c.rank=0}let r=o;r.next=yt.zpp_pool,yt.zpp_pool=r}}}sleepArbiters(){let e=null,t=this.c_arbiters_true,n=t.head,l=this.c_arbiters_false!=null;for(l&&n==null&&(l=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);n!=null;){let h=n.elt;if(h.b1.component.sleeping&&h.b2.component.sleeping){h.sleep_stamp=this.stamp,h.sleeping=!0;let x,b;e==null?(x=t.head,b=x.next,t.head=b,t.head==null&&(t.pushmod=!0)):(x=e.next,b=x.next,e.next=b,b==null&&(t.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=_,t.modified=!0,t.length--,t.pushmod=!0,n=b,l&&n==null&&(l=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);continue}e=n,n=n.next,l&&n==null&&(l=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null)}let s=null,i=this.f_arbiters,o=i.head,r=!1;for(r&&o==null&&(r=!1,i=null,s=null);o!=null;){let h=o.elt;if(h.b1.component.sleeping&&h.b2.component.sleeping){h.sleep_stamp=this.stamp,h.sleeping=!0;let x,b;s==null?(x=i.head,b=x.next,i.head=b,i.head==null&&(i.pushmod=!0)):(x=s.next,b=x.next,s.next=b,b==null&&(i.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=_,i.modified=!0,i.length--,i.pushmod=!0,o=b,r&&o==null&&(r=!1,i=null,s=null);continue}s=o,o=o.next,r&&o==null&&(r=!1,i=null,s=null)}let a=null,p=this.s_arbiters,c=p.head,u=!1;for(u&&c==null&&(u=!1,p=null,a=null);c!=null;){let h=c.elt;if(h.b1.component.sleeping&&h.b2.component.sleeping){h.sleep_stamp=this.stamp,h.sleeping=!0;let x,b;a==null?(x=p.head,b=x.next,p.head=b,p.head==null&&(p.pushmod=!0)):(x=a.next,b=x.next,a.next=b,b==null&&(p.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=_,p.modified=!0,p.length--,p.pushmod=!0,c=b,u&&c==null&&(u=!1,p=null,a=null);continue}a=c,c=c.next,u&&c==null&&(u=!1,p=null,a=null)}}static_validation(e){if(e.shapes.head!=null){if(e.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(e.zip_aabb){e.zip_aabb=!1,e.aabb.minx=1/0,e.aabb.miny=1/0,e.aabb.maxx=-1/0,e.aabb.maxy=-1/0;let n=e.shapes.head;for(;n!=null;){let l=n.elt;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let o=l.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let b=h;for(h=h.next;h!=null;){let Z=h;u+=b.x*(Z.y-x.y);let y=Z.y*b.x-Z.x*b.y;c.localCOMx+=(b.x+Z.x)*y,c.localCOMy+=(b.y+Z.y)*y,x=b,b=Z,h=h.next}h=c.lverts.next;let _=h;u+=b.x*(_.y-x.y);let d=_.y*b.x-_.x*b.y;c.localCOMx+=(b.x+_.x)*d,c.localCOMy+=(b.y+_.y)*d,x=b,b=_,h=h.next;let f=h;u+=b.x*(f.y-x.y);let m=f.y*b.x-f.x*b.y;c.localCOMx+=(b.x+f.x)*m,c.localCOMy+=(b.y+f.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else{let o=l.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,u=o.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),h.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}let s=e.aabb,i=l.aabb;i.minx<s.minx&&(s.minx=i.minx),i.maxx>s.maxx&&(s.maxx=i.maxx),i.miny<s.miny&&(s.miny=i.miny),i.maxy>s.maxy&&(s.maxy=i.maxy),n=n.next}}}if(e.validate_mass(),e.validate_inertia(),e.velx!=0||e.vely!=0||e.angvel!=0)throw new Error("Error: Static body cannot have any real velocity, only kinematic or surface velocities");let t=e.shapes.head;for(;t!=null;){let n=t.elt;if(n.type==1){let l=n.polygon;l.zip_sanitation&&(l.zip_sanitation=!1,l.splice_collinear_real());let s=n.polygon.valid();if($.ValidationResult_VALID==null&&($.internal=!0,$.ValidationResult_VALID=new I._nape.shape.ValidationResult,$.internal=!1),s!=$.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+n.polygon.outer.toString()+" is invalid : "+s.toString());let i=n.polygon;if(i.zip_gaxi&&i.body!=null){i.zip_gaxi=!1,i.validate_laxi();let o=i.body;if(o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let h=i.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot));let x=i.lverts.next,b=i.gverts.next;for(;b!=null;){let _=b,d=x;x=x.next,_.x=i.body.posx+(i.body.axisy*d.x-i.body.axisx*d.y),_.y=i.body.posy+(d.x*i.body.axisx+d.y*i.body.axisy),b=b.next}}let r=i.edges.head,a=i.gverts.next,p=a;for(a=a.next;a!=null;){let h=a,x=r.elt;r=r.next,x.gp0=p,x.gp1=h,x.gnormx=i.body.axisy*x.lnormx-i.body.axisx*x.lnormy,x.gnormy=x.lnormx*i.body.axisx+x.lnormy*i.body.axisy,x.gprojection=i.body.posx*x.gnormx+i.body.posy*x.gnormy+x.lprojection,x.wrap_gnorm!=null&&(x.wrap_gnorm.zpp_inner.x=x.gnormx,x.wrap_gnorm.zpp_inner.y=x.gnormy),x.tp0=x.gp0.y*x.gnormx-x.gp0.x*x.gnormy,x.tp1=x.gp1.y*x.gnormx-x.gp1.x*x.gnormy,p=h,a=a.next}let c=i.gverts.next,u=r.elt;r=r.next,u.gp0=p,u.gp1=c,u.gnormx=i.body.axisy*u.lnormx-i.body.axisx*u.lnormy,u.gnormy=u.lnormx*i.body.axisx+u.lnormy*i.body.axisy,u.gprojection=i.body.posx*u.gnormx+i.body.posy*u.gnormy+u.lprojection,u.wrap_gnorm!=null&&(u.wrap_gnorm.zpp_inner.x=u.gnormx,u.wrap_gnorm.zpp_inner.y=u.gnormy),u.tp0=u.gp0.y*u.gnormx-u.gp0.x*u.gnormy,u.tp1=u.gp1.y*u.gnormx-u.gp1.x*u.gnormy}}t=t.next}e.sweepFrozen=!0}validation(){let e=this.cbsets;if(!e.cbsets.empty()){let s=e.cbsets.parent;for(;s.prev!=null;)s=s.prev;for(;s!=null;)if(s.data.validate(),s.next!=null)for(s=s.next;s.prev!=null;)s=s.prev;else{for(;s.parent!=null&&s==s.parent.next;)s=s.parent;s=s.parent}}let t=this.live.head;for(;t!=null;){let s=t.elt;s.sweepRadius=0;let i=s.shapes.head;for(;i!=null;){let r=i.elt;if(r.type==1){let a=r.polygon;a.zip_sanitation&&(a.zip_sanitation=!1,a.splice_collinear_real());let p=r.polygon.valid();if($.ValidationResult_VALID==null&&($.internal=!0,$.ValidationResult_VALID=new I._nape.shape.ValidationResult,$.internal=!1),p!=$.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+r.polygon.outer.toString()+" is invalid : "+p.toString());let c=r.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=!1,c.validate_laxi();let u=c.body;if(u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let f=c.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let m=c.lverts.next,z=c.gverts.next;for(;z!=null;){let Z=z,y=m;m=m.next,Z.x=c.body.posx+(c.body.axisy*y.x-c.body.axisx*y.y),Z.y=c.body.posy+(y.x*c.body.axisx+y.y*c.body.axisy),z=z.next}}let h=c.edges.head,x=c.gverts.next,b=x;for(x=x.next;x!=null;){let f=x,m=h.elt;h=h.next,m.gp0=b,m.gp1=f,m.gnormx=c.body.axisy*m.lnormx-c.body.axisx*m.lnormy,m.gnormy=m.lnormx*c.body.axisx+m.lnormy*c.body.axisy,m.gprojection=c.body.posx*m.gnormx+c.body.posy*m.gnormy+m.lprojection,m.wrap_gnorm!=null&&(m.wrap_gnorm.zpp_inner.x=m.gnormx,m.wrap_gnorm.zpp_inner.y=m.gnormy),m.tp0=m.gp0.y*m.gnormx-m.gp0.x*m.gnormy,m.tp1=m.gp1.y*m.gnormx-m.gp1.x*m.gnormy,b=f,x=x.next}let _=c.gverts.next,d=h.elt;h=h.next,d.gp0=b,d.gp1=_,d.gnormx=c.body.axisy*d.lnormx-c.body.axisx*d.lnormy,d.gnormy=d.lnormx*c.body.axisx+d.lnormy*c.body.axisy,d.gprojection=c.body.posx*d.gnormx+c.body.posy*d.gnormy+d.lprojection,d.wrap_gnorm!=null&&(d.wrap_gnorm.zpp_inner.x=d.gnormx,d.wrap_gnorm.zpp_inner.y=d.gnormy),d.tp0=d.gp0.y*d.gnormx-d.gp0.x*d.gnormy,d.tp1=d.gp1.y*d.gnormx-d.gp1.x*d.gnormy}}r.validate_sweepRadius(),r.sweepRadius>s.sweepRadius&&(s.sweepRadius=r.sweepRadius),i=i.next}if(s.validate_mass(),s.validate_inertia(),s.shapes.head!=null){if(s.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(s.zip_aabb){s.zip_aabb=!1,s.aabb.minx=1/0,s.aabb.miny=1/0,s.aabb.maxx=-1/0,s.aabb.maxy=-1/0;let r=s.shapes.head;for(;r!=null;){let a=r.elt;if(a.zip_aabb&&a.body!=null)if(a.zip_aabb=!1,a.type==0){let u=a.circle;if(u.zip_worldCOM&&u.body!=null){if(u.zip_worldCOM=!1,u.zip_localCOM){if(u.zip_localCOM=!1,u.type==1){let _=u.polygon;if(_.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(_.lverts.next.next==null)_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;else if(_.lverts.next.next.next==null){_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;let d=1;_.localCOMx+=_.lverts.next.next.x*d,_.localCOMy+=_.lverts.next.next.y*d;let f=.5;_.localCOMx*=f,_.localCOMy*=f}else{_.localCOMx=0,_.localCOMy=0;let d=0,f=_.lverts.next,m=f;f=f.next;let z=f;for(f=f.next;f!=null;){let g=f;d+=z.x*(g.y-m.y);let k=g.y*z.x-g.x*z.y;_.localCOMx+=(z.x+g.x)*k,_.localCOMy+=(z.y+g.y)*k,m=z,z=g,f=f.next}f=_.lverts.next;let Z=f;d+=z.x*(Z.y-m.y);let y=Z.y*z.x-Z.x*z.y;_.localCOMx+=(z.x+Z.x)*y,_.localCOMy+=(z.y+Z.y)*y,m=z,z=Z,f=f.next;let w=f;d+=z.x*(w.y-m.y);let v=w.y*z.x-w.x*z.y;_.localCOMx+=(z.x+w.x)*v,_.localCOMy+=(z.y+w.y)*v,d=1/(3*d);let P=d;_.localCOMx*=P,_.localCOMy*=P}}u.wrap_localCOM!=null&&(u.wrap_localCOM.zpp_inner.x=u.localCOMx,u.wrap_localCOM.zpp_inner.y=u.localCOMy)}let b=u.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot)),u.worldCOMx=u.body.posx+(u.body.axisy*u.localCOMx-u.body.axisx*u.localCOMy),u.worldCOMy=u.body.posy+(u.localCOMx*u.body.axisx+u.localCOMy*u.body.axisy)}let h=u.radius,x=u.radius;u.aabb.minx=u.worldCOMx-h,u.aabb.miny=u.worldCOMy-x,u.aabb.maxx=u.worldCOMx+h,u.aabb.maxy=u.worldCOMy+x}else{let u=a.polygon;if(u.zip_gverts&&u.body!=null){u.zip_gverts=!1,u.validate_lverts();let b=u.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot));let _=u.lverts.next,d=u.gverts.next;for(;d!=null;){let f=d,m=_;_=_.next,f.x=u.body.posx+(u.body.axisy*m.x-u.body.axisx*m.y),f.y=u.body.posy+(m.x*u.body.axisx+m.y*u.body.axisy),d=d.next}}if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let h=u.gverts.next;u.aabb.minx=h.x,u.aabb.miny=h.y,u.aabb.maxx=h.x,u.aabb.maxy=h.y;let x=u.gverts.next.next;for(;x!=null;){let b=x;b.x<u.aabb.minx&&(u.aabb.minx=b.x),b.x>u.aabb.maxx&&(u.aabb.maxx=b.x),b.y<u.aabb.miny&&(u.aabb.miny=b.y),b.y>u.aabb.maxy&&(u.aabb.maxy=b.y),x=x.next}}let p=s.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),r=r.next}}s.validate_worldCOM()}if(s.validate_gravMass(),s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),!s.nomove&&s.type==2&&s.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!s.norotate&&s.type==2&&s.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");if(s.component.woken&&s.cbSet!=null){let r=s.cbSet.bodylisteners.head;for(;r!=null;){let a=r.elt;if(a.event!=2){r=r.next;continue}let p=this.push_callback(a);p.event=2,p.body=s,r=r.next}}s.component.woken=!1;let o=s.shapes.head;for(;o!=null;){let r=o.elt;this.bphase.sync(r),o=o.next}t=t.next}let n=this.kinematics.head;for(;n!=null;){let s=n.elt;s.sweepRadius=0;let i=s.shapes.head;for(;i!=null;){let r=i.elt;if(r.type==1){let a=r.polygon;a.zip_sanitation&&(a.zip_sanitation=!1,a.splice_collinear_real());let p=r.polygon.valid();if($.ValidationResult_VALID==null&&($.internal=!0,$.ValidationResult_VALID=new I._nape.shape.ValidationResult,$.internal=!1),p!=$.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+r.polygon.outer.toString()+" is invalid : "+p.toString());let c=r.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=!1,c.validate_laxi();let u=c.body;if(u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let f=c.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let m=c.lverts.next,z=c.gverts.next;for(;z!=null;){let Z=z,y=m;m=m.next,Z.x=c.body.posx+(c.body.axisy*y.x-c.body.axisx*y.y),Z.y=c.body.posy+(y.x*c.body.axisx+y.y*c.body.axisy),z=z.next}}let h=c.edges.head,x=c.gverts.next,b=x;for(x=x.next;x!=null;){let f=x,m=h.elt;h=h.next,m.gp0=b,m.gp1=f,m.gnormx=c.body.axisy*m.lnormx-c.body.axisx*m.lnormy,m.gnormy=m.lnormx*c.body.axisx+m.lnormy*c.body.axisy,m.gprojection=c.body.posx*m.gnormx+c.body.posy*m.gnormy+m.lprojection,m.wrap_gnorm!=null&&(m.wrap_gnorm.zpp_inner.x=m.gnormx,m.wrap_gnorm.zpp_inner.y=m.gnormy),m.tp0=m.gp0.y*m.gnormx-m.gp0.x*m.gnormy,m.tp1=m.gp1.y*m.gnormx-m.gp1.x*m.gnormy,b=f,x=x.next}let _=c.gverts.next,d=h.elt;h=h.next,d.gp0=b,d.gp1=_,d.gnormx=c.body.axisy*d.lnormx-c.body.axisx*d.lnormy,d.gnormy=d.lnormx*c.body.axisx+d.lnormy*c.body.axisy,d.gprojection=c.body.posx*d.gnormx+c.body.posy*d.gnormy+d.lprojection,d.wrap_gnorm!=null&&(d.wrap_gnorm.zpp_inner.x=d.gnormx,d.wrap_gnorm.zpp_inner.y=d.gnormy),d.tp0=d.gp0.y*d.gnormx-d.gp0.x*d.gnormy,d.tp1=d.gp1.y*d.gnormx-d.gp1.x*d.gnormy}}r.validate_sweepRadius(),r.sweepRadius>s.sweepRadius&&(s.sweepRadius=r.sweepRadius),i=i.next}if(s.validate_mass(),s.validate_inertia(),s.shapes.head!=null){if(s.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(s.zip_aabb){s.zip_aabb=!1,s.aabb.minx=1/0,s.aabb.miny=1/0,s.aabb.maxx=-1/0,s.aabb.maxy=-1/0;let r=s.shapes.head;for(;r!=null;){let a=r.elt;if(a.zip_aabb&&a.body!=null)if(a.zip_aabb=!1,a.type==0){let u=a.circle;if(u.zip_worldCOM&&u.body!=null){if(u.zip_worldCOM=!1,u.zip_localCOM){if(u.zip_localCOM=!1,u.type==1){let _=u.polygon;if(_.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(_.lverts.next.next==null)_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;else if(_.lverts.next.next.next==null){_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;let d=1;_.localCOMx+=_.lverts.next.next.x*d,_.localCOMy+=_.lverts.next.next.y*d;let f=.5;_.localCOMx*=f,_.localCOMy*=f}else{_.localCOMx=0,_.localCOMy=0;let d=0,f=_.lverts.next,m=f;f=f.next;let z=f;for(f=f.next;f!=null;){let g=f;d+=z.x*(g.y-m.y);let k=g.y*z.x-g.x*z.y;_.localCOMx+=(z.x+g.x)*k,_.localCOMy+=(z.y+g.y)*k,m=z,z=g,f=f.next}f=_.lverts.next;let Z=f;d+=z.x*(Z.y-m.y);let y=Z.y*z.x-Z.x*z.y;_.localCOMx+=(z.x+Z.x)*y,_.localCOMy+=(z.y+Z.y)*y,m=z,z=Z,f=f.next;let w=f;d+=z.x*(w.y-m.y);let v=w.y*z.x-w.x*z.y;_.localCOMx+=(z.x+w.x)*v,_.localCOMy+=(z.y+w.y)*v,d=1/(3*d);let P=d;_.localCOMx*=P,_.localCOMy*=P}}u.wrap_localCOM!=null&&(u.wrap_localCOM.zpp_inner.x=u.localCOMx,u.wrap_localCOM.zpp_inner.y=u.localCOMy)}let b=u.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot)),u.worldCOMx=u.body.posx+(u.body.axisy*u.localCOMx-u.body.axisx*u.localCOMy),u.worldCOMy=u.body.posy+(u.localCOMx*u.body.axisx+u.localCOMy*u.body.axisy)}let h=u.radius,x=u.radius;u.aabb.minx=u.worldCOMx-h,u.aabb.miny=u.worldCOMy-x,u.aabb.maxx=u.worldCOMx+h,u.aabb.maxy=u.worldCOMy+x}else{let u=a.polygon;if(u.zip_gverts&&u.body!=null){u.zip_gverts=!1,u.validate_lverts();let b=u.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot));let _=u.lverts.next,d=u.gverts.next;for(;d!=null;){let f=d,m=_;_=_.next,f.x=u.body.posx+(u.body.axisy*m.x-u.body.axisx*m.y),f.y=u.body.posy+(m.x*u.body.axisx+m.y*u.body.axisy),d=d.next}}if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let h=u.gverts.next;u.aabb.minx=h.x,u.aabb.miny=h.y,u.aabb.maxx=h.x,u.aabb.maxy=h.y;let x=u.gverts.next.next;for(;x!=null;){let b=x;b.x<u.aabb.minx&&(u.aabb.minx=b.x),b.x>u.aabb.maxx&&(u.aabb.maxx=b.x),b.y<u.aabb.miny&&(u.aabb.miny=b.y),b.y>u.aabb.maxy&&(u.aabb.maxy=b.y),x=x.next}}let p=s.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),r=r.next}}s.validate_worldCOM()}if(s.validate_gravMass(),s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),!s.nomove&&s.type==2&&s.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!s.norotate&&s.type==2&&s.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");let o=s.shapes.head;for(;o!=null;){let r=o.elt;this.bphase.sync(r),o=o.next}n=n.next}let l=this.live_constraints.head;for(;l!=null;){let s=l.elt;if(s.active){if(s.validate(),s.component.woken&&s.cbSet!=null){let i=s.cbSet.conlisteners.head;for(;i!=null;){let o=i.elt;if(o.event!=2){i=i.next;continue}let r=this.push_callback(o);r.event=2,r.constraint=s,i=i.next}}s.component.woken=!1}l=l.next}}updateVel(e){let t=null,n=1-e*this.global_lin_drag,l=1-e*this.global_ang_drag,s=this.live.head;for(;s!=null;){let i=s.elt;if(i.smass!=0){let o=e*i.imass;i.velx=n*i.velx+(i.forcex+this.gravityx*i.gravMass)*o,i.vely=n*i.vely+(i.forcey+this.gravityy*i.gravMass)*o}if(i.sinertia!=0){let o=0,r=0;o=i.worldCOMx-i.posx,r=i.worldCOMy-i.posy;let a=i.torque+(this.gravityy*o-this.gravityx*r)*i.gravMass;i.angvel=l*i.angvel+a*e*i.iinertia}t=s,s=s.next}}updatePos(e){let t=2*Math.PI/e,n=this.live.head;for(;n!=null;){let s=n.elt;s.pre_posx=s.posx,s.pre_posy=s.posy,s.pre_rot=s.rot,s.sweepTime=0,s.sweep_angvel=s.angvel%t;let i=e-s.sweepTime;if(i!=0){s.sweepTime=e;let o=i;if(s.posx+=s.velx*o,s.posy+=s.vely*o,s.angvel!=0){let r=s.sweep_angvel*i;if(s.rot+=r,r*r>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,u=(p*s.axisx+r*s.axisy)*c;s.axisy=(p*s.axisy-r*s.axisx)*c,s.axisx=u}}}if(s.disableCCD)s.sweepFrozen=!0,s.bullet=!1;else{let o=I._nape.Config.staticCCDLinearThreshold*s.sweepRadius,r=I._nape.Config.staticCCDAngularThreshold;if((s.velx*s.velx+s.vely*s.vely)*e*e>o*o||s.angvel*s.angvel*e*e>r*r||s.type==3){let a=s.sweep_angvel;a<0&&(a=-a);let p=1/a,c=s.shapes.head;for(;c!=null;){let u=c.elt,h=u.aabb,x=h.minx,b=h.miny,_=h.maxx,d=h.maxy,f=a*e*u.sweepCoef*.008333333333333333|0;f>8&&(f=8);let m=a*e/f,z=e-s.sweepTime;if(z!=0){s.sweepTime=e;let w=z;if(s.posx+=s.velx*w,s.posy+=s.vely*w,s.angvel!=0){let v=s.sweep_angvel*z;if(s.rot+=v,v*v>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let P=v*v,g=1-.5*P,k=1-P*P/8,N=(g*s.axisx+v*s.axisy)*k;s.axisy=(g*s.axisy-v*s.axisx)*k,s.axisx=N}}}if(u.type==0){let w=u.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else{let w=u.polygon,v=w.lverts.next,P=w.gverts.next,g=v;v=v.next,P.x=w.body.posx+(w.body.axisy*g.x-w.body.axisx*g.y),P.y=w.body.posy+(g.x*w.body.axisx+g.y*w.body.axisy),w.aabb.minx=P.x,w.aabb.miny=P.y,w.aabb.maxx=P.x,w.aabb.maxy=P.y;let k=w.gverts.next.next;for(;k!=null;){let N=k,E=v;v=v.next,N.x=w.body.posx+(w.body.axisy*E.x-w.body.axisx*E.y),N.y=w.body.posy+(E.x*w.body.axisx+E.y*w.body.axisy),N.x<w.aabb.minx&&(w.aabb.minx=N.x),N.x>w.aabb.maxx&&(w.aabb.maxx=N.x),N.y<w.aabb.miny&&(w.aabb.miny=N.y),N.y>w.aabb.maxy&&(w.aabb.maxy=N.y),k=k.next}}x<h.minx?h.minx=x:x=h.minx,b<h.miny?h.miny=b:b=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy;let Z=1,y=f;for(;Z<y;){let w=Z++,v=m*w*p,P=v-s.sweepTime;if(P!=0){s.sweepTime=v;let g=P;if(s.posx+=s.velx*g,s.posy+=s.vely*g,s.angvel!=0){let k=s.sweep_angvel*P;if(s.rot+=k,k*k>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let N=k*k,E=1-.5*N,M=1-N*N/8,C=(E*s.axisx+k*s.axisy)*M;s.axisy=(E*s.axisy-k*s.axisx)*M,s.axisx=C}}}if(u.type==0){let g=u.circle;g.worldCOMx=g.body.posx+(g.body.axisy*g.localCOMx-g.body.axisx*g.localCOMy),g.worldCOMy=g.body.posy+(g.localCOMx*g.body.axisx+g.localCOMy*g.body.axisy),g.aabb.minx=g.worldCOMx-g.radius,g.aabb.miny=g.worldCOMy-g.radius,g.aabb.maxx=g.worldCOMx+g.radius,g.aabb.maxy=g.worldCOMy+g.radius}else{let g=u.polygon,k=g.lverts.next,N=g.gverts.next,E=k;k=k.next,N.x=g.body.posx+(g.body.axisy*E.x-g.body.axisx*E.y),N.y=g.body.posy+(E.x*g.body.axisx+E.y*g.body.axisy),g.aabb.minx=N.x,g.aabb.miny=N.y,g.aabb.maxx=N.x,g.aabb.maxy=N.y;let M=g.gverts.next.next;for(;M!=null;){let C=M,D=k;k=k.next,C.x=g.body.posx+(g.body.axisy*D.x-g.body.axisx*D.y),C.y=g.body.posy+(D.x*g.body.axisx+D.y*g.body.axisy),C.x<g.aabb.minx&&(g.aabb.minx=C.x),C.x>g.aabb.maxx&&(g.aabb.maxx=C.x),C.y<g.aabb.miny&&(g.aabb.miny=C.y),C.y>g.aabb.maxy&&(g.aabb.maxy=C.y),M=M.next}}x<h.minx?h.minx=x:x=h.minx,b<h.miny?h.miny=b:b=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy}this.bphase.sync(u),c=c.next}if(s.sweepFrozen=!1,s.type==2&&s.bulletEnabled){let u=I._nape.Config.bulletCCDLinearThreshold*s.sweepRadius,h=I._nape.Config.bulletCCDAngularThreshold;((s.velx*s.velx+s.vely*s.vely)*e*e>u*u||s.angvel*s.angvel*e*e>h*h)&&(s.bullet=!0)}}else s.sweepFrozen=!0,s.bullet=!1}n=n.next}let l=this.kinematics.head;for(;l!=null;){let s=l.elt;s.pre_posx=s.posx,s.pre_posy=s.posy,s.pre_rot=s.rot,s.sweepTime=0,s.sweep_angvel=s.angvel%t;let i=e-s.sweepTime;if(i!=0){s.sweepTime=e;let o=i;if(s.posx+=s.velx*o,s.posy+=s.vely*o,s.angvel!=0){let r=s.sweep_angvel*i;if(s.rot+=r,r*r>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,u=(p*s.axisx+r*s.axisy)*c;s.axisy=(p*s.axisy-r*s.axisx)*c,s.axisx=u}}}if(s.disableCCD)s.sweepFrozen=!0,s.bullet=!1;else{let o=I._nape.Config.staticCCDLinearThreshold*s.sweepRadius,r=I._nape.Config.staticCCDAngularThreshold;if((s.velx*s.velx+s.vely*s.vely)*e*e>o*o||s.angvel*s.angvel*e*e>r*r||s.type==3){let a=s.sweep_angvel;a<0&&(a=-a);let p=1/a,c=s.shapes.head;for(;c!=null;){let u=c.elt,h=u.aabb,x=h.minx,b=h.miny,_=h.maxx,d=h.maxy,f=a*e*u.sweepCoef*.008333333333333333|0;f>8&&(f=8);let m=a*e/f,z=e-s.sweepTime;if(z!=0){s.sweepTime=e;let w=z;if(s.posx+=s.velx*w,s.posy+=s.vely*w,s.angvel!=0){let v=s.sweep_angvel*z;if(s.rot+=v,v*v>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let P=v*v,g=1-.5*P,k=1-P*P/8,N=(g*s.axisx+v*s.axisy)*k;s.axisy=(g*s.axisy-v*s.axisx)*k,s.axisx=N}}}if(u.type==0){let w=u.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else{let w=u.polygon,v=w.lverts.next,P=w.gverts.next,g=v;v=v.next,P.x=w.body.posx+(w.body.axisy*g.x-w.body.axisx*g.y),P.y=w.body.posy+(g.x*w.body.axisx+g.y*w.body.axisy),w.aabb.minx=P.x,w.aabb.miny=P.y,w.aabb.maxx=P.x,w.aabb.maxy=P.y;let k=w.gverts.next.next;for(;k!=null;){let N=k,E=v;v=v.next,N.x=w.body.posx+(w.body.axisy*E.x-w.body.axisx*E.y),N.y=w.body.posy+(E.x*w.body.axisx+E.y*w.body.axisy),N.x<w.aabb.minx&&(w.aabb.minx=N.x),N.x>w.aabb.maxx&&(w.aabb.maxx=N.x),N.y<w.aabb.miny&&(w.aabb.miny=N.y),N.y>w.aabb.maxy&&(w.aabb.maxy=N.y),k=k.next}}x<h.minx?h.minx=x:x=h.minx,b<h.miny?h.miny=b:b=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy;let Z=1,y=f;for(;Z<y;){let w=Z++,v=m*w*p,P=v-s.sweepTime;if(P!=0){s.sweepTime=v;let g=P;if(s.posx+=s.velx*g,s.posy+=s.vely*g,s.angvel!=0){let k=s.sweep_angvel*P;if(s.rot+=k,k*k>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let N=k*k,E=1-.5*N,M=1-N*N/8,C=(E*s.axisx+k*s.axisy)*M;s.axisy=(E*s.axisy-k*s.axisx)*M,s.axisx=C}}}if(u.type==0){let g=u.circle;g.worldCOMx=g.body.posx+(g.body.axisy*g.localCOMx-g.body.axisx*g.localCOMy),g.worldCOMy=g.body.posy+(g.localCOMx*g.body.axisx+g.localCOMy*g.body.axisy),g.aabb.minx=g.worldCOMx-g.radius,g.aabb.miny=g.worldCOMy-g.radius,g.aabb.maxx=g.worldCOMx+g.radius,g.aabb.maxy=g.worldCOMy+g.radius}else{let g=u.polygon,k=g.lverts.next,N=g.gverts.next,E=k;k=k.next,N.x=g.body.posx+(g.body.axisy*E.x-g.body.axisx*E.y),N.y=g.body.posy+(E.x*g.body.axisx+E.y*g.body.axisy),g.aabb.minx=N.x,g.aabb.miny=N.y,g.aabb.maxx=N.x,g.aabb.maxy=N.y;let M=g.gverts.next.next;for(;M!=null;){let C=M,D=k;k=k.next,C.x=g.body.posx+(g.body.axisy*D.x-g.body.axisx*D.y),C.y=g.body.posy+(D.x*g.body.axisx+D.y*g.body.axisy),C.x<g.aabb.minx&&(g.aabb.minx=C.x),C.x>g.aabb.maxx&&(g.aabb.maxx=C.x),C.y<g.aabb.miny&&(g.aabb.miny=C.y),C.y>g.aabb.maxy&&(g.aabb.maxy=C.y),M=M.next}}x<h.minx?h.minx=x:x=h.minx,b<h.miny?h.miny=b:b=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy}this.bphase.sync(u),c=c.next}if(s.sweepFrozen=!1,s.type==2&&s.bulletEnabled){let u=I._nape.Config.bulletCCDLinearThreshold*s.sweepRadius,h=I._nape.Config.bulletCCDAngularThreshold;((s.velx*s.velx+s.vely*s.vely)*e*e>u*u||s.angvel*s.angvel*e*e>h*h)&&(s.bullet=!0)}}else s.sweepFrozen=!0,s.bullet=!1}l=l.next}}presteparb(e,t,n){n==null&&(n=!1);let l=this;if(!e.cleared&&e.b1.component.sleeping&&e.b2.component.sleeping)return e.sleep_stamp=this.stamp,e.sleeping=!0,!0;if(!e.cleared||e.present!=0||e.intchange){let i=!n&&e.up_stamp==this.stamp-1&&!e.cleared&&!e.intchange,o=e.fresh&&!e.cleared&&!e.intchange;if(i&&(e.endGenerated=this.stamp),o||i||e.cleared||e.intchange){let r=e.ws1,a=e.ws2,p=this.mrca1;for(;p.head!=null;){let b=p.head;p.head=b.next;let _=b;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_,p.head==null&&(p.pushmod=!0),p.modified=!0,p.length--}p.pushmod=!0;let c=this.mrca2;for(;c.head!=null;){let b=c.head;c.head=b.next;let _=b;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_,c.head==null&&(c.pushmod=!0),c.modified=!0,c.length--}if(c.pushmod=!0,r.cbSet!=null){let b=this.mrca1,_;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new I._zpp.util.ZNPNode_ZPP_Interactor:(_=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=r;let d=_;d.next=b.head,b.head=d,b.modified=!0,b.length++}if(r.body.cbSet!=null){let b=this.mrca1,_=r.body,d;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_Interactor:(d=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=_;let f=d;f.next=b.head,b.head=f,b.modified=!0,b.length++}if(a.cbSet!=null){let b=this.mrca2,_;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new I._zpp.util.ZNPNode_ZPP_Interactor:(_=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=a;let d=_;d.next=b.head,b.head=d,b.modified=!0,b.length++}if(a.body.cbSet!=null){let b=this.mrca2,_=a.body,d;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_Interactor:(d=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=_;let f=d;f.next=b.head,b.head=f,b.modified=!0,b.length++}let u=r.body.compound,h=a.body.compound;for(;u!=h;){let b=u==null?0:u.depth,_=h==null?0:h.depth;if(b<_){if(h.cbSet!=null){let d=this.mrca2,f;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?f=new I._zpp.util.ZNPNode_ZPP_Interactor:(f=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=f.next,f.next=null),f.elt=h;let m=f;m.next=d.head,d.head=m,d.modified=!0,d.length++}h=h.compound}else{if(u.cbSet!=null){let d=this.mrca1,f;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?f=new I._zpp.util.ZNPNode_ZPP_Interactor:(f=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=f.next,f.next=null),f.elt=u;let m=f;m.next=d.head,d.head=m,d.modified=!0,d.length++}u=u.compound}}let x=this.mrca1.head;for(;x!=null;){let b=x.elt,_=this.mrca2.head;for(;_!=null;){let d=_.elt,f=b.cbSet,m=d.cbSet,z=f.manager,Z=null,w=(f.cbpairs.length<m.cbpairs.length?f.cbpairs:m.cbpairs).head;for(;w!=null;){let P=w.elt;if(P.a==f&&P.b==m||P.a==m&&P.b==f){Z=P;break}w=w.next}if(Z==null){let P;Ne.zpp_pool==null?P=new Ne:(P=Ne.zpp_pool,Ne.zpp_pool=P.next,P.next=null),P.zip_listeners=!0,zt.setlt(f,m)?(P.a=f,P.b=m):(P.a=m,P.b=f),Z=P,f.cbpairs.add(Z),m!=f&&m.cbpairs.add(Z)}if(Z.zip_listeners&&(Z.zip_listeners=!1,Z.__validate()),Z.listeners.head==null){_=_.next;continue}let v=I._zpp.phys.ZPP_Interactor.get(b,d);if(o||e.intchange){v==null&&(v=Yt.get(b,d),this.add_callbackset(v));let P=f.manager,g=null,N=(f.cbpairs.length<m.cbpairs.length?f.cbpairs:m.cbpairs).head;for(;N!=null;){let O=N.elt;if(O.a==f&&O.b==m||O.a==m&&O.b==f){g=O;break}N=N.next}if(g==null){let O;Ne.zpp_pool==null?O=new Ne:(O=Ne.zpp_pool,Ne.zpp_pool=O.next,O.next=null),O.zip_listeners=!0,zt.setlt(f,m)?(O.a=f,O.b=m):(O.a=m,O.b=f),g=O,f.cbpairs.add(g),m!=f&&m.cbpairs.add(g)}g.zip_listeners&&(g.zip_listeners=!1,g.__validate());let E=g.listeners.head;for(;E!=null;){let O=E.elt;if(O.event==0&&(O.itype&e.type)!=0&&v.empty_arb(O.itype)){let j=l.push_callback(O);j.event=0;let L=v.int1,U=v.int2,q,R=O.options1,B=L.cbTypes;if(R.nonemptyintersection(B,R.includes)&&!R.nonemptyintersection(B,R.excludes)){let S=O.options2,J=U.cbTypes;q=S.nonemptyintersection(J,S.includes)&&!S.nonemptyintersection(J,S.excludes)}else q=!1;q?(j.int1=L,j.int2=U):(j.int1=U,j.int2=L),j.set=v}E=E.next}let M,C;C=!1;let D=v.arbiters.head;for(;D!=null;){if(D.elt==e){C=!0;break}D=D.next}if(C)M=!1;else{let O=v.arbiters,j;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?j=new I._zpp.util.ZNPNode_ZPP_Arbiter:(j=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=j.next,j.next=null),j.elt=e;let L=j;L.next=O.head,O.head=L,O.modified=!0,O.length++,M=!0}M&&e.present++}else{e.present--,v.remove_arb(e);let P=f.manager,g=null,N=(f.cbpairs.length<m.cbpairs.length?f.cbpairs:m.cbpairs).head;for(;N!=null;){let M=N.elt;if(M.a==f&&M.b==m||M.a==m&&M.b==f){g=M;break}N=N.next}if(g==null){let M;Ne.zpp_pool==null?M=new Ne:(M=Ne.zpp_pool,Ne.zpp_pool=M.next,M.next=null),M.zip_listeners=!0,zt.setlt(f,m)?(M.a=f,M.b=m):(M.a=m,M.b=f),g=M,f.cbpairs.add(g),m!=f&&m.cbpairs.add(g)}g.zip_listeners&&(g.zip_listeners=!1,g.__validate());let E=g.listeners.head;for(;E!=null;){let M=E.elt;if(M.event==1&&(M.itype&e.type)!=0&&v.empty_arb(M.itype)){let C=l.push_callback(M);C.event=1;let D=v.int1,O=v.int2,j,L=M.options1,U=D.cbTypes;if(L.nonemptyintersection(U,L.includes)&&!L.nonemptyintersection(U,L.excludes)){let q=M.options2,R=O.cbTypes;j=q.nonemptyintersection(R,q.includes)&&!q.nonemptyintersection(R,q.excludes)}else j=!1;j?(C.int1=D,C.int2=O):(C.int1=O,C.int2=D),C.set=v}E=E.next}v.arbiters.head==null&&this.remove_callbackset(v)}_=_.next}x=x.next}}e.fresh=!1,e.intchange=!1}if(e.cleared||e.up_stamp+(e.type==Ae.COL?I._nape.Config.arbiterExpirationDelay:0)<this.stamp){if(e.type==Ae.SENSOR){let i=e.sensorarb;if(!i.cleared){let r=i.b1.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==i){let _,d;a==null?(_=r.head,d=_.next,r.head=d,r.head==null&&(r.pushmod=!0)):(_=a.next,d=_.next,a.next=d,d==null&&(r.pushmod=!0));let f=_;f.elt=null,f.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}let u=i.b2.arbiters,h=null,x=u.head,b=!1;for(;x!=null;){if(x.elt==i){let _,d;h==null?(_=u.head,d=_.next,u.head=d,u.head==null&&(u.pushmod=!0)):(_=h.next,d=_.next,h.next=d,d==null&&(u.pushmod=!0));let f=_;f.elt=null,f.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,u.modified=!0,u.length--,u.pushmod=!0,b=!0;break}h=x,x=x.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let o=i;o.next=jt.zpp_pool,jt.zpp_pool=o}else if(e.type==Ae.FLUID){let i=e.fluidarb;if(!i.cleared){let r=i.b1.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==i){let _,d;a==null?(_=r.head,d=_.next,r.head=d,r.head==null&&(r.pushmod=!0)):(_=a.next,d=_.next,a.next=d,d==null&&(r.pushmod=!0));let f=_;f.elt=null,f.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}let u=i.b2.arbiters,h=null,x=u.head,b=!1;for(;x!=null;){if(x.elt==i){let _,d;h==null?(_=u.head,d=_.next,u.head=d,u.head==null&&(u.pushmod=!0)):(_=h.next,d=_.next,h.next=d,d==null&&(u.pushmod=!0));let f=_;f.elt=null,f.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,u.modified=!0,u.length--,u.pushmod=!0,b=!0;break}h=x,x=x.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let o=i;o.next=Ct.zpp_pool,Ct.zpp_pool=o,i.pre_dt=-1}else{let i=e.colarb;if(!i.cleared){let r=i.b1.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==i){let _,d;a==null?(_=r.head,d=_.next,r.head=d,r.head==null&&(r.pushmod=!0)):(_=a.next,d=_.next,a.next=d,d==null&&(r.pushmod=!0));let f=_;f.elt=null,f.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}let u=i.b2.arbiters,h=null,x=u.head,b=!1;for(;x!=null;){if(x.elt==i){let _,d;h==null?(_=u.head,d=_.next,u.head=d,u.head==null&&(u.pushmod=!0)):(_=h.next,d=_.next,h.next=d,d==null&&(u.pushmod=!0));let f=_;f.elt=null,f.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,u.modified=!0,u.length--,u.pushmod=!0,b=!0;break}h=x,x=x.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}for(i.b1=i.b2=null,i.active=!1,i.intchange=!1;i.contacts.next!=null;){let r=i.contacts,a=r.next;r.pop();let p=a;p.arbiter=null,p.next=we.zpp_pool,we.zpp_pool=p;let c=i.innards,u=c.next;c.next=u.next,u._inuse=!1,c.next==null&&(c.pushmod=!0),c.modified=!0,c.length--}let o=i;o.userdef_dyn_fric=!1,o.userdef_stat_fric=!1,o.userdef_restitution=!1,o.userdef_rfric=!1,o.__ref_edge1=o.__ref_edge2=null,o.next=xt.zpp_pool,xt.zpp_pool=o,i.pre_dt=-1}return!0}let s=e.active;if(e.active=e.presentable=e.up_stamp==this.stamp,(e.immState&1)!=0){if(e.active&&e.type!=Ae.SENSOR)if(e.colarb!=null){let i=e.colarb;i.invalidated&&(i.invalidated=!1,i.userdef_restitution||(i.s1.material.elasticity<=-1/0||i.s2.material.elasticity<=-1/0?i.restitution=0:i.s1.material.elasticity>=1/0||i.s2.material.elasticity>=1/0?i.restitution=1:i.restitution=(i.s1.material.elasticity+i.s2.material.elasticity)/2,i.restitution<0&&(i.restitution=0),i.restitution>1&&(i.restitution=1)),i.userdef_dyn_fric||(i.dyn_fric=Math.sqrt(i.s1.material.dynamicFriction*i.s2.material.dynamicFriction)),i.userdef_stat_fric||(i.stat_fric=Math.sqrt(i.s1.material.staticFriction*i.s2.material.staticFriction)),i.userdef_rfric||(i.rfric=Math.sqrt(i.s1.material.rollingFriction*i.s2.material.rollingFriction))),i.pre_dt==-1&&(i.pre_dt=t);let o=t/i.pre_dt;i.pre_dt=t;let r=i.b1.smass+i.b2.smass;i.hc2=!1;let a=!0,c=i.b1.type!=2||i.b2.type!=2?i.continuous?I._nape.Config.contactContinuousStaticBiasCoef:I._nape.Config.contactStaticBiasCoef:i.continuous?I._nape.Config.contactContinuousBiasCoef:I._nape.Config.contactBiasCoef;i.biasCoef=c,i.continuous=!1;let u=null,h=null,x=i.innards.next,b=i.contacts.next;for(;b!=null;){let d=b;if(d.stamp+I._nape.Config.arbiterExpirationDelay<i.stamp){let z=i.contacts,Z,y;u==null?(Z=z.next,y=Z.next,z.next=y,z.next==null&&(z.pushmod=!0)):(Z=u.next,y=Z.next,u.next=y,y==null&&(z.pushmod=!0)),Z._inuse=!1,z.modified=!0,z.length--,z.pushmod=!0,b=y;let w=i.innards,v,P;h==null?(v=w.next,P=v.next,w.next=P,w.next==null&&(w.pushmod=!0)):(v=h.next,P=v.next,h.next=P,P==null&&(w.pushmod=!0)),v._inuse=!1,w.modified=!0,w.length--,w.pushmod=!0,x=P;let g=d;g.arbiter=null,g.next=we.zpp_pool,we.zpp_pool=g;continue}let f=d.inner,m=d.active;if(d.active=d.stamp==i.stamp,d.active){a?(a=!1,i.c1=f,i.oc1=d):(i.hc2=!0,i.c2=f,i.oc2=d),f.r2x=d.px-i.b2.posx,f.r2y=d.py-i.b2.posy,f.r1x=d.px-i.b1.posx,f.r1y=d.py-i.b1.posy;let z=f.r2x*i.nx+f.r2y*i.ny,Z=r+i.b2.sinertia*(z*z),y=f.r1x*i.nx+f.r1y*i.ny;Z+=i.b1.sinertia*(y*y),f.tMass=Z<I._nape.Config.epsilon*I._nape.Config.epsilon?0:1/Z;let w=i.ny*f.r2x-i.nx*f.r2y,v=r+i.b2.sinertia*(w*w),P=i.ny*f.r1x-i.nx*f.r1y;v+=i.b1.sinertia*(P*P),f.nMass=v<I._nape.Config.epsilon*I._nape.Config.epsilon?0:1/v;let g=0,k=0,N=i.b2.angvel+i.b2.kinangvel;g=i.b2.velx+i.b2.kinvelx-f.r2y*N,k=i.b2.vely+i.b2.kinvely+f.r2x*N,N=i.b1.angvel+i.b1.kinangvel,g-=i.b1.velx+i.b1.kinvelx-f.r1y*N,k-=i.b1.vely+i.b1.kinvely+f.r1x*N;let E=i.nx*g+i.ny*k;d.elasticity=i.restitution,f.bounce=E*d.elasticity,f.bounce>-I._nape.Config.elasticThreshold&&(f.bounce=0),E=k*i.nx-g*i.ny;let M=I._nape.Config.staticFrictionThreshold;E*E>M*M?f.friction=i.dyn_fric:f.friction=i.stat_fric,f.jnAcc*=o,f.jtAcc*=o}m!=d.active&&(i.contacts.modified=!0),u=b,h=x,x=x.next,b=b.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let d=i.c1;i.c1=i.c2,i.c2=d;let f=i.oc1;i.oc1=i.oc2,i.oc2=f,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(a=!0)}else i.hpc2=!1;if(i.jrAcc*=o,a||(i.rn1a=i.ny*i.c1.r1x-i.nx*i.c1.r1y,i.rt1a=i.c1.r1x*i.nx+i.c1.r1y*i.ny,i.rn1b=i.ny*i.c1.r2x-i.nx*i.c1.r2y,i.rt1b=i.c1.r2x*i.nx+i.c1.r2y*i.ny,i.k1x=i.b2.kinvelx-i.c1.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c1.r1y*i.b1.kinangvel),i.k1y=i.b2.kinvely+i.c1.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c1.r1x*i.b1.kinangvel)),i.hc2)if(i.rn2a=i.ny*i.c2.r1x-i.nx*i.c2.r1y,i.rt2a=i.c2.r1x*i.nx+i.c2.r1y*i.ny,i.rn2b=i.ny*i.c2.r2x-i.nx*i.c2.r2y,i.rt2b=i.c2.r2x*i.nx+i.c2.r2y*i.ny,i.k2x=i.b2.kinvelx-i.c2.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c2.r1y*i.b1.kinangvel),i.k2y=i.b2.kinvely+i.c2.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c2.r1x*i.b1.kinangvel),i.kMassa=r+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=r+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=r+i.b1.sinertia*i.rn2a*i.rn2a+i.b2.sinertia*i.rn2b*i.rn2b,i.kMassa*i.kMassa+2*i.kMassb*i.kMassb+i.kMassc*i.kMassc<I._nape.Config.illConditionedThreshold*(i.kMassa*i.kMassc-i.kMassb*i.kMassb)){i.Ka=i.kMassa,i.Kb=i.kMassb,i.Kc=i.kMassc;let f=i.kMassa*i.kMassc-i.kMassb*i.kMassb;if(f!=f)i.kMassa=i.kMassb=i.kMassc=0;else if(f==0){let m=0;i.kMassa!=0?i.kMassa=1/i.kMassa:(i.kMassa=0,m|=1),i.kMassc!=0?i.kMassc=1/i.kMassc:(i.kMassc=0,m|=2),i.kMassb=0}else{f=1/f;let m=i.kMassc*f;i.kMassc=i.kMassa*f,i.kMassa=m,i.kMassb*=-f}}else{if(i.hc2=!1,i.oc2.dist<i.oc1.dist){let f=i.c1;i.c1=i.c2,i.c2=f}i.oc2.active=!1,i.contacts.modified=!0}i.surfacex=i.b2.svelx,i.surfacey=i.b2.svely;let _=1;i.surfacex+=i.b1.svelx*_,i.surfacey+=i.b1.svely*_,i.surfacex=-i.surfacex,i.surfacey=-i.surfacey,i.rMass=i.b1.sinertia+i.b2.sinertia,i.rMass!=0&&(i.rMass=1/i.rMass),a&&(e.active=!1)}else{let i=e.fluidarb;i.pre_dt==-1&&(i.pre_dt=t);let o=t/i.pre_dt;i.pre_dt=t,i.r1x=i.centroidx-i.b1.posx,i.r1y=i.centroidy-i.b1.posy,i.r2x=i.centroidx-i.b2.posx,i.r2y=i.centroidy-i.b2.posy;let r=0,a=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(r=i.ws1.fluidProperties.gravityx,a=i.ws1.fluidProperties.gravityy):(r=this.gravityx,a=this.gravityy);let p=0,c=0;i.ws2.fluidEnabled&&i.ws2.fluidProperties.wrap_gravity!=null?(p=i.ws2.fluidProperties.gravityx,c=i.ws2.fluidProperties.gravityy):(p=this.gravityx,c=this.gravityy);let u=0,h=0;if(i.ws1.fluidEnabled&&i.ws2.fluidEnabled){let _=i.overlap*i.ws1.fluidProperties.density,d=i.overlap*i.ws2.fluidProperties.density;if(_>d){let f=_+d;u-=r*f,h-=a*f}else if(_<d){let f=_+d;u+=p*f,h+=c*f}else{let f=0,m=0;f=r+p,m=a+c;let z=.5;if(f*=z,m*=z,i.ws1.worldCOMx*f+i.ws1.worldCOMy*m>i.ws2.worldCOMx*f+i.ws2.worldCOMy*m){let Z=_+d;u-=f*Z,h-=m*Z}else{let Z=_+d;u+=f*Z,h+=m*Z}}}else if(i.ws1.fluidEnabled){let d=i.overlap*i.ws1.fluidProperties.density;u-=r*d,h-=a*d}else if(i.ws2.fluidEnabled){let d=i.overlap*i.ws2.fluidProperties.density;u+=p*d,h+=c*d}let x=t;if(u*=x,h*=x,i.buoyx=u,i.buoyy=h,i.b1.type==2){let _=i.b1.imass;i.b1.velx-=u*_,i.b1.vely-=h*_,i.b1.angvel-=(h*i.r1x-u*i.r1y)*i.b1.iinertia}if(i.b2.type==2){let _=i.b2.imass;i.b2.velx+=u*_,i.b2.vely+=h*_,i.b2.angvel+=(h*i.r2x-u*i.r2y)*i.b2.iinertia}if((!i.ws1.fluidEnabled||i.ws1.fluidProperties.viscosity==0)&&(!i.ws2.fluidEnabled||i.ws2.fluidProperties.viscosity==0))i.nodrag=!0,i.dampx=0,i.dampy=0,i.adamp=0;else{i.nodrag=!1;let _=0;if(i.ws1.fluidEnabled&&(i.ws2.validate_angDrag(),_+=i.ws1.fluidProperties.viscosity*i.ws2.angDrag*i.overlap/i.ws2.area),i.ws2.fluidEnabled&&(i.ws1.validate_angDrag(),_+=i.ws2.fluidProperties.viscosity*i.ws1.angDrag*i.overlap/i.ws1.area),_!=0){let z=i.b1.sinertia+i.b2.sinertia;z!=0?i.wMass=1/z:i.wMass=0,_*=4e-4;let Z=2*Math.PI*_;i.agamma=1/(t*Z*(2+Z*t));let y=1/(1+i.agamma),w=t*Z*Z*i.agamma;i.agamma*=y,i.wMass*=y}else i.wMass=0,i.agamma=0;let d=i.b2.velx+i.b2.kinvelx-i.r2y*(i.b2.angvel+i.b2.kinangvel)-(i.b1.velx+i.b1.kinvelx-i.r1y*(i.b2.angvel+i.b2.kinangvel)),f=i.b2.vely+i.b2.kinvely+i.r2x*(i.b2.angvel+i.b2.kinangvel)-(i.b1.vely+i.b1.kinvely+i.r1x*(i.b1.angvel+i.b1.kinangvel));if(!(d*d+f*f<I._nape.Config.epsilon*I._nape.Config.epsilon)){let z=d*d+f*f,y=1/Math.sqrt(z);d*=y,f*=y,i.nx=d,i.ny=f}let m=0;if(i.ws1.fluidEnabled){let z=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)m-=z*i.ws2.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else{let Z=i.ws2.polygon,y=0,w=0,v=Z.edges.head;for(;v!=null;){let P=v.elt;y+=P.length;let g=z*P.length*(P.gnormx*i.nx+P.gnormy*i.ny);g>0&&(g*=-I._nape.Config.fluidVacuumDrag,g=g),w-=g*.5*I._nape.Config.fluidLinearDrag,v=v.next}m+=w/y}}if(i.ws2.fluidEnabled){let z=-i.ws2.fluidProperties.viscosity*i.overlap/i.ws1.area;if(i.ws1.type==0)m-=z*i.ws1.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else{let Z=i.ws1.polygon,y=0,w=0,v=Z.edges.head;for(;v!=null;){let P=v.elt;y+=P.length;let g=z*P.length*(P.gnormx*i.nx+P.gnormy*i.ny);g>0&&(g*=-I._nape.Config.fluidVacuumDrag,g=g),w-=g*.5*I._nape.Config.fluidLinearDrag,v=v.next}m+=w/y}}if(m!=0){let z=i.b1.smass+i.b2.smass,Z=0,y=0,w=0;if(Z=z,y=0,w=z,i.b1.sinertia!=0){let E=i.r1x*i.b1.sinertia,M=i.r1y*i.b1.sinertia;Z+=M*i.r1y,y+=-M*i.r1x,w+=E*i.r1x}if(i.b2.sinertia!=0){let E=i.r2x*i.b2.sinertia,M=i.r2y*i.b2.sinertia;Z+=M*i.r2y,y+=-M*i.r2x,w+=E*i.r2x}let v=Z*w-y*y;if(v!=v)w=0,y=w,Z=y;else if(v==0){let E=0;Z!=0?Z=1/Z:(Z=0,E|=1),w!=0?w=1/w:(w=0,E|=2),y=0}else{v=1/v;let E=w*v;w=Z*v,Z=E,y*=-v}i.vMassa=Z,i.vMassb=y,i.vMassc=w;let P,g=2*Math.PI*m;i.lgamma=1/(t*g*(2+g*t));let k=1/(1+i.lgamma);P=t*g*g*i.lgamma,i.lgamma*=k;let N=k;i.vMassa*=N,i.vMassb*=N,i.vMassc*=N}else i.vMassa=0,i.vMassb=0,i.vMassc=0,i.lgamma=0}let b=o;i.dampx*=b,i.dampy*=b,i.adamp*=o}}else if(e.colarb!=null){let i=e.colarb,o=!0,r=null,a=null,p=i.innards.next;i.hc2=!1;let c=i.contacts.next;for(;c!=null;){let u=c;if(u.stamp+I._nape.Config.arbiterExpirationDelay<i.stamp){let b=i.contacts,_,d;r==null?(_=b.next,d=_.next,b.next=d,b.next==null&&(b.pushmod=!0)):(_=r.next,d=_.next,r.next=d,d==null&&(b.pushmod=!0)),_._inuse=!1,b.modified=!0,b.length--,b.pushmod=!0,c=d;let f=i.innards,m,z;a==null?(m=f.next,z=m.next,f.next=z,f.next==null&&(f.pushmod=!0)):(m=a.next,z=m.next,a.next=z,z==null&&(f.pushmod=!0)),m._inuse=!1,f.modified=!0,f.length--,f.pushmod=!0,p=z;let Z=u;Z.arbiter=null,Z.next=we.zpp_pool,we.zpp_pool=Z;continue}let h=u.inner,x=u.active;u.active=u.stamp==i.stamp,u.active&&(o?(o=!1,i.c1=h,i.oc1=u):(i.hc2=!0,i.c2=h,i.oc2=u)),x!=u.active&&(i.contacts.modified=!0),r=c,a=p,p=p.next,c=c.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let u=i.c1;i.c1=i.c2,i.c2=u;let h=i.oc1;i.oc1=i.oc2,i.oc2=h,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(o=!0)}else i.hpc2=!1;o&&(e.active=!1)}return s!=e.active&&(e.b1.arbiters.modified=!0,e.b2.arbiters.modified=!0,this.c_arbiters_true.modified=this.c_arbiters_false.modified=!0,this.s_arbiters.modified=this.f_arbiters.modified=!0),!1}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let _=n.elt;if(_.preStep(e)){n=this.live_constraints.erase(t),_.broken(),this.constraintCbBreak(_),_.removeOnBreak?(_.component.sleeping=!0,this.midstep=!1,_.compound!=null?_.compound.wrap_constraints.remove(_.outer):this.wrap_constraints.remove(_.outer),this.midstep=!0):_.active=!1,_.clearcache();continue}t=n,n=n.next}let l=null,s=this.c_arbiters_true,i=s.head,o=this.c_arbiters_false!=null;for(o&&i==null&&(o=!1,i=this.c_arbiters_false.head,s=this.c_arbiters_false,l=null);i!=null;){let _=i.elt;if(this.presteparb(_,e)){let d,f;l==null?(d=s.head,f=d.next,s.head=f,s.head==null&&(s.pushmod=!0)):(d=l.next,f=d.next,l.next=f,f==null&&(s.pushmod=!0));let m=d;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=m,s.modified=!0,s.length--,s.pushmod=!0,i=f,o&&i==null&&(o=!1,i=this.c_arbiters_false.head,s=this.c_arbiters_false,l=null);continue}l=i,i=i.next,o&&i==null&&(o=!1,i=this.c_arbiters_false.head,s=this.c_arbiters_false,l=null)}let r=null,a=this.f_arbiters,p=a.head,c=!1;for(c&&p==null&&(c=!1,a=null,r=null);p!=null;){let _=p.elt;if(this.presteparb(_,e)){let d,f;r==null?(d=a.head,f=d.next,a.head=f,a.head==null&&(a.pushmod=!0)):(d=r.next,f=d.next,r.next=f,f==null&&(a.pushmod=!0));let m=d;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=m,a.modified=!0,a.length--,a.pushmod=!0,p=f,c&&p==null&&(c=!1,a=null,r=null);continue}r=p,p=p.next,c&&p==null&&(c=!1,a=null,r=null)}let u=null,h=this.s_arbiters,x=h.head,b=!1;for(b&&x==null&&(b=!1,h=null,u=null);x!=null;){let _=x.elt;if(this.presteparb(_,e)){let d,f;u==null?(d=h.head,f=d.next,h.head=f,h.head==null&&(h.pushmod=!0)):(d=u.next,f=d.next,u.next=f,f==null&&(h.pushmod=!0));let m=d;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=m,h.modified=!0,h.length--,h.pushmod=!0,x=f,b&&x==null&&(b=!1,h=null,u=null);continue}u=x,x=x.next,b&&x==null&&(b=!1,h=null,u=null)}}warmStart(){let e=this.f_arbiters.head;for(;e!=null;){let s=e.elt;if(s.active&&(s.immState&1)!=0){let i=s.b1.imass;s.b1.velx-=s.dampx*i,s.b1.vely-=s.dampy*i;let o=s.b2.imass;s.b2.velx+=s.dampx*o,s.b2.vely+=s.dampy*o,s.b1.angvel-=s.b1.iinertia*(s.dampy*s.r1x-s.dampx*s.r1y),s.b2.angvel+=s.b2.iinertia*(s.dampy*s.r2x-s.dampx*s.r2y),s.b1.angvel-=s.adamp*s.b1.iinertia,s.b2.angvel+=s.adamp*s.b2.iinertia}e=e.next}let t=this.c_arbiters_false.head,n=!0;for(t==null&&(t=this.c_arbiters_true.head,n=!1);t!=null;){let s=t.elt;if(s.active&&(s.immState&1)!=0){let i=s.nx*s.c1.jnAcc-s.ny*s.c1.jtAcc,o=s.ny*s.c1.jnAcc+s.nx*s.c1.jtAcc,r=s.b1.imass;s.b1.velx-=i*r,s.b1.vely-=o*r,s.b1.angvel-=s.b1.iinertia*(o*s.c1.r1x-i*s.c1.r1y);let a=s.b2.imass;if(s.b2.velx+=i*a,s.b2.vely+=o*a,s.b2.angvel+=s.b2.iinertia*(o*s.c1.r2x-i*s.c1.r2y),s.hc2){let p=s.nx*s.c2.jnAcc-s.ny*s.c2.jtAcc,c=s.ny*s.c2.jnAcc+s.nx*s.c2.jtAcc,u=s.b1.imass;s.b1.velx-=p*u,s.b1.vely-=c*u,s.b1.angvel-=s.b1.iinertia*(c*s.c2.r1x-p*s.c2.r1y);let h=s.b2.imass;s.b2.velx+=p*h,s.b2.vely+=c*h,s.b2.angvel+=s.b2.iinertia*(c*s.c2.r2x-p*s.c2.r2y)}s.b2.angvel+=s.jrAcc*s.b2.iinertia,s.b1.angvel-=s.jrAcc*s.b1.iinertia}t=t.next,n&&t==null&&(t=this.c_arbiters_true.head,n=!1)}let l=this.live_constraints.head;for(;l!=null;)l.elt.warmStart(),l=l.next}iterateVel(e){let t=0,n=e;for(;t<n;){let l=t++,s=this.f_arbiters.head;for(;s!=null;){let p=s.elt;if(p.active&&(p.immState&1)!=0&&!p.nodrag){let c=p.b1.angvel+p.b1.kinangvel,u=p.b2.angvel+p.b2.kinangvel,h=p.b1.velx+p.b1.kinvelx-p.r1y*c-(p.b2.velx+p.b2.kinvelx-p.r2y*u),x=p.b1.vely+p.b1.kinvely+p.r1x*c-(p.b2.vely+p.b2.kinvely+p.r2x*u),b=p.vMassa*h+p.vMassb*x;x=p.vMassb*h+p.vMassc*x,h=b;let _=p.lgamma;h-=p.dampx*_,x-=p.dampy*_;let d=1;p.dampx+=h*d,p.dampy+=x*d;let f=p.b1.imass;p.b1.velx-=h*f,p.b1.vely-=x*f;let m=p.b2.imass;p.b2.velx+=h*m,p.b2.vely+=x*m,p.b1.angvel-=p.b1.iinertia*(x*p.r1x-h*p.r1y),p.b2.angvel+=p.b2.iinertia*(x*p.r2x-h*p.r2y);let z=(c-u)*p.wMass-p.adamp*p.agamma;p.adamp+=z,p.b1.angvel-=z*p.b1.iinertia,p.b2.angvel+=z*p.b2.iinertia}s=s.next}let i=null,o=this.live_constraints.head;for(;o!=null;){let p=o.elt;if(p.applyImpulseVel()){o=this.live_constraints.erase(i),p.broken(),this.constraintCbBreak(p),p.removeOnBreak?(p.component.sleeping=!0,this.midstep=!1,p.compound!=null?p.compound.wrap_constraints.remove(p.outer):this.wrap_constraints.remove(p.outer),this.midstep=!0):p.active=!1,p.clearcache();continue}i=o,o=o.next}let r=this.c_arbiters_false.head,a=!0;for(r==null&&(r=this.c_arbiters_true.head,a=!1);r!=null;){let p=r.elt;if(p.active&&(p.immState&1)!=0){let c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),u=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),h=(u*p.nx-c*p.ny+p.surfacex)*p.c1.tMass,x=p.c1.friction*p.c1.jnAcc,b=p.c1.jtAcc,_=b-h;_>x?_=x:_<-x&&(_=-x),h=_-b,p.c1.jtAcc=_;let d=-p.ny*h,f=p.nx*h;if(p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rt1b*h*p.b2.iinertia,p.b1.angvel-=p.rt1a*h*p.b1.iinertia,p.hc2){let m=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),z=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);h=(z*p.nx-m*p.ny+p.surfacex)*p.c2.tMass,x=p.c2.friction*p.c2.jnAcc,b=p.c2.jtAcc,_=b-h,_>x?_=x:_<-x&&(_=-x),h=_-b,p.c2.jtAcc=_,d=-p.ny*h,f=p.nx*h,p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rt2b*h*p.b2.iinertia,p.b1.angvel-=p.rt2a*h*p.b1.iinertia,c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),u=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),m=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),z=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);let Z=p.c1.jnAcc,y=p.c2.jnAcc,w=c*p.nx+u*p.ny+p.surfacey+p.c1.bounce-(p.Ka*Z+p.Kb*y),v=m*p.nx+z*p.ny+p.surfacey+p.c2.bounce-(p.Kb*Z+p.Kc*y),P=-(p.kMassa*w+p.kMassb*v),g=-(p.kMassb*w+p.kMassc*v);P>=0&&g>=0?(w=P-Z,v=g-y,p.c1.jnAcc=P,p.c2.jnAcc=g):(P=-p.c1.nMass*w,P>=0&&p.Kb*P+v>=0?(w=P-Z,v=-y,p.c1.jnAcc=P,p.c2.jnAcc=0):(g=-p.c2.nMass*v,g>=0&&p.Kb*g+w>=0?(w=-Z,v=g-y,p.c1.jnAcc=0,p.c2.jnAcc=g):w>=0&&v>=0?(w=-Z,v=-y,p.c1.jnAcc=p.c2.jnAcc=0):(w=0,v=0))),h=w+v,d=p.nx*h,f=p.ny*h,p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=(p.rn1b*w+p.rn2b*v)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*w+p.rn2a*v)*p.b1.iinertia}else p.radius!=0&&(h=(p.b2.angvel-p.b1.angvel)*p.rMass,x=p.rfric*p.c1.jnAcc,b=p.jrAcc,p.jrAcc-=h,p.jrAcc>x?p.jrAcc=x:p.jrAcc<-x&&(p.jrAcc=-x),h=p.jrAcc-b,p.b2.angvel+=h*p.b2.iinertia,p.b1.angvel-=h*p.b1.iinertia),c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),u=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),h=(p.c1.bounce+(p.nx*c+p.ny*u)+p.surfacey)*p.c1.nMass,b=p.c1.jnAcc,_=b-h,_<0&&(_=0),h=_-b,p.c1.jnAcc=_,d=p.nx*h,f=p.ny*h,p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rn1b*h*p.b2.iinertia,p.b1.angvel-=p.rn1a*h*p.b1.iinertia}r=r.next,a&&r==null&&(r=this.c_arbiters_true.head,a=!1)}}}iteratePos(e){let t=0,n=e;for(;t<n;){let l=t++,s=null,i=this.live_constraints.head;for(;i!=null;){let a=i.elt;if(!a.__velocity&&a.stiff&&a.applyImpulsePos()){i=this.live_constraints.erase(s),a.broken(),this.constraintCbBreak(a),a.removeOnBreak?(a.component.sleeping=!0,this.midstep=!1,a.compound!=null?a.compound.wrap_constraints.remove(a.outer):this.wrap_constraints.remove(a.outer),this.midstep=!0):a.active=!1,a.clearcache();continue}s=i,i=i.next}let o=this.c_arbiters_false.head,r=!0;for(o==null&&(o=this.c_arbiters_true.head,r=!1);o!=null;){let a=o.elt;if(a.active&&(a.immState&1)!=0)if(a.ptype==2){let p=a.c1,c=0,u=0;c=a.b2.axisy*p.lr2x-a.b2.axisx*p.lr2y,u=p.lr2x*a.b2.axisx+p.lr2y*a.b2.axisy;let h=1;c+=a.b2.posx*h,u+=a.b2.posy*h;let x=0,b=0;x=a.b1.axisy*p.lr1x-a.b1.axisx*p.lr1y,b=p.lr1x*a.b1.axisx+p.lr1y*a.b1.axisy;let _=1;x+=a.b1.posx*_,b+=a.b1.posy*_;let d=0,f=0;d=c-x,f=u-b;let m=Math.sqrt(d*d+f*f),z=a.radius-I._nape.Config.collisionSlop,Z=m-z;if(d*a.nx+f*a.ny<0&&(d=-d,f=-f,Z-=a.radius),Z<0)if(m<I._nape.Config.epsilon)a.b1.smass!=0?a.b1.posx+=I._nape.Config.epsilon*10:a.b2.posx+=I._nape.Config.epsilon*10;else{let y=1/m;d*=y,f*=y;let w=.5*(x+c),v=.5*(b+u),P=m-z;x=w-a.b1.posx,b=v-a.b1.posy,c=w-a.b2.posx,u=v-a.b2.posy;let g=f*x-d*b,k=f*c-d*u,N=a.b2.smass+k*k*a.b2.sinertia+a.b1.smass+g*g*a.b1.sinertia;if(N!=0){let E=-a.biasCoef*P/N,M=0,C=0,D=E;M=d*D,C=f*D;let O=a.b1.imass;a.b1.posx-=M*O,a.b1.posy-=C*O;let j=a.b1,L=-g*a.b1.iinertia*E;if(j.rot+=L,L*L>1e-4)j.axisx=Math.sin(j.rot),j.axisy=Math.cos(j.rot);else{let B=L*L,S=1-.5*B,J=1-B*B/8,Q=(S*j.axisx+L*j.axisy)*J;j.axisy=(S*j.axisy-L*j.axisx)*J,j.axisx=Q}let U=a.b2.imass;a.b2.posx+=M*U,a.b2.posy+=C*U;let q=a.b2,R=k*a.b2.iinertia*E;if(q.rot+=R,R*R>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else{let B=R*R,S=1-.5*B,J=1-B*B/8,Q=(S*q.axisx+R*q.axisy)*J;q.axisy=(S*q.axisy-R*q.axisx)*J,q.axisx=Q}}}}else{let p=0,c=0,u,h=0,x=0,b=0,_=0;if(a.ptype==0){p=a.b1.axisy*a.lnormx-a.b1.axisx*a.lnormy,c=a.lnormx*a.b1.axisx+a.lnormy*a.b1.axisy,u=a.lproj+(p*a.b1.posx+c*a.b1.posy),h=a.b2.axisy*a.c1.lr1x-a.b2.axisx*a.c1.lr1y,x=a.c1.lr1x*a.b2.axisx+a.c1.lr1y*a.b2.axisy;let m=1;if(h+=a.b2.posx*m,x+=a.b2.posy*m,a.hpc2){b=a.b2.axisy*a.c2.lr1x-a.b2.axisx*a.c2.lr1y,_=a.c2.lr1x*a.b2.axisx+a.c2.lr1y*a.b2.axisy;let z=1;b+=a.b2.posx*z,_+=a.b2.posy*z}}else{p=a.b2.axisy*a.lnormx-a.b2.axisx*a.lnormy,c=a.lnormx*a.b2.axisx+a.lnormy*a.b2.axisy,u=a.lproj+(p*a.b2.posx+c*a.b2.posy),h=a.b1.axisy*a.c1.lr1x-a.b1.axisx*a.c1.lr1y,x=a.c1.lr1x*a.b1.axisx+a.c1.lr1y*a.b1.axisy;let m=1;if(h+=a.b1.posx*m,x+=a.b1.posy*m,a.hpc2){b=a.b1.axisy*a.c2.lr1x-a.b1.axisx*a.c2.lr1y,_=a.c2.lr1x*a.b1.axisx+a.c2.lr1y*a.b1.axisy;let z=1;b+=a.b1.posx*z,_+=a.b1.posy*z}}let d=h*p+x*c-u-a.radius;d+=I._nape.Config.collisionSlop;let f=0;if(a.hpc2&&(f=b*p+_*c-u-a.radius,f+=I._nape.Config.collisionSlop),d<0||f<0){a.rev&&(p=-p,c=-c);let m=0,z=0;m=h-a.b1.posx,z=x-a.b1.posy;let Z=0,y=0;Z=h-a.b2.posx,y=x-a.b2.posy;let w=0,v=0,P=0,g=0;if(a.hpc2){w=b-a.b1.posx,v=_-a.b1.posy,P=b-a.b2.posx,g=_-a.b2.posy;let k=c*m-p*z,N=c*Z-p*y,E=c*w-p*v,M=c*P-p*g,C=a.b1.smass+a.b2.smass;a.kMassa=C+a.b1.sinertia*k*k+a.b2.sinertia*N*N,a.kMassb=C+a.b1.sinertia*k*E+a.b2.sinertia*N*M,a.kMassc=C+a.b1.sinertia*E*E+a.b2.sinertia*M*M;let D=0,O=0,j=0;D=a.kMassa,O=a.kMassb,j=a.kMassc;let L=d*a.biasCoef,U=f*a.biasCoef;for(;;){let q=0,R=0;q=L,R=U,q=-q,R=-R;let B=a.kMassa*a.kMassc-a.kMassb*a.kMassb;if(B!=B)R=0,q=R;else if(B==0)a.kMassa!=0?q/=a.kMassa:q=0,a.kMassc!=0?R/=a.kMassc:R=0;else{B=1/B;let Q=B*(a.kMassc*q-a.kMassb*R);R=B*(a.kMassa*R-a.kMassb*q),q=Q}if(q>=0&&R>=0){let Q=(q+R)*a.b1.imass;a.b1.posx-=p*Q,a.b1.posy-=c*Q;let Y=a.b1,X=-a.b1.iinertia*(k*q+E*R);if(Y.rot+=X,X*X>1e-4)Y.axisx=Math.sin(Y.rot),Y.axisy=Math.cos(Y.rot);else{let T=X*X,A=1-.5*T,W=1-T*T/8,H=(A*Y.axisx+X*Y.axisy)*W;Y.axisy=(A*Y.axisy-X*Y.axisx)*W,Y.axisx=H}let ee=(q+R)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let G=a.b2,F=a.b2.iinertia*(N*q+M*R);if(G.rot+=F,F*F>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else{let T=F*F,A=1-.5*T,W=1-T*T/8,H=(A*G.axisx+F*G.axisy)*W;G.axisy=(A*G.axisy-F*G.axisx)*W,G.axisx=H}break}q=-L/D,R=0;let S=O*q+U;if(q>=0&&S>=0){let Q=(q+R)*a.b1.imass;a.b1.posx-=p*Q,a.b1.posy-=c*Q;let Y=a.b1,X=-a.b1.iinertia*(k*q+E*R);if(Y.rot+=X,X*X>1e-4)Y.axisx=Math.sin(Y.rot),Y.axisy=Math.cos(Y.rot);else{let T=X*X,A=1-.5*T,W=1-T*T/8,H=(A*Y.axisx+X*Y.axisy)*W;Y.axisy=(A*Y.axisy-X*Y.axisx)*W,Y.axisx=H}let ee=(q+R)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let G=a.b2,F=a.b2.iinertia*(N*q+M*R);if(G.rot+=F,F*F>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else{let T=F*F,A=1-.5*T,W=1-T*T/8,H=(A*G.axisx+F*G.axisy)*W;G.axisy=(A*G.axisy-F*G.axisx)*W,G.axisx=H}break}q=0,R=-U/j;let J=O*R+L;if(R>=0&&J>=0){let Q=(q+R)*a.b1.imass;a.b1.posx-=p*Q,a.b1.posy-=c*Q;let Y=a.b1,X=-a.b1.iinertia*(k*q+E*R);if(Y.rot+=X,X*X>1e-4)Y.axisx=Math.sin(Y.rot),Y.axisy=Math.cos(Y.rot);else{let T=X*X,A=1-.5*T,W=1-T*T/8,H=(A*Y.axisx+X*Y.axisy)*W;Y.axisy=(A*Y.axisy-X*Y.axisx)*W,Y.axisx=H}let ee=(q+R)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let G=a.b2,F=a.b2.iinertia*(N*q+M*R);if(G.rot+=F,F*F>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else{let T=F*F,A=1-.5*T,W=1-T*T/8,H=(A*G.axisx+F*G.axisy)*W;G.axisy=(A*G.axisy-F*G.axisx)*W,G.axisx=H}break}break}}else{let k=c*m-p*z,N=c*Z-p*y,E=a.b2.smass+N*N*a.b2.sinertia+a.b1.smass+k*k*a.b1.sinertia;if(E!=0){let M=-a.biasCoef*d/E,C=0,D=0,O=M;C=p*O,D=c*O;let j=a.b1.imass;a.b1.posx-=C*j,a.b1.posy-=D*j;let L=a.b1,U=-k*a.b1.iinertia*M;if(L.rot+=U,U*U>1e-4)L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.rot);else{let S=U*U,J=1-.5*S,Q=1-S*S/8,Y=(J*L.axisx+U*L.axisy)*Q;L.axisy=(J*L.axisy-U*L.axisx)*Q,L.axisx=Y}let q=a.b2.imass;a.b2.posx+=C*q,a.b2.posy+=D*q;let R=a.b2,B=N*a.b2.iinertia*M;if(R.rot+=B,B*B>1e-4)R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.rot);else{let S=B*B,J=1-.5*S,Q=1-S*S/8,Y=(J*R.axisx+B*R.axisy)*Q;R.axisy=(J*R.axisy-B*R.axisx)*Q,R.axisx=Y}}}}}o=o.next,r&&o==null&&(o=this.c_arbiters_true.head,r=!1)}}}group_ignore(e,t){let n=e;for(;n!=null&&n.group==null;)n.ishape!=null?n=n.ishape.body:n.icompound!=null?n=n.icompound.compound:n=n.ibody.compound;let l=n==null?null:n.group;if(l==null)return!1;{let s=t;for(;s!=null&&s.group==null;)s.ishape!=null?s=s.ishape.body:s.icompound!=null?s=s.icompound.compound:s=s.ibody.compound;let i=s==null?null:s.group;if(i==null)return!1;{let o=!1;for(;l!=null&&i!=null;){if(l==i){o=l.ignore;break}l.depth<i.depth?i=i.group:l=l.group}return o}}}interactionType(e,t,n,l){let s;s=!1;let i=n.constraints.head;for(;i!=null;){let r=i.elt;if(r.ignore&&r.pair_exists(n.id,l.id)){s=!0;break}i=i.next}let o;if(s)o=!1;else{let r=e;for(;r!=null&&r.group==null;)r.ishape!=null?r=r.ishape.body:r.icompound!=null?r=r.icompound.compound:r=r.ibody.compound;let a=r==null?null:r.group,p;if(a==null)p=!1;else{let c=t;for(;c!=null&&c.group==null;)c.ishape!=null?c=c.ishape.body:c.icompound!=null?c=c.icompound.compound:c=c.ibody.compound;let u=c==null?null:c.group;if(u==null)p=!1;else{let h=!1;for(;a!=null&&u!=null;){if(a==u){h=a.ignore;break}a.depth<u.depth?u=u.group:a=a.group}p=h}}o=!p}if(o){let r;if(e.sensorEnabled||t.sensorEnabled){let a=e.filter,p=t.filter;r=(a.sensorMask&p.sensorGroup)!=0&&(p.sensorMask&a.sensorGroup)!=0}else r=!1;if(r)return 2;{let a;if(e.fluidEnabled||t.fluidEnabled){let p=e.filter,c=t.filter;a=(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0}else a=!1;if(a&&!(n.imass==0&&l.imass==0&&n.iinertia==0&&l.iinertia==0))return 0;{let p=e.filter,c=t.filter;return(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!(n.imass==0&&l.imass==0&&n.iinertia==0&&l.iinertia==0)?1:-1}}}else return-1}narrowPhase(e,t,n,l,s){let i=this,o=null,r=e.body,a=t.body,p;p=!1;let c=r.constraints.head;for(;c!=null;){let x=c.elt;if(x.ignore&&x.pair_exists(r.id,a.id)){p=!0;break}c=c.next}let u,h;if(p)h=!1;else{let x=e;for(;x!=null&&x.group==null;)x.ishape!=null?x=x.ishape.body:x.icompound!=null?x=x.icompound.compound:x=x.ibody.compound;let b=x==null?null:x.group,_;if(b==null)_=!1;else{let d=t;for(;d!=null&&d.group==null;)d.ishape!=null?d=d.ishape.body:d.icompound!=null?d=d.icompound.compound:d=d.ibody.compound;let f=d==null?null:d.group;if(f==null)_=!1;else{let m=!1;for(;b!=null&&f!=null;){if(b==f){m=b.ignore;break}b.depth<f.depth?f=f.group:b=b.group}_=m}}h=!_}if(h){let x;if(e.sensorEnabled||t.sensorEnabled){let b=e.filter,_=t.filter;x=(b.sensorMask&_.sensorGroup)!=0&&(_.sensorMask&b.sensorGroup)!=0}else x=!1;if(x)u=2;else{let b;if(e.fluidEnabled||t.fluidEnabled){let _=e.filter,d=t.filter;b=(_.fluidMask&d.fluidGroup)!=0&&(d.fluidMask&_.fluidGroup)!=0}else b=!1;if(b&&!(r.imass==0&&a.imass==0&&r.iinertia==0&&a.iinertia==0))u=0;else{let _=e.filter,d=t.filter;u=(_.collisionMask&d.collisionGroup)!=0&&(d.collisionMask&_.collisionGroup)!=0&&!(r.imass==0&&a.imass==0&&r.iinertia==0&&a.iinertia==0)?1:-1}}}else u=-1;if(u!=-1){let x,b;e.type>t.type?(x=t,b=e):e.type==t.type?e.id<t.id?(x=e,b=t):(b=e,x=t):(x=e,b=t);let _=x==t;if(u==0){let d;if(l==null){let y=null,v=(r.arbiters.length<a.arbiters.length?r:a).arbiters.head;for(;v!=null;){let P=v.elt;if(P.id==x.id&&P.di==b.id){y=P;break}v=v.next}d=y}else d=l;let f=d==null,m,z=!1;if(f)Ct.zpp_pool==null?m=new Ct:(m=Ct.zpp_pool,Ct.zpp_pool=m.next,m.next=null);else if(d.fluidarb==null){d.cleared=!0;{let w=d.b1.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let k,N;v==null?(k=w.head,N=k.next,w.head=N,w.head==null&&(w.pushmod=!0)):(k=v.next,N=k.next,v.next=N,N==null&&(w.pushmod=!0));let E=k;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}{let w=d.b2.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let k,N;v==null?(k=w.head,N=k.next,w.head=N,w.head==null&&(w.pushmod=!0)):(k=v.next,N=k.next,v.next=N,N==null&&(w.pushmod=!0));let E=k;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Ct.zpp_pool==null?m=new Ct:(m=Ct.zpp_pool,Ct.zpp_pool=m.next,m.next=null),m.intchange=!0,f=!0,z=!0}else m=d.fluidarb;let Z=4;if(f||m.stamp!=this.stamp||s)if(m.stamp=this.stamp,Ee.flowCollide(x,b,m)){if(f){let y=b.id;m.b1=e.body,m.ws1=e,m.b2=t.body,m.ws2=t,m.id=x.id,m.di=y;let w=m.b1.arbiters,v;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?v=new I._zpp.util.ZNPNode_ZPP_Arbiter:(v=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=v.next,v.next=null),v.elt=m;let P=v;P.next=w.head,w.head=P,w.modified=!0,w.length++;let g=m.b2.arbiters,k;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?k=new I._zpp.util.ZNPNode_ZPP_Arbiter:(k=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k.next,k.next=null),k.elt=m;let N=k;N.next=g.head,g.head=N,g.modified=!0,g.length++,m.active=!0,m.present=0,m.cleared=!1,m.sleeping=!1,m.fresh=!1,m.presentable=!1,m.nx=0,m.ny=1,m.dampx=0,m.dampy=0,m.adamp=0;let E=this.f_arbiters,M;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?M=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(M=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=M.next,M.next=null),M.elt=m;let C=M;C.next=E.head,E.head=C,E.modified=!0,E.length++,m.fresh=!z}else m.fresh=m.up_stamp<this.stamp-1||m.endGenerated==this.stamp&&s;if(m.up_stamp=m.stamp,m.fresh||(m.immState&4)==0){m.immState=1;let y=!1,w=m.ws1.id>m.ws2.id?m.ws2:m.ws1,v=m.ws1.id>m.ws2.id?m.ws1:m.ws2,P=this.mrca1;for(;P.head!=null;){let M=P.head;P.head=M.next;let C=M;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}P.pushmod=!0;let g=this.mrca2;for(;g.head!=null;){let M=g.head;g.head=M.next;let C=M;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}if(g.pushmod=!0,w.cbSet!=null){let M=this.mrca1,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=w;let D=C;D.next=M.head,M.head=D,M.modified=!0,M.length++}if(w.body.cbSet!=null){let M=this.mrca1,C=w.body,D;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?D=new I._zpp.util.ZNPNode_ZPP_Interactor:(D=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=D.next,D.next=null),D.elt=C;let O=D;O.next=M.head,M.head=O,M.modified=!0,M.length++}if(v.cbSet!=null){let M=this.mrca2,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=v;let D=C;D.next=M.head,M.head=D,M.modified=!0,M.length++}if(v.body.cbSet!=null){let M=this.mrca2,C=v.body,D;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?D=new I._zpp.util.ZNPNode_ZPP_Interactor:(D=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=D.next,D.next=null),D.elt=C;let O=D;O.next=M.head,M.head=O,M.modified=!0,M.length++}let k=w.body.compound,N=v.body.compound;for(;k!=N;){let M=k==null?0:k.depth,C=N==null?0:N.depth;if(M<C){if(N.cbSet!=null){let D=this.mrca2,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=N;let j=O;j.next=D.head,D.head=j,D.modified=!0,D.length++}N=N.compound}else{if(k.cbSet!=null){let D=this.mrca1,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=k;let j=O;j.next=D.head,D.head=j,D.modified=!0,D.length++}k=k.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,C=this.mrca2.head;for(;C!=null;){let D=C.elt,O=M.cbSet,j=D.cbSet,L=O.manager,U=null,R=(O.cbpairs.length<j.cbpairs.length?O.cbpairs:j.cbpairs).head;for(;R!=null;){let T=R.elt;if(T.a==O&&T.b==j||T.a==j&&T.b==O){U=T;break}R=R.next}if(U==null){let T;Ne.zpp_pool==null?T=new Ne:(T=Ne.zpp_pool,Ne.zpp_pool=T.next,T.next=null),T.zip_listeners=!0,zt.setlt(O,j)?(T.a=O,T.b=j):(T.a=j,T.b=O),U=T,O.cbpairs.add(U),j!=O&&j.cbpairs.add(U)}if(U.zip_listeners&&(U.zip_listeners=!1,U.__validate()),U.listeners.head==null){C=C.next;continue}let B=null,S=null,J=this.prelisteners;for(;J.head!=null;){let T=J.head;J.head=T.next;let A=T;A.elt=null,A.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=A,J.head==null&&(J.pushmod=!0),J.modified=!0,J.length--}J.pushmod=!0;let Q=null,Y=O.manager,X=null,G=(O.cbpairs.length<j.cbpairs.length?O.cbpairs:j.cbpairs).head;for(;G!=null;){let T=G.elt;if(T.a==O&&T.b==j||T.a==j&&T.b==O){X=T;break}G=G.next}if(X==null){let T;Ne.zpp_pool==null?T=new Ne:(T=Ne.zpp_pool,Ne.zpp_pool=T.next,T.next=null),T.zip_listeners=!0,zt.setlt(O,j)?(T.a=O,T.b=j):(T.a=j,T.b=O),X=T,O.cbpairs.add(X),j!=O&&j.cbpairs.add(X)}X.zip_listeners&&(X.zip_listeners=!1,X.__validate());let F=X.listeners.head;for(;F!=null;){let T=F.elt;if(T.event==5&&(T.itype&Z)!=0){let A=i.prelisteners,W;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?W=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(W=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=W.next,W.next=null),W.elt=T;let H=W;Q==null?(H.next=A.head,A.head=H):(H.next=Q.next,Q.next=H),A.pushmod=A.modified=!0,A.length++,Q=H,y=y||!T.pure}F=F.next}if(this.prelisteners.head==null){C=C.next;continue}if(B=I._zpp.phys.ZPP_Interactor.get(M,D),B==null&&(S=Yt.get(M,D),this.add_callbackset(S)),B==null||(B.FLUIDstamp!=this.stamp||s)&&(B.FLUIDstate&4)==0){if(S!=null&&(B=S),B!=null){let H=this.prelisteners.head;for(;H!=null;)H.elt.itype==7?(B.COLLISIONstamp=this.stamp,B.SENSORstamp=this.stamp,B.FLUIDstamp=this.stamp):B.FLUIDstamp=this.stamp,H=H.next}m.mutable=!0,m.wrap_position!=null&&(m.wrap_position.zpp_inner._immutable=!1);let T=m.active;m.active=!0;let A=!1;this.precb.zpp_inner.pre_arbiter=m,this.precb.zpp_inner.set=B;let W=this.prelisteners.head;for(;W!=null;){let H=W.elt;this.precb.zpp_inner.listener=H;let K=this.precb.zpp_inner,ne=B.int1,re=B.int2,se,ie=H.options1,oe=ne.cbTypes;if(ie.nonemptyintersection(oe,ie.includes)&&!ie.nonemptyintersection(oe,ie.excludes)){let pe=H.options2,ae=re.cbTypes;se=pe.nonemptyintersection(ae,pe.includes)&&!pe.nonemptyintersection(ae,pe.excludes)}else se=!1;se?(K.int1=ne,K.int2=re):(K.int1=re,K.int2=ne),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let ce=H.handlerp(this.precb);if(ce!=null){let pe;$.PreFlag_ACCEPT==null&&($.internal=!0,$.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,$.internal=!1),ce==$.PreFlag_ACCEPT?pe=5:($.PreFlag_ACCEPT_ONCE==null&&($.internal=!0,$.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,$.internal=!1),ce==$.PreFlag_ACCEPT_ONCE?pe=1:($.PreFlag_IGNORE==null&&($.internal=!0,$.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,$.internal=!1),pe=ce==$.PreFlag_IGNORE?6:2)),m.immState=pe}W=W.next}if(m.mutable=!1,m.wrap_position!=null&&(m.wrap_position.zpp_inner._immutable=!0),m.active=T,B!=null){let H=this.prelisteners.head;for(;H!=null;)H.elt.itype==7&&(B.COLLISIONstate=m.immState,B.SENSORstate=m.immState),B.FLUIDstate=m.immState,H=H.next}}else B==null?(m.immState&4)==0&&(m.immState=1):m.immState=B.FLUIDstate;C=C.next}E=E.next}if(y&&(m.immState&4)==0){if(m.b1.type==2){let M=m.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}if(m.b1.type==2){let M=m.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}}}if((m.immState&1)!=0){if(m.b1.type==2&&m.b1.component.sleeping){let y=m.b1;y.world||(y.component.waket=this.stamp+(this.midstep?0:1),y.type==3&&(y.kinematicDelaySleep=!0),y.component.sleeping&&this.really_wake(y,!1))}if(m.b2.type==2&&m.b2.component.sleeping){let y=m.b2;y.world||(y.component.waket=this.stamp+(this.midstep?0:1),y.type==3&&(y.kinematicDelaySleep=!0),y.component.sleeping&&this.really_wake(y,!1))}}if(m.sleeping){m.sleeping=!1;let y=this.f_arbiters,w;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?w=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(w=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=w.next,w.next=null),w.elt=m;let v=w;v.next=y.head,y.head=v,y.modified=!0,y.length++}o=m}else if(f){let y=m;y.next=Ct.zpp_pool,Ct.zpp_pool=y,o=null}else o=m;else o=m}else if(u==1){let d=n?this.c_arbiters_true:this.c_arbiters_false,f;if(l==null){let w=null,P=(r.arbiters.length<a.arbiters.length?r:a).arbiters.head;for(;P!=null;){let g=P.elt;if(g.id==x.id&&g.di==b.id){w=g;break}P=P.next}f=w}else f=l;let m=f==null,z,Z=!1;if(m)xt.zpp_pool==null?z=new xt:(z=xt.zpp_pool,xt.zpp_pool=z.next,z.next=null),z.stat=n;else if(f.colarb==null){f.cleared=!0;{let v=f.b1.arbiters,P=null,g=v.head,k=!1;for(;g!=null;){if(g.elt==f){let N,E;P==null?(N=v.head,E=N.next,v.head=E,v.head==null&&(v.pushmod=!0)):(N=P.next,E=N.next,P.next=E,E==null&&(v.pushmod=!0));let M=N;M.elt=null,M.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,v.modified=!0,v.length--,v.pushmod=!0,k=!0;break}P=g,g=g.next}}{let v=f.b2.arbiters,P=null,g=v.head,k=!1;for(;g!=null;){if(g.elt==f){let N,E;P==null?(N=v.head,E=N.next,v.head=E,v.head==null&&(v.pushmod=!0)):(N=P.next,E=N.next,P.next=E,E==null&&(v.pushmod=!0));let M=N;M.elt=null,M.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,v.modified=!0,v.length--,v.pushmod=!0,k=!0;break}P=g,g=g.next}}f.pair!=null&&(f.pair.arb=null,f.pair=null),f.active=!1,this.f_arbiters.modified=!0,xt.zpp_pool==null?z=new xt:(z=xt.zpp_pool,xt.zpp_pool=z.next,z.next=null),z.intchange=!0,z.stat=n,m=!0,Z=!0}else z=f.colarb,_=x!=z.s1,z.stat!=n&&(z.stat=n,z.sleeping||((n?this.c_arbiters_false:this.c_arbiters_true).remove(z),d.add(z)));let y=1;if(m||z.stamp!=this.stamp||s)if(z.stamp=this.stamp,Ee.contactCollide(x,b,z,_)){if(m){let w=b.id;z.b1=e.body,z.ws1=e,z.b2=t.body,z.ws2=t,z.id=x.id,z.di=w;let v=z.b1.arbiters,P;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?P=new I._zpp.util.ZNPNode_ZPP_Arbiter:(P=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=P.next,P.next=null),P.elt=z;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++;let k=z.b2.arbiters,N;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?N=new I._zpp.util.ZNPNode_ZPP_Arbiter:(N=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=N.next,N.next=null),N.elt=z;let E=N;E.next=k.head,k.head=E,k.modified=!0,k.length++,z.active=!0,z.present=0,z.cleared=!1,z.sleeping=!1,z.fresh=!1,z.presentable=!1,z.s1=e,z.s2=t,z.userdef_restitution||(z.s1.material.elasticity<=-1/0||z.s2.material.elasticity<=-1/0?z.restitution=0:z.s1.material.elasticity>=1/0||z.s2.material.elasticity>=1/0?z.restitution=1:z.restitution=(z.s1.material.elasticity+z.s2.material.elasticity)/2,z.restitution<0&&(z.restitution=0),z.restitution>1&&(z.restitution=1)),z.userdef_dyn_fric||(z.dyn_fric=Math.sqrt(z.s1.material.dynamicFriction*z.s2.material.dynamicFriction)),z.userdef_stat_fric||(z.stat_fric=Math.sqrt(z.s1.material.staticFriction*z.s2.material.staticFriction)),z.userdef_rfric||(z.rfric=Math.sqrt(z.s1.material.rollingFriction*z.s2.material.rollingFriction));let M;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?M=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(M=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=M.next,M.next=null),M.elt=z;let C=M;C.next=d.head,d.head=C,d.modified=!0,d.length++,z.fresh=!Z}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&s;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let w=!1,v=z.ws1.id>z.ws2.id?z.ws2:z.ws1,P=z.ws1.id>z.ws2.id?z.ws1:z.ws2,g=this.mrca1;for(;g.head!=null;){let C=g.head;g.head=C.next;let D=C;D.elt=null,D.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=D,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}g.pushmod=!0;let k=this.mrca2;for(;k.head!=null;){let C=k.head;k.head=C.next;let D=C;D.elt=null,D.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=D,k.head==null&&(k.pushmod=!0),k.modified=!0,k.length--}if(k.pushmod=!0,v.cbSet!=null){let C=this.mrca1,D;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?D=new I._zpp.util.ZNPNode_ZPP_Interactor:(D=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=D.next,D.next=null),D.elt=v;let O=D;O.next=C.head,C.head=O,C.modified=!0,C.length++}if(v.body.cbSet!=null){let C=this.mrca1,D=v.body,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=D;let j=O;j.next=C.head,C.head=j,C.modified=!0,C.length++}if(P.cbSet!=null){let C=this.mrca2,D;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?D=new I._zpp.util.ZNPNode_ZPP_Interactor:(D=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=D.next,D.next=null),D.elt=P;let O=D;O.next=C.head,C.head=O,C.modified=!0,C.length++}if(P.body.cbSet!=null){let C=this.mrca2,D=P.body,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=D;let j=O;j.next=C.head,C.head=j,C.modified=!0,C.length++}let N=v.body.compound,E=P.body.compound;for(;N!=E;){let C=N==null?0:N.depth,D=E==null?0:E.depth;if(C<D){if(E.cbSet!=null){let O=this.mrca2,j;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?j=new I._zpp.util.ZNPNode_ZPP_Interactor:(j=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=j.next,j.next=null),j.elt=E;let L=j;L.next=O.head,O.head=L,O.modified=!0,O.length++}E=E.compound}else{if(N.cbSet!=null){let O=this.mrca1,j;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?j=new I._zpp.util.ZNPNode_ZPP_Interactor:(j=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=j.next,j.next=null),j.elt=N;let L=j;L.next=O.head,O.head=L,O.modified=!0,O.length++}N=N.compound}}let M=this.mrca1.head;for(;M!=null;){let C=M.elt,D=this.mrca2.head;for(;D!=null;){let O=D.elt,j=C.cbSet,L=O.cbSet,U=j.manager,q=null,B=(j.cbpairs.length<L.cbpairs.length?j.cbpairs:L.cbpairs).head;for(;B!=null;){let A=B.elt;if(A.a==j&&A.b==L||A.a==L&&A.b==j){q=A;break}B=B.next}if(q==null){let A;Ne.zpp_pool==null?A=new Ne:(A=Ne.zpp_pool,Ne.zpp_pool=A.next,A.next=null),A.zip_listeners=!0,zt.setlt(j,L)?(A.a=j,A.b=L):(A.a=L,A.b=j),q=A,j.cbpairs.add(q),L!=j&&L.cbpairs.add(q)}if(q.zip_listeners&&(q.zip_listeners=!1,q.__validate()),q.listeners.head==null){D=D.next;continue}let S=null,J=null,Q=this.prelisteners;for(;Q.head!=null;){let A=Q.head;Q.head=A.next;let W=A;W.elt=null,W.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=W,Q.head==null&&(Q.pushmod=!0),Q.modified=!0,Q.length--}Q.pushmod=!0;let Y=null,X=j.manager,ee=null,F=(j.cbpairs.length<L.cbpairs.length?j.cbpairs:L.cbpairs).head;for(;F!=null;){let A=F.elt;if(A.a==j&&A.b==L||A.a==L&&A.b==j){ee=A;break}F=F.next}if(ee==null){let A;Ne.zpp_pool==null?A=new Ne:(A=Ne.zpp_pool,Ne.zpp_pool=A.next,A.next=null),A.zip_listeners=!0,zt.setlt(j,L)?(A.a=j,A.b=L):(A.a=L,A.b=j),ee=A,j.cbpairs.add(ee),L!=j&&L.cbpairs.add(ee)}ee.zip_listeners&&(ee.zip_listeners=!1,ee.__validate());let T=ee.listeners.head;for(;T!=null;){let A=T.elt;if(A.event==5&&(A.itype&y)!=0){let W=i.prelisteners,H;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?H=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(H=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=H.next,H.next=null),H.elt=A;let K=H;Y==null?(K.next=W.head,W.head=K):(K.next=Y.next,Y.next=K),W.pushmod=W.modified=!0,W.length++,Y=K,w=w||!A.pure}T=T.next}if(this.prelisteners.head==null){D=D.next;continue}if(S=I._zpp.phys.ZPP_Interactor.get(C,O),S==null&&(J=Yt.get(C,O),this.add_callbackset(J)),S==null||(S.COLLISIONstamp!=this.stamp||s)&&(S.COLLISIONstate&4)==0){if(J!=null&&(S=J),S!=null){let oe=this.prelisteners.head;for(;oe!=null;)oe.elt.itype==7?(S.COLLISIONstamp=this.stamp,S.SENSORstamp=this.stamp,S.FLUIDstamp=this.stamp):S.COLLISIONstamp=this.stamp,oe=oe.next}z.mutable=!0,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!1),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!1);let A=z.active;z.active=!0;let W=!1,H=!0,K=null,ne=null,re=z.innards.next;z.hc2=!1;let se=z.contacts.next;for(;se!=null;){let oe=se;if(oe.stamp+I._nape.Config.arbiterExpirationDelay<z.stamp){let ae=z.contacts,xe,te;K==null?(xe=ae.next,te=xe.next,ae.next=te,ae.next==null&&(ae.pushmod=!0)):(xe=K.next,te=xe.next,K.next=te,te==null&&(ae.pushmod=!0)),xe._inuse=!1,ae.modified=!0,ae.length--,ae.pushmod=!0,se=te;let he=z.innards,ye,ue;ne==null?(ye=he.next,ue=ye.next,he.next=ue,he.next==null&&(he.pushmod=!0)):(ye=ne.next,ue=ye.next,ne.next=ue,ue==null&&(he.pushmod=!0)),ye._inuse=!1,he.modified=!0,he.length--,he.pushmod=!0,re=ue;let Pe=oe;Pe.arbiter=null,Pe.next=we.zpp_pool,we.zpp_pool=Pe;continue}let ce=oe.inner,pe=oe.active;oe.active=oe.stamp==z.stamp,oe.active&&(H?(H=!1,z.c1=ce,z.oc1=oe):(z.hc2=!0,z.c2=ce,z.oc2=oe)),pe!=oe.active&&(z.contacts.modified=!0),K=se,ne=re,re=re.next,se=se.next}if(z.hc2){if(z.hpc2=!0,z.oc1.posOnly){let oe=z.c1;z.c1=z.c2,z.c2=oe;let ce=z.oc1;z.oc1=z.oc2,z.oc2=ce,z.hc2=!1}else z.oc2.posOnly&&(z.hc2=!1);z.oc1.posOnly&&(H=!0)}else z.hpc2=!1;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=S;let ie=this.prelisteners.head;for(;ie!=null;){let oe=ie.elt;this.precb.zpp_inner.listener=oe;let ce=this.precb.zpp_inner,pe=S.int1,ae=S.int2,xe,te=oe.options1,he=pe.cbTypes;if(te.nonemptyintersection(he,te.includes)&&!te.nonemptyintersection(he,te.excludes)){let ue=oe.options2,Pe=ae.cbTypes;xe=ue.nonemptyintersection(Pe,ue.includes)&&!ue.nonemptyintersection(Pe,ue.excludes)}else xe=!1;xe?(ce.int1=pe,ce.int2=ae):(ce.int1=ae,ce.int2=pe),this.precb.zpp_inner.pre_swapped=C!=this.precb.zpp_inner.int1;let ye=oe.handlerp(this.precb);if(ye!=null){let ue;$.PreFlag_ACCEPT==null&&($.internal=!0,$.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,$.internal=!1),ye==$.PreFlag_ACCEPT?ue=5:($.PreFlag_ACCEPT_ONCE==null&&($.internal=!0,$.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,$.internal=!1),ye==$.PreFlag_ACCEPT_ONCE?ue=1:($.PreFlag_IGNORE==null&&($.internal=!0,$.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,$.internal=!1),ue=ye==$.PreFlag_IGNORE?6:2)),z.immState=ue}ie=ie.next}if(z.mutable=!1,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!0),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!0),z.active=A,S!=null){let oe=this.prelisteners.head;for(;oe!=null;)oe.elt.itype==7?(S.COLLISIONstate=z.immState,S.SENSORstate=z.immState,S.FLUIDstate=z.immState):S.COLLISIONstate=z.immState,oe=oe.next}}else S==null?(z.immState&4)==0&&(z.immState=1):z.immState=S.COLLISIONstate;D=D.next}M=M.next}if(w&&(z.immState&4)==0){if(z.b1.type==2){let C=z.b1;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}if(z.b1.type==2){let C=z.b2;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}}}if((z.immState&1)!=0){if(z.b1.type==2&&z.b1.component.sleeping){let w=z.b1;w.world||(w.component.waket=this.stamp+(this.midstep?0:1),w.type==3&&(w.kinematicDelaySleep=!0),w.component.sleeping&&this.really_wake(w,!1))}if(z.b2.type==2&&z.b2.component.sleeping){let w=z.b2;w.world||(w.component.waket=this.stamp+(this.midstep?0:1),w.type==3&&(w.kinematicDelaySleep=!0),w.component.sleeping&&this.really_wake(w,!1))}}if(z.sleeping){z.sleeping=!1;let w;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?w=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(w=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=w.next,w.next=null),w.elt=z;let v=w;v.next=d.head,d.head=v,d.modified=!0,d.length++}o=z}else if(m){let w=z;w.userdef_dyn_fric=!1,w.userdef_stat_fric=!1,w.userdef_restitution=!1,w.userdef_rfric=!1,w.__ref_edge1=w.__ref_edge2=null,w.next=xt.zpp_pool,xt.zpp_pool=w,o=null}else o=z;else o=z}else{let d;if(l==null){let y=null,v=(r.arbiters.length<a.arbiters.length?r:a).arbiters.head;for(;v!=null;){let P=v.elt;if(P.id==x.id&&P.di==b.id){y=P;break}v=v.next}d=y}else d=l;let f=d==null,m,z=!1;if(f)jt.zpp_pool==null?m=new jt:(m=jt.zpp_pool,jt.zpp_pool=m.next,m.next=null);else if(d.sensorarb==null){d.cleared=!0;{let w=d.b1.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let k,N;v==null?(k=w.head,N=k.next,w.head=N,w.head==null&&(w.pushmod=!0)):(k=v.next,N=k.next,v.next=N,N==null&&(w.pushmod=!0));let E=k;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}{let w=d.b2.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let k,N;v==null?(k=w.head,N=k.next,w.head=N,w.head==null&&(w.pushmod=!0)):(k=v.next,N=k.next,v.next=N,N==null&&(w.pushmod=!0));let E=k;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,jt.zpp_pool==null?m=new jt:(m=jt.zpp_pool,jt.zpp_pool=m.next,m.next=null),m.intchange=!0,f=!0,z=!0}else m=d.sensorarb;let Z=2;if(f||m.stamp!=this.stamp||s)if(m.stamp=this.stamp,Ee.testCollide(x,b)){if(f){let y=b.id;m.b1=e.body,m.ws1=e,m.b2=t.body,m.ws2=t,m.id=x.id,m.di=y;let w=m.b1.arbiters,v;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?v=new I._zpp.util.ZNPNode_ZPP_Arbiter:(v=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=v.next,v.next=null),v.elt=m;let P=v;P.next=w.head,w.head=P,w.modified=!0,w.length++;let g=m.b2.arbiters,k;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?k=new I._zpp.util.ZNPNode_ZPP_Arbiter:(k=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k.next,k.next=null),k.elt=m;let N=k;N.next=g.head,g.head=N,g.modified=!0,g.length++,m.active=!0,m.present=0,m.cleared=!1,m.sleeping=!1,m.fresh=!1,m.presentable=!1;let E=this.s_arbiters,M;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?M=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(M=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=M.next,M.next=null),M.elt=m;let C=M;C.next=E.head,E.head=C,E.modified=!0,E.length++,m.fresh=!z}else m.fresh=m.up_stamp<this.stamp-1||m.endGenerated==this.stamp&&s;if(m.up_stamp=m.stamp,m.fresh||(m.immState&4)==0){m.immState=1;let y=!1,w=m.ws1.id>m.ws2.id?m.ws2:m.ws1,v=m.ws1.id>m.ws2.id?m.ws1:m.ws2,P=this.mrca1;for(;P.head!=null;){let M=P.head;P.head=M.next;let C=M;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}P.pushmod=!0;let g=this.mrca2;for(;g.head!=null;){let M=g.head;g.head=M.next;let C=M;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}if(g.pushmod=!0,w.cbSet!=null){let M=this.mrca1,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=w;let D=C;D.next=M.head,M.head=D,M.modified=!0,M.length++}if(w.body.cbSet!=null){let M=this.mrca1,C=w.body,D;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?D=new I._zpp.util.ZNPNode_ZPP_Interactor:(D=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=D.next,D.next=null),D.elt=C;let O=D;O.next=M.head,M.head=O,M.modified=!0,M.length++}if(v.cbSet!=null){let M=this.mrca2,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=v;let D=C;D.next=M.head,M.head=D,M.modified=!0,M.length++}if(v.body.cbSet!=null){let M=this.mrca2,C=v.body,D;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?D=new I._zpp.util.ZNPNode_ZPP_Interactor:(D=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=D.next,D.next=null),D.elt=C;let O=D;O.next=M.head,M.head=O,M.modified=!0,M.length++}let k=w.body.compound,N=v.body.compound;for(;k!=N;){let M=k==null?0:k.depth,C=N==null?0:N.depth;if(M<C){if(N.cbSet!=null){let D=this.mrca2,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=N;let j=O;j.next=D.head,D.head=j,D.modified=!0,D.length++}N=N.compound}else{if(k.cbSet!=null){let D=this.mrca1,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=k;let j=O;j.next=D.head,D.head=j,D.modified=!0,D.length++}k=k.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,C=this.mrca2.head;for(;C!=null;){let D=C.elt,O=M.cbSet,j=D.cbSet,L=O.manager,U=null,R=(O.cbpairs.length<j.cbpairs.length?O.cbpairs:j.cbpairs).head;for(;R!=null;){let T=R.elt;if(T.a==O&&T.b==j||T.a==j&&T.b==O){U=T;break}R=R.next}if(U==null){let T;Ne.zpp_pool==null?T=new Ne:(T=Ne.zpp_pool,Ne.zpp_pool=T.next,T.next=null),T.zip_listeners=!0,zt.setlt(O,j)?(T.a=O,T.b=j):(T.a=j,T.b=O),U=T,O.cbpairs.add(U),j!=O&&j.cbpairs.add(U)}if(U.zip_listeners&&(U.zip_listeners=!1,U.__validate()),U.listeners.head==null){C=C.next;continue}let B=null,S=null,J=this.prelisteners;for(;J.head!=null;){let T=J.head;J.head=T.next;let A=T;A.elt=null,A.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=A,J.head==null&&(J.pushmod=!0),J.modified=!0,J.length--}J.pushmod=!0;let Q=null,Y=O.manager,X=null,G=(O.cbpairs.length<j.cbpairs.length?O.cbpairs:j.cbpairs).head;for(;G!=null;){let T=G.elt;if(T.a==O&&T.b==j||T.a==j&&T.b==O){X=T;break}G=G.next}if(X==null){let T;Ne.zpp_pool==null?T=new Ne:(T=Ne.zpp_pool,Ne.zpp_pool=T.next,T.next=null),T.zip_listeners=!0,zt.setlt(O,j)?(T.a=O,T.b=j):(T.a=j,T.b=O),X=T,O.cbpairs.add(X),j!=O&&j.cbpairs.add(X)}X.zip_listeners&&(X.zip_listeners=!1,X.__validate());let F=X.listeners.head;for(;F!=null;){let T=F.elt;if(T.event==5&&(T.itype&Z)!=0){let A=i.prelisteners,W;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?W=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(W=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=W.next,W.next=null),W.elt=T;let H=W;Q==null?(H.next=A.head,A.head=H):(H.next=Q.next,Q.next=H),A.pushmod=A.modified=!0,A.length++,Q=H,y=y||!T.pure}F=F.next}if(this.prelisteners.head==null){C=C.next;continue}if(B=I._zpp.phys.ZPP_Interactor.get(M,D),B==null&&(S=Yt.get(M,D),this.add_callbackset(S)),B==null||(B.SENSORstamp!=this.stamp||s)&&(B.SENSORstate&4)==0){if(S!=null&&(B=S),B!=null){let H=this.prelisteners.head;for(;H!=null;)H.elt.itype==7?(B.COLLISIONstamp=this.stamp,B.SENSORstamp=this.stamp,B.FLUIDstamp=this.stamp):B.SENSORstamp=this.stamp,H=H.next}let T=m.active;m.active=!0;let A=!1;this.precb.zpp_inner.pre_arbiter=m,this.precb.zpp_inner.set=B;let W=this.prelisteners.head;for(;W!=null;){let H=W.elt;this.precb.zpp_inner.listener=H;let K=this.precb.zpp_inner,ne=B.int1,re=B.int2,se,ie=H.options1,oe=ne.cbTypes;if(ie.nonemptyintersection(oe,ie.includes)&&!ie.nonemptyintersection(oe,ie.excludes)){let pe=H.options2,ae=re.cbTypes;se=pe.nonemptyintersection(ae,pe.includes)&&!pe.nonemptyintersection(ae,pe.excludes)}else se=!1;se?(K.int1=ne,K.int2=re):(K.int1=re,K.int2=ne),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let ce=H.handlerp(this.precb);if(ce!=null){let pe;$.PreFlag_ACCEPT==null&&($.internal=!0,$.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,$.internal=!1),ce==$.PreFlag_ACCEPT?pe=5:($.PreFlag_ACCEPT_ONCE==null&&($.internal=!0,$.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,$.internal=!1),ce==$.PreFlag_ACCEPT_ONCE?pe=1:($.PreFlag_IGNORE==null&&($.internal=!0,$.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,$.internal=!1),pe=ce==$.PreFlag_IGNORE?6:2)),m.immState=pe}W=W.next}if(m.active=T,B!=null){let H=this.prelisteners.head;for(;H!=null;)H.elt.itype==7?(B.COLLISIONstate=m.immState,B.SENSORstate=m.immState,B.FLUIDstate=m.immState):B.SENSORstate=m.immState,H=H.next}}else B==null?(m.immState&4)==0&&(m.immState=1):m.immState=B.SENSORstate;C=C.next}E=E.next}if(y&&(m.immState&4)==0){if(m.b1.type!=1){let M=m.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}if(m.b2.type!=1){let M=m.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}}}if(m.sleeping){m.sleeping=!1;let y=this.s_arbiters,w;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?w=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(w=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=w.next,w.next=null),w.elt=m;let v=w;v.next=y.head,y.head=v,y.modified=!0,y.length++}o=m}else if(f){let y=m;y.next=jt.zpp_pool,jt.zpp_pool=y,o=null}else o=m;else o=m}}return o}MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let o=n.head;n.head=o.next;let r=o;r.elt=null,r.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let l=this.mrca2;for(;l.head!=null;){let o=l.head;l.head=o.next;let r=o;r.elt=null,r.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,l.head==null&&(l.pushmod=!0),l.modified=!0,l.length--}if(l.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_Interactor:(r=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=e;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(e.body.cbSet!=null){let o=this.mrca1,r=e.body,a;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}if(t.cbSet!=null){let o=this.mrca2,r;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_Interactor:(r=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=t;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(t.body.cbSet!=null){let o=this.mrca2,r=t.body,a;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let s=e.body.compound,i=t.body.compound;for(;s!=i;){let o=s==null?0:s.depth,r=i==null?0:i.depth;if(o<r){if(i.cbSet!=null){let a=this.mrca2,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=i;let c=p;c.next=a.head,a.head=c,a.modified=!0,a.length++}i=i.compound}else{if(s.cbSet!=null){let a=this.mrca1,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=s;let c=p;c.next=a.head,a.head=c,a.modified=!0,a.length++}s=s.compound}}}inlined_MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let o=n.head;n.head=o.next;let r=o;r.elt=null,r.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let l=this.mrca2;for(;l.head!=null;){let o=l.head;l.head=o.next;let r=o;r.elt=null,r.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,l.head==null&&(l.pushmod=!0),l.modified=!0,l.length--}if(l.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_Interactor:(r=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=e;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(e.body.cbSet!=null){let o=this.mrca1,r=e.body,a;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}if(t.cbSet!=null){let o=this.mrca2,r;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_Interactor:(r=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=t;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(t.body.cbSet!=null){let o=this.mrca2,r=t.body,a;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let s=e.body.compound,i=t.body.compound;for(;s!=i;){let o=s==null?0:s.depth,r=i==null?0:i.depth;if(o<r){if(i.cbSet!=null){let a=this.mrca2,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=i;let c=p;c.next=a.head,a.head=c,a.modified=!0,a.length++}i=i.compound}else{if(s.cbSet!=null){let a=this.mrca1,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=s;let c=p;c.next=a.head,a.head=c,a.modified=!0,a.length++}s=s.compound}}}};I.__name__=["zpp_nape","space","ZPP_Space"],I._zpp=null,I._nape=null;var di=I;var On=class{constructor(){this.aabb=null;this.shape=null;this.prev=null;this.next=null}free(){this.prev=null,this.shape=null,this.aabb=null}alloc(){}gt(e){return this.aabb.minx>e.aabb.minx}};On.__name__=["zpp_nape","space","ZPP_SweepData"],On.zpp_pool=null;var at=class at{constructor(e){this.failed=null;this.list=null;this.space=null;this.is_sweep=!1;this.sweep=null;this.__class__=at;at._zpp.space.ZPP_Broadphase._initFields(this),this.space=e,this.is_sweep=!0,this.sweep=this}static _init(){at.__super__=at._zpp.space.ZPP_Broadphase;let e=at._zpp.space.ZPP_Broadphase.prototype;Object.getOwnPropertyNames(e).forEach(t=>{t!=="constructor"&&!(t in at.prototype)&&(at.prototype[t]=e[t])})}__insert(e){let t;On.zpp_pool==null?t=new On:(t=On.zpp_pool,On.zpp_pool=t.next,t.next=null),e.sweep=t,t.shape=e,t.aabb=e.aabb,t.next=this.list,this.list!=null&&(this.list.prev=t),this.list=t}__remove(e){let t=e.sweep;t.prev==null?this.list=t.next:t.prev.next=t.next,t.next!=null&&(t.next.prev=t.prev),e.sweep=null;let n=t;n.prev=null,n.shape=null,n.aabb=null,n.next=On.zpp_pool,On.zpp_pool=n}__sync(e){if(!this.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let i=t.polygon;if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(i.lverts.next.next==null)i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;else if(i.lverts.next.next.next==null){i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;let o=1;i.localCOMx+=i.lverts.next.next.x*o,i.localCOMy+=i.lverts.next.next.y*o;let r=.5;i.localCOMx*=r,i.localCOMy*=r}else{i.localCOMx=0,i.localCOMy=0;let o=0,r=i.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let _=r;o+=p.x*(_.y-a.y);let d=_.y*p.x-_.x*p.y;i.localCOMx+=(p.x+_.x)*d,i.localCOMy+=(p.y+_.y)*d,a=p,p=_,r=r.next}r=i.lverts.next;let c=r;o+=p.x*(c.y-a.y);let u=c.y*p.x-c.x*p.y;i.localCOMx+=(p.x+c.x)*u,i.localCOMy+=(p.y+c.y)*u,a=p,p=c,r=r.next;let h=r;o+=p.x*(h.y-a.y);let x=h.y*p.x-h.x*p.y;i.localCOMx+=(p.x+h.x)*x,i.localCOMy+=(p.y+h.y)*x,o=1/(3*o);let b=o;i.localCOMx*=b,i.localCOMy*=b}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=i;i=i.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}}sync_broadphase(){if(this.space.validation(),this.list!=null){let e=this.list.next;for(;e!=null;){let t=e.next,n=e.prev;if(n!=null&&e.aabb.minx>n.aabb.minx){e=t;continue}for(;n.prev!=null&&n.prev.aabb.minx>e.aabb.minx;)n=n.prev;let l=e.prev;l.next=e.next,e.next!=null&&(e.next.prev=l),n.prev==null?(e.prev=null,this.list=e,e.next=n,n.prev=e):(e.prev=n.prev,n.prev=e,e.prev.next=e,e.next=n),e=t}}}sync_broadphase_fast(){let e=this.list.next;for(;e!=null;){let t=e.next,n=e.prev;if(n!=null&&e.aabb.minx>n.aabb.minx){e=t;continue}for(;n.prev!=null&&n.prev.aabb.minx>e.aabb.minx;)n=n.prev;let l=e.prev;l.next=e.next,e.next!=null&&(e.next.prev=l),n.prev==null?(e.prev=null,this.list=e,e.next=n,n.prev=e):(e.prev=n.prev,n.prev=e,e.prev.next=e,e.next=n),e=t}}broadphase(e,t){if(this.list!=null){let n=this.list.next;for(;n!=null;){let s=n.next,i=n.prev;if(i!=null&&n.aabb.minx>i.aabb.minx){n=s;continue}for(;i.prev!=null&&i.prev.aabb.minx>n.aabb.minx;)i=i.prev;let o=n.prev;o.next=n.next,n.next!=null&&(n.next.prev=o),i.prev==null?(n.prev=null,this.list=n,n.next=i,i.prev=n):(n.prev=i.prev,i.prev=n,n.prev.next=n,n.next=i),n=s}let l=this.list;for(;l!=null;){let s=l.next,i=l.shape,o=i.body,r=l.aabb.maxx;for(;s!=null&&!(s.aabb.minx>r);){let a=s.shape,p=a.body;if(p==o){s=s.next;continue}if(o.type==1&&p.type==1){s=s.next;continue}if(o.component.sleeping&&p.component.sleeping){s=s.next;continue}let c=i.aabb,u=a.aabb;u.miny>c.maxy||c.miny>u.maxy||(t?e.narrowPhase(i,a,o.type!=2||p.type!=2,null,!1):e.continuousEvent(i,a,o.type!=2||p.type!=2,null,!1)),s=s.next}l=l.next}}}clear(){for(;this.list!=null;)this.list.shape.removedFromSpace(),this.__remove(this.list.shape)}shapesUnderPoint(e,t,n,l){this.sync_broadphase();let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,o=l??new at._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.minx>e;)r=r.next;for(;r!=null&&r.aabb.minx<=e;){if(r.aabb.maxx>=e&&r.aabb.miny<=t&&r.aabb.maxy>=t){let p=r.shape,c;if(n!=null){let u=p.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(p.type==0?Ee.circleContains(p.circle,i)&&o.push(p.outer):Ee.polyContains(p.polygon,i)&&o.push(p.outer))}r=r.next}let a=i;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=le.zpp_pool,le.zpp_pool=a,o}bodiesUnderPoint(e,t,n,l){this.sync_broadphase();let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,o=l??new at._nape.phys.BodyList,r=this.list;for(;r!=null&&r.aabb.minx>e;)r=r.next;for(;r!=null&&r.aabb.minx<=e;){if(r.aabb.maxx>=e&&r.aabb.miny<=t&&r.aabb.maxy>=t){let p=r.shape,c=p.body.outer;if(!o.has(c)){let u;if(n!=null){let h=p.filter;u=(h.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(p.type==0?Ee.circleContains(p.circle,i)&&o.push(c):Ee.polyContains(p.polygon,i)&&o.push(c))}}r=r.next}let a=i;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=le.zpp_pool,le.zpp_pool=a,o}shapesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,o=s??new at._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.maxx<i.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=i.maxx;){let a=r.shape,p;if(l!=null){let c=a.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;if(p)if(t)if(n)Ee.containTest(this.aabbShape.zpp_inner,a)&&o.push(a.outer);else{let c=r.aabb;if(c.minx>=i.minx&&c.miny>=i.miny&&c.maxx<=i.maxx&&c.maxy<=i.maxy)o.push(a.outer);else{let u=r.aabb;i.miny<=u.maxy&&u.miny<=i.maxy&&i.minx<=u.maxx&&u.minx<=i.maxx&&Ee.testCollide_safe(a,this.aabbShape.zpp_inner)&&o.push(a.outer)}}else{let c;if(n){let u=r.aabb;c=u.minx>=i.minx&&u.miny>=i.miny&&u.maxx<=i.maxx&&u.maxy<=i.maxy}else{let u=r.aabb;c=i.miny<=u.maxy&&u.miny<=i.maxy&&i.minx<=u.maxx&&u.minx<=i.maxx}c&&o.push(a.outer)}r=r.next}return o}bodiesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,o=s??new at._nape.phys.BodyList;this.failed==null&&(this.failed=new at._nape.phys.BodyList);let r=this.list;for(;r!=null&&r.aabb.maxx<i.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=i.maxx;){let a=r.shape,p=a.body.outer,c=r.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx){let u;if(l!=null){let h=a.filter;u=(h.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(t)if(n){if(!this.failed.has(p)){let h=Ee.containTest(this.aabbShape.zpp_inner,a);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ee.testCollide_safe(a,this.aabbShape.zpp_inner)&&o.push(p);else if(n){if(!this.failed.has(p)){let h=a.aabb,x=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy;!o.has(p)&&x?o.push(p):x||(o.remove(p),this.failed.push(p))}}else{let h;if(o.has(p))h=!1;else{let x=a.aabb;h=x.minx>=i.minx&&x.miny>=i.miny&&x.maxx<=i.maxx&&x.maxy<=i.maxy}h&&o.push(p)}}r=r.next}return this.failed.clear(),o}shapesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let o=this.circShape.zpp_inner.aabb,r=i??new at._nape.shape.ShapeList,a=this.list;for(;a!=null&&a.aabb.maxx<o.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=o.maxx;){let p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx){let c=a.shape,u;if(s!=null){let h=c.filter;u=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(l?Ee.containTest(this.circShape.zpp_inner,c)&&r.push(c.outer):Ee.testCollide_safe(c,this.circShape.zpp_inner)&&r.push(c.outer))}a=a.next}return r}bodiesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let o=this.circShape.zpp_inner.aabb,r=i??new at._nape.phys.BodyList;this.failed==null&&(this.failed=new at._nape.phys.BodyList);let a=this.list;for(;a!=null&&a.aabb.maxx<o.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=o.maxx;){let p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx){let c=a.shape,u=c.body.outer,h;if(s!=null){let x=c.filter;h=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else h=!0;if(h)if(l){if(!this.failed.has(u)){let x=Ee.containTest(this.circShape.zpp_inner,c);!r.has(u)&&x?r.push(u):x||(r.remove(u),this.failed.push(u))}}else!r.has(u)&&Ee.testCollide_safe(c,this.circShape.zpp_inner)&&r.push(u)}a=a.next}return this.failed.clear(),r}shapesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new at._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.maxx<s.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=s.maxx;){let r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx){let a=o.shape,p;if(n!=null){let c=a.filter;p=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(t?Ee.containTest(e,a)&&i.push(a.outer):Ee.testCollide_safe(a,e)&&i.push(a.outer))}o=o.next}return i}bodiesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new at._nape.phys.BodyList;this.failed==null&&(this.failed=new at._nape.phys.BodyList);let o=this.list;for(;o!=null&&o.aabb.maxx<s.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=s.maxx;){let r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx){let a=o.shape,p=a.body.outer,c;if(n!=null){let u=a.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;if(c)if(t){if(!this.failed.has(p)){let u=Ee.containTest(e,a);!i.has(p)&&u?i.push(p):u||(i.remove(p),this.failed.push(p))}}else!i.has(p)&&Ee.testCollide_safe(e,a)&&i.push(p)}o=o.next}return this.failed.clear(),i}rayCast(e,t,n){this.sync_broadphase(),e.validate_dir();let l=e.rayAABB(),s=e.maxdist,i=null;if(e.dirx==0){let r=this.list;for(;r!=null&&r.aabb.minx<=l.minx;){let a,p=r.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx)if(n!=null){let c=r.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;if(a){let c=e.aabbsect(r.aabb);if(c>=0&&c<s){let u=r.shape.type==0?e.circlesect(r.shape.circle,t,s):e.polysect(r.shape.polygon,t,s);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(s=u.zpp_inner.toiDistance,i!=null){if(i.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");i.zpp_inner.free()}i=u}}}r=r.next}}else if(e.dirx<0){let r=this.list,a=null;for(;r!=null&&r.aabb.minx<=l.maxx;)a=r,r=r.next;for(r=a;r!=null;){let p,c=r.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(n!=null){let u=r.shape.filter;p=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else p=!0;else p=!1;if(p){let u=e.aabbsect(r.aabb);if(u>=0&&u<s){let h=r.shape.type==0?e.circlesect(r.shape.circle,t,s):e.polysect(r.shape.polygon,t,s);if(h!=null){if(h.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(s=h.zpp_inner.toiDistance,i!=null){if(i.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");i.zpp_inner.free()}i=h}}}r=r.prev}}else{let r=this.list;for(;r!=null&&r.aabb.minx<=l.maxx&&r.aabb.minx<e.originx+e.dirx*s;){let a,p=r.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx)if(n!=null){let c=r.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;if(a){let c=e.aabbsect(r.aabb);if(c>=0&&c<s){let u=r.shape.type==0?e.circlesect(r.shape.circle,t,s):e.polysect(r.shape.polygon,t,s);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(s=u.zpp_inner.toiDistance,i!=null){if(i.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");i.zpp_inner.free()}i=u}}}r=r.next}}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=be.zpp_pool,be.zpp_pool=o,i}rayMultiCast(e,t,n,l){this.sync_broadphase(),e.validate_dir();let s=e.rayAABB(),i=l??new at._nape.geom.RayResultList;if(e.dirx==0){let r=this.list;for(;r!=null&&r.aabb.minx<=s.minx;){let a,p=r.aabb;if(s.miny<=p.maxy&&p.miny<=s.maxy&&s.minx<=p.maxx&&p.minx<=s.maxx)if(n!=null){let c=r.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;a&&e.aabbsect(r.aabb)>=0&&(r.shape.type==0?e.circlesect2(r.shape.circle,t,i):e.polysect2(r.shape.polygon,t,i)),r=r.next}}else if(e.dirx<0){let r=this.list,a=null;for(;r!=null&&r.aabb.minx<=s.maxx;)a=r,r=r.next;for(r=a;r!=null;){let p,c=r.aabb;if(s.miny<=c.maxy&&c.miny<=s.maxy&&s.minx<=c.maxx&&c.minx<=s.maxx)if(n!=null){let u=r.shape.filter;p=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else p=!0;else p=!1;p&&e.aabbsect(r.aabb)>=0&&(r.shape.type==0?e.circlesect2(r.shape.circle,t,i):e.polysect2(r.shape.polygon,t,i)),r=r.prev}}else{let r=this.list;for(;r!=null&&r.aabb.minx<=s.maxx;){let a,p=r.aabb;if(s.miny<=p.maxy&&p.miny<=s.maxy&&s.minx<=p.maxx&&p.minx<=s.maxx)if(n!=null){let c=r.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;a&&e.aabbsect(r.aabb)>=0&&(r.shape.type==0?e.circlesect2(r.shape.circle,t,i):e.polysect2(r.shape.polygon,t,i)),r=r.next}}let o=s;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=be.zpp_pool,be.zpp_pool=o,i}};at.__name__=["zpp_nape","space","ZPP_SweepPhase"],at.__super__=null,at._zpp=null,at._nape=null;var rs=at;function io(){let V={},e={};return V.callbacks={},V.constraint={},V.dynamics={},V.geom={},V.phys={},V.shape={},V.space={},V.util={},e.ZPP_Const=ni,e.ZPP_ID=fn,e.callbacks||(e.callbacks={}),Gt._nape=V,Gt._zpp=e,e.callbacks.ZPP_Callback=Gt,zt._zpp=e,e.callbacks.ZPP_CbSet=zt,Ne._zpp=e,e.callbacks.ZPP_CbSetPair=Ne,e.util||(e.util={}),no(e),gn._zpp=e,e.callbacks.ZPP_CbType=gn,e.util.ZPP_Flags=$,qt._nape=V,qt._zpp=e,e.callbacks.ZPP_Listener=qt,e.callbacks.ZPP_BodyListener=Ds,e.callbacks.ZPP_ConstraintListener=Fs,e.callbacks.ZPP_InteractionListener=Cl,zs._nape=V,zs._zpp=e,e.callbacks.ZPP_OptionType=zs,e.constraint||(e.constraint={}),ve._nape=V,ve._zpp=e,e.constraint.ZPP_Constraint=ve,e.constraint.ZPP_Constraint.__name__=ve.__name__,e.constraint.ZPP_AngleJoint=qe,e.constraint.ZPP_AngleJoint.__name__=qe.__name__,e.constraint.ZPP_CopyHelper=Fn,e.constraint.ZPP_DistanceJoint=si,e.constraint.ZPP_DistanceJoint.__name__=si.__name__,e.constraint.ZPP_LineJoint=li,e.constraint.ZPP_LineJoint.__name__=li.__name__,e.constraint.ZPP_MotorJoint=oi,e.constraint.ZPP_MotorJoint.__name__=oi.__name__,e.constraint.ZPP_PivotJoint=ri,e.constraint.ZPP_PivotJoint.__name__=ri.__name__,e.constraint.ZPP_PulleyJoint=ai,e.constraint.ZPP_PulleyJoint.__name__=ai.__name__,e.constraint.ZPP_UserConstraint=qs,e.constraint.ZPP_UserConstraint.__name__=qs.__name__,e.constraint.ZPP_UserBody=$i,e.constraint.ZPP_WeldJoint=pi,e.constraint.ZPP_WeldJoint.__name__=pi.__name__,e.dynamics||(e.dynamics={}),Ae._nape=V,Ae._zpp=e,e.dynamics.ZPP_Arbiter=Ae,e.dynamics.ZPP_SensorArbiter=jt,Ct._nape=V,Ct._zpp=e,e.dynamics.ZPP_FluidArbiter=Ct,xt._nape=V,xt._zpp=e,e.dynamics.ZPP_ColArbiter=xt,e.dynamics.ZPP_IContact=ci,we._nape=V,we._zpp=e,e.dynamics.ZPP_Contact=we,_t._nape=V,_t._zpp=e,e.dynamics.ZPP_InteractionFilter=_t,Js._zpp=e,e.dynamics.ZPP_InteractionGroup=Js,Gn._nape=V,Gn._zpp=e,e.dynamics.ZPP_SpaceArbiterList=Gn,e.geom||(e.geom={}),be._nape=V,be._zpp=e,e.geom.ZPP_AABB=be,e.geom.ZPP_Collide=Ee,e.geom.ZPP_Convex=Ml,e.geom.ZPP_ConvexRayResult=zn,e.geom.ZPP_CutVert=He,e.geom.ZPP_CutInt=lt,e.geom.ZPP_Cutter=Zl,e.geom.ZPP_Geom=gs,e.geom.ZPP_GeomVert=ge,ge._createVec2Fn=function(){return new V.geom.Vec2},e.geom.ZPP_GeomPoly=Ws,e.geom.ZPP_MarchSpan=Cn,e.geom.ZPP_MarchPair=Mn,Ks._init(e,V),e.geom.ZPP_MarchingSquares=Ks,Ys._nape=V,e.geom.ZPP_Mat23=Ys,e.geom.ZPP_MatMN=gi,e.geom.ZPP_Monotone=kl,e.geom.ZPP_PartitionVertex=Ge,e.geom.ZPP_PartitionedPoly=is,e.geom.ZPP_Ray=El,e.geom.ZPP_SimpleVert=ke,e.geom.ZPP_SimpleSeg=Tt,e.geom.ZPP_SimpleEvent=Me,e.geom.ZPP_SimpleSweep=ki,e.geom.ZPP_Simple=Nl,e.geom.ZPP_SimplifyV=Zn,e.geom.ZPP_SimplifyP=Be,e.geom.ZPP_Simplify=Ol,e.geom.ZPP_ToiEvent=Cs,e.geom.ZPP_SweepDistance=Pn,e.geom.ZPP_PartitionPair=Bt,e.geom.ZPP_Triangular=Sl,e.geom.ZPP_Vec2=le,ui._zpp=e,e.geom.ZPP_Vec3=ui,e.geom.ZPP_VecMath=Xs,e.phys||(e.phys={}),e.phys.ZPP_Interactor=St,St._init(e,V),kn._init(e,V),e.phys.ZPP_Body=kn,Rn._nape=V,Rn._zpp=e,Rn._init(),e.phys.ZPP_Compound=Rn,En._nape=V,En._zpp=e,e.phys.ZPP_FluidProperties=En,Ve._nape=V,Ve._zpp=e,e.phys.ZPP_Material=Ve,e.shape||(e.shape={}),xi._nape=V,xi._zpp=e,xi._init(),e.shape.ZPP_Shape=xi,Xn._nape=V,Xn._zpp=e,Xn._init(),e.shape.ZPP_Circle=Xn,ot._nape=V,ot._zpp=e,e.shape.ZPP_Edge=ot,Hn._nape=V,Hn._zpp=e,Hn._init(),e.shape.ZPP_Polygon=Hn,e.space||(e.space={}),Oi._zpp=e,Oi._nape=V,e.space.ZPP_Broadphase=Oi,e.space.ZPP_AABBNode=Oe,e.space.ZPP_AABBPair=$e,e.space.ZPP_AABBTree=et,ls._zpp=e,ls._nape=V,ls._init(),e.space.ZPP_DynAABBPhase=ls,yt._zpp=e,e.space.ZPP_Island=yt,e.space.ZPP_Component=Zs,Yt._zpp=e,e.space.ZPP_CallbackSet=Yt,os._zpp=e,e.space.ZPP_CbSetManager=os,di._zpp=e,di._nape=V,e.space.ZPP_Space=di,e.space.ZPP_SweepData=On,rs._zpp=e,rs._nape=V,rs._init(),e.space.ZPP_SweepPhase=rs,e.util.ZNPArray2_Float=qi,e.util.ZNPArray2_ZPP_GeomVert=Ji,e.util.ZNPArray2_ZPP_MarchPair=Ui,e.util.Hashable2_Boolfalse=je,e.util.FastHash2_Hashable2_Boolfalse=Yi,e.util.ZPP_Math=js,e.util.ZPP_PubPool=de,e.callbacks.ZPP_InteractionListener._initStatics(e),e.geom.ZPP_Collide._initStatics(e),e.space.ZPP_AABBTree._initStatics(),V.__zpp=e,V}var Al;function me(){return Al||(Al=io()),Al}var so=!1;function lo(){if(so)return;let V=Al;if(!V?.callbacks?.CbEvent||!V?.callbacks?.CbType||!V?.callbacks?.ListenerType||!V?.dynamics?.ArbiterType||!V?.phys?.BodyType||!V?.shape?.ShapeType)return;so=!0;let e=V.__zpp;e.callbacks.ZPP_CbType._initEnums(V),e.callbacks.ZPP_Listener._initEnums(V,e.util.ZPP_Flags),e.dynamics.ZPP_Arbiter._initEnums(V,e.util.ZPP_Flags),e.phys.ZPP_Body._initEnums(V,e.util.ZPP_Flags),e.shape.ZPP_Shape._initEnums(V,e.util.ZPP_Flags)}var oo=new WeakMap;function Ze(V,e){if(!V)return null;let t=oo.get(V);return t||(t=e(V),oo.set(V,t)),t}var Re=class Re{constructor(e=0,t=0){this.zpp_pool=null;this.zpp_disp=!1;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;le.zpp_pool==null?n=new le:(n=le.zpp_pool,le.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,this.zpp_inner=n,n.outer=this}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}_checkImmutable(){this.zpp_inner.immutable()}_validate(){this.zpp_inner.validate()}_invalidate(){this.zpp_inner.invalidate()}static _disposeWeak(e){e.zpp_inner.weak&&e.dispose()}_setXY(e,t){if(this._checkDisposed(),this._checkImmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");this._validate(),(this.zpp_inner.x!==e||this.zpp_inner.y!==t)&&(this.zpp_inner.x=e,this.zpp_inner.y=t,this._invalidate())}static _poolGet(e,t,n){let l;if(de.poolVec2==null?l=new Re:(l=de.poolVec2,de.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===de.nextVec2&&(de.nextVec2=null)),l.zpp_inner==null){let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,l.zpp_inner=s,s.outer=l}else l.zpp_inner.immutable(),l.zpp_inner.validate(),(l.zpp_inner.x!==e||l.zpp_inner.y!==t)&&(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner.invalidate());return l.zpp_inner.weak=n,l}static _wrap(e){return e instanceof Re?e:e?e instanceof le?Ze(e,t=>{let n=Object.create(Re.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?Re._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=!1){if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");return Re._poolGet(e,t,n)}static weak(e=0,t=0){if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");return Re._poolGet(e,t,!0)}static fromPolar(e,t,n=!1){if(e!==e)throw new Error("Error: Vec2::length cannot be NaN");if(t!==t)throw new Error("Error: Vec2::angle cannot be NaN");let l=e*Math.cos(t),s=e*Math.sin(t);return Re._poolGet(l,s,n)}static fromAngle(e,t=!1){return Re.fromPolar(1,e,t)}static lerp(e,t,n,l=!1){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot lerp with null Vec2");if(n!==n)throw new Error("Error: Cannot lerp with NaN t");e.zpp_inner.validate(),t.zpp_inner.validate();let s=e.zpp_inner.x+n*(t.zpp_inner.x-e.zpp_inner.x),i=e.zpp_inner.y+n*(t.zpp_inner.y-e.zpp_inner.y),o=Re._poolGet(s,i,l);return Re._disposeWeak(e),Re._disposeWeak(t),o}static eq(e,t,n=0){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null){let o=e==null&&t==null;return e!=null&&Re._disposeWeak(e),t!=null&&Re._disposeWeak(t),o}e.zpp_inner.validate(),t.zpp_inner.validate();let l=e.zpp_inner.x-t.zpp_inner.x,s=e.zpp_inner.y-t.zpp_inner.y,i=(l<0?-l:l)<=n&&(s<0?-s:s)<=n;return Re._disposeWeak(e),Re._disposeWeak(t),i}static dsq(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,l=e.zpp_inner.y;t.zpp_inner.validate();let s=t.zpp_inner.x,i=t.zpp_inner.y,o=n-s,r=l-i,a=o*o+r*r;return Re._disposeWeak(e),Re._disposeWeak(t),a}static distance(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,l=e.zpp_inner.y;t.zpp_inner.validate();let s=t.zpp_inner.x,i=t.zpp_inner.y,o=n-s,r=l-i,a=Math.sqrt(o*o+r*r);return Re._disposeWeak(e),Re._disposeWeak(t),a}get x(){return this._checkDisposed(),this._validate(),this.zpp_inner.x}set x(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.x!==e){if(e!==e)throw new Error("Error: Vec2::x cannot be NaN");this.zpp_inner.x=e,this._invalidate()}}get y(){return this._checkDisposed(),this._validate(),this.zpp_inner.y}set y(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.y!==e){if(e!==e)throw new Error("Error: Vec2::y cannot be NaN");this.zpp_inner.y=e,this._invalidate()}}get length(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return Math.sqrt(e*e+t*t)}set length(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::length cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,l=t*t+n*n;if(l===0)throw new Error("Error: Cannot set length of a zero vector");let s=e/Math.sqrt(l);this._setXY(t*s,n*s),this._invalidate()}get angle(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e===t&&e===0?0:Math.atan2(t,e)}set angle(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::angle cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,l=Math.sqrt(t*t+n*n),s=l*Math.cos(e),i=l*Math.sin(e);this._setXY(s,i)}lsq(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e*e+t*t}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");e.zpp_inner.validate();let t=e.zpp_inner.x,n=e.zpp_inner.y;return this._setXY(t,n),Re._disposeWeak(e),this}setxy(e,t){return this._checkDisposed(),this._checkImmutable(),this._setXY(e,t),this}clone(){return this.copy()}equals(e,t=0){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)return!1;this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,l=this.zpp_inner.y-e.zpp_inner.y;return(n<0?-n:n)<=t&&(l<0?-l:l)<=t}copy(e=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y;return Re._poolGet(t,n,e)}rotate(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Cannot rotate Vec2 by NaN");if(e%(Math.PI*2)!==0){let t=Math.sin(e),n=Math.cos(e),l=n*this.zpp_inner.x-t*this.zpp_inner.y;this.zpp_inner.y=this.zpp_inner.x*t+this.zpp_inner.y*n,this.zpp_inner.x=l,this._invalidate()}return this}reflect(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this._validate();let n=this.zpp_inner.x,l=this.zpp_inner.y;if(Math.sqrt(n*n+l*l)===0)throw new Error("Error: Cannot reflect in zero vector");let s=Re._poolGet(n,l,!0);s.normalise();let i=e.sub(s.muleq(2*s.dot(e)),t);return Re._disposeWeak(e),i}normalise(){this._checkDisposed(),this._checkImmutable(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y,n=e*e+t*t;if(Math.sqrt(n)===0)throw new Error("Error: Cannot normalise vector of length 0");let l=1/Math.sqrt(n);return this._setXY(e*l,t*l),this._invalidate(),this}unit(e=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,l=t*t+n*n;if(Math.sqrt(l)===0)throw new Error("Error: Cannot normalise vector of length 0");let s=1/Math.sqrt(l);return Re._poolGet(t*s,n*s,e)}add(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x+e.zpp_inner.x,l=this.zpp_inner.y+e.zpp_inner.y,s=Re._poolGet(n,l,t);return Re._disposeWeak(e),s}addMul(e,t,n=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let l=this.zpp_inner.x+e.zpp_inner.x*t,s=this.zpp_inner.y+e.zpp_inner.y*t,i=Re._poolGet(l,s,n);return Re._disposeWeak(e),i}sub(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot subtract null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,l=this.zpp_inner.y-e.zpp_inner.y,s=Re._poolGet(n,l,t);return Re._disposeWeak(e),s}mul(e,t=!1){if(this._checkDisposed(),e!==e)throw new Error("Error: Cannot multiply with NaN");this._validate();let n=this.zpp_inner.x*e,l=this.zpp_inner.y*e;return Re._poolGet(n,l,t)}addeq(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x+e.zpp_inner.x,n=this.zpp_inner.y+e.zpp_inner.y;return this._setXY(t,n),Re._disposeWeak(e),this}subeq(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot subtract null vectors");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x-e.zpp_inner.x,n=this.zpp_inner.y-e.zpp_inner.y;return this._setXY(t,n),Re._disposeWeak(e),this}muleq(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Cannot multiply with NaN");this._validate();let t=this.zpp_inner.x*e,n=this.zpp_inner.y*e;return this._setXY(t,n),this}dot(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot take dot product with null vector");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x*e.zpp_inner.x+this.zpp_inner.y*e.zpp_inner.y;return Re._disposeWeak(e),t}cross(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot take cross product with null vector");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x*e.zpp_inner.y-this.zpp_inner.y*e.zpp_inner.x;return Re._disposeWeak(e),t}perp(e=!1){this._checkDisposed(),this._validate();let t=-this.zpp_inner.y,n=this.zpp_inner.x;return Re._poolGet(t,n,e)}dispose(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),this.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let e=this.zpp_inner;e.outer=null,this.zpp_inner=null,this.zpp_pool=null,de.nextVec2!=null?de.nextVec2.zpp_pool=this:de.poolVec2=this,de.nextVec2=this,this.zpp_disp=!0,e.free(),e.next=le.zpp_pool,le.zpp_pool=e}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};Re.__name__=["nape","geom","Vec2"];var st=Re;le._wrapFn=V=>Ze(V,e=>{let t=Object.create(st.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Uo=me();Uo.geom.Vec2=st;var Si=class Si{constructor(e=0,t=0,n=0){this.zpp_pool=null;this.zpp_disp=!1;let l=new ui;this.zpp_inner=l,l.outer=this,l.x=e,l.y=t,l.z=n}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!")}_checkImmutable(){if(this.zpp_inner.immutable)throw new Error("Error: Vec3 is immutable")}static _wrap(e){return e instanceof Si?e:e?e instanceof ui?Ze(e,t=>{let n=Object.create(Si.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?Si._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=0){let l;return de.poolVec3==null?l=new Si:(l=de.poolVec3,de.poolVec3=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===de.nextVec3&&(de.nextVec3=null)),l.setxyz(e,t,n),l.zpp_inner.immutable=!1,l.zpp_inner._validate=null,l}get x(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.x}set x(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e}get y(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.y}set y(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.y=e}get z(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.z}set z(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.z=e}get length(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return Math.sqrt(e*e+t*t+n*n)}set length(e){if(this._checkDisposed(),e!==e)throw new Error("Error: Vec3::length cannot be NaN");this.zpp_inner.validate();let{x:t,y:n,z:l}=this.zpp_inner,s=t*t+n*n+l*l;if(s===0)throw new Error("Error: Cannot set length of a zero vector");let i=e/Math.sqrt(s);this._checkImmutable(),this.zpp_inner.x=t*i,this.zpp_inner.y=n*i,this.zpp_inner.z=l*i}lsq(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return e*e+t*t+n*n}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot assign null Vec3");return e.zpp_inner.validate(),this.setxyz(e.zpp_inner.x,e.zpp_inner.y,e.zpp_inner.z)}setxyz(e,t,n){return this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e,this._checkImmutable(),this.zpp_inner.y=t,this._checkImmutable(),this.zpp_inner.z=n,this}equals(e,t=0){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)return!1;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,l=this.zpp_inner.y-e.zpp_inner.y,s=this.zpp_inner.z-e.zpp_inner.z;return(n<0?-n:n)<=t&&(l<0?-l:l)<=t&&(s<0?-s:s)<=t}clone(){return this._checkDisposed(),this.zpp_inner.validate(),Si.get(this.zpp_inner.x,this.zpp_inner.y,this.zpp_inner.z)}xy(e=!1){return this._checkDisposed(),this.zpp_inner.validate(),st.get(this.zpp_inner.x,this.zpp_inner.y,e)}dispose(){if(this.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(this.zpp_inner.immutable)throw new Error("Error: This Vec3 is not disposable");this.zpp_pool=null,de.nextVec3!=null?de.nextVec3.zpp_pool=this:de.poolVec3=this,de.nextVec3=this,this.zpp_disp=!0}toString(){return this._checkDisposed(),this.zpp_inner.validate(),"{ x: "+this.zpp_inner.x+" y: "+this.zpp_inner.y+" z: "+this.zpp_inner.z+" }"}};Si.__name__=["nape","geom","Vec3"];var yi=Si;ui._wrapFn=V=>Ze(V,e=>{let t=Object.create(yi.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var as=class as{get _inner(){return this}constructor(e=0,t=0,n=0,l=0){if(e!==e||t!==t)throw new Error("Error: AABB position cannot be NaN");if(n!==n||l!==l)throw new Error("Error: AABB dimensions cannot be NaN");let s;be.zpp_pool==null?s=new be:(s=be.zpp_pool,be.zpp_pool=s.next,s.next=null),s.minx=e,s.miny=t,s.maxx=e+n,s.maxy=t+l,this.zpp_inner=s,s.outer=this}static fromPoints(e){if(e==null||e.length===0)throw new Error("Error: AABB::fromPoints requires at least one point");let t=e[0];if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");t.zpp_inner.validate();let n=t.zpp_inner.x,l=t.zpp_inner.y,s=n,i=l;for(let o=1;o<e.length;o++){let r=e[o];if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(r==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");r.zpp_inner.validate();let a=r.zpp_inner.x,p=r.zpp_inner.y;a<n&&(n=a),p<l&&(l=p),a>s&&(s=a),p>i&&(i=p)}return new as(n,l,s-n,i-l)}static _wrap(e){return e instanceof as?e:e?e instanceof be?Ze(e,t=>{let n=Object.create(as.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?as._wrap(e.zpp_inner):null:null}get x(){return this.zpp_inner.validate(),this.zpp_inner.minx}set x(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::x cannot be NaN");this.zpp_inner.maxx+=e-this.zpp_inner.minx,this.zpp_inner.minx=e,this.zpp_inner.invalidate()}}get y(){return this.zpp_inner.validate(),this.zpp_inner.miny}set y(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::y cannot be NaN");this.zpp_inner.maxy+=e-this.zpp_inner.miny,this.zpp_inner.miny=e,this.zpp_inner.invalidate()}}get width(){return this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx}set width(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::width cannot be NaN");if(e<0)throw new Error("Error: AABB::width ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxx=this.zpp_inner.minx+e,this.zpp_inner.invalidate()}}get height(){return this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny}set height(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::height cannot be NaN");if(e<0)throw new Error("Error: AABB::height ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxy=this.zpp_inner.miny+e,this.zpp_inner.invalidate()}}get min(){return this.zpp_inner.getmin(),this.zpp_inner.wrap_min}set min(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::min");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::min components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::min components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.x;this.zpp_inner.getmax();let s=this.zpp_inner.wrap_max;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l>s.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let i=e.zpp_inner.y;this.zpp_inner.getmin();let o=this.zpp_inner.wrap_max;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(o.zpp_inner._validate!=null&&o.zpp_inner._validate(),i>o.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let r=this.zpp_inner.wrap_min;this._assignVec2(r,e),e.zpp_inner.weak&&this._disposeVec2(e)}get max(){return this.zpp_inner.getmax(),this.zpp_inner.wrap_max}set max(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::max");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::max components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::max components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.x;this.zpp_inner.getmin();let s=this.zpp_inner.wrap_min;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l<s.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let i=e.zpp_inner.y;this.zpp_inner.getmin();let o=this.zpp_inner.wrap_min;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(o.zpp_inner._validate!=null&&o.zpp_inner._validate(),i<o.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let r=this.zpp_inner.wrap_max;this._assignVec2(r,e),e.zpp_inner.weak&&this._disposeVec2(e)}_assignVec2(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=e.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t==null)throw new Error("Error: Cannot assign null Vec2");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let l=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let s=t.zpp_inner.y;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=e.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e.zpp_inner._validate!=null&&e.zpp_inner._validate(),e.zpp_inner.x==l){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate(),o=e.zpp_inner.y==s}else o=!1;o||(e.zpp_inner.x=l,e.zpp_inner.y=s,e.zpp_inner._invalidate!=null&&e.zpp_inner._invalidate(e.zpp_inner))}_disposeVec2(e){let n=me().zpp_nape;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let s=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let i=e;i.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=i:n.util.ZPP_PubPool.poolVec2=i,n.util.ZPP_PubPool.nextVec2=i,i.zpp_disp=!0;let o=s;o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o}clone(){return this.copy()}equals(e,t=0){if(e==null)return!1;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.minx-e.zpp_inner.minx,l=this.zpp_inner.miny-e.zpp_inner.miny,s=this.zpp_inner.maxx-e.zpp_inner.maxx,i=this.zpp_inner.maxy-e.zpp_inner.maxy;return(n<0?-n:n)<=t&&(l<0?-l:l)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t}copy(){this.zpp_inner.validate();let e=this.zpp_inner;return be.get(e.minx,e.miny,e.maxx,e.maxy).wrapper()}toString(){return this.zpp_inner.validate(),this.zpp_inner.toString()}};as.__name__=["nape","geom","AABB"];var Hs=as;be._wrapFn=V=>Ze(V,e=>{let t=Object.create(Hs.prototype);return t.zpp_inner=e,e.outer=t,t});var Vl=class{constructor(e,t){this._inner=e,this._wrap=t}get length(){return this._inner.length}at(e){return this._wrap(this._inner.at(e))}add(e){this._inner.add(e._inner??e)}remove(e){this._inner.remove(e._inner??e)}has(e){return this._inner.has(e._inner??e)}clear(){this._inner.clear()}get empty(){return this._inner.empty()}push(e){this._inner.push(e._inner??e)}pop(){return this._wrap(this._inner.pop())}shift(){return this._wrap(this._inner.shift())}unshift(e){this._inner.unshift(e._inner??e)}*[Symbol.iterator](){for(let e=0;e<this.length;e++)yield this.at(e)}toArray(){return[...this]}forEach(e){for(let t=0;t<this.length;t++)e(this.at(t),t)}toString(){return this._inner.toString()}};var ps=class ps{get _inner(){return this}constructor(e=1,t=1){let n;if(En.zpp_pool==null?n=new En:(n=En.zpp_pool,En.zpp_pool=n.next,n.next=null),this.zpp_inner=n,n.outer=this,e!=n.density*1e3){if(e!==e)throw new Error("Error: FluidProperties::density cannot be NaN");n.density=e/1e3,n.invalidate()}if(t!=n.viscosity){if(t!==t)throw new Error("Error: FluidProperties::viscosity cannot be NaN");if(t<0)throw new Error("Error: FluidProperties::viscosity ("+t+") must be >= 0");n.viscosity=t/1,n.invalidate()}}static _wrap(e){return e instanceof ps?e:e?e instanceof En?Ze(e,t=>{let n=Object.create(ps.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?ps._wrap(e.zpp_inner):null:null}get density(){return this.zpp_inner.density*1e3}set density(e){if(e!=this.zpp_inner.density*1e3){if(e!==e)throw new Error("Error: FluidProperties::density cannot be NaN");this.zpp_inner.density=e/1e3,this.zpp_inner.invalidate()}}get viscosity(){return this.zpp_inner.viscosity}set viscosity(e){if(e!=this.zpp_inner.viscosity){if(e!==e)throw new Error("Error: FluidProperties::viscosity cannot be NaN");if(e<0)throw new Error("Error: FluidProperties::viscosity ("+e+") must be >= 0");this.zpp_inner.viscosity=e/1,this.zpp_inner.invalidate()}}get gravity(){return this.zpp_inner.wrap_gravity}set gravity(e){let n=me().zpp_nape;if(e==null){if(this.zpp_inner.wrap_gravity!=null){this.zpp_inner.wrap_gravity.zpp_inner._inuse=!1;let l=this.zpp_inner.wrap_gravity;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),l.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let i=l.zpp_inner;l.zpp_inner.outer=null,l.zpp_inner=null;let o=l;o.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=o:n.util.ZPP_PubPool.poolVec2=o,n.util.ZPP_PubPool.nextVec2=o,o.zpp_disp=!0;let r=i;r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r,this.zpp_inner.wrap_gravity=null}}else{if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity();let l=this.zpp_inner.wrap_gravity;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=e.zpp_inner;i._validate!=null&&i._validate();let o=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=e.zpp_inner;r._validate!=null&&r._validate();let a=e.zpp_inner.y;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),o!=o||a!=a)throw new Error("Error: Vec2 components cannot be NaN");let c;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=l.zpp_inner;if(u._validate!=null&&u._validate(),l.zpp_inner.x==o){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=l.zpp_inner;h._validate!=null&&h._validate(),c=l.zpp_inner.y==a}else c=!1;if(!c){l.zpp_inner.x=o,l.zpp_inner.y=a;let h=l.zpp_inner;h._invalidate!=null&&h._invalidate(h)}if(e.zpp_inner.weak){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=e.zpp_inner;if(h._immutable)throw new Error("Error: Vec2 is immutable");if(h._isimmutable!=null&&h._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let x=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let b=e;b.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=b:n.util.ZPP_PubPool.poolVec2=b,n.util.ZPP_PubPool.nextVec2=b,b.zpp_disp=!0;let _=x;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=_}}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get shapes(){if(this.zpp_inner.wrap_shapes==null){let e=me();this.zpp_inner.wrap_shapes=e.zpp_nape.util.ZPP_ShapeList.get(this.zpp_inner.shapes,!0)}return this.zpp_inner.wrap_shapes}copy(){let t=me().zpp_nape,n=new ps(this.zpp_inner.density*1e3,this.zpp_inner.viscosity);this.zpp_inner.userData!=null&&(n.zpp_inner.userData={...this.zpp_inner.userData});let l=this.zpp_inner.wrap_gravity;if(l==null){if(n.zpp_inner.wrap_gravity!=null){n.zpp_inner.wrap_gravity.zpp_inner._inuse=!1;let s=n.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),s.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let o=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let r=s;r.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=r:t.util.ZPP_PubPool.poolVec2=r,t.util.ZPP_PubPool.nextVec2=r,r.zpp_disp=!0;let a=o;a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=a,n.zpp_inner.wrap_gravity=null}}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");n.zpp_inner.wrap_gravity==null&&n.zpp_inner.getgravity();let s=n.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),l==null)throw new Error("Error: Cannot assign null Vec2");if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;o._validate!=null&&o._validate();let r=l.zpp_inner.x;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;a._validate!=null&&a._validate();let p=l.zpp_inner.y;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=s.zpp_inner;if(c._immutable)throw new Error("Error: Vec2 is immutable");if(c._isimmutable!=null&&c._isimmutable(),r!=r||p!=p)throw new Error("Error: Vec2 components cannot be NaN");let u;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=s.zpp_inner;if(h._validate!=null&&h._validate(),s.zpp_inner.x==r){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=s.zpp_inner;x._validate!=null&&x._validate(),u=s.zpp_inner.y==p}else u=!1;if(!u){s.zpp_inner.x=r,s.zpp_inner.y=p;let x=s.zpp_inner;x._invalidate!=null&&x._invalidate(x)}if(l.zpp_inner.weak){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=l.zpp_inner;if(x._immutable)throw new Error("Error: Vec2 is immutable");if(x._isimmutable!=null&&x._isimmutable(),l.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let b=l.zpp_inner;l.zpp_inner.outer=null,l.zpp_inner=null;let _=l;_.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=_:t.util.ZPP_PubPool.poolVec2=_,t.util.ZPP_PubPool.nextVec2=_,_.zpp_disp=!0;let d=b;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=d}}return n}toString(){return"{ density: "+this.zpp_inner.density*1e3+" viscosity: "+this.zpp_inner.viscosity+" gravity: "+String(this.zpp_inner.wrap_gravity)+" }"}};ps.__name__=["nape","phys","FluidProperties"];var qn=ps;En._wrapFn=V=>Ze(V,e=>{let t=Object.create(qn.prototype);return t.zpp_inner=e,e.outer=t,t});var Wo=me();Wo.phys.FluidProperties=qn;var Qs,Il,jl;function ro(V){Qs=V}var $s=class $s{constructor(){this._inner=void 0,this.zpp_inner_i=null}static _wrap(e){return e?e instanceof $s?e:e.isBody&&e.isBody()&&Qs?Qs(e):e.isShape&&e.isShape()&&Il?Il(e):e.isCompound&&e.isCompound()&&jl?jl(e):Ze(e,t=>{let n=Object.create($s.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i??t,n}):null}get id(){return this.zpp_inner_i.id}get userData(){return this.zpp_inner_i.userData==null&&(this.zpp_inner_i.userData={}),this.zpp_inner_i.userData}get group(){return this.zpp_inner_i.group==null?null:this.zpp_inner_i.group.outer}set group(e){this.zpp_inner_i.immutable_midstep("Interactor::group"),this.zpp_inner_i.setGroup(e==null?null:e.zpp_inner)}get cbTypes(){return this.zpp_inner_i.wrap_cbTypes==null&&this.zpp_inner_i.setupcbTypes(),this.zpp_inner_i.wrap_cbTypes}get castBody(){if(this.zpp_inner_i.ibody!=null){let e=this.zpp_inner_i.ibody.outer;return Qs?Qs(e):e}return null}get castShape(){if(this.zpp_inner_i.ishape!=null){let e=this.zpp_inner_i.ishape.outer;return Il?Il(e):e}return null}get castCompound(){if(this.zpp_inner_i.icompound!=null){let e=this.zpp_inner_i.icompound.outer;return jl?jl(e):e}return null}isShape(){return this.zpp_inner_i.ishape!=null}isBody(){return this.zpp_inner_i.ibody!=null}isCompound(){return this.zpp_inner_i.icompound!=null}toString(){return""}};$s.zpp_internalAlloc=!1;var $n=$s;var el,tl;function ao(V){el=V}function po(V){tl=V}var ei=class V extends $n{constructor(){super()}static _wrap(e){if(!e)return null;let t=e.isCircle?e.isCircle()?0:e.isPolygon?.()?1:-1:e.zpp_inner?.type??-1;return t===0&&el?el(e):t===1&&tl?tl(e):e.outer?e.outer:Ze(e,n=>{let l=Object.create(V.prototype);return l._inner=n,l.zpp_inner=n.zpp_inner??n,l.zpp_inner_i=n.zpp_inner_i??n,l})}get type(){return xi.types[this.zpp_inner.type]}isCircle(){return this.zpp_inner.type===0}isPolygon(){return this.zpp_inner.type===1}get body(){let e=this.zpp_inner;return e.body!=null?e.body.outer:null}set body(e){let t=this.zpp_inner;t.immutable_midstep("Shape::body");let n=t.body!=null?t.body.outer:null;if(n!==e&&(t.body!=null&&n.zpp_inner.wrap_shapes.remove(this),e!=null)){let l=e.zpp_inner.wrap_shapes;l.zpp_inner.reverse_flag?l.push(this):l.unshift(this)}}get castCircle(){let e=this.zpp_inner;if(e.type===0){let t=e.circle.outer_zn;return el?el(t):t}return null}get castPolygon(){let e=this.zpp_inner;if(e.type===1){let t=e.polygon.outer_zn;return tl?tl(t):t}return null}get worldCOM(){let e=this.zpp_inner;return e.wrap_worldCOM==null&&this._setupWorldCOM(),e.wrap_worldCOM}get localCOM(){let e=this.zpp_inner;return e.wrap_localCOM==null&&(e.type===0?e.circle.setupLocalCOM():e.polygon.setupLocalCOM()),e.wrap_localCOM}set localCOM(e){let t=this.zpp_inner;if(t.immutable_midstep("Body::localCOM"),e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Shape::localCOM cannot be null");t.wrap_localCOM==null&&(t.type===0?t.circle.setupLocalCOM():t.polygon.setupLocalCOM()),t.wrap_localCOM.set(e),e.zpp_inner.weak&&e.dispose()}get area(){let e=this.zpp_inner;return e.validate_area_inertia(),e.area}get inertia(){let e=this.zpp_inner;return e.validate_area_inertia(),e.inertia}get angDrag(){let e=this.zpp_inner;return e.validate_angDrag(),e.angDrag}get material(){return this.zpp_inner.material.wrapper()}set material(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::material"),e==null)throw new Error("Error: Cannot assign null as Shape material");t.setMaterial(e.zpp_inner)}get filter(){return this.zpp_inner.filter.wrapper()}set filter(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::filter"),e==null)throw new Error("Error: Cannot assign null as Shape filter");t.setFilter(e.zpp_inner)}get fluidProperties(){let e=this.zpp_inner;return e.immutable_midstep("Shape::fluidProperties"),e.fluidProperties==null&&e.setFluid(new qn().zpp_inner),e.fluidProperties.wrapper()}set fluidProperties(e){let t=this.zpp_inner;if(e==null)throw new Error("Error: Cannot assign null as Shape fluidProperties, disable fluids by setting fluidEnabled to false");t.setFluid(e.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new qn().zpp_inner)}get cbTypes(){this.zpp_inner_i.wrap_cbTypes==null&&this.zpp_inner_i.setupcbTypes();let e=this.zpp_inner_i.wrap_cbTypes;return{_inner:e,add(t){e.add(t._inner)},remove(t){e.remove(t._inner)},has(t){return e.has(t._inner)},clear(){e.clear()},get length(){return e.length}}}get fluidEnabled(){return this.zpp_inner.fluidEnabled}set fluidEnabled(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::fluidEnabled"),t.fluidEnabled=e,e&&t.fluidProperties==null){let n=new qn;t.setFluid(n.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new qn().zpp_inner),t.fluidProperties.wrapper()}t.wake()}get sensorEnabled(){return this.zpp_inner.sensorEnabled}set sensorEnabled(e){let t=this.zpp_inner;t.immutable_midstep("Shape::sensorEnabled"),t.sensorEnabled=e,t.wake()}get bounds(){return this.zpp_inner.aabb.wrapper()}translate(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::translate()"),e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Cannot displace Shape by null Vec2");if(e.lsq()>0){let n=e.zpp_inner;n._validate!=null&&n._validate();let l=n.x;n._validate!=null&&n._validate();let s=n.y;(t.type===0?t.circle:t.polygon).__translate(l,s)}return e.zpp_inner.weak&&e.dispose(),this}scale(e,t){let n=this.zpp_inner,l=me();if(n.immutable_midstep("Shape::scale()"),n.body!=null&&n.body.space!=null&&n.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e!==e||t!==t)throw new Error("Error: Cannot scale Shape by NaN");if(e===0||t===0)throw new Error("Error: Cannot Scale shape by a factor of 0");if(n.type===0){let s=e*e-t*t;if(s*s<l.Config.epsilon*l.Config.epsilon)n.circle.__scale(e,t);else throw new Error("Error: Cannot perform a non equal scaling on a Circle")}else n.polygon.__scale(e,t);return this}rotate(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::rotate()"),t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e!==e)throw new Error("Error: Cannot rotate Shape by NaN");if(e%(2*Math.PI)!==0){let l=Math.cos(e),s=Math.sin(e);t.type===0?t.circle.__rotate(s,l):t.polygon.__rotate(s,l)}return this}transform(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::transform()"),t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Cannot transform Shape by null matrix");let n=e._inner??e;if(n.singular())throw new Error("Error: Cannot transform Shape by a singular matrix");if(t.type===0)if(n.equiorthogonal())t.circle.__transform(n);else throw new Error("Error: Cannot transform Circle by a non equiorthogonal matrix");else t.polygon.__transform(n);return this}contains(e){let t=this.zpp_inner;if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Cannot check null point for containment");if((t.body!=null?t.body.outer:null)==null)throw new Error("Error: Shape is not well defined without a Body");gs.validateShape(t);let n=e.zpp_inner;n._validate!=null&&n._validate();let l=Ee.shapeContains(t,n);return n.weak&&e.dispose(),l}copy(){let e=this.zpp_inner.copy();return e instanceof V?e:V._wrap(e)}toString(){return(this.zpp_inner.type===0?"Circle":"Polygon")+"#"+this.zpp_inner_i.id}_setupWorldCOM(){let e=me(),t=this.zpp_inner,n=t.worldCOMx,l=t.worldCOMy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(de.poolVec2==null?s=new e.geom.Vec2:(s=de.poolVec2,de.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===de.nextVec2&&(de.nextVec2=null)),s.zpp_inner==null){let i;le.zpp_pool==null?i=new le:(i=le.zpp_pool,le.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,t.wrap_worldCOM=s,t.wrap_worldCOM.zpp_inner._inuse=!0,t.wrap_worldCOM.zpp_inner._immutable=!0,t.wrap_worldCOM.zpp_inner._validate=t.getworldCOM.bind(t)}};var Kl=class{constructor(){this.user_length=0;this.zip_length=!1;this.push_ite=null;this.at_ite=null;this.at_index=0;this.reverse_flag=!1;this.dontremove=!1;this.subber=null;this.post_adder=null;this.adder=null;this._modifiable=null;this._validate=null;this._invalidate=null;this._invalidated=!1;this.immutable=!1;this.inner=null;this.outer=null;this._invalidated=!0}valmod(){this.validate(),this.inner.modified&&(this.inner.pushmod&&(this.push_ite=null),this.at_ite=null,this.inner.modified=!1,this.inner.pushmod=!1,this.zip_length=!0)}modified(){this.zip_length=!0,this.at_ite=null,this.push_ite=null}modify_test(){this._modifiable!=null&&this._modifiable()}validate(){this._invalidated&&(this._invalidated=!1,this._validate!=null&&this._validate())}invalidate(){this._invalidated=!0,this._invalidate!=null&&this._invalidate(this)}};function Sn(V,e,t,n){let l=me(),s=l.__zpp;class i extends Kl{constructor(){super(),this.inner=new s.util[V]}static get(r,a=!1){let p=new l[e][t];return p.zpp_inner.inner=r,a&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}}return i.internal=!1,i.__name__=["zpp_nape","util",n],i.prototype.__class__=i,s.util[n]=i,i}var Yl=null,Ko=null,Xl=null;Yl=Sn("ZNPList_ZPP_Constraint","constraint","ConstraintList","ZPP_ConstraintList");Sn("ZNPList_ZPP_Body","phys","BodyList","ZPP_BodyList");Ko=Sn("ZNPList_ZPP_Interactor","phys","InteractorList","ZPP_InteractorList");Sn("ZNPList_ZPP_Compound","phys","CompoundList","ZPP_CompoundList");Sn("ZNPList_ZPP_Listener","callbacks","ListenerList","ZPP_ListenerList");Sn("ZNPList_ZPP_CbType","callbacks","CbTypeList","ZPP_CbTypeList");Sn("ZNPList_ZPP_GeomPoly","geom","GeomPolyList","ZPP_GeomPolyList");Sn("ZNPList_RayResult","geom","RayResultList","ZPP_RayResultList");Sn("ZNPList_ConvexResult","geom","ConvexResultList","ZPP_ConvexResultList");Sn("ZNPList_ZPP_Edge","shape","EdgeList","ZPP_EdgeList");Sn("ZNPList_ZPP_Shape","shape","ShapeList","ZPP_ShapeList");Sn("ZNPList_ZPP_InteractionGroup","dynamics","InteractionGroupList","ZPP_InteractionGroupList");Xl=Sn("ZNPList_ZPP_Arbiter","dynamics","ArbiterList","ZPP_ArbiterList");function Jn(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Un(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Tn(V){if(V!=null&&V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}function An(V){V.zpp_inner.weak&&V.dispose()}function ks(V,e,t,n,l){if(Tn(t),t==null)throw new Error("Error: Body::"+V+" cannot be null");return e==null&&n!=null&&(n(),e=l()),e.set(t),e}function Bl(V,e,t){return st.get(V,e,t)}function rn(V,e){return $[V]==null&&($.internal=!0,$[V]=e(),$.internal=!1),$[V]}var Ai=class Ai extends $n{constructor(t,n){super();this.debugDraw=!0;let l=new kn;this.zpp_inner=l,l.outer=this,l.outer_i=this,this.zpp_inner_i=l,this._inner=this,n!=null?(Tn(n),l.posx=Jn(n),l.posy=Un(n)):(l.posx=0,l.posy=0);let s=me(),i;if(t==null?i=rn("BodyType_DYNAMIC",()=>new s.phys.BodyType):i=t,l.immutable_midstep("Body::type"),l.world)throw new Error("Error: Space::world is immutable");if(kn.types[l.type]!==i){if(i==null)throw new Error("Error: Cannot use null BodyType");let o=co(i,s);o===1&&l.space!=null&&(l.velx=0,l.vely=0,l.angvel=0),l.invalidate_type(),l.space!=null?l.space.transmitType(l,o):l.type=o}n!=null&&An(n),l.insert_cbtype(gn.ANY_BODY.zpp_inner)}static _wrap(t){return t?t instanceof Ai?t:t instanceof kn?Ze(t,n=>{let l=Object.create(Ai.prototype);return l.zpp_inner=n,n.outer=l,n.outer_i=l,l.zpp_inner_i=n,l._inner=l,l.debugDraw=!0,l}):t.zpp_inner?Ai._wrap(t.zpp_inner):Ze(t,n=>{let l=Object.create(Ai.prototype);return l._inner=n,l}):null}get type(){return kn.types[this.zpp_inner.type]}set type(t){let n=this.zpp_inner;if(n.immutable_midstep("Body::type"),n.world)throw new Error("Error: Space::world is immutable");if(kn.types[n.type]!==t){if(t==null)throw new Error("Error: Cannot use null BodyType");let l=me(),s=co(t,l);s===1&&n.space!=null&&(n.velx=0,n.vely=0,n.angvel=0),n.invalidate_type(),n.space!=null?n.space.transmitType(n,s):n.type=s}}isStatic(){return this.zpp_inner.type===1}isDynamic(){return this.zpp_inner.type===2}isKinematic(){return this.zpp_inner.type===3}get position(){return this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),this.zpp_inner.wrap_pos}set position(t){ks("position",this.zpp_inner.wrap_pos,t,()=>this.zpp_inner.setupPosition(),()=>this.zpp_inner.wrap_pos),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition()}get rotation(){return this.zpp_inner.rot}set rotation(t){let n=this.zpp_inner;if(n.immutable_midstep("Body::rotation"),n.world)throw new Error("Error: Space::world is immutable");if(n.type===1&&n.space!=null)throw new Error("Error: Static objects cannot be rotated once inside a Space");if(n.rot!==t){if(t!==t)throw new Error("Error: Body::rotation cannot be NaN");n.rot=t,n.invalidate_rot(),n.wake()}}get velocity(){return this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity(),this.zpp_inner.wrap_vel}set velocity(t){ks("velocity",this.zpp_inner.wrap_vel,t,()=>this.zpp_inner.setupVelocity(),()=>this.zpp_inner.wrap_vel),this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity()}get angularVel(){return this.zpp_inner.angvel}set angularVel(t){let n=this.zpp_inner;if(n.world)throw new Error("Error: Space::world is immutable");if(n.angvel!==t){if(t!==t)throw new Error("Error: Body::angularVel cannot be NaN");if(n.type===1)throw new Error("Error: A static object cannot be given a velocity");n.angvel=t,n.wake()}}get kinematicVel(){return this.zpp_inner.wrap_kinvel==null&&this.zpp_inner.setupkinvel(),this.zpp_inner.wrap_kinvel}set kinematicVel(t){ks("kinematicVel",this.zpp_inner.wrap_kinvel,t,()=>this.zpp_inner.setupkinvel(),()=>this.zpp_inner.wrap_kinvel),this.zpp_inner.wrap_kinvel==null&&this.zpp_inner.setupkinvel()}get kinAngVel(){return this.zpp_inner.kinangvel}set kinAngVel(t){let n=this.zpp_inner;if(n.world)throw new Error("Error: Space::world is immutable");if(n.kinangvel!==t){if(t!==t)throw new Error("Error: Body::kinAngVel cannot be NaN");n.kinangvel=t,n.wake()}}get surfaceVel(){return this.zpp_inner.wrap_svel==null&&this.zpp_inner.setupsvel(),this.zpp_inner.wrap_svel}set surfaceVel(t){ks("surfaceVel",this.zpp_inner.wrap_svel,t,()=>this.zpp_inner.setupsvel(),()=>this.zpp_inner.wrap_svel),this.zpp_inner.wrap_svel==null&&this.zpp_inner.setupsvel()}get force(){return this.zpp_inner.wrap_force==null&&this.zpp_inner.setupForce(),this.zpp_inner.wrap_force}set force(t){ks("force",this.zpp_inner.wrap_force,t,()=>this.zpp_inner.setupForce(),()=>this.zpp_inner.wrap_force),this.zpp_inner.wrap_force==null&&this.zpp_inner.setupForce()}get torque(){return this.zpp_inner.torque}set torque(t){let n=this.zpp_inner;if(n.world)throw new Error("Error: Space::world is immutable");if(n.type!==2)throw new Error("Error: Non-dynamic body cannot have torque applied.");if(t!==t)throw new Error("Error: Body::torque cannot be NaN");n.torque!==t&&(n.torque=t,n.wake())}get mass(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(this.zpp_inner.validate_mass(),this.zpp_inner.massMode===0&&this.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");return this.zpp_inner.cmass}set mass(t){if(this.zpp_inner.immutable_midstep("Body::mass"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: Mass cannot be NaN");if(t<=0)throw new Error("Error: Mass must be strictly positive");if(t>=1/0)throw new Error("Error: Mass cannot be infinite, use allowMovement = false instead");this.zpp_inner.massMode=1,this.zpp_inner.cmass=t,this.zpp_inner.invalidate_mass()}get inertia(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no inertia");if(this.zpp_inner.validate_inertia(),this.zpp_inner.inertiaMode===0&&this.zpp_inner.shapes.head==null)throw new Error("Error: Given current inertia mode flag, Body::inertia only makes sense if Body contains Shapes");return this.zpp_inner.cinertia}set inertia(t){if(this.zpp_inner.immutable_midstep("Body::inertia"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: Inertia cannot be NaN");if(t<=0)throw new Error("Error: Inertia must be strictly positive");if(t>=1/0)throw new Error("Error: Inertia cannot be infinite, use allowRotation = false instead");this.zpp_inner.inertiaMode=1,this.zpp_inner.cinertia=t,this.zpp_inner.invalidate_inertia()}get constraintMass(){return this.zpp_inner.world||this.zpp_inner.validate_mass(),this.zpp_inner.smass}get constraintInertia(){return this.zpp_inner.world||this.zpp_inner.validate_inertia(),this.zpp_inner.sinertia}get gravMass(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no gravMass");if(this.zpp_inner.validate_gravMass(),this.zpp_inner.shapes.head==null&&this.zpp_inner.massMode===0&&this.zpp_inner.gravMassMode!==1)throw new Error("Error: Given current mass/gravMass modes; Body::gravMass only makes sense if it contains Shapes");return this.zpp_inner.gravMass}set gravMass(t){if(this.zpp_inner.immutable_midstep("Body::gravMass"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: gravMass cannot be NaN");this.zpp_inner.gravMassMode=1,this.zpp_inner.gravMass=t,this.zpp_inner.invalidate_gravMass()}get gravMassScale(){if(this.zpp_inner.validate_gravMassScale(),this.zpp_inner.shapes.head==null&&this.zpp_inner.massMode===0&&this.zpp_inner.gravMassMode!==2)throw new Error("Error: Given current mass/gravMass modes; Body::gravMassScale only makes sense if it contains Shapes");return this.zpp_inner.gravMassScale}set gravMassScale(t){if(this.zpp_inner.immutable_midstep("Body::gravMassScale"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: gravMassScale cannot be NaN");this.zpp_inner.gravMassMode=2,this.zpp_inner.gravMassScale=t,this.zpp_inner.invalidate_gravMassScale()}get isBullet(){return this.zpp_inner.bulletEnabled}set isBullet(t){this.zpp_inner.bulletEnabled=t}get disableCCD(){return this.zpp_inner.disableCCD}set disableCCD(t){this.zpp_inner.disableCCD=t}get allowMovement(){return!this.zpp_inner.nomove}set allowMovement(t){this.zpp_inner.immutable_midstep("Body::"+(t==null?"null":""+t)),!this.zpp_inner.nomove!==t&&(this.zpp_inner.nomove=!t,this.zpp_inner.invalidate_mass())}get allowRotation(){return!this.zpp_inner.norotate}set allowRotation(t){this.zpp_inner.immutable_midstep("Body::"+(t==null?"null":""+t)),!this.zpp_inner.norotate!==t&&(this.zpp_inner.norotate=!t,this.zpp_inner.invalidate_inertia())}get isSleeping(){if(this.zpp_inner.space==null)throw new Error("Error: isSleeping makes no sense if the object is not contained within a Space");return this.zpp_inner.component.sleeping}get shapes(){return new Vl(this.zpp_inner.wrap_shapes,ei._wrap)}get space(){return this.zpp_inner.space==null?null:Vi._wrap(this.zpp_inner.space.outer)}set space(t){let n=t!=null?t._inner??t:null;if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let l=this.zpp_inner.space==null?null:this.zpp_inner.space.outer;if(l!==n&&(l!=null&&(this.zpp_inner.component.woken=!1,l.zpp_inner.wrap_bodies.remove(this)),n!=null)){let s=n.zpp_inner.wrap_bodies;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(t){let n=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(n!==t&&(n?.zpp_inner.wrap_bodies.remove(this),t!=null)){let l=t.zpp_inner.wrap_bodies;l.zpp_inner.reverse_flag?l.push(this):l.unshift(this)}}get bounds(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no bounds");return Hs._wrap(this.zpp_inner.aabb.wrapper())}get constraintVelocity(){return this.zpp_inner.wrapcvel==null&&this.zpp_inner.setup_cvel(),this.zpp_inner.wrapcvel}get localCOM(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no localCOM");if(this.zpp_inner.wrap_localCOM==null){let t=st.get(this.zpp_inner.localCOMx,this.zpp_inner.localCOMy);this.zpp_inner.wrap_localCOM=t,t.zpp_inner._inuse=!0,t.zpp_inner._immutable=!0,t.zpp_inner._validate=()=>this.zpp_inner.getlocalCOM()}return this.zpp_inner.wrap_localCOM}get worldCOM(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");if(this.zpp_inner.wrap_worldCOM==null){let t=st.get(this.zpp_inner.worldCOMx,this.zpp_inner.worldCOMy);this.zpp_inner.wrap_worldCOM=t,t.zpp_inner._inuse=!0,t.zpp_inner._immutable=!0,t.zpp_inner._validate=()=>this.zpp_inner.getworldCOM()}return this.zpp_inner.wrap_worldCOM}get massMode(){let t=me(),n=rn("MassMode_DEFAULT",()=>new t.phys.MassMode),l=rn("MassMode_FIXED",()=>new t.phys.MassMode);return[n,l][this.zpp_inner.massMode]}set massMode(t){let n=me();if(this.zpp_inner.immutable_midstep("Body::massMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: cannot use null massMode");let l=rn("MassMode_DEFAULT",()=>new n.phys.MassMode);this.zpp_inner.massMode=t===l?0:1,this.zpp_inner.invalidate_mass()}get inertiaMode(){let t=me(),n=rn("InertiaMode_DEFAULT",()=>new t.phys.InertiaMode),l=rn("InertiaMode_FIXED",()=>new t.phys.InertiaMode);return[n,l][this.zpp_inner.inertiaMode]}set inertiaMode(t){let n=me();if(this.zpp_inner.immutable_midstep("Body::inertiaMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot use null InertiaMode");let l=rn("InertiaMode_FIXED",()=>new n.phys.InertiaMode);this.zpp_inner.inertiaMode=t===l?1:0,this.zpp_inner.invalidate_inertia()}get gravMassMode(){let t=me(),n=rn("GravMassMode_DEFAULT",()=>new t.phys.GravMassMode),l=rn("GravMassMode_FIXED",()=>new t.phys.GravMassMode),s=rn("GravMassMode_SCALED",()=>new t.phys.GravMassMode);return[n,l,s][this.zpp_inner.gravMassMode]}set gravMassMode(t){let n=me();if(this.zpp_inner.immutable_midstep("Body::gravMassMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot use null gravMassMode");let l=rn("GravMassMode_SCALED",()=>new n.phys.GravMassMode);if(t===l)this.zpp_inner.gravMassMode=2;else{let s=rn("GravMassMode_DEFAULT",()=>new n.phys.GravMassMode);this.zpp_inner.gravMassMode=t===s?0:1}this.zpp_inner.invalidate_gravMass()}copy(){if(this.zpp_inner.world)throw new Error("Error: Space::world cannot be copied");return this.zpp_inner.copy()}toString(){let t=this.zpp_inner;return(t.world?"(space::world":"("+(t.type===2?"dynamic":t.type===1?"static":"kinematic"))+")#"+this.zpp_inner_i.id}integrate(t){if(t!==t)throw new Error("Cannot integrate by NaN time");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t===0)return this;let n=this.zpp_inner;n.sweepTime=0,n.sweep_angvel=n.angvel;let l=t-n.sweepTime;if(l!==0&&(n.sweepTime=t,n.posx+=n.velx*l,n.posy+=n.vely*l,n.angvel!==0)){let s=n.sweep_angvel*l;if(n.rot+=s,s*s>1e-4)n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot);else{let i=s*s,o=1-.5*i,r=1-i*i/8,a=(o*n.axisx+s*n.axisy)*r;n.axisy=(o*n.axisy-s*n.axisx)*r,n.axisx=a}}return ho(n),n.zip_worldCOM=!0,n.zip_axis=!0,ho(n),n.zip_worldCOM=!0,n.sweepTime=0,this}localPointToWorld(t,n=!1){if(Tn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let l=Jn(t),s=Un(t),i=this.zpp_inner.axisy*l-this.zpp_inner.axisx*s,o=l*this.zpp_inner.axisx+s*this.zpp_inner.axisy;return An(t),Bl(i+this.zpp_inner.posx,o+this.zpp_inner.posy,n)}worldPointToLocal(t,n=!1){if(Tn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let l=Jn(t)-this.zpp_inner.posx,s=Un(t)-this.zpp_inner.posy,i=l*this.zpp_inner.axisy+s*this.zpp_inner.axisx,o=s*this.zpp_inner.axisy-l*this.zpp_inner.axisx;return An(t),Bl(i,o,n)}localVectorToWorld(t,n=!1){if(Tn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let l=Jn(t),s=Un(t),i=this.zpp_inner.axisy*l-this.zpp_inner.axisx*s,o=l*this.zpp_inner.axisx+s*this.zpp_inner.axisy;return An(t),Bl(i,o,n)}worldVectorToLocal(t,n=!1){if(Tn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let l=Jn(t),s=Un(t),i=l*this.zpp_inner.axisy+s*this.zpp_inner.axisx,o=s*this.zpp_inner.axisy-l*this.zpp_inner.axisx;return An(t),Bl(i,o,n)}applyImpulse(t,n,l=!1){if(Tn(t),n!=null&&Tn(n),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot apply null impulse to Body");if(l&&this.isSleeping)return An(t),n!=null&&An(n),this;this.zpp_inner.validate_mass();let s=this.zpp_inner.imass,i=Jn(t),o=Un(t);if(this.zpp_inner.velx+=i*s,this.zpp_inner.vely+=o*s,n!=null){let r=Jn(n)-this.zpp_inner.posx,a=Un(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(o*r-i*a)*this.zpp_inner.iinertia,An(n)}return l||this.zpp_inner.type===2&&this.zpp_inner.wake(),An(t),this}applyAngularImpulse(t,n=!1){if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");return n&&this.isSleeping?this:(this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=t*this.zpp_inner.iinertia,n||this.zpp_inner.type===2&&this.zpp_inner.wake(),this)}setVelocityFromTarget(t,n,l){if(Tn(t),t==null)throw new Error("Cannot set velocity for null target position");if(l===0)throw new Error("deltaTime cannot be 0 for setVelocityFromTarget");let s=1/l;this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity(),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let i=t.sub(this.zpp_inner.wrap_pos,!0).muleq(s);this.zpp_inner.wrap_vel.set(i);let o=(n-this.zpp_inner.rot)*s;if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.angvel!==o){if(o!==o)throw new Error("Error: Body::angularVel cannot be NaN");if(this.zpp_inner.type===1)throw new Error("Error: A static object cannot be given a velocity");this.zpp_inner.angvel=o,this.zpp_inner.wake()}return An(t),this}translateShapes(t){if(this.zpp_inner.immutable_midstep("Body::translateShapes()"),Tn(t),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot displace by null Vec2");let n=t.zpp_inner.weak;t.zpp_inner.weak=!1;let l=this.zpp_inner.shapes.head;for(;l!=null;)l.elt.outer.translate(t),l=l.next;return t.zpp_inner.weak=n,An(t),this}rotateShapes(t){if(this.zpp_inner.immutable_midstep("Body::rotateShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.rotate(t),n=n.next;return this}scaleShapes(t,n){if(this.zpp_inner.immutable_midstep("Body::scaleShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let l=this.zpp_inner.shapes.head;for(;l!=null;)l.elt.outer.scale(t,n),l=l.next;return this}transformShapes(t){if(this.zpp_inner.immutable_midstep("Body::transformShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.transform(t),n=n.next;return this}align(){if(this.zpp_inner.immutable_midstep("Body::align()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.shapes.head==null)throw new Error("Error: Cannot align empty Body");this.zpp_inner.validate_localCOM();let t=st.get(-this.zpp_inner.localCOMx,-this.zpp_inner.localCOMy);this.translateShapes(t);let n=this.localVectorToWorld(t);return this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),this.zpp_inner.wrap_pos.subeq(n),this.zpp_inner.pre_posx<1/0&&(this.zpp_inner.pre_posx-=Jn(n),this.zpp_inner.pre_posy-=Un(n)),t.dispose(),n.dispose(),this}rotate(t,n){if(Tn(t),t==null)throw new Error("Error: Cannot rotate about a null Vec2");if(n!==n)throw new Error("Error: Cannot rotate by NaN radians");let l=t.zpp_inner.weak;t.zpp_inner.weak=!1,this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let s=this.zpp_inner.wrap_pos.sub(t);s.rotate(n);let i=t.add(s,!0);ks("position",this.zpp_inner.wrap_pos,i,()=>this.zpp_inner.setupPosition(),()=>this.zpp_inner.wrap_pos),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),s.dispose();{let o=this.zpp_inner.rot+n,r=this.zpp_inner;if(r.immutable_midstep("Body::rotation"),r.world)throw new Error("Error: Space::world is immutable");if(r.type===1&&r.space!=null)throw new Error("Error: Static objects cannot be rotated once inside a Space");if(r.rot!==o){if(o!==o)throw new Error("Error: Body::rotation cannot be NaN");r.rot=o,r.invalidate_rot(),r.wake()}}return t.zpp_inner.weak=l,An(t),this}setShapeMaterials(t){if(this.zpp_inner.immutable_midstep("Body::setShapeMaterials()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let l=n.elt.outer;if(l.zpp_inner.immutable_midstep("Shape::material"),t==null)throw new Error("Error: Cannot assign null as Shape material");l.zpp_inner.setMaterial(t.zpp_inner),l.zpp_inner.material.wrapper(),n=n.next}return this}setShapeFilters(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFilters()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let l=n.elt.outer;if(l.zpp_inner.immutable_midstep("Shape::filter"),t==null)throw new Error("Error: Cannot assign null as Shape filter");l.zpp_inner.setFilter(t.zpp_inner),l.zpp_inner.filter.wrapper(),n=n.next}return this}setShapeFluidProperties(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFluidProperties()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=me(),l=this.zpp_inner.shapes.head;for(;l!=null;){let s=l.elt.outer;if(t==null)throw new Error("Error: Cannot assign null as Shape fluidProperties, disable fluids by setting fluidEnabled to false");s.zpp_inner.setFluid(t.zpp_inner),s.zpp_inner.immutable_midstep("Shape::fluidProperties"),s.zpp_inner.fluidProperties==null&&s.zpp_inner.setFluid(new n.phys.FluidProperties().zpp_inner),s.zpp_inner.fluidProperties.wrapper(),l=l.next}return this}contains(t){if(Tn(t),t==null)throw new Error("Error: Cannot check containment of null point");let n=t.zpp_inner.weak;t.zpp_inner.weak=!1;let l=!1,s=this.zpp_inner.shapes.head;for(;s!=null;){if(s.elt.outer.contains(t)){l=!0;break}s=s.next}return t.zpp_inner.weak=n,An(t),l}connectedBodies(t=-1,n=null){return this.zpp_inner.connectedBodies(t,n)}interactingBodies(t=null,n=-1,l=null){let s;if(t==null)s=Ae.COL|Ae.SENSOR|Ae.FLUID;else{let i=me(),o=rn("InteractionType_COLLISION",()=>new i.callbacks.InteractionType);if(t===o)s=Ae.COL;else{let r=rn("InteractionType_SENSOR",()=>new i.callbacks.InteractionType);s=t===r?Ae.SENSOR:Ae.FLUID}}return this.zpp_inner.interactingBodies(s,l)}normalImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ae.COL,l=>l.collisionArbiter.normalImpulse(this,n),t)}tangentImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ae.COL,l=>l.collisionArbiter.tangentImpulse(this,n),t)}totalContactsImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ae.COL,l=>l.collisionArbiter.totalImpulse(this,n),t)}rollingImpulse(t=null,n=!1){let l=0,i=this._getArbiters().iterator();for(;;){i.zpp_inner.zpp_inner.valmod();let o=i.zpp_inner.zpp_gl();if(i.zpp_critical=!0,i.zpp_i>=o){i.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1;let r=i.zpp_inner.at(i.zpp_i++),a=r.zpp_inner;a.type===Ae.COL&&(t!=null&&a.b2!==t.zpp_inner&&a.b1!==t.zpp_inner||(l+=r.collisionArbiter.rollingImpulse(this,n)))}return l}buoyancyImpulse(t=null){return this._arbiterImpulseQuery(Ae.FLUID,n=>n.fluidArbiter.buoyancyImpulse(this),t)}dragImpulse(t=null){return this._arbiterImpulseQuery(Ae.FLUID,n=>n.fluidArbiter.dragImpulse(this),t)}totalFluidImpulse(t=null){return this._arbiterImpulseQuery(Ae.FLUID,n=>n.fluidArbiter.totalImpulse(this),t)}constraintsImpulse(){let t=0,n=0,l=0,s=this.zpp_inner.constraints.head;for(;s!=null;){let o=s.elt.outer.bodyImpulse(this),r=o.zpp_inner;r._validate!=null&&r._validate(),t+=r.x,r._validate!=null&&r._validate(),n+=r.y,r._validate!=null&&r._validate(),l+=r.z,o.dispose(),s=s.next}return yi.get(t,n,l)}totalImpulse(t=null,n=!1){let l=0,s=0,i=0,r=this._getArbiters().iterator();for(;;){r.zpp_inner.zpp_inner.valmod();let p=r.zpp_inner.zpp_gl();if(r.zpp_critical=!0,r.zpp_i>=p){r.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let u=r.zpp_inner.at(r.zpp_i++).zpp_inner;if(u.type===Ae.SENSOR||t!=null&&u.b2!==t.zpp_inner&&u.b1!==t.zpp_inner)continue;let h=u.wrapper().totalImpulse(this,n),x=h.zpp_inner;x._validate!=null&&x._validate(),l+=x.x,x._validate!=null&&x._validate(),s+=x.y,x._validate!=null&&x._validate(),i+=x.z,h.dispose()}let a=this.zpp_inner.constraints.head;for(;a!=null;){let p=a.elt;if(p.outer.active){let c=p.outer.bodyImpulse(this),u=c.zpp_inner;u._validate!=null&&u._validate(),l+=u.x,u._validate!=null&&u._validate(),s+=u.y,u._validate!=null&&u._validate(),i+=u.z,c.dispose()}a=a.next}return yi.get(l,s,i)}crushFactor(){if(this.zpp_inner.space==null)throw new Error("Error: Makes no sense to see how much an object not taking part in a simulation is being crushed");let t=0,n=st.get(0,0),s=this._getArbiters().iterator();for(;;){s.zpp_inner.zpp_inner.valmod();let x=s.zpp_inner.zpp_gl();if(s.zpp_critical=!0,s.zpp_i>=x){s.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1;let _=s.zpp_inner.at(s.zpp_i++).totalImpulse(this),d=_.xy();n.addeq(d);let f=Jn(d),m=Un(d);t+=Math.sqrt(f*f+m*m),d.dispose(),_.dispose()}let o=this._getConstraints();o.zpp_inner.valmod();let r=me().constraint.ConstraintIterator.get(o);for(;;){r.zpp_inner.zpp_inner.valmod();let x=r.zpp_inner;x.zpp_inner.valmod(),x.zpp_inner.zip_length&&(x.zpp_inner.zip_length=!1,x.zpp_inner.user_length=x.zpp_inner.inner.length);let b=x.zpp_inner.user_length;if(r.zpp_critical=!0,r.zpp_i>=b){r.zpp_next=me().constraint.ConstraintIterator.zpp_pool,me().constraint.ConstraintIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let d=r.zpp_inner.at(r.zpp_i++).bodyImpulse(this),f=d.xy();n.addeq(f);let m=Jn(f),z=Un(f);t+=Math.sqrt(m*m+z*z),f.dispose(),d.dispose()}let a=Jn(n),p=Un(n),c=Math.sqrt(a*a+p*p),u=this.mass,h=(t-c)/(u*this.zpp_inner.space.pre_dt);return n.dispose(),h}_getArbiters(){return this.zpp_inner.wrap_arbiters==null&&(this.zpp_inner.wrap_arbiters=Xl.get(this.zpp_inner.arbiters,!0)),this.zpp_inner.wrap_arbiters}_getConstraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=Yl.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}_arbiterImpulseQuery(t,n,l){let s=0,i=0,o=0,a=this._getArbiters().iterator();for(;;){a.zpp_inner.zpp_inner.valmod();let p=a.zpp_inner.zpp_gl();if(a.zpp_critical=!0,a.zpp_i>=p){a.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=a,a.zpp_inner=null;break}a.zpp_critical=!1;let c=a.zpp_inner.at(a.zpp_i++),u=c.zpp_inner;if(u.type!==t||l!=null&&u.b2!==l.zpp_inner&&u.b1!==l.zpp_inner)continue;let h=n(c),x=h.zpp_inner;x._validate!=null&&x._validate(),s+=x.x,x._validate!=null&&x._validate(),i+=x.y,x._validate!=null&&x._validate(),o+=x.z,h.dispose()}return yi.get(s,i,o)}};Ai.__name__=["nape","phys","Body"],Ai.__super__=$n;var tt=Ai;function co(V,e){let t=rn("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(V===t)return 2;let n=rn("BodyType_KINEMATIC",()=>new e.phys.BodyType);return V===n?3:1}function ho(V){let e=V.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}}var Yo=me();Yo.phys.Body=tt;ro(V=>tt._wrap(V));var Ii={SHAPES:1,JOINTS:2,CONTACTS:4,AABB:8,CENTER_OF_MASS:16,VELOCITIES:32,ALL:63};var Vi=class V{constructor(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=e==null?null:e.zpp_inner;this.zpp_inner=new di(n,t),this.zpp_inner.outer=this,e!=null&&e.zpp_inner?.weak&&e.dispose()}get _inner(){return this}static _wrap(e){return e?e instanceof V?e:e instanceof di?e.outer?e.outer:Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?.outer?e.zpp_inner.outer:Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n}):null}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get gravity(){return this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity(),this.zpp_inner.wrap_gravity}set gravity(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Space::gravity cannot be null");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity(),this.zpp_inner.wrap_gravity.set(e),e.zpp_inner?.weak&&e.dispose()}get broadphase(){return this.zpp_inner.bphase.is_sweep?($.Broadphase_SWEEP_AND_PRUNE==null&&($.internal=!0,$.Broadphase_SWEEP_AND_PRUNE=new(me()).space.Broadphase,$.internal=!1),$.Broadphase_SWEEP_AND_PRUNE):($.Broadphase_DYNAMIC_AABB_TREE==null&&($.internal=!0,$.Broadphase_DYNAMIC_AABB_TREE=new(me()).space.Broadphase,$.internal=!1),$.Broadphase_DYNAMIC_AABB_TREE)}get sortContacts(){return this.zpp_inner.sortcontacts}set sortContacts(e){this.zpp_inner.sortcontacts=e}get worldAngularDrag(){return this.zpp_inner.global_ang_drag}set worldAngularDrag(e){if(e!==e)throw new Error("Error: Space::worldAngularDrag cannot be NaN");this.zpp_inner.global_ang_drag=e}get worldLinearDrag(){return this.zpp_inner.global_lin_drag}set worldLinearDrag(e){if(e!==e)throw new Error("Error: Space::worldLinearDrag cannot be NaN");this.zpp_inner.global_lin_drag=e}get compounds(){return this.zpp_inner.wrap_compounds}get bodies(){return this.zpp_inner.wrap_bodies}get liveBodies(){return this.zpp_inner.wrap_live}get constraints(){return this.zpp_inner.wrap_constraints}get liveConstraints(){return this.zpp_inner.wrap_livecon}get world(){return tt._wrap(this.zpp_inner.__static)}get arbiters(){if(this.zpp_inner.wrap_arbiters==null){let e=new Gn;e.space=this.zpp_inner,this.zpp_inner.wrap_arbiters=e}return this.zpp_inner.wrap_arbiters}get listeners(){return this.zpp_inner.wrap_listeners}get timeStamp(){return this.zpp_inner.stamp}get elapsedTime(){return this.zpp_inner.time}step(e,t=10,n=10){if(e!==e)throw new Error("Error: deltaTime cannot be NaN");if(e<=0)throw new Error("Error: deltaTime must be strictly positive");if(t<=0)throw new Error("Error: must use atleast one velocity iteration");if(n<=0)throw new Error("Error: must use atleast one position iteration");this.zpp_inner.step(e,t,n)}clear(){if(this.zpp_inner.midstep)throw new Error("Error: Space::clear() cannot be called during space step()");this.zpp_inner.clear()}visitBodies(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitBodies");let t=me(),n=this.zpp_inner.wrap_bodies;n.zpp_inner.valmod();let l=t.phys.BodyIterator.get(n);for(;;){l.zpp_inner.zpp_inner.valmod();let o=l.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=r){l.zpp_next=t.phys.BodyIterator.zpp_pool,t.phys.BodyIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,e(l.zpp_inner.at(l.zpp_i++))}let s=this.zpp_inner.wrap_compounds;s.zpp_inner.valmod();let i=t.phys.CompoundIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let o=i.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(i.zpp_critical=!0,i.zpp_i>=r){i.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1,i.zpp_inner.at(i.zpp_i++).visitBodies(e)}}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitConstraints");let t=me(),n=this.zpp_inner.wrap_constraints;n.zpp_inner.valmod();let l=t.constraint.ConstraintIterator.get(n);for(;;){l.zpp_inner.zpp_inner.valmod();let o=l.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=r){l.zpp_next=t.constraint.ConstraintIterator.zpp_pool,t.constraint.ConstraintIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,e(l.zpp_inner.at(l.zpp_i++))}let s=this.zpp_inner.wrap_compounds;s.zpp_inner.valmod();let i=t.phys.CompoundIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let o=i.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(i.zpp_critical=!0,i.zpp_i>=r){i.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1,i.zpp_inner.at(i.zpp_i++).visitConstraints(e)}}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitCompounds");let t=me(),n=this.zpp_inner.wrap_compounds;n.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(n);for(;;){l.zpp_inner.zpp_inner.valmod();let s=l.zpp_inner;s.zpp_inner.valmod(),s.zpp_inner.zip_length&&(s.zpp_inner.zip_length=!1,s.zpp_inner.user_length=s.zpp_inner.inner.length);let i=s.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=i){l.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1;let o=l.zpp_inner.at(l.zpp_i++);e(o),o.visitCompounds(e)}}interactionType(e,t){if(e==null||t==null)throw new Error("Error: Cannot evaluate interaction type for null shapes");let n=e.zpp_inner,l=t.zpp_inner;if((n.body!=null?n.body.outer:null)==null||(l.body!=null?l.body.outer:null)==null)throw new Error("Error: Cannot evaluate interaction type for shapes not part of a Body");let s=n.body,i=l.body;if(s.type==1&&i.type==1||s.outer==i.outer)return null;let o=!1,r=s.constraints.head;for(;r!=null;){let h=r.elt;if(h.ignore&&h.pair_exists(s.id,i.id)){o=!0;break}r=r.next}let a;if(o)a=!1;else{let h=n;for(;h!=null&&h.group==null;)h.ishape!=null?h=h.ishape.body:h.icompound!=null?h=h.icompound.compound:h=h.ibody.compound;let x=h==null?null:h.group,b;if(x==null)b=!1;else{let _=l;for(;_!=null&&_.group==null;)_.ishape!=null?_=_.ishape.body:_.icompound!=null?_=_.icompound.compound:_=_.ibody.compound;let d=_==null?null:_.group;if(d==null)b=!1;else{let f=!1;for(;x!=null&&d!=null;){if(x==d){f=x.ignore;break}x.depth<d.depth?d=d.group:x=x.group}b=f}}a=!b}if(!a)return null;let p=n.filter,c=l.filter,u=s.imass==0&&i.imass==0&&s.iinertia==0&&i.iinertia==0;return(n.sensorEnabled||l.sensorEnabled)&&(p.sensorMask&c.sensorGroup)!=0&&(c.sensorMask&p.sensorGroup)!=0?($.InteractionType_SENSOR==null&&($.internal=!0,$.InteractionType_SENSOR=new(me()).callbacks.InteractionType,$.internal=!1),$.InteractionType_SENSOR):(n.fluidEnabled||l.fluidEnabled)&&(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0&&!u?($.InteractionType_FLUID==null&&($.internal=!0,$.InteractionType_FLUID=new(me()).callbacks.InteractionType,$.internal=!1),$.InteractionType_FLUID):(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!u?($.InteractionType_COLLISION==null&&($.internal=!0,$.InteractionType_COLLISION=new(me()).callbacks.InteractionType,$.internal=!1),$.InteractionType_COLLISION):null}shapesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes under a null point :)");let l=e.zpp_inner;l._validate!=null&&l._validate();let s=l.x;l._validate!=null&&l._validate();let i=l.y,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.shapesUnderPoint(s,i,o,n);return l.weak&&e.dispose(),r}bodiesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects under a null point :)");let l=e.zpp_inner;l._validate!=null&&l._validate();let s=l.x;l._validate!=null&&l._validate();let i=l.y,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.bodiesUnderPoint(s,i,o,n);return l.weak&&e.dispose(),r}shapesInAABB(e,t=!1,n=!0,l,s){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null AABB :)");let i=e.zpp_inner;if(i._validate!=null&&i._validate(),i.maxx-i.minx==0||i.maxy-i.miny==0)throw new Error("Error: Cannot evaluate shapes in degenerate AABB :/");let o=l==null?null:l.zpp_inner??l;return this.zpp_inner.shapesInAABB(e,n,t,o,s)}bodiesInAABB(e,t=!1,n=!0,l,s){if(e==null)throw new Error("Error: Cannot evaluate objects in a null AABB :)");let i=e.zpp_inner;if(i._validate!=null&&i._validate(),i.maxx-i.minx==0||i.maxy-i.miny==0)throw new Error("Error: Cannot evaluate objects in degenerate AABB :/");let o=l==null?null:l.zpp_inner??l;return this.zpp_inner.bodiesInAABB(e,n,t,o,s)}shapesInCircle(e,t,n=!1,l,s){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let i=l==null?null:l.zpp_inner??l,o=this.zpp_inner.shapesInCircle(e,t,n,i,s);return e.zpp_inner?.weak&&e.dispose(),o}bodiesInCircle(e,t,n=!1,l,s){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let i=l==null?null:l.zpp_inner??l,o=this.zpp_inner.bodiesInCircle(e,t,n,i,s);return e.zpp_inner?.weak&&e.dispose(),o}shapesInShape(e,t=!1,n,l){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null shapes :)");let s=e.zpp_inner;if((s.body!=null?s.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(s.type==1){let o=s.polygon.valid();if($.ValidationResult_VALID==null&&($.internal=!0,$.ValidationResult_VALID=new(me()).shape.ValidationResult,$.internal=!1),o!=$.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.toString())}let i=n==null?null:n.zpp_inner??n;return this.zpp_inner.shapesInShape(s,t,i,l)}bodiesInShape(e,t=!1,n,l){if(e==null)throw new Error("Error: Cannot evaluate bodies in a null shapes :)");let s=e.zpp_inner;if((s.body!=null?s.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(s.type==1){let o=s.polygon.valid();if($.ValidationResult_VALID==null&&($.internal=!0,$.ValidationResult_VALID=new(me()).shape.ValidationResult,$.internal=!1),o!=$.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.toString())}let i=n==null?null:n.zpp_inner??n;return this.zpp_inner.bodiesInShape(s,t,i,l)}shapesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let l=me(),s=n??new l.shape.ShapeList,i=e.zpp_inner.wrap_shapes;i.zpp_inner.valmod();let o=l.shape.ShapeIterator.get(i);for(;;){o.zpp_inner.zpp_inner.valmod();let r=o.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=a){o.zpp_next=l.shape.ShapeIterator.zpp_pool,l.shape.ShapeIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let p=o.zpp_inner.at(o.zpp_i++);this.shapesInShape(p,!1,t,s)}return s}bodiesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let l=me(),s=n??new l.phys.BodyList,i=e.zpp_inner.wrap_shapes;i.zpp_inner.valmod();let o=l.shape.ShapeIterator.get(i);for(;;){o.zpp_inner.zpp_inner.valmod();let r=o.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=a){o.zpp_next=l.shape.ShapeIterator.zpp_pool,l.shape.ShapeIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let p=o.zpp_inner.at(o.zpp_i++);this.bodiesInShape(p,!1,t,s)}return s}convexCast(e,t,n=!1,l){if(e==null)throw new Error("Error: Cannot cast null shape :)");let s=e.zpp_inner;if((s.body!=null?s.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexCast(s,t,l,n)}convexMultiCast(e,t,n=!1,l,s){if(e==null)throw new Error("Error: Cannot cast null shape :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexMultiCast(i,t,l,n,s)}rayCast(e,t=!1,n){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayCast(e,t,n)}rayMultiCast(e,t=!1,n,l){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayMultiCast(e,t,n,l)}debugDraw(e,t=Ii.ALL){if(e==null)throw new Error("Error: drawer cannot be null for Space::debugDraw");let n=(t&Ii.SHAPES)!==0,l=(t&Ii.JOINTS)!==0,s=(t&Ii.CONTACTS)!==0,i=(t&Ii.AABB)!==0,o=(t&Ii.CENTER_OF_MASS)!==0,r=(t&Ii.VELOCITIES)!==0,a=4283417591,p=4287669422,c=4294948685,u=4289058471,h=4293874512,x=1157627903,b=4294961979,_=4291728344;if(this.visitBodies(d=>{let f=d.zpp_inner,m=f.type===2,Z=f.type===1?p:m?a:c;if(n){let y=f.shapes.head;for(;y!=null;){let w=y.elt;if(w.type===0){let v=w.circle;w.zip_worldCOM&&w.validate_worldCOM();let P=w.worldCOMx,g=w.worldCOMy,k=v.radius,N=f.rot,E=P+Math.cos(N)*k,M=g+Math.sin(N)*k,C={x:P,y:g},D={x:E,y:M};m?e.drawSolidCircle(C,k,D,Z):e.drawCircle(C,k,Z)}else if(w.type===1){let v=w.polygon;v.zip_gverts&&v.validate_gverts();let P=[],g=v.gverts.next;for(;g!=null;)P.push({x:g.x,y:g.y}),g=g.next;P.length>=3&&(m?e.drawSolidPolygon(P,Z):e.drawPolygon(P,Z))}y=y.next}}if(i&&!f.world){let y=f.aabb,w=y.minx,v=y.miny,P=y.maxx,g=y.maxy;e.drawSegment({x:w,y:v},{x:P,y:v},x),e.drawSegment({x:P,y:v},{x:P,y:g},x),e.drawSegment({x:P,y:g},{x:w,y:g},x),e.drawSegment({x:w,y:g},{x:w,y:v},x)}if(o&&!f.world&&(f.validate_worldCOM(),e.drawPoint({x:f.worldCOMx,y:f.worldCOMy},b)),r&&!f.world&&m){let y=f.posx,w=f.posy;e.drawSegment({x:y,y:w},{x:y+f.velx,y:w+f.vely},_)}}),l&&this.visitConstraints(d=>{if(!d.debugDraw)return;let f=d.zpp_inner,m=f.b1,z=f.b2,Z=f.a1worldx??(m!=null?m.posx:0),y=f.a1worldy??(m!=null?m.posy:0),w=f.a2worldx??(z!=null?z.posx:0),v=f.a2worldy??(z!=null?z.posy:0);e.drawSegment({x:Z,y},{x:w,y:v},u),e.drawPoint({x:Z,y},u),e.drawPoint({x:w,y:v},u)}),s){let d=f=>{if(f==null)return;let m=f.head;for(;m!=null;){let z=m.elt;if(z!=null){let Z=z.nx,y=z.ny,w=z.contacts?.next;for(;w!=null;){let v=w.px,P=w.py;e.drawPoint({x:v,y:P},h),e.drawSegment({x:v,y:P},{x:v+Z*8,y:P+y*8},h),w=w.next}}m=m.next}};d(this.zpp_inner.c_arbiters_true),d(this.zpp_inner.c_arbiters_false)}}toString(){return`Space(bodies=${this.bodies.length})`}};var Es=class Es{constructor(){if(!$.internal)throw new Error("Error: Cannot instantiate BodyType derp!")}static get STATIC(){return $.BodyType_STATIC==null&&($.internal=!0,$.BodyType_STATIC=new Es,$.internal=!1),$.BodyType_STATIC}static get DYNAMIC(){return $.BodyType_DYNAMIC==null&&($.internal=!0,$.BodyType_DYNAMIC=new Es,$.internal=!1),$.BodyType_DYNAMIC}static get KINEMATIC(){return $.BodyType_KINEMATIC==null&&($.internal=!0,$.BodyType_KINEMATIC=new Es,$.internal=!1),$.BodyType_KINEMATIC}toString(){return this===$.BodyType_STATIC?"STATIC":this===$.BodyType_DYNAMIC?"DYNAMIC":this===$.BodyType_KINEMATIC?"KINEMATIC":""}};Es.__name__=["nape","phys","BodyType"];var cs=Es,Xo=me();Xo.phys.BodyType=cs;lo();var nl=class nl{constructor(){if(!$.internal)throw new Error("Error: Cannot instantiate MassMode derp!")}static get DEFAULT(){return $.MassMode_DEFAULT==null&&($.internal=!0,$.MassMode_DEFAULT=new nl,$.internal=!1),$.MassMode_DEFAULT}static get FIXED(){return $.MassMode_FIXED==null&&($.internal=!0,$.MassMode_FIXED=new nl,$.internal=!1),$.MassMode_FIXED}toString(){return this===$.MassMode_DEFAULT?"DEFAULT":this===$.MassMode_FIXED?"FIXED":""}};nl.__name__=["nape","phys","MassMode"];var il=nl,Ho=me();Ho.phys.MassMode=il;var sl=class sl{constructor(){if(!$.internal)throw new Error("Error: Cannot instantiate InertiaMode derp!")}static get DEFAULT(){return $.InertiaMode_DEFAULT==null&&($.internal=!0,$.InertiaMode_DEFAULT=new sl,$.internal=!1),$.InertiaMode_DEFAULT}static get FIXED(){return $.InertiaMode_FIXED==null&&($.internal=!0,$.InertiaMode_FIXED=new sl,$.internal=!1),$.InertiaMode_FIXED}toString(){return this===$.InertiaMode_DEFAULT?"DEFAULT":this===$.InertiaMode_FIXED?"FIXED":""}};sl.__name__=["nape","phys","InertiaMode"];var ll=sl,Qo=me();Qo.phys.InertiaMode=ll;var Ns=class Ns{constructor(){if(!$.internal)throw new Error("Error: Cannot instantiate GravMassMode derp!")}static get DEFAULT(){return $.GravMassMode_DEFAULT==null&&($.internal=!0,$.GravMassMode_DEFAULT=new Ns,$.internal=!1),$.GravMassMode_DEFAULT}static get FIXED(){return $.GravMassMode_FIXED==null&&($.internal=!0,$.GravMassMode_FIXED=new Ns,$.internal=!1),$.GravMassMode_FIXED}static get SCALED(){return $.GravMassMode_SCALED==null&&($.internal=!0,$.GravMassMode_SCALED=new Ns,$.internal=!1),$.GravMassMode_SCALED}toString(){return this===$.GravMassMode_DEFAULT?"DEFAULT":this===$.GravMassMode_FIXED?"FIXED":this===$.GravMassMode_SCALED?"SCALED":""}};Ns.__name__=["nape","phys","GravMassMode"];var Os=Ns,$o=me();$o.phys.GravMassMode=Os;var ji=class ji extends ei{constructor(e=50,t,n,l){super();let s=me(),i=new Xn;if(this.zpp_inner_zn=i,this.zpp_inner=i,this.zpp_inner_i=i,i.outer=this,i.outer_zn=this,i.outer_i=this,this._inner=this,e!==i.radius){if(e!==e)throw new Error("Error: Circle::radius cannot be NaN");if(e<s.Config.epsilon)throw new Error("Error: Circle::radius ("+e+") must be > Config.epsilon");if(e>ni.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");i.radius=e,i.invalidate_radius()}if(t!=null){if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=t.zpp_inner;o._validate!=null&&o._validate(),i.localCOMx=o.x,o._validate!=null&&o._validate(),i.localCOMy=o.y,o.weak&&t.dispose()}else i.localCOMx=0,i.localCOMy=0;n==null?Ve.zpp_pool!=null?(i.material=Ve.zpp_pool,Ve.zpp_pool=i.material.next,i.material.next=null):i.material=new Ve:(i.immutable_midstep("Shape::material"),i.setMaterial(n.zpp_inner),i.material.wrapper()),l==null?_t.zpp_pool!=null?(i.filter=_t.zpp_pool,_t.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new _t:(i.immutable_midstep("Shape::filter"),i.setFilter(l.zpp_inner),i.filter.wrapper()),i.insert_cbtype(gn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof ji?e:e instanceof Xn?Ze(e,t=>{let n=Object.create(ji.prototype);return n.zpp_inner_zn=t,n.zpp_inner=t,n.zpp_inner_i=t,t.outer=n,t.outer_zn=n,t.outer_i=n,n._inner=n,n}):e.zpp_inner_zn?ji._wrap(e.zpp_inner_zn):Ze(e,t=>{let n=Object.create(ji.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i,n}):null}get radius(){return this.zpp_inner_zn.radius}set radius(e){let t=this.zpp_inner_zn,n=me();if(this.zpp_inner.immutable_midstep("Circle::radius"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modifiy radius of Circle contained in static object once added to space");if(e!==t.radius){if(e!==e)throw new Error("Error: Circle::radius cannot be NaN");if(e<n.Config.epsilon)throw new Error("Error: Circle::radius ("+e+") must be > Config.epsilon");if(e>ni.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}};ji.__name__=["nape","shape","Circle"],ji.__super__=ei;var Ss=ji;ao(V=>Ss._wrap(V));var er=me();er.shape.Circle=Ss;var mi=class mi extends ei{constructor(e,t,n){super();let l=me();if(e==null)throw new Error("Error: localVerts cannot be null");let s=new Hn;if(this.zpp_inner_zn=s,this.zpp_inner=s,this.zpp_inner_i=s,s.outer=this,s.outer_zn=this,s.outer_i=this,this._inner=this,Array.isArray(e)){for(let i of e){if(i==null)throw new Error("Error: Array<Vec2> contains null objects");if(!(i instanceof st))throw new Error("Error: Array<Vec2> contains non Vec2 objects");if(i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");s.wrap_lverts==null&&s.getlverts();let o=i.zpp_inner;o._validate!=null&&o._validate();let r=o.x;o._validate!=null&&o._validate();let a=o.y,p=new st(r,a);s.wrap_lverts.push(p)}for(let i=e.length-1;i>=0;i--)e[i].zpp_inner?.weak&&(e[i].dispose(),e.splice(i,1))}else if(e instanceof l.geom.Vec2List){let i=e,o=i.iterator();for(;;){o.zpp_inner.zpp_inner.valmod();let c=o.zpp_inner.zpp_gl();if(o.zpp_critical=!0,o.zpp_i>=c){o.zpp_next=l.geom.Vec2Iterator.zpp_pool,l.geom.Vec2Iterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let u=o.zpp_inner.at(o.zpp_i++);if(u==null)throw new Error("Error: Vec2List contains null objects");if(u.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");s.wrap_lverts==null&&s.getlverts();let h=u.zpp_inner;h._validate!=null&&h._validate();let x=h.x;h._validate!=null&&h._validate();let b=h.y,_=new st(x,b);s.wrap_lverts.push(_)}i.zpp_inner._validate!=null&&i.zpp_inner._validate();let r=i.zpp_inner.inner,a=null,p=r.head;for(;p!=null;){let c=p.elt;c.outer?.zpp_inner?.weak?(p=r.erase(a),c.outer.zpp_inner.weak&&c.outer.dispose()):(a=p,p=p.next)}}else if(e instanceof l.geom.GeomPoly){let i=e.zpp_inner.vertices;if(i!=null){let o=i;do{s.wrap_lverts==null&&s.getlverts();let r=new st(o.x,o.y);s.wrap_lverts.push(r),o=o.next}while(o!==i)}}else throw new Error("Error: Invalid type for polygon object, should be Array<Vec2>, Vec2List, GeomPoly or for flash10+ flash.Vector<Vec2>");t==null?Ve.zpp_pool!=null?(s.material=Ve.zpp_pool,Ve.zpp_pool=s.material.next,s.material.next=null):s.material=new Ve:(s.immutable_midstep("Shape::material"),s.setMaterial(t.zpp_inner),s.material.wrapper()),n==null?_t.zpp_pool!=null?(s.filter=_t.zpp_pool,_t.zpp_pool=s.filter.next,s.filter.next=null):s.filter=new _t:(s.immutable_midstep("Shape::filter"),s.setFilter(n.zpp_inner),s.filter.wrapper()),s.insert_cbtype(gn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof mi?e:e instanceof Hn?Ze(e,t=>{let n=Object.create(mi.prototype);return n.zpp_inner_zn=t,n.zpp_inner=t,n.zpp_inner_i=t,t.outer=n,t.outer_zn=n,t.outer_i=n,n._inner=n,n}):e.zpp_inner_zn?mi._wrap(e.zpp_inner_zn):Ze(e,t=>{let n=Object.create(mi.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i,n}):null}static rect(e,t,n,l,s=!1){if(e!==e||t!==t||n!==n||l!==l)throw new Error("Error: Polygon.rect cannot accept NaN arguments");let i=new st(e,t);i.zpp_inner.weak=s;let o=new st(e+n,t);o.zpp_inner.weak=s;let r=new st(e+n,t+l);r.zpp_inner.weak=s;let a=new st(e,t+l);return a.zpp_inner.weak=s,[i,o,r,a]}static box(e,t=e,n=!1){if(e!==e||t!==t)throw new Error("Error: Polygon.box cannot accept NaN arguments");return mi.rect(-e/2,-t/2,e,t,n)}static regular(e,t,n,l=0,s=!1){if(e!==e||t!==t||l!==l)throw new Error("Error: Polygon.regular cannot accept NaN arguments");let i=[],o=Math.PI*2/n;for(let r=0;r<n;r++){let a=r*o+l,p=Math.cos(a)*e,c=Math.sin(a)*t,u=new st(p,c);u.zpp_inner.weak=s,i.push(u)}return i}get localVerts(){return this.zpp_inner_zn.wrap_lverts==null&&this.zpp_inner_zn.getlverts(),this.zpp_inner_zn.wrap_lverts}get worldVerts(){return this.zpp_inner_zn.wrap_gverts==null&&this.zpp_inner_zn.getgverts(),this.zpp_inner_zn.wrap_gverts}get edges(){return this.zpp_inner_zn.wrap_edges==null&&this.zpp_inner_zn.getedges(),this.zpp_inner_zn.wrap_edges}validity(){return this.zpp_inner_zn.valid()}};mi.__name__=["nape","shape","Polygon"],mi.__super__=ei;var As=mi;po(V=>As._wrap(V));var tr=me();tr.shape.Polygon=As;var Vn=class Vn{get _inner(){return this}constructor(e=0,t=1,n=2,l=1,s=.001){let i;if(Ve.zpp_pool==null?i=new Ve:(i=Ve.zpp_pool,Ve.zpp_pool=i.next,i.next=null),this.zpp_inner=i,i.outer=this,e!==i.elasticity){if(e!==e)throw new Error("Error: Material::elasticity cannot be NaN");i.elasticity=e,i.invalidate(Ve.WAKE|Ve.ARBITERS)}if(t!==i.dynamicFriction){if(t!==t)throw new Error("Error: Material::dynamicFriction cannot be NaN");if(t<0)throw new Error("Error: Material::dynamicFriction cannot be negative");i.dynamicFriction=t,i.invalidate(Ve.WAKE|Ve.ANGDRAG|Ve.ARBITERS)}if(n!==i.staticFriction){if(n!==n)throw new Error("Error: Material::staticFriction cannot be NaN");if(n<0)throw new Error("Error: Material::staticFriction cannot be negative");i.staticFriction=n,i.invalidate(Ve.WAKE|Ve.ARBITERS)}if(l!==i.density*1e3){if(l!==l)throw new Error("Error: Material::density cannot be NaN");if(l<0)throw new Error("Error: Material::density must be positive");i.density=l/1e3,i.invalidate(Ve.WAKE|Ve.PROPS)}if(s!==i.rollingFriction){if(s!==s)throw new Error("Error: Material::rollingFriction cannot be NaN");if(s<0)throw new Error("Error: Material::rollingFriction cannot be negative");i.rollingFriction=s,i.invalidate(Ve.WAKE|Ve.ARBITERS)}}static _wrap(e){return e instanceof Vn?e:e?e instanceof Ve?Ze(e,t=>{let n=Object.create(Vn.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?Vn._wrap(e.zpp_inner):null:null}get elasticity(){return this.zpp_inner.elasticity}set elasticity(e){if(e!==this.zpp_inner.elasticity){if(e!==e)throw new Error("Error: Material::elasticity cannot be NaN");this.zpp_inner.elasticity=e,this.zpp_inner.invalidate(Ve.WAKE|Ve.ARBITERS)}}get dynamicFriction(){return this.zpp_inner.dynamicFriction}set dynamicFriction(e){if(e!==this.zpp_inner.dynamicFriction){if(e!==e)throw new Error("Error: Material::dynamicFriction cannot be NaN");if(e<0)throw new Error("Error: Material::dynamicFriction cannot be negative");this.zpp_inner.dynamicFriction=e,this.zpp_inner.invalidate(Ve.WAKE|Ve.ANGDRAG|Ve.ARBITERS)}}get staticFriction(){return this.zpp_inner.staticFriction}set staticFriction(e){if(e!==this.zpp_inner.staticFriction){if(e!==e)throw new Error("Error: Material::staticFriction cannot be NaN");if(e<0)throw new Error("Error: Material::staticFriction cannot be negative");this.zpp_inner.staticFriction=e,this.zpp_inner.invalidate(Ve.WAKE|Ve.ARBITERS)}}get density(){return this.zpp_inner.density*1e3}set density(e){if(e!==this.zpp_inner.density*1e3){if(e!==e)throw new Error("Error: Material::density cannot be NaN");if(e<0)throw new Error("Error: Material::density must be positive");this.zpp_inner.density=e/1e3,this.zpp_inner.invalidate(Ve.WAKE|Ve.PROPS)}}get rollingFriction(){return this.zpp_inner.rollingFriction}set rollingFriction(e){if(e!==this.zpp_inner.rollingFriction){if(e!==e)throw new Error("Error: Material::rollingFriction cannot be NaN");if(e<0)throw new Error("Error: Material::rollingFriction cannot be negative");this.zpp_inner.rollingFriction=e,this.zpp_inner.invalidate(Ve.WAKE|Ve.ARBITERS)}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}copy(){let e=new Vn(this.zpp_inner.elasticity,this.zpp_inner.dynamicFriction,this.zpp_inner.staticFriction,this.zpp_inner.density*1e3,this.zpp_inner.rollingFriction);return this.zpp_inner.userData!=null&&(e.zpp_inner.userData={...this.zpp_inner.userData}),e}toString(){return"{ elasticity: "+this.zpp_inner.elasticity+" dynamicFriction: "+this.zpp_inner.dynamicFriction+" staticFriction: "+this.zpp_inner.staticFriction+" density: "+this.zpp_inner.density*1e3+" rollingFriction: "+this.zpp_inner.rollingFriction+" }"}static wood(){return new Vn(.4,.2,.38,.7,.005)}static steel(){return new Vn(.2,.57,.74,7.8,.001)}static ice(){return new Vn(.3,.03,.1,.9,1e-4)}static rubber(){return new Vn(.8,1,1.4,1.5,.01)}static glass(){return new Vn(.4,.4,.94,2.6,.002)}static sand(){return new Vn(-1,.45,.6,1.6,16)}};Vn.__name__=["nape","phys","Material"];var ol=Vn;Ve._wrapFn=V=>Ze(V,e=>{let t=Object.create(ol.prototype);return t.zpp_inner=e,e.outer=t,t});var hs=class hs{get _inner(){return this}constructor(e=1,t=-1,n=1,l=-1,s=1,i=-1){let o;_t.zpp_pool==null?o=new _t:(o=_t.zpp_pool,_t.zpp_pool=o.next,o.next=null),this.zpp_inner=o,o.outer=this,o.collisionGroup!=e&&(o.collisionGroup=e,o.invalidate()),o.collisionMask!=t&&(o.collisionMask=t,o.invalidate()),o.sensorGroup!=n&&(o.sensorGroup=n,o.invalidate()),o.sensorMask!=l&&(o.sensorMask=l,o.invalidate()),o.fluidGroup!=s&&(o.fluidGroup=s,o.invalidate()),o.fluidMask!=i&&(o.fluidMask=i,o.invalidate())}static _wrap(e){return e instanceof hs?e:e?e instanceof _t?Ze(e,t=>{let n=Object.create(hs.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?hs._wrap(e.zpp_inner):null:null}get collisionGroup(){return this.zpp_inner.collisionGroup}set collisionGroup(e){this.zpp_inner.collisionGroup!=e&&(this.zpp_inner.collisionGroup=e,this.zpp_inner.invalidate())}get collisionMask(){return this.zpp_inner.collisionMask}set collisionMask(e){this.zpp_inner.collisionMask!=e&&(this.zpp_inner.collisionMask=e,this.zpp_inner.invalidate())}get sensorGroup(){return this.zpp_inner.sensorGroup}set sensorGroup(e){this.zpp_inner.sensorGroup!=e&&(this.zpp_inner.sensorGroup=e,this.zpp_inner.invalidate())}get sensorMask(){return this.zpp_inner.sensorMask}set sensorMask(e){this.zpp_inner.sensorMask!=e&&(this.zpp_inner.sensorMask=e,this.zpp_inner.invalidate())}get fluidGroup(){return this.zpp_inner.fluidGroup}set fluidGroup(e){this.zpp_inner.fluidGroup!=e&&(this.zpp_inner.fluidGroup=e,this.zpp_inner.invalidate())}get fluidMask(){return this.zpp_inner.fluidMask}set fluidMask(e){this.zpp_inner.fluidMask!=e&&(this.zpp_inner.fluidMask=e,this.zpp_inner.invalidate())}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get shapes(){if(this.zpp_inner.wrap_shapes==null){let e=me();this.zpp_inner.wrap_shapes=e.zpp_nape.util.ZPP_ShapeList.get(this.zpp_inner.shapes,!0)}return this.zpp_inner.wrap_shapes}shouldCollide(e){if(e==null)throw new Error("Error: filter argument cannot be null for shouldCollide");return this.zpp_inner.shouldCollide(e.zpp_inner)}shouldSense(e){if(e==null)throw new Error("Error: filter argument cannot be null for shouldSense");return this.zpp_inner.shouldSense(e.zpp_inner)}shouldFlow(e){if(e==null)throw new Error("Error: filter argument cannot be null for shouldFlow");return this.zpp_inner.shouldFlow(e.zpp_inner)}copy(){return new hs(this.zpp_inner.collisionGroup,this.zpp_inner.collisionMask,this.zpp_inner.sensorGroup,this.zpp_inner.sensorMask,this.zpp_inner.fluidGroup,this.zpp_inner.fluidMask)}toString(){let e=(t,n)=>{let l="",s="0123456789ABCDEF",i=t;do l=s.charAt(i&15)+l,i>>>=4;while(i>0);for(;l.length<n;)l="0"+l;return l};return"{ collision: "+e(this.zpp_inner.collisionGroup,8)+"~"+e(this.zpp_inner.collisionMask,8)+" sensor: "+e(this.zpp_inner.sensorGroup,8)+"~"+e(this.zpp_inner.sensorMask,8)+" fluid: "+e(this.zpp_inner.fluidGroup,8)+"~"+e(this.zpp_inner.fluidMask,8)+" }"}};hs.__name__=["nape","dynamics","InteractionFilter"];var rl=hs;_t._wrapFn=V=>Ze(V,e=>{let t=Object.create(rl.prototype);return t.zpp_inner=e,e.outer=t,t});var al=class al{constructor(){if(!$.internal)throw new Error("Error: Cannot instantiate Broadphase derp!")}static get DYNAMIC_AABB_TREE(){return $.Broadphase_DYNAMIC_AABB_TREE==null&&($.internal=!0,$.Broadphase_DYNAMIC_AABB_TREE=new al,$.internal=!1),$.Broadphase_DYNAMIC_AABB_TREE}static get SWEEP_AND_PRUNE(){return $.Broadphase_SWEEP_AND_PRUNE==null&&($.internal=!0,$.Broadphase_SWEEP_AND_PRUNE=new al,$.internal=!1),$.Broadphase_SWEEP_AND_PRUNE}toString(){return this===$.Broadphase_DYNAMIC_AABB_TREE?"DYNAMIC_AABB_TREE":this===$.Broadphase_SWEEP_AND_PRUNE?"SWEEP_AND_PRUNE":""}};al.__name__=["nape","space","Broadphase"];var pl=al;var Bi=class Bi{constructor(){this.debugDraw=!0;this._inner=this}static _wrap(e){return e==null?null:e instanceof Bi?e:e.zpp_inner?.outer instanceof Bi?e.zpp_inner.outer:Ze(e,t=>{let n=Object.create(Bi.prototype);return n.zpp_inner=t.zpp_inner??t,n._inner=t,n.zpp_inner.outer=n,n.debugDraw=t.debugDraw??!0,n})}get space(){return this.zpp_inner.space==null?null:this.zpp_inner.space.outer}set space(e){if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");if((this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=e)if(this.zpp_inner.component!=null&&(this.zpp_inner.component.woken=!1),this.zpp_inner.clearcache(),this.zpp_inner.space!=null&&this.zpp_inner.space.wrap_constraints.remove(this),e!=null){let l=(e._inner?.zpp_inner??e.zpp_inner).wrap_constraints;l.zpp_inner.reverse_flag?l.push(this):l.unshift(this)}else this.zpp_inner.space=null}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(e){let t=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(t!=e&&(t?.zpp_inner.wrap_constraints.remove(this),e!=null)){let l=e.zpp_inner.wrap_constraints;l.zpp_inner.reverse_flag?l.push(this):l.unshift(this)}}get active(){return this.zpp_inner.active}set active(e){this.zpp_inner.active!=e&&(this.zpp_inner.component!=null&&(this.zpp_inner.component.woken=!1),this.zpp_inner.clearcache(),e?(this.zpp_inner.active=e,this.zpp_inner.activate(),this.zpp_inner.space!=null&&(this.zpp_inner.component!=null&&(this.zpp_inner.component.sleeping=!0),this.zpp_inner.space.wake_constraint(this.zpp_inner,!0))):(this.zpp_inner.space!=null&&(this.zpp_inner.wake(),this.zpp_inner.space.live_constraints.remove(this.zpp_inner)),this.zpp_inner.active=e,this.zpp_inner.deactivate()))}get ignore(){return this.zpp_inner.ignore}set ignore(e){this.zpp_inner.ignore!=e&&(this.zpp_inner.ignore=e,this.zpp_inner.wake())}get stiff(){return this.zpp_inner.stiff}set stiff(e){this.zpp_inner.stiff!=e&&(this.zpp_inner.stiff=e,this.zpp_inner.wake())}get frequency(){return this.zpp_inner.frequency}set frequency(e){if(e!==e)throw new Error("Error: Constraint::Frequency cannot be NaN");if(e<=0)throw new Error("Error: Constraint::Frequency must be >0");this.zpp_inner.frequency!=e&&(this.zpp_inner.frequency=e,this.zpp_inner.stiff||this.zpp_inner.wake())}get damping(){return this.zpp_inner.damping}set damping(e){if(e!==e)throw new Error("Error: Constraint::Damping cannot be Nan");if(e<0)throw new Error("Error: Constraint::Damping must be >=0");this.zpp_inner.damping!=e&&(this.zpp_inner.damping=e,this.zpp_inner.stiff||this.zpp_inner.wake())}get maxForce(){return this.zpp_inner.maxForce}set maxForce(e){if(e!==e)throw new Error("Error: Constraint::maxForce cannot be NaN");if(e<0)throw new Error("Error: Constraint::maxForce must be >=0");this.zpp_inner.maxForce!=e&&(this.zpp_inner.maxForce=e,this.zpp_inner.wake())}get maxError(){return this.zpp_inner.maxError}set maxError(e){if(e!==e)throw new Error("Error: Constraint::maxError cannot be NaN");if(e<0)throw new Error("Error: Constraint::maxError must be >=0");this.zpp_inner.maxError!=e&&(this.zpp_inner.maxError=e,this.zpp_inner.wake())}get breakUnderForce(){return this.zpp_inner.breakUnderForce}set breakUnderForce(e){this.zpp_inner.breakUnderForce!=e&&(this.zpp_inner.breakUnderForce=e,this.zpp_inner.wake())}get breakUnderError(){return this.zpp_inner.breakUnderError}set breakUnderError(e){this.zpp_inner.breakUnderError!=e&&(this.zpp_inner.breakUnderError=e,this.zpp_inner.wake())}get removeOnBreak(){return this.zpp_inner.removeOnBreak}set removeOnBreak(e){this.zpp_inner.removeOnBreak=e}get isSleeping(){if(this.zpp_inner.space==null||!this.zpp_inner.active)throw new Error("Error: isSleeping only makes sense if constraint is active and inside a space");return this.zpp_inner.component.sleeping}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get cbTypes(){return this.zpp_inner.wrap_cbTypes==null&&this.zpp_inner.setupcbTypes(),this.zpp_inner.wrap_cbTypes}impulse(){return null}bodyImpulse(e){return null}visitBodies(e){}copy(){return Bi._wrap(this.zpp_inner.copy())}toString(){return"{Constraint}"}};Bi.__name__=["nape","constraint","Constraint"],Bi.zpp_internalAlloc=!1;var an=Bi;function uo(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.x}function xo(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Tl(V){V.zpp_inner.weak&&V.dispose()}var cl=class V extends an{constructor(e,t,n,l){super();let s=new ri;if(this.zpp_inner=s,s.outer=this,s.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(s.a1localx=uo(n),s.a1localy=xo(n),Tl(n),l?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l==null)throw new Error("Error: Constraint::anchor2 cannot be null");s.a2localx=uo(l),s.a2localy=xo(l),Tl(l)}static _wrap(e){return e==null?null:e instanceof V?e:e.zpp_inner?.outer instanceof V?e.zpp_inner.outer:e instanceof ri?Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:tt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:tt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),Tl(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),Tl(e)}impulse(){let e=me(),t=new e.geom.MatMN(2,1);return t.zpp_inner.x[0]=this.zpp_inner.jAccx,t.zpp_inner.x[1]=this.zpp_inner.jAccy,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};ri._wrapFn=V=>Ze(V,e=>{let t=Object.create(cl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function _o(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.x}function yo(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Ll(V){V.zpp_inner.weak&&V.dispose()}var hl=class V extends an{constructor(e,t,n,l,s,i){super();let o=new si;if(this.zpp_inner=o,o.outer=this,o.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");let r=_o(n),a=yo(n);if(o.a1localx=r,o.a1localy=a,Ll(n),l?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l==null)throw new Error("Error: Constraint::anchor2 cannot be null");let p=_o(l),c=yo(l);if(o.a2localx=p,o.a2localy=c,Ll(l),this.zpp_inner.immutable_midstep("DistanceJoint::jointMin"),s!==s)throw new Error("Error: DistanceJoint::jointMin cannot be NaN");if(s<0)throw new Error("Error: DistanceJoint::jointMin must be >= 0");if(o.jointMin!=s&&(o.jointMin=s,o.wake()),this.zpp_inner.immutable_midstep("DistanceJoint::jointMax"),i!==i)throw new Error("Error: DistanceJoint::jointMax cannot be NaN");if(i<0)throw new Error("Error: DistanceJoint::jointMax must be >= 0");o.jointMax!=i&&(o.jointMax=i,o.wake())}static _wrap(e){return e==null?null:e instanceof V?e:e.zpp_inner?.outer instanceof V?e.zpp_inner.outer:e instanceof si?Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:tt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:tt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),Ll(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),Ll(e)}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("DistanceJoint::jointMin"),e!==e)throw new Error("Error: DistanceJoint::jointMin cannot be NaN");if(e<0)throw new Error("Error: DistanceJoint::jointMin must be >= 0");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("DistanceJoint::jointMax"),e!==e)throw new Error("Error: DistanceJoint::jointMax cannot be NaN");if(e<0)throw new Error("Error: DistanceJoint::jointMax must be >= 0");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}isSlack(){if(this.zpp_inner.b1==null||this.zpp_inner.b2==null)throw new Error("Error: Cannot compute slack for DistanceJoint if either body is null.");return this.zpp_inner.is_slack()}impulse(){let e=me(),t=new e.geom.MatMN(1,1);if(0>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return t.zpp_inner.x[0*t.zpp_inner.n]=this.zpp_inner.jAcc,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};si._wrapFn=V=>Ze(V,e=>{let t=Object.create(hl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var ul=class V extends an{constructor(e,t,n,l,s=1){super();let i=new qe;if(this.zpp_inner=i,i.outer=this,i.outer_zn=this,this._setBody1(e),this._setBody2(t),this.zpp_inner.immutable_midstep("AngleJoint::jointMin"),n!==n)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(i.jointMin!=n&&(i.jointMin=n,i.wake()),this.zpp_inner.immutable_midstep("AngleJoint::jointMax"),l!==l)throw new Error("Error: AngleJoint::jointMax cannot be NaN");if(i.jointMax!=l&&(i.jointMax=l,i.wake()),this.zpp_inner.immutable_midstep("AngleJoint::ratio"),s!==s)throw new Error("Error: AngleJoint::ratio cannot be NaN");i.ratio!=s&&(i.ratio=s,i.wake())}static _wrap(e){return e==null?null:e instanceof V?e:e.zpp_inner?.outer instanceof V?e.zpp_inner.outer:e instanceof qe?Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:tt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:tt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("AngleJoint::jointMin"),e!==e)throw new Error("Error: AngleJoint::jointMin cannot be NaN");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("AngleJoint::jointMax"),e!==e)throw new Error("Error: AngleJoint::jointMax cannot be NaN");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}get ratio(){return this.zpp_inner.ratio}set ratio(e){if(this.zpp_inner.immutable_midstep("AngleJoint::ratio"),e!==e)throw new Error("Error: AngleJoint::ratio cannot be NaN");this.zpp_inner.ratio!=e&&(this.zpp_inner.ratio=e,this.zpp_inner.wake())}isSlack(){if(this.zpp_inner.b1==null||this.zpp_inner.b2==null)throw new Error("Error: Cannot compute slack for AngleJoint if either body is null.");return this.zpp_inner.is_slack()}impulse(){let e=me(),t=new e.geom.MatMN(1,1);if(0>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return t.zpp_inner.x[0*t.zpp_inner.n]=this.zpp_inner.jAcc,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};qe._wrapFn=V=>Ze(V,e=>{let t=Object.create(ul.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var xl=class V extends an{constructor(e,t,n=0,l=1){super();let s=new oi;if(this.zpp_inner=s,s.outer=this,s.outer_zn=this,this._setBody1(e),this._setBody2(t),this.zpp_inner.immutable_midstep("MotorJoint::rate"),n!==n)throw new Error("Error: MotorJoint::rate cannot be NaN");if(s.rate!=n&&(s.rate=n,s.wake()),this.zpp_inner.immutable_midstep("MotorJoint::ratio"),l!==l)throw new Error("Error: MotorJoint::ratio cannot be NaN");s.ratio!=l&&(s.ratio=l,s.wake())}static _wrap(e){return e==null?null:e instanceof V?e:e.zpp_inner?.outer instanceof V?e.zpp_inner.outer:e instanceof oi?Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:tt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:tt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get rate(){return this.zpp_inner.rate}set rate(e){if(this.zpp_inner.immutable_midstep("MotorJoint::rate"),e!==e)throw new Error("Error: MotorJoint::rate cannot be NaN");this.zpp_inner.rate!=e&&(this.zpp_inner.rate=e,this.zpp_inner.wake())}get ratio(){return this.zpp_inner.ratio}set ratio(e){if(this.zpp_inner.immutable_midstep("MotorJoint::ratio"),e!==e)throw new Error("Error: MotorJoint::ratio cannot be NaN");this.zpp_inner.ratio!=e&&(this.zpp_inner.ratio=e,this.zpp_inner.wake())}impulse(){let e=me(),t=new e.geom.MatMN(1,1);if(0>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return t.zpp_inner.x[0*t.zpp_inner.n]=this.zpp_inner.jAcc,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};oi._wrapFn=V=>Ze(V,e=>{let t=Object.create(xl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Hl(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Ql(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Vs(V){V.zpp_inner.weak&&V.dispose()}var _l=class V extends an{constructor(e,t,n,l,s,i,o){super();let r=new li;if(this.zpp_inner=r,r.outer=this,r.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(r.a1localx=Hl(n),r.a1localy=Ql(n),Vs(n),l?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l==null)throw new Error("Error: Constraint::anchor2 cannot be null");if(r.a2localx=Hl(l),r.a2localy=Ql(l),Vs(l),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::direction cannot be null");if(r.nlocalx=Hl(s),r.nlocaly=Ql(s),r.zip_n=!0,Vs(s),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),i!==i)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(r.jointMin!=i&&(r.jointMin=i,r.wake()),this.zpp_inner.immutable_midstep("LineJoint::jointMax"),o!==o)throw new Error("Error: AngleJoint::jointMax cannot be NaN");r.jointMax!=o&&(r.jointMax=o,r.wake())}static _wrap(e){return e==null?null:e instanceof V?e:e.zpp_inner?.outer instanceof V?e.zpp_inner.outer:e instanceof li?Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:tt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:tt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),Vs(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),Vs(e)}get direction(){return this.zpp_inner.wrap_n==null&&this.zpp_inner.setup_n(),this.zpp_inner.wrap_n}set direction(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::direction cannot be null");this.zpp_inner.wrap_n==null&&this.zpp_inner.setup_n(),this.zpp_inner.wrap_n.set(e),Vs(e)}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("LineJoint::jointMin"),e!==e)throw new Error("Error: AngleJoint::jointMin cannot be NaN");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("LineJoint::jointMax"),e!==e)throw new Error("Error: AngleJoint::jointMax cannot be NaN");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}impulse(){let e=me(),t=new e.geom.MatMN(2,1);return t.zpp_inner.x[0]=this.zpp_inner.jAccx,t.zpp_inner.x[1]=this.zpp_inner.jAccy,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};li._wrapFn=V=>Ze(V,e=>{let t=Object.create(_l.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var bi=class bi{get _inner(){return this}constructor(e,t){if(e<=0||t<=0)throw new Error("Error: MatMN::dimensions cannot be < 1");this.zpp_inner=new gi(e,t),this.zpp_inner.outer=this}static _wrap(e){return e instanceof bi?e:e?e instanceof gi?Ze(e,t=>{let n=Object.create(bi.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?bi._wrap(e.zpp_inner):null:null}get rows(){return this.zpp_inner.m}get cols(){return this.zpp_inner.n}x(e,t){if(e<0||t<0||e>=this.zpp_inner.m||t>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return this.zpp_inner.x[e*this.zpp_inner.n+t]}setx(e,t,n){if(e<0||t<0||e>=this.zpp_inner.m||t>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return this.zpp_inner.x[e*this.zpp_inner.n+t]=n}equals(e,t=0){if(e==null||this.zpp_inner.m!==e.zpp_inner.m||this.zpp_inner.n!==e.zpp_inner.n)return!1;for(let n=0;n<this.zpp_inner.x.length;n++){let l=this.zpp_inner.x[n]-e.zpp_inner.x[n];if((l<0?-l:l)>t)return!1}return!0}clone(){let e=new bi(this.zpp_inner.m,this.zpp_inner.n);for(let t=0;t<this.zpp_inner.x.length;t++)e.zpp_inner.x[t]=this.zpp_inner.x[t];return e}toString(){let e="{ ",t=!0;for(let n=0;n<this.zpp_inner.m;n++){t||(e+="; "),t=!1;for(let l=0;l<this.zpp_inner.n;l++){if(n<0||l<0||n>=this.zpp_inner.m||l>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");e+=this.zpp_inner.x[n*this.zpp_inner.n+l]+" "}}return e+="}",e}transpose(){let e=new bi(this.zpp_inner.n,this.zpp_inner.m);for(let t=0;t<this.zpp_inner.m;t++)for(let n=0;n<this.zpp_inner.n;n++)e.zpp_inner.x[n*e.zpp_inner.n+t]=this.zpp_inner.x[t*this.zpp_inner.n+n];return e}mul(e){let t=e;if(this.zpp_inner.n!==t.zpp_inner.m)throw new Error("Error: Matrix dimensions aren't compatible");let n=new bi(this.zpp_inner.m,t.zpp_inner.n);for(let l=0;l<this.zpp_inner.m;l++)for(let s=0;s<t.zpp_inner.n;s++){let i=0;for(let o=0;o<this.zpp_inner.n;o++)i+=this.zpp_inner.x[l*this.zpp_inner.n+o]*t.zpp_inner.x[o*t.zpp_inner.n+s];n.zpp_inner.x[l*n.zpp_inner.n+s]=i}return n}};bi.__name__=["nape","geom","MatMN"];var dl=bi,nr=me();nr.geom.MatMN=dl;function yl(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.x}function ml(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.y}function bl(V){V.zpp_inner.weak&&V.dispose()}var fl=class V extends an{constructor(e,t,n,l,s,i,o,r,a,p,c=1){super();let u=new ai;if(this.zpp_inner=u,u.outer=this,u.outer_zn=this,this._setBody1(e),this._setBody2(t),this._setBody3(n),this._setBody4(l),this._setAnchorInit(s,"anchor1",(h,x)=>{u.a1localx=h,u.a1localy=x}),this._setAnchorInit(i,"anchor2",(h,x)=>{u.a2localx=h,u.a2localy=x}),this._setAnchorInit(o,"anchor3",(h,x)=>{u.a3localx=h,u.a3localy=x}),this._setAnchorInit(r,"anchor4",(h,x)=>{u.a4localx=h,u.a4localy=x}),u.immutable_midstep("PulleyJoint::jointMin"),a!==a)throw new Error("Error: PulleyJoint::jointMin cannot be NaN");if(a<0)throw new Error("Error: PulleyJoint::jointMin must be >= 0");if(u.jointMin!=a&&(u.jointMin=a,u.wake()),u.immutable_midstep("PulleyJoint::jointMax"),p!==p)throw new Error("Error: PulleyJoint::jointMax cannot be NaN");if(p<0)throw new Error("Error: PulleyJoint::jointMax must be >= 0");if(u.jointMax!=p&&(u.jointMax=p,u.wake()),u.immutable_midstep("PulleyJoint::ratio"),c!==c)throw new Error("Error: PulleyJoint::ratio cannot be NaN");u.ratio!=c&&(u.ratio=c,u.wake())}_setAnchorInit(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::"+t+" cannot be null");n(yl(e),ml(e)),bl(e)}static _wrap(e){return e==null?null:e instanceof V?e:e.zpp_inner?.outer instanceof V?e.zpp_inner.outer:e instanceof ai?Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:tt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}get body2(){return this.zpp_inner.b2==null?null:tt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}get body3(){return this.zpp_inner.b3==null?null:tt._wrap(this.zpp_inner.b3)}set body3(e){this._setBody3(e)}get body4(){return this.zpp_inner.b4==null?null:tt._wrap(this.zpp_inner.b4)}set body4(e){this._setBody4(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b3!=this.zpp_inner.b1&&this.zpp_inner.b4!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&this.zpp_inner.b3!=t&&this.zpp_inner.b4!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b3!=this.zpp_inner.b2&&this.zpp_inner.b4!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&this.zpp_inner.b3!=t&&this.zpp_inner.b4!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}_setBody3(e){this.zpp_inner.immutable_midstep("Constraint::body3");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b3&&(this.zpp_inner.b3!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b3&&this.zpp_inner.b2!=this.zpp_inner.b3&&this.zpp_inner.b4!=this.zpp_inner.b3&&this.zpp_inner.b3.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b3.wake()),this.zpp_inner.b3=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&this.zpp_inner.b2!=t&&this.zpp_inner.b4!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}_setBody4(e){this.zpp_inner.immutable_midstep("Constraint::body4");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b4&&(this.zpp_inner.b4!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b4&&this.zpp_inner.b2!=this.zpp_inner.b4&&this.zpp_inner.b3!=this.zpp_inner.b4&&this.zpp_inner.b4.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b4.wake()),this.zpp_inner.b4=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&this.zpp_inner.b2!=t&&this.zpp_inner.b3!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),yl(e),ml(e),this.zpp_inner.wrap_a1.set(e),bl(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),yl(e),ml(e),this.zpp_inner.wrap_a2.set(e),bl(e)}get anchor3(){return this.zpp_inner.wrap_a3==null&&this.zpp_inner.setup_a3(),this.zpp_inner.wrap_a3}set anchor3(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor3 cannot be null");this.zpp_inner.wrap_a3==null&&this.zpp_inner.setup_a3(),yl(e),ml(e),this.zpp_inner.wrap_a3.set(e),bl(e)}get anchor4(){return this.zpp_inner.wrap_a4==null&&this.zpp_inner.setup_a4(),this.zpp_inner.wrap_a4}set anchor4(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor4 cannot be null");this.zpp_inner.wrap_a4==null&&this.zpp_inner.setup_a4(),yl(e),ml(e),this.zpp_inner.wrap_a4.set(e),bl(e)}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("PulleyJoint::jointMin"),e!==e)throw new Error("Error: PulleyJoint::jointMin cannot be NaN");if(e<0)throw new Error("Error: PulleyJoint::jointMin must be >= 0");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("PulleyJoint::jointMax"),e!==e)throw new Error("Error: PulleyJoint::jointMax cannot be NaN");if(e<0)throw new Error("Error: PulleyJoint::jointMax must be >= 0");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}get ratio(){return this.zpp_inner.ratio}set ratio(e){if(this.zpp_inner.immutable_midstep("PulleyJoint::ratio"),e!==e)throw new Error("Error: PulleyJoint::ratio cannot be NaN");this.zpp_inner.ratio!=e&&(this.zpp_inner.ratio=e,this.zpp_inner.wake())}isSlack(){if(this.zpp_inner.b1==null||this.zpp_inner.b2==null||this.zpp_inner.b3==null||this.zpp_inner.b4==null)throw new Error("Error: Cannot compute slack for PulleyJoint if either body is null.");return this.zpp_inner.slack}impulse(){let e=new dl(1,1);if(0>=e.zpp_inner.m||0>=e.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return e.zpp_inner.x[0*e.zpp_inner.n]=this.zpp_inner.jAcc,e}bodyImpulse(e){if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let t=this.zpp_inner.b1?.outer??null,n=this.zpp_inner.b2?.outer??null,l=this.zpp_inner.b3?.outer??null,s=this.zpp_inner.b4?.outer??null;if(e!=t&&e!=n&&e!=l&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):yi.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1?.outer??null,n=this.zpp_inner.b2?.outer??null,l=this.zpp_inner.b3?.outer??null,s=this.zpp_inner.b4?.outer??null;t!=null&&e(t),n!=null&&n!=t&&e(n),l!=null&&l!=t&&l!=n&&e(l),s!=null&&s!=t&&s!=n&&s!=l&&e(s)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};ai._wrapFn=V=>Ze(V,e=>{let t=Object.create(fl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function mo(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.x}function bo(V){if(V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=V.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Dl(V){V.zpp_inner.weak&&V.dispose()}var zl=class V extends an{constructor(e,t,n,l,s=0){super();let i=new pi;if(this.zpp_inner=i,i.outer=this,i.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(i.a1localx=mo(n),i.a1localy=bo(n),Dl(n),l?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l==null)throw new Error("Error: Constraint::anchor2 cannot be null");if(i.a2localx=mo(l),i.a2localy=bo(l),Dl(l),this.zpp_inner.immutable_midstep("WeldJoint::phase"),s!==s)throw new Error("Error: WeldJoint::phase cannot be NaN");i.phase!=s&&(i.phase=s,i.wake())}static _wrap(e){return e==null?null:e instanceof V?e:e.zpp_inner?.outer instanceof V?e.zpp_inner.outer:e instanceof pi?Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(V.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:tt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:tt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),Dl(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),Dl(e)}get phase(){return this.zpp_inner.phase}set phase(e){if(this.zpp_inner.immutable_midstep("WeldJoint::phase"),e!==e)throw new Error("Error: WeldJoint::phase cannot be NaN");this.zpp_inner.phase!=e&&(this.zpp_inner.phase=e,this.zpp_inner.wake())}impulse(){let e=me(),t=new e.geom.MatMN(3,1);return t.zpp_inner.x[0]=this.zpp_inner.jAccx,t.zpp_inner.x[1]=this.zpp_inner.jAccy,t.zpp_inner.x[2]=this.zpp_inner.jAccz,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};pi._wrapFn=V=>Ze(V,e=>{let t=Object.create(zl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var Ti=class Ti extends $n{constructor(){super();let e=new Rn;this.zpp_inner=e,e.outer=this,e.outer_i=this,this.zpp_inner_i=e,this._inner=this,e.insert_cbtype(gn.ANY_COMPOUND.zpp_inner)}static _wrap(e){return e?e instanceof Ti?e:e instanceof Rn?Ze(e,t=>{let n=Object.create(Ti.prototype);return n.zpp_inner=t,t.outer=n,t.outer_i=n,n.zpp_inner_i=t,n._inner=n,n}):e.zpp_inner?Ti._wrap(e.zpp_inner):Ze(e,t=>{let n=Object.create(Ti.prototype);return n._inner=t,n}):null}get bodies(){return this.zpp_inner.wrap_bodies}get constraints(){return this.zpp_inner.wrap_constraints}get compounds(){return this.zpp_inner.wrap_compounds}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(e){this.zpp_inner.immutable_midstep("Compound::compound");let t=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(t!==e&&(t?.zpp_inner.wrap_compounds.remove(this),e!=null)){let n=e.zpp_inner.wrap_compounds;n.zpp_inner.reverse_flag?n.push(this):n.unshift(this)}}get space(){return this.zpp_inner.space==null?null:Vi._wrap(this.zpp_inner.space.outer)}set space(e){if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");this.zpp_inner.immutable_midstep("Compound::space");let t=this.zpp_inner.space==null?null:this.zpp_inner.space.outer;if(t!==e?._inner&&(t?.zpp_inner.wrap_compounds.remove(this),e!=null)){let n=e._inner.zpp_inner.wrap_compounds;n.zpp_inner.reverse_flag?n.push(this):n.unshift(this)}}copy(){return this.zpp_inner.copy()}breakApart(){this.zpp_inner.breakApart()}visitBodies(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitBodies");let t=this.zpp_inner.wrap_bodies,n=t.length;for(let i=0;i<n;i++)e(t.at(i));let l=this.zpp_inner.wrap_compounds,s=l.length;for(let i=0;i<s;i++)l.at(i).visitBodies(e)}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitConstraints");let t=this.zpp_inner.wrap_constraints,n=t.length;for(let i=0;i<n;i++)e(t.at(i));let l=this.zpp_inner.wrap_compounds,s=l.length;for(let i=0;i<s;i++)l.at(i).visitConstraints(e)}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitConstraints");let t=this.zpp_inner.wrap_compounds,n=t.length;for(let l=0;l<n;l++){let s=t.at(l);e(s),s.visitCompounds(e)}}COM(e=!1){let t=new st(0,0),n=0;if(this.visitBodies(l=>{if(l.zpp_inner.wrap_shapes.zpp_inner.inner.head!=null){if(l.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");l.zpp_inner.wrap_worldCOM==null&&l.zpp_inner.getworldCOM();let i=l.zpp_inner.wrap_worldCOM;if(l.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(l.zpp_inner.validate_mass(),l.zpp_inner.massMode==0&&l.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");let o=l.zpp_inner.cmass;t.addeq(i.mul(o,!0)),n+=o}}),n===0)throw new Error("Error: COM of an empty Compound is undefined silly");return t.muleq(1/n),e&&(t.zpp_inner.weak=!0),t}translate(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot translate by null Vec2");let t=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(n=>{n.zpp_inner.wrap_pos==null&&n.zpp_inner.setupPosition(),n.zpp_inner.wrap_pos.addeq(e)}),e.zpp_inner.weak=t,e.zpp_inner.weak&&e.dispose(),this}rotate(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot rotate about a null Vec2");if(t!==t)throw new Error("Error: Cannot rotate by NaN radians");let n=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(l=>{l.rotate(e,t)}),e.zpp_inner.weak=n,e.zpp_inner.weak&&e.dispose(),this}toString(){return"Compound"+this.zpp_inner.id}};Ti.__name__=["nape","phys","Compound"],Ti.__super__=$n;var Li=Ti;Rn._wrapFn=V=>Ze(V,e=>{let t=Object.create(Li.prototype);return t.zpp_inner=e,e.outer=t,e.outer_i=t,t.zpp_inner_i=e,t._inner=t,t});Object.defineProperty(Li.prototype,"bodies",{get:function(){return this.zpp_inner.wrap_bodies},configurable:!0});Object.defineProperty(Li.prototype,"constraints",{get:function(){return this.zpp_inner.wrap_constraints},configurable:!0});Object.defineProperty(Li.prototype,"compounds",{get:function(){return this.zpp_inner.wrap_compounds},configurable:!0});function xs(V){return st.get(V.x,V.y)}function dn(V){return st.weak(V.x,V.y)}function ir(V){return new ol(V.elasticity,V.dynamicFriction,V.staticFriction,V.density,V.rollingFriction)}function sr(V){let e=new rl;return e.collisionGroup=V.collisionGroup,e.collisionMask=V.collisionMask,e.sensorGroup=V.sensorGroup,e.sensorMask=V.sensorMask,e.fluidGroup=V.fluidGroup,e.fluidMask=V.fluidMask,e}function lr(V){let e=new qn(V.density,V.viscosity);return V.gravity!=null&&(e.gravity=xs(V.gravity)),e}function or(V){let e=ir(V.material),t=sr(V.filter),n;if(V.type==="circle"){let l=xs(V.localCOM);n=new Ss(V.radius,l,e,t)}else{let l=V.localVerts.map(s=>xs(s));n=new As(l,e,t)}return n.sensorEnabled=V.sensorEnabled,n.fluidEnabled=V.fluidEnabled,V.fluidEnabled&&V.fluidProperties!=null&&(n.fluidProperties=lr(V.fluidProperties)),n}function rr(V){let e=V.type==="STATIC"?cs.STATIC:V.type==="KINEMATIC"?cs.KINEMATIC:cs.DYNAMIC,t=new tt(e,dn(V.position));t.rotation=V.rotation,V.type!=="STATIC"&&(t.velocity=xs(V.velocity),t.angularVel=V.angularVel),t.kinematicVel=xs(V.kinematicVel),t.kinAngVel=V.kinAngVel,t.surfaceVel=xs(V.surfaceVel),V.type==="DYNAMIC"&&(t.force=xs(V.force),t.torque=V.torque),V.massMode==="FIXED"&&V.mass!=null?t.mass=V.mass:V.massMode==="DEFAULT"&&(t.massMode=il.DEFAULT),V.inertiaMode==="FIXED"&&V.inertia!=null?t.inertia=V.inertia:V.inertiaMode==="DEFAULT"&&(t.inertiaMode=ll.DEFAULT),V.gravMassMode==="SCALED"?(t.gravMassMode=Os.SCALED,t.gravMassScale=V.gravMassScale):V.gravMassMode==="FIXED"&&(t.gravMassMode=Os.FIXED),t.allowMovement=V.allowMovement,t.allowRotation=V.allowRotation,t.isBullet=V.bullet;for(let n of V.shapes)or(n).body=t;return V.userData!=null&&Object.assign(t.userData,V.userData),t}function us(V,e){V.active=e.active,V.ignore=e.ignore,V.stiff=e.stiff,V.frequency=e.frequency,V.damping=e.damping,V.maxForce=e.maxForce,V.maxError=e.maxError,V.breakUnderForce=e.breakUnderForce,V.breakUnderError=e.breakUnderError,V.removeOnBreak=e.removeOnBreak,e.userData!=null&&Object.assign(V.userData,e.userData)}function ar(V,e){let t=V.body1Id!=null?e[V.body1Id]??null:null,n=V.body2Id!=null?e[V.body2Id]??null:null;switch(V.type){case"PivotJoint":{let l=new cl(t,n,dn(V.anchor1),dn(V.anchor2));return us(l,V),l}case"DistanceJoint":{let l=new hl(t,n,dn(V.anchor1),dn(V.anchor2),V.jointMin,V.jointMax);return us(l,V),l}case"AngleJoint":{let l=new ul(t,n,V.jointMin,V.jointMax,V.ratio);return us(l,V),l}case"MotorJoint":{let l=new xl(t,n,V.rate,V.ratio);return us(l,V),l}case"LineJoint":{let l=new _l(t,n,dn(V.anchor1),dn(V.anchor2),dn(V.direction),V.jointMin,V.jointMax);return us(l,V),l}case"PulleyJoint":{let l=new fl(t,n,null,null,dn(V.anchor1),dn(V.anchor2),dn(V.anchor3),dn(V.anchor4),V.jointMin,V.jointMax,V.ratio);return us(l,V),l}case"WeldJoint":{let l=new zl(t,n,dn(V.anchor1),dn(V.anchor2),V.phase);return us(l,V),l}}}function fo(V){if(V.version!==1)throw new Error(`nape-js serialization: unsupported snapshot version ${V.version} (expected ${1})`);let e=V.broadphase==="SWEEP_AND_PRUNE"?pl.SWEEP_AND_PRUNE:pl.DYNAMIC_AABB_TREE,t=new Vi(dn(V.gravity),e);t.worldLinearDrag=V.worldLinearDrag,t.worldAngularDrag=V.worldAngularDrag,t.sortContacts=V.sortContacts;let n=V.bodies.map(rr),l=V.constraints.map(o=>ar(o,n)),s=new Set,i=new Set;for(let o of V.compounds){let r=new Li;for(let a of o.bodyIds)n[a].compound=r,s.add(a);for(let a of o.constraintIndices)l[a].compound=r,i.add(a);r.space=t}for(let o=0;o<n.length;o++)s.has(o)||(n[o].space=t);for(let o=0;o<l.length;o++)i.has(o)||(l[o].space=t);return t}0&&(module.exports={SNAPSHOT_VERSION,spaceFromJSON,spaceToJSON});
|
|
1
|
+
"use strict";var kl=Object.defineProperty;var po=Object.getOwnPropertyDescriptor;var co=Object.getOwnPropertyNames;var ho=Object.prototype.hasOwnProperty;var uo=(g,e)=>{for(var t in e)kl(g,t,{get:e[t],enumerable:!0})},xo=(g,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of co(e))!ho.call(g,s)&&s!==t&&kl(g,s,{get:()=>e[s],enumerable:!(n=po(e,s))||n.enumerable});return g};var _o=g=>xo(kl({},"__esModule",{value:!0}),g);var Mr={};uo(Mr,{BINARY_SNAPSHOT_VERSION:()=>gs,SNAPSHOT_VERSION:()=>Cs,spaceFromBinary:()=>ao,spaceFromJSON:()=>no,spaceToBinary:()=>so,spaceToJSON:()=>Ll});module.exports=_o(Mr);var Cs=1;function ut(g){return{x:g.x,y:g.y}}function Tl(g){if(g==null)return null;try{let e=JSON.stringify(g);return e==="{}"?null:JSON.parse(e)}catch{return null}}function yo(g){return{elasticity:g.elasticity,dynamicFriction:g.dynamicFriction,staticFriction:g.staticFriction,density:g.density,rollingFriction:g.rollingFriction}}function mo(g){return{collisionGroup:g.collisionGroup,collisionMask:g.collisionMask,sensorGroup:g.sensorGroup,sensorMask:g.sensorMask,fluidGroup:g.fluidGroup,fluidMask:g.fluidMask}}function bo(g){if(g==null)return null;let e=g.gravity;return{density:g.density,viscosity:g.viscosity,gravity:e!=null?ut(e):null}}function fo(g){let e=yo(g.material),t=mo(g.filter),n=g.fluidEnabled,s=n?bo(g.fluidProperties):null,i=g.sensorEnabled;if(g.isCircle()){let l=g,r=g.localCOM;return{type:"circle",radius:l.radius,localCOM:ut(r),material:e,filter:t,sensorEnabled:i,fluidEnabled:n,fluidProperties:s}}else{let r=g.localVerts,a=[],o=r.length;for(let p=0;p<o;p++)a.push(ut(r.at(p)));return{type:"polygon",localVerts:a,material:e,filter:t,sensorEnabled:i,fluidEnabled:n,fluidProperties:s}}}var zo={1:"STATIC",2:"DYNAMIC",3:"KINEMATIC"},Po={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},wo={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},vo={0:"DEFAULT",1:"FIXED",2:"SCALED"};function go(g,e){let t=g.zpp_inner,n=Po[t.massMode]??"DEFAULT",s=wo[t.inertiaMode]??"DEFAULT",i=vo[t.gravMassMode]??"DEFAULT",l=[],r=g.shapes,a=r.length;for(let o=0;o<a;o++)l.push(fo(r.at(o)));return{id:e,type:zo[t.type]??"DYNAMIC",position:ut(g.position),rotation:g.rotation,velocity:ut(g.velocity),angularVel:g.angularVel,kinematicVel:ut(g.kinematicVel),kinAngVel:g.kinAngVel,surfaceVel:ut(g.surfaceVel),force:ut(g.force),torque:t.type===2?g.torque:0,massMode:n,mass:n==="FIXED"?t.cmass:null,inertiaMode:s,inertia:s==="FIXED"?t.cinertia:null,gravMassMode:i,gravMassScale:t.gravMassScale,allowMovement:g.allowMovement,allowRotation:g.allowRotation,bullet:g.isBullet,shapes:l,userData:Tl(t.userData)}}function ki(g,e,t,n){let s=g.zpp_inner,i=t!=null?e.get(t.zpp_inner.id)??null:null,l=n!=null?e.get(n.zpp_inner.id)??null:null;return{body1Id:i,body2Id:l,active:s.active,ignore:s.ignore,stiff:s.stiff,frequency:s.frequency,damping:s.damping,maxForce:s.maxForce,maxError:s.maxError,breakUnderForce:s.breakUnderForce,breakUnderError:s.breakUnderError,removeOnBreak:s.removeOnBreak,userData:Tl(s.userData)}}function Co(g,e){switch(g.constructor?.name??""){case"PivotJoint":{let n=g;return{...ki(g,e,n.body1,n.body2),type:"PivotJoint",anchor1:ut(n.anchor1),anchor2:ut(n.anchor2)}}case"DistanceJoint":{let n=g;return{...ki(g,e,n.body1,n.body2),type:"DistanceJoint",anchor1:ut(n.anchor1),anchor2:ut(n.anchor2),jointMin:n.jointMin,jointMax:n.jointMax}}case"AngleJoint":{let n=g;return{...ki(g,e,n.body1,n.body2),type:"AngleJoint",jointMin:n.jointMin,jointMax:n.jointMax,ratio:n.ratio}}case"MotorJoint":{let n=g;return{...ki(g,e,n.body1,n.body2),type:"MotorJoint",rate:n.rate,ratio:n.ratio}}case"LineJoint":{let n=g;return{...ki(g,e,n.body1,n.body2),type:"LineJoint",anchor1:ut(n.anchor1),anchor2:ut(n.anchor2),direction:ut(n.direction),jointMin:n.jointMin,jointMax:n.jointMax}}case"PulleyJoint":{let n=g;return{...ki(g,e,n.body1,n.body2),type:"PulleyJoint",anchor1:ut(n.anchor1),anchor2:ut(n.anchor2),anchor3:ut(n.anchor3),anchor4:ut(n.anchor4),jointMin:n.jointMin,jointMax:n.jointMax,ratio:n.ratio}}case"WeldJoint":{let n=g;return{...ki(g,e,n.body1,n.body2),type:"WeldJoint",anchor1:ut(n.anchor1),anchor2:ut(n.anchor2),phase:n.phase}}default:return null}}function Ll(g){let e=[],t=new Map,n=new Map;function s(f){let z=f.zpp_inner.id;if(n.has(z))return;let P=e.length;t.set(f,P),n.set(z,P),e.push(go(f,P))}let i=g.bodies,l=i.length;for(let f=0;f<l;f++)s(i.at(f));let r=g.compounds,a=r.length;for(let f=0;f<a;f++){let P=r.at(f).bodies,k=P.length;for(let m=0;m<k;m++)s(P.at(m))}let o=[],p=new Map;function c(f){if(p.has(f))return;let z=Co(f,n);z!=null&&(p.set(f,o.length),o.push(z))}let h=g.constraints,u=h.length;for(let f=0;f<u;f++)c(h.at(f));for(let f=0;f<a;f++){let P=r.at(f).constraints,k=P.length;for(let m=0;m<k;m++)c(P.at(m))}let x=[];for(let f=0;f<a;f++){let z=r.at(f),P=[],k=z.bodies,m=k.length;for(let w=0;w<m;w++){let O=k.at(w),E=t.get(O);E!=null&&P.push(E)}let b=[],C=z.constraints,v=C.length;for(let w=0;w<v;w++){let O=C.at(w),E=p.get(O);E!=null&&b.push(E)}x.push({bodyIds:P,constraintIndices:b,childIndices:[]})}let d=g.zpp_inner.bphase.is_sweep?"SWEEP_AND_PRUNE":"DYNAMIC_AABB_TREE",_=g.gravity;return{version:1,gravity:ut(_),worldLinearDrag:g.worldLinearDrag,worldAngularDrag:g.worldAngularDrag,sortContacts:g.sortContacts,broadphase:d,bodies:e,constraints:o,compounds:x}}var ri=class{static POSINF(){return 1/0}static NEGINF(){return-1/0}};ri.FMAX=1e100;var vt=class vt{static Constraint(){return vt._Constraint++}static Interactor(){return vt._Interactor++}static CbType(){return vt._CbType++}static CbSet(){return vt._CbSet++}static Listener(){return vt._Listener++}static ZPP_SimpleVert(){return vt._ZPP_SimpleVert++}static ZPP_SimpleSeg(){return vt._ZPP_SimpleSeg++}static Space(){return vt._Space++}static InteractionGroup(){return vt._InteractionGroup++}};vt._Constraint=0,vt._Interactor=0,vt._CbType=0,vt._CbSet=0,vt._Listener=0,vt._ZPP_SimpleVert=0,vt._ZPP_SimpleSeg=0,vt._Space=0,vt._InteractionGroup=0;var un=vt;var H=class{};H.GravMassMode_DEFAULT=null,H.GravMassMode_FIXED=null,H.GravMassMode_SCALED=null,H.InertiaMode_DEFAULT=null,H.InertiaMode_FIXED=null,H.MassMode_DEFAULT=null,H.MassMode_FIXED=null,H.BodyType_STATIC=null,H.BodyType_DYNAMIC=null,H.BodyType_KINEMATIC=null,H.ListenerType_BODY=null,H.ListenerType_CONSTRAINT=null,H.ListenerType_INTERACTION=null,H.ListenerType_PRE=null,H.PreFlag_ACCEPT=null,H.PreFlag_IGNORE=null,H.PreFlag_ACCEPT_ONCE=null,H.PreFlag_IGNORE_ONCE=null,H.CbEvent_BEGIN=null,H.CbEvent_ONGOING=null,H.CbEvent_END=null,H.CbEvent_WAKE=null,H.CbEvent_SLEEP=null,H.CbEvent_BREAK=null,H.CbEvent_PRE=null,H.InteractionType_COLLISION=null,H.InteractionType_SENSOR=null,H.InteractionType_FLUID=null,H.InteractionType_ANY=null,H.Winding_UNDEFINED=null,H.Winding_CLOCKWISE=null,H.Winding_ANTICLOCKWISE=null,H.ValidationResult_VALID=null,H.ValidationResult_DEGENERATE=null,H.ValidationResult_CONCAVE=null,H.ValidationResult_SELF_INTERSECTING=null,H.ShapeType_CIRCLE=null,H.ShapeType_POLYGON=null,H.Broadphase_DYNAMIC_AABB_TREE=null,H.Broadphase_SWEEP_AND_PRUNE=null,H.ArbiterType_COLLISION=null,H.ArbiterType_SENSOR=null,H.ArbiterType_FLUID=null,H.internal=!1,H.id_ImmState_ACCEPT=1,H.id_ImmState_IGNORE=2,H.id_ImmState_ALWAYS=4,H.id_GravMassMode_DEFAULT=0,H.id_GravMassMode_FIXED=1,H.id_GravMassMode_SCALED=2,H.id_InertiaMode_DEFAULT=0,H.id_InertiaMode_FIXED=1,H.id_MassMode_DEFAULT=0,H.id_MassMode_FIXED=1,H.id_BodyType_STATIC=1,H.id_BodyType_DYNAMIC=2,H.id_BodyType_KINEMATIC=3,H.id_ListenerType_BODY=0,H.id_ListenerType_CONSTRAINT=1,H.id_ListenerType_INTERACTION=2,H.id_ListenerType_PRE=3,H.id_PreFlag_ACCEPT=1,H.id_PreFlag_IGNORE=2,H.id_PreFlag_ACCEPT_ONCE=3,H.id_PreFlag_IGNORE_ONCE=4,H.id_CbEvent_BEGIN=0,H.id_CbEvent_END=1,H.id_CbEvent_WAKE=2,H.id_CbEvent_SLEEP=3,H.id_CbEvent_BREAK=4,H.id_CbEvent_PRE=5,H.id_CbEvent_ONGOING=6,H.id_InteractionType_COLLISION=1,H.id_InteractionType_SENSOR=2,H.id_InteractionType_FLUID=4,H.id_InteractionType_ANY=7,H.id_Winding_UNDEFINED=0,H.id_Winding_CLOCKWISE=1,H.id_Winding_ANTICLOCKWISE=2,H.id_ValidationResult_VALID=0,H.id_ValidationResult_DEGENERATE=1,H.id_ValidationResult_CONCAVE=2,H.id_ValidationResult_SELF_INTERSECTING=3,H.id_ShapeType_CIRCLE=0,H.id_ShapeType_POLYGON=1,H.id_Broadphase_DYNAMIC_AABB_TREE=0,H.id_Broadphase_SWEEP_AND_PRUNE=1,H.id_ArbiterType_COLLISION=1,H.id_ArbiterType_SENSOR=2,H.id_ArbiterType_FLUID=4;var el=class{static sqrt(e){return Math.sqrt(e)}static invsqrt(e){return 1/Math.sqrt(e)}static sqr(e){return e*e}static clamp2(e,t){let n=-t;return e<n?n:e>t?t:e}static clamp(e,t,n){return e<t?t:e>n?n:e}};var _e=class{};_e.poolGeomPoly=null,_e.nextGeomPoly=null,_e.poolVec2=null,_e.nextVec2=null,_e.poolVec3=null,_e.nextVec3=null;var Ms=class{constructor(e,t){this.list=[];this.width=0;this.width=e,this.list=[]}resize(e,t,n){this.width=e;let s=e*t;for(let i=0;i<s;i++)this.list[i]=n}get(e,t){return this.list[t*this.width+e]}set(e,t,n){return this.list[t*this.width+e]=n}},as=class extends Ms{},ps=class extends Ms{},cs=class extends Ms{};var bn=class bn{constructor(){this.value=!1;this.next=null;this.hnext=null;this.id=0;this.di=0}static _alloc(){if(bn.zpp_pool==null)return new bn;let e=bn.zpp_pool;return bn.zpp_pool=e.next,e.next=null,e}static get(e,t,n){let s=bn._alloc();return s.id=e,s.di=t,s.value=n,s}static getpersist(e,t){let n=bn._alloc();return n.id=e,n.di=t,n}static ordered_get(e,t,n){if(e<=t){let s=bn._alloc();return s.id=e,s.di=t,s.value=n,s}else{let s=bn._alloc();return s.id=t,s.di=e,s.value=n,s}}static ordered_get_persist(e,t){if(e<=t){let n=bn._alloc();return n.id=e,n.di=t,n}else{let n=bn._alloc();return n.id=t,n.di=e,n}}free(){}alloc(){}};bn.zpp_pool=null;var je=bn;var Mo=1048576,Ei=1048575,Ni=106039,Oi=class{constructor(){this.cnt=0;this.cnt=0,this.table=new Array(Mo).fill(null)}empty(){return this.cnt==0}clear(){for(let e=0;e<this.table.length;e++){let t=this.table[e];if(t!=null){for(;t!=null;){let n=t.hnext;t.hnext=null,t=n}this.table[e]=null}}}get(e,t){let n=this.table[e*Ni+t&Ei];if(n==null)return null;if(n.id==e&&n.di==t)return n;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n}ordered_get(e,t){if(e>t){let s=e;e=t,t=s}let n=this.table[e*Ni+t&Ei];if(n==null)return null;if(n.id==e&&n.di==t)return n;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n}has(e,t){let n=this.table[e*Ni+t&Ei];if(n==null)return!1;if(n.id==e&&n.di==t)return!0;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n!=null}maybeAdd(e){let t=e.id*Ni+e.di&Ei,n=this.table[t],s=!0;n==null?(this.table[t]=e,e.hnext=null):s&&(e.hnext=n.hnext,n.hnext=e),s&&this.cnt++}add(e){let t=e.id*Ni+e.di&Ei,n=this.table[t];n==null?(this.table[t]=e,e.hnext=null):(e.hnext=n.hnext,n.hnext=e),this.cnt++}remove(e){let t=e.id*Ni+e.di&Ei,n=this.table[t];if(n==e)this.table[t]=n.hnext;else if(n!=null){let s;for(;s=n,n=n.hnext,n!=null&&n!=e;);s.hnext=n.hnext}e.hnext=null,this.cnt--}hash(e,t){return e*Ni+t&Ei}};var Zs=class{constructor(){this.elt=null;this.next=null}alloc(){}free(){this.elt=null}elem(){return this.elt}};Zs.zpp_pool=null;var xt=class{constructor(){this.head=null;this.length=0;this.modified=!1;this.pushmod=!1}_allocNode(){let e=this.constructor._NodeClass,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor._NodeClass;e.elt=null,e.next=t.zpp_pool,t.zpp_pool=e}begin(){return this.head}setbegin(e){this.head=e,this.modified=!0,this.pushmod=!0}add(e){let t=this._allocNode();return t.elt=e,t.next=this.head,this.head=t,this.modified=!0,this.length++,e}addAll(e){let t=e.head;for(;t!=null;)this.add(t.elt),t=t.next}insert(e,t){let n=this._allocNode();return n.elt=t,e==null?(n.next=this.head,this.head=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.head.elt;return this.pop(),e}erase(e){let t,n;return e==null?(t=this.head,n=t.next,this.head=n,this.head==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),this._freeNode(t),this.modified=!0,this.length--,this.pushmod=!0,n}remove(e){let t=null,n=this.head;for(;n!=null;){if(n.elt==e){this.erase(t);break}t=n,n=n.next}}try_remove(e){let t=null,n=this.head,s=!1;for(;n!=null;){if(n.elt==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){for(;this.head!=null;){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=!0),this.modified=!0,this.length--}this.pushmod=!0}reverse(){let e=this.head,t=null;for(;e!=null;){let n=e.next;e.next=t,this.head=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.head==null}size(){return this.length}has(e){let t=this.head;for(;t!=null;){if(t.elt==e)return!0;t=t.next}return!1}front(){return this.head.elt}back(){let e=this.head,t=e;for(;t!=null;)e=t,t=t.next;return e.elt}iterator_at(e){let t=this.head;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t!=null?t.elt:null}};xt.prototype.inlined_add=xt.prototype.add;xt.prototype.inlined_insert=xt.prototype.insert;xt.prototype.inlined_pop=xt.prototype.pop;xt.prototype.inlined_pop_unsafe=xt.prototype.pop_unsafe;xt.prototype.inlined_erase=xt.prototype.erase;xt.prototype.inlined_remove=xt.prototype.remove;xt.prototype.inlined_try_remove=xt.prototype.try_remove;xt.prototype.inlined_clear=xt.prototype.clear;xt.prototype.inlined_has=xt.prototype.has;var ks=class{constructor(){this.colour=0;this.parent=null;this.next=null;this.prev=null;this.data=null;this.swapped=null;this.lt=null}_allocNode(){let e=this.constructor,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor;e.data=null,e.lt=null,e.swapped=null,e.next=t.zpp_pool,t.zpp_pool=e}free(){this.data=null,this.lt=null,this.swapped=null}alloc(){}verify(){if(!this.empty()){let e=this.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;){let t=e.data,n=!0;if(!this.empty()){let s=this.parent;for(;s.prev!=null;)s=s.prev;for(;s!=null;){let i=s.data;if(n){if(t==i)n=!1;else if(!this.lt(i,t)&&this.lt(t,i))return!1}else if(!this.lt(t,i)&&this.lt(i,t))return!1;if(s.next!=null)for(s=s.next;s.prev!=null;)s=s.prev;else{for(;s.parent!=null&&s==s.parent.next;)s=s.parent;s=s.parent}}}if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent}}}return!0}empty(){return this.parent==null}singular(){return this.parent!=null&&this.parent.prev==null?this.parent.next==null:!1}size(){let e=0;if(!this.empty()){let t=this.parent;for(;t.prev!=null;)t=t.prev;for(;t!=null;)if(++e,t.next!=null)for(t=t.next;t.prev!=null;)t=t.prev;else{for(;t.parent!=null&&t==t.parent.next;)t=t.parent;t=t.parent}}return e}has(e){return this.find(e)!=null}find(e){let t=this.parent;for(;t!=null&&t.data!=e;)this.lt(e,t.data)?t=t.prev:t=t.next;return t}has_weak(e){return this.find_weak(e)!=null}find_weak(e){let t=this.parent;for(;t!=null;)if(this.lt(e,t.data))t=t.prev;else if(this.lt(t.data,e))t=t.next;else break;return t}lower_bound(e){let t=null;if(!this.empty()){let n=this.parent;for(;n.prev!=null;)n=n.prev;for(;n!=null;){if(!this.lt(n.data,e)){t=n.data;break}if(n.next!=null)for(n=n.next;n.prev!=null;)n=n.prev;else{for(;n.parent!=null&&n==n.parent.next;)n=n.parent;n=n.parent}}}return t}first(){let e=this.parent;for(;e.prev!=null;)e=e.prev;return e.data}pop_front(){let e=this.parent;for(;e.prev!=null;)e=e.prev;let t=e.data;return this.remove_node(e),t}remove(e){this.remove_node(this.find(e))}successor_node(e){if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{let t=e;for(e=e.parent;e!=null&&e.prev!=t;)t=e,e=e.parent}return e}predecessor_node(e){if(e.prev!=null)for(e=e.prev;e.next!=null;)e=e.next;else{let t=e;for(e=e.parent;e!=null&&e.next!=t;)t=e,e=e.parent}return e}successor(e){let t=this.successor_node(this.find(e));return t==null?null:t.data}predecessor(e){let t=this.predecessor_node(this.find(e));return t==null?null:t.data}remove_node(e){if(e.next!=null&&e.prev!=null){let s=e.next;for(;s.prev!=null;)s=s.prev;let i=e.data;e.data=s.data,s.data=i,this.swapped!=null&&this.swapped(e.data,s.data),e=s}let t=e.prev==null?e.next:e.prev;if(e.colour==1){if(e.prev!=null||e.next!=null)t.colour=1;else if(e.parent!=null){let s=e.parent;for(;;){s.colour++,s.prev.colour--,s.next.colour--;let i=s.prev;if(i.colour==-1){this.__fix_neg_red(i);break}else if(i.colour==0){if(i.prev!=null&&i.prev.colour==0){this.__fix_dbl_red(i.prev);break}if(i.next!=null&&i.next.colour==0){this.__fix_dbl_red(i.next);break}}let l=s.next;if(l.colour==-1){this.__fix_neg_red(l);break}else if(l.colour==0){if(l.prev!=null&&l.prev.colour==0){this.__fix_dbl_red(l.prev);break}if(l.next!=null&&l.next.colour==0){this.__fix_dbl_red(l.next);break}}if(s.colour==2)if(s.parent==null)s.colour=1;else{s=s.parent;continue}break}}}let n=e.parent;n==null?this.parent=t:n.prev==e?n.prev=t:n.next=t,t!=null&&(t.parent=n),e.parent=e.prev=e.next=null,this._freeNode(e)}clear(){if(this.parent!=null){let e=this.parent;for(;e!=null;)if(e.prev!=null)e=e.prev;else if(e.next!=null)e=e.next;else{let t=e.parent;t!=null&&(e==t.prev?t.prev=null:t.next=null,e.parent=null),this._freeNode(e),e=t}this.parent=null}}clear_with(e){if(this.parent==null)return;let t=this.parent;for(;t!=null;)if(t.prev!=null)t=t.prev;else if(t.next!=null)t=t.next;else{e(t.data);let n=t.parent;n!=null&&(t==n.prev?n.prev=null:n.next=null,t.parent=null),this._freeNode(t),t=n}this.parent=null}clear_node(e,t){t(e.data);let n=e.parent;return n!=null&&(e==n.prev?n.prev=null:n.next=null,e.parent=null),this._freeNode(e),n}__fix_neg_red(e){let t=e.parent,n;if(t.prev==e){let s=e.prev,i=e.next,l=i.prev,r=i.next;s.colour=0,e.colour=t.colour=1,e.next=l,l!=null&&(l.parent=e);let a=t.data;t.data=i.data,i.data=a,this.swapped!=null&&this.swapped(t.data,i.data),i.prev=r,r!=null&&(r.parent=i),i.next=t.next,t.next!=null&&(t.next.parent=i),t.next=i,i!=null&&(i.parent=t),n=s}else{let s=e.next,i=e.prev,l=i.next,r=i.prev;s.colour=0,e.colour=t.colour=1,e.prev=l,l!=null&&(l.parent=e);let a=t.data;t.data=i.data,i.data=a,this.swapped!=null&&this.swapped(t.data,i.data),i.next=r,r!=null&&(r.parent=i),i.prev=t.prev,t.prev!=null&&(t.prev.parent=i),t.prev=i,i!=null&&(i.parent=t),n=s}n.prev!=null&&n.prev.colour==0?this.__fix_dbl_red(n.prev):n.next!=null&&n.next.colour==0&&this.__fix_dbl_red(n.next)}__fix_dbl_red(e){for(;;){let t=e.parent,n=t.parent;if(n==null){t.colour=1;break}let s,i,l,r,a,o,p;t==n.prev?(l=n,p=n.next,e==t.prev?(s=e,i=t,r=e.prev,a=e.next,o=t.next):(s=t,i=e,r=t.prev,a=e.prev,o=e.next)):(s=n,r=n.prev,e==t.prev?(i=e,l=t,a=e.prev,o=e.next,p=t.next):(i=t,l=e,a=t.prev,o=e.prev,p=e.next));let c=n.parent;if(c==null?this.parent=i:c.prev==n?c.prev=i:c.next=i,i!=null&&(i.parent=c),s.prev=r,r!=null&&(r.parent=s),s.next=a,a!=null&&(a.parent=s),i.prev=s,s!=null&&(s.parent=i),i.next=l,l!=null&&(l.parent=i),l.prev=o,o!=null&&(o.parent=l),l.next=p,p!=null&&(p.parent=l),i.colour=n.colour-1,s.colour=1,l.colour=1,i==this.parent)this.parent.colour=1;else if(i.colour==0&&i.parent.colour==0){e=i;continue}break}}try_insert_bool(e){let t=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else{let n=this.parent;for(;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break}return t==null?!1:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),!0)}try_insert(e){let t=null,n=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else for(n=this.parent;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break;return t==null?n:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t)}insert(e){let t=this._allocNode();if(t.data=e,this.parent==null)this.parent=t;else{let n=this.parent;for(;;)if(this.lt(t.data,n.data))if(n.prev==null){n.prev=t,t.parent=n;break}else n=n.prev;else if(n.next==null){n.next=t,t.parent=n;break}else n=n.next}return t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t}};ks.zpp_pool=null;var pi=null,tl=null,hs=null,El=null,Zo=null,Nl=null,us=null,Xt=null,xs=null,Jn=null,ds=null,_s=null,Ol=null,ko=null,Eo=null,No=null,Oo=null,So=null,Ao=null,Vo=null,Io=null;function qe(g){let e=class extends Zs{};return e.zpp_pool=null,e}function Ue(g,e){let t=class extends xt{};return t._NodeClass=e,t}function ai(g){let e=class extends ks{};return e.zpp_pool=null,e}function Fl(g){g.util||(g.util={}),g.util.ZNPNode_ZPP_CbType=qe("ZPP_CbType"),g.util.ZNPNode_ZPP_CallbackSet=qe("ZPP_CallbackSet"),g.util.ZNPNode_ZPP_Shape=qe("ZPP_Shape"),g.util.ZNPNode_ZPP_Body=qe("ZPP_Body"),g.util.ZNPNode_ZPP_Constraint=qe("ZPP_Constraint"),g.util.ZNPNode_ZPP_Compound=qe("ZPP_Compound"),g.util.ZNPNode_ZPP_Arbiter=qe("ZPP_Arbiter"),g.util.ZNPNode_ZPP_InteractionListener=qe("ZPP_InteractionListener"),g.util.ZNPNode_ZPP_CbSet=qe("ZPP_CbSet"),g.util.ZNPNode_ZPP_Interactor=qe("ZPP_Interactor"),g.util.ZNPNode_ZPP_BodyListener=qe("ZPP_BodyListener"),g.util.ZNPNode_ZPP_CbSetPair=qe("ZPP_CbSetPair"),g.util.ZNPNode_ZPP_ConstraintListener=qe("ZPP_ConstraintListener"),g.util.ZNPNode_ZPP_CutInt=qe("ZPP_CutInt"),g.util.ZNPNode_ZPP_CutVert=qe("ZPP_CutVert"),g.util.ZNPNode_ZPP_PartitionVertex=qe("ZPP_PartitionVertex"),g.util.ZNPNode_ZPP_SimplifyP=qe("ZPP_SimplifyP"),g.util.ZNPNode_ZPP_PartitionedPoly=qe("ZPP_PartitionedPoly"),g.util.ZNPNode_ZPP_GeomVert=qe("ZPP_GeomVert"),g.util.ZNPNode_ZPP_SimpleVert=qe("ZPP_SimpleVert"),g.util.ZNPNode_ZPP_SimpleEvent=qe("ZPP_SimpleEvent"),g.util.ZNPNode_ZPP_Vec2=qe("ZPP_Vec2"),g.util.ZNPNode_ZPP_AABBPair=qe("ZPP_AABBPair"),g.util.ZNPNode_ZPP_Edge=qe("ZPP_Edge"),g.util.ZNPNode_ZPP_AABBNode=qe("ZPP_AABBNode"),g.util.ZNPNode_ZPP_Component=qe("ZPP_Component"),g.util.ZNPNode_ZPP_FluidArbiter=qe("ZPP_FluidArbiter"),g.util.ZNPNode_ZPP_SensorArbiter=qe("ZPP_SensorArbiter"),g.util.ZNPNode_ZPP_Listener=qe("ZPP_Listener"),g.util.ZNPNode_ZPP_ColArbiter=qe("ZPP_ColArbiter"),g.util.ZNPNode_ZPP_InteractionGroup=qe("ZPP_InteractionGroup"),g.util.ZNPNode_ZPP_ToiEvent=qe("ZPP_ToiEvent"),g.util.ZNPNode_ConvexResult=qe("ConvexResult"),g.util.ZNPNode_ZPP_GeomPoly=qe("ZPP_GeomPoly"),g.util.ZNPNode_RayResult=qe("RayResult");let e=g.util;Eo=g.util.ZNPList_ZPP_InteractionListener=Ue("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),No=g.util.ZNPList_ZPP_BodyListener=Ue("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),Oo=g.util.ZNPList_ZPP_ConstraintListener=Ue("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),So=g.util.ZNPList_ZPP_Constraint=Ue("ZPP_Constraint",e.ZNPNode_ZPP_Constraint),Ao=g.util.ZNPList_ZPP_Interactor=Ue("ZPP_Interactor",e.ZNPNode_ZPP_Interactor),Vo=g.util.ZNPList_ZPP_CbSet=Ue("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),ko=g.util.ZNPList_ZPP_CbType=Ue("ZPP_CbType",e.ZNPNode_ZPP_CbType),g.util.ZNPList_ZPP_Vec2=Ue("ZPP_Vec2",e.ZNPNode_ZPP_Vec2),Zo=g.util.ZNPList_ZPP_Vec2,g.util.ZNPList_ZPP_CallbackSet=Ue("ZPP_CallbackSet",e.ZNPNode_ZPP_CallbackSet),g.util.ZNPList_ZPP_Shape=Ue("ZPP_Shape",e.ZNPNode_ZPP_Shape),g.util.ZNPList_ZPP_Body=Ue("ZPP_Body",e.ZNPNode_ZPP_Body),g.util.ZNPList_ZPP_Compound=Ue("ZPP_Compound",e.ZNPNode_ZPP_Compound),g.util.ZNPList_ZPP_Arbiter=Ue("ZPP_Arbiter",e.ZNPNode_ZPP_Arbiter),Io=g.util.ZNPList_ZPP_CbSetPair=Ue("ZPP_CbSetPair",e.ZNPNode_ZPP_CbSetPair),g.util.ZNPList_ZPP_CutInt=Ue("ZPP_CutInt",e.ZNPNode_ZPP_CutInt),g.util.ZNPList_ZPP_CutVert=Ue("ZPP_CutVert",e.ZNPNode_ZPP_CutVert),g.util.ZNPList_ZPP_PartitionVertex=Ue("ZPP_PartitionVertex",e.ZNPNode_ZPP_PartitionVertex),pi=g.util.ZNPList_ZPP_PartitionVertex,g.util.ZNPList_ZPP_SimplifyP=Ue("ZPP_SimplifyP",e.ZNPNode_ZPP_SimplifyP),El=g.util.ZNPList_ZPP_SimplifyP,g.util.ZNPList_ZPP_PartitionedPoly=Ue("ZPP_PartitionedPoly",e.ZNPNode_ZPP_PartitionedPoly),tl=g.util.ZNPList_ZPP_PartitionedPoly,g.util.ZNPList_ZPP_GeomVert=Ue("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),hs=g.util.ZNPList_ZPP_GeomVert,g.util.ZNPList_ZPP_SimpleVert=Ue("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),Ol=g.util.ZNPList_ZPP_SimpleEvent=Ue("ZPP_SimpleEvent",e.ZNPNode_ZPP_SimpleEvent),g.util.ZNPList_ZPP_AABBPair=Ue("ZPP_AABBPair",e.ZNPNode_ZPP_AABBPair),g.util.ZNPList_ZPP_Edge=Ue("ZPP_Edge",e.ZNPNode_ZPP_Edge),g.util.ZNPList_ZPP_AABBNode=Ue("ZPP_AABBNode",e.ZNPNode_ZPP_AABBNode),g.util.ZNPList_ZPP_Component=Ue("ZPP_Component",e.ZNPNode_ZPP_Component),g.util.ZNPList_ZPP_FluidArbiter=Ue("ZPP_FluidArbiter",e.ZNPNode_ZPP_FluidArbiter),g.util.ZNPList_ZPP_SensorArbiter=Ue("ZPP_SensorArbiter",e.ZNPNode_ZPP_SensorArbiter),g.util.ZNPList_ZPP_Listener=Ue("ZPP_Listener",e.ZNPNode_ZPP_Listener),g.util.ZNPList_ZPP_ColArbiter=Ue("ZPP_ColArbiter",e.ZNPNode_ZPP_ColArbiter),g.util.ZNPList_ZPP_InteractionGroup=Ue("ZPP_InteractionGroup",e.ZNPNode_ZPP_InteractionGroup),g.util.ZNPList_ZPP_ToiEvent=Ue("ZPP_ToiEvent",e.ZNPNode_ZPP_ToiEvent),g.util.ZNPList_ConvexResult=Ue("ConvexResult",e.ZNPNode_ConvexResult),g.util.ZNPList_ZPP_GeomPoly=Ue("ZPP_GeomPoly",e.ZNPNode_ZPP_GeomPoly),g.util.ZNPList_RayResult=Ue("RayResult",e.ZNPNode_RayResult),us=g.util.ZNPNode_RayResult,Nl=g.util.ZNPList_ZPP_SimpleVert,g.util.ZPP_Set_ZPP_Body=ai("ZPP_Body"),g.util.ZPP_Set_ZPP_CbSetPair=ai("ZPP_CbSetPair"),g.util.ZPP_Set_ZPP_PartitionVertex=ai("ZPP_PartitionVertex"),ds=g.util.ZPP_Set_ZPP_PartitionVertex,g.util.ZPP_Set_ZPP_PartitionPair=ai("ZPP_PartitionPair"),_s=g.util.ZPP_Set_ZPP_PartitionPair,g.util.ZPP_Set_ZPP_SimpleVert=ai("ZPP_SimpleVert"),Xt=g.util.ZPP_Set_ZPP_SimpleVert,g.util.ZPP_Set_ZPP_SimpleSeg=ai("ZPP_SimpleSeg"),xs=g.util.ZPP_Set_ZPP_SimpleSeg,g.util.ZPP_Set_ZPP_SimpleEvent=ai("ZPP_SimpleEvent"),Jn=g.util.ZPP_Set_ZPP_SimpleEvent,g.util.ZPP_Set_ZPP_CbSet=ai("ZPP_CbSet")}var ft=class ft{constructor(){this.outer_body=null;this.outer_con=null;this.outer_int=null;this.event=0;this.listener=null;this.space=null;this.index=0;this.next=null;this.prev=null;this.length=0;this.int1=null;this.int2=null;this.set=null;this.wrap_arbiters=null;this.pre_arbiter=null;this.pre_swapped=!1;this.body=null;this.constraint=null}wrapper_body(){return this.outer_body==null&&(ft.internal=!0,this.outer_body=ft._createBodyCb(),ft.internal=!1,this.outer_body.zpp_inner=this),this.outer_body}wrapper_con(){return this.outer_con==null&&(ft.internal=!0,this.outer_con=ft._createConCb(),ft.internal=!1,this.outer_con.zpp_inner=this),this.outer_con}wrapper_int(){let e=ft._zpp;return this.outer_int==null&&(ft.internal=!0,this.outer_int=ft._createIntCb(),ft.internal=!1,this.outer_int.zpp_inner=this),this.wrap_arbiters==null?this.wrap_arbiters=e.util.ZPP_ArbiterList.get(this.set.arbiters,!0):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=!0,this.wrap_arbiters.zpp_inner.at_ite=null,this.outer_int}push(e){this.prev!=null?this.prev.next=e:this.next=e,e.prev=this.prev,e.next=null,this.prev=e,this.length++}push_rev(e){this.next!=null?this.next.prev=e:this.prev=e,e.next=this.next,e.prev=null,this.next=e,this.length++}pop(){let e=this.next;return this.next=e.next,this.next==null?this.prev=null:this.next.prev=null,this.length--,e}pop_rev(){let e=this.prev;return this.prev=e.prev,this.prev==null?this.next=null:this.prev.next=null,this.length--,e}empty(){return this.next==null}clear(){for(;!this.empty();)this.pop()}splice(e){let t=e.next;return e.prev==null?(this.next=e.next,this.next!=null?this.next.prev=null:this.prev=null):(e.prev.next=e.next,e.next!=null?e.next.prev=e.prev:this.prev=e.prev),this.length--,t}rotateL(){this.push(this.pop())}rotateR(){this.push_rev(this.pop_rev())}cycleNext(e){return e.next==null?this.next:e.next}cyclePrev(e){return e.prev==null?this.prev:e.prev}at(e){let t=this.next;for(;e--!=0;)t=t.next;return t}rev_at(e){let t=this.prev;for(;e--!=0;)t=t.prev;return t}free(){this.int1=this.int2=null,this.body=null,this.constraint=null,this.listener=null,this.wrap_arbiters!=null&&(this.wrap_arbiters.zpp_inner.inner=null),this.set=null}alloc(){}genarbs(){let e=ft._zpp;this.wrap_arbiters==null?this.wrap_arbiters=e.util.ZPP_ArbiterList.get(this.set.arbiters,!0):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=!0,this.wrap_arbiters.zpp_inner.at_ite=null}};ft._nape=null,ft._zpp=null,ft.internal=!1,ft.zpp_pool=null,ft._createBodyCb=null,ft._createConCb=null,ft._createIntCb=null,ft._createPreCb=null;var jt=ft;var Rt=class Rt{constructor(){this.count=0;this.next=null;this.id=0;this.manager=null;this.cbpairs=null;this.zip_listeners=!1;this.zip_bodylisteners=!1;this.zip_conlisteners=!1;this.interactors=null;this.wrap_interactors=null;this.constraints=null;this.wrap_constraints=null;let e=Rt._zpp;this.cbTypes=new e.util.ZNPList_ZPP_CbType,this.listeners=new e.util.ZNPList_ZPP_InteractionListener,this.zip_listeners=!0,this.bodylisteners=new e.util.ZNPList_ZPP_BodyListener,this.zip_bodylisteners=!0,this.conlisteners=new e.util.ZNPList_ZPP_ConstraintListener,this.zip_conlisteners=!0,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.interactors=new e.util.ZNPList_ZPP_Interactor,this.id=e.ZPP_ID.CbSet(),this.cbpairs=new e.util.ZNPList_ZPP_CbSetPair}static setlt(e,t){let n=e.cbTypes.head,s=t.cbTypes.head;for(;n!=null&&s!=null;){let i=n.elt,l=s.elt;if(i.id<l.id)return!0;if(l.id<i.id)return!1;n=n.next,s=s.next}return s!=null?n==null:!1}static get(e){let t;Rt.zpp_pool==null?t=new Rt:(t=Rt.zpp_pool,Rt.zpp_pool=t.next,t.next=null);let n=null,s=e.head;for(;s!=null;){let i=s.elt;n=t.cbTypes.insert(n,i),i.cbsets.add(t),s=s.next}return t}static compatible(e,t,n){let s,i=e.options1,l=t.cbTypes;if(i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)){let r=e.options2,a=n.cbTypes;s=r.nonemptyintersection(a,r.includes)&&!r.nonemptyintersection(a,r.excludes)}else s=!1;if(s)return!0;{let r=e.options2,a=t.cbTypes;if(r.nonemptyintersection(a,r.includes)&&!r.nonemptyintersection(a,r.excludes)){let o=e.options1,p=n.cbTypes;return o.nonemptyintersection(p,o.includes)?!o.nonemptyintersection(p,o.excludes):!1}else return!1}}static findOrCreatePair(e,t){let n=Rt._zpp,s=null,l=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;l!=null;){let r=l.elt;if(r.a==e&&r.b==t||r.a==t&&r.b==e){s=r;break}l=l.next}if(s==null){let r;n.callbacks.ZPP_CbSetPair.zpp_pool==null?r=new n.callbacks.ZPP_CbSetPair:(r=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=r.next,r.next=null),r.zip_listeners=!0,Rt.setlt(e,t)?(r.a=e,r.b=t):(r.a=t,r.b=e),s=r,e.cbpairs.add(s),t!=e&&t.cbpairs.add(s)}return s.zip_listeners&&(s.zip_listeners=!1,s.__validate()),s}static empty_intersection(e,t){return Rt.findOrCreatePair(e,t).listeners.head==null}static single_intersection(e,t,n){let i=Rt.findOrCreatePair(e,t).listeners.head;return i!=null&&i.elt==n?i.next==null:!1}static find_all(e,t,n,s){let l=Rt.findOrCreatePair(e,t).listeners.head;for(;l!=null;){let r=l.elt;r.event==n&&s(r),l=l.next}}increment(){this.count++}decrement(){return--this.count==0}invalidate_pairs(){let e=this.cbpairs.head;for(;e!=null;){let t=e.elt;t.zip_listeners=!0,e=e.next}}invalidate_listeners(){this.zip_listeners=!0,this.invalidate_pairs()}validate_listeners(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners())}realvalidate_listeners(){let e=Rt._zpp;this.listeners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.listeners.head,l=n.listeners.head;for(;l!=null;){let r=l.elt;if(i!=null&&i.elt==r)l=l.next,s=i,i=i.next;else{let a;if(i!=null){let o=i.elt;a=r.precedence>o.precedence||r.precedence==o.precedence&&r.id>o.id}else a=!0;if(a){if(r.space==this.manager.space){let o=this.listeners,p;e.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?p=new e.util.ZNPNode_ZPP_InteractionListener:(p=e.util.ZNPNode_ZPP_InteractionListener.zpp_pool,e.util.ZNPNode_ZPP_InteractionListener.zpp_pool=p.next,p.next=null),p.elt=r;let c=p;s==null?(c.next=o.head,o.head=c):(c.next=s.next,s.next=c),o.pushmod=o.modified=!0,o.length++,s=c}l=l.next}else s=i,i=i.next}}t=t.next}}invalidate_bodylisteners(){this.zip_bodylisteners=!0}validate_bodylisteners(){this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners())}realvalidate_bodylisteners(){let e=Rt._zpp;this.bodylisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.bodylisteners.head,l=n.bodylisteners.head;for(;l!=null;){let r=l.elt;if(i!=null&&i.elt==r)l=l.next,s=i,i=i.next;else{let a;if(i!=null){let o=i.elt;a=r.precedence>o.precedence||r.precedence==o.precedence&&r.id>o.id}else a=!0;if(a){let o=r.options;if(!o.nonemptyintersection(this.cbTypes,o.excludes)&&r.space==this.manager.space){let p=this.bodylisteners,c;e.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_BodyListener:(c=e.util.ZNPNode_ZPP_BodyListener.zpp_pool,e.util.ZNPNode_ZPP_BodyListener.zpp_pool=c.next,c.next=null),c.elt=r;let h=c;s==null?(h.next=p.head,p.head=h):(h.next=s.next,s.next=h),p.pushmod=p.modified=!0,p.length++,s=h}l=l.next}else s=i,i=i.next}}t=t.next}}invalidate_conlisteners(){this.zip_conlisteners=!0}validate_conlisteners(){this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}realvalidate_conlisteners(){let e=Rt._zpp;this.conlisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.conlisteners.head,l=n.conlisteners.head;for(;l!=null;){let r=l.elt;if(i!=null&&i.elt==r)l=l.next,s=i,i=i.next;else{let a;if(i!=null){let o=i.elt;a=r.precedence>o.precedence||r.precedence==o.precedence&&r.id>o.id}else a=!0;if(a){let o=r.options;if(!o.nonemptyintersection(this.cbTypes,o.excludes)&&r.space==this.manager.space){let p=this.conlisteners,c;e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_ConstraintListener:(c=e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=c.next,c.next=null),c.elt=r;let h=c;s==null?(h.next=p.head,p.head=h):(h.next=s.next,s.next=h),p.pushmod=p.modified=!0,p.length++,s=h}l=l.next}else s=i,i=i.next}}t=t.next}}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners()),this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners()),this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}addConstraint(e){this.constraints.add(e)}addInteractor(e){this.interactors.add(e)}remConstraint(e){this.constraints.remove(e)}remInteractor(e){this.interactors.remove(e)}free(){for(this.listeners.clear(),this.zip_listeners=!0,this.bodylisteners.clear(),this.zip_bodylisteners=!0,this.conlisteners.clear(),this.zip_conlisteners=!0;this.cbTypes.head!=null;)this.cbTypes.pop_unsafe().cbsets.remove(this)}alloc(){}};Rt._zpp=null,Rt.zpp_pool=null;var dt=Rt;var Ln=class Ln{constructor(){this.a=null;this.b=null;this.next=null;this.zip_listeners=!1;this.listeners=null;let e=Ln._zpp;this.listeners=new e.util.ZNPList_ZPP_InteractionListener}static get(e,t){let n=Ln._zpp,s;return Ln.zpp_pool==null?s=new Ln:(s=Ln.zpp_pool,Ln.zpp_pool=s.next,s.next=null),s.zip_listeners=!0,n.callbacks.ZPP_CbSet.setlt(e,t)?(s.a=e,s.b=t):(s.a=t,s.b=e),s}static setlt(e,t){let n=Ln._zpp;return n.callbacks.ZPP_CbSet.setlt(e.a,t.a)?!0:e.a==t.a?n.callbacks.ZPP_CbSet.setlt(e.b,t.b):!1}free(){this.a=this.b=null,this.listeners.clear()}alloc(){this.zip_listeners=!0}compatible(e){let t,n=e.options1,s=this.a.cbTypes;if(n.nonemptyintersection(s,n.includes)&&!n.nonemptyintersection(s,n.excludes)){let i=e.options2,l=this.b.cbTypes;t=i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)}else t=!1;if(t)return!0;{let i=e.options2,l=this.a.cbTypes;if(i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)){let r=e.options1,a=this.b.cbTypes;return r.nonemptyintersection(a,r.includes)?!r.nonemptyintersection(a,r.excludes):!1}else return!1}}invalidate(){this.zip_listeners=!0}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.__validate())}__validate(){this.listeners.clear();let e=this.a.listeners.head,t=this.b.listeners.head;for(;e!=null&&t!=null;){let n=e.elt,s=t.elt;if(n==s){let i,l,r=n.options1,a=this.a.cbTypes;if(r.nonemptyintersection(a,r.includes)&&!r.nonemptyintersection(a,r.excludes)){let o=n.options2,p=this.b.cbTypes;l=o.nonemptyintersection(p,o.includes)&&!o.nonemptyintersection(p,o.excludes)}else l=!1;if(l)i=!0;else{let o=n.options2,p=this.a.cbTypes;if(o.nonemptyintersection(p,o.includes)&&!o.nonemptyintersection(p,o.excludes)){let c=n.options1,h=this.b.cbTypes;i=c.nonemptyintersection(h,c.includes)&&!c.nonemptyintersection(h,c.excludes)}else i=!1}i&&this.listeners.add(n),e=e.next,t=t.next}else n.precedence>s.precedence||n.precedence==s.precedence&&n.id>s.id?e=e.next:t=t.next}}empty_intersection(){return this.listeners.head==null}single_intersection(e){let t=this.listeners.head;return t!=null&&t.elt==e?t.next==null:!1}forall(e,t){let n=this.listeners.head;for(;n!=null;){let s=n.elt;s.event==e&&t(s),n=n.next}}};Ln._zpp=null,Ln.zpp_pool=null;var Ne=Ln;var ln=class ln{constructor(){this.outer=null;this.userData=null;this.id=0;this.cbsets=null;this.interactors=null;this.wrap_interactors=null;this.constraints=null;this.wrap_constraints=null;this.listeners=null;this.bodylisteners=null;this.conlisteners=null;let e=ln._zpp;this.id=e.ZPP_ID.CbType(),this.listeners=new e.util.ZNPList_ZPP_InteractionListener,this.bodylisteners=new e.util.ZNPList_ZPP_BodyListener,this.conlisteners=new e.util.ZNPList_ZPP_ConstraintListener,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.interactors=new e.util.ZNPList_ZPP_Interactor,this.cbsets=new e.util.ZNPList_ZPP_CbSet}static _initEnums(e){ln.ANY_SHAPE=new e.callbacks.CbType,ln.ANY_BODY=new e.callbacks.CbType,ln.ANY_COMPOUND=new e.callbacks.CbType,ln.ANY_CONSTRAINT=new e.callbacks.CbType}static setlt(e,t){return e.id<t.id}addInteractor(e){this.interactors.add(e)}remInteractor(e){this.interactors.remove(e)}addConstraint(e){this.constraints.add(e)}remConstraint(e){this.constraints.remove(e)}addint(e){let t=ln._zpp,n=null,s=this.listeners.head;for(;s!=null;){let a=s.elt;if(e.precedence>a.precedence||e.precedence===a.precedence&&e.id>a.id)break;n=s,s=s.next}let i=this.listeners,l;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_InteractionListener:(l=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++;let r=this.cbsets.head;for(;r!=null;)r.elt.zip_listeners=!0,r.elt.invalidate_pairs(),r=r.next}removeint(e){this.listeners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_listeners=!0,t.elt.invalidate_pairs(),t=t.next}invalidateint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_listeners=!0,e.elt.invalidate_pairs(),e=e.next}addbody(e){let t=ln._zpp,n=null,s=this.bodylisteners.head;for(;s!=null;){let a=s.elt;if(e.precedence>a.precedence||e.precedence===a.precedence&&e.id>a.id)break;n=s,s=s.next}let i=this.bodylisteners,l;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_BodyListener:(l=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++;let r=this.cbsets.head;for(;r!=null;)r.elt.zip_bodylisteners=!0,r=r.next}removebody(e){this.bodylisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_bodylisteners=!0,t=t.next}invalidatebody(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_bodylisteners=!0,e=e.next}addconstraint(e){let t=ln._zpp,n=null,s=this.conlisteners.head;for(;s!=null;){let a=s.elt;if(e.precedence>a.precedence||e.precedence===a.precedence&&e.id>a.id)break;n=s,s=s.next}let i=this.conlisteners,l;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_ConstraintListener:(l=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++;let r=this.cbsets.head;for(;r!=null;)r.elt.zip_conlisteners=!0,r=r.next}removeconstraint(e){this.conlisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_conlisteners=!0,t=t.next}invalidateconstraint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_conlisteners=!0,e=e.next}};ln._zpp=null,ln.ANY_SHAPE=null,ln.ANY_BODY=null,ln.ANY_COMPOUND=null,ln.ANY_CONSTRAINT=null;var fn=ln;var $n=class $n{constructor(){this.space=null;this.interaction=null;this.constraint=null;this.body=null;this.precedence=0;this.event=0;this.type=0;this.id=0;this.outer=null;this.id=un.Listener()}static setlt(e,t){return e.precedence<=t.precedence?e.precedence==t.precedence?e.id>t.id:!1:!0}swapEvent(e){}invalidate_precedence(){}addedToSpace(){}removedFromSpace(){}static _initEnums(e,t){let n=()=>{t.internal=!0;let i=new e.callbacks.ListenerType;return t.internal=!1,i};t.ListenerType_BODY==null&&(t.ListenerType_BODY=n()),t.ListenerType_CONSTRAINT==null&&(t.ListenerType_CONSTRAINT=n()),t.ListenerType_INTERACTION==null&&(t.ListenerType_INTERACTION=n()),t.ListenerType_PRE==null&&(t.ListenerType_PRE=n()),$n.types=[t.ListenerType_BODY,t.ListenerType_CONSTRAINT,t.ListenerType_INTERACTION,t.ListenerType_PRE];let s=()=>{t.internal=!0;let i=new e.callbacks.CbEvent;return t.internal=!1,i};t.CbEvent_BEGIN==null&&(t.CbEvent_BEGIN=s()),t.CbEvent_END==null&&(t.CbEvent_END=s()),t.CbEvent_WAKE==null&&(t.CbEvent_WAKE=s()),t.CbEvent_SLEEP==null&&(t.CbEvent_SLEEP=s()),t.CbEvent_BREAK==null&&(t.CbEvent_BREAK=s()),t.CbEvent_PRE==null&&(t.CbEvent_PRE=s()),t.CbEvent_ONGOING==null&&(t.CbEvent_ONGOING=s()),$n.events=[t.CbEvent_BEGIN,t.CbEvent_END,t.CbEvent_WAKE,t.CbEvent_SLEEP,t.CbEvent_BREAK,t.CbEvent_PRE,t.CbEvent_ONGOING]}};$n._nape=null,$n._zpp=null,$n.internal=!1,$n.types=[],$n.events=[];var Tt=$n;var nl=class extends Tt{constructor(t,n,s){super();this.handler=null;this.options=null;this.outer_zn=null;this.event=n,this.handler=s,this.body=this,this.type=0,this.options=t.zpp_inner}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=Tt._zpp;this.options.handler=(s,i,l)=>this.cbtype_change(s,i,l);let n=this.options.includes.head;for(;n!=null;){let s=n.elt,i=null,l=s.bodylisteners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next}let r=s.bodylisteners,a;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?a=new t.util.ZNPNode_ZPP_BodyListener:(a=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=a.next,a.next=null),a.elt=this;let o=a;i==null?(o.next=r.head,r.head=o):(o.next=i.next,i.next=o),r.pushmod=r.modified=!0,r.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_bodylisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.bodylisteners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_bodylisteners=!0,s=s.next}t=t.next}this.options.handler=null}cbtype_change(t,n,s){this.removedFromSpace();let i=this.options;n?s?i.effect_change(t,!0,!0):i.includes.remove(t):s?i.effect_change(t,!1,!0):i.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3)throw new Error("Error: BodyListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};var il=class extends Tt{constructor(t,n,s){super();this.handler=null;this.options=null;this.outer_zn=null;this.event=n,this.handler=s,this.constraint=this,this.type=1,this.options=t.zpp_inner}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=Tt._zpp;this.options.handler=(s,i,l)=>this.cbtype_change(s,i,l);let n=this.options.includes.head;for(;n!=null;){let s=n.elt,i=null,l=s.conlisteners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next}let r=s.conlisteners,a;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?a=new t.util.ZNPNode_ZPP_ConstraintListener:(a=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=a.next,a.next=null),a.elt=this;let o=a;i==null?(o.next=r.head,r.head=o):(o.next=i.next,i.next=o),r.pushmod=r.modified=!0,r.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_conlisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.conlisteners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_conlisteners=!0,s=s.next}t=t.next}this.options.handler=null}cbtype_change(t,n,s){this.removedFromSpace();let i=this.options;n?s?i.effect_change(t,!0,!0):i.includes.remove(t):s?i.effect_change(t,!1,!0):i.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3&&t!=4)throw new Error("Error: ConstraintListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};var gt=class gt extends Tt{constructor(t,n,s,i){super();this.outer_zni=null;this.outer_znp=null;this.itype=0;this.handleri=null;this.allowSleepingCallbacks=!1;this.pure=!1;this.handlerp=null;this.type=i,this.interaction=this,this.event=s,this.options1=t.zpp_inner,this.options2=n.zpp_inner,this.allowSleepingCallbacks=!1}setInteractionType(t){this.itype=t}wake(){let t=this.options1.includes.head,n=this.options2.includes.head;for(;t!=null&&n!=null;){let s=t.elt,i=n.elt;if(s==i){let l=s.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;t=t.next,n=n.next}else if(s.id<i.id){let l=s.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;t=t.next}else{let l=i.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;n=n.next}}for(;t!=null;){let s=t.elt.interactors.head;for(;s!=null;)s.elt.wake(),s=s.next;t=t.next}for(;n!=null;){let s=n.elt.interactors.head;for(;s!=null;)s.elt.wake(),s=s.next;n=n.next}}CbSetset(t,n,s){let i=Tt._zpp,l=gt.UCbSet,r=gt.VCbSet,a=gt.WCbSet,o=t.head,p=n.head;for(;o!=null&&p!=null;){let c=o.elt,h=p.elt;if(c==h){let u=this._allocCbSetNode(i);u.elt=c,u.next=a.head,a.head=u,a.modified=!0,a.length++,o=o.next,p=p.next}else if(i.callbacks.ZPP_CbSet.setlt(c,h)){let u=this._allocCbSetNode(i);u.elt=c,u.next=l.head,l.head=u,l.modified=!0,l.length++,o=o.next}else{let u=this._allocCbSetNode(i);u.elt=h,u.next=r.head,r.head=u,r.modified=!0,r.length++,p=p.next}}for(;o!=null;){let c=this._allocCbSetNode(i);c.elt=o.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,o=o.next}for(;p!=null;){let c=this._allocCbSetNode(i);c.elt=p.elt,c.next=r.head,r.head=c,r.modified=!0,r.length++,p=p.next}for(;l.head!=null;){let c=l.pop_unsafe(),h=n.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe(),h=a.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;a.head!=null;){let c=a.pop_unsafe();s(c,c);let h=a.head;for(;h!=null;)s(c,h.elt),h=h.next}}CbTypeset(t,n,s){let i=Tt._zpp,l=gt.UCbType,r=gt.VCbType,a=gt.WCbType,o=t.head,p=n.head;for(;o!=null&&p!=null;){let c=o.elt,h=p.elt;if(c==h){let u=this._allocCbTypeNode(i);u.elt=c,u.next=a.head,a.head=u,a.modified=!0,a.length++,o=o.next,p=p.next}else if(c.id<h.id){let u=this._allocCbTypeNode(i);u.elt=c,u.next=l.head,l.head=u,l.modified=!0,l.length++,o=o.next}else{let u=this._allocCbTypeNode(i);u.elt=h,u.next=r.head,r.head=u,r.modified=!0,r.length++,p=p.next}}for(;o!=null;){let c=this._allocCbTypeNode(i);c.elt=o.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,o=o.next}for(;p!=null;){let c=this._allocCbTypeNode(i);c.elt=p.elt,c.next=r.head,r.head=c,r.modified=!0,r.length++,p=p.next}for(;l.head!=null;){let c=l.pop_unsafe(),h=n.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe(),h=a.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;a.head!=null;){let c=a.pop_unsafe();s(c,c);let h=a.head;for(;h!=null;)s(c,h.elt),h=h.next}}with_uniquesets(t){let n=Tt._zpp,s;if(n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool==null?s=new n.util.ZPP_Set_ZPP_CbSetPair:(s=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=s.next,s.next=null),s.lt=n.callbacks.ZPP_CbSetPair.setlt,this.CbTypeset(this.options1.includes,this.options2.includes,(l,r)=>{this.CbSetset(l.cbsets,r.cbsets,(a,o)=>{if(a.validate(),o.validate(),n.callbacks.ZPP_CbSet.single_intersection(a,o,this)){let p;n.callbacks.ZPP_CbSetPair.zpp_pool==null?p=new n.callbacks.ZPP_CbSetPair:(p=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=p.next,p.next=null),p.zip_listeners=!0,n.callbacks.ZPP_CbSet.setlt(a,o)?(p.a=a,p.b=o):(p.a=o,p.b=a),s.try_insert(p)}})}),s.parent!=null){let l=s.parent;for(;l!=null;)if(l.prev!=null)l=l.prev;else if(l.next!=null)l=l.next;else{let r=l.data;t?this.space.freshListenerType(r.a,r.b):this.space.nullListenerType(r.a,r.b);let a=r;a.a=a.b=null,a.listeners.clear(),a.next=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=a;let o=l.parent;o!=null&&(l==o.prev?o.prev=null:o.next=null,l.parent=null);let p=l;p.data=null,p.lt=null,p.swapped=null,p.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=p,l=o}s.parent=null}let i=s;i.data=null,i.lt=null,i.swapped=null,i.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=i}with_union(t){let n=this.options1.includes.head,s=this.options2.includes.head;for(;n!=null&&s!=null;){let i=n.elt,l=s.elt;i==l?(t(i),n=n.next,s=s.next):i.id<l.id?(t(i),n=n.next):(t(l),s=s.next)}for(;n!=null;)t(n.elt),n=n.next;for(;s!=null;)t(s.elt),s=s.next}addedToSpace(){let t=Tt._zpp,n=this.type==3;this.with_union(s=>{let i=null,l=s.listeners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next}let r=s.listeners,a;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?a=new t.util.ZNPNode_ZPP_InteractionListener:(a=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=a.next,a.next=null),a.elt=this;let o=a;i==null?(o.next=r.head,r.head=o):(o.next=i.next,i.next=o),r.pushmod=r.modified=!0,r.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_listeners=!0,c.invalidate_pairs(),p=p.next}if(n){let c=s.interactors.head;for(;c!=null;)c.elt.wake(),c=c.next}}),this.options1.handler=(s,i,l)=>this.cbtype_change1(s,i,l),this.options2.handler=(s,i,l)=>this.cbtype_change2(s,i,l),this.with_uniquesets(!0)}removedFromSpace(){this.with_uniquesets(!1);let t=this.type==3;this.with_union(n=>{n.listeners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_listeners=!0,i.invalidate_pairs(),s=s.next}if(t){let i=n.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next}}),this.options1.handler=null,this.options2.handler=null}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}cbtype_change1(t,n,s){this.cbtype_change(this.options1,t,n,s)}cbtype_change2(t,n,s){this.cbtype_change(this.options2,t,n,s)}cbtype_change(t,n,s,i){this.removedFromSpace(),s?i?t.effect_change(n,!0,!0):t.includes.remove(n):i?t.effect_change(n,!1,!0):t.excludes.remove(n),this.addedToSpace()}swapEvent(t){if(this.type==3)throw new Error("Error: PreListener event can only be PRE");if(t!=0&&t!=1&&t!=6)throw new Error("Error: InteractionListener event must be either BEGIN, END, ONGOING");this.removedFromSpace(),this.event=t,this.addedToSpace()}_allocCbSetNode(t){let n;return t.util.ZNPNode_ZPP_CbSet.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbSet:(n=t.util.ZNPNode_ZPP_CbSet.zpp_pool,t.util.ZNPNode_ZPP_CbSet.zpp_pool=n.next,n.next=null),n}_allocCbTypeNode(t){let n;return t.util.ZNPNode_ZPP_CbType.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbType:(n=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=n.next,n.next=null),n}static _initStatics(t){gt.UCbSet=new t.util.ZNPList_ZPP_CbSet,gt.VCbSet=new t.util.ZNPList_ZPP_CbSet,gt.WCbSet=new t.util.ZNPList_ZPP_CbSet,gt.UCbType=new t.util.ZNPList_ZPP_CbType,gt.VCbType=new t.util.ZNPList_ZPP_CbType,gt.WCbType=new t.util.ZNPList_ZPP_CbType}};gt.UCbSet=null,gt.VCbSet=null,gt.WCbSet=null,gt.UCbType=null,gt.VCbType=null,gt.WCbType=null;var sl=gt;var qn=class qn{constructor(){this.outer=null;this.handler=null;this.includes=null;this.excludes=null;this.wrap_includes=null;this.wrap_excludes=null;let e=qn._zpp;this.includes=new e.util.ZNPList_ZPP_CbType,this.excludes=new e.util.ZNPList_ZPP_CbType}static argument(e){let t=qn._nape;return e==null?new t.callbacks.OptionType:e instanceof t.callbacks.OptionType?e:new t.callbacks.OptionType().including(e)}setup_includes(){let e=qn._zpp;this.wrap_includes=e.util.ZPP_CbTypeList.get(this.includes,!0)}setup_excludes(){let e=qn._zpp;this.wrap_excludes=e.util.ZPP_CbTypeList.get(this.excludes,!0)}excluded(e){return this.nonemptyintersection(e,this.excludes)}included(e){return this.nonemptyintersection(e,this.includes)}compatible(e){return this.nonemptyintersection(e,this.includes)?!this.nonemptyintersection(e,this.excludes):!1}nonemptyintersection(e,t){let n=!1,s=e.head,i=t.head;for(;i!=null&&s!=null;){let l=i.elt,r=s.elt;if(l===r){n=!0;break}else l.id<r.id?i=i.next:s=s.next}return n}insertOrdered(e,t){let n=qn._zpp,s=null,i=e.head;for(;i!=null;){let r=i.elt;if(t.id<r.id)break;s=i,i=i.next}let l;n.util.ZNPNode_ZPP_CbType.zpp_pool==null?l=new n.util.ZNPNode_ZPP_CbType:(l=n.util.ZNPNode_ZPP_CbType.zpp_pool,n.util.ZNPNode_ZPP_CbType.zpp_pool=l.next,l.next=null),l.elt=t,s==null?(l.next=e.head,e.head=l):(l.next=s.next,s.next=l),e.pushmod=e.modified=!0,e.length++}effect_change(e,t,n){t?n?this.insertOrdered(this.includes,e):this.includes.remove(e):n?this.insertOrdered(this.excludes,e):this.excludes.remove(e)}append_type(e,t){e===this.includes?this.includes.has(t)||(this.excludes.has(t)?this.handler!=null?this.handler(t,!1,!1):this.excludes.remove(t):this.handler!=null?this.handler(t,!0,!0):this.insertOrdered(this.includes,t)):this.excludes.has(t)||(this.includes.has(t)?this.handler!=null?this.handler(t,!0,!1):this.includes.remove(t):this.handler!=null?this.handler(t,!1,!0):this.insertOrdered(this.excludes,t))}set(e){if(e!==this){for(;this.includes.head!=null;)this.append_type(this.excludes,this.includes.head.elt);for(;this.excludes.head!=null;)this.append_type(this.includes,this.excludes.head.elt);let t=e.excludes.head;for(;t!=null;){let s=t.elt;this.append_type(this.excludes,s),t=t.next}let n=e.includes.head;for(;n!=null;){let s=n.elt;this.append_type(this.includes,s),n=n.next}}return this}append(e,t){let n=qn._nape;if(t==null)throw new Error("Error: Cannot append null, only CbType and CbType list values");if(t instanceof n.callbacks.CbType){let s=t;this.append_type(e,s.zpp_inner)}else if(t instanceof n.callbacks.CbTypeList){let s=t;s.zpp_inner.valmod();let i=n.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let l=i.zpp_inner;l.zpp_inner.valmod(),l.zpp_inner.zip_length&&(l.zpp_inner.zip_length=!1,l.zpp_inner.user_length=l.zpp_inner.inner.length);let r=l.zpp_inner.user_length;i.zpp_critical=!0;let a;if(i.zpp_i<r?a=!0:(i.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,a=!1),!a)break;i.zpp_critical=!1;let o=i.zpp_inner.at(i.zpp_i++);this.append_type(e,o.zpp_inner)}}else if(t instanceof Array){let s=t,i=0;for(;i<s.length;){let l=s[i];if(++i,!(l instanceof n.callbacks.CbType))throw new Error("Error: Cannot append non-CbType or CbType list value");let r=l;this.append_type(e,r.zpp_inner)}}else throw new Error("Error: Cannot append non-CbType or CbType list value")}};qn._nape=null,qn._zpp=null;var ys=qn;var zn=class zn{constructor(){this.outer=null;this.id=0;this.userData=null;this.compound=null;this.space=null;this.active=!1;this.stiff=!1;this.frequency=0;this.damping=0;this.maxForce=0;this.maxError=0;this.breakUnderForce=!1;this.breakUnderError=!1;this.removeOnBreak=!1;this.component=null;this.ignore=!1;this.__velocity=!1;this.cbTypes=null;this.cbSet=null;this.wrap_cbTypes=null;this.pre_dt=-1;this._initBase()}_initBase(){let e=zn._zpp;this.id=un.Constraint(),this.stiff=!0,this.active=!0,this.ignore=!1,this.frequency=10,this.damping=1,this.maxForce=1/0,this.maxError=1/0,this.breakUnderForce=!1,this.removeOnBreak=!0,this.pre_dt=-1,this.cbTypes=new e.util.ZNPList_ZPP_CbType}clear(){}activeBodies(){}inactiveBodies(){}clearcache(){}validate(){}wake_connected(){}forest(){}broken(){}warmStart(){}draw(e){}pair_exists(e,t){return!1}preStep(e){return!1}applyImpulseVel(){return!1}applyImpulsePos(){return!1}copy(e,t){return null}immutable_midstep(e){if(this.space!=null&&this.space.midstep)throw new Error("Error: Constraint::"+e+" cannot be set during space step()")}setupcbTypes(){let e=zn._zpp;this.wrap_cbTypes=e.util.ZPP_CbTypeList.get(this.cbTypes),this.wrap_cbTypes.zpp_inner.adder=this.wrap_cbTypes_adder.bind(this),this.wrap_cbTypes.zpp_inner.subber=this.wrap_cbTypes_subber.bind(this),this.wrap_cbTypes.zpp_inner.dontremove=!0,this.wrap_cbTypes.zpp_inner._modifiable=this.immutable_cbTypes.bind(this)}immutable_cbTypes(){this.immutable_midstep("Constraint::cbTypes")}wrap_cbTypes_subber(e){let t=e.zpp_inner;this.cbTypes.has(t)&&(this.space!=null&&(this.dealloc_cbSet(),t.constraints.remove(this)),this.cbTypes.remove(t),this.space!=null&&(this.alloc_cbSet(),this.wake()))}wrap_cbTypes_adder(e){return this.insert_cbtype(e.zpp_inner),!1}insert_cbtype(e){let t=zn._zpp;if(!this.cbTypes.has(e)){this.space!=null&&(this.dealloc_cbSet(),e.constraints.add(this));let n=null,s=this.cbTypes.head;for(;s!=null;){let a=s.elt;if(e.id<a.id)break;n=s,s=s.next}let i=this.cbTypes,l;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?l=new t.util.ZNPNode_ZPP_CbType:(l=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;n==null?(r.next=i.head,i.head=r):(r.next=n.next,n.next=r),i.pushmod=i.modified=!0,i.length++,this.space!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){(this.cbSet=this.space.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.constraints.add(this))}dealloc_cbSet(){let e=zn._zpp;if(this.cbSet!=null){if(this.cbSet.constraints.remove(this),--this.cbSet.count==0){this.space.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=!0,t.bodylisteners.clear(),t.zip_bodylisteners=!0,t.conlisteners.clear(),t.zip_conlisteners=!0;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=e.callbacks.ZPP_CbSet.zpp_pool,e.callbacks.ZPP_CbSet.zpp_pool=t}this.cbSet=null}}activate(){this.space!=null&&this.activeInSpace()}deactivate(){this.space!=null&&this.inactiveOrOutSpace()}addedToSpace(){this.active&&this.activeInSpace(),this.activeBodies();let e=this.cbTypes.head;for(;e!=null;)e.elt.constraints.add(this),e=e.next}removedFromSpace(){this.active&&this.inactiveOrOutSpace(),this.inactiveBodies();let e=this.cbTypes.head;for(;e!=null;)e.elt.constraints.remove(this),e=e.next}activeInSpace(){let e=zn._zpp;this.alloc_cbSet(),e.space.ZPP_Component.zpp_pool==null?this.component=new e.space.ZPP_Component:(this.component=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=this.component.next,this.component.next=null),this.component.isBody=!1,this.component.constraint=this}inactiveOrOutSpace(){let e=zn._zpp;this.dealloc_cbSet();let t=this.component;t.body=null,t.constraint=null,t.next=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t,this.component=null}wake(){this.space!=null&&this.space.wake_constraint(this)}copyto(e){let t=zn._nape,n=this.outer;n.zpp_inner.wrap_cbTypes==null&&n.zpp_inner.setupcbTypes();let s=n.zpp_inner.wrap_cbTypes;s.zpp_inner.valmod();let i=t.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let y=i.zpp_inner;y.zpp_inner.valmod(),y.zpp_inner.zip_length&&(y.zpp_inner.zip_length=!1,y.zpp_inner.user_length=y.zpp_inner.inner.length);let d=y.zpp_inner.user_length;i.zpp_critical=!0;let _;if(i.zpp_i<d?_=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,_=!1),!_)break;i.zpp_critical=!1;let f=i.zpp_inner.at(i.zpp_i++);e.zpp_inner.wrap_cbTypes==null&&e.zpp_inner.setupcbTypes();let z=e.zpp_inner.wrap_cbTypes;z.zpp_inner.reverse_flag?z.push(f):z.unshift(f)}e.zpp_inner.removeOnBreak=n.zpp_inner.removeOnBreak;let l=n.zpp_inner.breakUnderError;e.zpp_inner.breakUnderError!=l&&(e.zpp_inner.breakUnderError=l,e.zpp_inner.wake());let r=n.zpp_inner.breakUnderForce;e.zpp_inner.breakUnderForce!=r&&(e.zpp_inner.breakUnderForce=r,e.zpp_inner.wake());let a=n.zpp_inner.maxError;if(a!==a)throw new Error("Error: Constraint::maxError cannot be NaN");if(a<0)throw new Error("Error: Constraint::maxError must be >=0");e.zpp_inner.maxError!=a&&(e.zpp_inner.maxError=a,e.zpp_inner.wake());let o=n.zpp_inner.maxForce;if(o!==o)throw new Error("Error: Constraint::maxForce cannot be NaN");if(o<0)throw new Error("Error: Constraint::maxForce must be >=0");e.zpp_inner.maxForce!=o&&(e.zpp_inner.maxForce=o,e.zpp_inner.wake());let p=n.zpp_inner.damping;if(p!==p)throw new Error("Error: Constraint::Damping cannot be Nan");if(p<0)throw new Error("Error: Constraint::Damping must be >=0");e.zpp_inner.damping!=p&&(e.zpp_inner.damping=p,e.zpp_inner.stiff||e.zpp_inner.wake());let c=n.zpp_inner.frequency;if(c!==c)throw new Error("Error: Constraint::Frequency cannot be NaN");if(c<=0)throw new Error("Error: Constraint::Frequency must be >0");e.zpp_inner.frequency!=c&&(e.zpp_inner.frequency=c,e.zpp_inner.stiff||e.zpp_inner.wake());let h=n.zpp_inner.stiff;e.zpp_inner.stiff!=h&&(e.zpp_inner.stiff=h,e.zpp_inner.wake());let u=n.zpp_inner.ignore;e.zpp_inner.ignore!=u&&(e.zpp_inner.ignore=u,e.zpp_inner.wake());let x=n.zpp_inner.active;e.zpp_inner.active!=x&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.woken=!1),e.zpp_inner.clearcache(),x?(e.zpp_inner.active=x,e.zpp_inner.activate(),e.zpp_inner.space!=null&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.sleeping=!0),e.zpp_inner.space.wake_constraint(e.zpp_inner,!0))):(e.zpp_inner.space!=null&&(e.zpp_inner.wake(),e.zpp_inner.space.live_constraints.remove(e.zpp_inner)),e.zpp_inner.active=x,e.zpp_inner.deactivate()))}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let s=t.parent;t.parent=n,n=t,t=s}for(;n!=null;){let s=n.parent;n.parent=t,n=s}return t}static _unionComponents(e,t){let n=zn._findRoot(e),s=zn._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}};zn._nape=null,zn._zpp=null;var Me=zn;var Fn=class g{constructor(){this.id=0;this.bc=null;this.cb=null}static dict(e,t){let n=new g;return n.id=e,n.bc=t,n}static todo(e,t){let n=new g;return n.id=e,n.cb=t,n}};var Es=class Es extends Me{constructor(){super();this.outer_zn=null;this.ratio=0;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.scale=0;this.b1=null;this.b2=null;this.kMass=0;this.jAcc=0;this.jMax=0;this.gamma=0;this.bias=0;this.stepped=!1;this.ratio=1,this.jAcc=0,this.slack=!1,this.jMax=1/0,this.stepped=!1}is_slack(){let t=this.ratio*this.b2.rot-this.b1.rot;return this.equal?(this.scale=1,!1):t<this.jointMin?(this.scale=-1,!1):t>this.jointMax?(this.scale=1,!1):(this.scale=0,!0)}bodyImpulse(t){let n=me();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.scale*this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.scale*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let s=Es._createFn(null,null,this.jointMin,this.jointMax,this.ratio);if(this.copyto(s),t!=null&&this.b1!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b1.id){i=r.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(Fn.todo(this.b1.id,r=>{s.zpp_inner.b1=r.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b2.id){i=r.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(Fn.todo(this.b2.id,r=>{s.zpp_inner.b2=r.zpp_inner}))}return s}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: AngleJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: AngleJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let s=this.b1.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let s=this.b2.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1,this.slack=!1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax;let s=this.ratio*this.b2.rot-this.b1.rot;this.equal?(s-=this.jointMax,this.slack=!1,this.scale=1):s<this.jointMin?(s=this.jointMin-s,this.scale=-1,this.slack=!1):s>this.jointMax?(s-=this.jointMax,this.scale=1,this.slack=!1):(this.scale=0,s=0,this.slack=!0);let i=s;if(!this.slack){if(this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&i*i>this.maxError*this.maxError)return!0;let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let r=1/(1+this.gamma),a=t*l*l*this.gamma;this.gamma*=r,this.kMass*=r,this.bias=-i*a,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){this.slack||(this.b1.angvel-=this.scale*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*this.jAcc)}applyImpulseVel(){if(this.slack)return!1;let t=this.scale*(this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel),n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;return this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&(this.jAcc>this.jMax||this.jAcc<-this.jMax)?!0:(this.stiff||(this.jAcc>this.jMax?this.jAcc=this.jMax:this.jAcc<-this.jMax&&(this.jAcc=-this.jMax)),n=this.jAcc-s,this.b1.angvel-=this.scale*this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*n,!1)}applyImpulsePos(){let t=this.ratio*this.b2.rot-this.b1.rot,n;this.equal?(t-=this.jointMax,n=!1,this.scale=1):t<this.jointMin?(t=this.jointMin-t,this.scale=-1,n=!1):t>this.jointMax?(t-=this.jointMax,this.scale=1,n=!1):(this.scale=0,t=0,n=!0);let s=t;if(!n){if(this.breakUnderError&&s*s>this.maxError*this.maxError)return!0;let l=-(s*.5)*this.kMass;if(this.equal||l<0){let r=this.b1,a=-this.scale*l*this.b1.iinertia;if(r.rot+=a,a*a>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let c=a*a,h=1-.5*c,u=1-c*c/8,x=(h*r.axisx+a*r.axisy)*u;r.axisy=(h*r.axisy-a*r.axisx)*u,r.axisx=x}let o=this.b2,p=this.ratio*this.scale*l*this.b2.iinertia;if(o.rot+=p,p*p>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let c=p*p,h=1-.5*c,u=1-c*c/8,x=(h*o.axisx+p*o.axisy)*u;o.axisy=(h*o.axisy-p*o.axisx)*u,o.axisx=x}}}return!1}draw(t){}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let s=n*n,i=1-.5*s,l=1-s*s/8,r=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=r}}static _copyBody(t,n,s,i,l){if(t!=null&&s!=null){let r=null;for(let a=0;a<t.length;a++){let o=t[a];if(o.id==s.id){r=o.bc;break}}r!=null?i.zpp_inner_zn[l]=r.zpp_inner:n.push(Fn.todo(s.id,function(a){i.zpp_inner_zn[l]=a.zpp_inner}))}}};Es._wrapFn=null,Es._createFn=null;var Je=Es;var Et=class Et{constructor(){this.x=0;this.y=0;this.next=null;this.length=0;this.modified=!1;this.pushmod=!1;this._inuse=!1;this.weak=!1;this.outer=null;this._immutable=!1;this._isimmutable=null;this._validate=null;this._invalidate=null}static get(e,t,n){n==null&&(n=!1);let s;return Et.zpp_pool==null?s=new Et:(s=Et.zpp_pool,Et.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=n,s.x=e,s.y=t,s}validate(){this._validate!=null&&this._validate()}invalidate(){this._invalidate!=null&&this._invalidate(this)}immutable(){if(this._immutable)throw new Error("Error: Vec2 is immutable");this._isimmutable!=null&&this._isimmutable()}wrapper(){if(this.outer==null)if(Et._wrapFn)this.outer=Et._wrapFn(this);else{this.outer=new Et._nape.geom.Vec2;let e=this.outer.zpp_inner;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e._isimmutable=null,e._validate=null,e._invalidate=null,e.next=Et.zpp_pool,Et.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this._isimmutable=null,this._validate=null,this._invalidate=null}alloc(){this.weak=!1}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}inlined_add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;)this.add(t),t=t.next}insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}inlined_insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let s;t==null?(s=this.next,this.next=s.next,this.next==null&&(this.pushmod=!0)):(s=t.next,t.next=s.next,s.next==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e)return this.erase(t),!0;t=n,n=n.next}return!1}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let s;t==null?(s=this.next,this.next=s.next,this.next==null&&(this.pushmod=!0)):(s=t.next,t.next=s.next,s.next==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let s;return t==null?(s=this.next,this.next=s.next,this.next==null&&(this.pushmod=!0)):(s=t.next,t.next=s.next,s.next==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,!0}t=n,n=n.next}return!1}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=this.next;for(;t!=null;){if(t===e)return!0;t=t.next}return!1}inlined_has(e){let t=this.next;for(;t!=null;){if(t===e)return!0;t=t.next}return!1}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}copy(){let e=this.x,t=this.y,n;return Et.zpp_pool==null?n=new Et:(n=Et.zpp_pool,Et.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,n}toString(){return"{ x: "+this.x+" y: "+this.y+" }"}};Et.zpp_pool=null,Et._nape=null,Et._zpp=null,Et._wrapFn=null;var le=Et;var Si=class Si extends Me{constructor(){super();this.outer_zn=null;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.nx=0;this.ny=0;this.cx1=0;this.cx2=0;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a1=null;this.wrap_a2=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=n*n+s*s;return i<Me._nape.Config.epsilon?t=!0:(i=Math.sqrt(i),this.equal||i<this.jointMin||i>this.jointMax?t=!1:t=!0),t}bodyImpulse(t){let n=Me._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAcc*this.nx,-this.jAcc*this.ny,-this.cx1*this.jAcc):n.geom.Vec3.get(this.jAcc*this.nx,this.jAcc*this.ny,this.cx2*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){this.wrap_a1=Si._setupAnchorVec2(this.a1localx,this.a1localy,this.validate_a1.bind(this),this.invalidate_a1.bind(this))}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){this.wrap_a2=Si._setupAnchorVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=Si._createFn(null,null,i,l.zpp_inner_zn.wrap_a2,this.jointMin,this.jointMax);return this.copyto(r),Je._copyBody(t,n,this.b1,r,"b1"),Je._copyBody(t,n,this.b2,r,"b2"),r}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: DistanceJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.nx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.ny=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely);let s=this.nx*this.nx+this.ny*this.ny;if(s<Me._nape.Config.epsilon)this.nx=0,this.ny=0,s=0,this.slack=!0;else{s=Math.sqrt(s);let l=1/s;this.nx*=l,this.ny*=l,this.equal?(s-=this.jointMax,this.slack=!1):s<this.jointMin?(s=this.jointMin-s,this.nx=-this.nx,this.ny=-this.ny,this.slack=!1):s>this.jointMax?(s-=this.jointMax,this.slack=!1):(this.nx=0,this.ny=0,s=0,this.slack=!0)}let i=s;if(!this.slack){if(this.cx1=this.ny*this.a1relx-this.nx*this.a1rely,this.cx2=this.ny*this.a2relx-this.nx*this.a2rely,this.kMass=this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&i*i>this.maxError*this.maxError)return!0;let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let r=1/(1+this.gamma),a=t*l*l*this.gamma;this.gamma*=r,this.kMass*=r,this.bias=-i*a,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.nx*t,this.b1.vely-=this.ny*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.nx*n,this.b2.vely+=this.ny*n,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.nx*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.ny*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-s;let i=this.b1.imass*n;this.b1.velx-=this.nx*i,this.b1.vely-=this.ny*i;let l=this.b2.imass*n;return this.b2.velx+=this.nx*l,this.b2.vely+=this.ny*l,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,!1}applyImpulsePos(){let t,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r,a=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s),p=a*a+o*o;if(p<Me._nape.Config.epsilon)a=0,o=0,p=0,r=!0;else{p=Math.sqrt(p);let h=1/p;a*=h,o*=h,this.equal?(p-=this.jointMax,r=!1):p<this.jointMin?(p=this.jointMin-p,a=-a,o=-o,r=!1):p>this.jointMax?(p-=this.jointMax,r=!1):(a=0,o=0,p=0,r=!0)}let c=p;if(!r){if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;if(c*c<Me._nape.Config.constraintLinearSlop*Me._nape.Config.constraintLinearSlop)return!1;if(c*=.5,c*c>6){let y=this.b1.smass+this.b2.smass;if(y>Me._nape.Config.epsilon){let d=.75/y;if(t=-c*d,this.equal||t<0){let _=t*this.b1.imass;this.b1.posx-=a*_,this.b1.posy-=o*_;let f=t*this.b2.imass;this.b2.posx+=a*f,this.b2.posy+=o*f,a=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s);let z=a*a+o*o;if(z<Me._nape.Config.epsilon)a=0,o=0,z=0;else{z=Math.sqrt(z);let P=1/z;a*=P,o*=P,this.equal?z-=this.jointMax:z<this.jointMin?(z=this.jointMin-z,a=-a,o=-o):z>this.jointMax?z-=this.jointMax:(a=0,o=0,z=0)}c=z,c*=.5}}}let h=o*n-a*s,u=o*i-a*l,x=this.b1.smass+this.b2.smass+h*h*this.b1.sinertia+u*u*this.b2.sinertia;if(x!=0&&(x=1/x),t=-c*x,this.equal||t<0){let y=this.b1.imass*t;this.b1.posx-=a*y,this.b1.posy-=o*y;let d=this.b2.imass*t;this.b2.posx+=a*d,this.b2.posy+=o*d,Je._rotateBody(this.b1,-h*this.b1.iinertia*t),Je._rotateBody(this.b2,u*this.b2.iinertia*t)}}return!1}draw(t){}static _setupAnchorVec2(t,n,s,i){let l=Me._nape,r=t,a=n;if(a==null&&(a=0),r==null&&(r=0),r!=r||a!=a)throw new Error("Error: Vec2 components cannot be NaN");let o;if(_e.poolVec2==null?o=new l.geom.Vec2:(o=_e.poolVec2,_e.poolVec2=o.zpp_pool,o.zpp_pool=null,o.zpp_disp=!1,o==_e.nextVec2&&(_e.nextVec2=null)),o.zpp_inner==null){let p;le.zpp_pool==null?p=new le:(p=le.zpp_pool,le.zpp_pool=p.next,p.next=null),p.weak=!1,p._immutable=!1,p.x=r,p.y=a,o.zpp_inner=p,o.zpp_inner.outer=o}else{if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=o.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),r!=r||a!=a)throw new Error("Error: Vec2 components cannot be NaN");let c;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=o.zpp_inner;if(h._validate!=null&&h._validate(),o.zpp_inner.x==r){if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=o.zpp_inner;u._validate!=null&&u._validate(),c=o.zpp_inner.y==a}else c=!1;if(!c){o.zpp_inner.x=r,o.zpp_inner.y=a;let u=o.zpp_inner;u._invalidate!=null&&u._invalidate(u)}}return o.zpp_inner.weak=!1,o.zpp_inner._inuse=!0,o.zpp_inner._validate=s,o.zpp_inner._invalidate=i,o}};Si._wrapFn=null,Si._createFn=null;var ci=Si;var Ns=class Ns extends Me{constructor(){super();this.outer_zn=null;this.scale=0;this.jointMin=0;this.jointMax=0;this.equal=!1;this.dot1=0;this.dot2=0;this.cx1=0;this.cx2=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.zip_n=null;this.nlocalx=0;this.nlocaly=0;this.nrelx=0;this.nrely=0;this.wrap_n=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.jAccx=0;this.jAccy=0;this.jMax=null;this.gamma=null;this.biasx=0;this.biasy=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.nlocalx=0,this.nlocaly=0,this.nrelx=0,this.nrely=0,this.jAccx=0,this.jAccy=0,this.jMax=1/0,this.jointMin=-1/0,this.jointMax=1/0,this.stepped=!1}_setupVec2(t,n,s,i){let l=Me._nape,r=Me._zpp;if(n==null&&(n=0),t==null&&(t=0),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");let a;if(r.util.ZPP_PubPool.poolVec2==null?a=new l.geom.Vec2:(a=r.util.ZPP_PubPool.poolVec2,r.util.ZPP_PubPool.poolVec2=a.zpp_pool,a.zpp_pool=null,a.zpp_disp=!1,a==r.util.ZPP_PubPool.nextVec2&&(r.util.ZPP_PubPool.nextVec2=null)),a.zpp_inner==null){let o;r.geom.ZPP_Vec2.zpp_pool==null?o=new r.geom.ZPP_Vec2:(o=r.geom.ZPP_Vec2.zpp_pool,r.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=t,o.y=n,a.zpp_inner=o,a.zpp_inner.outer=a}else{if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=a.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=a.zpp_inner;p._validate!=null&&p._validate();let c;if(a.zpp_inner.x==t){if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=a.zpp_inner;h._validate!=null&&h._validate(),c=a.zpp_inner.y==n}else c=!1;if(!c){a.zpp_inner.x=t,a.zpp_inner.y=n;let h=a.zpp_inner;h._invalidate!=null&&h._invalidate(h)}}return a.zpp_inner.weak=!1,a.zpp_inner._inuse=!0,a.zpp_inner._validate=s,a.zpp_inner._invalidate=i,a}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){this.wrap_a1=this._setupVec2(this.a1localx,this.a1localy,this.validate_a1.bind(this),this.invalidate_a1.bind(this))}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){this.wrap_a2=this._setupVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}validate_n(){this.wrap_n.zpp_inner.x=this.nlocalx,this.wrap_n.zpp_inner.y=this.nlocaly}invalidate_n(t){this.immutable_midstep("Constraint::n"),this.nlocalx=t.x,this.nlocaly=t.y,this.zip_n=!0,this.wake()}setup_n(){this.wrap_n=this._setupVec2(this.nlocalx,this.nlocaly,this.validate_n.bind(this),this.invalidate_n.bind(this))}validate_norm(){if(this.zip_n){this.zip_n=!1;let t=this.nlocalx*this.nlocalx+this.nlocaly*this.nlocaly,s=1/Math.sqrt(t);this.nlocalx*=s,this.nlocaly*=s}}bodyImpulse(t){let n=Me._nape;if(this.stepped){let s=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,i=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy;return t==this.b1?n.geom.Vec3.get(-s,-i,this.scale*this.cx1*i-this.dot1*s):n.geom.Vec3.get(s,i,this.scale*this.cx1*i-this.dot1*s)}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=l.zpp_inner_zn.wrap_a2,a=this.outer_zn;a.zpp_inner_zn.wrap_n==null&&a.zpp_inner_zn.setup_n();let o=Ns._createFn(null,null,i,r,a.zpp_inner_zn.wrap_n,this.jointMin,this.jointMax);return this.copyto(o),Je._copyBody(t,n,this.b1,o,"b1"),Je._copyBody(t,n,this.b2,o,"b2"),o}validate(){let t=Me._nape;if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.nlocalx*this.nlocalx+this.nlocaly*this.nlocaly<t.Config.epsilon)throw new Error("Error: DistanceJoint direction must be non-degenerate");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.equal=this.jointMin==this.jointMax,this.stepped=!0,this.validate_norm(),this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.nrelx=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,this.nrely=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b2.posx+this.a2relx-this.b1.posx-this.a1relx,i=this.b2.posy+this.a2rely-this.b1.posy-this.a1rely,l=i*this.nrelx-s*this.nrely,r=this.nrelx*s+this.nrely*i;this.equal?(r-=this.jointMin,this.scale=1):r>this.jointMax?(r-=this.jointMax,this.scale=1):r<this.jointMin?(r=this.jointMin-r,this.scale=-1):(r=0,this.scale=0);let a=s+this.a1relx,o=i+this.a1rely;this.dot1=this.nrelx*a+this.nrely*o,this.cx1=o*this.nrelx-a*this.nrely,this.dot2=this.nrelx*this.a2relx+this.nrely*this.a2rely,this.cx2=this.a2rely*this.nrelx-this.a2relx*this.nrely,this.kMassa=this.b1.smass+this.b2.smass+this.dot1*this.dot1*this.b1.sinertia+this.dot2*this.dot2*this.b2.sinertia,this.kMassb=-this.scale*(this.dot1*this.cx1*this.b1.sinertia+this.dot2*this.cx2*this.b2.sinertia),this.kMassc=this.scale*this.scale*(this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia);let p=this.kMassa*this.kMassc-this.kMassb*this.kMassb,c;if(p!==p)this.kMassa=this.kMassb=this.kMassc=0,c=3;else if(p==0){let u=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,u|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,u|=2),this.kMassb=0,c=u}else{let u=1/p,x=this.kMassc*u;this.kMassc=this.kMassa*u,this.kMassa=x,this.kMassb*=-u,c=0}if((c&1)!=0&&(this.jAccx=0),(c&2)!=0&&(this.jAccy=0),this.stiff)this.gamma=0,this.biasx=0,this.biasy=0;else{if(this.breakUnderError&&l*l+r*r>this.maxError*this.maxError)return!0;let u=2*Math.PI*this.frequency;this.gamma=1/(t*u*(2*this.damping+u*t));let x=1/(1+this.gamma),y=t*u*u*this.gamma;this.gamma*=x;let d=x;this.kMassa*=d,this.kMassb*=d,this.kMassc*=d,this.biasx=l,this.biasy=r;let _=-y;this.biasx*=_,this.biasy*=_;let f=this.maxError,z=this.biasx*this.biasx+this.biasy*this.biasy;if(z>f*f){let P=f*(1/Math.sqrt(z));this.biasx*=P,this.biasy*=P}}let h=n;return this.jAccx*=h,this.jAccy*=h,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,n=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy,s=this.b1.imass;this.b1.velx-=t*s,this.b1.vely-=n*s;let i=this.b2.imass;this.b2.velx+=t*i,this.b2.vely+=n*i,this.b1.angvel+=(this.scale*this.cx1*this.jAccy-this.dot1*this.jAccx)*this.b1.iinertia,this.b2.angvel+=(this.dot2*this.jAccx-this.scale*this.cx2*this.jAccy)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx-this.b1.velx,n=this.b2.vely-this.b1.vely;t+=this.b2.kinvelx-this.b1.kinvelx,n+=this.b2.kinvely-this.b1.kinvely;let s=n*this.nrelx-t*this.nrely+(this.b2.angvel+this.b2.kinangvel)*this.dot2-(this.b1.angvel+this.b1.kinangvel)*this.dot1,i=this.scale*(this.nrelx*t+this.nrely*n-(this.b2.angvel+this.b2.kinangvel)*this.cx2+(this.b1.angvel+this.b1.kinangvel)*this.cx1),l=this.biasx-s,r=this.biasy-i,a=this.kMassa*l+this.kMassb*r;r=this.kMassb*l+this.kMassc*r,l=a;let o=this.gamma;l-=this.jAccx*o,r-=this.jAccy*o;let p=this.jAccx,c=this.jAccy;if(this.jAccx+=l,this.jAccy+=r,this.jAccy>0&&(this.jAccy=0),this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let f=this.jMax,z=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(z>f*f){let P=f*(1/Math.sqrt(z));this.jAccx*=P,this.jAccy*=P}}let h=this.jAccx-p,u=this.jAccy-c,x=this.scale*this.nrelx*u-this.nrely*h,y=this.nrelx*h+this.scale*this.nrely*u,d=this.b1.imass;this.b1.velx-=x*d,this.b1.vely-=y*d;let _=this.b2.imass;return this.b2.velx+=x*_,this.b2.vely+=y*_,this.b1.angvel+=(this.scale*this.cx1*u-this.dot1*h)*this.b1.iinertia,this.b2.angvel+=(this.dot2*h-this.scale*this.cx2*u)*this.b2.iinertia,!1}applyImpulsePos(){let t=Me._nape,n=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,s=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,i=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,r=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,a=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o=this.b2.posx+r-this.b1.posx-i,p=this.b2.posy+a-this.b1.posy-l,c,h=p*n-o*s,u=n*o+s*p;if(this.equal?(u-=this.jointMin,c=1):u>this.jointMax?(u-=this.jointMax,c=1):u<this.jointMin?(u=this.jointMin-u,c=-1):(u=0,c=0),this.breakUnderError&&h*h+u*u>this.maxError*this.maxError)return!0;if(h*h+u*u<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let x,y,d=.5;if(h*=d,u*=d,h*h+u*u>6){let Z=this.b1.smass+this.b2.smass;if(Z>t.Config.epsilon){let S=.8/Z,V=S*(s*h-c*n*u),D=S*(n*h*c-s*h),T=this.b1.imass;this.b1.posx-=V*T,this.b1.posy-=D*T;let G=this.b2.imass;this.b2.posx+=V*G,this.b2.posy+=D*G,o=this.b2.posx+r-this.b1.posx-i,p=this.b2.posy+a-this.b1.posy-l,h=p*n-o*s,u=n*o+s*p,this.equal?(u-=this.jointMin,c=1):u>this.jointMax?(u-=this.jointMax,c=1):u<this.jointMin?(u=this.jointMin-u,c=-1):(u=0,c=0);let q=.5;h*=q,u*=q}}let _=o+i,f=p+l,z=n*_+s*f,P=f*n-_*s,k=n*r+s*a,m=a*n-r*s,b=this.b1.smass+this.b2.smass+z*z*this.b1.sinertia+k*k*this.b2.sinertia,C=-c*(z*P*this.b1.sinertia+k*m*this.b2.sinertia),v=c*c*(this.b1.smass+this.b2.smass+P*P*this.b1.sinertia+m*m*this.b2.sinertia);x=-h,y=-u;let w=b*v-C*C;if(w!==w)y=0,x=y;else if(w==0)b!=0?x/=b:x=0,v!=0?y/=v:y=0;else{let Z=1/w,S=Z*(v*x-C*y);y=Z*(b*y-C*x),x=S}y>0&&(y=0);let O=c*n*y-s*x,E=n*x+c*s*y,M=this.b1.imass;this.b1.posx-=O*M,this.b1.posy-=E*M;let N=this.b2.imass;return this.b2.posx+=O*N,this.b2.posy+=E*N,Je._rotateBody(this.b1,(c*P*y-z*x)*this.b1.iinertia),Je._rotateBody(this.b2,(k*x-c*m*y)*this.b2.iinertia),!1}draw(t){}};Ns._wrapFn=null,Ns._createFn=null;var hi=Ns;var Os=class Os extends Me{constructor(){super();this.outer_zn=null;this.ratio=0;this.rate=0;this.b1=null;this.b2=null;this.kMass=0;this.jAcc=0;this.jMax=0;this.stepped=!1;this.jAcc=0,this.stepped=!1,this.__velocity=!0}bodyImpulse(t){let n=me();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let s=Os._createFn(null,null,this.rate,this.ratio);if(this.copyto(s),t!=null&&this.b1!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b1.id){i=r.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(Fn.todo(this.b1.id,r=>{s.zpp_inner.b1=r.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b2.id){i=r.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(Fn.todo(this.b2.id,r=>{s.zpp_inner.b2=r.zpp_inner}))}return s}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: MotorJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let s=this.b1.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let s=this.b2.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;return this.pre_dt=t,this.stepped=!0,this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass=1/this.kMass,this.jAcc*=n,this.jMax=this.maxForce*t,!1}warmStart(){this.b1.angvel-=this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.b2.iinertia*this.jAcc}applyImpulseVel(){let t=this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel-this.rate,n=-this.kMass*t,s=this.jAcc;if(this.jAcc+=n,this.breakUnderForce){if(this.jAcc>this.jMax||this.jAcc<-this.jMax)return!0}else this.jAcc<-this.jMax?this.jAcc=-this.jMax:this.jAcc>this.jMax&&(this.jAcc=this.jMax);return n=this.jAcc-s,this.b1.angvel-=this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.b2.iinertia*n,!1}applyImpulsePos(){return!1}};Os._wrapFn=null,Os._createFn=null;var ui=Os;var Ss=class Ss extends Me{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.jAccx=0;this.jAccy=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.stepped=!1;this.stepped=!1,this.jAccx=0,this.jAccy=0,this.jMax=1/0,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0}bodyImpulse(t){let n=Me._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAccx,-this.jAccy,-(this.jAccy*this.a1relx-this.jAccx*this.a1rely)):n.geom.Vec3.get(this.jAccx,this.jAccy,this.jAccy*this.a2relx-this.jAccx*this.a2rely):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){let t=Me._nape,n=Me._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),a=l.zpp_inner.y==i}else a=!1;if(!a){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a1=l,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=Me._nape,n=Me._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),a=l.zpp_inner.y==i}else a=!1;if(!a){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=Ss._createFn(null,null,i,l.zpp_inner_zn.wrap_a2);return this.copyto(r),Je._copyBody(t,n,this.b1,r,"b1"),Je._copyBody(t,n,this.b2,r,"b2"),r}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: PivotJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: PivotJoint cannot be simulated with body1 == body2 (body1=body2="+this.b1.outer.toString()+")");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b1.smass+this.b2.smass;if(this.kMassa=s,this.kMassb=0,this.kMassc=s,this.b1.sinertia!=0){let a=this.a1relx*this.b1.sinertia,o=this.a1rely*this.b1.sinertia;this.kMassa+=o*this.a1rely,this.kMassb+=-o*this.a1relx,this.kMassc+=a*this.a1relx}if(this.b2.sinertia!=0){let a=this.a2relx*this.b2.sinertia,o=this.a2rely*this.b2.sinertia;this.kMassa+=o*this.a2rely,this.kMassb+=-o*this.a2relx,this.kMassc+=a*this.a2relx}let i=this.kMassa*this.kMassc-this.kMassb*this.kMassb,l;if(i!=i)this.kMassa=this.kMassb=this.kMassc=0,l=3;else if(i==0){let a=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,a|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,a|=2),this.kMassb=0,l=a}else{let a=1/i,o=this.kMassc*a;this.kMassc=this.kMassa*a,this.kMassa=o,this.kMassb*=-a,l=0}if((l&1)!=0&&(this.jAccx=0),(l&2)!=0&&(this.jAccy=0),this.stiff)this.biasx=0,this.biasy=0,this.gamma=0;else{let a=2*Math.PI*this.frequency;this.gamma=1/(t*a*(2*this.damping+a*t));let o=1/(1+this.gamma),p=t*a*a*this.gamma;this.gamma*=o;let c=o;if(this.kMassa*=c,this.kMassb*=c,this.kMassc*=c,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy>this.maxError*this.maxError)return!0;let h=-p;this.biasx*=h,this.biasy*=h;let u=this.maxError,x=this.biasx*this.biasx+this.biasy*this.biasy;if(x>u*u){let y=u*(1/Math.sqrt(x));this.biasx*=y,this.biasy*=y}}let r=n;return this.jAccx*=r,this.jAccy*=r,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),s=this.biasx-t,i=this.biasy-n,l=this.kMassa*s+this.kMassb*i;i=this.kMassb*s+this.kMassc*i,s=l;let r=this.gamma;s-=this.jAccx*r,i-=this.jAccy*r;let a=this.jAccx,o=this.jAccy,p=1;if(this.jAccx+=s*p,this.jAccy+=i*p,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let u=this.jMax,x=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(x>u*u){let y=u*(1/Math.sqrt(x));this.jAccx*=y,this.jAccy*=y}}s=this.jAccx-a,i=this.jAccy-o;let c=this.b1.imass;this.b1.velx-=s*c,this.b1.vely-=i*c;let h=this.b2.imass;return this.b2.velx+=s*h,this.b2.vely+=i*h,this.b1.angvel-=(i*this.a1relx-s*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(i*this.a2relx-s*this.a2rely)*this.b2.iinertia,!1}applyImpulsePos(){let t=Me._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s);if(this.breakUnderError&&r*r+a*a>this.maxError*this.maxError)return!0;if(r*r+a*a<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let o=.5;r*=o,a*=o;let p,c;if(r*r+a*a>6){let b=this.b1.smass+this.b2.smass;if(b>t.Config.epsilon){let C=.75/b;p=-r*C,c=-a*C;let v=20,w=p*p+c*c;if(w>v*v){let N=v*(1/Math.sqrt(w));p*=N,c*=N}let O=this.b1.imass;this.b1.posx-=p*O,this.b1.posy-=c*O;let E=this.b2.imass;this.b2.posx+=p*E,this.b2.posy+=c*E,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s);let M=.5;r*=M,a*=M}}let h=this.b1.smass+this.b2.smass,u=h,x=0,y=h;if(this.b1.sinertia!=0){let b=n*this.b1.sinertia,C=s*this.b1.sinertia;u+=C*s,x+=-C*n,y+=b*n}if(this.b2.sinertia!=0){let b=i*this.b2.sinertia,C=l*this.b2.sinertia;u+=C*l,x+=-C*i,y+=b*i}p=-r,c=-a;let d=6,_=p*p+c*c;if(_>d*d){let b=d*(1/Math.sqrt(_));p*=b,c*=b}let f=u*y-x*x;if(f!=f)c=0,p=0;else if(f==0)u!=0?p/=u:p=0,y!=0?c/=y:c=0;else{let b=1/f,C=b*(y*p-x*c);c=b*(u*c-x*p),p=C}let z=this.b1.imass;this.b1.posx-=p*z,this.b1.posy-=c*z;let P=this.b2.imass;this.b2.posx+=p*P,this.b2.posy+=c*P;let k=-(c*n-p*s)*this.b1.iinertia;Je._rotateBody(this.b1,k);let m=(c*i-p*l)*this.b2.iinertia;return Je._rotateBody(this.b2,m),!1}draw(t){}};Ss._wrapFn=null,Ss._createFn=null;var xi=Ss;var As=class As extends Me{constructor(){super();this.outer_zn=null;this.ratio=1;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.n12x=0;this.n12y=0;this.n34x=0;this.n34y=0;this.cx1=0;this.cx2=0;this.cx3=0;this.cx4=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.b3=null;this.a3localx=0;this.a3localy=0;this.a3relx=0;this.a3rely=0;this.wrap_a3=null;this.b4=null;this.a4localx=0;this.a4localy=0;this.a4relx=0;this.a4rely=0;this.wrap_a4=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.a3localx=0,this.a3localy=0,this.a3relx=0,this.a3rely=0,this.a4localx=0,this.a4localy=0,this.a4relx=0,this.a4rely=0,this.n12x=1,this.n12y=0,this.n34x=1,this.n34y=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=this.cx3=this.cx4=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),l=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),r=Math.sqrt(n*n+s*s),a=Math.sqrt(i*i+l*l),o=r+this.ratio*a;return this.equal||o<this.jointMin||o>this.jointMax?t=!1:t=!0,t}bodyImpulse(t){let n=Me._nape;if(this.stepped){let s=n.geom.Vec3.get();return t==this.b1&&(s.zpp_inner.x=s.zpp_inner.x-this.jAcc*this.n12x,s.zpp_inner.y=s.zpp_inner.y-this.jAcc*this.n12y,s.zpp_inner.z=s.zpp_inner.z-this.cx1*this.jAcc),t==this.b2&&(s.zpp_inner.x=s.zpp_inner.x+this.jAcc*this.n12x,s.zpp_inner.y=s.zpp_inner.y+this.jAcc*this.n12y,s.zpp_inner.z=s.zpp_inner.z+this.cx2*this.jAcc),t==this.b3&&(s.zpp_inner.x=s.zpp_inner.x-this.jAcc*this.n34x,s.zpp_inner.y=s.zpp_inner.y-this.jAcc*this.n34y,s.zpp_inner.z=s.zpp_inner.z-this.cx3*this.jAcc),t==this.b4&&(s.zpp_inner.x=s.zpp_inner.x+this.jAcc*this.n34x,s.zpp_inner.y=s.zpp_inner.y+this.jAcc*this.n34y,s.zpp_inner.z=s.zpp_inner.z+this.cx4*this.jAcc),s}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this),this.b3!=this.b1&&this.b3!=this.b2&&this.b3!=null&&this.b3.constraints.add(this),this.b4!=this.b1&&this.b4!=this.b2&&this.b4!=this.b3&&this.b4!=null&&this.b4.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this),this.b3!=this.b1&&this.b3!=this.b2&&this.b3!=null&&this.b3.constraints.remove(this),this.b4!=this.b1&&this.b4!=this.b2&&this.b4!=this.b3&&this.b4!=null&&this.b4.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){let t=Me._nape,n=Me._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),a=l.zpp_inner.y==i}else a=!1;if(!a){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a1=l,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=Me._nape,n=Me._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),a=l.zpp_inner.y==i}else a=!1;if(!a){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}validate_a3(){this.wrap_a3.zpp_inner.x=this.a3localx,this.wrap_a3.zpp_inner.y=this.a3localy}invalidate_a3(t){this.immutable_midstep("Constraint::a3"),this.a3localx=t.x,this.a3localy=t.y,this.wake()}setup_a3(){let t=Me._nape,n=Me._zpp,s=this.a3localx,i=this.a3localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),a=l.zpp_inner.y==i}else a=!1;if(!a){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a3=l,this.wrap_a3.zpp_inner._inuse=!0,this.wrap_a3.zpp_inner._validate=this.validate_a3.bind(this),this.wrap_a3.zpp_inner._invalidate=this.invalidate_a3.bind(this)}validate_a4(){this.wrap_a4.zpp_inner.x=this.a4localx,this.wrap_a4.zpp_inner.y=this.a4localy}invalidate_a4(t){this.immutable_midstep("Constraint::a4"),this.a4localx=t.x,this.a4localy=t.y,this.wake()}setup_a4(){let t=Me._nape,n=Me._zpp,s=this.a4localx,i=this.a4localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),a=l.zpp_inner.y==i}else a=!1;if(!a){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a4=l,this.wrap_a4.zpp_inner._inuse=!0,this.wrap_a4.zpp_inner._validate=this.validate_a4.bind(this),this.wrap_a4.zpp_inner._invalidate=this.invalidate_a4.bind(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=l.zpp_inner_zn.wrap_a2,a=this.outer_zn;a.zpp_inner_zn.wrap_a3==null&&a.zpp_inner_zn.setup_a3();let o=a.zpp_inner_zn.wrap_a3,p=this.outer_zn;p.zpp_inner_zn.wrap_a4==null&&p.zpp_inner_zn.setup_a4();let c=As._createFn(null,null,null,null,i,r,o,p.zpp_inner_zn.wrap_a4,this.jointMin,this.jointMax,this.ratio);return this.copyto(c),Je._copyBody(t,n,this.b1,c,"b1"),Je._copyBody(t,n,this.b2,c,"b2"),Je._copyBody(t,n,this.b3,c,"b3"),Je._copyBody(t,n,this.b4,c,"b4"),c}validate(){if(this.b1==null||this.b2==null||this.b3==null||this.b4==null)throw new Error("Error: PulleyJoint cannot be simulated with null bodies");if(this.b1==this.b2||this.b3==this.b4)throw new Error("Error: PulleyJoint cannot have body1==body2 or body3==body4");if(this.b1.space!=this.space||this.b2.space!=this.space||this.b3.space!=this.space||this.b4.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: PulleyJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: PulleyJoint cannot have both bodies in a linked pair non-dynamic");if(this.b3.type!=2&&this.b4.type!=2)throw new Error("Error: PulleyJoint cannot have both bodies in a linked pair non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake(),this.b3!=null&&this.b3.type==2&&this.b3.wake(),this.b4!=null&&this.b4.type==2&&this.b4.wake()}forest(){this.b1.type==2&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component),this.b3.type==2&&Me._unionComponents(this.b3.component,this.component),this.b4.type==2&&Me._unionComponents(this.b4.component,this.component)}pair_exists(t,n){return this.b1.id==t&&(this.b2.id==n||this.b3.id==n||this.b4.id==n)||this.b2.id==t&&(this.b3.id==n||this.b4.id==n||this.b1.id==n)||this.b3.id==t&&(this.b4.id==n||this.b1.id==n||this.b2.id==n)?!0:this.b4.id==t?this.b1.id==n||this.b2.id==n?!0:this.b3.id==n:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let s=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),i=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),l=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),r=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),a=Math.sqrt(s*s+i*i),o=Math.sqrt(l*l+r*r);if(a!=0){let h=1/a;this.n12x=s*h,this.n12y=i*h}if(o!=0){let h=1/o;this.n34x=l*h,this.n34y=r*h;let u=this.ratio;this.n34x*=u,this.n34y*=u}else{let h=this.ratio/Math.sqrt(this.n34x*this.n34x+this.n34y*this.n34y);this.n34x*=h,this.n34y*=h}let p=a+this.ratio*o;this.equal?(p-=this.jointMax,this.slack=!1):p<this.jointMin?(p=this.jointMin-p,this.n12x=-this.n12x,this.n12y=-this.n12y,this.n34x=-this.n34x,this.n34y=-this.n34y,this.slack=!1):p>this.jointMax?(p-=this.jointMax,this.slack=!1):(this.n12x=0,this.n12y=0,this.n34x=0,this.n34y=0,p=0,this.slack=!0);let c=p;if(!this.slack){this.cx1=this.n12y*this.a1relx-this.n12x*this.a1rely,this.cx2=this.n12y*this.a2relx-this.n12x*this.a2rely,this.cx3=this.n34y*this.a3relx-this.n34x*this.a3rely,this.cx4=this.n34y*this.a4relx-this.n34x*this.a4rely;let h=this.ratio*this.ratio,u=this.b1.smass+this.b2.smass+h*(this.b3.smass+this.b4.smass)+this.b1.sinertia*this.cx1*this.cx1+this.b2.sinertia*this.cx2*this.cx2+this.b3.sinertia*this.cx3*this.cx3+this.b4.sinertia*this.cx4*this.cx4;if(this.b1==this.b4&&(u-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx4*this.b1.sinertia)),this.b1==this.b3&&(u+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx3*this.b1.sinertia)),this.b2==this.b3&&(u-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx3*this.b2.sinertia)),this.b2==this.b4&&(u+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx4*this.b2.sinertia)),this.kMass=u,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;let x=2*Math.PI*this.frequency;this.gamma=1/(t*x*(2*this.damping+x*t));let y=1/(1+this.gamma),d=t*x*x*this.gamma;this.gamma*=y,this.kMass*=y,this.bias=-c*d,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.n12x*t,this.b1.vely-=this.n12y*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.n12x*n,this.b2.vely+=this.n12y*n;let s=this.b3.imass*this.jAcc;this.b3.velx-=this.n34x*s,this.b3.vely-=this.n34y*s;let i=this.b4.imass*this.jAcc;this.b4.velx+=this.n34x*i,this.b4.vely+=this.n34y*i,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc,this.b3.angvel-=this.cx3*this.b3.iinertia*this.jAcc,this.b4.angvel+=this.cx4*this.b4.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.n12x*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.n12y*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+this.n34x*(this.b4.velx+this.b4.kinvelx-this.b3.velx-this.b3.kinvelx)+this.n34y*(this.b4.vely+this.b4.kinvely-this.b3.vely-this.b3.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1+(this.b4.angvel+this.b4.kinangvel)*this.cx4-(this.b3.angvel+this.b3.kinangvel)*this.cx3,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-s;let i=this.b1.imass*n;this.b1.velx-=this.n12x*i,this.b1.vely-=this.n12y*i;let l=this.b2.imass*n;this.b2.velx+=this.n12x*l,this.b2.vely+=this.n12y*l;let r=this.b3.imass*n;this.b3.velx-=this.n34x*r,this.b3.vely-=this.n34y*r;let a=this.b4.imass*n;return this.b4.velx+=this.n34x*a,this.b4.vely+=this.n34y*a,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,this.b3.angvel-=this.cx3*this.b3.iinertia*n,this.b4.angvel+=this.cx4*this.b4.iinertia*n,!1}applyImpulsePos(){let t=Me._nape,n,s=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,i=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,l=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,r=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,a=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,o=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,p=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,c=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy,h,u=this.n12x,x=this.n12y,y=this.n34x,d=this.n34y,_=this.b2.posx+l-(this.b1.posx+s),f=this.b2.posy+r-(this.b1.posy+i),z=this.b4.posx+p-(this.b3.posx+a),P=this.b4.posy+c-(this.b3.posy+o),k=Math.sqrt(_*_+f*f),m=Math.sqrt(z*z+P*P);if(k!=0){let v=1/k;u=_*v,x=f*v}if(m!=0){let v=1/m;y=z*v,d=P*v;let w=this.ratio;y*=w,d*=w}else{let v=this.ratio/Math.sqrt(y*y+d*d);y*=v,d*=v}let b=k+this.ratio*m;this.equal?(b-=this.jointMax,h=!1):b<this.jointMin?(b=this.jointMin-b,u=-u,x=-x,y=-y,d=-d,h=!1):b>this.jointMax?(b-=this.jointMax,h=!1):(u=0,x=0,y=0,d=0,b=0,h=!0);let C=b;if(!h){if(this.breakUnderError&&C*C>this.maxError*this.maxError)return!0;if(C*C<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;if(C*=.5,C*C>6){let S=this.b1.smass+this.b2.smass;if(S>t.Config.epsilon){let V=.75/S;if(n=-C*V,this.equal||n<0){let D=n*this.b1.imass;this.b1.posx-=u*D,this.b1.posy-=x*D;let T=n*this.b2.imass;this.b2.posx+=u*T,this.b2.posy+=x*T;let G=n*this.b3.imass;this.b3.posx-=y*G,this.b3.posy-=d*G;let q=n*this.b4.imass;this.b4.posx+=y*q,this.b4.posy+=d*q;let R=this.b2.posx+l-(this.b1.posx+s),j=this.b2.posy+r-(this.b1.posy+i),A=this.b4.posx+p-(this.b3.posx+a),W=this.b4.posy+c-(this.b3.posy+o),Q=Math.sqrt(R*R+j*j),Y=Math.sqrt(A*A+W*W);if(Q!=0){let ee=1/Q;u=R*ee,x=j*ee}if(Y!=0){let ee=1/Y;y=A*ee,d=W*ee;let J=this.ratio;y*=J,d*=J}else{let ee=this.ratio/Math.sqrt(y*y+d*d);y*=ee,d*=ee}let X=Q+this.ratio*Y;this.equal?X-=this.jointMax:X<this.jointMin?(X=this.jointMin-X,u=-u,x=-x,y=-y,d=-d):X>this.jointMax?X-=this.jointMax:(u=0,x=0,y=0,d=0,X=0),C=X,C*=.5}}}let v=x*s-u*i,w=x*l-u*r,O=d*a-y*o,E=d*p-y*c,M=this.ratio*this.ratio,N=this.b1.smass+this.b2.smass+M*(this.b3.smass+this.b4.smass)+this.b1.sinertia*v*v+this.b2.sinertia*w*w+this.b3.sinertia*O*O+this.b4.sinertia*E*E;this.b1==this.b4&&(N-=2*((u*y+x*d)*this.b1.smass+v*E*this.b1.sinertia)),this.b1==this.b3&&(N+=2*((u*y+x*d)*this.b1.smass+v*O*this.b1.sinertia)),this.b2==this.b3&&(N-=2*((u*y+x*d)*this.b2.smass+w*O*this.b2.sinertia)),this.b2==this.b4&&(N+=2*((u*y+x*d)*this.b2.smass+w*E*this.b2.sinertia));let Z=N;if(Z!=0&&(Z=1/Z),n=-C*Z,this.equal||n<0){let S=this.b1.imass*n;this.b1.posx-=u*S,this.b1.posy-=x*S;let V=this.b2.imass*n;this.b2.posx+=u*V,this.b2.posy+=x*V;let D=this.b3.imass*n;this.b3.posx-=y*D,this.b3.posy-=d*D;let T=this.b4.imass*n;this.b4.posx+=y*T,this.b4.posy+=d*T,Je._rotateBody(this.b1,-v*this.b1.iinertia*n),Je._rotateBody(this.b2,w*this.b2.iinertia*n),Je._rotateBody(this.b3,-O*this.b3.iinertia*n),Je._rotateBody(this.b4,E*this.b4.iinertia*n)}}return!1}draw(t){}};As._wrapFn=null,As._createFn=null;var di=As;var ms=class{constructor(e,t){this.cnt=0;this.body=null;this.cnt=e,this.body=t}};var ll=class extends Me{constructor(t,n){super();this.outer_zn=null;this.bodies=null;this.dim=0;this.jAcc=null;this.bias=null;this.stepped=!1;this.L=null;this.y=null;this.soft=0;this.gamma=0;this.velonly=!1;this.jMax=0;this.Keff=null;this.vec3=null;this.J=null;this.jOld=null;this.bodies=[],this.dim=t,this.velonly=n,this.jAcc=[],this.bias=[],this.L=[],this.J=[],this.jOld=[],this.y=[],this.Keff=[],this.vec3=Me._nape.geom.Vec3.get(0,0,0);for(let s=0;s<t;s++){let i=this.bias[s]=this.J[s]=this.jOld[s]=this.y[s]=0;this.jAcc[s]=i;for(let l=0;l<t;l++)this.L[s*t+l]=0}this.stepped=!1}bindVec2_invalidate(t){this.outer_zn.__invalidate()}addBody(t){let n=null;for(let s of this.bodies)if(s.body===t){n=s;break}n===null?(this.bodies.push(new ms(1,t)),this.active&&this.space!=null&&t?.constraints.add(this)):n.cnt++}remBody(t){let n=null,s=this.bodies.length|0,i=0;for(;i<s;){let l=this.bodies[i];if(l.body===t){l.cnt--,l.cnt===0&&(s>0&&(this.bodies[i]=this.bodies[s-1]),this.bodies.pop(),this.active&&this.space!=null&&t?.constraints.remove(this)),n=l;break}++i}return n!=null}bodyImpulse(t){for(let s=0;s<this.dim;s++)this.J[s]=this.jAcc[s];let n=Me._nape.geom.Vec3.get(0,0,0);return this.stepped&&this.outer_zn.__impulse(this.J,t.outer,n),n}activeBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.add(this)}inactiveBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.remove(this)}copy(t,n){let s=this.outer_zn.__copy();throw this.copyto(s),new Error("not done yet")}validate(){for(let t of this.bodies)if(t.body.space!==this.space)throw new Error("Error: Constraints must have each body within the same sapce to which the constraint has been assigned");this.outer_zn.__validate()}wake_connected(){for(let t of this.bodies)t.body.type===2&&t.body.wake()}forest(){for(let t of this.bodies)if(t.body.type===2){let n;if(t.body.component===t.body.component.parent)n=t.body.component;else{let i=t.body.component,l=null;for(;i!==i.parent;){let r=i.parent;i.parent=l,l=i,i=r}for(;l!=null;){let r=l.parent;l.parent=i,l=r}n=i}let s;if(this.component===this.component.parent)s=this.component;else{let i=this.component,l=null;for(;i!==i.parent;){let r=i.parent;i.parent=l,l=i,i=r}for(;l!=null;){let r=l.parent;l.parent=i,l=r}s=i}n!==s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}}pair_exists(t,n){let s=!1,i=this.bodies.length|0;for(let l=0;l<i;l++){let r=this.bodies[l].body;for(let a=l+1;a<i;a++){let o=this.bodies[a].body;if(r.id===t&&o.id===n||r.id===n&&o.id===t){s=!0;break}}if(s)break}return s}broken(){this.outer_zn.__broken()}clearcache(){for(let t=0;t<this.dim;t++)this.jAcc[t]=0;this.pre_dt=-1}lsq(t){let n=0;for(let s=0;s<this.dim;s++)n+=t[s]*t[s];return n}_clamp(t,n){let s=this.lsq(t);if(s>n*n){let i=n/Math.sqrt(s);for(let l=0;l<this.dim;l++)t[l]*=i}}solve(t){let n=0;for(let s=0;s<this.dim;s++){let i=0;for(let r=0;r<s-1;r++)i+=this.L[s*this.dim+r]*this.L[s*this.dim+r];let l=Math.sqrt(t[n++]-i);if(this.L[s*this.dim+s]=l,l!==0){l=1/l;for(let r=s+1;r<this.dim;r++){let a=0;for(let o=0;o<s-1;o++)a+=this.L[r*this.dim+o]*this.L[s*this.dim+o];this.L[r*this.dim+s]=l*(t[n++]-a)}}else{for(let r=s+1;r<this.dim;r++)this.L[r*this.dim+s]=0;n+=this.dim-s-1}}return this.L}transform(t,n){for(let s=0;s<this.dim;s++){let i=n[s],l=t[s*this.dim+s];if(l!==0){for(let r=0;r<s;r++)i-=t[s*this.dim+r]*this.y[r];this.y[s]=i/l}else this.y[s]=0}for(let s=0;s<this.dim;s++){let i=this.dim-1-s,l=t[i*this.dim+i];if(l!==0){let r=this.y[i];for(let a=i+1;a<this.dim;a++)r-=t[a*this.dim+i]*n[a];n[i]=r/l}else n[i]=0}}preStep(t){this.pre_dt===-1&&(this.pre_dt=t);let n=t/this.pre_dt;if(this.pre_dt=t,this.stepped=!0,this.outer_zn.__prepare(),this.outer_zn.__eff_mass(this.Keff),this.L=this.solve(this.Keff),!this.stiff&&!this.velonly){let s=2*Math.PI*this.frequency;this.gamma=1/(t*s*(2*this.damping+s*t));let i=1/(1+this.gamma),l=t*s*s*this.gamma;if(this.gamma*=i,this.soft=i,this.outer_zn.__position(this.bias),this.breakUnderError&&this.lsq(this.bias)>this.maxError*this.maxError)return!0;for(let r=0;r<this.dim;r++)this.bias[r]*=-l;this._clamp(this.bias,this.maxError)}else{for(let s=0;s<this.dim;s++)this.bias[s]=0;this.gamma=0,this.soft=1}for(let s=0;s<this.dim;s++)this.jAcc[s]*=n;return this.jMax=this.maxForce*t,!1}warmStart(){for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.jAcc,n.outer,this.vec3);let s=n.imass,i=n,l=i.velx,r=this.vec3;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let a=r.zpp_inner;a._validate!=null&&a._validate(),i.velx=l+r.zpp_inner.x*s;let o=n,p=o.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let h=c.zpp_inner;h._validate!=null&&h._validate(),o.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,y=this.vec3;if(y!=null&&y.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let d=y.zpp_inner;d._validate!=null&&d._validate(),u.angvel=x+y.zpp_inner.z*n.iinertia}}applyImpulseVel(){this.outer_zn.__velocity(this.J);for(let t=0;t<this.dim;t++)this.J[t]=this.bias[t]-this.J[t];this.transform(this.L,this.J);for(let t=0;t<this.dim;t++)this.jOld[t]=this.jAcc[t],this.jAcc[t]+=this.J[t]=this.J[t]*this.soft-this.jAcc[t]*this.gamma;if(this.outer_zn.__clamp(this.jAcc),(this.breakUnderForce||!this.stiff)&&this.lsq(this.jAcc)>this.jMax*this.jMax){if(this.breakUnderForce)return!0;this.stiff||this._clamp(this.jAcc,this.jMax)}for(let t=0;t<this.dim;t++)this.J[t]=this.jAcc[t]-this.jOld[t];for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.J,n.outer,this.vec3);let s=n.imass,i=n,l=i.velx,r=this.vec3;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let a=r.zpp_inner;a._validate!=null&&a._validate(),i.velx=l+r.zpp_inner.x*s;let o=n,p=o.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let h=c.zpp_inner;h._validate!=null&&h._validate(),o.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,y=this.vec3;if(y!=null&&y.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let d=y.zpp_inner;d._validate!=null&&d._validate(),u.angvel=x+y.zpp_inner.z*n.iinertia}return!1}applyImpulsePos(){if(this.velonly)return!1;this.outer_zn.__prepare(),this.outer_zn.__position(this.J);let t=this.lsq(this.J);if(this.breakUnderError&&t>this.maxError*this.maxError)return!0;if(t<Me._nape.Config.constraintLinearSlop*Me._nape.Config.constraintLinearSlop)return!1;for(let n=0;n<this.dim;n++)this.J[n]*=-1;this.outer_zn.__eff_mass(this.Keff),this.transform(this.solve(this.Keff),this.J),this.outer_zn.__clamp(this.J);for(let n of this.bodies){let s=n.body;this.outer_zn.__impulse(this.J,s.outer,this.vec3);let i=s.imass,l=s,r=l.posx,a=this.vec3;if(a!=null&&a.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let o=a.zpp_inner;o._validate!=null&&o._validate(),l.posx=r+a.zpp_inner.x*i;let p=s,c=p.posy,h=this.vec3;if(h!=null&&h.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let u=h.zpp_inner;u._validate!=null&&u._validate(),p.posy=c+h.zpp_inner.y*i;let x=this.vec3;if(x!=null&&x.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let y=x.zpp_inner;y._validate!=null&&y._validate();let d=x.zpp_inner.z*s.iinertia;if(s.rot+=d,d*d>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let _=d*d,f=1-.5*_,z=1-_*_/8,P=(f*s.axisx+d*s.axisy)*z;s.axisy=(f*s.axisy-d*s.axisx)*z,s.axisx=P}}return!1}draw(t){this.outer_zn.__draw(t)}};var Vs=class Vs extends Me{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.phase=0;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.kMassd=0;this.kMasse=0;this.kMassf=0;this.jAccx=0;this.jAccy=0;this.jAccz=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.biasz=0;this.stepped=!1;this.phase=0,this.jAccx=0,this.jAccy=0,this.jAccz=0,this.jMax=1/0,this.stepped=!1,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0}bodyImpulse(t){let n=Me._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAccx,-this.jAccy,-(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)):n.geom.Vec3.get(this.jAccx,this.jAccy,this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){let t=Me._nape,n=Me._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),a=l.zpp_inner.y==i}else a=!1;if(!a){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a1=l,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=Me._nape,n=Me._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),a=l.zpp_inner.y==i}else a=!1;if(!a){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=Vs._createFn(null,null,i,l.zpp_inner_zn.wrap_a2);return this.copyto(r),Je._copyBody(t,n,this.b1,r,"b1"),Je._copyBody(t,n,this.b2,r,"b2"),r}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: WeldJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.jAccz=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b1.smass+this.b2.smass;if(this.kMassa=s,this.kMassb=0,this.kMassd=s,this.kMassc=0,this.kMasse=0,this.kMassf=0,this.b1.sinertia!=0){let r=this.a1relx*this.b1.sinertia,a=this.a1rely*this.b1.sinertia;this.kMassa+=a*this.a1rely,this.kMassb+=-a*this.a1relx,this.kMassd+=r*this.a1relx,this.kMassc+=-a,this.kMasse+=r,this.kMassf+=this.b1.sinertia}if(this.b2.sinertia!=0){let r=this.a2relx*this.b2.sinertia,a=this.a2rely*this.b2.sinertia;this.kMassa+=a*this.a2rely,this.kMassb+=-a*this.a2relx,this.kMassd+=r*this.a2relx,this.kMassc+=-a,this.kMasse+=r,this.kMassf+=this.b2.sinertia}let i=this.kMassa*(this.kMassd*this.kMassf-this.kMasse*this.kMasse)+this.kMassb*(this.kMassc*this.kMasse-this.kMassb*this.kMassf)+this.kMassc*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),l;if(i!=i)this.kMassa=0,this.kMassb=0,this.kMassd=0,this.kMassc=0,this.kMasse=0,this.kMassf=0,l=7;else if(i==0){let r=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,r|=1),this.kMassd!=0?this.kMassd=1/this.kMassd:(this.kMassd=0,r|=2),this.kMassf!=0?this.kMassf=1/this.kMassf:(this.kMassf=0,r|=4),this.kMassb=this.kMassc=this.kMasse=0,l=r}else{let r=1/i,a=r*(this.kMassd*this.kMassf-this.kMasse*this.kMasse),o=r*(this.kMasse*this.kMassc-this.kMassb*this.kMassf),p=r*(this.kMassa*this.kMassf-this.kMassc*this.kMassc),c=r*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),h=r*(this.kMassb*this.kMassc-this.kMassa*this.kMasse),u=r*(this.kMassa*this.kMassd-this.kMassb*this.kMassb);this.kMassa=a,this.kMassb=o,this.kMassd=p,this.kMassc=c,this.kMasse=h,this.kMassf=u,l=0}if((l&1)!=0&&(this.jAccx=0),(l&2)!=0&&(this.jAccy=0),(l&4)!=0&&(this.jAccz=0),this.stiff)this.biasx=0,this.biasy=0,this.biasz=0,this.gamma=0;else{let r=2*Math.PI*this.frequency;this.gamma=1/(t*r*(2*this.damping+r*t));let a=1/(1+this.gamma),o=t*r*r*this.gamma;this.gamma*=a;let p=a;if(this.kMassa*=p,this.kMassb*=p,this.kMassd*=p,this.kMassc*=p,this.kMasse*=p,this.kMassf*=p,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.biasz=this.b2.rot-this.b1.rot-this.phase,this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz>this.maxError*this.maxError)return!0;let c=-o;this.biasx*=c,this.biasy*=c,this.biasz*=c;let h=this.maxError,u=this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz;if(u>h*h){let x=h*(1/Math.sqrt(u));this.biasx*=x,this.biasy*=x,this.biasz*=x}}return this.jAccx*=n,this.jAccy*=n,this.jAccz*=n,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),s=this.b2.angvel+this.b2.kinangvel-this.b1.angvel-this.b1.kinangvel,i=this.biasx-t,l=this.biasy-n,r=this.biasz-s,a=this.kMassa*i+this.kMassb*l+this.kMassc*r,o=this.kMassb*i+this.kMassd*l+this.kMasse*r;r=this.kMassc*i+this.kMasse*l+this.kMassf*r,i=a,l=o,i-=this.jAccx*this.gamma,l-=this.jAccy*this.gamma,r-=this.jAccz*this.gamma;let p=this.jAccx,c=this.jAccy,h=this.jAccz;if(this.jAccx+=i,this.jAccy+=l,this.jAccz+=r,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz>this.jMax*this.jMax)return!0}else if(!this.stiff){let y=this.jMax,d=this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz;if(d>y*y){let _=y*(1/Math.sqrt(d));this.jAccx*=_,this.jAccy*=_,this.jAccz*=_}}i=this.jAccx-p,l=this.jAccy-c,r=this.jAccz-h;let u=this.b1.imass;this.b1.velx-=i*u,this.b1.vely-=l*u;let x=this.b2.imass;return this.b2.velx+=i*x,this.b2.vely+=l*x,this.b1.angvel-=(l*this.a1relx-i*this.a1rely+r)*this.b1.iinertia,this.b2.angvel+=(l*this.a2relx-i*this.a2rely+r)*this.b2.iinertia,!1}applyImpulsePos(){let t=Me._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s),o=this.b2.rot-this.b1.rot-this.phase,p,c,h;if(this.breakUnderError&&r*r+a*a+o*o>this.maxError*this.maxError)return!0;let u=!0;r*r+a*a<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(u=!1,r=0,a=0);let x=t.Config.constraintAngularSlop;if(o*o<x*x)if(u)o=0;else return!1;if(r*=.5,a*=.5,o*=.5,r*r+a*a>6){let V=this.b1.smass+this.b2.smass;if(V>t.Config.epsilon){let D=.75/V;p=-r*D,c=-a*D;let T=20,G=p*p+c*c;if(G>T*T){let j=T*(1/Math.sqrt(G));p*=j,c*=j}let q=this.b1.imass;this.b1.posx-=p*q,this.b1.posy-=c*q;let R=this.b2.imass;this.b2.posx+=p*R,this.b2.posy+=c*R,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s),o=this.b2.rot-this.b1.rot-this.phase,r*=.5,a*=.5,o*=.5}}let y=this.b1.smass+this.b2.smass,d=y,_=0,f=y,z=0,P=0,k=0;if(this.b1.sinertia!=0){let V=n*this.b1.sinertia,D=s*this.b1.sinertia;d+=D*s,_+=-D*n,f+=V*n,z+=-D,P+=V,k+=this.b1.sinertia}if(this.b2.sinertia!=0){let V=i*this.b2.sinertia,D=l*this.b2.sinertia;d+=D*l,_+=-D*i,f+=V*i,z+=-D,P+=V,k+=this.b2.sinertia}p=-r,c=-a,h=-o;let m=6,b=p*p+c*c;if(b>m*m){let V=m*(1/Math.sqrt(b));p*=V,c*=V}let v=h<-.25,w=d*(f*k-P*P)+_*(z*P-_*k)+z*(_*P-z*f);if(w!=w)h=0,c=h,p=c;else if(w==0)d!=0?p/=d:p=0,f!=0?c/=f:c=0,k!=0?h/=k:h=0;else{let V=1/w,D=P*z-_*k,T=_*P-z*f,G=_*z-d*P,q=V*(p*(f*k-P*P)+c*D+h*T),R=V*(p*D+c*(d*k-z*z)+h*G);h=V*(p*T+c*G+h*(d*f-_*_)),p=q,c=R}let O=this.b1.imass;this.b1.posx-=p*O,this.b1.posy-=c*O;let E=this.b2.imass;this.b2.posx+=p*E,this.b2.posy+=c*E;let M=this.b1,N=-(c*n-p*s+h)*this.b1.iinertia;Je._rotateBody(M,N);let Z=this.b2,S=(c*i-p*l+h)*this.b2.iinertia;return Je._rotateBody(Z,S),!1}draw(t){}};Vs._wrapFn=null,Vs._createFn=null;var _i=Vs;var it=class it{constructor(){this.outer=null;this.hnext=null;this.id=0;this.di=0;this.stamp=0;this.up_stamp=0;this.sleep_stamp=0;this.endGenerated=0;this.active=!1;this.cleared=!1;this.sleeping=!1;this.present=0;this.intchange=!1;this.presentable=!1;this.continuous=!1;this.fresh=!1;this.immState=0;this.invalidated=!1;this.b1=null;this.b2=null;this.ws1=null;this.ws2=null;this.pair=null;this.type=0;this.colarb=null;this.fluidarb=null;this.sensorarb=null;this.sensorarb=null,this.fluidarb=null,this.colarb=null,this.type=0,this.pair=null,this.ws2=null,this.ws1=null,this.b2=null,this.b1=null,this.invalidated=!1,this.immState=0,this.fresh=!1,this.continuous=!1,this.presentable=!1,this.intchange=!1,this.present=0,this.sleeping=!1,this.cleared=!1,this.active=!1,this.endGenerated=0,this.sleep_stamp=0,this.up_stamp=0,this.stamp=0,this.di=0,this.id=0,this.hnext=null,this.outer=null}static _initEnums(e,t){let n=()=>{t.internal=!0;let s=new e.dynamics.ArbiterType;return t.internal=!1,s};t.ArbiterType_COLLISION==null&&(t.ArbiterType_COLLISION=n()),t.ArbiterType_SENSOR==null&&(t.ArbiterType_SENSOR=n()),t.ArbiterType_FLUID==null&&(t.ArbiterType_FLUID=n()),it.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID]}wrapper(){if(this.outer==null){let e=it._nape;it.internal=!0,this.type==it.COL?(this.colarb.outer_zn=it._createColArb(),this.outer=this.colarb.outer_zn):this.type==it.FLUID?(this.fluidarb.outer_zn=it._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,it.internal=!1}return this.outer}inactiveme(){return!this.active}acting(){return this.active?(this.immState&1)!=0:!1}swap_features(){let e=this.b1;this.b1=this.b2,this.b2=e,e=this.ws1,this.ws1=this.ws2,this.ws2=e,e=this.colarb.s1,this.colarb.s1=this.colarb.s2,this.colarb.s2=e}lazyRetire(e,t){let n=it._zpp;this.cleared=!0,(t==null||this.b2==t)&&it._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&it._removeFromArbiterList(this.b2.arbiters,this,n),this.pair!=null&&(this.pair.arb=null,this.pair=null),this.active=!1,e.f_arbiters.modified=!0}sup_assign(e,t,n,s){let i=it._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=s,it._addToArbiterList(this.b1.arbiters,this,i),it._addToArbiterList(this.b2.arbiters,this,i),this.active=!0,this.present=0,this.cleared=!1,this.sleeping=!1,this.fresh=!1,this.presentable=!1}sup_retire(){let e=it._zpp;this.cleared||(it._removeFromArbiterList(this.b1.arbiters,this,e),it._removeFromArbiterList(this.b2.arbiters,this,e),this.pair!=null&&(this.pair.arb=null,this.pair=null)),this.b1=this.b2=null,this.active=!1,this.intchange=!1}static _removeFromArbiterList(e,t,n){let s=null,i=e.head;for(;i!=null;){if(i.elt==t){let l,r;s==null?(l=e.head,r=l.next,e.head=r,e.head==null&&(e.pushmod=!0)):(l=s.next,r=l.next,s.next=r,r==null&&(e.pushmod=!0));let a=l;a.elt=null,a.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=a,e.modified=!0,e.length--,e.pushmod=!0;break}s=i,i=i.next}}static _addToArbiterList(e,t,n){let s;n.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?s=new n.util.ZNPNode_ZPP_Arbiter:(s=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=s.next,s.next=null),s.elt=t;let i=s;i.next=e.head,e.head=i,e.modified=!0,e.length++}};it._nape=null,it._zpp=null,it.internal=!1,it._createColArb=null,it._createFluidArb=null,it.COL=1,it.FLUID=4,it.SENSOR=2,it.types=[];var Ve=it;var Is=class Is extends Ve{constructor(){super(),this.next=null,this.type=Ve.SENSOR,this.sensorarb=this}alloc(){}free(){}assign(e,t,n,s){this.sup_assign(e,t,n,s)}retire(){this.sup_retire(),this.next=Is.zpp_pool,Is.zpp_pool=this}makemutable(){}makeimmutable(){}};Is.zpp_pool=null;var Nt=Is;var Bs=class Bs extends Ve{constructor(){super();this.outer_zn=null;this.centroidx=0;this.centroidy=0;this.overlap=0;this.r1x=0;this.r1y=0;this.r2x=0;this.r2y=0;this.nodrag=!1;this.wMass=0;this.adamp=0;this.agamma=0;this.vMassa=0;this.vMassb=0;this.vMassc=0;this.dampx=0;this.dampy=0;this.lgamma=0;this.nx=0;this.ny=0;this.buoyx=0;this.buoyy=0;this.wrap_position=null;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.wrap_position=null,this.buoyy=0,this.buoyx=0,this.ny=0,this.nx=0,this.lgamma=0,this.dampy=0,this.dampx=0,this.vMassc=0,this.vMassb=0,this.vMassa=0,this.agamma=0,this.adamp=0,this.wMass=0,this.nodrag=!1,this.r2y=0,this.r2x=0,this.r1y=0,this.r1x=0,this.overlap=0,this.centroidy=0,this.centroidx=0,this.next=null,this.outer_zn=null,this.type=Ve.FLUID,this.fluidarb=this,this.buoyx=0,this.buoyy=0,this.pre_dt=-1}alloc(){}free(){}position_validate(){if(!this.active)throw new Error("Error: Arbiter not currently in use");this.wrap_position.zpp_inner.x=this.centroidx,this.wrap_position.zpp_inner.y=this.centroidy}position_invalidate(t){this.centroidx=t.x,this.centroidy=t.y}getposition(){let t=Ve._zpp,n=Ve._nape,s;if(t.util.ZPP_PubPool.poolVec2==null?s=new n.geom.Vec2:(s=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;t.geom.ZPP_Vec2.zpp_pool==null?i=new t.geom.ZPP_Vec2:(i=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=0,i.y=0,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");i._isimmutable!=null&&i._isimmutable();let l;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=s.zpp_inner;if(r._validate!=null&&r._validate(),s.zpp_inner.x==0){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=s.zpp_inner;a._validate!=null&&a._validate(),l=s.zpp_inner.y==0}else l=!1;if(!l){s.zpp_inner.x=0,s.zpp_inner.y=0;let a=s.zpp_inner;a._invalidate!=null&&a._invalidate(a)}}s.zpp_inner.weak=!1,this.wrap_position=s,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!this.mutable,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this),this.wrap_position.zpp_inner._invalidate=this.position_invalidate.bind(this)}assign(t,n,s,i){this.sup_assign(t,n,s,i),this.nx=0,this.ny=1,this.dampx=0,this.dampy=0,this.adamp=0}retire(){this.sup_retire(),this.next=Bs.zpp_pool,Bs.zpp_pool=this,this.pre_dt=-1}makemutable(){this.mutable=!0,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=!1)}makeimmutable(){this.mutable=!1,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=!0)}inject(t,n,s){this.overlap=t,this.centroidx=n,this.centroidy=s}preStep(t,n){let s=Ve._nape;this.pre_dt==-1&&(this.pre_dt=n);let i=n/this.pre_dt;this.pre_dt=n,this.r1x=this.centroidx-this.b1.posx,this.r1y=this.centroidy-this.b1.posy,this.r2x=this.centroidx-this.b2.posx,this.r2y=this.centroidy-this.b2.posy;let l,r;this.ws1.fluidEnabled&&this.ws1.fluidProperties.wrap_gravity!=null?(l=this.ws1.fluidProperties.gravityx,r=this.ws1.fluidProperties.gravityy):(l=t.gravityx,r=t.gravityy);let a,o;this.ws2.fluidEnabled&&this.ws2.fluidProperties.wrap_gravity!=null?(a=this.ws2.fluidProperties.gravityx,o=this.ws2.fluidProperties.gravityy):(a=t.gravityx,o=t.gravityy);let p=0,c=0;if(this.ws1.fluidEnabled&&this.ws2.fluidEnabled){let h=this.overlap*this.ws1.fluidProperties.density,u=this.overlap*this.ws2.fluidProperties.density;if(h>u){let x=h+u;p-=l*x,c-=r*x}else if(h<u){let x=h+u;p+=a*x,c+=o*x}else{let x=l+a,y=r+o,d=.5;if(x*=d,y*=d,this.ws1.worldCOMx*x+this.ws1.worldCOMy*y>this.ws2.worldCOMx*x+this.ws2.worldCOMy*y){let _=h+u;p-=x*_,c-=y*_}else{let _=h+u;p+=x*_,c+=y*_}}}else if(this.ws1.fluidEnabled){let h=this.overlap*this.ws1.fluidProperties.density;p-=l*h,c-=r*h}else if(this.ws2.fluidEnabled){let h=this.overlap*this.ws2.fluidProperties.density;p+=a*h,c+=o*h}if(p*=n,c*=n,this.buoyx=p,this.buoyy=c,this.b1.type==2&&(this.b1.velx-=p*this.b1.imass,this.b1.vely-=c*this.b1.imass,this.b1.angvel-=(c*this.r1x-p*this.r1y)*this.b1.iinertia),this.b2.type==2&&(this.b2.velx+=p*this.b2.imass,this.b2.vely+=c*this.b2.imass,this.b2.angvel+=(c*this.r2x-p*this.r2y)*this.b2.iinertia),(!this.ws1.fluidEnabled||this.ws1.fluidProperties.viscosity==0)&&(!this.ws2.fluidEnabled||this.ws2.fluidProperties.viscosity==0))this.nodrag=!0,this.dampx=0,this.dampy=0,this.adamp=0;else{this.nodrag=!1;let h=0;if(this.ws1.fluidEnabled&&(this.ws2.validate_angDrag(),h+=this.ws1.fluidProperties.viscosity*this.ws2.angDrag*this.overlap/this.ws2.area),this.ws2.fluidEnabled&&(this.ws1.validate_angDrag(),h+=this.ws2.fluidProperties.viscosity*this.ws1.angDrag*this.overlap/this.ws1.area),h!=0){let d=this.b1.sinertia+this.b2.sinertia;d!=0?this.wMass=1/d:this.wMass=0,h*=4e-4;let _=2*Math.PI*h;this.agamma=1/(n*_*(2+_*n));let f=1/(1+this.agamma);this.agamma*=f,this.wMass*=f}else this.wMass=0,this.agamma=0;let u=this.b2.velx+this.b2.kinvelx-this.r2y*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.r1y*(this.b2.angvel+this.b2.kinangvel)),x=this.b2.vely+this.b2.kinvely+this.r2x*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.r1x*(this.b1.angvel+this.b1.kinangvel));if(!(u*u+x*x<s.Config.epsilon*s.Config.epsilon)){let d=u*u+x*x,_=1/Math.sqrt(d);this.nx=u*_,this.ny=x*_}let y=0;if(this.ws1.fluidEnabled){let d=-this.ws1.fluidProperties.viscosity*this.overlap/this.ws2.area;if(this.ws2.type==0)y-=d*this.ws2.circle.radius*s.Config.fluidLinearDrag/(2*this.ws2.circle.radius*Math.PI);else{let _=this.ws2.polygon,f=0,z=0,P=_.edges.head;for(;P!=null;){let k=P.elt;f+=k.length;let m=d*k.length*(k.gnormx*this.nx+k.gnormy*this.ny);m>0&&(m*=-s.Config.fluidVacuumDrag),z-=m*.5*s.Config.fluidLinearDrag,P=P.next}y+=z/f}}if(this.ws2.fluidEnabled){let d=-this.ws2.fluidProperties.viscosity*this.overlap/this.ws1.area;if(this.ws1.type==0)y-=d*this.ws1.circle.radius*s.Config.fluidLinearDrag/(2*this.ws1.circle.radius*Math.PI);else{let _=this.ws1.polygon,f=0,z=0,P=_.edges.head;for(;P!=null;){let k=P.elt;f+=k.length;let m=d*k.length*(k.gnormx*this.nx+k.gnormy*this.ny);m>0&&(m*=-s.Config.fluidVacuumDrag),z-=m*.5*s.Config.fluidLinearDrag,P=P.next}y+=z/f}}if(y!=0){let d=this.b1.smass+this.b2.smass,_=d,f=0,z=d;if(this.b1.sinertia!=0){let b=this.r1x*this.b1.sinertia,C=this.r1y*this.b1.sinertia;_+=C*this.r1y,f+=-C*this.r1x,z+=b*this.r1x}if(this.b2.sinertia!=0){let b=this.r2x*this.b2.sinertia,C=this.r2y*this.b2.sinertia;_+=C*this.r2y,f+=-C*this.r2x,z+=b*this.r2x}let P=_*z-f*f;if(P!==P)z=0,f=z,_=f;else if(P==0)_!=0?_=1/_:_=0,z!=0?z=1/z:z=0,f=0;else{let b=1/P,C=z*b;z=_*b,_=C,f*=-b}this.vMassa=_,this.vMassb=f,this.vMassc=z;let k=2*Math.PI*y;this.lgamma=1/(n*k*(2+k*n));let m=1/(1+this.lgamma);this.lgamma*=m,this.vMassa*=m,this.vMassb*=m,this.vMassc*=m}else this.vMassa=0,this.vMassb=0,this.vMassc=0,this.lgamma=0}this.dampx*=i,this.dampy*=i,this.adamp*=i}warmStart(){this.b1.velx-=this.dampx*this.b1.imass,this.b1.vely-=this.dampy*this.b1.imass,this.b2.velx+=this.dampx*this.b2.imass,this.b2.vely+=this.dampy*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(this.dampy*this.r1x-this.dampx*this.r1y),this.b2.angvel+=this.b2.iinertia*(this.dampy*this.r2x-this.dampx*this.r2y),this.b1.angvel-=this.adamp*this.b1.iinertia,this.b2.angvel+=this.adamp*this.b2.iinertia}applyImpulseVel(){if(!this.nodrag){let t=this.b1.angvel+this.b1.kinangvel,n=this.b2.angvel+this.b2.kinangvel,s=this.b1.velx+this.b1.kinvelx-this.r1y*t-(this.b2.velx+this.b2.kinvelx-this.r2y*n),i=this.b1.vely+this.b1.kinvely+this.r1x*t-(this.b2.vely+this.b2.kinvely+this.r2x*n),l=this.vMassa*s+this.vMassb*i;i=this.vMassb*s+this.vMassc*i,s=l,s-=this.dampx*this.lgamma,i-=this.dampy*this.lgamma,this.dampx+=s,this.dampy+=i,this.b1.velx-=s*this.b1.imass,this.b1.vely-=i*this.b1.imass,this.b2.velx+=s*this.b2.imass,this.b2.vely+=i*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(i*this.r1x-s*this.r1y),this.b2.angvel+=this.b2.iinertia*(i*this.r2x-s*this.r2y);let r=(t-n)*this.wMass-this.adamp*this.agamma;this.adamp+=r,this.b1.angvel-=r*this.b1.iinertia,this.b2.angvel+=r*this.b2.iinertia}}};Bs.zpp_pool=null;var zt=Bs;var yi=class{constructor(){this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.r1x=0;this.r1y=0;this.r2x=0;this.r2y=0;this.nMass=0;this.tMass=0;this.bounce=0;this.friction=0;this.jnAcc=0;this.jtAcc=0;this.lr1x=0;this.lr1y=0;this.lr2x=0;this.lr2y=0}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};var xn=class xn{constructor(){this.outer=null;this.px=0;this.py=0;this.wrap_position=null;this.arbiter=null;this.active=!1;this.posOnly=!1;this.stamp=0;this.hash=0;this.fresh=!1;this.dist=0;this.elasticity=0;this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.length=0,this.pushmod=!1,this.modified=!1,this._inuse=!1,this.next=null,this.elasticity=0,this.dist=0,this.fresh=!1,this.hash=0,this.stamp=0,this.posOnly=!1,this.active=!1,this.inner=null,this.arbiter=null,this.wrap_position=null,this.py=0,this.px=0,this.outer=null,this.inner=new yi}wrapper(){return this.outer==null&&(xn._wrapFn?this.outer=xn._wrapFn(this):(xn.internal=!0,this.outer=new xn._nape.dynamics.Contact,xn.internal=!1,this.outer.zpp_inner=this)),this.outer}position_validate(){if(this.inactiveme())throw new Error("Error: Contact not currently in use");this.wrap_position.zpp_inner.x=this.px,this.wrap_position.zpp_inner.y=this.py}getposition(){let e=xn._zpp,t=xn._nape,n;if(e.util.ZPP_PubPool.poolVec2==null?n=new t.geom.Vec2:(n=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let s;e.geom.ZPP_Vec2.zpp_pool==null?s=new e.geom.ZPP_Vec2:(s=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){n.zpp_inner.x=0,n.zpp_inner.y=0;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}n.zpp_inner.weak=!1,this.wrap_position=n,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!0,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this)}inactiveme(){return!(this.active&&this.arbiter!=null&&this.arbiter.active)}free(){this.arbiter=null}alloc(){}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};xn._nape=null,xn._zpp=null,xn.zpp_pool=null,xn.internal=!1,xn._wrapFn=null;var Pe=xn;var Pt=class Pt extends Ve{constructor(){super();this.outer_zn=null;this.dyn_fric=0;this.stat_fric=0;this.restitution=0;this.rfric=0;this.userdef_dyn_fric=!1;this.userdef_stat_fric=!1;this.userdef_restitution=!1;this.userdef_rfric=!1;this.s1=null;this.s2=null;this.wrap_contacts=null;this.nx=0;this.ny=0;this.wrap_normal=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.Ka=0;this.Kb=0;this.Kc=0;this.rMass=0;this.jrAcc=0;this.rn1a=0;this.rt1a=0;this.rn1b=0;this.rt1b=0;this.rn2a=0;this.rt2a=0;this.rn2b=0;this.rt2b=0;this.k1x=0;this.k1y=0;this.k2x=0;this.k2y=0;this.surfacex=0;this.surfacey=0;this.ptype=null;this.lnormx=0;this.lnormy=0;this.lproj=0;this.radius=0;this.rev=!1;this.biasCoef=0;this.__ref_edge1=null;this.__ref_edge2=null;this.__ref_vertex=0;this.c1=null;this.oc1=null;this.c2=null;this.oc2=null;this.hc2=!1;this.hpc2=!1;this.stat=!1;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.stat=!1,this.next=null,this.hpc2=!1,this.hc2=!1,this.oc2=null,this.c2=null,this.oc1=null,this.c1=null,this.__ref_vertex=0,this.__ref_edge2=null,this.__ref_edge1=null,this.biasCoef=0,this.rev=!1,this.radius=0,this.lproj=0,this.lnormy=0,this.lnormx=0,this.surfacey=0,this.surfacex=0,this.k2y=0,this.k2x=0,this.k1y=0,this.k1x=0,this.rt2b=0,this.rn2b=0,this.rt2a=0,this.rn2a=0,this.rt1b=0,this.rn1b=0,this.rt1a=0,this.rn1a=0,this.jrAcc=0,this.rMass=0,this.Kc=0,this.Kb=0,this.Ka=0,this.kMassc=0,this.kMassb=0,this.kMassa=0,this.wrap_normal=null,this.ny=0,this.nx=0,this.innards=null,this.wrap_contacts=null,this.contacts=null,this.s2=null,this.s1=null,this.userdef_rfric=!1,this.userdef_restitution=!1,this.userdef_stat_fric=!1,this.userdef_dyn_fric=!1,this.rfric=0,this.restitution=0,this.stat_fric=0,this.dyn_fric=0,this.outer_zn=null,this.pre_dt=-1,this.contacts=new Pe,this.innards=new yi,this.type=Ve.COL,this.colarb=this}alloc(){}free(){this.userdef_dyn_fric=!1,this.userdef_stat_fric=!1,this.userdef_restitution=!1,this.userdef_rfric=!1,this.__ref_edge1=this.__ref_edge2=null}normal_validate(){if(this.cleared)throw new Error("Error: Arbiter not currently in use");this.wrap_normal.zpp_inner.x=this.nx,this.wrap_normal.zpp_inner.y=this.ny,this.ws1.id>this.ws2.id&&(this.wrap_normal.zpp_inner.x=-this.wrap_normal.zpp_inner.x,this.wrap_normal.zpp_inner.y=-this.wrap_normal.zpp_inner.y)}getnormal(){let t=Ve._zpp,n=Ve._nape,s=0,i=0,l;if(t.util.ZPP_PubPool.poolVec2==null?l=new n.geom.Vec2:(l=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;t.geom.ZPP_Vec2.zpp_pool==null?r=new t.geom.ZPP_Vec2:(r=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!==s||i!==i)throw new Error("Error: Vec2 components cannot be NaN");let a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),a=l.zpp_inner.y==i}else a=!1;if(!a){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_normal=l,this.wrap_normal.zpp_inner._immutable=!0,this.wrap_normal.zpp_inner._inuse=!0,this.wrap_normal.zpp_inner._validate=this.normal_validate.bind(this)}injectContact(t,n,s,i,l,r,a=!1){let o=null,p=this.contacts.next;for(;p!=null;){if(r==p.hash){o=p;break}p=p.next}if(o==null){Pe.zpp_pool==null?o=new Pe:(o=Pe.zpp_pool,Pe.zpp_pool=o.next,o.next=null);let c=o.inner;c.jnAcc=c.jtAcc=0,o.hash=r,o.fresh=!0,o.arbiter=this,this.jrAcc=0,o._inuse=!0,o.next=this.contacts.next,this.contacts.next=o,this.contacts.modified=!0,this.contacts.length++,this.innards.add(c)}else o.fresh=!1;return o.px=t,o.py=n,this.nx=s,this.ny=i,o.dist=l,o.stamp=this.stamp,o.posOnly=a,o}assign(t,n,s,i){this.sup_assign(t,n,s,i),this.s1=t,this.s2=n,this._calcFrictionRestitution()}calcProperties(){this._calcFrictionRestitution()}validate_props(){this.invalidated&&(this.invalidated=!1,this._calcFrictionRestitution())}_calcFrictionRestitution(){this.userdef_restitution||(this.s1.material.elasticity<=-1/0||this.s2.material.elasticity<=-1/0?this.restitution=0:this.s1.material.elasticity>=1/0||this.s2.material.elasticity>=1/0?this.restitution=1:this.restitution=(this.s1.material.elasticity+this.s2.material.elasticity)/2,this.restitution<0&&(this.restitution=0),this.restitution>1&&(this.restitution=1)),this.userdef_dyn_fric||(this.dyn_fric=Math.sqrt(this.s1.material.dynamicFriction*this.s2.material.dynamicFriction)),this.userdef_stat_fric||(this.stat_fric=Math.sqrt(this.s1.material.staticFriction*this.s2.material.staticFriction)),this.userdef_rfric||(this.rfric=Math.sqrt(this.s1.material.rollingFriction*this.s2.material.rollingFriction))}retire(){for(this.sup_retire();this.contacts.next!=null;){let t=this.contacts.next;this.contacts.pop(),t.arbiter=null,t.next=Pe.zpp_pool,Pe.zpp_pool=t;let n=this.innards.next;this.innards.next=n.next,n._inuse=!1,this.innards.next==null&&(this.innards.pushmod=!0),this.innards.modified=!0,this.innards.length--}this.free(),this.next=Pt.zpp_pool,Pt.zpp_pool=this,this.pre_dt=-1}makemutable(){this.mutable=!0,this.wrap_normal!=null&&(this.wrap_normal.zpp_inner._immutable=!1),this.wrap_contacts!=null&&(this.wrap_contacts.zpp_inner.immutable=!1)}makeimmutable(){this.mutable=!1,this.wrap_normal!=null&&(this.wrap_normal.zpp_inner._immutable=!0),this.wrap_contacts!=null&&(this.wrap_contacts.zpp_inner.immutable=!0)}contacts_adder(t){throw new Error("Error: Cannot add new contacts, information required is far too specific and detailed :)")}contacts_subber(t){let n=null,s=null,i=this.innards.next,l=this.contacts.next;for(;l!=null;){if(l==t.zpp_inner){this.contacts.erase(n),this.innards.erase(s),l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;break}n=l,s=i,i=i.next,l=l.next}}setupcontacts(){let t=Ve._zpp;this.wrap_contacts=t.util.ZPP_ContactList.get(this.contacts,!0),this.wrap_contacts.zpp_inner.immutable=!this.mutable,this.wrap_contacts.zpp_inner.adder=this.contacts_adder.bind(this),this.wrap_contacts.zpp_inner.dontremove=!0,this.wrap_contacts.zpp_inner.subber=this.contacts_subber.bind(this)}cleanupContacts(){let t=Ve._nape,n=!0,s=null,i=null,l=this.innards.next;this.hc2=!1;let r=this.contacts.next;for(;r!=null;){let a=r;if(a.stamp+t.Config.arbiterExpirationDelay<this.stamp){r=Pt._eraseFromList(this.contacts,s),l=Pt._eraseFromList(this.innards,i),a.arbiter=null,a.next=Pe.zpp_pool,Pe.zpp_pool=a;continue}let o=a.inner,p=a.active;a.active=a.stamp==this.stamp,a.active&&(n?(n=!1,this.c1=o,this.oc1=a):(this.hc2=!0,this.c2=o,this.oc2=a)),p!=a.active&&(this.contacts.modified=!0),s=r,i=l,l=l.next,r=r.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let a=this.c1;this.c1=this.c2,this.c2=a,a=this.oc1,this.oc1=this.oc2,this.oc2=a,this.hc2=!1}else this.oc2.posOnly&&(this.hc2=!1);this.oc1.posOnly&&(n=!0)}else this.hpc2=!1;return n}preStep(t){let n=Ve._nape;this.validate_props(),this.pre_dt==-1&&(this.pre_dt=t);let s=t/this.pre_dt;this.pre_dt=t;let i=this.b1.smass+this.b2.smass;this.hc2=!1;let l=!0,a=this.b1.type!=2||this.b2.type!=2?this.continuous?n.Config.contactContinuousStaticBiasCoef:n.Config.contactStaticBiasCoef:this.continuous?n.Config.contactContinuousBiasCoef:n.Config.contactBiasCoef;this.biasCoef=a,this.continuous=!1;let o=null,p=null,c=this.innards.next,h=this.contacts.next;for(;h!=null;){let u=h;if(u.stamp+n.Config.arbiterExpirationDelay<this.stamp){h=Pt._eraseFromList(this.contacts,o),c=Pt._eraseFromList(this.innards,p),u.arbiter=null,u.next=Pe.zpp_pool,Pe.zpp_pool=u;continue}let x=u.inner,y=u.active;if(u.active=u.stamp==this.stamp,u.active){l?(l=!1,this.c1=x,this.oc1=u):(this.hc2=!0,this.c2=x,this.oc2=u),x.r2x=u.px-this.b2.posx,x.r2y=u.py-this.b2.posy,x.r1x=u.px-this.b1.posx,x.r1y=u.py-this.b1.posy;let d=x.r2x*this.nx+x.r2y*this.ny,_=i+this.b2.sinertia*(d*d);d=x.r1x*this.nx+x.r1y*this.ny,_+=this.b1.sinertia*(d*d),x.tMass=_<n.Config.epsilon*n.Config.epsilon?0:1/_,d=this.ny*x.r2x-this.nx*x.r2y;let f=i+this.b2.sinertia*(d*d);d=this.ny*x.r1x-this.nx*x.r1y,f+=this.b1.sinertia*(d*d),x.nMass=f<n.Config.epsilon*n.Config.epsilon?0:1/f;let z=this.b2.angvel+this.b2.kinangvel,P=this.b2.velx+this.b2.kinvelx-x.r2y*z,k=this.b2.vely+this.b2.kinvely+x.r2x*z;z=this.b1.angvel+this.b1.kinangvel,P-=this.b1.velx+this.b1.kinvelx-x.r1y*z,k-=this.b1.vely+this.b1.kinvely+x.r1x*z;let m=this.nx*P+this.ny*k;u.elasticity=this.restitution,x.bounce=m*u.elasticity,x.bounce>-n.Config.elasticThreshold&&(x.bounce=0);let b=k*this.nx-P*this.ny,C=n.Config.staticFrictionThreshold;b*b>C*C?x.friction=this.dyn_fric:x.friction=this.stat_fric,x.jnAcc*=s,x.jtAcc*=s}y!=u.active&&(this.contacts.modified=!0),o=h,p=c,c=c.next,h=h.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let u=this.c1;this.c1=this.c2,this.c2=u,u=this.oc1,this.oc1=this.oc2,this.oc2=u,this.hc2=!1}else this.oc2.posOnly&&(this.hc2=!1);this.oc1.posOnly&&(l=!0)}else this.hpc2=!1;if(this.jrAcc*=s,l||(this.rn1a=this.ny*this.c1.r1x-this.nx*this.c1.r1y,this.rt1a=this.c1.r1x*this.nx+this.c1.r1y*this.ny,this.rn1b=this.ny*this.c1.r2x-this.nx*this.c1.r2y,this.rt1b=this.c1.r2x*this.nx+this.c1.r2y*this.ny,this.k1x=this.b2.kinvelx-this.c1.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c1.r1y*this.b1.kinangvel),this.k1y=this.b2.kinvely+this.c1.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c1.r1x*this.b1.kinangvel)),this.hc2)if(this.rn2a=this.ny*this.c2.r1x-this.nx*this.c2.r1y,this.rt2a=this.c2.r1x*this.nx+this.c2.r1y*this.ny,this.rn2b=this.ny*this.c2.r2x-this.nx*this.c2.r2y,this.rt2b=this.c2.r2x*this.nx+this.c2.r2y*this.ny,this.k2x=this.b2.kinvelx-this.c2.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c2.r1y*this.b1.kinangvel),this.k2y=this.b2.kinvely+this.c2.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c2.r1x*this.b1.kinangvel),this.kMassa=i+this.b1.sinertia*this.rn1a*this.rn1a+this.b2.sinertia*this.rn1b*this.rn1b,this.kMassb=i+this.b1.sinertia*this.rn1a*this.rn2a+this.b2.sinertia*this.rn1b*this.rn2b,this.kMassc=i+this.b1.sinertia*this.rn2a*this.rn2a+this.b2.sinertia*this.rn2b*this.rn2b,this.kMassa*this.kMassa+2*this.kMassb*this.kMassb+this.kMassc*this.kMassc<n.Config.illConditionedThreshold*(this.kMassa*this.kMassc-this.kMassb*this.kMassb)){this.Ka=this.kMassa,this.Kb=this.kMassb,this.Kc=this.kMassc;let x=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(x!==x)this.kMassa=this.kMassb=this.kMassc=0;else if(x==0)this.kMassa!=0?this.kMassa=1/this.kMassa:this.kMassa=0,this.kMassc!=0?this.kMassc=1/this.kMassc:this.kMassc=0,this.kMassb=0;else{let y=1/x,d=this.kMassc*y;this.kMassc=this.kMassa*y,this.kMassa=d,this.kMassb*=-y}}else{if(this.hc2=!1,this.oc2.dist<this.oc1.dist){let x=this.c1;this.c1=this.c2,this.c2=x}this.oc2.active=!1,this.contacts.modified=!0}return this.surfacex=this.b2.svelx,this.surfacey=this.b2.svely,this.surfacex+=this.b1.svelx,this.surfacey+=this.b1.svely,this.surfacex=-this.surfacex,this.surfacey=-this.surfacey,this.rMass=this.b1.sinertia+this.b2.sinertia,this.rMass!=0&&(this.rMass=1/this.rMass),l}warmStart(){let t=this.nx*this.c1.jnAcc-this.ny*this.c1.jtAcc,n=this.ny*this.c1.jnAcc+this.nx*this.c1.jtAcc;this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c1.r1x-t*this.c1.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c1.r2x-t*this.c1.r2y),this.hc2&&(t=this.nx*this.c2.jnAcc-this.ny*this.c2.jtAcc,n=this.ny*this.c2.jnAcc+this.nx*this.c2.jtAcc,this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c2.r1x-t*this.c2.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c2.r2x-t*this.c2.r2y)),this.b2.angvel+=this.jrAcc*this.b2.iinertia,this.b1.angvel-=this.jrAcc*this.b1.iinertia}applyImpulseVel(){let t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),s=(n*this.nx-t*this.ny+this.surfacex)*this.c1.tMass,i=this.c1.friction*this.c1.jnAcc,l=this.c1.jtAcc,r=l-s;r>i?r=i:r<-i&&(r=-i),s=r-l,this.c1.jtAcc=r;let a=-this.ny*s,o=this.nx*s;if(this.b2.velx+=a*this.b2.imass,this.b2.vely+=o*this.b2.imass,this.b1.velx-=a*this.b1.imass,this.b1.vely-=o*this.b1.imass,this.b2.angvel+=this.rt1b*s*this.b2.iinertia,this.b1.angvel-=this.rt1a*s*this.b1.iinertia,this.hc2){let p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);s=(c*this.nx-p*this.ny+this.surfacex)*this.c2.tMass,i=this.c2.friction*this.c2.jnAcc,l=this.c2.jtAcc,r=l-s,r>i?r=i:r<-i&&(r=-i),s=r-l,this.c2.jtAcc=r,a=-this.ny*s,o=this.nx*s,this.b2.velx+=a*this.b2.imass,this.b2.vely+=o*this.b2.imass,this.b1.velx-=a*this.b1.imass,this.b1.vely-=o*this.b1.imass,this.b2.angvel+=this.rt2b*s*this.b2.iinertia,this.b1.angvel-=this.rt2a*s*this.b1.iinertia,t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);let h=this.c1.jnAcc,u=this.c2.jnAcc,x=t*this.nx+n*this.ny+this.surfacey+this.c1.bounce-(this.Ka*h+this.Kb*u),y=p*this.nx+c*this.ny+this.surfacey+this.c2.bounce-(this.Kb*h+this.Kc*u),d=-(this.kMassa*x+this.kMassb*y),_=-(this.kMassb*x+this.kMassc*y);d>=0&&_>=0?(x=d-h,y=_-u,this.c1.jnAcc=d,this.c2.jnAcc=_):(d=-this.c1.nMass*x,d>=0&&this.Kb*d+y>=0?(x=d-h,y=-u,this.c1.jnAcc=d,this.c2.jnAcc=0):(_=-this.c2.nMass*y,_>=0&&this.Kb*_+x>=0?(x=-h,y=_-u,this.c1.jnAcc=0,this.c2.jnAcc=_):x>=0&&y>=0?(x=-h,y=-u,this.c1.jnAcc=this.c2.jnAcc=0):(x=0,y=0))),s=x+y,a=this.nx*s,o=this.ny*s,this.b2.velx+=a*this.b2.imass,this.b2.vely+=o*this.b2.imass,this.b1.velx-=a*this.b1.imass,this.b1.vely-=o*this.b1.imass,this.b2.angvel+=(this.rn1b*x+this.rn2b*y)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*x+this.rn2a*y)*this.b1.iinertia}else this.radius!=0&&(s=(this.b2.angvel-this.b1.angvel)*this.rMass,i=this.rfric*this.c1.jnAcc,l=this.jrAcc,this.jrAcc-=s,this.jrAcc>i?this.jrAcc=i:this.jrAcc<-i&&(this.jrAcc=-i),s=this.jrAcc-l,this.b2.angvel+=s*this.b2.iinertia,this.b1.angvel-=s*this.b1.iinertia),t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),s=(this.c1.bounce+(this.nx*t+this.ny*n)+this.surfacey)*this.c1.nMass,l=this.c1.jnAcc,r=l-s,r<0&&(r=0),s=r-l,this.c1.jnAcc=r,a=this.nx*s,o=this.ny*s,this.b2.velx+=a*this.b2.imass,this.b2.vely+=o*this.b2.imass,this.b1.velx-=a*this.b1.imass,this.b1.vely-=o*this.b1.imass,this.b2.angvel+=this.rn1b*s*this.b2.iinertia,this.b1.angvel-=this.rn1a*s*this.b1.iinertia}applyImpulsePos(){let t=Ve._nape;this.ptype==2?this._applyImpulsePosCircle(t):this._applyImpulsePosEdge(t)}_applyImpulsePosCircle(t){let n=this.c1,s=this.b2.axisy*n.lr2x-this.b2.axisx*n.lr2y,i=n.lr2x*this.b2.axisx+n.lr2y*this.b2.axisy;s+=this.b2.posx,i+=this.b2.posy;let l=this.b1.axisy*n.lr1x-this.b1.axisx*n.lr1y,r=n.lr1x*this.b1.axisx+n.lr1y*this.b1.axisy;l+=this.b1.posx,r+=this.b1.posy;let a=s-l,o=i-r,p=Math.sqrt(a*a+o*o),c=this.radius-t.Config.collisionSlop,h=p-c;if(a*this.nx+o*this.ny<0&&(a=-a,o=-o,h-=this.radius),h<0)if(p<t.Config.epsilon)this.b1.smass!=0?this.b1.posx+=t.Config.epsilon*10:this.b2.posx+=t.Config.epsilon*10;else{let u=1/p;a*=u,o*=u;let x=.5*(l+s),y=.5*(r+i),d=p-c;l=x-this.b1.posx,r=y-this.b1.posy,s=x-this.b2.posx,i=y-this.b2.posy;let _=o*l-a*r,f=o*s-a*i,z=this.b2.smass+f*f*this.b2.sinertia+this.b1.smass+_*_*this.b1.sinertia;if(z!=0){let P=-this.biasCoef*d/z,k=a*P,m=o*P;this.b1.posx-=k*this.b1.imass,this.b1.posy-=m*this.b1.imass,Pt._rotateBody(this.b1,-_*this.b1.iinertia*P),this.b2.posx+=k*this.b2.imass,this.b2.posy+=m*this.b2.imass,Pt._rotateBody(this.b2,f*this.b2.iinertia*P)}}}_applyImpulsePosEdge(t){let n,s,i,l,r,a=0,o=0;this.ptype==0?(n=this.b1.axisy*this.lnormx-this.b1.axisx*this.lnormy,s=this.lnormx*this.b1.axisx+this.lnormy*this.b1.axisy,i=this.lproj+(n*this.b1.posx+s*this.b1.posy),l=this.b2.axisy*this.c1.lr1x-this.b2.axisx*this.c1.lr1y,r=this.c1.lr1x*this.b2.axisx+this.c1.lr1y*this.b2.axisy,l+=this.b2.posx,r+=this.b2.posy,this.hpc2&&(a=this.b2.axisy*this.c2.lr1x-this.b2.axisx*this.c2.lr1y,o=this.c2.lr1x*this.b2.axisx+this.c2.lr1y*this.b2.axisy,a+=this.b2.posx,o+=this.b2.posy)):(n=this.b2.axisy*this.lnormx-this.b2.axisx*this.lnormy,s=this.lnormx*this.b2.axisx+this.lnormy*this.b2.axisy,i=this.lproj+(n*this.b2.posx+s*this.b2.posy),l=this.b1.axisy*this.c1.lr1x-this.b1.axisx*this.c1.lr1y,r=this.c1.lr1x*this.b1.axisx+this.c1.lr1y*this.b1.axisy,l+=this.b1.posx,r+=this.b1.posy,this.hpc2&&(a=this.b1.axisy*this.c2.lr1x-this.b1.axisx*this.c2.lr1y,o=this.c2.lr1x*this.b1.axisx+this.c2.lr1y*this.b1.axisy,a+=this.b1.posx,o+=this.b1.posy));let p=l*n+r*s-i-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=a*n+o*s-i-this.radius,c+=t.Config.collisionSlop),p<0||c<0){this.rev&&(n=-n,s=-s);let h=l-this.b1.posx,u=r-this.b1.posy,x=l-this.b2.posx,y=r-this.b2.posy;if(this.hpc2){let d=a-this.b1.posx,_=o-this.b1.posy,f=a-this.b2.posx,z=o-this.b2.posy,P=s*h-n*u,k=s*x-n*y,m=s*d-n*_,b=s*f-n*z,C=this.b1.smass+this.b2.smass;this.kMassa=C+this.b1.sinertia*P*P+this.b2.sinertia*k*k,this.kMassb=C+this.b1.sinertia*P*m+this.b2.sinertia*k*b,this.kMassc=C+this.b1.sinertia*m*m+this.b2.sinertia*b*b;let v=this.kMassa,w=this.kMassb,O=this.kMassc,E=p*this.biasCoef,M=c*this.biasCoef;for(;;){let N=-E,Z=-M,S=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(S!==S)N=0,Z=0;else if(S==0)this.kMassa!=0?N/=this.kMassa:N=0,this.kMassc!=0?Z/=this.kMassc:Z=0;else{let V=1/S,D=V*(this.kMassc*N-this.kMassb*Z);Z=V*(this.kMassa*Z-this.kMassb*N),N=D}if(N>=0&&Z>=0){Pt._applyPosImpulse2(this.b1,this.b2,n,s,N,Z,P,m,k,b);break}if(N=-E/v,Z=0,N>=0&&w*N+M>=0){Pt._applyPosImpulse2(this.b1,this.b2,n,s,N,Z,P,m,k,b);break}if(N=0,Z=-M/O,Z>=0&&w*Z+E>=0){Pt._applyPosImpulse2(this.b1,this.b2,n,s,N,Z,P,m,k,b);break}break}}else{let d=s*h-n*u,_=s*x-n*y,f=this.b2.smass+_*_*this.b2.sinertia+this.b1.smass+d*d*this.b1.sinertia;if(f!=0){let z=-this.biasCoef*p/f,P=n*z,k=s*z;this.b1.posx-=P*this.b1.imass,this.b1.posy-=k*this.b1.imass,Pt._rotateBody(this.b1,-d*this.b1.iinertia*z),this.b2.posx+=P*this.b2.imass,this.b2.posy+=k*this.b2.imass,Pt._rotateBody(this.b2,_*this.b2.iinertia*z)}}}}static _eraseFromList(t,n){let s,i;return n==null?(s=t.next,i=s.next,t.next=i,t.next==null&&(t.pushmod=!0)):(s=n.next,i=s.next,n.next=i,i==null&&(t.pushmod=!0)),s._inuse=!1,t.modified=!0,t.length--,t.pushmod=!0,i}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let s=n*n,i=1-.5*s,l=1-s*s/8,r=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=r}}static _applyPosImpulse2(t,n,s,i,l,r,a,o,p,c){let h=(l+r)*t.imass;t.posx-=s*h,t.posy-=i*h,Pt._rotateBody(t,-t.iinertia*(a*l+o*r));let u=(l+r)*n.imass;n.posx+=s*u,n.posy+=i*u,Pt._rotateBody(n,n.iinertia*(p*l+c*r))}};Pt.FACE1=0,Pt.FACE2=1,Pt.CIRCLE=2,Pt.zpp_pool=null;var pt=Pt;var Gt=class Gt{constructor(){this.collisionGroup=1;this.collisionMask=-1;this.sensorGroup=1;this.sensorMask=-1;this.fluidGroup=1;this.fluidMask=-1;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new Gt._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Gt._wrapFn)this.outer=Gt._wrapFn(this);else{this.outer=new Gt._nape.dynamics.InteractionFilter;let e=this.outer.zpp_inner;e.outer=null,e.next=Gt.zpp_pool,Gt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Gt._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Gt.zpp_pool==null?e=new Gt:(e=Gt.zpp_pool,Gt.zpp_pool=e.next,e.next=null),e.collisionGroup=this.collisionGroup,e.collisionMask=this.collisionMask,e.sensorGroup=this.sensorGroup,e.sensorMask=this.sensorMask,e.fluidGroup=this.fluidGroup,e.fluidMask=this.fluidMask,e}shouldCollide(e){return(this.collisionMask&e.collisionGroup)!==0&&(e.collisionMask&this.collisionGroup)!==0}shouldSense(e){return(this.sensorMask&e.sensorGroup)!==0&&(e.sensorMask&this.sensorGroup)!==0}shouldFlow(e){return(this.fluidMask&e.fluidGroup)!==0&&(e.fluidMask&this.fluidGroup)!==0}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_filter(),e=e.next}};Gt.zpp_pool=null,Gt._nape=null,Gt._zpp=null,Gt._wrapFn=null;var ct=Gt;var Ai=class Ai{constructor(){this.outer=null;this.ignore=!1;this.group=null;this.groups=null;this.wrap_groups=null;this.interactors=null;this.wrap_interactors=null;this.depth=0;let e=Ai._zpp;this.groups=new e.util.ZNPList_ZPP_InteractionGroup,this.interactors=new e.util.ZNPList_ZPP_Interactor}setGroup(e){this.group!==e&&(this.group!=null&&(this.group.groups.remove(this),this.depth=0,this.group.invalidate(!0)),this.group=e,e!=null?(e.groups.add(this),this.depth=e.depth+1,e.invalidate(!0)):this.invalidate(!0))}invalidate(e){if(e==null&&(e=!1),!(e||this.ignore))return;let t=this.interactors.head;for(;t!=null;){let s=t.elt;s.ibody!=null?s.ibody.wake():s.ishape!=null?s.ishape.body.wake():s.icompound.wake(),t=t.next}let n=this.groups.head;for(;n!=null;)n.elt.invalidate(e),n=n.next}addGroup(e){this.groups.add(e),e.depth=this.depth+1}remGroup(e){this.groups.remove(e),e.depth=0}addInteractor(e){this.interactors.add(e)}remInteractor(e,t){this.interactors.remove(e)}};Ai.SHAPE=1,Ai.BODY=2,Ai._zpp=null,Ai._wrapFn=null;var js=Ai;var Un=class{constructor(){this.zpp_inner=null;this.space=null;this._length=0;this.zip_length=!1;this.lengths=[];this.ite_0=null;this.ite_1=null;this.ite_2=null;this.ite_3=null;this.at_index_0=0;this.at_index_1=0;this.at_index_2=0;this.at_index_3=0;this.at_index_0=0,this.at_index_1=0,this.at_index_2=0,this.at_index_3=0,this.zip_length=!0,this._length=0,this.lengths=[],this.lengths.push(0),this.lengths.push(0),this.lengths.push(0),this.lengths.push(0)}zpp_gl(){if(this.zpp_vm(),this.zip_length){this._length=0;let e=0,t=0,n=this.space.c_arbiters_true.head;for(;n!=null;)n.elt.active&&++t,n=n.next;this.lengths[e++]=t,this._length+=t;let s=0,i=this.space.c_arbiters_false.head;for(;i!=null;)i.elt.active&&++s,i=i.next;this.lengths[e++]=s,this._length+=s;let l=0,r=this.space.f_arbiters.head;for(;r!=null;)r.elt.active&&++l,r=r.next;this.lengths[e++]=l,this._length+=l;let a=0,o=this.space.s_arbiters.head;for(;o!=null;)o.elt.active&&++a,o=o.next;this.lengths[e++]=a,this._length+=a,this.zip_length=!1}return this._length}zpp_vm(){let e=!1;this.space.c_arbiters_true.modified&&(e=!0,this.space.c_arbiters_true.modified=!1),this.space.c_arbiters_false.modified&&(e=!0,this.space.c_arbiters_false.modified=!1),this.space.f_arbiters.modified&&(e=!0,this.space.f_arbiters.modified=!1),this.space.s_arbiters.modified&&(e=!0,this.space.s_arbiters.modified=!1),e&&(this.zip_length=!0,this._length=0,this.ite_0=null,this.ite_1=null,this.ite_2=null,this.ite_3=null)}push(e){throw new Error("Error: ArbiterList is immutable")}pop(){throw new Error("Error: ArbiterList is immutable")}unshift(e){throw new Error("Error: ArbiterList is immutable")}shift(){throw new Error("Error: ArbiterList is immutable")}remove(e){throw new Error("Error: ArbiterList is immutable")}clear(){throw new Error("Error: ArbiterList is immutable")}at(e){if(this.zpp_vm(),e<0||e>=this.zpp_gl())throw new Error("Error: Index out of bounds");let t=null,n=0;if(t==null)if(e<n+this.lengths[0]){let s=e-n;if(s<this.at_index_0||this.ite_0==null)for(this.at_index_0=0,this.ite_0=this.space.c_arbiters_true.head;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;for(;this.at_index_0!=s;)for(this.at_index_0++,this.ite_0=this.ite_0.next;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;t=this.ite_0.elt.wrapper()}else n+=this.lengths[0];if(t==null)if(e<n+this.lengths[1]){let s=e-n;if(s<this.at_index_1||this.ite_1==null)for(this.at_index_1=0,this.ite_1=this.space.c_arbiters_false.head;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;for(;this.at_index_1!=s;)for(this.at_index_1++,this.ite_1=this.ite_1.next;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;t=this.ite_1.elt.wrapper()}else n+=this.lengths[1];if(t==null)if(e<n+this.lengths[2]){let s=e-n;if(s<this.at_index_2||this.ite_2==null)for(this.at_index_2=0,this.ite_2=this.space.f_arbiters.head;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;for(;this.at_index_2!=s;)for(this.at_index_2++,this.ite_2=this.ite_2.next;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;t=this.ite_2.elt.wrapper()}else n+=this.lengths[2];if(t==null)if(e<n+this.lengths[3]){let s=e-n;if(s<this.at_index_3||this.ite_3==null)for(this.at_index_3=0,this.ite_3=this.space.s_arbiters.head;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;for(;this.at_index_3!=s;)for(this.at_index_3++,this.ite_3=this.ite_3.next;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;t=this.ite_3.elt.wrapper()}else n+=this.lengths[3];return t}};Un._nape=null,Un._zpp=null;var Ct=class Ct{constructor(){this._invalidate=null;this._validate=null;this._immutable=!1;this.outer=null;this.next=null;this.minx=0;this.miny=0;this.maxx=0;this.maxy=0;this.wrap_min=null;this.wrap_max=null}static get(e,t,n,s){let i;return Ct.zpp_pool==null?i=new Ct:(i=Ct.zpp_pool,Ct.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=t,i.maxx=n,i.maxy=s,i}validate(){this._validate!=null&&this._validate()}invalidate(){this._invalidate!=null&&this._invalidate(this)}wrapper(){if(this.outer==null)if(Ct._wrapFn)this.outer=Ct._wrapFn(this);else{this.outer=new Ct._nape.geom.AABB;let e=this.outer.zpp_inner;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e.wrap_min=e.wrap_max=null,e._invalidate=null,e._validate=null,e.next=Ct.zpp_pool,Ct.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}alloc(){}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this.wrap_min=this.wrap_max=null,this._invalidate=null,this._validate=null}copy(){return Ct.get(this.minx,this.miny,this.maxx,this.maxy)}width(){return this.maxx-this.minx}height(){return this.maxy-this.miny}perimeter(){return(this.maxx-this.minx+(this.maxy-this.miny))*2}static _makeVec2Wrapper(e,t){let n=Ct._zpp,s=Ct._nape;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new s.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;n.geom.ZPP_Vec2.zpp_pool==null?l=new n.geom.ZPP_Vec2:(l=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=e,l.y=t,i.zpp_inner=l,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");l._validate!=null&&l._validate(),(l.x!==e||l.y!==t)&&(l.x=e,l.y=t,l._invalidate!=null&&l._invalidate(l))}return i.zpp_inner.weak=!1,i}getmin(){this.wrap_min==null&&(this.wrap_min=Ct._makeVec2Wrapper(this.minx,this.miny),this.wrap_min.zpp_inner._inuse=!0,this._immutable?this.wrap_min.zpp_inner._immutable=!0:this.wrap_min.zpp_inner._invalidate=this.mod_min.bind(this),this.wrap_min.zpp_inner._validate=this.dom_min.bind(this))}dom_min(){this._validate!=null&&this._validate(),this.wrap_min.zpp_inner.x=this.minx,this.wrap_min.zpp_inner.y=this.miny}mod_min(e){(e.x!==this.minx||e.y!==this.miny)&&(this.minx=e.x,this.miny=e.y,this._invalidate!=null&&this._invalidate(this))}getmax(){this.wrap_max==null&&(this.wrap_max=Ct._makeVec2Wrapper(this.maxx,this.maxy),this.wrap_max.zpp_inner._inuse=!0,this._immutable?this.wrap_max.zpp_inner._immutable=!0:this.wrap_max.zpp_inner._invalidate=this.mod_max.bind(this),this.wrap_max.zpp_inner._validate=this.dom_max.bind(this))}dom_max(){this._validate!=null&&this._validate(),this.wrap_max.zpp_inner.x=this.maxx,this.wrap_max.zpp_inner.y=this.maxy}mod_max(e){(e.x!==this.maxx||e.y!==this.maxy)&&(this.maxx=e.x,this.maxy=e.y,this._invalidate!=null&&this._invalidate(this))}intersectX(e){return!(e.minx>this.maxx||this.minx>e.maxx)}intersectY(e){return!(e.miny>this.maxy||this.miny>e.maxy)}intersect(e){return e.miny<=this.maxy&&this.miny<=e.maxy&&e.minx<=this.maxx&&this.minx<=e.maxx}combine(e){e.minx<this.minx&&(this.minx=e.minx),e.maxx>this.maxx&&(this.maxx=e.maxx),e.miny<this.miny&&(this.miny=e.miny),e.maxy>this.maxy&&(this.maxy=e.maxy)}contains(e){return e.minx>=this.minx&&e.miny>=this.miny&&e.maxx<=this.maxx&&e.maxy<=this.maxy}containsPoint(e){return e.x>=this.minx&&e.x<=this.maxx&&e.y>=this.miny&&e.y<=this.maxy}setCombine(e,t){this.minx=e.minx<t.minx?e.minx:t.minx,this.miny=e.miny<t.miny?e.miny:t.miny,this.maxx=e.maxx>t.maxx?e.maxx:t.maxx,this.maxy=e.maxy>t.maxy?e.maxy:t.maxy}setExpand(e,t){this.minx=e.minx-t,this.miny=e.miny-t,this.maxx=e.maxx+t,this.maxy=e.maxy+t}setExpandPoint(e,t){e<this.minx&&(this.minx=e),e>this.maxx&&(this.maxx=e),t<this.miny&&(this.miny=t),t>this.maxy&&(this.maxy=t)}toString(){return"{ x: "+this.minx+" y: "+this.miny+" w: "+(this.maxx-this.minx)+" h: "+(this.maxy-this.miny)+" }"}};Ct.zpp_pool=null,Ct._nape=null,Ct._zpp=null,Ct._wrapFn=null;var be=Ct;var Ce=class Ce{static _initStatics(e){Ce.flowpoly=new e.util.ZNPList_ZPP_Vec2,Ce.flowsegs=new e.util.ZNPList_ZPP_Vec2}static circleContains(e,t){let n=t.x-e.worldCOMx,s=t.y-e.worldCOMy;return n*n+s*s<e.radius*e.radius}static polyContains(e,t){let n;n=!0;let s=e.edges.head;for(;s!=null;){let i=s.elt;if(i.gnormx*t.x+i.gnormy*t.y<=i.gprojection){s=s.next;continue}else{n=!1;break}}return n}static shapeContains(e,t){return e.type==0?Ce.circleContains(e.circle,t):Ce.polyContains(e.polygon,t)}static bodyContains(e,t){let n;n=!1;let s=e.shapes.head;for(;s!=null;){let i=s.elt;if(Ce.shapeContains(i,t)){n=!0;break}s=s.next}return n}static containTest(e,t){let n=e.aabb,s=t.aabb;if(s.minx>=n.minx&&s.miny>=n.miny&&s.maxx<=n.maxx&&s.maxy<=n.maxy)if(e.type==0)if(t.type==0){let i=e.circle.radius+-t.circle.radius,l=t.circle.worldCOMx-e.circle.worldCOMx,r=t.circle.worldCOMy-e.circle.worldCOMy;return l*l+r*r<=i*i}else{let i;i=!0;let l=t.polygon.gverts.next;for(;l!=null;){let r=l,a=e.circle.radius,o=r.x-e.circle.worldCOMx,p=r.y-e.circle.worldCOMy;if(o*o+p*p<=a*a){l=l.next;continue}else{i=!1;break}}return i}else if(t.type==0){let i;i=!0;let l=e.polygon.edges.head;for(;l!=null;){let r=l.elt;if(r.gnormx*t.circle.worldCOMx+r.gnormy*t.circle.worldCOMy+t.circle.radius<=r.gprojection){l=l.next;continue}else{i=!1;break}}return i}else{let i;i=!0;let l=e.polygon.edges.head;for(;l!=null;){let r=l.elt,a=-1e100,o=t.polygon.gverts.next;for(;o!=null;){let p=o,c=r.gnormx*p.x+r.gnormy*p.y;c>a&&(a=c),o=o.next}if(a<=r.gprojection){l=l.next;continue}else{i=!1;break}}return i}else return!1}static contactCollide(e,t,n,s){let i=me();if(t.type==1)if(e.type==1){let l=!0,r=-1e100,a=-1e100,o=-1,p=null,c=null,h=e.polygon.edges.head;for(;h!=null;){let u=h.elt,x=1e100,y=t.polygon.gverts.next;for(;y!=null;){let d=y,_=u.gnormx*d.x+u.gnormy*d.y;if(_<x&&(x=_),x-u.gprojection<=r)break;y=y.next}if(x-=u.gprojection,x>=0){l=!1;break}x>r&&(r=x,p=u,o=1),h=h.next}if(l){let u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,y=1e100,d=e.polygon.gverts.next;for(;d!=null;){let _=d,f=x.gnormx*_.x+x.gnormy*_.y;if(f<y&&(y=f),y-x.gprojection<=r)break;d=d.next}if(y-=x.gprojection,y>=0){l=!1;break}y>r&&(r=y,c=x,o=2),u=u.next}if(l){let x,y,d,_;o==1?(x=e.polygon,y=t.polygon,d=p,_=1):(x=t.polygon,y=e.polygon,d=c,_=-1);let f=null,z=1e100,P=y.edges.head;for(;P!=null;){let q=P.elt,R=d.gnormx*q.gnormx+d.gnormy*q.gnormy;R<z&&(z=R,f=q),P=P.next}let k=f.gp0.x,m=f.gp0.y,b=f.gp1.x,C=f.gp1.y,v=b-k,w=C-m,O=d.gnormy*k-d.gnormx*m,E=d.gnormy*b-d.gnormx*C,M=1/(E-O),N=(-d.tp1-O)*M;if(N>i.Config.epsilon){let q=N;k+=v*q,m+=w*q}let Z=(-d.tp0-E)*M;if(Z<-i.Config.epsilon){let q=Z;b+=v*q,C+=w*q}let S=_,V=d.gnormx*S,D=d.gnormy*S;n.lnormx=d.lnormx,n.lnormy=d.lnormy,n.lproj=d.lprojection,n.radius=0,n.rev=s!=(_==-1),n.ptype=n.rev?1:0;let T=k*d.gnormx+m*d.gnormy-d.gprojection,G=b*d.gnormx+C*d.gnormy-d.gprojection;if(T>0&&G>0)return!1;{s&&(V=-V,D=-D);let q=k-d.gnormx*T*.5,R=m-d.gnormy*T*.5,j=n.rev?1:0,A=T>0;A==null&&(A=!1);let W=null,Q=n.contacts.next;for(;Q!=null;){let K=Q;if(j==K.hash){W=K;break}Q=Q.next}if(W==null){Pe.zpp_pool==null?W=new Pe:(W=Pe.zpp_pool,Pe.zpp_pool=W.next,W.next=null);let K=W.inner;K.jnAcc=K.jtAcc=0,W.hash=j,W.fresh=!0,W.arbiter=n,n.jrAcc=0;let ie=n.contacts;W._inuse=!0;let re=W;re.next=ie.next,ie.next=re,ie.modified=!0,ie.length++,n.innards.add(K)}else W.fresh=!1;W.px=q,W.py=R,n.nx=V,n.ny=D,W.dist=T,W.stamp=n.stamp,W.posOnly=A;let Y=W,X=1;k-=y.body.posx*X,m-=y.body.posy*X,Y.inner.lr1x=k*y.body.axisy+m*y.body.axisx,Y.inner.lr1y=m*y.body.axisy-k*y.body.axisx;let ee=b-d.gnormx*G*.5,J=C-d.gnormy*G*.5,L=n.rev?0:1,F=G>0;F==null&&(F=!1);let I=null,U=n.contacts.next;for(;U!=null;){let K=U;if(L==K.hash){I=K;break}U=U.next}if(I==null){Pe.zpp_pool==null?I=new Pe:(I=Pe.zpp_pool,Pe.zpp_pool=I.next,I.next=null);let K=I.inner;K.jnAcc=K.jtAcc=0,I.hash=L,I.fresh=!0,I.arbiter=n,n.jrAcc=0;let ie=n.contacts;I._inuse=!0;let re=I;re.next=ie.next,ie.next=re,ie.modified=!0,ie.length++,n.innards.add(K)}else I.fresh=!1;I.px=ee,I.py=J,n.nx=V,n.ny=D,I.dist=G,I.stamp=n.stamp,I.posOnly=F,Y=I;let $=1;return b-=y.body.posx*$,C-=y.body.posy*$,Y.inner.lr1x=b*y.body.axisy+C*y.body.axisx,Y.inner.lr1y=C*y.body.axisy-b*y.body.axisx,o==1?(n.__ref_edge1=d,n.__ref_edge2=f):(n.__ref_edge2=d,n.__ref_edge1=f),!0}}else return!1}else return!1}else{let l=-1e100,r=-1e100,a=!0,o=null,p=null,c=t.polygon.gverts.next,h=t.polygon.edges.head;for(;h!=null;){let u=h.elt,x=u.gnormx*e.circle.worldCOMx+u.gnormy*e.circle.worldCOMy-u.gprojection-e.circle.radius;if(x>0){a=!1;break}x>l&&(l=x,o=u,p=c),c=c.next,h=h.next}if(a){let u=p,x=p.next==null?t.polygon.gverts.next:p.next,y=e.circle.worldCOMy*o.gnormx-e.circle.worldCOMx*o.gnormy;if(y<=u.y*o.gnormx-u.x*o.gnormy){let d=e.circle.radius,_=u.x-e.circle.worldCOMx,f=u.y-e.circle.worldCOMy,z=_*_+f*f,P;if(z>d*d)P=null;else if(z<i.Config.epsilon*i.Config.epsilon){let k=e.circle.worldCOMx,m=e.circle.worldCOMy,b=null,C=n.contacts.next;for(;C!=null;){let v=C;if(v.hash==0){b=v;break}C=C.next}if(b==null){Pe.zpp_pool==null?b=new Pe:(b=Pe.zpp_pool,Pe.zpp_pool=b.next,b.next=null);let v=b.inner;v.jnAcc=v.jtAcc=0,b.hash=0,b.fresh=!0,b.arbiter=n,n.jrAcc=0;let w=n.contacts;b._inuse=!0;let O=b;O.next=w.next,w.next=O,w.modified=!0,w.length++,n.innards.add(v)}else b.fresh=!1;b.px=k,b.py=m,n.nx=1,n.ny=0,b.dist=-d,b.stamp=n.stamp,b.posOnly=!1,P=b}else{let k=1/Math.sqrt(z),m=k<i.Config.epsilon?1e100:1/k,b=.5+(e.circle.radius-.5*d)*k;if(s){let C=e.circle.worldCOMx+_*b,v=e.circle.worldCOMy+f*b,w=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){w=E;break}O=O.next}if(w==null){Pe.zpp_pool==null?w=new Pe:(w=Pe.zpp_pool,Pe.zpp_pool=w.next,w.next=null);let E=w.inner;E.jnAcc=E.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let M=n.contacts;w._inuse=!0;let N=w;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else w.fresh=!1;w.px=C,w.py=v,n.nx=-_*k,n.ny=-f*k,w.dist=m-d,w.stamp=n.stamp,w.posOnly=!1,P=w}else{let C=e.circle.worldCOMx+_*b,v=e.circle.worldCOMy+f*b,w=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){w=E;break}O=O.next}if(w==null){Pe.zpp_pool==null?w=new Pe:(w=Pe.zpp_pool,Pe.zpp_pool=w.next,w.next=null);let E=w.inner;E.jnAcc=E.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let M=n.contacts;w._inuse=!0;let N=w;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else w.fresh=!1;w.px=C,w.py=v,n.nx=_*k,n.ny=f*k,w.dist=m-d,w.stamp=n.stamp,w.posOnly=!1,P=w}}if(P!=null){let k=P.inner;n.ptype=2;let m=u.x-t.polygon.body.posx,b=u.y-t.polygon.body.posy;n.__ref_edge1=o,n.__ref_vertex=-1,s?(k.lr1x=m*t.polygon.body.axisy+b*t.polygon.body.axisx,k.lr1y=b*t.polygon.body.axisy-m*t.polygon.body.axisx,k.lr2x=e.circle.localCOMx,k.lr2y=e.circle.localCOMy):(k.lr2x=m*t.polygon.body.axisy+b*t.polygon.body.axisx,k.lr2y=b*t.polygon.body.axisy-m*t.polygon.body.axisx,k.lr1x=e.circle.localCOMx,k.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return P!=null}else if(y>=x.y*o.gnormx-x.x*o.gnormy){let d=e.circle.radius,_=x.x-e.circle.worldCOMx,f=x.y-e.circle.worldCOMy,z=_*_+f*f,P;if(z>d*d)P=null;else if(z<i.Config.epsilon*i.Config.epsilon){let k=e.circle.worldCOMx,m=e.circle.worldCOMy,b=null,C=n.contacts.next;for(;C!=null;){let v=C;if(v.hash==0){b=v;break}C=C.next}if(b==null){Pe.zpp_pool==null?b=new Pe:(b=Pe.zpp_pool,Pe.zpp_pool=b.next,b.next=null);let v=b.inner;v.jnAcc=v.jtAcc=0,b.hash=0,b.fresh=!0,b.arbiter=n,n.jrAcc=0;let w=n.contacts;b._inuse=!0;let O=b;O.next=w.next,w.next=O,w.modified=!0,w.length++,n.innards.add(v)}else b.fresh=!1;b.px=k,b.py=m,n.nx=1,n.ny=0,b.dist=-d,b.stamp=n.stamp,b.posOnly=!1,P=b}else{let k=1/Math.sqrt(z),m=k<i.Config.epsilon?1e100:1/k,b=.5+(e.circle.radius-.5*d)*k;if(s){let C=e.circle.worldCOMx+_*b,v=e.circle.worldCOMy+f*b,w=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){w=E;break}O=O.next}if(w==null){Pe.zpp_pool==null?w=new Pe:(w=Pe.zpp_pool,Pe.zpp_pool=w.next,w.next=null);let E=w.inner;E.jnAcc=E.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let M=n.contacts;w._inuse=!0;let N=w;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else w.fresh=!1;w.px=C,w.py=v,n.nx=-_*k,n.ny=-f*k,w.dist=m-d,w.stamp=n.stamp,w.posOnly=!1,P=w}else{let C=e.circle.worldCOMx+_*b,v=e.circle.worldCOMy+f*b,w=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){w=E;break}O=O.next}if(w==null){Pe.zpp_pool==null?w=new Pe:(w=Pe.zpp_pool,Pe.zpp_pool=w.next,w.next=null);let E=w.inner;E.jnAcc=E.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let M=n.contacts;w._inuse=!0;let N=w;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else w.fresh=!1;w.px=C,w.py=v,n.nx=_*k,n.ny=f*k,w.dist=m-d,w.stamp=n.stamp,w.posOnly=!1,P=w}}if(P!=null){let k=P.inner;n.ptype=2;let m=x.x-t.polygon.body.posx,b=x.y-t.polygon.body.posy;n.__ref_edge1=o,n.__ref_vertex=1,s?(k.lr1x=m*t.polygon.body.axisy+b*t.polygon.body.axisx,k.lr1y=b*t.polygon.body.axisy-m*t.polygon.body.axisx,k.lr2x=e.circle.localCOMx,k.lr2y=e.circle.localCOMy):(k.lr2x=m*t.polygon.body.axisy+b*t.polygon.body.axisx,k.lr2y=b*t.polygon.body.axisy-m*t.polygon.body.axisx,k.lr1x=e.circle.localCOMx,k.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return P!=null}else{let d=e.circle.radius+l*.5,_=o.gnormx*d,f=o.gnormy*d,z=e.circle.worldCOMx-_,P=e.circle.worldCOMy-f,k;if(s){let m=o.gnormx,b=o.gnormy,C=null,v=n.contacts.next;for(;v!=null;){let w=v;if(w.hash==0){C=w;break}v=v.next}if(C==null){Pe.zpp_pool==null?C=new Pe:(C=Pe.zpp_pool,Pe.zpp_pool=C.next,C.next=null);let w=C.inner;w.jnAcc=w.jtAcc=0,C.hash=0,C.fresh=!0,C.arbiter=n,n.jrAcc=0;let O=n.contacts;C._inuse=!0;let E=C;E.next=O.next,O.next=E,O.modified=!0,O.length++,n.innards.add(w)}else C.fresh=!1;C.px=z,C.py=P,n.nx=m,n.ny=b,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,k=C}else{let m=-o.gnormx,b=-o.gnormy,C=null,v=n.contacts.next;for(;v!=null;){let w=v;if(w.hash==0){C=w;break}v=v.next}if(C==null){Pe.zpp_pool==null?C=new Pe:(C=Pe.zpp_pool,Pe.zpp_pool=C.next,C.next=null);let w=C.inner;w.jnAcc=w.jtAcc=0,C.hash=0,C.fresh=!0,C.arbiter=n,n.jrAcc=0;let O=n.contacts;C._inuse=!0;let E=C;E.next=O.next,O.next=E,O.modified=!0,O.length++,n.innards.add(w)}else C.fresh=!1;C.px=z,C.py=P,n.nx=m,n.ny=b,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,k=C}return n.ptype=s?0:1,n.lnormx=o.lnormx,n.lnormy=o.lnormy,n.rev=!s,n.lproj=o.lprojection,n.radius=e.circle.radius,k.inner.lr1x=e.circle.localCOMx,k.inner.lr1y=e.circle.localCOMy,n.__ref_edge1=o,n.__ref_vertex=0,!0}}else return!1}else{let l=e.circle.radius+t.circle.radius,r=t.circle.worldCOMx-e.circle.worldCOMx,a=t.circle.worldCOMy-e.circle.worldCOMy,o=r*r+a*a,p;if(o>l*l)p=null;else if(o<i.Config.epsilon*i.Config.epsilon){let c=e.circle.worldCOMx,h=e.circle.worldCOMy,u=null,x=n.contacts.next;for(;x!=null;){let y=x;if(y.hash==0){u=y;break}x=x.next}if(u==null){Pe.zpp_pool==null?u=new Pe:(u=Pe.zpp_pool,Pe.zpp_pool=u.next,u.next=null);let y=u.inner;y.jnAcc=y.jtAcc=0,u.hash=0,u.fresh=!0,u.arbiter=n,n.jrAcc=0;let d=n.contacts;u._inuse=!0;let _=u;_.next=d.next,d.next=_,d.modified=!0,d.length++,n.innards.add(y)}else u.fresh=!1;u.px=c,u.py=h,n.nx=1,n.ny=0,u.dist=-l,u.stamp=n.stamp,u.posOnly=!1,p=u}else{let c=1/Math.sqrt(o),h=c<i.Config.epsilon?1e100:1/c,u=.5+(e.circle.radius-.5*l)*c;if(s){let x=e.circle.worldCOMx+r*u,y=e.circle.worldCOMy+a*u,d=null,_=n.contacts.next;for(;_!=null;){let f=_;if(f.hash==0){d=f;break}_=_.next}if(d==null){Pe.zpp_pool==null?d=new Pe:(d=Pe.zpp_pool,Pe.zpp_pool=d.next,d.next=null);let f=d.inner;f.jnAcc=f.jtAcc=0,d.hash=0,d.fresh=!0,d.arbiter=n,n.jrAcc=0;let z=n.contacts;d._inuse=!0;let P=d;P.next=z.next,z.next=P,z.modified=!0,z.length++,n.innards.add(f)}else d.fresh=!1;d.px=x,d.py=y,n.nx=-r*c,n.ny=-a*c,d.dist=h-l,d.stamp=n.stamp,d.posOnly=!1,p=d}else{let x=e.circle.worldCOMx+r*u,y=e.circle.worldCOMy+a*u,d=null,_=n.contacts.next;for(;_!=null;){let f=_;if(f.hash==0){d=f;break}_=_.next}if(d==null){Pe.zpp_pool==null?d=new Pe:(d=Pe.zpp_pool,Pe.zpp_pool=d.next,d.next=null);let f=d.inner;f.jnAcc=f.jtAcc=0,d.hash=0,d.fresh=!0,d.arbiter=n,n.jrAcc=0;let z=n.contacts;d._inuse=!0;let P=d;P.next=z.next,z.next=P,z.modified=!0,z.length++,n.innards.add(f)}else d.fresh=!1;d.px=x,d.py=y,n.nx=r*c,n.ny=a*c,d.dist=h-l,d.stamp=n.stamp,d.posOnly=!1,p=d}}if(p!=null){let c=p.inner;return s?(c.lr1x=t.circle.localCOMx,c.lr1y=t.circle.localCOMy,c.lr2x=e.circle.localCOMx,c.lr2y=e.circle.localCOMy):(c.lr1x=e.circle.localCOMx,c.lr1y=e.circle.localCOMy,c.lr2x=t.circle.localCOMx,c.lr2y=t.circle.localCOMy),n.radius=e.circle.radius+t.circle.radius,n.ptype=2,!0}else return!1}}static testCollide_safe(e,t){let n=me();if(t.type==0){let s=e;e=t,t=s}return Ce.testCollide(e,t)}static testCollide(e,t){let n=me();if(t.type==1)if(e.type==1){let s=!0,i=e.polygon.edges.head;for(;i!=null;){let l=i.elt,r=1e100,a=t.polygon.gverts.next;for(;a!=null;){let o=a,p=l.gnormx*o.x+l.gnormy*o.y;p<r&&(r=p),a=a.next}if(r-=l.gprojection,r>0){s=!1;break}i=i.next}if(s){let l=t.polygon.edges.head;for(;l!=null;){let r=l.elt,a=1e100,o=e.polygon.gverts.next;for(;o!=null;){let p=o,c=r.gnormx*p.x+r.gnormy*p.y;c<a&&(a=c),o=o.next}if(a-=r.gprojection,a>0){s=!1;break}l=l.next}return s}else return!1}else{let s=null,i=null,l=!0,r=-1e100,a=t.polygon.gverts.next,o=t.polygon.edges.head;for(;o!=null;){let p=o.elt,c=p.gnormx*e.circle.worldCOMx+p.gnormy*e.circle.worldCOMy-p.gprojection-e.circle.radius;if(c>0){l=!1;break}c>r&&(r=c,s=p,i=a),a=a.next,o=o.next}if(l){let p=i,c=i.next==null?t.polygon.gverts.next:i.next,h=e.circle.worldCOMy*s.gnormx-e.circle.worldCOMx*s.gnormy;if(h<=p.y*s.gnormx-p.x*s.gnormy){let u=e.circle.radius,x=p.x-e.circle.worldCOMx,y=p.y-e.circle.worldCOMy;return x*x+y*y<=u*u}else if(h>=c.y*s.gnormx-c.x*s.gnormy){let u=e.circle.radius,x=c.x-e.circle.worldCOMx,y=c.y-e.circle.worldCOMy;return x*x+y*y<=u*u}else return!0}else return!1}else{let s=e.circle.radius+t.circle.radius,i=t.circle.worldCOMx-e.circle.worldCOMx,l=t.circle.worldCOMy-e.circle.worldCOMy;return i*i+l*l<=s*s}}static flowCollide(e,t,n){let s=me();if(t.type==1)if(e.type==1){let i=[],l=[],r=!0,a=!0,o=e.polygon.edges.head;for(;o!=null;){let p=o.elt,c=1e100,h=0,u=t.polygon.gverts.next;for(;u!=null;){let x=u,y=p.gnormx*x.x+p.gnormy*x.y;y<c&&(c=y),y>=p.gprojection+s.Config.epsilon&&(l[h]=!0,a=!1),++h,u=u.next}if(c-=p.gprojection,c>0){r=!1;break}o=o.next}if(a){let p=t.polygon;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=!1,p.zip_localCOM){if(p.zip_localCOM=!1,p.type==1){let h=p.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let u=1;h.localCOMx+=h.lverts.next.next.x*u,h.localCOMy+=h.lverts.next.next.y*u;let x=.5;h.localCOMx*=x,h.localCOMy*=x}else{h.localCOMx=0,h.localCOMy=0;let u=0,x=h.lverts.next,y=x;x=x.next;let d=x;for(x=x.next;x!=null;){let m=x;u+=d.x*(m.y-y.y);let b=m.y*d.x-m.x*d.y;h.localCOMx+=(d.x+m.x)*b,h.localCOMy+=(d.y+m.y)*b,y=d,d=m,x=x.next}x=h.lverts.next;let _=x;u+=d.x*(_.y-y.y);let f=_.y*d.x-_.x*d.y;h.localCOMx+=(d.x+_.x)*f,h.localCOMy+=(d.y+_.y)*f,y=d,d=_,x=x.next;let z=x;u+=d.x*(z.y-y.y);let P=z.y*d.x-z.x*d.y;h.localCOMx+=(d.x+z.x)*P,h.localCOMy+=(d.y+z.y)*P,u=1/(3*u);let k=u;h.localCOMx*=k,h.localCOMy*=k}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let c=p.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else if(r){a=!0;let p=t.polygon.edges.head;for(;p!=null;){let c=p.elt,h=1e100,u=0,x=e.polygon.gverts.next;for(;x!=null;){let y=x,d=c.gnormx*y.x+c.gnormy*y.y;d<h&&(h=d),d>=c.gprojection+s.Config.epsilon&&(i[u]=!0,a=!1),++u,x=x.next}if(h-=c.gprojection,h>0){r=!1;break}p=p.next}if(a){let c=e.polygon;if(c.zip_worldCOM&&c.body!=null){if(c.zip_worldCOM=!1,c.zip_localCOM){if(c.zip_localCOM=!1,c.type==1){let u=c.polygon;if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(u.lverts.next.next==null)u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;else if(u.lverts.next.next.next==null){u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;let x=1;u.localCOMx+=u.lverts.next.next.x*x,u.localCOMy+=u.lverts.next.next.y*x;let y=.5;u.localCOMx*=y,u.localCOMy*=y}else{u.localCOMx=0,u.localCOMy=0;let x=0,y=u.lverts.next,d=y;y=y.next;let _=y;for(y=y.next;y!=null;){let b=y;x+=_.x*(b.y-d.y);let C=b.y*_.x-b.x*_.y;u.localCOMx+=(_.x+b.x)*C,u.localCOMy+=(_.y+b.y)*C,d=_,_=b,y=y.next}y=u.lverts.next;let f=y;x+=_.x*(f.y-d.y);let z=f.y*_.x-f.x*_.y;u.localCOMx+=(_.x+f.x)*z,u.localCOMy+=(_.y+f.y)*z,d=_,_=f,y=y.next;let P=y;x+=_.x*(P.y-d.y);let k=P.y*_.x-P.x*_.y;u.localCOMx+=(_.x+P.x)*k,u.localCOMy+=(_.y+P.y)*k,x=1/(3*x);let m=x;u.localCOMx*=m,u.localCOMy*=m}}c.wrap_localCOM!=null&&(c.wrap_localCOM.zpp_inner.x=c.localCOMx,c.wrap_localCOM.zpp_inner.y=c.localCOMy)}let h=c.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.worldCOMx=c.body.posx+(c.body.axisy*c.localCOMx-c.body.axisx*c.localCOMy),c.worldCOMy=c.body.posy+(c.localCOMx*c.body.axisx+c.localCOMy*c.body.axisy)}return n.overlap=e.polygon.area,n.centroidx=e.polygon.worldCOMx,n.centroidy=e.polygon.worldCOMy,!0}else if(r){for(;Ce.flowpoly.head!=null;){let P=Ce.flowpoly.pop_unsafe();if(!P._inuse){let k=P;k.outer!=null&&(k.outer.zpp_inner=null,k.outer=null),k._isimmutable=null,k._validate=null,k._invalidate=null,k.next=le.zpp_pool,le.zpp_pool=k}}let c=null,h=!1,u=e.polygon.gverts.next,x=0,y=t.polygon.gverts.next,d=0,_=0,f=t.polygon.edgeCnt;for(;_<f;){let P=_++;if(l[P])y=y.next;else{d=P;break}}if(y==null){y=t.polygon.gverts.next,h=!0;let P=0,k=e.polygon.edgeCnt;for(;P<k;){let m=P++;if(i[m])u=u.next;else{x=m;break}}u==null?u=e.polygon.gverts.next:(Ce.flowpoly.add(u),c=Ce.flowpoly.head.elt)}else Ce.flowpoly.add(y),c=Ce.flowpoly.head.elt;let z=1;if(Ce.flowpoly.head==null){let P=!0,k=e.polygon.gverts.next,m=k,b=k.next;for(;b!=null;){let C=b,v=2,w=!0,O=t.polygon.gverts.next,E=O,M=O.next;for(;M!=null;){let N=M,Z=0,S=m.x-E.x,V=m.y-E.y,D=C.x-m.x,T=C.y-m.y,G=N.x-E.x,q=N.y-E.y,R=T*G-D*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let A=(q*S-G*V)*R;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let W=(T*S-D*V)*R;W>s.Config.epsilon&&W<1-s.Config.epsilon?(Z=A,j=!0):j=!1}else j=!1}else j=!1;j&&Z<v&&(v=Z,y=O),O=M,E=N,M=M.next}if(w)for(;;){M=t.polygon.gverts.next;let N=M,Z=0,S=m.x-E.x,V=m.y-E.y,D=C.x-m.x,T=C.y-m.y,G=N.x-E.x,q=N.y-E.y,R=T*G-D*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let A=(q*S-G*V)*R;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let W=(T*S-D*V)*R;W>s.Config.epsilon&&W<1-s.Config.epsilon?(Z=A,j=!0):j=!1}else j=!1}else j=!1;j&&Z<v&&(v=Z,y=O);break}if(v!=2){let N=v,Z=m.x+(C.x-m.x)*N,S=m.y+(C.y-m.y)*N,V;le.zpp_pool==null?V=new le:(V=le.zpp_pool,le.zpp_pool=V.next,V.next=null),V.weak=!1,V._immutable=!1,V.x=Z,V.y=S,c=V,Ce.flowpoly.add(c),h=!0,u=k,P=!1;break}k=b,m=C,b=b.next}if(P)for(;;){b=e.polygon.gverts.next;let C=b,v=2,w=!0,O=t.polygon.gverts.next,E=O,M=O.next;for(;M!=null;){let N=M,Z=0,S=m.x-E.x,V=m.y-E.y,D=C.x-m.x,T=C.y-m.y,G=N.x-E.x,q=N.y-E.y,R=T*G-D*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let A=(q*S-G*V)*R;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let W=(T*S-D*V)*R;W>s.Config.epsilon&&W<1-s.Config.epsilon?(Z=A,j=!0):j=!1}else j=!1}else j=!1;j&&Z<v&&(v=Z,y=O),O=M,E=N,M=M.next}if(w)for(;;){M=t.polygon.gverts.next;let N=M,Z=0,S=m.x-E.x,V=m.y-E.y,D=C.x-m.x,T=C.y-m.y,G=N.x-E.x,q=N.y-E.y,R=T*G-D*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let A=(q*S-G*V)*R;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let W=(T*S-D*V)*R;W>s.Config.epsilon&&W<1-s.Config.epsilon?(Z=A,j=!0):j=!1}else j=!1}else j=!1;j&&Z<v&&(v=Z,y=O);break}if(v!=2){let N=v,Z=m.x+(C.x-m.x)*N,S=m.y+(C.y-m.y)*N,V;le.zpp_pool==null?V=new le:(V=le.zpp_pool,le.zpp_pool=V.next,V.next=null),V.weak=!1,V._immutable=!1,V.x=Z,V.y=S,c=V,Ce.flowpoly.add(c),h=!0,u=k;break}break}z=2}for(;;)if(h)if(u=u.next,++x,u==null&&(u=e.polygon.gverts.next,x=0),i[x]){let P=Ce.flowpoly.head.elt,k=u,m=y,b=y.next;b==null&&(b=t.polygon.gverts.next);let C=-1,v=null,w=0,O=0,E=b,M=b;for(;;){let j=M,A=0,W=m.x-P.x,Q=m.y-P.y,Y=j.x-m.x,X=j.y-m.y,ee=k.x-P.x,J=k.y-P.y,L=X*ee-Y*J,F;if(L*L>s.Config.epsilon*s.Config.epsilon){L=1/L;let I=(J*W-ee*Q)*L;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*W-Y*Q)*L;U>s.Config.epsilon&&U<1-s.Config.epsilon?(A=I,F=!0):F=!1}else F=!1}else F=!1;if(F&&A>=C)if(v=y,w=d,++O==z){C=A,M=E;break}else C=A;m=j,y=M,++d,d>=t.polygon.edgeCnt&&(d=0),M=M.next,M==null&&(M=t.polygon.gverts.next);break}for(;M!=E;){let j=M,A=0,W=m.x-P.x,Q=m.y-P.y,Y=j.x-m.x,X=j.y-m.y,ee=k.x-P.x,J=k.y-P.y,L=X*ee-Y*J,F;if(L*L>s.Config.epsilon*s.Config.epsilon){L=1/L;let I=(J*W-ee*Q)*L;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*W-Y*Q)*L;U>s.Config.epsilon&&U<1-s.Config.epsilon?(A=I,F=!0):F=!1}else F=!1}else F=!1;if(F&&A>=C)if(v=y,w=d,++O==z){C=A;break}else C=A;m=j,y=M,++d,d>=t.polygon.edgeCnt&&(d=0),M=M.next,M==null&&(M=t.polygon.gverts.next)}if(v==null)break;let N=v,Z=v.next;Z==null&&(Z=t.polygon.gverts.next);let S=Z,V=C,D=N.x+(S.x-N.x)*V,T=N.y+(S.y-N.y)*V,G;if(c!=null){let j=D-c.x,A=T-c.y;G=j*j+A*A<s.Config.epsilon}else G=!1;if(G)break;let q=Ce.flowpoly,R;le.zpp_pool==null?R=new le:(R=le.zpp_pool,le.zpp_pool=R.next,R.next=null),R.weak=!1,R._immutable=!1,R.x=D,R.y=T,q.add(R),c==null&&(c=Ce.flowpoly.head.elt),y=v,d=w,h=!h,z=2}else{let P=u,k;if(c!=null){let m=P.x-c.x,b=P.y-c.y;k=m*m+b*b<s.Config.epsilon}else k=!1;if(k)break;Ce.flowpoly.add(P),c==null&&(c=Ce.flowpoly.head.elt),z=1}else if(y=y.next,++d,y==null&&(y=t.polygon.gverts.next,d=0),l[d]){let P=Ce.flowpoly.head.elt,k=y,m=u,b=u.next;b==null&&(b=e.polygon.gverts.next);let C=-1,v=null,w=0,O=0,E=b,M=b;for(;;){let j=M,A=0,W=m.x-P.x,Q=m.y-P.y,Y=j.x-m.x,X=j.y-m.y,ee=k.x-P.x,J=k.y-P.y,L=X*ee-Y*J,F;if(L*L>s.Config.epsilon*s.Config.epsilon){L=1/L;let I=(J*W-ee*Q)*L;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*W-Y*Q)*L;U>s.Config.epsilon&&U<1-s.Config.epsilon?(A=I,F=!0):F=!1}else F=!1}else F=!1;if(F&&A>=C)if(v=u,w=x,++O==z){C=A,M=E;break}else C=A;m=j,u=M,++x,x>=e.polygon.edgeCnt&&(x=0),M=M.next,M==null&&(M=e.polygon.gverts.next);break}for(;M!=E;){let j=M,A=0,W=m.x-P.x,Q=m.y-P.y,Y=j.x-m.x,X=j.y-m.y,ee=k.x-P.x,J=k.y-P.y,L=X*ee-Y*J,F;if(L*L>s.Config.epsilon*s.Config.epsilon){L=1/L;let I=(J*W-ee*Q)*L;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*W-Y*Q)*L;U>s.Config.epsilon&&U<1-s.Config.epsilon?(A=I,F=!0):F=!1}else F=!1}else F=!1;if(F&&A>=C)if(v=u,w=x,++O==z){C=A;break}else C=A;m=j,u=M,++x,x>=e.polygon.edgeCnt&&(x=0),M=M.next,M==null&&(M=e.polygon.gverts.next)}if(v==null)break;let N=v,Z=v.next;Z==null&&(Z=e.polygon.gverts.next);let S=Z,V=C,D=N.x+(S.x-N.x)*V,T=N.y+(S.y-N.y)*V,G;if(c!=null){let j=D-c.x,A=T-c.y;G=j*j+A*A<s.Config.epsilon}else G=!1;if(G)break;let q=Ce.flowpoly,R;le.zpp_pool==null?R=new le:(R=le.zpp_pool,le.zpp_pool=R.next,R.next=null),R.weak=!1,R._immutable=!1,R.x=D,R.y=T,q.add(R),c==null&&(c=Ce.flowpoly.head.elt),u=v,x=w,h=!h,z=2}else{let P=y,k;if(c!=null){let m=P.x-c.x,b=P.y-c.y;k=m*m+b*b<s.Config.epsilon}else k=!1;if(k)break;Ce.flowpoly.add(P),c==null&&(c=Ce.flowpoly.head.elt),z=1}if(Ce.flowpoly.head!=null&&Ce.flowpoly.head.next!=null&&Ce.flowpoly.head.next.next!=null){let P=0,k=0,m=0,b=Ce.flowpoly.head,C=b.elt;b=b.next;let v=b.elt;for(b=b.next;b!=null;){let S=b.elt;P+=v.x*(S.y-C.y);let V=S.y*v.x-S.x*v.y;k+=(v.x+S.x)*V,m+=(v.y+S.y)*V,C=v,v=S,b=b.next}b=Ce.flowpoly.head;let w=b.elt;P+=v.x*(w.y-C.y);let O=w.y*v.x-w.x*v.y;k+=(v.x+w.x)*O,m+=(v.y+w.y)*O,C=v,v=w,b=b.next;let E=b.elt;P+=v.x*(E.y-C.y);let M=E.y*v.x-E.x*v.y;k+=(v.x+E.x)*M,m+=(v.y+E.y)*M,P*=.5;let Z=1/(6*P);return k*=Z,m*=Z,n.overlap=-P,n.centroidx=k,n.centroidy=m,!0}else return!1}else return!1}else return!1}else{let i=[],l=!0,r=null,a=null,o=-1e100,p=!0,c=t.polygon.gverts.next,h=0,u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,y=x.gnormx*e.circle.worldCOMx+x.gnormy*e.circle.worldCOMy;if(y>x.gprojection+e.circle.radius){p=!1;break}else y+e.circle.radius>x.gprojection+s.Config.epsilon&&(l=!1,i[h]=!0);y-=x.gprojection+e.circle.radius,y>o&&(o=y,r=x,a=c),c=c.next,++h,u=u.next}if(p){if(l)return n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0;{let x=a,y=a.next==null?t.polygon.gverts.next:a.next,d=e.circle.worldCOMy*r.gnormx-e.circle.worldCOMx*r.gnormy,_;if(d<=x.y*r.gnormx-x.x*r.gnormy){let f=e.circle.radius,z=x.x-e.circle.worldCOMx,P=x.y-e.circle.worldCOMy;_=z*z+P*P<=f*f}else if(d>=y.y*r.gnormx-y.x*r.gnormy){let f=e.circle.radius,z=y.x-e.circle.worldCOMx,P=y.y-e.circle.worldCOMy;_=z*z+P*P<=f*f}else _=!0;if(_){let f=[],z=0,P=!0,k=null,m=0,b=t.polygon.gverts.next;for(;b!=null;){let C=b,v=C.x-e.circle.worldCOMx,w=C.y-e.circle.worldCOMy,O=v*v+w*w;(f[z]=O<=e.circle.radius*e.circle.radius)?(m=z,k=b):P=!1,++z,b=b.next}if(P){let C=t.polygon;if(C.zip_worldCOM&&C.body!=null){if(C.zip_worldCOM=!1,C.zip_localCOM){if(C.zip_localCOM=!1,C.type==1){let w=C.polygon;if(w.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(w.lverts.next.next==null)w.localCOMx=w.lverts.next.x,w.localCOMy=w.lverts.next.y;else if(w.lverts.next.next.next==null){w.localCOMx=w.lverts.next.x,w.localCOMy=w.lverts.next.y;let O=1;w.localCOMx+=w.lverts.next.next.x*O,w.localCOMy+=w.lverts.next.next.y*O;let E=.5;w.localCOMx*=E,w.localCOMy*=E}else{w.localCOMx=0,w.localCOMy=0;let O=0,E=w.lverts.next,M=E;E=E.next;let N=E;for(E=E.next;E!=null;){let G=E;O+=N.x*(G.y-M.y);let q=G.y*N.x-G.x*N.y;w.localCOMx+=(N.x+G.x)*q,w.localCOMy+=(N.y+G.y)*q,M=N,N=G,E=E.next}E=w.lverts.next;let Z=E;O+=N.x*(Z.y-M.y);let S=Z.y*N.x-Z.x*N.y;w.localCOMx+=(N.x+Z.x)*S,w.localCOMy+=(N.y+Z.y)*S,M=N,N=Z,E=E.next;let V=E;O+=N.x*(V.y-M.y);let D=V.y*N.x-V.x*N.y;w.localCOMx+=(N.x+V.x)*D,w.localCOMy+=(N.y+V.y)*D,O=1/(3*O);let T=O;w.localCOMx*=T,w.localCOMy*=T}}C.wrap_localCOM!=null&&(C.wrap_localCOM.zpp_inner.x=C.localCOMx,C.wrap_localCOM.zpp_inner.y=C.localCOMy)}let v=C.body;v.zip_axis&&(v.zip_axis=!1,v.axisx=Math.sin(v.rot),v.axisy=Math.cos(v.rot)),C.worldCOMx=C.body.posx+(C.body.axisy*C.localCOMx-C.body.axisx*C.localCOMy),C.worldCOMy=C.body.posy+(C.localCOMx*C.body.axisx+C.localCOMy*C.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else{for(;Ce.flowpoly.head!=null;){let w=Ce.flowpoly.pop_unsafe();if(!w._inuse){let O=w;O.outer!=null&&(O.outer.zpp_inner=null,O.outer=null),O._isimmutable=null,O._validate=null,O._invalidate=null,O.next=le.zpp_pool,le.zpp_pool=O}}Ce.flowsegs.clear();let C=null,v=1;for(k==null?(k=t.polygon.gverts.next,v=2):(C=k,Ce.flowpoly.add(C));v!=0;)if(v==1)if(k=k.next,k==null&&(k=t.polygon.gverts.next),++m,m>=t.polygon.edgeCnt&&(m=0),f[m]){let w=C.x-k.x,O=C.y-k.y;if(w*w+O*O<s.Config.epsilon)break;Ce.flowpoly.add(k)}else{let w=Ce.flowpoly.head.elt,O=k,E=O.x-w.x,M=O.y-w.y,N=w.x-e.circle.worldCOMx,Z=w.y-e.circle.worldCOMy,S=E*E+M*M,V=2*(N*E+Z*M),D=N*N+Z*Z-e.circle.radius*e.circle.radius,T=Math.sqrt(V*V-4*S*D);S=1/(2*S);let G=(-V-T)*S,q=G<s.Config.epsilon?(-V+T)*S:G,R=0,j=0,A=q;R=w.x+(O.x-w.x)*A,j=w.y+(O.y-w.y)*A;let W=C.x-R,Q=C.y-j;if(W*W+Q*Q<s.Config.epsilon)break;let Y=Ce.flowpoly,X;le.zpp_pool==null?X=new le:(X=le.zpp_pool,le.zpp_pool=X.next,X.next=null),X.weak=!1,X._immutable=!1,X.x=R,X.y=j,Y.add(X),v=2}else if(v==2){let w=k.next;w==null&&(w=t.polygon.gverts.next);let O=k;v=0;let E=w,M=w;for(;;){let N=M,Z=m+1;if(Z==t.polygon.edgeCnt&&(Z=0),i[m])if(f[Z]){let S=N.x-O.x,V=N.y-O.y,D=O.x-e.circle.worldCOMx,T=O.y-e.circle.worldCOMy,G=S*S+V*V,q=2*(D*S+T*V),R=D*D+T*T-e.circle.radius*e.circle.radius,j=Math.sqrt(q*q-4*G*R);G=1/(2*G);let A=(-q-j)*G,W=A<s.Config.epsilon?(-q+j)*G:A,Q=0,Y=0,X=W;Q=O.x+(N.x-O.x)*X,Y=O.y+(N.y-O.y)*X;let ee=C.x-Q,J=C.y-Y;if(ee*ee+J*J<s.Config.epsilon){v=0,M=E;break}let L;le.zpp_pool==null?L=new le:(L=le.zpp_pool,le.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=Q,L.y=Y;let F=L;Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(F),Ce.flowpoly.add(F),v=1,M=E;break}else{let S=0,V=0,D=N.x-O.x,T=N.y-O.y,G=O.x-e.circle.worldCOMx,q=O.y-e.circle.worldCOMy,R=D*D+T*T,j=2*(G*D+q*T),A=G*G+q*q-e.circle.radius*e.circle.radius,W=j*j-4*R*A,Q;if(W*W<s.Config.epsilon?(W<0?S=10:(V=-j/(2*R),S=V),Q=!1):(W=Math.sqrt(W),R=1/(2*R),S=(-j-W)*R,V=(-j+W)*R,Q=!0),S<1-s.Config.epsilon&&V>s.Config.epsilon){let Y=0,X=0,ee=S;Y=O.x+(N.x-O.x)*ee,X=O.y+(N.y-O.y)*ee;let J;if(C!=null){let I=C.x-Y,U=C.y-X;J=I*I+U*U<s.Config.epsilon}else J=!1;if(J){v=0,M=E;break}let L;le.zpp_pool==null?L=new le:(L=le.zpp_pool,le.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=Y,L.y=X;let F=L;if(Ce.flowpoly.head!=null&&(Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(F)),Ce.flowpoly.add(F),C==null&&(C=Ce.flowpoly.head.elt),Q){let I=0,U=0,$=V;I=O.x+(N.x-O.x)*$,U=O.y+(N.y-O.y)*$;let K=Ce.flowpoly,ie;le.zpp_pool==null?ie=new le:(ie=le.zpp_pool,le.zpp_pool=ie.next,ie.next=null),ie.weak=!1,ie._immutable=!1,ie.x=I,ie.y=U,K.add(ie)}}}O=N,k=M,m=Z,M=M.next,M==null&&(M=t.polygon.gverts.next);break}for(;M!=E;){let N=M,Z=m+1;if(Z==t.polygon.edgeCnt&&(Z=0),i[m])if(f[Z]){let S=N.x-O.x,V=N.y-O.y,D=O.x-e.circle.worldCOMx,T=O.y-e.circle.worldCOMy,G=S*S+V*V,q=2*(D*S+T*V),R=D*D+T*T-e.circle.radius*e.circle.radius,j=Math.sqrt(q*q-4*G*R);G=1/(2*G);let A=(-q-j)*G,W=A<s.Config.epsilon?(-q+j)*G:A,Q=0,Y=0,X=W;Q=O.x+(N.x-O.x)*X,Y=O.y+(N.y-O.y)*X;let ee=C.x-Q,J=C.y-Y;if(ee*ee+J*J<s.Config.epsilon){v=0,M=E;break}let L;le.zpp_pool==null?L=new le:(L=le.zpp_pool,le.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=Q,L.y=Y;let F=L;Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(F),Ce.flowpoly.add(F),v=1,M=E;break}else{let S=0,V=0,D=N.x-O.x,T=N.y-O.y,G=O.x-e.circle.worldCOMx,q=O.y-e.circle.worldCOMy,R=D*D+T*T,j=2*(G*D+q*T),A=G*G+q*q-e.circle.radius*e.circle.radius,W=j*j-4*R*A,Q;if(W*W<s.Config.epsilon?(W<0?S=10:(V=-j/(2*R),S=V),Q=!1):(W=Math.sqrt(W),R=1/(2*R),S=(-j-W)*R,V=(-j+W)*R,Q=!0),S<1-s.Config.epsilon&&V>s.Config.epsilon){let Y=0,X=0,ee=S;Y=O.x+(N.x-O.x)*ee,X=O.y+(N.y-O.y)*ee;let J;if(C!=null){let I=C.x-Y,U=C.y-X;J=I*I+U*U<s.Config.epsilon}else J=!1;if(J){v=0,M=E;break}let L;le.zpp_pool==null?L=new le:(L=le.zpp_pool,le.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=Y,L.y=X;let F=L;if(Ce.flowpoly.head!=null&&(Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(F)),Ce.flowpoly.add(F),C==null&&(C=Ce.flowpoly.head.elt),Q){let I=0,U=0,$=V;I=O.x+(N.x-O.x)*$,U=O.y+(N.y-O.y)*$;let K=Ce.flowpoly,ie;le.zpp_pool==null?ie=new le:(ie=le.zpp_pool,le.zpp_pool=ie.next,ie.next=null),ie.weak=!1,ie._immutable=!1,ie.x=I,ie.y=U,K.add(ie)}}}O=N,k=M,m=Z,M=M.next,M==null&&(M=t.polygon.gverts.next)}}if(Ce.flowpoly.head==null)return!1;if(Ce.flowpoly.head.next==null){let w=!0,O=t.polygon.edges.head;for(;O!=null;){let E=O.elt;if(E.gnormx*e.circle.worldCOMx+E.gnormy*e.circle.worldCOMy>E.gprojection){w=!1;break}O=O.next}return w?(n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0):!1}else{let w=0,O=0,E=0;if(Ce.flowpoly.head.next.next!=null){let N=0,Z=0,S=0;N=0;let V=Ce.flowpoly.head,D=V.elt;V=V.next;let T=V.elt;for(V=V.next;V!=null;){let Y=V.elt;N+=T.x*(Y.y-D.y);let X=Y.y*T.x-Y.x*T.y;Z+=(T.x+Y.x)*X,S+=(T.y+Y.y)*X,D=T,T=Y,V=V.next}V=Ce.flowpoly.head;let G=V.elt;N+=T.x*(G.y-D.y);let q=G.y*T.x-G.x*T.y;Z+=(T.x+G.x)*q,S+=(T.y+G.y)*q,D=T,T=G,V=V.next;let R=V.elt;N+=T.x*(R.y-D.y);let j=R.y*T.x-R.x*T.y;Z+=(T.x+R.x)*j,S+=(T.y+R.y)*j,N*=.5;let W=1/(6*N);Z*=W,S*=W;let Q=-N;w+=Z*Q,O+=S*Q,E-=N}else Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(Ce.flowpoly.head.next.elt);for(;Ce.flowsegs.head!=null;){let N=Ce.flowsegs.pop_unsafe(),Z=Ce.flowsegs.pop_unsafe(),S=Z.x-N.x,V=Z.y-N.y,D=S,T=V,G=D*D+T*T,R=1/Math.sqrt(G);D*=R,T*=R;let j=D;D=-T,T=j;let A=N.x+Z.x,W=N.y+Z.y,Q=.5;A*=Q,W*=Q;let Y=1;A-=e.circle.worldCOMx*Y,W-=e.circle.worldCOMy*Y;let X=D*A+T*W,ee=0,J=0,L=X,F=L/e.circle.radius,I=Math.sqrt(1-F*F),U=Math.acos(F);ee=e.circle.radius*(e.circle.radius*U-L*I),J=.6666666666666666*e.circle.radius*I*I*I/(U-F*I),A=e.circle.worldCOMx,W=e.circle.worldCOMy;let $=J;A+=D*$,W+=T*$;let K=ee;w+=A*K,O+=W*K,E+=ee}let M=1/E;return w*=M,O*=M,n.overlap=E,n.centroidx=w,n.centroidy=O,!0}}}else return!1}}else return!1}else{let i=e.circle,l=t.circle,r=l.worldCOMx-i.worldCOMx,a=l.worldCOMy-i.worldCOMy,o=i.radius+l.radius,p=r*r+a*a;if(p>o*o)return!1;if(p<s.Config.epsilon*s.Config.epsilon)return i.radius<l.radius?(n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy):(n.overlap=l.area,n.centroidx=l.worldCOMx,n.centroidy=l.worldCOMy),!0;{let c=Math.sqrt(p),h=1/c,u=.5*(c-(l.radius*l.radius-i.radius*i.radius)*h);if(u<=-i.radius)n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy;else{let x=c-u;if(x<=-l.radius)n.overlap=l.area,n.centroidx=l.worldCOMx,n.centroidy=l.worldCOMy;else{let y=0,d=0,_=0,f=0,z=u,P=z/i.radius,k=Math.sqrt(1-P*P),m=Math.acos(P);y=i.radius*(i.radius*m-z*k),d=.6666666666666666*i.radius*k*k*k/(m-P*k);let b=x,C=b/l.radius,v=Math.sqrt(1-C*C),w=Math.acos(C);_=l.radius*(l.radius*w-b*v),f=.6666666666666666*l.radius*v*v*v/(w-C*v);let O=y+_,E=(d*y+(c-f)*_)/O*h;n.overlap=O,n.centroidx=i.worldCOMx+r*E,n.centroidy=i.worldCOMy+a*E}}return!0}}}};Ce.flowpoly=null,Ce.flowsegs=null;var Ee=Ce;var ol=class g{static isinner(e,t,n){let s=e.x-t.x,i=e.y-t.y,l=n.x-t.x;return(n.y-t.y)*s-l*i>=0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}let s=e.vertices,i=e.vertices;if(s!=null){let l=s;for(;;){let r=l,a=r.prev,o=null,p=r.diagonals.head;for(;p!=null;){let c=p.elt,h=p.next==null?r.next:p.next.elt;if(!g.isinner(h,r,a)){o=p,a=c,p=p.next;continue}let u=!0,x=c,y=x.prev,d=null,_=x.diagonals.head;for(;_!=null;){let f=_.elt;if(f==r){let z=_.next==null?x.next:_.next.elt;u=g.isinner(z,x,y);break}y=f,d=_,_=_.next}if(u){p=r.diagonals.erase(o),x.diagonals.erase(d);continue}a=c,o=p,p=p.next}if(l=l.next,l==i)break}}}};var nt=class nt{constructor(){this.normal=null;this.shape=null;this.convex=null;this.position=null;this.ray=null;this.inner=!1;this.next=null;this.toiDistance=0}static getRay(e,t,n,s){let i;nt.rayPool==null?(nt.internal=!0,i=nt._createRayResult(),i.zpp_inner=new nt,i.zpp_inner.ray=i,nt.internal=!1):(i=nt.rayPool.ray,nt.rayPool=nt.rayPool.next,i.zpp_inner.next=null);let l=i.zpp_inner;return l.normal=e,e.zpp_inner._immutable=!0,l.toiDistance=t,l.inner=n,l.shape=s,i}static getConvex(e,t,n,s){let i;nt.convexPool==null?(nt.internal=!0,i=nt._createConvexResult(),i.zpp_inner=new nt,i.zpp_inner.convex=i,nt.internal=!1):(i=nt.convexPool.convex,nt.convexPool=nt.convexPool.next,i.zpp_inner.next=null);let l=i.zpp_inner;return l.normal=e,l.position=t,e.zpp_inner._immutable=!0,t.zpp_inner._immutable=!0,l.toiDistance=n,l.shape=s,i}disposed(){if(this.next!=null)throw new Error("Error: This object has been disposed of and cannot be used")}free(){nt._disposeVec2(this.normal),this.position!=null&&nt._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=nt.convexPool,nt.convexPool=this):(this.next=nt.rayPool,nt.rayPool=this)}static _disposeVec2(e){if(e.zpp_inner._immutable=!1,e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=e.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");if(t._isimmutable!=null&&t._isimmutable(),t._inuse)throw new Error("Error: This Vec2 is not disposable");let n=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null,e.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=e:_e.poolVec2=e,_e.nextVec2=e,e.zpp_disp=!0,n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=le.zpp_pool,le.zpp_pool=n}};nt.rayPool=null,nt.convexPool=null,nt.internal=!1,nt._createRayResult=null,nt._createConvexResult=null;var dn=nt;var Vi=class Vi{constructor(){this.prev=null;this.next=null;this.posx=0;this.posy=0;this.vert=null;this.value=0;this.positive=!1;this.parent=null;this.rank=0;this.used=!1}static path(e){let t;return Vi.zpp_pool==null?t=new Vi:(t=Vi.zpp_pool,Vi.zpp_pool=t.next,t.next=null),t.vert=e,t.parent=t,t.rank=0,t.used=!1,t}alloc(){}free(){this.vert=null,this.parent=null}};Vi.zpp_pool=null;var Qe=Vi;var Ii=class Ii{constructor(){this.next=null;this.time=0;this.virtualint=!1;this.vertex=!1;this.path0=null;this.end=null;this.start=null;this.path1=null}static get(e,t,n,s,i,l=!1,r=!1){let a;return Ii.zpp_pool==null?a=new Ii:(a=Ii.zpp_pool,Ii.zpp_pool=a.next,a.next=null),a.virtualint=l,a.end=t,a.start=n,a.path0=s,a.path1=i,a.time=e,a.vertex=r,a}alloc(){}free(){this.end=this.start=null,this.path0=this.path1=null}};Ii.zpp_pool=null;var st=Ii;var ei=class ei{constructor(){this.x=0;this.y=0;this.prev=null;this.next=null;this.wrap=null;this.forced=!1}static get(e,t){let n;return ei.zpp_pool==null?n=new ei:(n=ei.zpp_pool,ei.zpp_pool=n.next,n.next=null),n.forced=!1,n.x=e,n.y=t,n}alloc(){this.forced=!1}free(){if(this.wrap!=null){this.wrap.zpp_inner._inuse=!1;let e=this.wrap;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=e.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");if(t._isimmutable!=null&&t._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let n=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let s=e;s.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=s:_e.poolVec2=s,_e.nextVec2=s,s.zpp_disp=!0;let i=n;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i._isimmutable=null,i._validate=null,i._invalidate=null,i.next=le.zpp_pool,le.zpp_pool=i,this.wrap=null}this.prev=this.next=null}wrapper(){if(this.wrap==null){let e=this.x,t=this.y;if(t==null&&(t=0),e==null&&(e=0),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(_e.poolVec2==null?n=ei._createVec2Fn():(n=_e.poolVec2,_e.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n===_e.nextVec2&&(_e.nextVec2=null)),n.zpp_inner==null){let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x===e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y===t}else i=!1;if(!i){n.zpp_inner.x=e,n.zpp_inner.y=t;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}n.zpp_inner.weak=!1,this.wrap=n,this.wrap.zpp_inner._inuse=!0,this.wrap.zpp_inner._invalidate=s=>this.modwrap(s),this.wrap.zpp_inner._validate=()=>this.getwrap()}return this.wrap}modwrap(e){this.x=e.x,this.y=e.y}getwrap(){this.wrap.zpp_inner.x=this.x,this.wrap.zpp_inner.y=this.y}};ei.zpp_pool=null,ei._createVec2Fn=null;var ve=ei;var et=class et{static run(e,t,n,s,i,l){let r=me(),a=r.__zpp;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=t.zpp_inner;o._validate!=null&&o._validate();let p=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=t.zpp_inner;c._validate!=null&&c._validate();let h=t.zpp_inner.y;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=n.zpp_inner;u._validate!=null&&u._validate();let x=n.zpp_inner.x-p;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let y=n.zpp_inner;y._validate!=null&&y._validate();let d=n.zpp_inner.y-h,_=s?0:-1/0,f=i?1:1/0,z=-(h*x-p*d),P=null,k=!1,m=e;for(;;){let j;Qe.zpp_pool==null?j=new Qe:(j=Qe.zpp_pool,Qe.zpp_pool=j.next,j.next=null),j.vert=m,j.posx=m.x,j.posy=m.y,j.value=j.posy*x-j.posx*d+z,j.positive=j.value>0,j.value==0&&(k=!0);let A=j;if(P==null?A.prev=A.next=A:(A.prev=P,A.next=P.next,P.next.prev=A,P.next=A),P=A,m=m.next,m==e)break}if(k){let j=null,A=P,W=P;if(A!=null){let U=A;for(;;){let $=U;if($.value!=0){j=$;break}if(U=U.next,U==W)break}}let Q,Y;Q=x,Y=d;let X=Q*Q+Y*Y,J=1/Math.sqrt(X);Q*=J,Y*=J;let L=Q;Q=-Y,Y=L;let F=null,I=j;for(;;){if(I.value!=0&&(F==null||I==F.next)){if(F=I,I=I.next,I==j)break;continue}let U=F.value*I.value;if(U==0){if(I=I.next,I==j)break;continue}let $=F.next,K;if(U>0)K=F.positive;else{let se=$.next,te,oe;te=$.posx+se.posx,oe=$.posy+se.posy;let pe=.5;te*=pe,oe*=pe;let ce=te+Q*1e-8,ae=oe+Y*1e-8,ue=!1,ne=e,he=e;if(ne!=null){let ye=ne;for(;;){let de=ye,we=de.prev;if((de.y<ae&&we.y>=ae||we.y<ae&&de.y>=ae)&&(de.x<=ce||we.x<=ce)&&de.x+(ae-de.y)/(we.y-de.y)*(we.x-de.x)<ce&&(ue=!ue),ye=ye.next,ye==he)break}}K=ue}let ie=$,re=I;if(ie!=null){let se=ie;for(;;){let te=se;if(te.positive=K,se=se.next,se==re)break}}if(F=I,I=I.next,I==j)break}for(;!(I.value!=0&&(F==null||I==F.next));){let U=F.value*I.value;if(U==0)break;let $=F.next,K;if(U>0)K=F.positive;else{let se=$.next,te,oe;te=$.posx+se.posx,oe=$.posy+se.posy;let pe=.5;te*=pe,oe*=pe;let ce=te+Q*1e-8,ae=oe+Y*1e-8,ue=!1,ne=e,he=e;if(ne!=null){let ye=ne;for(;;){let de=ye,we=de.prev;if((de.y<ae&&we.y>=ae||we.y<ae&&de.y>=ae)&&(de.x<=ce||we.x<=ce)&&de.x+(ae-de.y)/(we.y-de.y)*(we.x-de.x)<ce&&(ue=!ue),ye=ye.next,ye==he)break}}K=ue}let ie=$,re=I;if(ie!=null){let se=ie;for(;;){let te=se;if(te.positive=K,se=se.next,se==re)break}}break}}et.ints==null&&(et.ints=new a.util.ZNPList_ZPP_CutInt),et.paths==null&&(et.paths=new a.util.ZNPList_ZPP_CutVert);let b=null,C=P.posx,v=P.posy,w;ve.zpp_pool==null?w=new ve:(w=ve.zpp_pool,ve.zpp_pool=w.next,w.next=null),w.forced=!1,w.x=C,w.y=v;let O=w;O.prev=O.next=O,b=O;let E=b,M;Qe.zpp_pool==null?M=new Qe:(M=Qe.zpp_pool,Qe.zpp_pool=M.next,M.next=null),M.vert=b,M.parent=M,M.rank=0,M.used=!1;let N=M;et.paths.add(N);let Z=P;for(;;){let j=Z.next,A=j.posx,W=j.posy,Q;ve.zpp_pool==null?Q=new ve:(Q=ve.zpp_pool,ve.zpp_pool=Q.next,Q.next=null),Q.forced=!1,Q.x=A,Q.y=W;let Y=Q;if(Z.positive==j.positive){let X=Y;b==null?(X.prev=X.next=X,b=X):(X.next=b,X.prev=b.prev,b.prev.next=X,b.prev=X)}else{let X=j.posx-Z.posx,ee=j.posy-Z.posy,J=d*X-x*ee;J=1/J;let L=p-Z.posx,F=h-Z.posy,I=(ee*L-X*F)*J;if(I<_||I>f){let U=et.ints,$=!0;$==null&&($=!1);let K;st.zpp_pool==null?K=new st:(K=st.zpp_pool,st.zpp_pool=K.next,K.next=null),K.virtualint=$,K.end=null,K.start=null,K.path0=null,K.path1=null,K.time=I,K.vertex=!1,U.add(K);let ie=Y;b==null?(ie.prev=ie.next=ie,b=ie):(ie.next=b,ie.prev=b.prev,b.prev.next=ie,b.prev=ie)}else if(Z.value==0){let U=b.prev;b=null;let $=U.x,K=U.y,ie;ve.zpp_pool==null?ie=new ve:(ie=ve.zpp_pool,ve.zpp_pool=ie.next,ie.next=null),ie.forced=!1,ie.x=$,ie.y=K;let re=ie;re.prev=re.next=re,b=re;let se=Y;b==null?(se.prev=se.next=se,b=se):(se.next=b,se.prev=b.prev,b.prev.next=se,b.prev=se);let te=et.paths.head.elt,oe=et.paths,pe;Qe.zpp_pool==null?pe=new Qe:(pe=Qe.zpp_pool,Qe.zpp_pool=pe.next,pe.next=null),pe.vert=b,pe.parent=pe,pe.rank=0,pe.used=!1,oe.add(pe);let ce=et.paths.head.elt,ae=et.ints,ue=!0;ue==null&&(ue=!1);let ne;st.zpp_pool==null?ne=new st:(ne=st.zpp_pool,st.zpp_pool=ne.next,ne.next=null),ne.virtualint=ue,ne.end=U,ne.start=b,ne.path0=te,ne.path1=ce,ne.time=I,ne.vertex=!1,ae.add(ne)}else if(j.value==0){let U=Y;b==null?(U.prev=U.next=U,b=U):(U.next=b,U.prev=b.prev,b.prev.next=U,b.prev=U);let $=b.prev;b=null;let K=j.posx,ie=j.posy,re;ve.zpp_pool==null?re=new ve:(re=ve.zpp_pool,ve.zpp_pool=re.next,re.next=null),re.forced=!1,re.x=K,re.y=ie;let se=re;se.prev=se.next=se,b=se;let te=et.paths.head.elt,oe=et.paths,pe;Qe.zpp_pool==null?pe=new Qe:(pe=Qe.zpp_pool,Qe.zpp_pool=pe.next,pe.next=null),pe.vert=b,pe.parent=pe,pe.rank=0,pe.used=!1,oe.add(pe);let ce=et.paths.head.elt,ae=et.ints,ue=!0;ue==null&&(ue=!1);let ne;st.zpp_pool==null?ne=new st:(ne=st.zpp_pool,st.zpp_pool=ne.next,ne.next=null),ne.virtualint=ue,ne.end=$,ne.start=b,ne.path0=te,ne.path1=ce,ne.time=I,ne.vertex=!1,ae.add(ne)}else{let U=(d*L-x*F)*J,$,K;$=Z.posx,K=Z.posy;let ie=U;$+=X*ie,K+=ee*ie;let re;ve.zpp_pool==null?re=new ve:(re=ve.zpp_pool,ve.zpp_pool=re.next,re.next=null),re.forced=!1,re.x=$,re.y=K;let se=re;b==null?(se.prev=se.next=se,b=se):(se.next=b,se.prev=b.prev,b.prev.next=se,b.prev=se);let te=b.prev;b=null;let oe;ve.zpp_pool==null?oe=new ve:(oe=ve.zpp_pool,ve.zpp_pool=oe.next,oe.next=null),oe.forced=!1,oe.x=$,oe.y=K;let pe=oe;pe.prev=pe.next=pe,b=pe;let ce=Y;b==null?(ce.prev=ce.next=ce,b=ce):(ce.next=b,ce.prev=b.prev,b.prev.next=ce,b.prev=ce);let ae=et.paths.head.elt,ue=et.paths,ne;Qe.zpp_pool==null?ne=new Qe:(ne=Qe.zpp_pool,Qe.zpp_pool=ne.next,ne.next=null),ne.vert=b,ne.parent=ne,ne.rank=0,ne.used=!1,ue.add(ne);let he=et.paths.head.elt,ye=et.ints,de=!1;de==null&&(de=!1);let we;st.zpp_pool==null?we=new st:(we=st.zpp_pool,st.zpp_pool=we.next,we.next=null),we.virtualint=de,we.end=te,we.start=b,we.path0=ae,we.path1=he,we.time=I,we.vertex=!1,ye.add(we)}}if(Z=Z.next,Z==P)break}let S=b.prev;S.next.prev=E.prev,E.prev.next=S.next,S.next=E,E.prev=S;let V=et.paths.head.elt,D;if(N==N.parent)D=N;else{let j=N,A=null;for(;j!=j.parent;){let W=j.parent;j.parent=A,A=j,j=W}for(;A!=null;){let W=A.parent;A.parent=j,A=W}D=j}let T;if(V==V.parent)T=V;else{let j=V,A=null;for(;j!=j.parent;){let W=j.parent;j.parent=A,A=j,j=W}for(;A!=null;){let W=A.parent;A.parent=j,A=W}T=j}D!=T&&(D.rank<T.rank?D.parent=T:D.rank>T.rank?T.parent=D:(T.parent=D,D.rank++));let G=et.ints;if(G.head!=null&&G.head.next!=null){let j=G.head,A,W,Q,Y,X=1,ee,J,L;for(;;){for(ee=0,W=j,j=null,A=j;W!=null;){for(++ee,Q=W,J=0,L=X;Q!=null&&J<X;)++J,Q=Q.next;for(;J>0||L>0&&Q!=null;)J==0?(Y=Q,Q=Q.next,--L):L==0||Q==null||W.elt.time<Q.elt.time?(Y=W,W=W.next,--J):(Y=Q,Q=Q.next,--L),A!=null?A.next=Y:j=Y,A=Y;W=Q}if(A.next=null,X<<=1,!(ee>1))break}G.head=j,G.modified=!0,G.pushmod=!0}for(;et.ints.head!=null;){let j=et.ints.pop_unsafe(),A=et.ints.pop_unsafe();if(!j.virtualint&&!A.virtualint){j.end.next.prev=A.start.prev,A.start.prev.next=j.end.next,j.end.next=A.start,A.start.prev=j.end,A.end.next.prev=j.start.prev,j.start.prev.next=A.end.next,A.end.next=j.start,j.start.prev=A.end;let Y;if(j.path0==j.path0.parent)Y=j.path0;else{let L=j.path0,F=null;for(;L!=L.parent;){let I=L.parent;L.parent=F,F=L,L=I}for(;F!=null;){let I=F.parent;F.parent=L,F=I}Y=L}let X;if(A.path1==A.path1.parent)X=A.path1;else{let L=A.path1,F=null;for(;L!=L.parent;){let I=L.parent;L.parent=F,F=L,L=I}for(;F!=null;){let I=F.parent;F.parent=L,F=I}X=L}Y!=X&&(Y.rank<X.rank?Y.parent=X:Y.rank>X.rank?X.parent=Y:(X.parent=Y,Y.rank++));let ee;if(j.path1==j.path1.parent)ee=j.path1;else{let L=j.path1,F=null;for(;L!=L.parent;){let I=L.parent;L.parent=F,F=L,L=I}for(;F!=null;){let I=F.parent;F.parent=L,F=I}ee=L}let J;if(A.path0==A.path0.parent)J=A.path0;else{let L=A.path0,F=null;for(;L!=L.parent;){let I=L.parent;L.parent=F,F=L,L=I}for(;F!=null;){let I=F.parent;F.parent=L,F=I}J=L}ee!=J&&(ee.rank<J.rank?ee.parent=J:ee.rank>J.rank?J.parent=ee:(J.parent=ee,ee.rank++))}else if(j.virtualint&&!A.virtualint){let Y;if(A.end!=null&&A.end.prev==A.end){A.end.next=A.end.prev=null;let J=A.end;if(J.wrap!=null){J.wrap.zpp_inner._inuse=!1;let L=J.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=L.zpp_inner;if(F._immutable)throw new Error("Error: Vec2 is immutable");if(F._isimmutable!=null&&F._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let I=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let U=L;U.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=U:_e.poolVec2=U,_e.nextVec2=U,U.zpp_disp=!0;let $=I;$.outer!=null&&($.outer.zpp_inner=null,$.outer=null),$._isimmutable=null,$._validate=null,$._invalidate=null,$.next=le.zpp_pool,le.zpp_pool=$,J.wrap=null}J.prev=J.next=null,J.next=ve.zpp_pool,ve.zpp_pool=J,Y=null}else{let J=A.end.prev;A.end.prev.next=A.end.next,A.end.next.prev=A.end.prev,A.end.next=A.end.prev=null;let L=A.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=F.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let $=F;$.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=$:_e.poolVec2=$,_e.nextVec2=$,$.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L,A.end=null,Y=J}if(A.end=Y,!A.vertex)if(A.end!=A.path0.vert){A.start.x=A.end.x,A.start.y=A.end.y;let J;if(A.end!=null&&A.end.prev==A.end){A.end.next=A.end.prev=null;let L=A.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=F.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let $=F;$.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=$:_e.poolVec2=$,_e.nextVec2=$,$.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L,J=null}else{let L=A.end.prev;A.end.prev.next=A.end.next,A.end.next.prev=A.end.prev,A.end.next=A.end.prev=null;let F=A.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let I=F.wrap;if(I!=null&&I.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let U=I.zpp_inner;if(U._immutable)throw new Error("Error: Vec2 is immutable");if(U._isimmutable!=null&&U._isimmutable(),I.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let $=I.zpp_inner;I.zpp_inner.outer=null,I.zpp_inner=null;let K=I;K.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=K:_e.poolVec2=K,_e.nextVec2=K,K.zpp_disp=!0;let ie=$;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=le.zpp_pool,le.zpp_pool=ie,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F,A.end=null,J=L}A.end=J}else{let J=A.start.next;if(A.start.x=J.x,A.start.y=J.y,J!=null&&J.prev==J){J.next=J.prev=null;let L=J;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=F.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let $=F;$.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=$:_e.poolVec2=$,_e.nextVec2=$,$.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L}else{J.prev.next=J.next,J.next.prev=J.prev,J.next=J.prev=null;let L=J;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=F.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let $=F;$.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=$:_e.poolVec2=$,_e.nextVec2=$,$.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L}}A.end.next.prev=A.start.prev,A.start.prev.next=A.end.next,A.end.next=A.start,A.start.prev=A.end;let X;if(A.path0==A.path0.parent)X=A.path0;else{let J=A.path0,L=null;for(;J!=J.parent;){let F=J.parent;J.parent=L,L=J,J=F}for(;L!=null;){let F=L.parent;L.parent=J,L=F}X=J}let ee;if(A.path1==A.path1.parent)ee=A.path1;else{let J=A.path1,L=null;for(;J!=J.parent;){let F=J.parent;J.parent=L,L=J,J=F}for(;L!=null;){let F=L.parent;L.parent=J,L=F}ee=J}X!=ee&&(X.rank<ee.rank?X.parent=ee:X.rank>ee.rank?ee.parent=X:(ee.parent=X,X.rank++))}else if(A.virtualint&&!j.virtualint){let Y;if(j.end!=null&&j.end.prev==j.end){j.end.next=j.end.prev=null;let J=j.end;if(J.wrap!=null){J.wrap.zpp_inner._inuse=!1;let L=J.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=L.zpp_inner;if(F._immutable)throw new Error("Error: Vec2 is immutable");if(F._isimmutable!=null&&F._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let I=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let U=L;U.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=U:_e.poolVec2=U,_e.nextVec2=U,U.zpp_disp=!0;let $=I;$.outer!=null&&($.outer.zpp_inner=null,$.outer=null),$._isimmutable=null,$._validate=null,$._invalidate=null,$.next=le.zpp_pool,le.zpp_pool=$,J.wrap=null}J.prev=J.next=null,J.next=ve.zpp_pool,ve.zpp_pool=J,Y=null}else{let J=j.end.prev;j.end.prev.next=j.end.next,j.end.next.prev=j.end.prev,j.end.next=j.end.prev=null;let L=j.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=F.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let $=F;$.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=$:_e.poolVec2=$,_e.nextVec2=$,$.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L,j.end=null,Y=J}if(j.end=Y,!j.vertex)if(j.end!=j.path0.vert){j.start.x=j.end.x,j.start.y=j.end.y;let J;if(j.end!=null&&j.end.prev==j.end){j.end.next=j.end.prev=null;let L=j.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=F.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let $=F;$.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=$:_e.poolVec2=$,_e.nextVec2=$,$.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L,J=null}else{let L=j.end.prev;j.end.prev.next=j.end.next,j.end.next.prev=j.end.prev,j.end.next=j.end.prev=null;let F=j.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let I=F.wrap;if(I!=null&&I.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let U=I.zpp_inner;if(U._immutable)throw new Error("Error: Vec2 is immutable");if(U._isimmutable!=null&&U._isimmutable(),I.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let $=I.zpp_inner;I.zpp_inner.outer=null,I.zpp_inner=null;let K=I;K.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=K:_e.poolVec2=K,_e.nextVec2=K,K.zpp_disp=!0;let ie=$;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=le.zpp_pool,le.zpp_pool=ie,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F,j.end=null,J=L}j.end=J}else{let J=j.start.next;if(j.start.x=J.x,j.start.y=J.y,J!=null&&J.prev==J){J.next=J.prev=null;let L=J;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=F.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let $=F;$.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=$:_e.poolVec2=$,_e.nextVec2=$,$.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L}else{J.prev.next=J.next,J.next.prev=J.prev,J.next=J.prev=null;let L=J;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=F.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let $=F;$.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=$:_e.poolVec2=$,_e.nextVec2=$,$.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L}}j.end.next.prev=j.start.prev,j.start.prev.next=j.end.next,j.end.next=j.start,j.start.prev=j.end;let X;if(j.path0==j.path0.parent)X=j.path0;else{let J=j.path0,L=null;for(;J!=J.parent;){let F=J.parent;J.parent=L,L=J,J=F}for(;L!=null;){let F=L.parent;L.parent=J,L=F}X=J}let ee;if(j.path1==j.path1.parent)ee=j.path1;else{let J=j.path1,L=null;for(;J!=J.parent;){let F=J.parent;J.parent=L,L=J,J=F}for(;L!=null;){let F=L.parent;L.parent=J,L=F}ee=J}X!=ee&&(X.rank<ee.rank?X.parent=ee:X.rank>ee.rank?ee.parent=X:(ee.parent=X,X.rank++))}let W=j;W.end=W.start=null,W.path0=W.path1=null,W.next=st.zpp_pool,st.zpp_pool=W;let Q=A;Q.end=Q.start=null,Q.path0=Q.path1=null,Q.next=st.zpp_pool,st.zpp_pool=Q}let q=l??new r.geom.GeomPolyList,R=et.paths.head;for(;R!=null;){let j=R.elt,A;if(j==j.parent)A=j;else{let Y=j,X=null;for(;Y!=Y.parent;){let ee=Y.parent;Y.parent=X,X=Y,Y=ee}for(;X!=null;){let ee=X.parent;X.parent=Y,X=ee}A=Y}if(A.used){R=R.next;continue}A.used=!0;let W=A.vert,Q=!0;for(;A.vert!=null&&(Q||W!=A.vert);)if(Q=!1,W.x==W.next.x&&W.y==W.next.y)if(W==A.vert&&(A.vert=W.next==W?null:W.next,Q=!0),W!=null&&W.prev==W)W.next=W.prev=null,W=null;else{let Y=W.next;W.prev.next=W.next,W.next.prev=W.prev,W.next=W.prev=null,W=Y}else W=W.next;if(A.vert!=null){let Y=r.geom.GeomPoly.get();Y.zpp_inner.vertices=A.vert,q.zpp_inner.reverse_flag?q.push(Y):q.unshift(Y)}R=R.next}for(;et.paths.head!=null;){let A=et.paths.pop_unsafe();A.vert=null,A.parent=null,A.next=Qe.zpp_pool,Qe.zpp_pool=A}for(;P!=null;)if(P!=null&&P.prev==P){P.next=P.prev=null;let j=P;j.vert=null,j.parent=null,j.next=Qe.zpp_pool,Qe.zpp_pool=j,P=null}else{let j=P.next;P.prev.next=P.next,P.next.prev=P.prev,P.next=P.prev=null;let A=P;A.vert=null,A.parent=null,A.next=Qe.zpp_pool,Qe.zpp_pool=A,P=j}return q}};et.ints=null,et.paths=null;var rl=et;var bs=class g{static validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let o=t.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=t.body.posx+(t.body.axisy*u.x-t.body.axisx*u.y),h.y=t.body.posy+(u.x*t.body.axisx+u.y*t.body.axisy),c=c.next}}let s=t.edges.head,i=t.gverts.next,l=i;for(i=i.next;i!=null;){let o=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=o,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,l=o,i=i.next}let r=t.gverts.next,a=s.elt;a.gp0=l,a.gp1=r,a.gnormx=t.body.axisy*a.lnormx-t.body.axisx*a.lnormy,a.gnormy=a.lnormx*t.body.axisx+a.lnormy*t.body.axisy,a.gprojection=t.body.posx*a.gnormx+t.body.posy*a.gnormy+a.lprojection,a.wrap_gnorm!=null&&(a.wrap_gnorm.zpp_inner.x=a.gnormx,a.wrap_gnorm.zpp_inner.y=a.gnormy),a.tp0=a.gp0.y*a.gnormx-a.gp0.x*a.gnormy,a.tp1=a.gp1.y*a.gnormx-a.gp1.x*a.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;g._validateWorldCOM(t);let n=t.radius,s=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-s,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+s}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,r=t.gverts.next;for(;r!=null;){let a=r,o=l;l=l.next,a.x=t.body.posx+(t.body.axisy*o.x-t.body.axisx*o.y),a.y=t.body.posy+(o.x*t.body.axisx+o.y*t.body.axisy),r=r.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next}}if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type==1&&g._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy));let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type==1&&g._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy));let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}static _computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null){e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;let t=1;e.localCOMx+=e.lverts.next.next.x*t,e.localCOMy+=e.lverts.next.next.y*t;let n=.5;e.localCOMx*=n,e.localCOMy*=n}else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let c=n;t+=i.x*(c.y-s.y);let h=c.y*i.x-c.x*i.y;e.localCOMx+=(i.x+c.x)*h,e.localCOMy+=(i.y+c.y)*h,s=i,i=c,n=n.next}n=e.lverts.next;let l=n;t+=i.x*(l.y-s.y);let r=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*r,e.localCOMy+=(i.y+l.y)*r,s=i,i=l,n=n.next;let a=n;t+=i.x*(a.y-s.y);let o=a.y*i.x-a.x*i.y;e.localCOMx+=(i.x+a.x)*o,e.localCOMy+=(i.y+a.y)*o,t=1/(3*t);let p=t;e.localCOMx*=p,e.localCOMy*=p}}};var al=class{constructor(e=null){this.outer=null;this.vertices=null;this.outer=e}};var Sn=class{constructor(){this.rank=0;this.out=!1;this.next=null;this.parent=this}free(){this.parent=this}alloc(){this.out=!1,this.rank=0}};Sn.zpp_pool=null;var An=class{constructor(){this.p1=null;this.key1=0;this.okey1=0;this.p2=null;this.key2=0;this.okey2=0;this.pr=null;this.keyr=0;this.okeyr=0;this.pd=null;this.span1=null;this.span2=null;this.spanr=null;this.next=null}free(){this.p1=this.p2=this.pr=this.pd=null,this.span1=this.span2=this.spanr=null}alloc(){}};An.zpp_pool=null;var ze=class ze{static _init(e,t){ze._zpp=e,ze._nape=t,ze.me=new ze,ze.look_march=[-1,224,56,216,14,-1,54,214,131,99,-1,91,141,109,181,85]}static _allocVert(e,t){let n;return ve.zpp_pool==null?n=new ve:(n=ve.zpp_pool,ve.zpp_pool=n.next,n.next=null),n.forced=!1,n.x=e,n.y=t,n}static _freeVert(e){if(e.wrap!=null){e.wrap.zpp_inner._inuse=!1;let t=e.wrap;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=t.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let s=t.zpp_inner;t.zpp_inner.outer=null,t.zpp_inner=null;let i=t;i.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=i:_e.poolVec2=i,_e.nextVec2=i,i.zpp_disp=!0;let l=s;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l._isimmutable=null,l._validate=null,l._invalidate=null,l.next=le.zpp_pool,le.zpp_pool=l,e.wrap=null}e.prev=e.next=null,e.next=ve.zpp_pool,ve.zpp_pool=e}static _allocSpan(){let e;return Sn.zpp_pool==null?e=new Sn:(e=Sn.zpp_pool,Sn.zpp_pool=e.next,e.next=null),e.out=!1,e.rank=0,e}static _allocPair(){let e;return An.zpp_pool==null?e=new An:(e=An.zpp_pool,An.zpp_pool=e.next,e.next=null),e}static _freePair(e){e.p1=e.p2=e.pr=e.pd=null,e.span1=e.span2=e.spanr=null,e.next=An.zpp_pool,An.zpp_pool=e}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let s=t.parent;t.parent=n,n=t,t=s}for(;n!=null;){let s=n.parent;n.parent=t,n=s}return t}static _union(e,t){let n=ze._findRoot(e),s=ze._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}static _pushVert(e,t){return e==null?t.prev=t.next=t:(t.prev=e,t.next=e.next,e.next.prev=t,e.next=t),t}static _isDegenKey(e){return e==1||e==4||e==16||e==64||e==3||e==12||e==48||e==192||e==129||e==6||e==24||e==96||e==5||e==20||e==80||e==65||e==17||e==68}static ISO(e,t,n){return e(t,n)}static run(e,t,n,s,i,l,r,a,o){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate();let c=(s-t)/l.zpp_inner.x,h=c|0;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");p=l.zpp_inner,p._validate!=null&&p._validate();let u=(i-n)/l.zpp_inner.y,x=u|0;c!=h&&++h,u!=x&&++x,a&&(ze.map==null?ze.map=new cs(h,x):ze.map.resize(h,x,null)),ze.isos==null?ze.isos=new as(h+1,x+1):ze.isos.resize(h+1,x+1,0);for(let _=0;_<x+1;_++){let f;if(_==0)f=n;else if(_<=x){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let z=l.zpp_inner;z._validate!=null&&z._validate(),f=n+l.zpp_inner.y*_}else f=i;for(let z=0;z<h+1;z++){let P;if(z==0)P=t;else if(z<=h){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let b=l.zpp_inner;b._validate!=null&&b._validate(),P=t+l.zpp_inner.x*z}else P=s;let k=ze.isos,m=e(P,f);k.list[_*k.width+z]=m}}ze.ints==null?ze.ints=new ps(h+1,(x<<1)+1):ze.ints.resize(h+1,(x<<1)+1,null);let y=null;a&&(y=ze._allocSpan(),y.next=null);let d=n;for(let _=0;_<x;_++){let f=d,z;if(_==x-1)z=i;else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let m=l.zpp_inner;m._validate!=null&&m._validate(),z=n+l.zpp_inner.y*(_+1)}d=z;let P=t,k=null;for(let m=0;m<h;m++){let b=P,C;if(m==h-1)C=s;else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let N=l.zpp_inner;N._validate!=null&&N._validate(),C=t+l.zpp_inner.x*(m+1)}P=C;let v=m==0||!a,w=_==0||!a,O=m==h-1||!a,E=_==x-1||!a,M=ze.me.marchSquare(e,ze.isos,ze.ints,b,f,C,z,m,_,v,w,O,E,r);if(M==null){k=null;continue}if(a){let N=M.p2!=null&&M.okey2!=14?M.p2:M.p1;M.pd=((N==M.p2?M.okey2:M.okey1)&128)==0?N.prev:N.prev.prev;let Z=ze.map;Z.list[_*Z.width+m]=M;let S;if(k!=null){let T=M.key1,G=T&1|(T&192)>>5,q=0;(G&1)!=0&&++q,(G&2)!=0&&++q,(G&4)!=0&&++q,S=q>=2}else S=!1;S?(ze.me.combLR(k,M),M.span1=k.spanr):(M.span1=ze._allocSpan(),M.span1.next=y,y=M.span1),M.p2!=null?(M.span2=ze._allocSpan(),M.span2.next=y,y=M.span2,M.spanr=M.span2):M.spanr=M.span1;let V=(M.keyr&28)>>2,D=0;(V&1)!=0&&++D,(V&2)!=0&&++D,(V&4)!=0&&++D,D>=2?k=M:k=null}else ze.me.output(o,M.p1),M.p2!=null&&ze.me.output(o,M.p2),ze._freePair(M)}}if(a){for(let _=1;_<x;_++){let f=null;for(let z=0;z<h;z++){let P=ze.map,k=P.list[_*P.width+z];if(k==null){f=null;continue}let b=(k.p2!=null&&k.okey2==14?k.okey2:k.okey1)&7,C=0;if((b&1)!=0&&++C,(b&2)!=0&&++C,(b&4)!=0&&++C,C<2){f=null;continue}let v=ze.map,w=v.list[(_-1)*v.width+z];if(w==null){f=null;continue}let E=((w.p2!=null&&w.okey2==56?w.okey2:w.okey1)&112)>>4,M=0;if((E&1)!=0&&++M,(E&2)!=0&&++M,(E&4)!=0&&++M,M<2){f=null;continue}let N=w.p2!=null&&w.okey2==56?w.span2:w.span1,Z=k.p2!=null&&k.okey2==14?k.span2:k.span1,S=ze._findRoot(N),V=ze._findRoot(Z);S==V?f!=Z&&ze.me.combUD_virtual(w,k):(ze._union(N,Z),ze.me.combUD(w,k)),f=((Z==k.span2?k.okey2:k.okey1)&4)!=0?Z:null}}for(let _=0;_<x;_++)for(let f=0;f<h;f++){let z=ze.map,P=z.list[_*z.width+f];if(P==null)continue;let k=ze._findRoot(P.span1);k.out||(k.out=!0,ze.me.output(o,P.p1)),P.p2!=null&&(k=ze._findRoot(P.span2),k.out||(k.out=!0,ze.me.output(o,P.p2))),ze._freePair(P),z.list[_*z.width+f]=null}for(;y!=null;){let _=y;y=_.next;let f=_;f.parent=f,f.next=Sn.zpp_pool,Sn.zpp_pool=f}}}output(e,t){let n=ze._nape,s;if(t==null||t.next==t||t.next==t.prev)s=!0;else{let r=0,a=t,o=t;if(a!=null){let c=a;for(;;){let h=c;if(r+=h.x*(h.next.y-h.prev.y),c=c.next,c==o)break}}let p=r*.5;s=p*p<n.Config.epsilon*n.Config.epsilon}if(s){for(;t!=null;)if(t!=null&&t.prev==t)t.next=t.prev=null,t=null;else{let r=t.next;t.prev.next=t.next,t.next.prev=t.prev,t.next=t.prev=null,t=r}return}let i=n.geom.GeomPoly.get();i.zpp_inner.vertices=t;let l=e;l.zpp_inner.reverse_flag?l.push(i):l.unshift(i)}linkright(e,t){let n=t&7;return n==0?e:n==3?e.next.next:e.next}linkleft(e,t){return(t&1)==0?e.prev:e}linkdown(e,t){return(t&128)==0?e.prev:e.prev.prev}linkup(e,t){return e}combLR(e,t){let n=e.pr,s=e.okeyr&7,i=s==0?n:s==3?n.next.next:n.next,l=t.p1,r=(t.okey1&1)==0?l.prev:l,a=i.next,o=r.prev;(e.keyr&4)!=0?(t.pr==t.p1&&(t.pr=i.prev),t.p1=i.prev,i.prev.next=r.next,r.next.prev=i.prev,ze._freeVert(i)):(i.next=r.next,r.next.prev=i),ze._freeVert(r),(e.keyr&16)!=0?(t.pd=a.next,a.next.prev=o.prev,o.prev.next=a.next,ze._freeVert(a)):(a.prev=o.prev,o.prev.next=a),ze._freeVert(o)}combUD(e,t){let n=e.pd,s=t.p2!=null&&t.key2==14?t.p2:t.p1,i=n.prev,l=s.next;s.next=n.next,n.next.prev=s,ze._freeVert(n),l.prev=i.prev,i.prev.next=l,i==e.p1&&(e.p1=l),ze._freeVert(i)}combUD_virtual(e,t){let n=e.pd,s=t.p2!=null&&t.key2==14?t.p2:t.p1,i=n.prev,l=s.next;n.forced=s.forced=i.forced=l.forced=!0}combLeft(e){let t=e&1|(e&192)>>5,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combRight(e){let t=(e&28)>>2,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combUp(e){let t=e&7,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combDown(e){let t=(e&112)>>4,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}comb(e){let t=0;return(e&1)!=0&&++t,(e&2)!=0&&++t,(e&4)!=0&&++t,t>=2}_buildPoly(e,t,n,s,i,l,r,a,o,p,c,h,u,x,y,d,_,f,z){let P=null;for(let k=0;k<8;k++)if((e&1<<k)!=0){let m;if(k==0)m=ze._allocVert(s,i),(x||y)&&(m.forced=!0);else if(k==2)m=ze._allocVert(l,i),(d||y)&&(m.forced=!0);else if(k==4)m=ze._allocVert(l,r),(d||_)&&(m.forced=!0);else if(k==6)m=ze._allocVert(s,r),(x||_)&&(m.forced=!0);else if(k==1){if(m=n.list[(o<<1)*n.width+a],m==null){let b=this.xlerp(s,l,i,p,c,f,z);m=ze._allocVert(b,i),n.list[(o<<1)*n.width+a]=m}else m=ze._allocVert(m.x,m.y);y&&(m.forced=!0),(m.x==s||m.x==l)&&(m.x==s&&(e&1)!=0||m.x==l&&(e&4)!=0)&&(e^=2)}else if(k==5){if(m=n.list[((o<<1)+2)*n.width+a],m==null){let b=this.xlerp(s,l,r,u,h,f,z);m=ze._allocVert(b,r),n.list[((o<<1)+2)*n.width+a]=m}else m=ze._allocVert(m.x,m.y);_&&(m.forced=!0),(m.x==s||m.x==l)&&(m.x==s&&(e&64)!=0||m.x==l&&(e&16)!=0)&&(e^=32)}else if(k==3){if(m=n.list[((o<<1)+1)*n.width+(a+1)],m==null){let b=this.ylerp(i,r,l,c,h,f,z);m=ze._allocVert(l,b),n.list[((o<<1)+1)*n.width+(a+1)]=m}else m=ze._allocVert(m.x,m.y);d&&(m.forced=!0),(m.y==i||m.y==r)&&(m.y==i&&(e&4)!=0||m.y==r&&(e&16)!=0)&&(e^=8)}else{if(m=n.list[((o<<1)+1)*n.width+a],m==null){let b=this.ylerp(i,r,s,p,u,f,z);m=ze._allocVert(s,b),n.list[((o<<1)+1)*n.width+a]=m}else m=ze._allocVert(m.x,m.y);x&&(m.forced=!0),(m.y==i||m.y==r)&&(m.y==i&&(e&1)!=0||m.y==r&&(e&64)!=0)&&(e^=128)}P=ze._pushVert(P,m)}return P!=null&&(P=P.next),{head:P,val:e}}marchSquare(e,t,n,s,i,l,r,a,o,p,c,h,u,x){let y=0,d=t.list[o*t.width+a];d<0&&(y|=8);let _=t.list[o*t.width+(a+1)];_<0&&(y|=4);let f=t.list[(o+1)*t.width+(a+1)];f<0&&(y|=2);let z=t.list[(o+1)*t.width+a];if(z<0&&(y|=1),y==0)return null;let P=ze._allocPair();if(y!=10&&y!=5){let k=ze.look_march[y];P.okey1=k;let m=this._buildPoly(k,t,n,s,i,l,r,a,o,d,_,f,z,p,c,h,u,e,x);P.p1=m.head,k=m.val,P.key1=k,ze._isDegenKey(k)&&(k=0,P.key1=0,P.p1=null),k==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let k=e(.5*(s+l),.5*(i+r))<0;if(y==10)if(k){let m=187;P.okey1=m;let b=this._buildPoly(m,t,n,s,i,l,r,a,o,d,_,f,z,p,c,h,u,e,x);P.p1=b.head,m=b.val,P.key1=m,ze._isDegenKey(m)&&(m=0,P.key1=0,P.p1=null),m==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let m=131;P.okey1=m;let b=this._buildPoly(m,t,n,s,i,l,r,a,o,d,_,f,z,p,c,h,u,e,x);if(P.p1=b.head,m=b.val,P.key1=m,ze._isDegenKey(m)&&(m=0,P.key1=0,P.p1=null),m!=0){let C=56;P.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,r,a,o,d,_,f,z,p,c,h,u,e,x,P).val,P.key2=C,ze._isDegenKey(C)&&(C=0,P.key2=0,P.p2=null),C==0?(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1):(P.pr=P.p2,P.okeyr=P.okey2,P.keyr=P.key2)}else{let C=56;P.okey1=C;let v=this._buildPoly(C,t,n,s,i,l,r,a,o,d,_,f,z,p,c,h,u,e,x);P.p1=v.head,C=v.val,P.key1=C,ze._isDegenKey(C)&&(C=0,P.key1=0,P.p1=null),C==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}}else if(k){let m=238;P.okey1=m;let b=this._buildPoly(m,t,n,s,i,l,r,a,o,d,_,f,z,p,c,h,u,e,x);P.p1=b.head,m=b.val,P.key1=m,ze._isDegenKey(m)&&(m=0,P.key1=0,P.p1=null),m==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let m=224;P.okey1=m;let b=this._buildPoly(m,t,n,s,i,l,r,a,o,d,_,f,z,p,c,h,u,e,x);if(P.p1=b.head,m=b.val,P.key1=m,ze._isDegenKey(m)&&(m=0,P.key1=0,P.p1=null),m!=0){let C=14;P.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,r,a,o,d,_,f,z,p,c,h,u,e,x,P).val,P.key2=C,ze._isDegenKey(C)&&(C=0,P.key2=0,P.p2=null),C==0?(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1):(P.pr=P.p2,P.okeyr=P.okey2,P.keyr=P.key2)}else{let C=14;P.okey1=C;let v=this._buildPoly(C,t,n,s,i,l,r,a,o,d,_,f,z,p,c,h,u,e,x);P.p1=v.head,C=v.val,P.key1=C,ze._isDegenKey(C)&&(C=0,P.key1=0,P.p1=null),C==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}}}return P}_buildPoly2(e,t,n,s,i,l,r,a,o,p,c,h,u,x,y,d,_,f,z,P){for(let k=0;k<8;k++)if((e&1<<k)!=0){let m;if(k==0)m=ze._allocVert(s,i),(x||y)&&(m.forced=!0);else if(k==2)m=ze._allocVert(l,i),(d||y)&&(m.forced=!0);else if(k==4)m=ze._allocVert(l,r),(d||_)&&(m.forced=!0);else if(k==6)m=ze._allocVert(s,r),(x||_)&&(m.forced=!0);else if(k==1){if(m=n.list[(o<<1)*n.width+a],m==null){let C=this.xlerp(s,l,i,p,c,f,z);m=ze._allocVert(C,i),n.list[(o<<1)*n.width+a]=m}else m=ze._allocVert(m.x,m.y);y&&(m.forced=!0),(m.x==s||m.x==l)&&(m.x==s&&(e&1)!=0||m.x==l&&(e&4)!=0)&&(e^=2)}else if(k==5){if(m=n.list[((o<<1)+2)*n.width+a],m==null){let C=this.xlerp(s,l,r,u,h,f,z);m=ze._allocVert(C,r),n.list[((o<<1)+2)*n.width+a]=m}else m=ze._allocVert(m.x,m.y);_&&(m.forced=!0),(m.x==s||m.x==l)&&(m.x==s&&(e&64)!=0||m.x==l&&(e&16)!=0)&&(e^=32)}else if(k==3){if(m=n.list[((o<<1)+1)*n.width+(a+1)],m==null){let C=this.ylerp(i,r,l,c,h,f,z);m=ze._allocVert(l,C),n.list[((o<<1)+1)*n.width+(a+1)]=m}else m=ze._allocVert(m.x,m.y);d&&(m.forced=!0),(m.y==i||m.y==r)&&(m.y==i&&(e&4)!=0||m.y==r&&(e&16)!=0)&&(e^=8)}else{if(m=n.list[((o<<1)+1)*n.width+a],m==null){let C=this.ylerp(i,r,s,p,u,f,z);m=ze._allocVert(s,C),n.list[((o<<1)+1)*n.width+a]=m}else m=ze._allocVert(m.x,m.y);x&&(m.forced=!0),(m.y==i||m.y==r)&&(m.y==i&&(e&1)!=0||m.y==r&&(e&64)!=0)&&(e^=128)}let b=m;P.p2==null?P.p2=b.prev=b.next=b:(b.prev=P.p2,b.next=P.p2.next,P.p2.next.prev=b,P.p2.next=b),P.p2=b}return P.p2!=null&&(P.p2=P.p2.next),{val:e}}lerp(e,t,n,s){let i=ze._nape;if(n==0)return e;if(s==0)return t;{let l=n-s,r=l*l<i.Config.epsilon*i.Config.epsilon?.5:n/l;return r<0?r=0:r>1&&(r=1),e+r*(t-e)}}xlerp(e,t,n,s,i,l,r){let a=ze._nape,o;if(s==0)o=e;else if(i==0)o=t;else{let p=s-i,c=p*p<a.Config.epsilon*a.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),o=e+c*(t-e)}for(;r--!=0&&e<o&&o<t;){let p=l(o,n);if(p==0)break;if(s*p<0?(t=o,i=p):(e=o,s=p),s==0)o=e;else if(i==0)o=t;else{let c=s-i,h=c*c<a.Config.epsilon*a.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),o=e+h*(t-e)}}return o}ylerp(e,t,n,s,i,l,r){let a=ze._nape,o;if(s==0)o=e;else if(i==0)o=t;else{let p=s-i,c=p*p<a.Config.epsilon*a.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),o=e+c*(t-e)}for(;r--!=0&&e<o&&o<t;){let p=l(n,o);if(p==0)break;if(s*p<0?(t=o,i=p):(e=o,s=p),s==0)o=e;else if(i==0)o=t;else{let c=s-i,h=c*c<a.Config.epsilon*a.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),o=e+h*(t-e)}}return o}};ze.isos=null,ze.ints=null,ze.map=null,ze._zpp=null,ze._nape=null;var Ts=ze;var on=class on{constructor(){this.outer=null;this.a=0;this.b=0;this.c=0;this.d=0;this.tx=0;this.ty=0;this._invalidate=null;this.next=null}static get(){let e;return on.zpp_pool==null?e=new on:(e=on.zpp_pool,on.zpp_pool=e.next,e.next=null),e}static identity(){let e=on.get();return e.setas(1,0,0,1,0,0),e}wrapper(){if(this.outer==null)if(on._wrapFn)this.outer=on._wrapFn(this);else{this.outer=new on._nape.geom.Mat23;let e=this.outer.zpp_inner;e.next=on.zpp_pool,on.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}invalidate(){this._invalidate!=null&&this._invalidate()}set(e){this.setas(e.a,e.b,e.c,e.d,e.tx,e.ty)}setas(e,t,n,s,i,l){this.tx=i,this.ty=l,this.a=e,this.b=t,this.c=n,this.d=s}free(){}alloc(){}};on._nape=null,on._wrapFn=null,on.zpp_pool=null;var Ls=on;var Bi=class{constructor(e,t){this.outer=null;this.m=0;this.n=0;this.m=e,this.n=t,this.x=[];let n=0,s=e*t;for(;n<s;)n++,this.x.push(0)}};var _t=class _t{constructor(){this.node=null;this.prev=null;this.next=null;this.rightchain=!1;this.helper=null;this.type=0;this.diagonals=null;this.forced=!1;this.y=0;this.x=0;this.mag=0;this.id=0;this.id=_t.nextId++,this.diagonals=new pi}static get(e){let t;return _t.zpp_pool==null?t=new _t:(t=_t.zpp_pool,_t.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t}static rightdistance(e,t){let n=e.next.y>e.y,s=e.next.x-e.x,i=e.next.y-e.y,l=t.x-e.x,r=t.y-e.y;return(n?-1:1)*(r*s-l*i)}static vert_lt(e,t){if(t==e||t==e.next)return!0;if(e.y==e.next.y){let n=e.x,s=e.next.x;return(n<s?n:s)<=t.x}else return _t.rightdistance(e,t)<=0}static edge_swap(e,t){let n=e.node;e.node=t.node,t.node=n}static edge_lt(e,t){if(e==t&&e.next==t.next)return!1;if(e==t.next)return!_t.vert_lt(e,t);if(t==e.next)return _t.vert_lt(t,e);if(e.y==e.next.y)if(t.y==t.next.y){let n=e.x,s=e.next.x,i=t.x,l=t.next.x;return(n>s?n:s)>(i>l?i:l)}else return _t.rightdistance(t,e)>0?!0:_t.rightdistance(t,e.next)>0;else{let n=_t.rightdistance(e,t),s=_t.rightdistance(e,t.next);if(n==0&&s==0){let r=e.x,a=e.next.x,o=t.x,p=t.next.x;return(r>a?r:a)>(o>p?o:p)}if(n*s>=0)return n<0?!0:s<0;let i=_t.rightdistance(t,e),l=_t.rightdistance(t,e.next);return i*l>=0?i>0?!0:l>0:!1}}alloc(){}free(){this.helper=null}copy(){let e;return _t.zpp_pool==null?e=new _t:(e=_t.zpp_pool,_t.zpp_pool=e.next,e.next=null),e.x=this.x,e.y=this.y,e.forced=this.forced,e}sort(){let e=this.prev.x-this.x,t=this.prev.y-this.y,n=this.next.x-this.x,s=this.next.y-this.y,i=s*e-n*t,l=i>0?-1:i==0?0:1,r=this.diagonals;if(r.head!=null&&r.head.next!=null){let a=r.head,o,p,c,h,u=1,x,y,d;for(;;){for(x=0,p=a,a=null,o=a;p!=null;){for(++x,c=p,y=0,d=u;c!=null&&y<u;)++y,c=c.next;for(;y>0||d>0&&c!=null;){if(y==0)h=c,c=c.next,--d;else if(d==0||c==null)h=p,p=p.next,--y;else{let _;if(l==1){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,s=c.elt.y-this.y;let f=s*e-n*t;_=(f>0?-1:f==0?0:1)==1}else{e=this.prev.x-this.x,t=this.prev.y-this.y,n=p.elt.x-this.x,s=p.elt.y-this.y;let f=s*e-n*t,z=f>0?-1:f==0?0:1;e=this.prev.x-this.x,t=this.prev.y-this.y,n=c.elt.x-this.x,s=c.elt.y-this.y;let P=s*e-n*t,k=P>0?-1:P==0?0:1;if(z*k==1||z*k==0&&(z==1||k==1)){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,s=c.elt.y-this.y;let m=s*e-n*t;_=(m>0?-1:m==0?0:1)==1}else if(z==-1||k==-1)_=k==-1;else if(z==0&&k==0){e=this.x-this.prev.x,t=this.y-this.prev.y,n=p.elt.x-this.x,s=p.elt.y-this.y;let m=e*n+t*s;n=c.elt.x-this.x,s=c.elt.y-this.y;let b=e*n+t*s;_=m<0&&b>0?!0:!(b<0&&m>0)}else _=!0}_?(h=p,p=p.next,--y):(h=c,c=c.next,--d)}o!=null?o.next=h:a=h,o=h}p=c}if(o.next=null,u<<=1,!(x>1))break}r.head=a,r.modified=!0,r.pushmod=!0}}};_t.zpp_pool=null,_t.nextId=0;var Ge=_t;var rn=class rn{constructor(e){this.next=null;this.vertices=null;this.init(e)}static getSharedPP(){return rn.sharedPPList==null&&(rn.sharedPPList=new tl),rn.sharedPPList}static getShared(){return rn.sharedGVList==null&&(rn.sharedGVList=new hs),rn.sharedGVList}eq(e,t){let n=e.x-t.x,s=e.y-t.y;return n*n+s*s<me().Config.epsilon*me().Config.epsilon}alloc(){}free(){}init(e){if(e==null)return;let t=0,n=e,s=e;if(n!=null){let r=n;for(;;){let a=r;if(t+=a.x*(a.next.y-a.prev.y),r=r.next,r==s)break}}let i=t*.5>0,l=e;for(;;){let r;if(i){let a;Ge.zpp_pool==null?a=new Ge:(a=Ge.zpp_pool,Ge.zpp_pool=a.next,a.next=null),a.x=l.x,a.y=l.y;let o=a;this.vertices==null?this.vertices=o.prev=o.next=o:(o.prev=this.vertices,o.next=this.vertices.next,this.vertices.next.prev=o,this.vertices.next=o),r=o}else{let a;Ge.zpp_pool==null?a=new Ge:(a=Ge.zpp_pool,Ge.zpp_pool=a.next,a.next=null),a.x=l.x,a.y=l.y;let o=a;this.vertices==null?this.vertices=o.prev=o.next=o:(o.next=this.vertices,o.prev=this.vertices.prev,this.vertices.prev.next=o,this.vertices.prev=o),r=o}if(this.vertices=r,this.vertices.forced=l.forced,l=l.next,l==e)break}this.remove_collinear_vertices()}remove_collinear_vertices(){let e=this.vertices,t=!0;for(;t||e!=this.vertices;)if(t=!1,this.eq(e,e.next)){if(e==this.vertices&&(this.vertices=e.next,t=!0),e.forced&&(e.next.forced=!0),e!=null&&e.prev==e){e.next=e.prev=null;let s=e;s.helper=null,s.next=Ge.zpp_pool,Ge.zpp_pool=s,e=null,e=null}else{let s=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let i=e;i.helper=null,i.next=Ge.zpp_pool,Ge.zpp_pool=i,e=s}if(e==null){this.vertices=null;break}}else e=e.next;if(this.vertices==null)return!0;let n;for(;;){for(n=!1,e=this.vertices,t=!0;t||e!=this.vertices;){t=!1;let s=e.prev,i=e.x-s.x,l=e.y-s.y,r=e.next.x-e.x,o=(e.next.y-e.y)*i-r*l;if(o*o>=me().Config.epsilon*me().Config.epsilon)e=e.next;else{if(e==this.vertices&&(this.vertices=e.next,t=!0),e!=null&&e.prev==e){e.next=e.prev=null;let p=e;p.helper=null,p.next=Ge.zpp_pool,Ge.zpp_pool=p,e=null,e=null}else{let p=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let c=e;c.helper=null,c.next=Ge.zpp_pool,Ge.zpp_pool=c,e=p}if(n=!0,e==null){n=!1,this.vertices=null;break}}}if(!n)break}return this.vertices==null}add_diagonal(e,t){e.diagonals.add(t),t.diagonals.add(e),e.forced=t.forced=!0}extract_partitions(e){if(e==null&&(e=new tl),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}for(this.pull_partitions(this.vertices,e);this.vertices!=null;){let l;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let r=this.vertices;r.helper=null,r.next=Ge.zpp_pool,Ge.zpp_pool=r,l=this.vertices=null}else{let r=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let a=this.vertices;a.helper=null,a.next=Ge.zpp_pool,Ge.zpp_pool=a,this.vertices=null,l=r}this.vertices=l}let s=null,i=e.head;for(;i!=null;){if(i.elt.remove_collinear_vertices()){e.erase(s);continue}s=i,i=i.next}}return e}pull_partitions(e,t){let n;rn.zpp_pool==null?n=new rn:(n=rn.zpp_pool,rn.zpp_pool=n.next,n.next=null);let s=e;for(;;){let a;Ge.zpp_pool==null?a=new Ge:(a=Ge.zpp_pool,Ge.zpp_pool=a.next,a.next=null),a.x=s.x,a.y=s.y,a.forced=s.forced;let o=a;if(n.vertices==null?n.vertices=o.prev=o.next=o:(o.prev=n.vertices,o.next=n.vertices.next,n.vertices.next.prev=o,n.vertices.next=o),n.vertices=o,n.vertices.forced=s.forced,s.diagonals.head!=null){let p=s.diagonals,c=p.head.elt;if(p.pop(),c==e)break;s=this.pull_partitions(s,t)}else s=s.next;if(s==e)break}let i=0,l=n.vertices,r=n.vertices;if(l!=null){let a=l;for(;;){let o=a;if(i+=o.x*(o.next.y-o.prev.y),a=a.next,a==r)break}}return i*.5!=0&&t.add(n),s}extract(e){if(e==null&&(e=new hs),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let s=t;for(;s.sort(),s=s.next,s!=n;);}for(this.pull(this.vertices,e);this.vertices!=null;){let s;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let i=this.vertices;i.helper=null,i.next=Ge.zpp_pool,Ge.zpp_pool=i,s=this.vertices=null}else{let i=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let l=this.vertices;l.helper=null,l.next=Ge.zpp_pool,Ge.zpp_pool=l,this.vertices=null,s=i}this.vertices=s}}return e}pull(e,t){let n=null,s=e;for(;;){let o=s.x,p=s.y,c;ve.zpp_pool==null?c=new ve:(c=ve.zpp_pool,ve.zpp_pool=c.next,c.next=null),c.forced=!1,c.x=o,c.y=p;let h=c;if(n==null?h.prev=h.next=h:(h.prev=n,h.next=n.next,n.next.prev=h,n.next=h),n=h,n.forced=s.forced,s.diagonals.head!=null){let u=s.diagonals,x=u.head.elt;if(u.pop(),x==e)break;s=this.pull(s,t)}else s=s.next;if(s==e)break}let i=0,l=n,r=n;if(l!=null){let o=l;for(;;){let p=o;if(i+=p.x*(p.next.y-p.prev.y),o=o.next,o==r)break}}let a=i*.5;if(a*a>=me().Config.epsilon*me().Config.epsilon){let o=n,p=!0;for(;p||o!=n;){p=!1;let c=o.x-o.next.x,h=o.y-o.next.y;if(c*c+h*h<me().Config.epsilon*me().Config.epsilon){if(o==n&&(n=o.next,p=!0),o.forced&&(o.next.forced=!0),o!=null&&o.prev==o)o.next=o.prev=null,o=null;else{let u=o.next;o.prev.next=o.next,o.next.prev=o.prev,o.next=o.prev=null,o=u}if(o==null){n=null;break}}else o=o.next}if(n!=null){let c;for(;;){for(c=!1,o=n,p=!0;p||o!=n;){p=!1;let h=o.prev,u=o.x-h.x,x=o.y-h.y,y=o.next.x-o.x,_=(o.next.y-o.y)*u-y*x;if(_*_>=me().Config.epsilon*me().Config.epsilon)o=o.next;else{if(o==n&&(n=o.next,p=!0),o!=null&&o.prev==o)o.next=o.prev=null,o=null;else{let f=o.next;o.prev.next=o.next,o.next.prev=o.prev,o.next=o.prev=null,o=f}if(c=!0,o==null){c=!1,n=null;break}}}if(!c)break}}n!=null&&t.add(n)}return s}};rn.zpp_pool=null,rn.sharedPPList=null,rn.sharedGVList=null;var ji=rn;var De=class De{static bisector(e){let t=e.prev,n=e.next,s=e.x-t.x,i=e.y-t.y,l=n.x-e.x,r=n.y-e.y,a;le.zpp_pool==null?a=new le:(a=le.zpp_pool,le.zpp_pool=a.next,a.next=null),a.weak=!1,a._immutable=!1,a.x=-i-r,a.y=s+l;let o=a,p=o.x*o.x+o.y*o.y,h=1/Math.sqrt(p);return o.x*=h,o.y*=h,r*s-l*i<0&&(o.x=-o.x,o.y=-o.y),o}static below(e,t){if(e.y<t.y)return!0;if(e.y>t.y)return!1;if(e.x<t.x)return!0;if(e.x>t.x)return!1;{let n=De.bisector(e),s=De.bisector(t),i=1;n.x+=e.x*i,n.y+=e.y*i;let l=1;s.x+=t.x*l,s.y+=t.y*l;let r=n.x<s.x||n.x==s.x&&n.y<s.y;return n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=le.zpp_pool,le.zpp_pool=n,s.outer!=null&&(s.outer.zpp_inner=null,s.outer=null),s._isimmutable=null,s._validate=null,s._invalidate=null,s.next=le.zpp_pool,le.zpp_pool=s,r}}static above(e,t){return De.below(t,e)}static left_vertex(e){let t=e.prev;return t.y>e.y?!0:t.y==e.y?e.next.y<e.y:!1}static isMonotone(e){let t=e,n=e,s=e.next,i=e;if(s!=null){let a=s;for(;;){let o=a;if(o.y<t.y&&(t=o),o.y>n.y&&(n=o),a=a.next,a==i)break}}let l=!0,r=t;if(n!=t.next){let a=t.next,o=n;if(a!=null){let p=a;for(;;){let c=p;if(c.y<r.y){l=!1;break}if(r=c,p=p.next,p==o)break}}}if(!l)return!1;if(r=t,n!=t.prev){let a=t.prev,o=n;if(a!=null){let p=a;for(;;){let c=p;if(c.y<r.y){l=!1;break}if(r=c,p=p.prev,p==o)break}}}return l}static getShared(){return De.sharedPPoly==null&&(De.sharedPPoly=new ji),De.sharedPPoly}static decompose(e,t){if(t==null?t=new ji(e):t.init(e),t.vertices==null)return t;De.queue==null&&(De.queue=new pi);let n=t.vertices,s=t.vertices;if(n!=null){let l=n;for(;;){let r=l;De.queue.add(r);let a=r.next.x-r.x,o=r.next.y-r.y,p=r.prev.x-r.x,h=(r.prev.y-r.y)*a-p*o>0;if(r.type=De.below(r.prev,r)?De.below(r.next,r)?h?0:3:4:De.below(r,r.next)?h?1:2:4,l=l.next,l==s)break}}let i=De.queue;if(i.head!=null&&i.head.next!=null){let l=i.head,r,a,o,p,c=1,h,u,x;for(;;){for(h=0,a=l,l=null,r=l;a!=null;){for(++h,o=a,u=0,x=c;o!=null&&u<c;)++u,o=o.next;for(;u>0||x>0&&o!=null;)u==0?(p=o,o=o.next,--x):x==0||o==null||De.above(a.elt,o.elt)?(p=a,a=a.next,--u):(p=o,o=o.next,--x),r!=null?r.next=p:l=p,r=p;a=o}if(r.next=null,c<<=1,!(h>1))break}i.head=l,i.modified=!0,i.pushmod=!0}for(De.edges==null&&(ds.zpp_pool==null?De.edges=new ds:(De.edges=ds.zpp_pool,ds.zpp_pool=De.edges.next,De.edges.next=null),De.edges.lt=Ge.edge_lt,De.edges.swapped=Ge.edge_swap);De.queue.head!=null;){let l=De.queue.pop_unsafe();switch(l.type){case 0:l.helper=l,l.node=De.edges.insert(l);break;case 1:{let r=l.prev;if(r.helper==null)throw new Error("Fatal error (1): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),De.edges.remove_node(r.node),r.helper=null;break}case 2:{let r=l.prev;if(r.helper==null)throw new Error("Fatal error (3): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),De.edges.remove_node(r.node),r.helper=null;let a=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){a=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else{for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent}}}let o=a;if(o!=null){if(o.helper==null)throw new Error("Fatal error (4): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(l,o.helper),o.helper=l}break}case 3:{let r=null;if(!De.edges.empty()){let o=De.edges.parent;for(;o.prev!=null;)o=o.prev;for(;o!=null;){let p=o.data;if(!Ge.vert_lt(p,l)){r=p;break}if(o.next!=null)for(o=o.next;o.prev!=null;)o=o.prev;else{for(;o.parent!=null&&o==o.parent.next;)o=o.parent;o=o.parent}}}let a=r;if(a!=null){if(a.helper==null)throw new Error("Fatal error (2): Polygon is not weakly-simple and clockwise");t.add_diagonal(l,a.helper),a.helper=l}l.node=De.edges.insert(l),l.helper=l;break}case 4:{let r=l.prev;if(De.left_vertex(l)){if(r.helper==null)throw new Error("Fatal error (5): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),De.edges.remove_node(r.node),r.helper=null,l.node=De.edges.insert(l),l.helper=l}else{let a=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){a=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else{for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent}}}let o=a;if(o==null||o.helper==null)throw new Error("Fatal error (6): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(l,o.helper),o.helper=l}break}}}return t}};De.queue=null,De.edges=null,De.sharedPPoly=null;var pl=De;var Ti=class Ti{constructor(){this.node=null;this.di=0;this.id=0;this.b=null;this.a=null;this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null}static get(e,t){let n;return Ti.zpp_pool==null?n=new Ti:(n=Ti.zpp_pool,Ti.zpp_pool=n.next,n.next=null),n.a=e,n.b=t,e.id<t.id?(n.id=e.id,n.di=t.id):(n.id=t.id,n.di=e.id),n}static edge_swap(e,t){let n=e.node;e.node=t.node,t.node=n}static edge_lt(e,t){return e.id>=t.id?e.id==t.id?e.di<t.di:!1:!0}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){this.a=this.b=null,this.node=null}alloc(){}};Ti.zpp_pool=null;var Ot=Ti;var St=class St{constructor(){this.zip_dir=!1;this.absnormaly=0;this.absnormalx=0;this.normaly=0;this.normalx=0;this.idiry=0;this.idirx=0;this.diry=0;this.dirx=0;this.originy=0;this.originx=0;this.userData=null;this.maxdist=0;this.direction=null;this.origin=null;let e=me(),t;if(_e.poolVec2==null?t=new e.geom.Vec2:(t=_e.poolVec2,_e.poolVec2=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t==_e.nextVec2&&(_e.nextVec2=null)),t.zpp_inner==null){let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,t.zpp_inner=s,t.zpp_inner.outer=t}else{if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=t.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=t.zpp_inner;if(l._validate!=null&&l._validate(),t.zpp_inner.x==0){if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=t.zpp_inner;r._validate!=null&&r._validate(),i=t.zpp_inner.y==0}else i=!1;if(!i){t.zpp_inner.x=0,t.zpp_inner.y=0;let r=t.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}t.zpp_inner.weak=!1,this.origin=t,this.origin.zpp_inner._invalidate=s=>this.origin_invalidate(s);let n;if(_e.poolVec2==null?n=new e.geom.Vec2:(n=_e.poolVec2,_e.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==_e.nextVec2&&(_e.nextVec2=null)),n.zpp_inner==null){let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){n.zpp_inner.x=0,n.zpp_inner.y=0;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}n.zpp_inner.weak=!1,this.direction=n,this.direction.zpp_inner._invalidate=s=>this.direction_invalidate(s),this.originx=0,this.originy=0,this.dirx=0,this.diry=0,this.zip_dir=!1}origin_invalidate(e){this.originx=e.x,this.originy=e.y}direction_invalidate(e){this.dirx=e.x,this.diry=e.y,this.zip_dir=!0}invalidate_dir(){this.zip_dir=!0}validate_dir(){if(this.zip_dir){this.zip_dir=!1;let e=me();if(this.dirx*this.dirx+this.diry*this.diry<e.Config.epsilon)throw new Error("Error: Ray::direction is degenerate");let t=this.dirx*this.dirx+this.diry*this.diry,n=1/Math.sqrt(t);this.dirx*=n,this.diry*=n,this.idirx=1/this.dirx,this.idiry=1/this.diry,this.normalx=-this.diry,this.normaly=this.dirx;let s=this.normalx;this.absnormalx=s<0?-s:s;let i=this.normaly;this.absnormaly=i<0?-i:i}}rayAABB(){let e=this.originx,t=e,n=this.originy,s=n;if(this.maxdist>=1/0?(this.dirx>0?t=1/0:this.dirx<0&&(t=-1/0),this.diry>0?s=1/0:this.diry<0&&(s=-1/0)):(t+=this.maxdist*this.dirx,s+=this.maxdist*this.diry),t<e){let l=e;e=t,t=l}if(s<n){let l=n;n=s,s=l}let i;return be.zpp_pool==null?i=new be:(i=be.zpp_pool,be.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=n,i.maxx=t,i.maxy=s,i}aabbtest(e){let t=this.normalx*(this.originx-.5*(e.minx+e.maxx))+this.normaly*(this.originy-.5*(e.miny+e.maxy)),n=this.absnormalx*.5*(e.maxx-e.minx)+this.absnormaly*.5*(e.maxy-e.miny),s=t;return(s<0?-s:s)<n}aabbsect(e){let t=this.originx>=e.minx&&this.originx<=e.maxx,n=this.originy>=e.miny&&this.originy<=e.maxy;if(t&&n)return 0;{let s=-1;for(;!(this.dirx>=0&&this.originx>=e.maxx)&&!(this.dirx<=0&&this.originx<=e.minx||this.diry>=0&&this.originy>=e.maxy||this.diry<=0&&this.originy<=e.miny);){if(this.dirx>0){let i=(e.minx-this.originx)*this.idirx;if(i>=0&&i<=this.maxdist){let l=this.originy+i*this.diry;if(l>=e.miny&&l<=e.maxy){s=i;break}}}else if(this.dirx<0){let i=(e.maxx-this.originx)*this.idirx;if(i>=0&&i<=this.maxdist){let l=this.originy+i*this.diry;if(l>=e.miny&&l<=e.maxy){s=i;break}}}if(this.diry>0){let i=(e.miny-this.originy)*this.idiry;if(i>=0&&i<=this.maxdist){let l=this.originx+i*this.dirx;if(l>=e.minx&&l<=e.maxx){s=i;break}}}else if(this.diry<0){let i=(e.maxy-this.originy)*this.idiry;if(i>=0&&i<=this.maxdist){let l=this.originx+i*this.dirx;if(l>=e.minx&&l<=e.maxx){s=i;break}}}break}return s}}static _allocVec2(e,t){let n=me();if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(_e.poolVec2==null?s=new n.geom.Vec2:(s=_e.poolVec2,_e.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==_e.nextVec2&&(_e.nextVec2=null)),s.zpp_inner==null){let i;le.zpp_pool==null?i=new le:(i=le.zpp_pool,le.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=e,i.y=t,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;s.zpp_inner._validate!=null&&s.zpp_inner._validate(),s.zpp_inner.x==e?(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l=s.zpp_inner.y==t):l=!1,l||(s.zpp_inner.x=e,s.zpp_inner.y=t,s.zpp_inner._invalidate!=null&&s.zpp_inner._invalidate(s.zpp_inner))}return s.zpp_inner.weak=!1,s}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let s=1;n.localCOMx+=n.lverts.next.next.x*s,n.localCOMy+=n.lverts.next.next.y*s;let i=.5;n.localCOMx*=i,n.localCOMy*=i}else{n.localCOMx=0,n.localCOMy=0;let s=0,i=n.lverts.next,l=i;i=i.next;let r=i;for(i=i.next;i!=null;){let u=i;s+=r.x*(u.y-l.y);let x=u.y*r.x-u.x*r.y;n.localCOMx+=(r.x+u.x)*x,n.localCOMy+=(r.y+u.y)*x,l=r,r=u,i=i.next}i=n.lverts.next;let a=i;s+=r.x*(a.y-l.y);let o=a.y*r.x-a.x*r.y;n.localCOMx+=(r.x+a.x)*o,n.localCOMy+=(r.y+a.y)*o,l=r,r=a,i=i.next;let p=i;s+=r.x*(p.y-l.y);let c=p.y*r.x-p.x*r.y;n.localCOMx+=(r.x+p.x)*c,n.localCOMy+=(r.y+p.y)*c,s=1/(3*s);let h=s;n.localCOMx*=h,n.localCOMy*=h}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}_circleNormal(e,t,n){let s=this.originx+this.dirx*e,i=this.originy+this.diry*e;s-=t.worldCOMx,i-=t.worldCOMy;let l=s*s+i*i,r=1/Math.sqrt(l);return s*=r,i*=r,n&&(s=-s,i=-i),{nx:s,ny:i}}static _insertSorted(e,t){let n=null,s=e.zpp_inner.inner.head;for(;s!=null;){let r=s.elt;if(t.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(t.zpp_inner.toiDistance<r.zpp_inner.toiDistance)break;n=s,s=s.next}let i=e.zpp_inner.inner,l;us.zpp_pool==null?l=new us:(l=us.zpp_pool,us.zpp_pool=l.next,l.next=null),l.elt=t,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++}circlesect(e,t,n){St._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,r=2*(s*this.dirx+i*this.diry),a=s*s+i*i-e.radius*e.radius,o=r*r-4*l*a;if(o==0){let p=-r/2*l;if((!t||a>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,a<=0),h=St._allocVec2(c.nx,c.ny);return dn.getRay(h,p,a<=0,e.outer)}else return null}else{o=Math.sqrt(o),l=1/(2*l);let p=(-r-o)*l,c=(-r+o)*l;if(p>0)if(p<n&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=St._allocVec2(h.nx,h.ny);return dn.getRay(u,p,!1,e.outer)}else return null;else if(c>0&&t)if(c<n&&c<=this.maxdist){let h=this._circleNormal(c,e,!0),u=St._allocVec2(h.nx,h.ny);return dn.getRay(u,c,!0,e.outer)}else return null;else return null}}circlesect2(e,t,n){St._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,r=2*(s*this.dirx+i*this.diry),a=s*s+i*i-e.radius*e.radius,o=r*r-4*l*a;if(o==0){let p=-r/2*l;if((!t||a>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,a<=0),h=St._allocVec2(c.nx,c.ny),u=dn.getRay(h,p,a<=0,e.outer);St._insertSorted(n,u)}}else{o=Math.sqrt(o),l=1/(2*l);let p=(-r-o)*l,c=(-r+o)*l;if(p>0&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=St._allocVec2(h.nx,h.ny),x=dn.getRay(u,p,!1,e.outer);St._insertSorted(n,x)}if(c>0&&c<=this.maxdist&&t){let h=this._circleNormal(c,e,!0),u=St._allocVec2(h.nx,h.ny),x=dn.getRay(u,c,!0,e.outer);St._insertSorted(n,x)}}}polysect(e,t,n){let s=me(),i=n,l=null,r=e.edges.head,a=!0,o=e.gverts.next,p=o,c=o.next;for(;c!=null;){let h=c,u=r.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,y=h.y-p.y,d=p.x-this.originx,_=p.y-this.originy,f=y*this.dirx-x*this.diry;if(f*f>s.Config.epsilon){f=1/f;let z=(y*d-x*_)*f;if(z>0&&z<i&&z<=this.maxdist){let P=(this.diry*d-this.dirx*_)*f;P>-s.Config.epsilon&&P<1+s.Config.epsilon&&(i=z,l=r.elt)}}}r=r.next,p=h,c=c.next}if(a){c=e.gverts.next;let h=c,u=r.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,y=h.y-p.y,d=p.x-this.originx,_=p.y-this.originy,f=y*this.dirx-x*this.diry;if(f*f>s.Config.epsilon){f=1/f;let z=(y*d-x*_)*f;if(z>0&&z<i&&z<=this.maxdist){let P=(this.diry*d-this.dirx*_)*f;P>-s.Config.epsilon&&P<1+s.Config.epsilon&&(i=z,l=r.elt)}}}}if(l!=null){let h=l.gnormx,u=l.gnormy,x=h*this.dirx+u*this.diry>0;x&&(h=-h,u=-u);let y=St._allocVec2(h,u);return dn.getRay(y,i,x,e.outer)}else return null}polysect2(e,t,n){let s=me(),i=1/0,l=-1,r=null,a=null,o=e.edges.head,p=!0,c=e.gverts.next,h=c,u=c.next;for(;u!=null;){let x=u,y=o.elt;if(t||y.gnormx*this.dirx+y.gnormy*this.diry<0){let d=x.x-h.x,_=x.y-h.y,f=h.x-this.originx,z=h.y-this.originy,P=_*this.dirx-d*this.diry;if(P*P>s.Config.epsilon){P=1/P;let k=(_*f-d*z)*P;if(k>0&&k<=this.maxdist&&(k<i||k>l)){let m=(this.diry*f-this.dirx*z)*P;m>-s.Config.epsilon&&m<1+s.Config.epsilon&&(k<i&&(i=k,r=o.elt),k>l&&(l=k,a=o.elt))}}}o=o.next,h=x,u=u.next}if(p){u=e.gverts.next;let x=u,y=o.elt;if(t||y.gnormx*this.dirx+y.gnormy*this.diry<0){let d=x.x-h.x,_=x.y-h.y,f=h.x-this.originx,z=h.y-this.originy,P=_*this.dirx-d*this.diry;if(P*P>s.Config.epsilon){P=1/P;let k=(_*f-d*z)*P;if(k>0&&k<=this.maxdist&&(k<i||k>l)){let m=(this.diry*f-this.dirx*z)*P;m>-s.Config.epsilon&&m<1+s.Config.epsilon&&(k<i&&(i=k,r=o.elt),k>l&&(l=k,a=o.elt))}}}}if(r!=null){let x=r.gnormx,y=r.gnormy,d=x*this.dirx+y*this.diry>0;d&&(x=-x,y=-y);let _=St._allocVec2(x,y),f=dn.getRay(_,i,d,e.outer);St._insertSorted(n,f)}if(a!=null&&r!=a){let x=a.gnormx,y=a.gnormy,d=x*this.dirx+y*this.diry>0;d&&(x=-x,y=-y);let _=St._allocVec2(x,y),f=dn.getRay(_,l,d,e.outer);St._insertSorted(n,f)}}};St.internal=!1;var cl=St;var mi=class mi{constructor(){this.forced=!1;this.x=0;this.y=0;this.links=null;this.id=0;this.next=null;this.node=null;this.id=un.ZPP_SimpleVert(),Xt.zpp_pool==null?this.links=new Xt:(this.links=Xt.zpp_pool,Xt.zpp_pool=this.links.next,this.links.next=null),this.links.lt=mi.less_xy}static less_xy(e,t){return e.y<t.y?!0:e.y==t.y?e.x<t.x:!1}static swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}static get(e,t){let n;return mi.zpp_pool==null?n=new mi:(n=mi.zpp_pool,mi.zpp_pool=n.next,n.next=null),n.x=e,n.y=t,n}free(){this.links.clear(),this.node=null,this.forced=!1}alloc(){}};mi.zpp_pool=null;var ke=mi;var Li=class Li{constructor(){this.left=null;this.right=null;this.vertices=null;this.id=0;this.next=null;this.prev=null;this.node=null;this.id=un.ZPP_SimpleSeg(),Xt.zpp_pool==null?this.vertices=new Xt:(this.vertices=Xt.zpp_pool,Xt.zpp_pool=this.vertices.next,this.vertices.next=null),this.vertices.lt=(e,t)=>this.less_xy(e,t)}static get(e,t){let n;return Li.zpp_pool==null?n=new Li:(n=Li.zpp_pool,Li.zpp_pool=n.next,n.next=null),n.left=e,n.right=t,n.vertices.insert(e),n.vertices.insert(t),n}free(){this.left=this.right=null,this.prev=null,this.node=null,this.vertices.clear()}alloc(){}less_xy(e,t){return e.x<t.x?!0:e.x==t.x?e.y<t.y:!1}};Li.zpp_pool=null;var At=Li;var Fi=class Fi{constructor(){this.type=0;this.vertex=null;this.segment=null;this.segment2=null;this.node=null;this.next=null}static swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}static less_xy(e,t){return e.vertex.x<t.vertex.x?!0:e.vertex.x>t.vertex.x?!1:e.vertex.y<t.vertex.y?!0:e.vertex.y>t.vertex.y?!1:e.type<t.type}static get(e){let t;return Fi.zpp_pool==null?t=new Fi:(t=Fi.zpp_pool,Fi.zpp_pool=t.next,t.next=null),t.vertex=e,t}free(){this.vertex=null,this.segment=this.segment2=null,this.node=null}alloc(){}};Fi.zpp_pool=null;var ge=Fi;var Di=class{constructor(){this.sweepx=0;this.tree=null;xs.zpp_pool==null?this.tree=new xs:(this.tree=xs.zpp_pool,xs.zpp_pool=this.tree.next,this.tree.next=null),this.tree.lt=(e,t)=>this.edge_lt(e,t),this.tree.swapped=(e,t)=>this.swap_nodes(e,t)}swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}edge_lt(e,t){let n=e.left,s=e.right,i=t.left,l=t.right,r,a,o,p,c;if(e.left==t.left&&e.right==t.right)return!1;if(e.left==t.right)return n.x==s.x?n.y<s.y?n.y>i.y:s.y>i.y:(c=s.x<n.x,r=s.x-n.x,a=s.y-n.y,o=i.x-n.x,p=i.y-n.y,(c?a*o-r*p:p*r-o*a)<0);if(e.right==t.left){let h;return i.x==l.x?h=i.y<l.y?i.y>n.y:l.y>n.y:(c=l.x<i.x,r=l.x-i.x,a=l.y-i.y,o=n.x-i.x,p=n.y-i.y,h=(c?a*o-r*p:p*r-o*a)<0),!h}else{if(e.left==t.left)return n.x==s.x?n.y<s.y?n.y>l.y:s.y>l.y:(c=s.x<n.x,r=s.x-n.x,a=s.y-n.y,o=l.x-n.x,p=l.y-n.y,(c?a*o-r*p:p*r-o*a)<0);if(e.right==t.right)return n.x==s.x?n.y<s.y?n.y>i.y:s.y>i.y:(c=s.x<n.x,r=s.x-n.x,a=s.y-n.y,o=i.x-n.x,p=i.y-n.y,(c?a*o-r*p:p*r-o*a)<0)}if(n.x==s.x)if(i.x==l.x){let h=n.y<s.y?s:n,u=i.y<l.y?l:i;return h.y>u.y}else{c=l.x<i.x,r=l.x-i.x,a=l.y-i.y,o=n.x-i.x,p=n.y-i.y;let h=c?a*o-r*p:p*r-o*a;c=l.x<i.x,r=l.x-i.x,a=l.y-i.y,o=s.x-i.x,p=s.y-i.y;let u=c?a*o-r*p:p*r-o*a;return h*u>=0?h>=0:this.sweepx>=n.x}else if(i.x==l.x){c=s.x<n.x,r=s.x-n.x,a=s.y-n.y,o=i.x-n.x,p=i.y-n.y;let h=c?a*o-r*p:p*r-o*a;c=s.x<n.x,r=s.x-n.x,a=s.y-n.y,o=l.x-n.x,p=l.y-n.y;let u=c?a*o-r*p:p*r-o*a;return h*u>=0?h<0:this.sweepx<i.x}else{c=s.x<n.x,r=s.x-n.x,a=s.y-n.y,o=i.x-n.x,p=i.y-n.y;let h=(c?a*o-r*p:p*r-o*a)<0;c=s.x<n.x,r=s.x-n.x,a=s.y-n.y,o=l.x-n.x,p=l.y-n.y;let u=(c?a*o-r*p:p*r-o*a)<0;if(h==u)return h;{c=l.x<i.x,r=l.x-i.x,a=l.y-i.y,o=n.x-i.x,p=n.y-i.y;let x=(c?a*o-r*p:p*r-o*a)>=0;c=l.x<i.x,r=l.x-i.x,a=l.y-i.y,o=s.x-i.x,p=s.y-i.y;let y=(c?a*o-r*p:p*r-o*a)>=0;if(x==y)return x;let d=(this.sweepx-n.x)/(s.x-n.x)*(s.y-n.y)+n.y,_=(this.sweepx-i.x)/(l.x-i.x)*(l.y-i.y)+i.y;return d>_}}}clear(){this.tree.clear()}add(e){e.node=this.tree.insert(e);let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);return t!=null&&(e.next=t.data,t.data.prev=e),n!=null&&(e.prev=n.data,n.data.next=e),e}remove(e){let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);t!=null&&(t.data.prev=e.prev),n!=null&&(n.data.next=e.next),this.tree.remove_node(e.node),e.node=null}intersect(e,t){if(e==null||t==null)return!1;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return!1;{let n=e.left,s=e.right,i=t.left,l=t.right,r=(i.x-n.x)*(s.y-n.y)-(s.x-n.x)*(i.y-n.y),a=(l.x-n.x)*(s.y-n.y)-(s.x-n.x)*(l.y-n.y);if(r*a>0)return!1;{let o=(n.x-i.x)*(l.y-i.y)-(l.x-i.x)*(n.y-i.y),p=(s.x-i.x)*(l.y-i.y)-(l.x-i.x)*(s.y-i.y);return!(o*p>0)}}}intersection(e,t){if(e==null||t==null)return null;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return null;{let n=e.left,s=e.right,i=t.left,l=t.right,r=s.x-n.x,a=s.y-n.y,o=l.x-i.x,p=l.y-i.y,c=p*r-o*a;if(c==0)return null;c=1/c;let h=i.x-n.x,u=i.y-n.y,x=(p*h-o*u)*c;if(x<0||x>1)return null;let y=(a*h-r*u)*c;if(y<0||y>1)return null;let d;if(y==0||y==1||x==0||x==1){let z=y==0;if(y==1&&z)throw new Error("corner case 1a");if(y==1&&(z=!0),x==0&&z)throw new Error("corner case 1b");if(x==0&&(z=!0),x==1&&z)throw new Error("corner case 1c");d=y==0?i:y==1?l:x==0?n:s}else{let z=.5*(n.x+r*x+i.x+o*y),P=.5*(n.y+a*x+i.y+p*y),k;ke.zpp_pool==null?k=new ke:(k=ke.zpp_pool,ke.zpp_pool=k.next,k.next=null),k.x=z,k.y=P,d=k}let _;ge.zpp_pool==null?_=new ge:(_=ge.zpp_pool,ge.zpp_pool=_.next,_.next=null),_.vertex=d;let f=_;return f.type=0,f.segment=e,f.segment2=t,f}}};var xe=class xe{static decompose(e,t){xe.sweep==null&&(xe.sweep=new Di,xe.inthash=new Oi),xe.vertices==null&&(Xt.zpp_pool==null?xe.vertices=new Xt:(xe.vertices=Xt.zpp_pool,Xt.zpp_pool=xe.vertices.next,xe.vertices.next=null),xe.vertices.lt=ke.less_xy,xe.vertices.swapped=ke.swap_nodes),xe.queue==null&&(Jn.zpp_pool==null?xe.queue=new Jn:(xe.queue=Jn.zpp_pool,Jn.zpp_pool=xe.queue.next,xe.queue.next=null),xe.queue.lt=ge.less_xy,xe.queue.swapped=ge.swap_nodes);let n=null,s=null,i=e,l=e;if(i!=null){let x=i;for(;;){let y=x,d=y.x,_=y.y,f;ke.zpp_pool==null?f=new ke:(f=ke.zpp_pool,ke.zpp_pool=f.next,f.next=null),f.x=d,f.y=_;let z=f,P=xe.vertices.parent;for(;P!=null;)if(xe.vertices.lt(z,P.data))P=P.prev;else if(xe.vertices.lt(P.data,z))P=P.next;else break;let k=P;if(k!=null){let m=z;m.links.clear(),m.node=null,m.forced=!1,m.next=ke.zpp_pool,ke.zpp_pool=m,z=k.data}else z.node=xe.vertices.insert(z);if(s!=null){let m;ge.zpp_pool==null?m=new ge:(m=ge.zpp_pool,ge.zpp_pool=m.next,m.next=null),m.vertex=s;let b=m,C;ge.zpp_pool==null?C=new ge:(C=ge.zpp_pool,ge.zpp_pool=C.next,C.next=null),C.vertex=z;let v=C,w;ge.less_xy(b,v)?(b.type=1,v.type=2,w=At.get(s,z)):(b.type=2,v.type=1,w=At.get(z,s)),b.segment=v.segment=w,xe.queue.insert(b),xe.queue.insert(v),s.links.insert(z),z.links.insert(s)}if(s=z,n==null&&(n=z),x=x.next,x==l)break}}let r;ge.zpp_pool==null?r=new ge:(r=ge.zpp_pool,ge.zpp_pool=r.next,r.next=null),r.vertex=s;let a=r,o;ge.zpp_pool==null?o=new ge:(o=ge.zpp_pool,ge.zpp_pool=o.next,o.next=null),o.vertex=n;let p=o,c;for(ge.less_xy(a,p)?(a.type=1,p.type=2,c=At.get(s,n)):(a.type=2,p.type=1,c=At.get(n,s)),a.segment=p.segment=c,xe.queue.insert(a),xe.queue.insert(p),s.links.insert(n),n.links.insert(s),xe.ints==null&&(Jn.zpp_pool==null?xe.ints=new Jn:(xe.ints=Jn.zpp_pool,Jn.zpp_pool=xe.ints.next,xe.ints.next=null),xe.ints.lt=ge.less_xy);!xe.queue.empty();){let x=xe.queue.pop_front();if(xe.sweep.sweepx=x.vertex.x,x.type==1){let d=x.segment;if(xe.sweep.add(d),d.next!=null&&d!=null&&!(d.next.id<d.id?xe.inthash.has(d.next.id,d.id):xe.inthash.has(d.id,d.next.id))){let _=xe.sweep.intersection(d.next,d);if(_!=null)if(_.vertex.x>=xe.sweep.sweepx){let f=xe.queue.parent;for(;f!=null;)if(xe.queue.lt(_,f.data))f=f.prev;else if(xe.queue.lt(f.data,_))f=f.next;else break;let z=f;if(z==null){let P=xe.ints.parent;for(;P!=null;)if(xe.ints.lt(_,P.data))P=P.prev;else if(xe.ints.lt(P.data,_))P=P.next;else break;let k=P;if(k!=null){let m=_.vertex;m.links.clear(),m.node=null,m.forced=!1,m.next=ke.zpp_pool,ke.zpp_pool=m,_.vertex=k.data.vertex,k.data=_,xe.queue.insert(_)}else xe.queue.insert(_),xe.ints.insert(_);if(d.next.id<d.id){let m=xe.inthash,b=d.next.id,C=d.id,v;je.zpp_pool==null?v=new je:(v=je.zpp_pool,je.zpp_pool=v.next,v.next=null),v.id=b,v.di=C;let w=v;w.value=!0,m.add(w)}else{let m=xe.inthash,b=d.id,C=d.next.id,v;je.zpp_pool==null?v=new je:(v=je.zpp_pool,je.zpp_pool=v.next,v.next=null),v.id=b,v.di=C;let w=v;w.value=!0,m.add(w)}}else{let P=z.data;if(P.segment!=_.segment||_.segment2!=P.segment2)throw new Error("corner case 2, shiiiit.");let k=_.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=ke.zpp_pool,ke.zpp_pool=k;let m=_;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=ge.zpp_pool,ge.zpp_pool=m}}else{let f=_.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f;let z=_;z.vertex=null,z.segment=z.segment2=null,z.node=null,z.next=ge.zpp_pool,ge.zpp_pool=z}}if(d!=null&&d.prev!=null&&!(d.id<d.prev.id?xe.inthash.has(d.id,d.prev.id):xe.inthash.has(d.prev.id,d.id))){let _=xe.sweep.intersection(d,d.prev);if(_!=null)if(_.vertex.x>=xe.sweep.sweepx){let f=xe.queue.parent;for(;f!=null;)if(xe.queue.lt(_,f.data))f=f.prev;else if(xe.queue.lt(f.data,_))f=f.next;else break;let z=f;if(z==null){let P=xe.ints.parent;for(;P!=null;)if(xe.ints.lt(_,P.data))P=P.prev;else if(xe.ints.lt(P.data,_))P=P.next;else break;let k=P;if(k!=null){let m=_.vertex;m.links.clear(),m.node=null,m.forced=!1,m.next=ke.zpp_pool,ke.zpp_pool=m,_.vertex=k.data.vertex,k.data=_,xe.queue.insert(_)}else xe.queue.insert(_),xe.ints.insert(_);if(d.id<d.prev.id){let m=xe.inthash,b=d.id,C=d.prev.id,v;je.zpp_pool==null?v=new je:(v=je.zpp_pool,je.zpp_pool=v.next,v.next=null),v.id=b,v.di=C;let w=v;w.value=!0,m.add(w)}else{let m=xe.inthash,b=d.prev.id,C=d.id,v;je.zpp_pool==null?v=new je:(v=je.zpp_pool,je.zpp_pool=v.next,v.next=null),v.id=b,v.di=C;let w=v;w.value=!0,m.add(w)}}else{let P=z.data;if(P.segment!=_.segment||_.segment2!=P.segment2)throw new Error("corner case 2, shiiiit.");let k=_.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=ke.zpp_pool,ke.zpp_pool=k;let m=_;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=ge.zpp_pool,ge.zpp_pool=m}}else{let f=_.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f;let z=_;z.vertex=null,z.segment=z.segment2=null,z.node=null,z.next=ge.zpp_pool,ge.zpp_pool=z}}}else if(x.type==2){let d=x.segment;if(d.node!=null){let _=d.next,f=d.prev;xe.sweep.remove(d);let z=d;if(z.left=z.right=null,z.prev=null,z.node=null,z.vertices.clear(),z.next=At.zpp_pool,At.zpp_pool=z,_!=null&&f!=null&&!(_.id<f.id?xe.inthash.has(_.id,f.id):xe.inthash.has(f.id,_.id))){let P=xe.sweep.intersection(_,f);if(P!=null)if(P.vertex.x>=xe.sweep.sweepx){let k=xe.queue.parent;for(;k!=null;)if(xe.queue.lt(P,k.data))k=k.prev;else if(xe.queue.lt(k.data,P))k=k.next;else break;let m=k;if(m==null){let b=xe.ints.parent;for(;b!=null;)if(xe.ints.lt(P,b.data))b=b.prev;else if(xe.ints.lt(b.data,P))b=b.next;else break;let C=b;if(C!=null){let v=P.vertex;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v,P.vertex=C.data.vertex,C.data=P,xe.queue.insert(P)}else xe.queue.insert(P),xe.ints.insert(P);if(_.id<f.id){let v=xe.inthash,w=_.id,O=f.id,E;je.zpp_pool==null?E=new je:(E=je.zpp_pool,je.zpp_pool=E.next,E.next=null),E.id=w,E.di=O;let M=E;M.value=!0,v.add(M)}else{let v=xe.inthash,w=f.id,O=_.id,E;je.zpp_pool==null?E=new je:(E=je.zpp_pool,je.zpp_pool=E.next,E.next=null),E.id=w,E.di=O;let M=E;M.value=!0,v.add(M)}}else{let b=m.data;if(b.segment!=P.segment||P.segment2!=b.segment2)throw new Error("corner case 2, shiiiit.");let C=P.vertex;C.links.clear(),C.node=null,C.forced=!1,C.next=ke.zpp_pool,ke.zpp_pool=C;let v=P;v.vertex=null,v.segment=v.segment2=null,v.node=null,v.next=ge.zpp_pool,ge.zpp_pool=v}}else{let k=P.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=ke.zpp_pool,ke.zpp_pool=k;let m=P;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=ge.zpp_pool,ge.zpp_pool=m}}}}else{let d=x.vertex,_=d.node==null,f=x.segment,z=x.segment2;if(z.next!=f){let C=f;f=z,z=C}let P=f.vertices.parent;for(;P!=null;)if(f.vertices.lt(d,P.data))P=P.prev;else if(f.vertices.lt(P.data,d))P=P.next;else break;let k=P==null,m=z.vertices.parent;for(;m!=null;)if(z.vertices.lt(d,m.data))m=m.prev;else if(z.vertices.lt(m.data,d))m=m.next;else break;let b=m==null;if(k){let C=f.vertices.insert(d),v=d==f.left?d:f.vertices.predecessor_node(C).data,w=d==f.right?d:f.vertices.successor_node(C).data;v.links.remove(w),d!=v&&v.links.insert(d),w.links.remove(v),d!=w&&w.links.insert(d),d!=v&&d.links.insert(v),d!=w&&d.links.insert(w)}if(b){let C=z.vertices.insert(d),v=d==z.left?d:z.vertices.predecessor_node(C).data,w=d==z.right?d:z.vertices.successor_node(C).data;v.links.remove(w),d!=v&&v.links.insert(d),w.links.remove(v),d!=w&&w.links.insert(d),d!=v&&d.links.insert(v),d!=w&&d.links.insert(w)}if(_&&(d.node=xe.vertices.insert(d)),d.forced=!0,_){let C=f.node,v=z.node;C.data=z,v.data=f,f.node=v,z.node=C,z.next=f.next,f.next=z,f.prev=z.prev,z.prev=f,f.prev!=null&&(f.prev.next=f),z.next!=null&&(z.next.prev=z)}if(z.next!=null&&z!=null&&!(z.next.id<z.id?xe.inthash.has(z.next.id,z.id):xe.inthash.has(z.id,z.next.id))){let C=xe.sweep.intersection(z.next,z);if(C!=null)if(C.vertex.x>=xe.sweep.sweepx){let v=xe.queue.parent;for(;v!=null;)if(xe.queue.lt(C,v.data))v=v.prev;else if(xe.queue.lt(v.data,C))v=v.next;else break;let w=v;if(w==null){let O=xe.ints.parent;for(;O!=null;)if(xe.ints.lt(C,O.data))O=O.prev;else if(xe.ints.lt(O.data,C))O=O.next;else break;let E=O;if(E!=null){let M=C.vertex;M.links.clear(),M.node=null,M.forced=!1,M.next=ke.zpp_pool,ke.zpp_pool=M,C.vertex=E.data.vertex,E.data=C,xe.queue.insert(C)}else xe.queue.insert(C),xe.ints.insert(C);if(z.next.id<z.id){let M=xe.inthash,N=z.next.id,Z=z.id,S;je.zpp_pool==null?S=new je:(S=je.zpp_pool,je.zpp_pool=S.next,S.next=null),S.id=N,S.di=Z;let V=S;V.value=!0,M.add(V)}else{let M=xe.inthash,N=z.id,Z=z.next.id,S;je.zpp_pool==null?S=new je:(S=je.zpp_pool,je.zpp_pool=S.next,S.next=null),S.id=N,S.di=Z;let V=S;V.value=!0,M.add(V)}}else{let O=w.data;if(O.segment!=C.segment||C.segment2!=O.segment2)throw new Error("corner case 2, shiiiit.");let E=C.vertex;E.links.clear(),E.node=null,E.forced=!1,E.next=ke.zpp_pool,ke.zpp_pool=E;let M=C;M.vertex=null,M.segment=M.segment2=null,M.node=null,M.next=ge.zpp_pool,ge.zpp_pool=M}}else{let v=C.vertex;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v;let w=C;w.vertex=null,w.segment=w.segment2=null,w.node=null,w.next=ge.zpp_pool,ge.zpp_pool=w}}if(f!=null&&f.prev!=null&&!(f.id<f.prev.id?xe.inthash.has(f.id,f.prev.id):xe.inthash.has(f.prev.id,f.id))){let C=xe.sweep.intersection(f,f.prev);if(C!=null)if(C.vertex.x>=xe.sweep.sweepx){let v=xe.queue.parent;for(;v!=null;)if(xe.queue.lt(C,v.data))v=v.prev;else if(xe.queue.lt(v.data,C))v=v.next;else break;let w=v;if(w==null){let O=xe.ints.parent;for(;O!=null;)if(xe.ints.lt(C,O.data))O=O.prev;else if(xe.ints.lt(O.data,C))O=O.next;else break;let E=O;if(E!=null){let M=C.vertex;M.links.clear(),M.node=null,M.forced=!1,M.next=ke.zpp_pool,ke.zpp_pool=M,C.vertex=E.data.vertex,E.data=C,xe.queue.insert(C)}else xe.queue.insert(C),xe.ints.insert(C);if(f.id<f.prev.id){let M=xe.inthash,N=f.id,Z=f.prev.id,S;je.zpp_pool==null?S=new je:(S=je.zpp_pool,je.zpp_pool=S.next,S.next=null),S.id=N,S.di=Z;let V=S;V.value=!0,M.add(V)}else{let M=xe.inthash,N=f.prev.id,Z=f.id,S;je.zpp_pool==null?S=new je:(S=je.zpp_pool,je.zpp_pool=S.next,S.next=null),S.id=N,S.di=Z;let V=S;V.value=!0,M.add(V)}}else{let O=w.data;if(O.segment!=C.segment||C.segment2!=O.segment2)throw new Error("corner case 2, shiiiit.");let E=C.vertex;E.links.clear(),E.node=null,E.forced=!1,E.next=ke.zpp_pool,ke.zpp_pool=E;let M=C;M.vertex=null,M.segment=M.segment2=null,M.node=null,M.next=ge.zpp_pool,ge.zpp_pool=M}}else{let v=C.vertex;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v;let w=C;w.vertex=null,w.segment=w.segment2=null,w.node=null,w.next=ge.zpp_pool,ge.zpp_pool=w}}xe.ints.remove(x)}let y=x;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=ge.zpp_pool,ge.zpp_pool=y}let h=0,u=xe.inthash.table.length;for(;h<u;){let x=h++,y=xe.inthash.table[x];if(y!=null){for(;y!=null;){let d=y.hnext;y.hnext=null;let _=y;_.next=je.zpp_pool,je.zpp_pool=_,y=d}xe.inthash.table[x]=null}}for(t==null&&(t=new hs);!xe.vertices.empty();)xe.clip_polygon(xe.vertices,t);return t}static clip_polygon(e,t){let n=null,s=e.first(),i=s,l=s.links.parent,r=l.prev==null?l.next:l.prev,a=l.data,o=r.data,p=s.x-a.x,c=s.y-a.y,h=o.x-s.x;(o.y-s.y)*p-h*c<0&&(o=a);let x=s.x,y=s.y,d;ve.zpp_pool==null?d=new ve:(d=ve.zpp_pool,ve.zpp_pool=d.next,d.next=null),d.forced=!1,d.x=x,d.y=y;let _=d;if(n==null)_.prev=_.next=_;else{let z=n,P=z.next;_.prev=z,_.next=P,P.prev=_,z.next=_}for(n=_,n.forced=s.forced;;){if(s.links.remove(o),o.links.remove(s),o==i){if(s.links.empty()){e.remove(s);let b=s;b.links.clear(),b.node=null,b.forced=!1,b.next=ke.zpp_pool,ke.zpp_pool=b}break}let z=o.x,P=o.y,k;ve.zpp_pool==null?k=new ve:(k=ve.zpp_pool,ve.zpp_pool=k.next,k.next=null),k.forced=!1,k.x=z,k.y=P;let m=k;if(n==null)m.prev=m.next=m;else{let b=n,C=b.next;m.prev=b,m.next=C,C.prev=m,b.next=m}if(n=m,n.forced=o.forced,o.links.singular()){if(s.links.empty()){e.remove(s);let b=s;b.links.clear(),b.node=null,b.forced=!1,b.next=ke.zpp_pool,ke.zpp_pool=b}s=o,o=o.links.parent.data}else{let b=null,C=0;if(!o.links.empty()){let v=o.links.parent;for(;v.prev!=null;)v=v.prev;for(;v!=null;){let w=v.data;if(b==null){b=w;let O=o.x-s.x,E=o.y-s.y,M=w.x-o.x;C=(w.y-o.y)*O-M*E}else{let O=o.x-s.x,E=o.y-s.y,M=w.x-o.x,Z=(w.y-o.y)*O-M*E;if(Z>0&&C<=0)b=w,C=Z;else if(C*Z>=0){let S=o.x-w.x,V=o.y-w.y,D=b.x-o.x;(b.y-o.y)*S-D*V>0&&(b=w,C=Z)}}if(v.next!=null)for(v=v.next;v.prev!=null;)v=v.prev;else{for(;v.parent!=null&&v==v.parent.next;)v=v.parent;v=v.parent}}}if(s.links.empty()){e.remove(s);let v=s;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v}s=o,o=b}}e.remove(i);let f=i;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f,t.add(n)}static isSimple(e){xe.sweep==null&&(xe.sweep=new Di,xe.inthash=new Oi);let t=xe.list_vertices;t==null&&(t=xe.list_vertices=new Nl);let n=e,s=e;if(n!=null){let d=n;for(;;){let _=d,f=_.x,z=_.y,P;if(ke.zpp_pool==null?P=new ke:(P=ke.zpp_pool,ke.zpp_pool=P.next,P.next=null),P.x=f,P.y=z,t.add(P),d=d.next,d==s)break}}let i=xe.list_queue;i==null&&(i=xe.list_queue=new Ol);let l=t.head,r=l.elt;for(l=l.next;l!=null;){let d=l.elt,_;ge.zpp_pool==null?_=new ge:(_=ge.zpp_pool,ge.zpp_pool=_.next,_.next=null),_.vertex=r;let f=i.add(_),z;ge.zpp_pool==null?z=new ge:(z=ge.zpp_pool,ge.zpp_pool=z.next,z.next=null),z.vertex=d;let P=i.add(z),k;ge.less_xy(f,P)?(f.type=1,P.type=2,k=At.get(r,d)):(f.type=2,P.type=1,k=At.get(d,r)),f.segment=P.segment=k,r=d,l=l.next}let a=t.head.elt,o;ge.zpp_pool==null?o=new ge:(o=ge.zpp_pool,ge.zpp_pool=o.next,o.next=null),o.vertex=r;let p=i.add(o),c;ge.zpp_pool==null?c=new ge:(c=ge.zpp_pool,ge.zpp_pool=c.next,c.next=null),c.vertex=a;let h=i.add(c),u;ge.less_xy(p,h)?(p.type=1,h.type=2,u=At.get(r,a)):(p.type=2,h.type=1,u=At.get(a,r)),p.segment=h.segment=u;let x=i;if(x.head!=null&&x.head.next!=null){let d=x.head,_,f,z,P,k=1,m,b,C;for(;;){for(m=0,f=d,d=null,_=null;f!=null;){for(++m,z=f,b=0,C=k;z!=null&&b<k;)++b,z=z.next;for(;b>0||C>0&&z!=null;)b==0?(P=z,z=z.next,--C):C==0||z==null||ge.less_xy(f.elt,z.elt)?(P=f,f=f.next,--b):(P=z,z=z.next,--C),_!=null?_.next=P:d=P,_=P;f=z}if(_.next=null,k<<=1,!(m>1))break}x.head=d,x.modified=!0,x.pushmod=!0}let y=!0;for(;i.head!=null;){let d=i.pop_unsafe(),_=d.segment;if(d.type==1){if(xe.sweep.add(_),xe.sweep.intersect(_,_.next)||xe.sweep.intersect(_,_.prev)){y=!1;break}}else if(d.type==2){if(xe.sweep.intersect(_.prev,_.next)){y=!1;break}xe.sweep.remove(_);let z=_;z.left=z.right=null,z.prev=null,z.node=null,z.vertices.clear(),z.next=At.zpp_pool,At.zpp_pool=z}let f=d;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=ge.zpp_pool,ge.zpp_pool=f}for(;i.head!=null;){let d=i.pop_unsafe();if(d.type==2){let f=d.segment;f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=At.zpp_pool,At.zpp_pool=f}let _=d;_.vertex=null,_.segment=_.segment2=null,_.node=null,_.next=ge.zpp_pool,ge.zpp_pool=_}for(xe.sweep.clear();t.head!=null;){let d=t.pop_unsafe();d.links.clear(),d.node=null,d.forced=!1,d.next=ke.zpp_pool,ke.zpp_pool=d}return y}};xe.sweep=null,xe.inthash=null,xe.vertices=null,xe.queue=null,xe.ints=null,xe.list_vertices=null,xe.list_queue=null;var hl=xe;var Ri=class Ri{constructor(){this.x=0;this.y=0;this.next=null;this.prev=null;this.flag=!1;this.forced=!1}static get(e){let t;return Ri.zpp_pool==null?t=new Ri:(t=Ri.zpp_pool,Ri.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t.flag=!1,t}free(){}alloc(){}};Ri.zpp_pool=null;var Pn=Ri;var Gi=class Gi{constructor(){this.next=null;this.min=null;this.max=null}static get(e,t){let n;return Gi.zpp_pool==null?n=new Gi:(n=Gi.zpp_pool,Gi.zpp_pool=n.next,n.next=null),n.min=e,n.max=t,n}free(){this.min=null,this.max=null}alloc(){}};Gi.zpp_pool=null;var Te=Gi;var Vt=class Vt{static lessval(e,t){return e.x-t.x+(e.y-t.y)}static less(e,t){return e.x-t.x+(e.y-t.y)<0}static distance(e,t,n){let s=n.x-t.x,i=n.y-t.y,l=e.x-t.x,r=e.y-t.y;if(s*s+i*i==0)return l*l+r*r;{let o=(l*s+r*i)/(s*s+i*i);if(o<=0)return l*l+r*r;if(o>=1){let p=e.x-n.x,c=e.y-n.y;return p*p+c*c}else{let p=o;return l-=s*p,r-=i*p,l*l+r*r}}}static simplify(e,t){let n=null,s=null,i=null;t*=t,Vt.stack==null&&(Vt.stack=new El);let l=null,r=null,a=e;for(;;){let p;Pn.zpp_pool==null?p=new Pn:(p=Pn.zpp_pool,Pn.zpp_pool=p.next,p.next=null),p.x=a.x,p.y=a.y,p.flag=!1;let c=p;if(c.forced=a.forced,c.forced){if(c.flag=!0,l!=null){let u=Vt.stack,x;Te.zpp_pool==null?x=new Te:(x=Te.zpp_pool,Te.zpp_pool=x.next,x.next=null),x.min=l,x.max=c,u.add(x)}else r=c;l=c}let h=c;if(n==null?h.prev=h.next=h:(h.prev=n,h.next=n.next,n.next.prev=h,n.next=h),n=h,s==null?(s=n,i=n):(n.x-s.x+(n.y-s.y)<0&&(s=n),i.x-n.x+(i.y-n.y)<0&&(i=n)),a=a.next,a==e)break}if(Vt.stack.head==null)if(r==null){s.flag=i.flag=!0;let p=Vt.stack,c;Te.zpp_pool==null?c=new Te:(c=Te.zpp_pool,Te.zpp_pool=c.next,c.next=null),c.min=s,c.max=i,p.add(c);let h=Vt.stack,u;Te.zpp_pool==null?u=new Te:(u=Te.zpp_pool,Te.zpp_pool=u.next,u.next=null),u.min=i,u.max=s,h.add(u)}else{let p=s.x-r.x+(s.y-r.y);p<0&&(p=-p);let c=i.x-r.x+(i.y-r.y);if(c<0&&(c=-c),p>c){s.flag=r.flag=!0;let h=Vt.stack,u;Te.zpp_pool==null?u=new Te:(u=Te.zpp_pool,Te.zpp_pool=u.next,u.next=null),u.min=s,u.max=r,h.add(u);let x=Vt.stack,y;Te.zpp_pool==null?y=new Te:(y=Te.zpp_pool,Te.zpp_pool=y.next,y.next=null),y.min=r,y.max=s,x.add(y)}else{i.flag=r.flag=!0;let h=Vt.stack,u;Te.zpp_pool==null?u=new Te:(u=Te.zpp_pool,Te.zpp_pool=u.next,u.next=null),u.min=i,u.max=r,h.add(u);let x=Vt.stack,y;Te.zpp_pool==null?y=new Te:(y=Te.zpp_pool,Te.zpp_pool=y.next,y.next=null),y.min=r,y.max=i,x.add(y)}}else{let p=Vt.stack,c;Te.zpp_pool==null?c=new Te:(c=Te.zpp_pool,Te.zpp_pool=c.next,c.next=null),c.min=l,c.max=r,p.add(c)}for(;Vt.stack.head!=null;){let p=Vt.stack.pop_unsafe(),c=p.min,h=p.max,u=p;u.min=u.max=null,u.next=Te.zpp_pool,Te.zpp_pool=u;let x=t,y=null,d=c.next;for(;d!=h;){let _=Vt.distance(d,c,h);_>x&&(x=_,y=d),d=d.next}if(y!=null){y.flag=!0;let _=Vt.stack,f;Te.zpp_pool==null?f=new Te:(f=Te.zpp_pool,Te.zpp_pool=f.next,f.next=null),f.min=c,f.max=y,_.add(f);let z=Vt.stack,P;Te.zpp_pool==null?P=new Te:(P=Te.zpp_pool,Te.zpp_pool=P.next,P.next=null),P.min=y,P.max=h,z.add(P)}}let o=null;for(;n!=null;){if(n.flag){let p=n.x,c=n.y,h;ve.zpp_pool==null?h=new ve:(h=ve.zpp_pool,ve.zpp_pool=h.next,h.next=null),h.forced=!1,h.x=p,h.y=c;let u=h;o==null?u.prev=u.next=u:(u.prev=o,u.next=o.next,o.next.prev=u,o.next=u),o=u,o.forced=n.forced}if(n!=null&&n.prev==n)n.next=n.prev=null,n.next=Pn.zpp_pool,Pn.zpp_pool=n,n=null;else{let p=n.next;n.prev.next=n.next,n.next.prev=n.prev,n.next=n.prev=null,n.next=Pn.zpp_pool,Pn.zpp_pool=n,n=p}}return o}};Vt.stack=null;var ul=Vt;var Fs=class{constructor(){this.next=null;this.toi=0;this.s1=null;this.s2=null;this.arbiter=null;this.frozen1=!1;this.frozen2=!1;this.slipped=!1;this.failed=!1;this.kinematic=!1;this.c1=new le,this.c2=new le,this.axis=new le}alloc(){this.failed=!1,this.s1=this.s2=null,this.arbiter=null}free(){}};Fs.zpp_pool=null;var wn=class{static dynamicSweep(e,t,n,s,i){let l=me();i==null&&(i=!1);let r=e.s1,a=e.s2,o=r.body,p=a.body,c=0,h=0;c=p.velx-o.velx,h=p.vely-o.vely;let u=o.angvel;u<0&&(u=-u);let x=p.angvel;x<0&&(x=-x);let y=r.sweepCoef*u+a.sweepCoef*x;if(!i&&!e.kinematic&&c*c+h*h<l.Config.dynamicSweepLinearThreshold*l.Config.dynamicSweepLinearThreshold&&y<l.Config.dynamicSweepAngularThreshold){e.toi=-1,e.failed=!0;return}let d=e.c1,_=e.c2,f=e.axis,z=n,P=0;for(;;){let Z=z*t,S=Z-o.sweepTime;if(S!=0){o.sweepTime=Z;let Y=S;if(o.posx+=o.velx*Y,o.posy+=o.vely*Y,o.angvel!=0){let X=o.sweep_angvel*S;if(o.rot+=X,X*X>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let ee=X*X,J=1-.5*ee,L=1-ee*ee/8,F=(J*o.axisx+X*o.axisy)*L;o.axisy=(J*o.axisy-X*o.axisx)*L,o.axisx=F}}}if(r.type==0)r.worldCOMx=o.posx+(o.axisy*r.localCOMx-o.axisx*r.localCOMy),r.worldCOMy=o.posy+(r.localCOMx*o.axisx+r.localCOMy*o.axisy);else{let Y=r.polygon,X=Y.lverts.next,ee=Y.gverts.next;for(;ee!=null;){let $=ee,K=X;X=X.next,$.x=o.posx+(o.axisy*K.x-o.axisx*K.y),$.y=o.posy+(K.x*o.axisx+K.y*o.axisy),ee=ee.next}let J=Y.edges.head,L=Y.gverts.next,F=L;for(L=L.next;L!=null;){let $=L,K=J.elt;J=J.next,K.gnormx=o.axisy*K.lnormx-o.axisx*K.lnormy,K.gnormy=K.lnormx*o.axisx+K.lnormy*o.axisy,K.gprojection=o.posx*K.gnormx+o.posy*K.gnormy+K.lprojection,K.tp0=F.y*K.gnormx-F.x*K.gnormy,K.tp1=$.y*K.gnormx-$.x*K.gnormy,F=$,L=L.next}let I=Y.gverts.next,U=J.elt;J=J.next,U.gnormx=o.axisy*U.lnormx-o.axisx*U.lnormy,U.gnormy=U.lnormx*o.axisx+U.lnormy*o.axisy,U.gprojection=o.posx*U.gnormx+o.posy*U.gnormy+U.lprojection,U.tp0=F.y*U.gnormx-F.x*U.gnormy,U.tp1=I.y*U.gnormx-I.x*U.gnormy}let V=z*t,D=V-p.sweepTime;if(D!=0){p.sweepTime=V;let Y=D;if(p.posx+=p.velx*Y,p.posy+=p.vely*Y,p.angvel!=0){let X=p.sweep_angvel*D;if(p.rot+=X,X*X>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let ee=X*X,J=1-.5*ee,L=1-ee*ee/8,F=(J*p.axisx+X*p.axisy)*L;p.axisy=(J*p.axisy-X*p.axisx)*L,p.axisx=F}}}if(a.type==0)a.worldCOMx=p.posx+(p.axisy*a.localCOMx-p.axisx*a.localCOMy),a.worldCOMy=p.posy+(a.localCOMx*p.axisx+a.localCOMy*p.axisy);else{let Y=a.polygon,X=Y.lverts.next,ee=Y.gverts.next;for(;ee!=null;){let $=ee,K=X;X=X.next,$.x=p.posx+(p.axisy*K.x-p.axisx*K.y),$.y=p.posy+(K.x*p.axisx+K.y*p.axisy),ee=ee.next}let J=Y.edges.head,L=Y.gverts.next,F=L;for(L=L.next;L!=null;){let $=L,K=J.elt;J=J.next,K.gnormx=p.axisy*K.lnormx-p.axisx*K.lnormy,K.gnormy=K.lnormx*p.axisx+K.lnormy*p.axisy,K.gprojection=p.posx*K.gnormx+p.posy*K.gnormy+K.lprojection,K.tp0=F.y*K.gnormx-F.x*K.gnormy,K.tp1=$.y*K.gnormx-$.x*K.gnormy,F=$,L=L.next}let I=Y.gverts.next,U=J.elt;J=J.next,U.gnormx=p.axisy*U.lnormx-p.axisx*U.lnormy,U.gnormy=U.lnormx*p.axisx+U.lnormy*p.axisy,U.gprojection=p.posx*U.gnormx+p.posy*U.gnormy+U.lprojection,U.tp0=F.y*U.gnormx-F.x*U.gnormy,U.tp1=I.y*U.gnormx-I.x*U.gnormy}let T=r,G=a,q=d,R=_;var k;if(T.type==0&&G.type==0){let Y=T.circle,X=G.circle;var m;let ee=0,J=0;ee=X.worldCOMx-Y.worldCOMx,J=X.worldCOMy-Y.worldCOMy;let L=Math.sqrt(ee*ee+J*J);if(m=L-(Y.radius+X.radius),m<1e100){if(L==0)ee=1,J=0;else{let U=1/L;ee*=U,J*=U}let F=Y.radius;q.x=Y.worldCOMx+ee*F,q.y=Y.worldCOMy+J*F;let I=-X.radius;R.x=X.worldCOMx+ee*I,R.y=X.worldCOMy+J*I,f.x=ee,f.y=J}k=m}else{let Y=!1;if(T.type==0&&G.type==1){let X=T;T=G,G=X;let ee=q;q=R,R=ee,Y=!0}if(T.type==1&&G.type==0){let X=T.polygon,ee=G.circle,J=-1e100,L=null,F=X.edges.head;for(;F!=null;){let I=F.elt,U=I.gnormx*ee.worldCOMx+I.gnormy*ee.worldCOMy-I.gprojection-ee.radius;if(U>1e100){J=U;break}U>0?U>J&&(J=U,L=I):J<0&&U>J&&(J=U,L=I),F=F.next}if(J<1e100){let I=L.gp0,U=L.gp1,$=ee.worldCOMy*L.gnormx-ee.worldCOMx*L.gnormy;if($<=I.y*L.gnormx-I.x*L.gnormy){let K=0,ie=0;K=ee.worldCOMx-I.x,ie=ee.worldCOMy-I.y;let re=Math.sqrt(K*K+ie*ie);if(J=re-ee.radius,J<1e100){if(re==0)K=1,ie=0;else{let oe=1/re;K*=oe,ie*=oe}let se=0;q.x=I.x+K*se,q.y=I.y+ie*se;let te=-ee.radius;R.x=ee.worldCOMx+K*te,R.y=ee.worldCOMy+ie*te,f.x=K,f.y=ie}}else if($>=U.y*L.gnormx-U.x*L.gnormy){let K=0,ie=0;K=ee.worldCOMx-U.x,ie=ee.worldCOMy-U.y;let re=Math.sqrt(K*K+ie*ie);if(J=re-ee.radius,J<1e100){if(re==0)K=1,ie=0;else{let oe=1/re;K*=oe,ie*=oe}let se=0;q.x=U.x+K*se,q.y=U.y+ie*se;let te=-ee.radius;R.x=ee.worldCOMx+K*te,R.y=ee.worldCOMy+ie*te,f.x=K,f.y=ie}}else{let K=-ee.radius;R.x=ee.worldCOMx+L.gnormx*K,R.y=ee.worldCOMy+L.gnormy*K;let ie=-J;q.x=R.x+L.gnormx*ie,q.y=R.y+L.gnormy*ie,f.x=L.gnormx,f.y=L.gnormy}}Y&&(f.x=-f.x,f.y=-f.y),k=J}else{let X=T.polygon,ee=G.polygon,J=-1e100,L=null,F=null,I=0,U=X.edges.head;for(;U!=null;){let $=U.elt,K=1e100,ie=ee.gverts.next;for(;ie!=null;){let re=ie,se=$.gnormx*re.x+$.gnormy*re.y;se<K&&(K=se),ie=ie.next}if(K-=$.gprojection,K>1e100){J=K;break}K>0?K>J&&(J=K,L=$,I=1):J<0&&K>J&&(J=K,L=$,I=1),U=U.next}if(J<1e100){let $=ee.edges.head;for(;$!=null;){let K=$.elt,ie=1e100,re=X.gverts.next;for(;re!=null;){let se=re,te=K.gnormx*se.x+K.gnormy*se.y;te<ie&&(ie=te),re=re.next}if(ie-=K.gprojection,ie>1e100){J=ie;break}ie>0?ie>J&&(J=ie,F=K,I=2):J<0&&ie>J&&(J=ie,F=K,I=2),$=$.next}if(J<1e100){var b,C,v;if(I==1)b=X,C=ee,v=L;else{b=ee,C=X,v=F;let se=q;q=R,R=se,Y=!Y}let K=null,ie=1e100,re=C.edges.head;for(;re!=null;){let se=re.elt,te=v.gnormx*se.gnormx+v.gnormy*se.gnormy;te<ie&&(ie=te,K=se),re=re.next}if(Y?(f.x=-v.gnormx,f.y=-v.gnormy):(f.x=v.gnormx,f.y=v.gnormy),J>=0){let se=v.gp0,te=v.gp1,oe=K.gp0,pe=K.gp1,ce=0,ae=0,ue=0,ne=0;ce=te.x-se.x,ae=te.y-se.y,ue=pe.x-oe.x,ne=pe.y-oe.y;let he=1/(ce*ce+ae*ae),ye=1/(ue*ue+ne*ne),de=-(ce*(se.x-oe.x)+ae*(se.y-oe.y))*he,we=-(ce*(se.x-pe.x)+ae*(se.y-pe.y))*he,Oe=-(ue*(oe.x-se.x)+ne*(oe.y-se.y))*ye,Le=-(ue*(oe.x-te.x)+ne*(oe.y-te.y))*ye;de<0?de=0:de>1&&(de=1),we<0?we=0:we>1&&(we=1),Oe<0?Oe=0:Oe>1&&(Oe=1),Le<0?Le=0:Le>1&&(Le=1);let Ke=0,Xe=0,He=de;Ke=se.x+ce*He,Xe=se.y+ae*He;let Re=0,mt=0,wt=we;Re=se.x+ce*wt,mt=se.y+ae*wt;let rt=0,at=0,ot=Oe;rt=oe.x+ue*ot,at=oe.y+ne*ot;let Ye=0,bt=0,Bt=Le;Ye=oe.x+ue*Bt,bt=oe.y+ne*Bt;let Ft=0,Zt=0;Ft=Ke-oe.x,Zt=Xe-oe.y;let kt=Ft*Ft+Zt*Zt,yn=0,Ut=0;yn=Re-pe.x,Ut=mt-pe.y;let pn=yn*yn+Ut*Ut,nn=0,cn=0;nn=rt-se.x,cn=at-se.y;let Wt=nn*nn+cn*cn,mn=0,Kt=0;mn=Ye-te.x,Kt=bt-te.y;let hn=mn*mn+Kt*Kt,Dt=0,Yt=0,sn=null;kt<pn?(Dt=Ke,Yt=Xe,sn=oe):(Dt=Re,Yt=mt,sn=pe,kt=pn);let Qn=0,Tn=0,Nn=null;if(Wt<hn?(Qn=rt,Tn=at,Nn=se):(Qn=Ye,Tn=bt,Nn=te,Wt=hn),kt<Wt?(q.x=Dt,q.y=Yt,R.x=sn.x,R.y=sn.y,J=Math.sqrt(kt)):(R.x=Qn,R.y=Tn,q.x=Nn.x,q.y=Nn.y,J=Math.sqrt(Wt)),J!=0){f.x=R.x-q.x,f.y=R.y-q.y;let On=1/J;f.x*=On,f.y*=On,Y&&(f.x=-f.x,f.y=-f.y)}k=J}else{let se=0,te=0;se=K.gp0.x,te=K.gp0.y;let oe=0,pe=0;oe=K.gp1.x,pe=K.gp1.y;let ce=0,ae=0;ce=oe-se,ae=pe-te;let ue=v.gnormy*se-v.gnormx*te,ne=v.gnormy*oe-v.gnormx*pe,he=1/(ne-ue),ye=(-v.tp1-ue)*he;if(ye>l.Config.epsilon){let Le=ye;se+=ce*Le,te+=ae*Le}let de=(-v.tp0-ne)*he;if(de<-l.Config.epsilon){let Le=de;oe+=ce*Le,pe+=ae*Le}let we=se*v.gnormx+te*v.gnormy-v.gprojection,Oe=oe*v.gnormx+pe*v.gnormy-v.gprojection;if(we<Oe){R.x=se,R.y=te;let Le=-we;q.x=R.x+v.gnormx*Le,q.y=R.y+v.gnormy*Le,k=we}else{R.x=oe,R.y=pe;let Le=-Oe;q.x=R.x+v.gnormx*Le,q.y=R.y+v.gnormy*Le,k=Oe}}}else k=1e100}else k=1e100}}let j=k+s,A=c*f.x+h*f.y;if(j<l.Config.distanceThresholdCCD){if(i)break;let Y=0,X=0;Y=d.x-o.posx,X=d.y-o.posy;let ee=0,J=0;ee=_.x-p.posx,J=_.y-p.posy;let L=A-o.sweep_angvel*(f.y*Y-f.x*X)+p.sweep_angvel*(f.y*ee-f.x*J);if(L>0&&(e.slipped=!0),L<=0||j<l.Config.distanceThresholdCCD*.5)break}let W=(y-A)*t;if(W<=0){z=-1;break}let Q=j/W;if(Q<1e-6&&(Q=1e-6),z+=Q,z>=1){z=1;let Y=z*t,X=Y-o.sweepTime;if(X!=0){o.sweepTime=Y;let ie=X;if(o.posx+=o.velx*ie,o.posy+=o.vely*ie,o.angvel!=0){let re=o.sweep_angvel*X;if(o.rot+=re,re*re>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let se=re*re,te=1-.5*se,oe=1-se*se/8,pe=(te*o.axisx+re*o.axisy)*oe;o.axisy=(te*o.axisy-re*o.axisx)*oe,o.axisx=pe}}}if(r.type==0)r.worldCOMx=o.posx+(o.axisy*r.localCOMx-o.axisx*r.localCOMy),r.worldCOMy=o.posy+(r.localCOMx*o.axisx+r.localCOMy*o.axisy);else{let ie=r.polygon,re=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ue=se,ne=re;re=re.next,ue.x=o.posx+(o.axisy*ne.x-o.axisx*ne.y),ue.y=o.posy+(ne.x*o.axisx+ne.y*o.axisy),se=se.next}let te=ie.edges.head,oe=ie.gverts.next,pe=oe;for(oe=oe.next;oe!=null;){let ue=oe,ne=te.elt;te=te.next,ne.gnormx=o.axisy*ne.lnormx-o.axisx*ne.lnormy,ne.gnormy=ne.lnormx*o.axisx+ne.lnormy*o.axisy,ne.gprojection=o.posx*ne.gnormx+o.posy*ne.gnormy+ne.lprojection,ne.tp0=pe.y*ne.gnormx-pe.x*ne.gnormy,ne.tp1=ue.y*ne.gnormx-ue.x*ne.gnormy,pe=ue,oe=oe.next}let ce=ie.gverts.next,ae=te.elt;te=te.next,ae.gnormx=o.axisy*ae.lnormx-o.axisx*ae.lnormy,ae.gnormy=ae.lnormx*o.axisx+ae.lnormy*o.axisy,ae.gprojection=o.posx*ae.gnormx+o.posy*ae.gnormy+ae.lprojection,ae.tp0=pe.y*ae.gnormx-pe.x*ae.gnormy,ae.tp1=ce.y*ae.gnormx-ce.x*ae.gnormy}let ee=z*t,J=ee-p.sweepTime;if(J!=0){p.sweepTime=ee;let ie=J;if(p.posx+=p.velx*ie,p.posy+=p.vely*ie,p.angvel!=0){let re=p.sweep_angvel*J;if(p.rot+=re,re*re>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let se=re*re,te=1-.5*se,oe=1-se*se/8,pe=(te*p.axisx+re*p.axisy)*oe;p.axisy=(te*p.axisy-re*p.axisx)*oe,p.axisx=pe}}}if(a.type==0)a.worldCOMx=p.posx+(p.axisy*a.localCOMx-p.axisx*a.localCOMy),a.worldCOMy=p.posy+(a.localCOMx*p.axisx+a.localCOMy*p.axisy);else{let ie=a.polygon,re=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ue=se,ne=re;re=re.next,ue.x=p.posx+(p.axisy*ne.x-p.axisx*ne.y),ue.y=p.posy+(ne.x*p.axisx+ne.y*p.axisy),se=se.next}let te=ie.edges.head,oe=ie.gverts.next,pe=oe;for(oe=oe.next;oe!=null;){let ue=oe,ne=te.elt;te=te.next,ne.gnormx=p.axisy*ne.lnormx-p.axisx*ne.lnormy,ne.gnormy=ne.lnormx*p.axisx+ne.lnormy*p.axisy,ne.gprojection=p.posx*ne.gnormx+p.posy*ne.gnormy+ne.lprojection,ne.tp0=pe.y*ne.gnormx-pe.x*ne.gnormy,ne.tp1=ue.y*ne.gnormx-ue.x*ne.gnormy,pe=ue,oe=oe.next}let ce=ie.gverts.next,ae=te.elt;te=te.next,ae.gnormx=p.axisy*ae.lnormx-p.axisx*ae.lnormy,ae.gnormy=ae.lnormx*p.axisx+ae.lnormy*p.axisy,ae.gprojection=p.posx*ae.gnormx+p.posy*ae.gnormy+ae.lprojection,ae.tp0=pe.y*ae.gnormx-pe.x*ae.gnormy,ae.tp1=ce.y*ae.gnormx-ce.x*ae.gnormy}let L=r,F=a,I=d,U=_;var w;if(L.type==0&&F.type==0){let ie=L.circle,re=F.circle;var O;let se=0,te=0;se=re.worldCOMx-ie.worldCOMx,te=re.worldCOMy-ie.worldCOMy;let oe=Math.sqrt(se*se+te*te);if(O=oe-(ie.radius+re.radius),O<1e100){if(oe==0)se=1,te=0;else{let ae=1/oe;se*=ae,te*=ae}let pe=ie.radius;I.x=ie.worldCOMx+se*pe,I.y=ie.worldCOMy+te*pe;let ce=-re.radius;U.x=re.worldCOMx+se*ce,U.y=re.worldCOMy+te*ce,f.x=se,f.y=te}w=O}else{let ie=!1;if(L.type==0&&F.type==1){let re=L;L=F,F=re;let se=I;I=U,U=se,ie=!0}if(L.type==1&&F.type==0){let re=L.polygon,se=F.circle,te=-1e100,oe=null,pe=re.edges.head;for(;pe!=null;){let ce=pe.elt,ae=ce.gnormx*se.worldCOMx+ce.gnormy*se.worldCOMy-ce.gprojection-se.radius;if(ae>1e100){te=ae;break}ae>0?ae>te&&(te=ae,oe=ce):te<0&&ae>te&&(te=ae,oe=ce),pe=pe.next}if(te<1e100){let ce=oe.gp0,ae=oe.gp1,ue=se.worldCOMy*oe.gnormx-se.worldCOMx*oe.gnormy;if(ue<=ce.y*oe.gnormx-ce.x*oe.gnormy){let ne=0,he=0;ne=se.worldCOMx-ce.x,he=se.worldCOMy-ce.y;let ye=Math.sqrt(ne*ne+he*he);if(te=ye-se.radius,te<1e100){if(ye==0)ne=1,he=0;else{let Oe=1/ye;ne*=Oe,he*=Oe}let de=0;I.x=ce.x+ne*de,I.y=ce.y+he*de;let we=-se.radius;U.x=se.worldCOMx+ne*we,U.y=se.worldCOMy+he*we,f.x=ne,f.y=he}}else if(ue>=ae.y*oe.gnormx-ae.x*oe.gnormy){let ne=0,he=0;ne=se.worldCOMx-ae.x,he=se.worldCOMy-ae.y;let ye=Math.sqrt(ne*ne+he*he);if(te=ye-se.radius,te<1e100){if(ye==0)ne=1,he=0;else{let Oe=1/ye;ne*=Oe,he*=Oe}let de=0;I.x=ae.x+ne*de,I.y=ae.y+he*de;let we=-se.radius;U.x=se.worldCOMx+ne*we,U.y=se.worldCOMy+he*we,f.x=ne,f.y=he}}else{let ne=-se.radius;U.x=se.worldCOMx+oe.gnormx*ne,U.y=se.worldCOMy+oe.gnormy*ne;let he=-te;I.x=U.x+oe.gnormx*he,I.y=U.y+oe.gnormy*he,f.x=oe.gnormx,f.y=oe.gnormy}}ie&&(f.x=-f.x,f.y=-f.y),w=te}else{let re=L.polygon,se=F.polygon,te=-1e100,oe=null,pe=null,ce=0,ae=re.edges.head;for(;ae!=null;){let ue=ae.elt,ne=1e100,he=se.gverts.next;for(;he!=null;){let ye=he,de=ue.gnormx*ye.x+ue.gnormy*ye.y;de<ne&&(ne=de),he=he.next}if(ne-=ue.gprojection,ne>1e100){te=ne;break}ne>0?ne>te&&(te=ne,oe=ue,ce=1):te<0&&ne>te&&(te=ne,oe=ue,ce=1),ae=ae.next}if(te<1e100){let ue=se.edges.head;for(;ue!=null;){let ne=ue.elt,he=1e100,ye=re.gverts.next;for(;ye!=null;){let de=ye,we=ne.gnormx*de.x+ne.gnormy*de.y;we<he&&(he=we),ye=ye.next}if(he-=ne.gprojection,he>1e100){te=he;break}he>0?he>te&&(te=he,pe=ne,ce=2):te<0&&he>te&&(te=he,pe=ne,ce=2),ue=ue.next}if(te<1e100){var E,M,N;if(ce==1)E=re,M=se,N=oe;else{E=se,M=re,N=pe;let de=I;I=U,U=de,ie=!ie}let ne=null,he=1e100,ye=M.edges.head;for(;ye!=null;){let de=ye.elt,we=N.gnormx*de.gnormx+N.gnormy*de.gnormy;we<he&&(he=we,ne=de),ye=ye.next}if(ie?(f.x=-N.gnormx,f.y=-N.gnormy):(f.x=N.gnormx,f.y=N.gnormy),te>=0){let de=N.gp0,we=N.gp1,Oe=ne.gp0,Le=ne.gp1,Ke=0,Xe=0,He=0,Re=0;Ke=we.x-de.x,Xe=we.y-de.y,He=Le.x-Oe.x,Re=Le.y-Oe.y;let mt=1/(Ke*Ke+Xe*Xe),wt=1/(He*He+Re*Re),rt=-(Ke*(de.x-Oe.x)+Xe*(de.y-Oe.y))*mt,at=-(Ke*(de.x-Le.x)+Xe*(de.y-Le.y))*mt,ot=-(He*(Oe.x-de.x)+Re*(Oe.y-de.y))*wt,Ye=-(He*(Oe.x-we.x)+Re*(Oe.y-we.y))*wt;rt<0?rt=0:rt>1&&(rt=1),at<0?at=0:at>1&&(at=1),ot<0?ot=0:ot>1&&(ot=1),Ye<0?Ye=0:Ye>1&&(Ye=1);let bt=0,Bt=0,Ft=rt;bt=de.x+Ke*Ft,Bt=de.y+Xe*Ft;let Zt=0,kt=0,yn=at;Zt=de.x+Ke*yn,kt=de.y+Xe*yn;let Ut=0,pn=0,nn=ot;Ut=Oe.x+He*nn,pn=Oe.y+Re*nn;let cn=0,Wt=0,mn=Ye;cn=Oe.x+He*mn,Wt=Oe.y+Re*mn;let Kt=0,hn=0;Kt=bt-Oe.x,hn=Bt-Oe.y;let Dt=Kt*Kt+hn*hn,Yt=0,sn=0;Yt=Zt-Le.x,sn=kt-Le.y;let Qn=Yt*Yt+sn*sn,Tn=0,Nn=0;Tn=Ut-de.x,Nn=pn-de.y;let On=Tn*Tn+Nn*Nn,Ci=0,Mi=0;Ci=cn-we.x,Mi=Wt-we.y;let Zi=Ci*Ci+Mi*Mi,rs=0,Cl=0,Qs=null;Dt<Qn?(rs=bt,Cl=Bt,Qs=Oe):(rs=Zt,Cl=kt,Qs=Le,Dt=Qn);let Ml=0,Zl=0,$s=null;if(On<Zi?(Ml=Ut,Zl=pn,$s=de):(Ml=cn,Zl=Wt,$s=we,On=Zi),Dt<On?(I.x=rs,I.y=Cl,U.x=Qs.x,U.y=Qs.y,te=Math.sqrt(Dt)):(U.x=Ml,U.y=Zl,I.x=$s.x,I.y=$s.y,te=Math.sqrt(On)),te!=0){f.x=U.x-I.x,f.y=U.y-I.y;let jl=1/te;f.x*=jl,f.y*=jl,ie&&(f.x=-f.x,f.y=-f.y)}w=te}else{let de=0,we=0;de=ne.gp0.x,we=ne.gp0.y;let Oe=0,Le=0;Oe=ne.gp1.x,Le=ne.gp1.y;let Ke=0,Xe=0;Ke=Oe-de,Xe=Le-we;let He=N.gnormy*de-N.gnormx*we,Re=N.gnormy*Oe-N.gnormx*Le,mt=1/(Re-He),wt=(-N.tp1-He)*mt;if(wt>l.Config.epsilon){let Ye=wt;de+=Ke*Ye,we+=Xe*Ye}let rt=(-N.tp0-Re)*mt;if(rt<-l.Config.epsilon){let Ye=rt;Oe+=Ke*Ye,Le+=Xe*Ye}let at=de*N.gnormx+we*N.gnormy-N.gprojection,ot=Oe*N.gnormx+Le*N.gnormy-N.gprojection;if(at<ot){U.x=de,U.y=we;let Ye=-at;I.x=U.x+N.gnormx*Ye,I.y=U.y+N.gnormy*Ye,w=at}else{U.x=Oe,U.y=Le;let Ye=-ot;I.x=U.x+N.gnormx*Ye,I.y=U.y+N.gnormy*Ye,w=ot}}}else w=1e100}else w=1e100}}let $=w+s,K=c*f.x+h*f.y;if($<l.Config.distanceThresholdCCD){if(i)break;let ie=0,re=0;ie=d.x-o.posx,re=d.y-o.posy;let se=0,te=0;se=_.x-p.posx,te=_.y-p.posy;let oe=K-o.sweep_angvel*(f.y*ie-f.x*re)+p.sweep_angvel*(f.y*se-f.x*te);if(oe>0&&(e.slipped=!0),oe<=0||$<l.Config.distanceThresholdCCD*.5)break}z=-1;break}if(++P>=40){j>s&&(e.failed=!0);break}}e.toi=z}static staticSweep(e,t,n,s){let i=me(),l=e.s1,r=e.s2,a=l.body,o=r.body,p=0,c=0;p=-a.velx,c=-a.vely;let h=a.sweep_angvel;h<0&&(h=-h);let u=l.sweepCoef*h,x=e.c1,y=e.c2,d=e.axis,_=n,f=0;for(;;){let M=_*t,N=M-a.sweepTime;if(N!=0){a.sweepTime=M;let j=N;if(a.posx+=a.velx*j,a.posy+=a.vely*j,a.angvel!=0){let A=a.sweep_angvel*N;if(a.rot+=A,A*A>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let W=A*A,Q=1-.5*W,Y=1-W*W/8,X=(Q*a.axisx+A*a.axisy)*Y;a.axisy=(Q*a.axisy-A*a.axisx)*Y,a.axisx=X}}}if(l.type==0)l.worldCOMx=a.posx+(a.axisy*l.localCOMx-a.axisx*l.localCOMy),l.worldCOMy=a.posy+(l.localCOMx*a.axisx+l.localCOMy*a.axisy);else{let j=l.polygon,A=j.lverts.next,W=j.gverts.next;for(;W!=null;){let L=W,F=A;A=A.next,L.x=a.posx+(a.axisy*F.x-a.axisx*F.y),L.y=a.posy+(F.x*a.axisx+F.y*a.axisy),W=W.next}let Q=j.edges.head,Y=j.gverts.next,X=Y;for(Y=Y.next;Y!=null;){let L=Y,F=Q.elt;Q=Q.next,F.gnormx=a.axisy*F.lnormx-a.axisx*F.lnormy,F.gnormy=F.lnormx*a.axisx+F.lnormy*a.axisy,F.gprojection=a.posx*F.gnormx+a.posy*F.gnormy+F.lprojection,F.tp0=X.y*F.gnormx-X.x*F.gnormy,F.tp1=L.y*F.gnormx-L.x*F.gnormy,X=L,Y=Y.next}let ee=j.gverts.next,J=Q.elt;Q=Q.next,J.gnormx=a.axisy*J.lnormx-a.axisx*J.lnormy,J.gnormy=J.lnormx*a.axisx+J.lnormy*a.axisy,J.gprojection=a.posx*J.gnormx+a.posy*J.gnormy+J.lprojection,J.tp0=X.y*J.gnormx-X.x*J.gnormy,J.tp1=ee.y*J.gnormx-ee.x*J.gnormy}let Z=l,S=r,V=x,D=y;var z;if(Z.type==0&&S.type==0){let j=Z.circle,A=S.circle;var P;let W=0,Q=0;W=A.worldCOMx-j.worldCOMx,Q=A.worldCOMy-j.worldCOMy;let Y=Math.sqrt(W*W+Q*Q);if(P=Y-(j.radius+A.radius),P<1e100){if(Y==0)W=1,Q=0;else{let J=1/Y;W*=J,Q*=J}let X=j.radius;V.x=j.worldCOMx+W*X,V.y=j.worldCOMy+Q*X;let ee=-A.radius;D.x=A.worldCOMx+W*ee,D.y=A.worldCOMy+Q*ee,d.x=W,d.y=Q}z=P}else{let j=!1;if(Z.type==0&&S.type==1){let A=Z;Z=S,S=A;let W=V;V=D,D=W,j=!0}if(Z.type==1&&S.type==0){let A=Z.polygon,W=S.circle,Q=-1e100,Y=null,X=A.edges.head;for(;X!=null;){let ee=X.elt,J=ee.gnormx*W.worldCOMx+ee.gnormy*W.worldCOMy-ee.gprojection-W.radius;if(J>1e100){Q=J;break}J>0?J>Q&&(Q=J,Y=ee):Q<0&&J>Q&&(Q=J,Y=ee),X=X.next}if(Q<1e100){let ee=Y.gp0,J=Y.gp1,L=W.worldCOMy*Y.gnormx-W.worldCOMx*Y.gnormy;if(L<=ee.y*Y.gnormx-ee.x*Y.gnormy){let F=0,I=0;F=W.worldCOMx-ee.x,I=W.worldCOMy-ee.y;let U=Math.sqrt(F*F+I*I);if(Q=U-W.radius,Q<1e100){if(U==0)F=1,I=0;else{let ie=1/U;F*=ie,I*=ie}let $=0;V.x=ee.x+F*$,V.y=ee.y+I*$;let K=-W.radius;D.x=W.worldCOMx+F*K,D.y=W.worldCOMy+I*K,d.x=F,d.y=I}}else if(L>=J.y*Y.gnormx-J.x*Y.gnormy){let F=0,I=0;F=W.worldCOMx-J.x,I=W.worldCOMy-J.y;let U=Math.sqrt(F*F+I*I);if(Q=U-W.radius,Q<1e100){if(U==0)F=1,I=0;else{let ie=1/U;F*=ie,I*=ie}let $=0;V.x=J.x+F*$,V.y=J.y+I*$;let K=-W.radius;D.x=W.worldCOMx+F*K,D.y=W.worldCOMy+I*K,d.x=F,d.y=I}}else{let F=-W.radius;D.x=W.worldCOMx+Y.gnormx*F,D.y=W.worldCOMy+Y.gnormy*F;let I=-Q;V.x=D.x+Y.gnormx*I,V.y=D.y+Y.gnormy*I,d.x=Y.gnormx,d.y=Y.gnormy}}j&&(d.x=-d.x,d.y=-d.y),z=Q}else{let A=Z.polygon,W=S.polygon,Q=-1e100,Y=null,X=null,ee=0,J=A.edges.head;for(;J!=null;){let L=J.elt,F=1e100,I=W.gverts.next;for(;I!=null;){let U=I,$=L.gnormx*U.x+L.gnormy*U.y;$<F&&(F=$),I=I.next}if(F-=L.gprojection,F>1e100){Q=F;break}F>0?F>Q&&(Q=F,Y=L,ee=1):Q<0&&F>Q&&(Q=F,Y=L,ee=1),J=J.next}if(Q<1e100){let L=W.edges.head;for(;L!=null;){let F=L.elt,I=1e100,U=A.gverts.next;for(;U!=null;){let $=U,K=F.gnormx*$.x+F.gnormy*$.y;K<I&&(I=K),U=U.next}if(I-=F.gprojection,I>1e100){Q=I;break}I>0?I>Q&&(Q=I,X=F,ee=2):Q<0&&I>Q&&(Q=I,X=F,ee=2),L=L.next}if(Q<1e100){var k,m,b;if(ee==1)k=A,m=W,b=Y;else{k=W,m=A,b=X;let $=V;V=D,D=$,j=!j}let F=null,I=1e100,U=m.edges.head;for(;U!=null;){let $=U.elt,K=b.gnormx*$.gnormx+b.gnormy*$.gnormy;K<I&&(I=K,F=$),U=U.next}if(j?(d.x=-b.gnormx,d.y=-b.gnormy):(d.x=b.gnormx,d.y=b.gnormy),Q>=0){let $=b.gp0,K=b.gp1,ie=F.gp0,re=F.gp1,se=0,te=0,oe=0,pe=0;se=K.x-$.x,te=K.y-$.y,oe=re.x-ie.x,pe=re.y-ie.y;let ce=1/(se*se+te*te),ae=1/(oe*oe+pe*pe),ue=-(se*($.x-ie.x)+te*($.y-ie.y))*ce,ne=-(se*($.x-re.x)+te*($.y-re.y))*ce,he=-(oe*(ie.x-$.x)+pe*(ie.y-$.y))*ae,ye=-(oe*(ie.x-K.x)+pe*(ie.y-K.y))*ae;ue<0?ue=0:ue>1&&(ue=1),ne<0?ne=0:ne>1&&(ne=1),he<0?he=0:he>1&&(he=1),ye<0?ye=0:ye>1&&(ye=1);let de=0,we=0,Oe=ue;de=$.x+se*Oe,we=$.y+te*Oe;let Le=0,Ke=0,Xe=ne;Le=$.x+se*Xe,Ke=$.y+te*Xe;let He=0,Re=0,mt=he;He=ie.x+oe*mt,Re=ie.y+pe*mt;let wt=0,rt=0,at=ye;wt=ie.x+oe*at,rt=ie.y+pe*at;let ot=0,Ye=0;ot=de-ie.x,Ye=we-ie.y;let bt=ot*ot+Ye*Ye,Bt=0,Ft=0;Bt=Le-re.x,Ft=Ke-re.y;let Zt=Bt*Bt+Ft*Ft,kt=0,yn=0;kt=He-$.x,yn=Re-$.y;let Ut=kt*kt+yn*yn,pn=0,nn=0;pn=wt-K.x,nn=rt-K.y;let cn=pn*pn+nn*nn,Wt=0,mn=0,Kt=null;bt<Zt?(Wt=de,mn=we,Kt=ie):(Wt=Le,mn=Ke,Kt=re,bt=Zt);let hn=0,Dt=0,Yt=null;if(Ut<cn?(hn=He,Dt=Re,Yt=$):(hn=wt,Dt=rt,Yt=K,Ut=cn),bt<Ut?(V.x=Wt,V.y=mn,D.x=Kt.x,D.y=Kt.y,Q=Math.sqrt(bt)):(D.x=hn,D.y=Dt,V.x=Yt.x,V.y=Yt.y,Q=Math.sqrt(Ut)),Q!=0){d.x=D.x-V.x,d.y=D.y-V.y;let sn=1/Q;d.x*=sn,d.y*=sn,j&&(d.x=-d.x,d.y=-d.y)}z=Q}else{let $=0,K=0;$=F.gp0.x,K=F.gp0.y;let ie=0,re=0;ie=F.gp1.x,re=F.gp1.y;let se=0,te=0;se=ie-$,te=re-K;let oe=b.gnormy*$-b.gnormx*K,pe=b.gnormy*ie-b.gnormx*re,ce=1/(pe-oe),ae=(-b.tp1-oe)*ce;if(ae>i.Config.epsilon){let ye=ae;$+=se*ye,K+=te*ye}let ue=(-b.tp0-pe)*ce;if(ue<-i.Config.epsilon){let ye=ue;ie+=se*ye,re+=te*ye}let ne=$*b.gnormx+K*b.gnormy-b.gprojection,he=ie*b.gnormx+re*b.gnormy-b.gprojection;if(ne<he){D.x=$,D.y=K;let ye=-ne;V.x=D.x+b.gnormx*ye,V.y=D.y+b.gnormy*ye,z=ne}else{D.x=ie,D.y=re;let ye=-he;V.x=D.x+b.gnormx*ye,V.y=D.y+b.gnormy*ye,z=he}}}else z=1e100}else z=1e100}}let T=z+s,G=p*d.x+c*d.y;if(T<i.Config.distanceThresholdCCD){let j=0,A=0;j=x.x-a.posx,A=x.y-a.posy;let W=G-a.sweep_angvel*(d.y*j-d.x*A);if(W>0&&(e.slipped=!0),W<=0||T<i.Config.distanceThresholdCCD*.5)break}let q=(u-G)*t;if(q<=0){_=-1;break}let R=T/q;if(R<1e-6&&(R=1e-6),_+=R,_>=1){_=1;let j=_*t,A=j-a.sweepTime;if(A!=0){a.sweepTime=j;let L=A;if(a.posx+=a.velx*L,a.posy+=a.vely*L,a.angvel!=0){let F=a.sweep_angvel*A;if(a.rot+=F,F*F>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let I=F*F,U=1-.5*I,$=1-I*I/8,K=(U*a.axisx+F*a.axisy)*$;a.axisy=(U*a.axisy-F*a.axisx)*$,a.axisx=K}}}if(l.type==0)l.worldCOMx=a.posx+(a.axisy*l.localCOMx-a.axisx*l.localCOMy),l.worldCOMy=a.posy+(l.localCOMx*a.axisx+l.localCOMy*a.axisy);else{let L=l.polygon,F=L.lverts.next,I=L.gverts.next;for(;I!=null;){let se=I,te=F;F=F.next,se.x=a.posx+(a.axisy*te.x-a.axisx*te.y),se.y=a.posy+(te.x*a.axisx+te.y*a.axisy),I=I.next}let U=L.edges.head,$=L.gverts.next,K=$;for($=$.next;$!=null;){let se=$,te=U.elt;U=U.next,te.gnormx=a.axisy*te.lnormx-a.axisx*te.lnormy,te.gnormy=te.lnormx*a.axisx+te.lnormy*a.axisy,te.gprojection=a.posx*te.gnormx+a.posy*te.gnormy+te.lprojection,te.tp0=K.y*te.gnormx-K.x*te.gnormy,te.tp1=se.y*te.gnormx-se.x*te.gnormy,K=se,$=$.next}let ie=L.gverts.next,re=U.elt;U=U.next,re.gnormx=a.axisy*re.lnormx-a.axisx*re.lnormy,re.gnormy=re.lnormx*a.axisx+re.lnormy*a.axisy,re.gprojection=a.posx*re.gnormx+a.posy*re.gnormy+re.lprojection,re.tp0=K.y*re.gnormx-K.x*re.gnormy,re.tp1=ie.y*re.gnormx-ie.x*re.gnormy}let W=l,Q=r,Y=x,X=y;var C;if(W.type==0&&Q.type==0){let L=W.circle,F=Q.circle;var v;let I=0,U=0;I=F.worldCOMx-L.worldCOMx,U=F.worldCOMy-L.worldCOMy;let $=Math.sqrt(I*I+U*U);if(v=$-(L.radius+F.radius),v<1e100){if($==0)I=1,U=0;else{let re=1/$;I*=re,U*=re}let K=L.radius;Y.x=L.worldCOMx+I*K,Y.y=L.worldCOMy+U*K;let ie=-F.radius;X.x=F.worldCOMx+I*ie,X.y=F.worldCOMy+U*ie,d.x=I,d.y=U}C=v}else{let L=!1;if(W.type==0&&Q.type==1){let F=W;W=Q,Q=F;let I=Y;Y=X,X=I,L=!0}if(W.type==1&&Q.type==0){let F=W.polygon,I=Q.circle,U=-1e100,$=null,K=F.edges.head;for(;K!=null;){let ie=K.elt,re=ie.gnormx*I.worldCOMx+ie.gnormy*I.worldCOMy-ie.gprojection-I.radius;if(re>1e100){U=re;break}re>0?re>U&&(U=re,$=ie):U<0&&re>U&&(U=re,$=ie),K=K.next}if(U<1e100){let ie=$.gp0,re=$.gp1,se=I.worldCOMy*$.gnormx-I.worldCOMx*$.gnormy;if(se<=ie.y*$.gnormx-ie.x*$.gnormy){let te=0,oe=0;te=I.worldCOMx-ie.x,oe=I.worldCOMy-ie.y;let pe=Math.sqrt(te*te+oe*oe);if(U=pe-I.radius,U<1e100){if(pe==0)te=1,oe=0;else{let ue=1/pe;te*=ue,oe*=ue}let ce=0;Y.x=ie.x+te*ce,Y.y=ie.y+oe*ce;let ae=-I.radius;X.x=I.worldCOMx+te*ae,X.y=I.worldCOMy+oe*ae,d.x=te,d.y=oe}}else if(se>=re.y*$.gnormx-re.x*$.gnormy){let te=0,oe=0;te=I.worldCOMx-re.x,oe=I.worldCOMy-re.y;let pe=Math.sqrt(te*te+oe*oe);if(U=pe-I.radius,U<1e100){if(pe==0)te=1,oe=0;else{let ue=1/pe;te*=ue,oe*=ue}let ce=0;Y.x=re.x+te*ce,Y.y=re.y+oe*ce;let ae=-I.radius;X.x=I.worldCOMx+te*ae,X.y=I.worldCOMy+oe*ae,d.x=te,d.y=oe}}else{let te=-I.radius;X.x=I.worldCOMx+$.gnormx*te,X.y=I.worldCOMy+$.gnormy*te;let oe=-U;Y.x=X.x+$.gnormx*oe,Y.y=X.y+$.gnormy*oe,d.x=$.gnormx,d.y=$.gnormy}}L&&(d.x=-d.x,d.y=-d.y),C=U}else{let F=W.polygon,I=Q.polygon,U=-1e100,$=null,K=null,ie=0,re=F.edges.head;for(;re!=null;){let se=re.elt,te=1e100,oe=I.gverts.next;for(;oe!=null;){let pe=oe,ce=se.gnormx*pe.x+se.gnormy*pe.y;ce<te&&(te=ce),oe=oe.next}if(te-=se.gprojection,te>1e100){U=te;break}te>0?te>U&&(U=te,$=se,ie=1):U<0&&te>U&&(U=te,$=se,ie=1),re=re.next}if(U<1e100){let se=I.edges.head;for(;se!=null;){let te=se.elt,oe=1e100,pe=F.gverts.next;for(;pe!=null;){let ce=pe,ae=te.gnormx*ce.x+te.gnormy*ce.y;ae<oe&&(oe=ae),pe=pe.next}if(oe-=te.gprojection,oe>1e100){U=oe;break}oe>0?oe>U&&(U=oe,K=te,ie=2):U<0&&oe>U&&(U=oe,K=te,ie=2),se=se.next}if(U<1e100){var w,O,E;if(ie==1)w=F,O=I,E=$;else{w=I,O=F,E=K;let ce=Y;Y=X,X=ce,L=!L}let te=null,oe=1e100,pe=O.edges.head;for(;pe!=null;){let ce=pe.elt,ae=E.gnormx*ce.gnormx+E.gnormy*ce.gnormy;ae<oe&&(oe=ae,te=ce),pe=pe.next}if(L?(d.x=-E.gnormx,d.y=-E.gnormy):(d.x=E.gnormx,d.y=E.gnormy),U>=0){let ce=E.gp0,ae=E.gp1,ue=te.gp0,ne=te.gp1,he=0,ye=0,de=0,we=0;he=ae.x-ce.x,ye=ae.y-ce.y,de=ne.x-ue.x,we=ne.y-ue.y;let Oe=1/(he*he+ye*ye),Le=1/(de*de+we*we),Ke=-(he*(ce.x-ue.x)+ye*(ce.y-ue.y))*Oe,Xe=-(he*(ce.x-ne.x)+ye*(ce.y-ne.y))*Oe,He=-(de*(ue.x-ce.x)+we*(ue.y-ce.y))*Le,Re=-(de*(ue.x-ae.x)+we*(ue.y-ae.y))*Le;Ke<0?Ke=0:Ke>1&&(Ke=1),Xe<0?Xe=0:Xe>1&&(Xe=1),He<0?He=0:He>1&&(He=1),Re<0?Re=0:Re>1&&(Re=1);let mt=0,wt=0,rt=Ke;mt=ce.x+he*rt,wt=ce.y+ye*rt;let at=0,ot=0,Ye=Xe;at=ce.x+he*Ye,ot=ce.y+ye*Ye;let bt=0,Bt=0,Ft=He;bt=ue.x+de*Ft,Bt=ue.y+we*Ft;let Zt=0,kt=0,yn=Re;Zt=ue.x+de*yn,kt=ue.y+we*yn;let Ut=0,pn=0;Ut=mt-ue.x,pn=wt-ue.y;let nn=Ut*Ut+pn*pn,cn=0,Wt=0;cn=at-ne.x,Wt=ot-ne.y;let mn=cn*cn+Wt*Wt,Kt=0,hn=0;Kt=bt-ce.x,hn=Bt-ce.y;let Dt=Kt*Kt+hn*hn,Yt=0,sn=0;Yt=Zt-ae.x,sn=kt-ae.y;let Qn=Yt*Yt+sn*sn,Tn=0,Nn=0,On=null;nn<mn?(Tn=mt,Nn=wt,On=ue):(Tn=at,Nn=ot,On=ne,nn=mn);let Ci=0,Mi=0,Zi=null;if(Dt<Qn?(Ci=bt,Mi=Bt,Zi=ce):(Ci=Zt,Mi=kt,Zi=ae,Dt=Qn),nn<Dt?(Y.x=Tn,Y.y=Nn,X.x=On.x,X.y=On.y,U=Math.sqrt(nn)):(X.x=Ci,X.y=Mi,Y.x=Zi.x,Y.y=Zi.y,U=Math.sqrt(Dt)),U!=0){d.x=X.x-Y.x,d.y=X.y-Y.y;let rs=1/U;d.x*=rs,d.y*=rs,L&&(d.x=-d.x,d.y=-d.y)}C=U}else{let ce=0,ae=0;ce=te.gp0.x,ae=te.gp0.y;let ue=0,ne=0;ue=te.gp1.x,ne=te.gp1.y;let he=0,ye=0;he=ue-ce,ye=ne-ae;let de=E.gnormy*ce-E.gnormx*ae,we=E.gnormy*ue-E.gnormx*ne,Oe=1/(we-de),Le=(-E.tp1-de)*Oe;if(Le>i.Config.epsilon){let Re=Le;ce+=he*Re,ae+=ye*Re}let Ke=(-E.tp0-we)*Oe;if(Ke<-i.Config.epsilon){let Re=Ke;ue+=he*Re,ne+=ye*Re}let Xe=ce*E.gnormx+ae*E.gnormy-E.gprojection,He=ue*E.gnormx+ne*E.gnormy-E.gprojection;if(Xe<He){X.x=ce,X.y=ae;let Re=-Xe;Y.x=X.x+E.gnormx*Re,Y.y=X.y+E.gnormy*Re,C=Xe}else{X.x=ue,X.y=ne;let Re=-He;Y.x=X.x+E.gnormx*Re,Y.y=X.y+E.gnormy*Re,C=He}}}else C=1e100}else C=1e100}}let ee=C+s,J=p*d.x+c*d.y;if(ee<i.Config.distanceThresholdCCD){let L=0,F=0;L=x.x-a.posx,F=x.y-a.posy;let I=J-a.sweep_angvel*(d.y*L-d.x*F);if(I>0&&(e.slipped=!0),I<=0||ee<i.Config.distanceThresholdCCD*.5)break}_=-1;break}if(++f>=40){T>s&&(e.failed=!0);break}}e.toi=_}static distanceBody(e,t,n,s){let i=me(),l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1;let r;le.zpp_pool==null?r=new le:(r=le.zpp_pool,le.zpp_pool=r.next,r.next=null),r.weak=!1;let a;le.zpp_pool==null?a=new le:(a=le.zpp_pool,le.zpp_pool=a.next,a.next=null),a.weak=!1;let o=1e100,p=e.shapes.head;for(;p!=null;){let z=p.elt,P=t.shapes.head;for(;P!=null;){let k=P.elt,m=z,b=k,C=l,v=r,w=o;w==null&&(w=1e100);var c;if(m.type==0&&b.type==0){let O=m.circle,E=b.circle;var h;let M=0,N=0;M=E.worldCOMx-O.worldCOMx,N=E.worldCOMy-O.worldCOMy;let Z=Math.sqrt(M*M+N*N);if(h=Z-(O.radius+E.radius),h<w){if(Z==0)M=1,N=0;else{let D=1/Z;M*=D,N*=D}let S=O.radius;C.x=O.worldCOMx+M*S,C.y=O.worldCOMy+N*S;let V=-E.radius;v.x=E.worldCOMx+M*V,v.y=E.worldCOMy+N*V,a.x=M,a.y=N}c=h}else{let O=!1;if(m.type==0&&b.type==1){let E=m;m=b,b=E;let M=C;C=v,v=M,O=!0}if(m.type==1&&b.type==0){let E=m.polygon,M=b.circle,N=-1e100,Z=null,S=E.edges.head;for(;S!=null;){let V=S.elt,D=V.gnormx*M.worldCOMx+V.gnormy*M.worldCOMy-V.gprojection-M.radius;if(D>w){N=D;break}D>0?D>N&&(N=D,Z=V):N<0&&D>N&&(N=D,Z=V),S=S.next}if(N<w){let V=Z.gp0,D=Z.gp1,T=M.worldCOMy*Z.gnormx-M.worldCOMx*Z.gnormy;if(T<=V.y*Z.gnormx-V.x*Z.gnormy){let G=0,q=0;G=M.worldCOMx-V.x,q=M.worldCOMy-V.y;let R=Math.sqrt(G*G+q*q);if(N=R-M.radius,N<w){if(R==0)G=1,q=0;else{let W=1/R;G*=W,q*=W}let j=0;C.x=V.x+G*j,C.y=V.y+q*j;let A=-M.radius;v.x=M.worldCOMx+G*A,v.y=M.worldCOMy+q*A,a.x=G,a.y=q}}else if(T>=D.y*Z.gnormx-D.x*Z.gnormy){let G=0,q=0;G=M.worldCOMx-D.x,q=M.worldCOMy-D.y;let R=Math.sqrt(G*G+q*q);if(N=R-M.radius,N<w){if(R==0)G=1,q=0;else{let W=1/R;G*=W,q*=W}let j=0;C.x=D.x+G*j,C.y=D.y+q*j;let A=-M.radius;v.x=M.worldCOMx+G*A,v.y=M.worldCOMy+q*A,a.x=G,a.y=q}}else{let G=-M.radius;v.x=M.worldCOMx+Z.gnormx*G,v.y=M.worldCOMy+Z.gnormy*G;let q=-N;C.x=v.x+Z.gnormx*q,C.y=v.y+Z.gnormy*q,a.x=Z.gnormx,a.y=Z.gnormy}}O&&(a.x=-a.x,a.y=-a.y),c=N}else{let E=m.polygon,M=b.polygon,N=-1e100,Z=null,S=null,V=0,D=E.edges.head;for(;D!=null;){let T=D.elt,G=1e100,q=M.gverts.next;for(;q!=null;){let R=q,j=T.gnormx*R.x+T.gnormy*R.y;j<G&&(G=j),q=q.next}if(G-=T.gprojection,G>w){N=G;break}G>0?G>N&&(N=G,Z=T,V=1):N<0&&G>N&&(N=G,Z=T,V=1),D=D.next}if(N<w){let T=M.edges.head;for(;T!=null;){let G=T.elt,q=1e100,R=E.gverts.next;for(;R!=null;){let j=R,A=G.gnormx*j.x+G.gnormy*j.y;A<q&&(q=A),R=R.next}if(q-=G.gprojection,q>w){N=q;break}q>0?q>N&&(N=q,S=G,V=2):N<0&&q>N&&(N=q,S=G,V=2),T=T.next}if(N<w){var u,x,y;if(V==1)u=E,x=M,y=Z;else{u=M,x=E,y=S;let j=C;C=v,v=j,O=!O}let G=null,q=1e100,R=x.edges.head;for(;R!=null;){let j=R.elt,A=y.gnormx*j.gnormx+y.gnormy*j.gnormy;A<q&&(q=A,G=j),R=R.next}if(O?(a.x=-y.gnormx,a.y=-y.gnormy):(a.x=y.gnormx,a.y=y.gnormy),N>=0){let j=y.gp0,A=y.gp1,W=G.gp0,Q=G.gp1,Y=0,X=0,ee=0,J=0;Y=A.x-j.x,X=A.y-j.y,ee=Q.x-W.x,J=Q.y-W.y;let L=1/(Y*Y+X*X),F=1/(ee*ee+J*J),I=-(Y*(j.x-W.x)+X*(j.y-W.y))*L,U=-(Y*(j.x-Q.x)+X*(j.y-Q.y))*L,$=-(ee*(W.x-j.x)+J*(W.y-j.y))*F,K=-(ee*(W.x-A.x)+J*(W.y-A.y))*F;I<0?I=0:I>1&&(I=1),U<0?U=0:U>1&&(U=1),$<0?$=0:$>1&&($=1),K<0?K=0:K>1&&(K=1);let ie=0,re=0,se=I;ie=j.x+Y*se,re=j.y+X*se;let te=0,oe=0,pe=U;te=j.x+Y*pe,oe=j.y+X*pe;let ce=0,ae=0,ue=$;ce=W.x+ee*ue,ae=W.y+J*ue;let ne=0,he=0,ye=K;ne=W.x+ee*ye,he=W.y+J*ye;let de=0,we=0;de=ie-W.x,we=re-W.y;let Oe=de*de+we*we,Le=0,Ke=0;Le=te-Q.x,Ke=oe-Q.y;let Xe=Le*Le+Ke*Ke,He=0,Re=0;He=ce-j.x,Re=ae-j.y;let mt=He*He+Re*Re,wt=0,rt=0;wt=ne-A.x,rt=he-A.y;let at=wt*wt+rt*rt,ot=0,Ye=0,bt=null;Oe<Xe?(ot=ie,Ye=re,bt=W):(ot=te,Ye=oe,bt=Q,Oe=Xe);let Bt=0,Ft=0,Zt=null;if(mt<at?(Bt=ce,Ft=ae,Zt=j):(Bt=ne,Ft=he,Zt=A,mt=at),Oe<mt?(C.x=ot,C.y=Ye,v.x=bt.x,v.y=bt.y,N=Math.sqrt(Oe)):(v.x=Bt,v.y=Ft,C.x=Zt.x,C.y=Zt.y,N=Math.sqrt(mt)),N!=0){a.x=v.x-C.x,a.y=v.y-C.y;let kt=1/N;a.x*=kt,a.y*=kt,O&&(a.x=-a.x,a.y=-a.y)}c=N}else{let j=0,A=0;j=G.gp0.x,A=G.gp0.y;let W=0,Q=0;W=G.gp1.x,Q=G.gp1.y;let Y=0,X=0;Y=W-j,X=Q-A;let ee=y.gnormy*j-y.gnormx*A,J=y.gnormy*W-y.gnormx*Q,L=1/(J-ee),F=(-y.tp1-ee)*L;if(F>i.Config.epsilon){let K=F;j+=Y*K,A+=X*K}let I=(-y.tp0-J)*L;if(I<-i.Config.epsilon){let K=I;W+=Y*K,Q+=X*K}let U=j*y.gnormx+A*y.gnormy-y.gprojection,$=W*y.gnormx+Q*y.gnormy-y.gprojection;if(U<$){v.x=j,v.y=A;let K=-U;C.x=v.x+y.gnormx*K,C.y=v.y+y.gnormy*K,c=U}else{v.x=W,v.y=Q;let K=-$;C.x=v.x+y.gnormx*K,C.y=v.y+y.gnormy*K,c=$}}}else c=w}else c=w}}c<o&&(o=c,n.x=l.x,n.y=l.y,s.x=r.x,s.y=r.y),P=P.next}p=p.next}let d=l;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=le.zpp_pool,le.zpp_pool=d;let _=r;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=le.zpp_pool,le.zpp_pool=_;let f=a;return f.outer!=null&&(f.outer.zpp_inner=null,f.outer=null),f._isimmutable=null,f._validate=null,f._invalidate=null,f.next=le.zpp_pool,le.zpp_pool=f,o}static distance(e,t,n,s,i,l){let r=me();if(l==null&&(l=1e100),e.type==0&&t.type==0){let a=e.circle,o=t.circle,p,c=0,h=0;c=o.worldCOMx-a.worldCOMx,h=o.worldCOMy-a.worldCOMy;let u=Math.sqrt(c*c+h*h);if(p=u-(a.radius+o.radius),p<l){if(u==0)c=1,h=0;else{let d=1/u;c*=d,h*=d}let x=a.radius;n.x=a.worldCOMx+c*x,n.y=a.worldCOMy+h*x;let y=-o.radius;s.x=o.worldCOMx+c*y,s.y=o.worldCOMy+h*y,i.x=c,i.y=h}return p}else{let a=!1;if(e.type==0&&t.type==1){let o=e;e=t,t=o;let p=n;n=s,s=p,a=!0}if(e.type==1&&t.type==0){let o=e.polygon,p=t.circle,c=-1e100,h=null,u=o.edges.head;for(;u!=null;){let x=u.elt,y=x.gnormx*p.worldCOMx+x.gnormy*p.worldCOMy-x.gprojection-p.radius;if(y>l){c=y;break}y>0?y>c&&(c=y,h=x):c<0&&y>c&&(c=y,h=x),u=u.next}if(c<l){let x=h.gp0,y=h.gp1,d=p.worldCOMy*h.gnormx-p.worldCOMx*h.gnormy;if(d<=x.y*h.gnormx-x.x*h.gnormy){let _=0,f=0;_=p.worldCOMx-x.x,f=p.worldCOMy-x.y;let z=Math.sqrt(_*_+f*f);if(c=z-p.radius,c<l){if(z==0)_=1,f=0;else{let m=1/z;_*=m,f*=m}let P=0;n.x=x.x+_*P,n.y=x.y+f*P;let k=-p.radius;s.x=p.worldCOMx+_*k,s.y=p.worldCOMy+f*k,i.x=_,i.y=f}}else if(d>=y.y*h.gnormx-y.x*h.gnormy){let _=0,f=0;_=p.worldCOMx-y.x,f=p.worldCOMy-y.y;let z=Math.sqrt(_*_+f*f);if(c=z-p.radius,c<l){if(z==0)_=1,f=0;else{let m=1/z;_*=m,f*=m}let P=0;n.x=y.x+_*P,n.y=y.y+f*P;let k=-p.radius;s.x=p.worldCOMx+_*k,s.y=p.worldCOMy+f*k,i.x=_,i.y=f}}else{let _=-p.radius;s.x=p.worldCOMx+h.gnormx*_,s.y=p.worldCOMy+h.gnormy*_;let f=-c;n.x=s.x+h.gnormx*f,n.y=s.y+h.gnormy*f,i.x=h.gnormx,i.y=h.gnormy}}return a&&(i.x=-i.x,i.y=-i.y),c}else{let o=e.polygon,p=t.polygon,c=-1e100,h=null,u=null,x=0,y=o.edges.head;for(;y!=null;){let d=y.elt,_=1e100,f=p.gverts.next;for(;f!=null;){let z=f,P=d.gnormx*z.x+d.gnormy*z.y;P<_&&(_=P),f=f.next}if(_-=d.gprojection,_>l){c=_;break}_>0?_>c&&(c=_,h=d,x=1):c<0&&_>c&&(c=_,h=d,x=1),y=y.next}if(c<l){let d=p.edges.head;for(;d!=null;){let _=d.elt,f=1e100,z=o.gverts.next;for(;z!=null;){let P=z,k=_.gnormx*P.x+_.gnormy*P.y;k<f&&(f=k),z=z.next}if(f-=_.gprojection,f>l){c=f;break}f>0?f>c&&(c=f,u=_,x=2):c<0&&f>c&&(c=f,u=_,x=2),d=d.next}if(c<l){let _,f,z;if(x==1)_=o,f=p,z=h;else{_=p,f=o,z=u;let b=n;n=s,s=b,a=!a}let P=null,k=1e100,m=f.edges.head;for(;m!=null;){let b=m.elt,C=z.gnormx*b.gnormx+z.gnormy*b.gnormy;C<k&&(k=C,P=b),m=m.next}if(a?(i.x=-z.gnormx,i.y=-z.gnormy):(i.x=z.gnormx,i.y=z.gnormy),c>=0){let b=z.gp0,C=z.gp1,v=P.gp0,w=P.gp1,O=0,E=0,M=0,N=0;O=C.x-b.x,E=C.y-b.y,M=w.x-v.x,N=w.y-v.y;let Z=1/(O*O+E*E),S=1/(M*M+N*N),V=-(O*(b.x-v.x)+E*(b.y-v.y))*Z,D=-(O*(b.x-w.x)+E*(b.y-w.y))*Z,T=-(M*(v.x-b.x)+N*(v.y-b.y))*S,G=-(M*(v.x-C.x)+N*(v.y-C.y))*S;V<0?V=0:V>1&&(V=1),D<0?D=0:D>1&&(D=1),T<0?T=0:T>1&&(T=1),G<0?G=0:G>1&&(G=1);let q=0,R=0,j=V;q=b.x+O*j,R=b.y+E*j;let A=0,W=0,Q=D;A=b.x+O*Q,W=b.y+E*Q;let Y=0,X=0,ee=T;Y=v.x+M*ee,X=v.y+N*ee;let J=0,L=0,F=G;J=v.x+M*F,L=v.y+N*F;let I=0,U=0;I=q-v.x,U=R-v.y;let $=I*I+U*U,K=0,ie=0;K=A-w.x,ie=W-w.y;let re=K*K+ie*ie,se=0,te=0;se=Y-b.x,te=X-b.y;let oe=se*se+te*te,pe=0,ce=0;pe=J-C.x,ce=L-C.y;let ae=pe*pe+ce*ce,ue=0,ne=0,he=null;$<re?(ue=q,ne=R,he=v):(ue=A,ne=W,he=w,$=re);let ye=0,de=0,we=null;if(oe<ae?(ye=Y,de=X,we=b):(ye=J,de=L,we=C,oe=ae),$<oe?(n.x=ue,n.y=ne,s.x=he.x,s.y=he.y,c=Math.sqrt($)):(s.x=ye,s.y=de,n.x=we.x,n.y=we.y,c=Math.sqrt(oe)),c!=0){i.x=s.x-n.x,i.y=s.y-n.y;let Oe=1/c;i.x*=Oe,i.y*=Oe,a&&(i.x=-i.x,i.y=-i.y)}return c}else{let b=0,C=0;b=P.gp0.x,C=P.gp0.y;let v=0,w=0;v=P.gp1.x,w=P.gp1.y;let O=0,E=0;O=v-b,E=w-C;let M=z.gnormy*b-z.gnormx*C,N=z.gnormy*v-z.gnormx*w,Z=1/(N-M),S=(-z.tp1-M)*Z;if(S>r.Config.epsilon){let G=S;b+=O*G,C+=E*G}let V=(-z.tp0-N)*Z;if(V<-r.Config.epsilon){let G=V;v+=O*G,w+=E*G}let D=b*z.gnormx+C*z.gnormy-z.gprojection,T=v*z.gnormx+w*z.gnormy-z.gprojection;if(D<T){s.x=b,s.y=C;let G=-D;return n.x=s.x+z.gnormx*G,n.y=s.y+z.gnormy*G,D}else{s.x=v,s.y=w;let G=-T;return n.x=s.x+z.gnormx*G,n.y=s.y+z.gnormy*G,T}}}else return l}else return l}}}};var Fe=class Fe{static lt(e,t){return e.y<t.y?!0:e.y==t.y?e.x<t.x:!1}static right_turn(e,t,n){let s=n.x-t.x,i=n.y-t.y,l=t.x-e.x;return(t.y-e.y)*s-l*i}static delaunay(e,t,n,s){let i=n.x-t.x,l=n.y-t.y,r=t.x-e.x,a=t.y-e.y,o,p,c;return a*i-r*l>=0?c=!0:(i=s.x-n.x,l=s.y-n.y,r=n.x-t.x,a=n.y-t.y,c=a*i-r*l>=0),c?p=!0:(i=e.x-s.x,l=e.y-s.y,r=s.x-n.x,a=s.y-n.y,p=a*i-r*l>=0),p?o=!0:(i=t.x-e.x,l=t.y-e.y,r=e.x-s.x,a=e.y-s.y,o=a*i-r*l>=0),o?!0:t.x*(n.y*s.mag-n.mag*s.y)-n.x*(t.y*s.mag-t.mag*s.y)+s.x*(t.y*n.mag-t.mag*n.y)-(e.x*(n.y*s.mag-n.mag*s.y)-n.x*(e.y*s.mag-e.mag*s.y)+s.x*(e.y*n.mag-e.mag*n.y))+(e.x*(t.y*s.mag-t.mag*s.y)-t.x*(e.y*s.mag-e.mag*s.y)+s.x*(e.y*t.mag-e.mag*t.y))-(e.x*(t.y*n.mag-t.mag*n.y)-t.x*(e.y*n.mag-e.mag*n.y)+n.x*(e.y*t.mag-e.mag*t.y))>0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let a=t;for(;;){let o=a;if(o.sort(),o.mag=o.x*o.x+o.y*o.y,a=a.next,a==n)break}}Fe.edgeSet==null&&(_s.zpp_pool==null?Fe.edgeSet=new _s:(Fe.edgeSet=_s.zpp_pool,_s.zpp_pool=Fe.edgeSet.next,Fe.edgeSet.next=null),Fe.edgeSet.lt=Ot.edge_lt,Fe.edgeSet.swapped=Ot.edge_swap);let s;Ot.zpp_pool==null?s=new Ot:(s=Ot.zpp_pool,Ot.zpp_pool=s.next,s.next=null);let i=e.vertices,l=e.vertices;if(i!=null){let a=i;for(;;){let o=a,p=o.next;o.diagonals.reverse();let c=o.diagonals.head;for(;c!=null;){let h=c.elt;if(h.id<o.id){p=h,c=c.next;continue}let u=c.next==null?o.prev:c.next.elt;if(!Fe.delaunay(o,p,h,u)){let x;Ot.zpp_pool==null?x=new Ot:(x=Ot.zpp_pool,Ot.zpp_pool=x.next,x.next=null),x.a=o,x.b=h,o.id<h.id?(x.id=o.id,x.di=h.id):(x.id=h.id,x.di=o.id);let y=x;s.add(y),y.node=Fe.edgeSet.insert(y)}p=h,c=c.next}if(a=a.next,a==l)break}}for(;s.next!=null;){let a=s.pop_unsafe(),o=a.a,p=a.b,c=o.next,h=null,u=o.diagonals.head;for(;u!=null;){let y=u.elt;if(y==p){u=u.next,h=u==null?o.prev:u.elt;break}c=y,u=u.next}if(o.diagonals.remove(p),p.diagonals.remove(o),p==c.next)c.diagonals.add(h);else{let y=c.diagonals.head;for(;y!=null;){if(y.elt==p){c.diagonals.insert(y,h);break}y=y.next}}if(o==h.next)h.diagonals.add(c);else{let y=h.diagonals.head;for(;y!=null;){if(y.elt==o){h.diagonals.insert(y,c);break}y=y.next}}Fe.edgeSet.remove_node(a.node);let x=a;x.a=x.b=null,x.node=null,x.next=Ot.zpp_pool,Ot.zpp_pool=x}let r=s;r.a=r.b=null,r.node=null,r.next=Ot.zpp_pool,Ot.zpp_pool=r}static triangulate(e){let t=e.vertices,n=e.vertices,s=e.vertices.next,i=e.vertices;if(s!=null){let o=s;for(;;){let p=o;if((p.y<t.y||p.y==t.y&&p.x<t.x)&&(t=p),(n.y<p.y||n.y==p.y&&n.x<p.x)&&(n=p),o=o.next,o==i)break}}Fe.queue==null&&(Fe.queue=new pi);let l=n.prev,r=n.next;for(Fe.queue.add(n);l!=t||r!=t;)l==t||r!=t&&(l.y<r.y||l.y==r.y&&l.x<r.x)?(Fe.queue.add(r),r.rightchain=!1,r=r.next):(Fe.queue.add(l),l.rightchain=!0,l=l.prev);Fe.queue.add(t),Fe.stack==null&&(Fe.stack=new pi),Fe.stack.add(Fe.queue.pop_unsafe());let a=Fe.queue.pop_unsafe();for(Fe.stack.add(a);;){let o=Fe.queue.pop_unsafe();if(Fe.queue.head==null)break;if(o.rightchain!=Fe.stack.head.elt.rightchain){for(;;){let p=Fe.stack.pop_unsafe();if(Fe.stack.head==null)break;e.add_diagonal(p,o)}Fe.stack.add(a)}else{let p=Fe.stack.pop_unsafe();for(;Fe.stack.head!=null;){let c=Fe.stack.head.elt,h=o.x-p.x,u=o.y-p.y,x=p.x-c.x,d=(p.y-c.y)*h-x*u;if(o.rightchain&&d>=0||!o.rightchain&&d<=0)break;e.add_diagonal(c,o),p=c,Fe.stack.pop()}Fe.stack.add(p)}Fe.stack.add(o),a=o}if(Fe.stack.head!=null)for(Fe.stack.pop();Fe.stack.head!=null;){let o=Fe.stack.pop_unsafe();if(Fe.stack.head==null)break;e.add_diagonal(n,o)}return e}};Fe.queue=null,Fe.stack=null,Fe.edgeSet=null;var xl=Fe;var fs=class fs{constructor(){this.outer=null;this.x=0;this.y=0;this.z=0;this.immutable=!1;this._validate=null}validate(){this._validate!=null&&this._validate()}wrapper(){return this.outer==null&&fs._wrapFn&&(this.outer=fs._wrapFn(this)),this.outer}};fs._zpp=null,fs._wrapFn=null;var ti=fs;var dl=class{static vec_dsq(e,t,n,s){let i=e-n,l=t-s;return i*i+l*l}static vec_distance(e,t,n,s){let i=e-n,l=t-s;return Math.sqrt(i*i+l*l)}};var _n=class _n{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;_n.initFields(this)}static initFields(e){let t=_n._zpp;e.wrap_cbTypes=null,e.cbSet=null,e.cbTypes=null,e.group=null,e.cbsets=null,e.icompound=null,e.ibody=null,e.ishape=null,e.userData=null,e.id=0,e.outer_i=null,e.id=un.Interactor(),e.cbsets=new t.util.ZNPList_ZPP_CallbackSet,e.cbTypes=new t.util.ZNPList_ZPP_CbType}static get(e,t){let n=e.id<t.id?e.id:t.id,s=e.id<t.id?t.id:e.id,i=e.cbsets.length<t.cbsets.length?e.cbsets:t.cbsets,l=null,r=i.head;for(;r!=null;){let a=r.elt;if(a.id==n&&a.di==s){l=a;break}r=r.next}return l}static int_callback(e,t,n){let s=e.int1,i=e.int2,l,r=t.options1,a=s.cbTypes;if(r.nonemptyintersection(a,r.includes)&&!r.nonemptyintersection(a,r.excludes)){let o=t.options2,p=i.cbTypes;l=o.nonemptyintersection(p,o.includes)&&!o.nonemptyintersection(p,o.excludes)}else l=!1;l?(n.int1=s,n.int2=i):(n.int1=i,n.int2=s)}isShape(){return this.ishape!=null}isBody(){return this.ibody!=null}isCompound(){return this.icompound!=null}__iaddedToSpace(){this.group!=null&&this.group.interactors.add(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.add(this),e=e.next;this.alloc_cbSet()}__iremovedFromSpace(){this.group!=null&&this.group.interactors.remove(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.remove(this),e=e.next;this.dealloc_cbSet()}wake(){if(this.ishape!=null){let e=this.ishape.body;e!=null&&e.space!=null&&e.space.non_inlined_wake(e)}else this.ibody!=null?this.ibody.space!=null&&this.ibody.space.non_inlined_wake(this.ibody):this.icompound.space!=null&&this.icompound.space.wakeCompound(this.icompound)}_getSpace(){return this.ishape!=null?this.ishape.body==null?null:this.ishape.body.space:this.ibody!=null?this.ibody.space:this.icompound.space}getSpace(){return this._getSpace()}setupcbTypes(){let e=_n._zpp;this.wrap_cbTypes=e.util.ZPP_CbTypeList.get(this.cbTypes),this.wrap_cbTypes.zpp_inner.adder=this.wrap_cbTypes_adder.bind(this),this.wrap_cbTypes.zpp_inner.subber=this.wrap_cbTypes_subber.bind(this),this.wrap_cbTypes.zpp_inner.dontremove=!0,this.wrap_cbTypes.zpp_inner._modifiable=this.immutable_cbTypes.bind(this)}immutable_cbTypes(){this.immutable_midstep("Interactor::cbTypes")}wrap_cbTypes_subber(e){let t=e.zpp_inner;if(this.cbTypes.has(t)){let n=this._getSpace();n!=null&&(this.dealloc_cbSet(),t.interactors.remove(this)),this.cbTypes.remove(t),n!=null&&(this.alloc_cbSet(),this.wake())}}wrap_cbTypes_adder(e){return this.insert_cbtype(e.zpp_inner),!1}insert_cbtype(e){let t=_n._zpp;if(!this.cbTypes.has(e)){let n=this._getSpace();n!=null&&(this.dealloc_cbSet(),e.interactors.add(this));let s=null,i=this.cbTypes.head;for(;i!=null;){let o=i.elt;if(e.id<o.id)break;s=i,i=i.next}let l=this.cbTypes,r;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?r=new t.util.ZNPNode_ZPP_CbType:(r=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=r.next,r.next=null),r.elt=e;let a=r;s==null?(a.next=l.head,l.head=a):(a.next=s.next,s.next=a),l.pushmod=l.modified=!0,l.length++,n!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){let e=this._getSpace();(this.cbSet=e.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.interactors.add(this),this.cbSet.validate(),e.freshInteractorType(this))}dealloc_cbSet(){let e=this._getSpace();if(this.cbSet!=null){if(this.cbSet.interactors.remove(this),e.nullInteractorType(this),--this.cbSet.count==0){e.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=!0,t.bodylisteners.clear(),t.zip_bodylisteners=!0,t.conlisteners.clear(),t.zip_conlisteners=!0;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=dt.zpp_pool,dt.zpp_pool=t}this.cbSet=null}}setGroup(e){if(this.group!=e){let t=this._getSpace()!=null;t&&this.group!=null&&this.group.interactors.remove(this),this.group=e,t&&e!=null&&e.interactors.add(this),t&&(this.ishape!=null?this.ishape.body.wake():this.ibody!=null?this.ibody.wake():this.icompound.wake())}}immutable_midstep(e){if(this.ibody!=null){let t=this.ibody;if(t.space!=null&&t.space.midstep)throw new Error("Error: "+e+" cannot be set during a space step()")}else this.ishape!=null?this.ishape.__immutable_midstep(e):this.icompound.__imutable_midstep(e)}lookup_group(){let e=this;for(;e!=null&&e.group==null;)e.ishape!=null?e=e.ishape.body:e.icompound!=null?e=e.icompound.compound:e=e.ibody.compound;return e==null?null:e.group}copyto(e){let t=_n._nape;e.zpp_inner_i.group=this.group;let n=this.outer_i;n.zpp_inner_i.wrap_cbTypes==null&&n.zpp_inner_i.setupcbTypes();let s=n.zpp_inner_i.wrap_cbTypes;s.zpp_inner.valmod();let i=t.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let l=i.zpp_inner;l.zpp_inner.valmod(),l.zpp_inner.zip_length&&(l.zpp_inner.zip_length=!1,l.zpp_inner.user_length=l.zpp_inner.inner.length);let r=l.zpp_inner.user_length;i.zpp_critical=!0;let a;if(i.zpp_i<r?a=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,a=!1),!a)break;i.zpp_critical=!1;let o=i.zpp_inner.at(i.zpp_i++);e.zpp_inner_i.wrap_cbTypes==null&&e.zpp_inner_i.setupcbTypes();let p=e.zpp_inner_i.wrap_cbTypes;p.zpp_inner.reverse_flag?p.push(o):p.unshift(o)}this.userData!=null&&(e.zpp_inner_i.userData=Object.assign({},this.userData))}static _init(e,t){_n._initialized||(_n._initialized=!0,_n._zpp=e,_n._nape=t)}};_n._nape=null,_n._zpp=null,_n._initialized=!1;var Jt=_n;var Be=class Be{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.world=!1;this.type=0;this.compound=null;this.shapes=null;this.wrap_shapes=null;this.space=null;this.arbiters=null;this.wrap_arbiters=null;this.constraints=null;this.wrap_constraints=null;this.component=null;this.graph_depth=0;this.sweepTime=0;this.sweep_angvel=0;this.sweepFrozen=!1;this.sweepRadius=0;this.bullet=!1;this.bulletEnabled=!1;this.disableCCD=!1;this.pre_posx=0;this.pre_posy=0;this.posx=0;this.posy=0;this.wrap_pos=null;this.velx=0;this.vely=0;this.wrap_vel=null;this.forcex=0;this.forcey=0;this.wrap_force=null;this.kinvelx=0;this.kinvely=0;this.wrap_kinvel=null;this.svelx=0;this.svely=0;this.wrap_svel=null;this.wrapcvel=null;this.angvel=0;this.torque=0;this.kinangvel=0;this.pre_rot=0;this.rot=0;this.axisx=0;this.axisy=0;this.zip_axis=!1;this.kinematicDelaySleep=!1;this.mass=0;this.zip_mass=!1;this.massMode=0;this.imass=0;this.smass=0;this.cmass=0;this.nomove=!1;this.gravMass=0;this.zip_gravMass=!1;this.gravMassMode=0;this.gravMassScale=0;this.zip_gravMassScale=!1;this.inertiaMode=0;this.inertia=0;this.zip_inertia=!1;this.cinertia=0;this.iinertia=0;this.sinertia=0;this.norotate=!1;this.aabb=null;this.zip_aabb=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;let e=Be._zpp;Jt.initFields(this),this.ibody=this,this.world=!1,this.bulletEnabled=!1,this.sweepTime=0,this.sweep_angvel=0,this.norotate=this.nomove=!1,this.disableCCD=!1,this.posx=0,this.posy=0,this.rot=0,this.axisx=0,this.axisy=1,this.svelx=0,this.svely=0,this.velx=0,this.vely=0,this.kinvelx=0,this.kinvely=0,this.forcex=0,this.forcey=0,this.torque=this.angvel=this.kinangvel=0,this.pre_posx=1/0,this.pre_posy=1/0,this.pre_rot=1/0,this.localCOMx=0,this.localCOMy=0,this.worldCOMx=0,this.worldCOMy=0,this.zip_aabb=!0;let t;be.zpp_pool==null?t=new be:(t=be.zpp_pool,be.zpp_pool=t.next,t.next=null),t.minx=0,t.miny=0,t.maxx=0,t.maxy=0,this.aabb=t,this.aabb._immutable=!0,this.aabb._validate=this.aabb_validate.bind(this),this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.arbiters=new e.util.ZNPList_ZPP_Arbiter,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.shapes=new e.util.ZNPList_ZPP_Shape,this.wrap_shapes=e.util.ZPP_ShapeList.get(this.shapes),this.wrap_shapes.zpp_inner.adder=this.shapes_adder.bind(this),this.wrap_shapes.zpp_inner.subber=this.shapes_subber.bind(this),this.wrap_shapes.zpp_inner._invalidate=this.shapes_invalidate.bind(this),this.wrap_shapes.zpp_inner._modifiable=this.shapes_modifiable.bind(this),this.kinematicDelaySleep=!1}static bodysetlt(e,t){return e.id<t.id}static __static(){let e=Be._nape,t=Be._zpp;t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new e.phys.BodyType,t.util.ZPP_Flags.internal=!1);let n=new e.phys.Body(t.util.ZPP_Flags.BodyType_STATIC),s=n.zpp_inner;return s.world=!0,s.wrap_shapes.zpp_inner.immutable=!0,s.smass=s.imass=s.cmass=s.mass=s.gravMass=0,s.sinertia=s.iinertia=s.cinertia=s.inertia=0,s.cbTypes.clear(),n}isStatic(){return this.type===1}isDynamic(){return this.type===2}isKinematic(){return this.type===3}invalidate_type(){this.invalidate_mass(),this.invalidate_inertia()}invalidate_shapes(){this.zip_aabb=!0,this.zip_localCOM=!0,this.zip_worldCOM=!0,this.invalidate_mass(),this.invalidate_inertia()}init_bodysetlist(){if(Be.bodyset==null){let e=Be._zpp;Be.bodyset=new e.util.ZPP_Set_ZPP_Body,Be.bodyset.lt=Be.bodysetlt,Be.bodystack=new e.util.ZNPList_ZPP_Body}}connectedBodies_cont(e){Be.bodyset.try_insert_bool(e.zpp_inner)&&(Be.bodystack.add(e.zpp_inner),e.zpp_inner.graph_depth=Be.cur_graph_depth+1)}connectedBodies(e,t){let n=Be._nape;Be.bodyset==null&&this.init_bodysetlist();let s=t??new n.phys.BodyList;for(Be.bodystack.add(this),Be.bodyset.insert(this),this.graph_depth=0;Be.bodystack.head!=null;){let l=Be.bodystack.pop_unsafe();if(l.graph_depth===e)continue;Be.cur_graph_depth=l.graph_depth;let r=l.constraints.head;for(;r!=null;)r.elt.outer.visitBodies(this.connectedBodies_cont.bind(this)),r=r.next}let i=Be.bodyset;if(i.parent!=null){let l=i.parent;for(;l!=null;)if(l.prev!=null)l=l.prev;else if(l.next!=null)l=l.next;else{let r=l.data;if(r!==this){let p=r.outer;s.zpp_inner.reverse_flag?s.push(p):s.unshift(p)}let a=l.parent;a!=null&&(l===a.prev?a.prev=null:a.next=null,l.parent=null);let o=l;o.data=null,o.lt=null,o.next=Be._zpp.util.ZPP_Set_ZPP_Body.zpp_pool,Be._zpp.util.ZPP_Set_ZPP_Body.zpp_pool=o,l=a}i.parent=null}return s}interactingBodies(e,t){let n=Be._nape,s=Be._zpp;Be.bodyset==null&&this.init_bodysetlist();let i=t??new n.phys.BodyList,l=this.arbiters.head;for(;l!=null;){let a=l.elt;if(!a.sleeping&&(e===4||a.type===e)){let o=a.b1===this?a.b2:a.b1;if(Be.bodyset.try_insert_bool(o)){let p=o.outer;i.zpp_inner.reverse_flag?i.push(p):i.unshift(p)}}l=l.next}let r=Be.bodyset;if(r.parent!=null){let a=r.parent;for(;a!=null;)if(a.prev!=null)a=a.prev;else if(a.next!=null)a=a.next;else{let o=a.parent;o!=null&&(a===o.prev?o.prev=null:o.next=null,a.parent=null);let p=a;p.data=null,p.lt=null,p.next=s.util.ZPP_Set_ZPP_Body.zpp_pool,s.util.ZPP_Set_ZPP_Body.zpp_pool=p,a=o}r.parent=null}return i}atRest(e){let t=Be._nape;if(this.type!==2)return this.component.sleeping;let n=t.Config.linearSleepThreshold*t.Config.linearSleepThreshold,s;if(this.velx*this.velx+this.vely*this.vely>n)s=!1;else{let i=this.posx-this.pre_posx,l=this.posy-this.pre_posy;if(i*i+l*l>.25*n*e*e)s=!1;else{let r=this.aabb.maxx-this.aabb.minx,a=this.aabb.maxy-this.aabb.miny,o=r*r+a*a,p=t.Config.angularSleepThreshold*t.Config.angularSleepThreshold;if(4*this.angvel*this.angvel*o>p)s=!1;else{let c=this.rot-this.pre_rot;s=!(c*c*o>p*e*e)}}}return s||(this.component.waket=this.space.stamp),this.component.waket+t.Config.sleepDelay<this.space.stamp}refreshArbiters(){let e=this.arbiters.head;for(;e!=null;){let t=e.elt;t.invalidated=!0,e=e.next}}sweepIntegrate(e){let t=e-this.sweepTime;if(t!==0&&(this.sweepTime=e,this.posx+=this.velx*t,this.posy+=this.vely*t,this.angvel!==0)){let n=this.sweep_angvel*t;if(this.rot+=n,n*n>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let s=n*n,i=1-.5*s,l=1-s*s/8,r=(i*this.axisx+n*this.axisy)*l;this.axisy=(i*this.axisy-n*this.axisx)*l,this.axisx=r}}}sweepValidate(e){if(e.type===0)e.worldCOMx=this.posx+(this.axisy*e.localCOMx-this.axisx*e.localCOMy),e.worldCOMy=this.posy+(e.localCOMx*this.axisx+e.localCOMy*this.axisy);else{let t=e.polygon,n=t.lverts.next,s=t.gverts.next;for(;s!=null;){let p=s,c=n;n=n.next,p.x=this.posx+(this.axisy*c.x-this.axisx*c.y),p.y=this.posy+(c.x*this.axisx+c.y*this.axisy),s=s.next}let i=t.edges.head,l=t.gverts.next,r=l;for(l=l.next;l!=null;){let p=l,c=i.elt;i=i.next,c.gnormx=this.axisy*c.lnormx-this.axisx*c.lnormy,c.gnormy=c.lnormx*this.axisx+c.lnormy*this.axisy,c.gprojection=this.posx*c.gnormx+this.posy*c.gnormy+c.lprojection,c.tp0=r.y*c.gnormx-r.x*c.gnormy,c.tp1=p.y*c.gnormx-p.x*c.gnormy,r=p,l=l.next}let a=t.gverts.next,o=i.elt;o.gnormx=this.axisy*o.lnormx-this.axisx*o.lnormy,o.gnormy=o.lnormx*this.axisx+o.lnormy*this.axisy,o.gprojection=this.posx*o.gnormx+this.posy*o.gnormy+o.lprojection,o.tp0=r.y*o.gnormx-r.x*o.gnormy,o.tp1=a.y*o.gnormx-a.x*o.gnormy}}invalidate_pos(){let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}pos_invalidate(e){if(this.immutable_midstep("Body::position"),this.type===1&&this.space!=null)throw new Error("Error: Cannot move a static object once inside a Space");this.posx===e.x&&this.posy===e.y||(this.posx=e.x,this.posy=e.y,this.invalidate_pos(),this.wake())}pos_validate(){this.wrap_pos.zpp_inner.x=this.posx,this.wrap_pos.zpp_inner.y=this.posy}vel_invalidate(e){if(this.type===1)throw new Error("Error: Static body cannot have its velocity set.");this.velx=e.x,this.vely=e.y,this.wake()}vel_validate(){this.wrap_vel.zpp_inner.x=this.velx,this.wrap_vel.zpp_inner.y=this.vely}kinvel_invalidate(e){this.kinvelx=e.x,this.kinvely=e.y,this.wake()}kinvel_validate(){this.wrap_kinvel.zpp_inner.x=this.kinvelx,this.wrap_kinvel.zpp_inner.y=this.kinvely}svel_invalidate(e){this.svelx=e.x,this.svely=e.y,this.wake()}svel_validate(){this.wrap_svel.zpp_inner.x=this.svelx,this.wrap_svel.zpp_inner.y=this.svely}force_invalidate(e){if(this.type!==2)throw new Error("Error: Non-dynamic body cannot have force applied.");this.forcex=e.x,this.forcey=e.y,this.wake()}force_validate(){this.wrap_force.zpp_inner.x=this.forcex,this.wrap_force.zpp_inner.y=this.forcey}_setupVec2Wrapper(e,t,n,s){let i=Be._nape;if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;if(_e.poolVec2==null?l=new i.geom.Vec2:(l=_e.poolVec2,_e.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===_e.nextVec2&&(_e.nextVec2=null)),l.zpp_inner==null){let r;le.zpp_pool==null?r=new le:(r=le.zpp_pool,le.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=e,r.y=t,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let a;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x===e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),a=l.zpp_inner.y===t):a=!1,a||(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner._invalidate!=null&&l.zpp_inner._invalidate(l.zpp_inner))}return l.zpp_inner.weak=!1,l}setupPosition(){this.wrap_pos=this._setupVec2Wrapper(this.posx,this.posy,null,null),this.wrap_pos.zpp_inner._inuse=!0,this.world?this.wrap_pos.zpp_inner._immutable=!0:(this.wrap_pos.zpp_inner._invalidate=this.pos_invalidate.bind(this),this.wrap_pos.zpp_inner._validate=this.pos_validate.bind(this))}setupVelocity(){this.wrap_vel=this._setupVec2Wrapper(this.velx,this.vely,null,null),this.wrap_vel.zpp_inner._inuse=!0,this.world?this.wrap_vel.zpp_inner._immutable=!0:(this.wrap_vel.zpp_inner._invalidate=this.vel_invalidate.bind(this),this.wrap_vel.zpp_inner._validate=this.vel_validate.bind(this))}setupkinvel(){this.wrap_kinvel=this._setupVec2Wrapper(this.kinvelx,this.kinvely,null,null),this.wrap_kinvel.zpp_inner._inuse=!0,this.world?this.wrap_kinvel.zpp_inner._immutable=!0:(this.wrap_kinvel.zpp_inner._invalidate=this.kinvel_invalidate.bind(this),this.wrap_kinvel.zpp_inner._validate=this.kinvel_validate.bind(this))}setupsvel(){this.wrap_svel=this._setupVec2Wrapper(this.svelx,this.svely,null,null),this.wrap_svel.zpp_inner._inuse=!0,this.world?this.wrap_svel.zpp_inner._immutable=!0:(this.wrap_svel.zpp_inner._invalidate=this.svel_invalidate.bind(this),this.wrap_svel.zpp_inner._validate=this.svel_validate.bind(this))}setupForce(){this.wrap_force=this._setupVec2Wrapper(this.forcex,this.forcey,null,null),this.wrap_force.zpp_inner._inuse=!0,this.world?this.wrap_force.zpp_inner._immutable=!0:(this.wrap_force.zpp_inner._invalidate=this.force_invalidate.bind(this),this.wrap_force.zpp_inner._validate=this.force_validate.bind(this))}cvel_validate(){this.wrapcvel.zpp_inner.x=this.velx+this.kinvelx,this.wrapcvel.zpp_inner.y=this.vely+this.kinvely}setup_cvel(){this.wrapcvel=this._setupVec2Wrapper(this.velx+this.kinvelx,this.vely+this.kinvely,null,null),this.wrapcvel.zpp_inner._inuse=!0,this.wrapcvel.zpp_inner._immutable=!0,this.wrapcvel.zpp_inner._validate=this.cvel_validate.bind(this)}invalidate_rot(){this.zip_axis=!0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}validate_axis(){this.zip_axis&&(this.zip_axis=!1,this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}quick_validate_axis(){this.zip_axis&&(this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}delta_rot(e){if(e*e>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let t=e*e,n=1-.5*t,s=1-t*t/8,i=(n*this.axisx+e*this.axisy)*s;this.axisy=(n*this.axisy-e*this.axisx)*s,this.axisx=i}this.zip_axis=!1}invalidate_mass(){this.zip_mass=!0,this.invalidate_gravMass()}validate_mass(){if(this.zip_mass||this.massMode===0&&!1){if(this.zip_mass=!1,this.massMode===0){this.cmass=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cmass+=n.area*n.material.density,t=t.next}}this.type===2&&!this.nomove?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0)}}invalidate_gravMass(){this.gravMassMode!==1&&(this.zip_gravMass=!0),this.gravMassMode!==2&&(this.zip_gravMassScale=!0),this.wake()}validate_gravMass(){this.zip_gravMass&&(this.zip_gravMass=!1,this.validate_mass(),this.gravMassMode===0?(this.validate_mass(),this.gravMass=this.cmass):this.gravMassMode===2&&(this.validate_mass(),this.gravMass=this.cmass*this.gravMassScale))}invalidate_gravMassScale(){this.gravMassMode!==2?this.zip_gravMassScale=!0:this.invalidate_gravMass()}validate_gravMassScale(){this.zip_gravMassScale&&(this.zip_gravMassScale=!1,this.gravMassMode===0?this.gravMassScale=1:this.gravMassMode===1&&(this.validate_mass(),this.gravMassScale=this.gravMass/this.cmass))}invalidate_inertia(){this.zip_inertia=!0,this.wake()}validate_inertia(){if(this.zip_inertia||this.inertiaMode===0&&!1){if(this.zip_inertia=!1,this.inertiaMode===0){this.cinertia=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cinertia+=n.inertia*n.area*n.material.density,t=t.next}}this.type===2&&!this.norotate?(this.inertia=this.cinertia,this.sinertia=this.iinertia=1/this.inertia):(this.inertia=1/0,this.sinertia=this.iinertia=0)}}invalidate_wake(){this.wake()}invalidate_aabb(){this.zip_aabb=!0}validate_aabb(){if(this.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(this.zip_aabb){this.zip_aabb=!1,this.aabb.minx=1/0,this.aabb.miny=1/0,this.aabb.maxx=-1/0,this.aabb.maxy=-1/0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.zip_aabb&&t.body!=null&&(t.zip_aabb=!1,t.type===0?this._validateCircleAABB(t.circle):this._validatePolygonAABB(t.polygon)),t.aabb.minx<this.aabb.minx&&(this.aabb.minx=t.aabb.minx),t.aabb.maxx>this.aabb.maxx&&(this.aabb.maxx=t.aabb.maxx),t.aabb.miny<this.aabb.miny&&(this.aabb.miny=t.aabb.miny),t.aabb.maxy>this.aabb.maxy&&(this.aabb.maxy=t.aabb.maxy),e=e.next}}}_validateCircleAABB(e){e.zip_worldCOM&&e.body!=null&&(e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type===1&&this._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)),this.validate_axis(),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy));let t=e.radius;e.aabb.minx=e.worldCOMx-t,e.aabb.miny=e.worldCOMy-t,e.aabb.maxx=e.worldCOMx+t,e.aabb.maxy=e.worldCOMy+t}_validatePolygonAABB(e){if(e.zip_gverts&&e.body!=null){e.zip_gverts=!1,e.validate_lverts(),this.validate_axis();let s=e.lverts.next,i=e.gverts.next;for(;i!=null;){let l=i,r=s;s=s.next,l.x=e.body.posx+(e.body.axisy*r.x-e.body.axisx*r.y),l.y=e.body.posy+(r.x*e.body.axisx+r.y*e.body.axisy),i=i.next}}if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let t=e.gverts.next;e.aabb.minx=t.x,e.aabb.miny=t.y,e.aabb.maxx=t.x,e.aabb.maxy=t.y;let n=e.gverts.next.next;for(;n!=null;){let s=n;s.x<e.aabb.minx&&(e.aabb.minx=s.x),s.x>e.aabb.maxx&&(e.aabb.maxx=s.x),s.y<e.aabb.miny&&(e.aabb.miny=s.y),s.y>e.aabb.maxy&&(e.aabb.maxy=s.y),n=n.next}}aabb_validate(){if(this.shapes.head==null)throw new Error("Error: bounds only makes sense when Body has shapes");this.validate_aabb()}invalidate_localCOM(){this.zip_localCOM=!0,this.zip_worldCOM=!0}invalidate_worldCOM(){this.zip_worldCOM=!0}_computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y,e.localCOMx+=e.lverts.next.next.x,e.localCOMy+=e.lverts.next.next.y,e.localCOMx*=.5,e.localCOMy*=.5;else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let p=n;t+=i.x*(p.y-s.y);let c=p.y*i.x-p.x*i.y;e.localCOMx+=(i.x+p.x)*c,e.localCOMy+=(i.y+p.y)*c,s=i,i=p,n=n.next}n=e.lverts.next;let l=n;t+=i.x*(l.y-s.y);let r=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*r,e.localCOMy+=(i.y+l.y)*r,s=i,i=l,n=n.next;let a=n;t+=i.x*(a.y-s.y);let o=a.y*i.x-a.x*i.y;e.localCOMx+=(i.x+a.x)*o,e.localCOMy+=(i.y+a.y)*o,t=1/(3*t),e.localCOMx*=t,e.localCOMy*=t}}validate_localCOM(){if(this.zip_localCOM){this.zip_localCOM=!1;let e=0,t=0,n=0,s=this.shapes.head;for(;s!=null;){let i=s.elt;i.zip_localCOM&&(i.zip_localCOM=!1,i.type===1&&this._computePolygonLocalCOM(i.polygon),i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)),i.validate_area_inertia();let l=i.area*i.material.density;e+=i.localCOMx*l,t+=i.localCOMy*l,n+=i.area*i.material.density,s=s.next}if(n!==0){let i=1/n;this.localCOMx=e*i,this.localCOMy=t*i}this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy),this.zip_mass&&this.massMode===0&&(this.zip_mass=!1,this.cmass=n,this.type===2?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0))}}validate_worldCOM(){this.zip_worldCOM&&(this.zip_worldCOM=!1,this.validate_localCOM(),this.validate_axis(),this.worldCOMx=this.posx+(this.axisy*this.localCOMx-this.axisx*this.localCOMy),this.worldCOMy=this.posy+(this.localCOMx*this.axisx+this.localCOMy*this.axisy)),this.wrap_worldCOM!=null&&(this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy)}getlocalCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its localCOM");this.validate_localCOM()}getworldCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its worldCOM");this.validate_worldCOM()}__immutable_midstep(){if(this.world)throw new Error("Error: Space::world is immutable")}clear(){if(this.space!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a Space!");if(this.constraints.head!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a constraint!");for(;this.shapes.head!=null;){let t=this.shapes.pop_unsafe();t.removedFromBody(),t.body=null}this.invalidate_shapes(),this.pre_posx=0,this.pre_posy=0,this.posx=0,this.posy=0,this.velx=0,this.vely=0,this.forcex=0,this.forcey=0,this.kinvelx=0,this.kinvely=0,this.svelx=0,this.svely=0,this.angvel=this.torque=this.kinangvel=this.pre_rot=this.rot=0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}for(this.zip_worldCOM=!0,this.zip_axis=!0,e=this.shapes.head;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0,this.axisx=0,this.axisy=1,this.zip_axis=!1,this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.norotate=!1,this.nomove=!1}shapes_adder(e){if(e.zpp_inner.body!==this){if(e.zpp_inner.body!=null&&e.zpp_inner.body.wrap_shapes.remove(e),e.zpp_inner.body=this,e.zpp_inner.addedToBody(),this.space!=null){let t=this.space,n=e.zpp_inner,s=n.body;s.world||(s.component.waket=t.stamp+(t.midstep?0:1),s.type===3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&t.really_wake(s,!1)),t.bphase.insert(n),n.addedToSpace()}return e.zpp_inner.type===1&&(e.zpp_inner.polygon.invalidate_gaxi(),e.zpp_inner.polygon.invalidate_gverts()),!0}else return!1}shapes_subber(e){this.space!=null&&this.space.removed_shape(e.zpp_inner),e.zpp_inner.body=null,e.zpp_inner.removedFromBody()}shapes_invalidate(e){this.invalidate_shapes()}shapes_modifiable(){if(this.immutable_midstep("Body::shapes"),this.type===1&&this.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}addedToSpace(){let e=Be._zpp,t;e.space.ZPP_Component.zpp_pool==null?t=new e.space.ZPP_Component:(t=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t.next,t.next=null),t.isBody=!0,t.body=this,this.component=t,this.__iaddedToSpace()}removedFromSpace(){let e=Be._zpp;for(;this.arbiters.head!=null;){let n=this.arbiters.pop_unsafe(),s=this.space;n.cleared=!0,n.b2===this&&this._removeArbiterFromList(n.b1.arbiters,n,e),n.b1===this&&this._removeArbiterFromList(n.b2.arbiters,n,e),n.pair!=null&&(n.pair.arb=null,n.pair=null),n.active=!1,s.f_arbiters.modified=!0}let t=this.component;t.body=null,t.constraint=null,t.next=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t,this.component=null,this.__iremovedFromSpace()}_removeArbiterFromList(e,t,n){let s=null,i=e.head;for(;i!=null;){if(i.elt===t){let l;s==null?(l=e.head,e.head=l.next,e.head==null&&(e.pushmod=!0)):(l=s.next,s.next=l.next,l.next==null&&(e.pushmod=!0));let r=l;r.elt=null,r.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=r,e.modified=!0,e.length--,e.pushmod=!0;break}s=i,i=i.next}}copy(){let e=Be._nape,t=new e.phys.Body().zpp_inner;t.type=this.type,t.bulletEnabled=this.bulletEnabled,t.disableCCD=this.disableCCD;let n=this.shapes.head;for(;n!=null;){let s=n.elt,i=t.outer.zpp_inner.wrap_shapes,l=s.outer.copy();i.zpp_inner.reverse_flag?i.push(l):i.unshift(l),n=n.next}if(t.posx=this.posx,t.posy=this.posy,t.velx=this.velx,t.vely=this.vely,t.forcex=this.forcex,t.forcey=this.forcey,t.rot=this.rot,t.angvel=this.angvel,t.torque=this.torque,t.kinvelx=this.kinvelx,t.kinvely=this.kinvely,t.kinangvel=this.kinangvel,t.svelx=this.svelx,t.svely=this.svely,!this.zip_axis)t.axisx=this.axisx,t.axisy=this.axisy;else{t.zip_axis=!0;let s=t.shapes.head;for(;s!=null;){let i=s.elt;i.type===1&&(i.polygon.invalidate_gverts(),i.polygon.invalidate_gaxi()),i.invalidate_worldCOM(),s=s.next}t.zip_worldCOM=!0}return t.rot=this.rot,t.massMode=this.massMode,t.gravMassMode=this.gravMassMode,t.inertiaMode=this.inertiaMode,t.norotate=this.norotate,t.nomove=this.nomove,t.cmass=this.cmass,t.cinertia=this.cinertia,this.zip_mass?t.invalidate_mass():t.mass=this.mass,this.zip_gravMass?t.invalidate_gravMass():t.gravMass=this.gravMass,this.zip_gravMassScale?t.invalidate_gravMassScale():t.gravMassScale=this.gravMassScale,this.zip_inertia?t.invalidate_inertia():t.inertia=this.inertia,this.zip_aabb?t.zip_aabb=!0:(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy),this.zip_localCOM?(t.zip_localCOM=!0,t.zip_worldCOM=!0):(t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy),this.zip_worldCOM?t.zip_worldCOM=!0:(t.worldCOMx=this.worldCOMx,t.worldCOMy=this.worldCOMy),this.copyto(t.outer),t.outer}static _init(e,t){if(!Be._initialized){Be._initialized=!0,Be._zpp=e,Be._nape=t;for(let n of Object.getOwnPropertyNames(Jt.prototype))n!=="constructor"&&!(n in Be.prototype)&&(Be.prototype[n]=Jt.prototype[n])}}static _initEnums(e,t){let n=()=>{t.internal=!0;let s=new e.phys.BodyType;return t.internal=!1,s};t.BodyType_STATIC==null&&(t.BodyType_STATIC=n()),t.BodyType_DYNAMIC==null&&(t.BodyType_DYNAMIC=n()),t.BodyType_KINEMATIC==null&&(t.BodyType_KINEMATIC=n()),Be.types=[null,t.BodyType_STATIC,t.BodyType_DYNAMIC,t.BodyType_KINEMATIC]}};Be._nape=null,Be._zpp=null,Be.types=[],Be.bodystack=null,Be.bodyset=null,Be.cur_graph_depth=0,Be._initialized=!1;var vn=Be;var Ht=class Ht{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.bodies=null;this.constraints=null;this.compounds=null;this.wrap_bodies=null;this.wrap_constraints=null;this.wrap_compounds=null;this.depth=0;this.compound=null;this.space=null;let e=Ht._zpp;Jt.initFields(this),this.icompound=this,this.depth=1,this.bodies=new e.util.ZNPList_ZPP_Body,this.wrap_bodies=e.util.ZPP_BodyList.get(this.bodies),this.wrap_bodies.zpp_inner.adder=this.bodies_adder.bind(this),this.wrap_bodies.zpp_inner.subber=this.bodies_subber.bind(this),this.wrap_bodies.zpp_inner._modifiable=this.bodies_modifiable.bind(this),this.constraints=new e.util.ZNPList_ZPP_Constraint,this.wrap_constraints=e.util.ZPP_ConstraintList.get(this.constraints),this.wrap_constraints.zpp_inner.adder=this.constraints_adder.bind(this),this.wrap_constraints.zpp_inner.subber=this.constraints_subber.bind(this),this.wrap_constraints.zpp_inner._modifiable=this.constraints_modifiable.bind(this),this.compounds=new e.util.ZNPList_ZPP_Compound,this.wrap_compounds=e.util.ZPP_CompoundList.get(this.compounds),this.wrap_compounds.zpp_inner.adder=this.compounds_adder.bind(this),this.wrap_compounds.zpp_inner.subber=this.compounds_subber.bind(this),this.wrap_compounds.zpp_inner._modifiable=this.compounds_modifiable.bind(this)}__imutable_midstep(e){if(this.space!=null&&this.space.midstep)throw new Error("Error: "+e+" cannot be set during space step()")}addedToSpace(){this.__iaddedToSpace()}removedFromSpace(){this.__iremovedFromSpace()}breakApart(){for(this.space!=null&&(this.__iremovedFromSpace(),this.space.nullInteractorType(this)),this.compound!=null?this.compound.compounds.remove(this):this.space!=null&&this.space.compounds.remove(this);this.bodies.head!=null;){let e=this.bodies.pop_unsafe();(e.compound=this.compound)!=null?this.compound.bodies.add(e):this.space!=null&&this.space.bodies.add(e),this.space!=null&&this.space.freshInteractorType(e)}for(;this.constraints.head!=null;){let e=this.constraints.pop_unsafe();(e.compound=this.compound)!=null?this.compound.constraints.add(e):this.space!=null&&this.space.constraints.add(e)}for(;this.compounds.head!=null;){let e=this.compounds.pop_unsafe();(e.compound=this.compound)!=null?this.compound.compounds.add(e):this.space!=null&&this.space.compounds.add(e),this.space!=null&&this.space.freshInteractorType(e)}this.compound=null,this.space=null}static _zppOf(e){return e.zpp_inner??e._inner?.zpp_inner??e._inner}bodies_adder(e){let t=Ht._zppOf(e);return t.compound!==this?(t.compound!=null?t.compound.wrap_bodies.remove(e):t.space!=null&&t.space.wrap_bodies.remove(e),t.compound=this,this.space!=null&&this.space.addBody(t),!0):!1}bodies_subber(e){let t=Ht._zppOf(e);t.compound=null,this.space!=null&&this.space.remBody(t)}bodies_modifiable(){this.immutable_midstep("Compound::bodies")}constraints_adder(e){let t=Ht._zppOf(e);return t.compound!==this?(t.compound!=null?t.compound.wrap_constraints.remove(e):t.space!=null&&t.space.wrap_constraints.remove(e),t.compound=this,this.space!=null&&this.space.addConstraint(t),!0):!1}constraints_subber(e){let t=Ht._zppOf(e);t.compound=null,this.space!=null&&this.space.remConstraint(t)}constraints_modifiable(){this.immutable_midstep("Compound::constraints")}compounds_adder(e){let t=Ht._zppOf(e),n=this;for(;n!=null&&n!==t;)n=n.compound;if(n===t)throw new Error("Error: Assignment would cause a cycle in the Compound tree: assigning "+e.toString()+".compound = "+this.outer.toString());return t.compound!==this?(t.compound!=null?t.compound.wrap_compounds.remove(e):t.space!=null&&t.space.wrap_compounds.remove(e),t.compound=this,t.depth=this.depth+1,this.space!=null&&this.space.addCompound(t),!0):!1}compounds_subber(e){let t=Ht._zppOf(e);t.compound=null,t.depth=1,this.space!=null&&this.space.remCompound(t)}compounds_modifiable(){this.immutable_midstep("Compound::compounds")}copy(e,t){let n=Ht._nape,s=Ht._zpp,i=e==null;e==null&&(e=[]),t==null&&(t=[]);let l=new n.phys.Compound,r=this.compounds.head;for(;r!=null;){let c=r.elt.copy(e,t);if(c.zpp_inner.immutable_midstep("Compound::compound"),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_compounds.remove(c),l!=null)){let h=l.zpp_inner.wrap_compounds;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c)}r=r.next}let a=this.bodies.head;for(;a!=null;){let p=a.elt,c=p.outer.copy();if(e.push(s.constraint.ZPP_CopyHelper.dict(p.id,c)),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_bodies.remove(c),l!=null)){let h=l.zpp_inner.wrap_bodies;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c)}a=a.next}let o=this.constraints.head;for(;o!=null;){let c=o.elt.copy(e,t);if((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_constraints.remove(c),l!=null)){let h=l.zpp_inner.wrap_constraints;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c)}o=o.next}if(i)for(;t.length>0;){let p=t.pop();for(let c=0;c<e.length;c++){let h=e[c];if(h.id===p.id){p.cb(h.bc);break}}}return this.copyto(l),l}static _init(){for(let e of Object.getOwnPropertyNames(Jt.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(Ht.prototype,e)&&(Ht.prototype[e]=Jt.prototype[e])}};Ht._nape=null,Ht._zpp=null,Ht._wrapFn=null;var Dn=Ht;var It=class It{constructor(){this.viscosity=1;this.density=1;this.gravityx=0;this.gravityy=0;this.wrap_gravity=null;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new It._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(It._wrapFn)this.outer=It._wrapFn(this);else{this.outer=new It._nape.phys.FluidProperties;let e=this.outer.zpp_inner;e.outer=null,e.next=It.zpp_pool,It.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new It._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return It.zpp_pool==null?e=new It:(e=It.zpp_pool,It.zpp_pool=e.next,e.next=null),e.viscosity=this.viscosity,e.density=this.density,e}gravity_invalidate(e){this.gravityx=e.x,this.gravityy=e.y,this.invalidate()}gravity_validate(){this.wrap_gravity.zpp_inner.x=this.gravityx,this.wrap_gravity.zpp_inner.y=this.gravityy}getgravity(){let e=It._zpp,t=It._nape,n=this.gravityx??0,s=this.gravityy??0;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let r=!1;l._validate!=null&&l._validate(),(l.x!==n||l.y!==s)&&(r=!0),r&&(l.x=n,l.y=s,l._invalidate!=null&&l._invalidate(l))}i.zpp_inner.weak=!1,this.wrap_gravity=i,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=this.gravity_invalidate.bind(this),this.wrap_gravity.zpp_inner._validate=this.gravity_validate.bind(this)}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_fluidprops(),e=e.next}};It.zpp_pool=null,It._nape=null,It._zpp=null,It._wrapFn=null;var gn=It;var Lt=class Lt{constructor(){this.elasticity=0;this.dynamicFriction=1;this.staticFriction=2;this.density=.001;this.rollingFriction=.01;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new Lt._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Lt._wrapFn)this.outer=Lt._wrapFn(this);else{this.outer=new Lt._nape.phys.Material;let e=this.outer.zpp_inner;e.outer=null,e.next=Lt.zpp_pool,Lt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Lt._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e=new Lt;return e.dynamicFriction=this.dynamicFriction,e.staticFriction=this.staticFriction,e.density=this.density,e.elasticity=this.elasticity,e.rollingFriction=this.rollingFriction,e}set(e){this.dynamicFriction=e.dynamicFriction,this.staticFriction=e.staticFriction,this.density=e.density,this.elasticity=e.elasticity,this.rollingFriction=e.rollingFriction}invalidate(e){let t=this.shapes.head;for(;t!=null;)t.elt.invalidate_material(e),t=t.next}};Lt.zpp_pool=null,Lt.WAKE=1,Lt.PROPS=2,Lt.ANGDRAG=4,Lt.ARBITERS=8,Lt._nape=null,Lt._zpp=null,Lt._wrapFn=null;var Ae=Lt;var Cn=class Cn{constructor(e){this.outer=null;this.body=null;this.type=0;this.area=0;this.zip_area_inertia=!1;this.inertia=0;this.angDrag=0;this.zip_angDrag=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;this.sweepRadius=0;this.zip_sweepRadius=!1;this.sweepCoef=0;this.circle=null;this.polygon=null;this.refmaterial=null;this.material=null;this.filter=null;this.fluidProperties=null;this.fluidEnabled=!1;this.sensorEnabled=!1;this.sweep=null;this.node=null;this.pairs=null;this.aabb=null;this.zip_aabb=!1;this.ishape=null;this.userData=null;e!==void 0&&this._initShape(e)}static _initEnums(e,t){let n=()=>{t.internal=!0;let s=new e.shape.ShapeType;return t.internal=!1,s};t.ShapeType_CIRCLE==null&&(t.ShapeType_CIRCLE=n()),t.ShapeType_POLYGON==null&&(t.ShapeType_POLYGON=n()),Cn.types=[t.ShapeType_CIRCLE,t.ShapeType_POLYGON]}_initShape(e){let t=Cn._zpp;Jt.initFields(this),this.pairs=new t.util.ZNPList_ZPP_AABBPair,this.ishape=this,this.type=e;let n;be.zpp_pool==null?n=new be:(n=be.zpp_pool,be.zpp_pool=n.next,n.next=null),n.minx=0,n.miny=0,n.maxx=0,n.maxy=0,this.aabb=n,this.aabb._immutable=!0,this.aabb._validate=this.aabb_validate.bind(this),this.zip_area_inertia=this.zip_angDrag=this.zip_localCOM=this.zip_sweepRadius=!0,this.localCOMx=0,this.localCOMy=0,this.worldCOMx=0,this.worldCOMy=0,this.fluidEnabled=!1,this.sensorEnabled=!1,this.fluidProperties=null,this.body=null,this.refmaterial=new Ae,this.sweepRadius=this.sweepCoef=0}static _init(){if(!Cn._initialized){Cn._initialized=!0;for(let e of Object.getOwnPropertyNames(Jt.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(Cn.prototype,e)&&(Cn.prototype[e]=Jt.prototype[e])}}isCircle(){return this.type===0}isPolygon(){return this.type===1}invalidate_sweepRadius(){this.zip_sweepRadius=!0}validate_sweepRadius(){this.zip_sweepRadius&&(this.zip_sweepRadius=!1,this.type===0?this.circle.__validate_sweepRadius():this.polygon.__validate_sweepRadius())}clear(){this.type===0?this.circle.__clear():this.polygon.__clear()}validate_aabb(){this.zip_aabb&&this.body!=null&&(this.zip_aabb=!1,this.type===0?this.circle.__validate_aabb():this.polygon.__validate_aabb())}force_validate_aabb(){this.type===0?this.circle._force_validate_aabb():this.polygon._force_validate_aabb()}invalidate_aabb(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}validate_area_inertia(){this.zip_area_inertia&&(this.zip_area_inertia=!1,this.type===0?this.circle.__validate_area_inertia():this.polygon.__validate_area_inertia())}validate_angDrag(){(this.zip_angDrag||this.refmaterial.dynamicFriction!==this.material.dynamicFriction)&&(this.zip_angDrag=!1,this.refmaterial.dynamicFriction=this.material.dynamicFriction,this.type===0?this.circle.__validate_angDrag():this.polygon.__validate_angDrag())}validate_localCOM(){this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy))}validate_worldCOM(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.validate_localCOM();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy)}}getworldCOM(){if(this.body==null)throw new Error("Error: worldCOM only makes sense when Shape belongs to a Body");this.validate_worldCOM(),this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy}invalidate_area_inertia(){this.zip_area_inertia=!0,this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia())}invalidate_angDrag(){this.zip_angDrag=!0}invalidate_localCOM(){this.zip_localCOM=!0,this.invalidate_area_inertia(),this.type===0&&(this.zip_sweepRadius=!0),this.invalidate_angDrag(),this.invalidate_worldCOM(),this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0)}invalidate_worldCOM(){this.zip_worldCOM=!0,this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}invalidate_material(e){(e&Ae.WAKE)!==0&&this.wake(),(e&Ae.ARBITERS)!==0&&this.body!=null&&this.body.refreshArbiters(),(e&Ae.PROPS)!==0&&this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia()),(e&Ae.ANGDRAG)!==0&&this.invalidate_angDrag(),this.refmaterial.set(this.material)}invalidate_filter(){this.wake()}invalidate_fluidprops(){this.fluidEnabled&&this.wake()}aabb_validate(){if(this.body==null)throw new Error("Error: bounds only makes sense when Shape belongs to a Body");this.validate_aabb()}setMaterial(e){this.material!==e&&(this.body!=null&&this.body.space!=null&&this.material!=null&&this.material.shapes.remove(this),this.material=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake(),this.body!=null&&this.body.refreshArbiters())}setFilter(e){this.filter!==e&&(this.body!=null&&this.body.space!=null&&this.filter!=null&&this.filter.shapes.remove(this),this.filter=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake())}setFluid(e){this.fluidProperties!==e&&(this.body!=null&&this.body.space!=null&&this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this),this.fluidProperties=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.fluidEnabled&&this.wake())}__immutable_midstep(e){if(this.body!=null&&this.body.space!=null&&this.body.space.midstep)throw new Error("Error: "+e+" cannot be set during a space step()")}addedToBody(){this.invalidate_worldCOM(),this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}removedFromBody(){}addedToSpace(){this.__iaddedToSpace(),this.material.shapes.add(this),this.filter.shapes.add(this),this.fluidProperties!=null&&this.fluidProperties.shapes.add(this)}removedFromSpace(){this.__iremovedFromSpace(),this.material.shapes.remove(this),this.filter.shapes.remove(this),this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this)}copy(){let e=Cn._zpp,t=this.type===0?this.circle.__copy():this.polygon.__copy();this.zip_area_inertia?t.invalidate_area_inertia():(t.area=this.area,t.inertia=this.inertia),this.zip_sweepRadius?t.zip_sweepRadius=!0:(t.sweepRadius=this.sweepRadius,t.sweepCoef=this.sweepCoef),this.zip_angDrag?t.invalidate_angDrag():t.angDrag=this.angDrag,this.zip_aabb?(t.zip_aabb=!0,t.body!=null&&(t.body.zip_aabb=!0)):(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy);let n=t.material;n.outer=null,n.next=Ae.zpp_pool,Ae.zpp_pool=n;let s=t.filter;return s.outer=null,s.next=e.dynamics.ZPP_InteractionFilter.zpp_pool,e.dynamics.ZPP_InteractionFilter.zpp_pool=s,t.material=this.material,t.filter=this.filter,this.fluidProperties!=null&&(t.fluidProperties=this.fluidProperties),t.fluidEnabled=this.fluidEnabled,t.sensorEnabled=this.sensorEnabled,this.userData!=null&&(t.userData=Object.assign({},this.userData)),this.copyto(t.outer),t.outer}};Cn._nape=null,Cn._zpp=null,Cn.types=[],Cn._initialized=!1;var ni=Cn;var Mn=class Mn{constructor(){this.radius=0;this.outer_zn=null;this.radius=0,this.outer_zn=null,this._initShape(0),this.circle=this,this.zip_localCOM=!1}static _init(){if(Mn._initialized)return;Mn._initialized=!0;let t=Mn._zpp.shape.ZPP_Shape.prototype,n=Mn.prototype;for(let s in t)Object.prototype.hasOwnProperty.call(n,s)||(n[s]=t[s]);for(let s of Object.getOwnPropertyNames(t))s!=="constructor"&&!Object.prototype.hasOwnProperty.call(n,s)&&(n[s]=t[s])}__clear(){}invalidate_radius(){this.invalidate_area_inertia(),this.invalidate_angDrag(),this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0),this.body!=null&&this.body.wake()}localCOM_validate(){this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy}localCOM_invalidate(e){this.localCOMx=e.x,this.localCOMy=e.y,this.invalidate_localCOM(),this.body!=null&&this.body.wake()}localCOM_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify localCOM of Circle added to a static Body whilst within a Space")}setupLocalCOM(){let e=Mn._zpp,t=Mn._nape,n=this.localCOMx,s=this.localCOMy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,this.wrap_localCOM=i,this.wrap_localCOM.zpp_inner._inuse=!0,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this),this.wrap_localCOM.zpp_inner._isimmutable=this.localCOM_immutable.bind(this)}__validate_aabb(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy));let n=this.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),this.worldCOMx=n.posx+(n.axisy*this.localCOMx-n.axisx*this.localCOMy),this.worldCOMy=n.posy+(this.localCOMx*n.axisx+this.localCOMy*n.axisy)}let e=this.radius,t=this.radius;this.aabb.minx=this.worldCOMx-e,this.aabb.miny=this.worldCOMy-t,this.aabb.maxx=this.worldCOMx+e,this.aabb.maxy=this.worldCOMy+t}_force_validate_aabb(){let e=this.body;this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy),this.aabb.minx=this.worldCOMx-this.radius,this.aabb.miny=this.worldCOMy-this.radius,this.aabb.maxx=this.worldCOMx+this.radius,this.aabb.maxy=this.worldCOMy+this.radius}__validate_sweepRadius(){this.sweepCoef=Math.sqrt(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy),this.sweepRadius=this.sweepCoef+this.radius}__validate_area_inertia(){let e=this.radius*this.radius;this.area=e*Math.PI,this.inertia=e*.5+(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy)}__validate_angDrag(){let e=Mn._nape,t=this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy,n=this.radius*this.radius,s=this.material.dynamicFriction*e.Config.fluidAngularDragFriction;this.angDrag=(t+2*n)*s+.5*e.Config.fluidAngularDrag*(1+e.Config.fluidVacuumDrag)*t,this.angDrag/=2*(t+.5*n)}__scale(e,t){let n=((e<0?-e:e)+(t<0?-t:t))/2;this.radius*=n<0?-n:n,this.invalidate_radius(),this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0&&(this.localCOMx*=e,this.localCOMy*=t,this.invalidate_localCOM())}__translate(e,t){this.localCOMx+=e,this.localCOMy+=t,this.invalidate_localCOM()}__rotate(e,t){if(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0){let n=t*this.localCOMx-e*this.localCOMy,s=this.localCOMx*e+this.localCOMy*t;this.localCOMx=n,this.localCOMy=s,this.invalidate_localCOM()}}__transform(e){let t=e.zpp_inner.a*e.zpp_inner.d-e.zpp_inner.b*e.zpp_inner.c;t<0&&(t=-t),this.radius*=Math.sqrt(t);let n=e.zpp_inner.a*this.localCOMx+e.zpp_inner.b*this.localCOMy+e.zpp_inner.tx;this.localCOMy=e.zpp_inner.c*this.localCOMx+e.zpp_inner.d*this.localCOMy+e.zpp_inner.ty,this.localCOMx=n,this.invalidate_radius(),this.invalidate_localCOM()}__copy(){let e=Mn._nape,t=new e.shape.Circle(this.radius).zpp_inner_zn;return t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy,t.zip_localCOM=!1,t}};Mn._nape=null,Mn._zpp=null,Mn._initialized=!1;var Wn=Mn;var Qt=class Qt{constructor(){this.next=null;this.polygon=null;this.outer=null;this.lnormx=0;this.lnormy=0;this.wrap_lnorm=null;this.gnormx=0;this.gnormy=0;this.wrap_gnorm=null;this.length=0;this.lprojection=0;this.gprojection=0;this.lp0=null;this.gp0=null;this.lp1=null;this.gp1=null;this.tp0=0;this.tp1=0;this.lnormx=0,this.lnormy=0,this.gnormx=0,this.gnormy=0,this.length=0,this.lprojection=0,this.gprojection=0}free(){this.polygon=null}alloc(){}wrapper(){return this.outer==null&&(Qt._wrapFn?this.outer=Qt._wrapFn(this):(Qt.internal=!0,this.outer=new Qt._nape.shape.Edge,Qt.internal=!1,this.outer.zpp_inner=this)),this.outer}lnorm_validate(){if(this.polygon==null)throw new Error("Error: Edge not currently in use");this.polygon.validate_laxi(),this.wrap_lnorm.zpp_inner.x=this.lnormx,this.wrap_lnorm.zpp_inner.y=this.lnormy}gnorm_validate(){if(this.polygon==null)throw new Error("Error: Edge not currently in use");if(this.polygon.body==null)throw new Error("Error: Edge worldNormal only makes sense if the parent Polygon is contained within a rigid body");this.polygon.validate_gaxi(),this.wrap_gnorm.zpp_inner.x=this.gnormx,this.wrap_gnorm.zpp_inner.y=this.gnormy}getlnorm(){let e=Qt._zpp,t=Qt._nape,n=this.lnormx,s=this.lnormy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,this.wrap_lnorm=i,this.wrap_lnorm.zpp_inner._immutable=!0,this.wrap_lnorm.zpp_inner._validate=this.lnorm_validate.bind(this)}getgnorm(){let e=Qt._zpp,t=Qt._nape,n=this.gnormx,s=this.gnormy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,this.wrap_gnorm=i,this.wrap_gnorm.zpp_inner._immutable=!0,this.wrap_gnorm.zpp_inner._validate=this.gnorm_validate.bind(this)}};Qt.zpp_pool=null,Qt.internal=!1,Qt._nape=null,Qt._zpp=null,Qt._wrapFn=null;var lt=Qt;var yt=class yt{constructor(){this.outer_zn=null;this.lverts=null;this.wrap_lverts=null;this.gverts=null;this.wrap_gverts=null;this.edges=null;this.wrap_edges=null;this.edgeCnt=0;this.reverse_flag=!1;this.zip_lverts=!1;this.zip_laxi=!1;this.zip_gverts=!1;this.zip_gaxi=!1;this.zip_valid=!1;this.zip_sanitation=!1;this.validation=null;this.zip_sanitation=!1,this.zip_valid=!1,this.zip_gaxi=!1,this.zip_gverts=!1,this.zip_laxi=!1,this.zip_lverts=!1,this.reverse_flag=!1,this.edgeCnt=0,this.wrap_edges=null,this.edges=null,this.wrap_gverts=null,this.gverts=null,this.wrap_lverts=null,this.lverts=null,this.outer_zn=null;let e=yt._zpp;this._initShape(1),this.polygon=this,this.lverts=new e.geom.ZPP_Vec2,this.gverts=new e.geom.ZPP_Vec2,this.edges=new e.util.ZNPList_ZPP_Edge,this.edgeCnt=0}static _init(){if(yt._initialized)return;yt._initialized=!0;let t=yt._zpp.shape.ZPP_Shape.prototype,n=yt.prototype;for(let s in t)Object.prototype.hasOwnProperty.call(n,s)||(n[s]=t[s]);for(let s of Object.getOwnPropertyNames(t))s!=="constructor"&&!Object.prototype.hasOwnProperty.call(n,s)&&(n[s]=t[s])}__clear(){}lverts_pa_invalidate(e){this.invalidate_lverts()}lverts_pa_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify local vertex of Polygon added to a static body whilst within a Space")}gverts_pa_validate(){if(this.body==null)throw new Error("Error: World vertex only makes sense when Polygon is contained in a rigid body");this._validateGverts()}lverts_post_adder(e){let t=yt._zpp;e.zpp_inner._invalidate=this.lverts_pa_invalidate.bind(this),e.zpp_inner._isimmutable=this.lverts_pa_immutable.bind(this);let n=null,s=null,i=this.lverts.next;for(;i!=null&&i!==e.zpp_inner;)n=n==null?this.gverts.next:n.next,s=s==null?this.edges.head:s.next,i=i.next;let l;if(t.geom.ZPP_Vec2.zpp_pool==null?l=new t.geom.ZPP_Vec2:(l=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!0,l.x=0,l.y=0,this.gverts.insert(n,l),this.lverts.next.next!=null)if(this.lverts.next.next.next==null){let r;lt.zpp_pool==null?r=new lt:(r=lt.zpp_pool,lt.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.add(r);let a;lt.zpp_pool==null?a=new lt:(a=lt.zpp_pool,lt.zpp_pool=a.next,a.next=null),a.polygon=this,this.edges.add(a),this.edgeCnt+=2}else{let r;lt.zpp_pool==null?r=new lt:(r=lt.zpp_pool,lt.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.insert(s,r),this.edgeCnt++}l._validate=this.gverts_pa_validate.bind(this)}lverts_subber(e){this.cleanup_lvert(e.zpp_inner)}lverts_invalidate(e){this.invalidate_lverts()}lverts_validate(){this.validate_lverts()}lverts_modifiable(){if(this.immutable_midstep("Polygon::localVerts"),this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}gverts_validate(){this._validateGverts()}edges_validate(){this.validate_lverts()}getlverts(){let e=yt._zpp;this.wrap_lverts=e.util.ZPP_MixVec2List.get(this.lverts),this.wrap_lverts.zpp_inner.post_adder=this.lverts_post_adder.bind(this),this.wrap_lverts.zpp_inner.subber=this.lverts_subber.bind(this),this.wrap_lverts.zpp_inner._invalidate=this.lverts_invalidate.bind(this),this.wrap_lverts.zpp_inner._validate=this.lverts_validate.bind(this),this.wrap_lverts.zpp_inner._modifiable=this.lverts_modifiable.bind(this),this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag}getgverts(){let e=yt._zpp;this.wrap_gverts=e.util.ZPP_MixVec2List.get(this.gverts,!0),this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag,this.wrap_gverts.zpp_inner._validate=this.gverts_validate.bind(this)}getedges(){let e=yt._zpp;this.wrap_edges=e.util.ZPP_EdgeList.get(this.edges,!0),this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag,this.wrap_edges.zpp_inner._validate=this.edges_validate.bind(this)}invalidate_lverts(){this.invalidate_laxi(),this.invalidate_area_inertia(),this.invalidate_angDrag(),this.invalidate_localCOM(),this.invalidate_gverts(),this.zip_lverts=!0,this.zip_valid=!0,this.zip_sanitation=!0,this.body!=null&&this.body.wake()}invalidate_laxi(){this.invalidate_gaxi(),this.zip_sweepRadius=!0,this.zip_laxi=!0}invalidate_gverts(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0),this.zip_gverts=!0}invalidate_gaxi(){this.zip_gaxi=!0}validate_lverts(){this.zip_lverts&&(this.zip_lverts=!1,this.lverts.length>2&&(this.validate_area_inertia(),this.area<0&&(this.reverse_vertices(),this.area=-this.area)))}validate_laxi(){if(this.zip_laxi){this.zip_laxi=!1,this.validate_lverts();let t=this.edges.head,n=this.lverts.next,s=n;for(n=n.next;n!=null;){let h=n,u=t.elt;t=t.next,u.lp0=s,u.lp1=h;let x=s.x-h.x,y=s.y-h.y,d=Math.sqrt(x*x+y*y);u.length=d;let _=1/d;x*=_,y*=_;let f=x;x=-y,y=f,u.lprojection=x*s.x+y*s.y,u.lnormx=x,u.lnormy=y,u.wrap_lnorm!=null&&(u.wrap_lnorm.zpp_inner.x=x,u.wrap_lnorm.zpp_inner.y=y),s=h,n=n.next}let i=this.lverts.next,l=t.elt;l.lp0=s,l.lp1=i;let r=s.x-i.x,a=s.y-i.y,o=Math.sqrt(r*r+a*a);l.length=o;let p=1/o;r*=p,a*=p;let c=r;r=-a,a=c,l.lprojection=r*s.x+a*s.y,l.lnormx=r,l.lnormy=a,l.wrap_lnorm!=null&&(l.wrap_lnorm.zpp_inner.x=r,l.wrap_lnorm.zpp_inner.y=a)}}validate_gverts(){this._validateGverts()}validate_gaxi(){if(this.zip_gaxi&&this.body!=null){this.zip_gaxi=!1,this.validate_laxi();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this._validateGverts();let t=this.edges.head,n=this.gverts.next,s=n;for(n=n.next;n!=null;){let r=n,a=t.elt;t=t.next,a.gp0=s,a.gp1=r,a.gnormx=e.axisy*a.lnormx-e.axisx*a.lnormy,a.gnormy=a.lnormx*e.axisx+a.lnormy*e.axisy,a.gprojection=e.posx*a.gnormx+e.posy*a.gnormy+a.lprojection,a.wrap_gnorm!=null&&(a.wrap_gnorm.zpp_inner.x=a.gnormx,a.wrap_gnorm.zpp_inner.y=a.gnormy),a.tp0=a.gp0.y*a.gnormx-a.gp0.x*a.gnormy,a.tp1=a.gp1.y*a.gnormx-a.gp1.x*a.gnormy,s=r,n=n.next}let i=this.gverts.next,l=t.elt;l.gp0=s,l.gp1=i,l.gnormx=e.axisy*l.lnormx-e.axisx*l.lnormy,l.gnormy=l.lnormx*e.axisx+l.lnormy*e.axisy,l.gprojection=e.posx*l.gnormx+e.posy*l.gnormy+l.lprojection,l.wrap_gnorm!=null&&(l.wrap_gnorm.zpp_inner.x=l.gnormx,l.wrap_gnorm.zpp_inner.y=l.gnormy),l.tp0=l.gp0.y*l.gnormx-l.gp0.x*l.gnormy,l.tp1=l.gp1.y*l.gnormx-l.gp1.x*l.gnormy}}_validateGverts(){if(this.zip_gverts&&this.body!=null){this.zip_gverts=!1,this.validate_lverts();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let t=this.lverts.next,n=this.gverts.next;for(;n!=null;){let s=n,i=t;t=t.next,s.x=e.posx+(e.axisy*i.x-e.axisx*i.y),s.y=e.posy+(i.x*e.axisx+i.y*e.axisy),n=n.next}}}cleanup_lvert(e){let t=yt._zpp,n=null,s=null,i=this.lverts.next;for(;i!=null&&i!==e;)n=n==null?this.gverts.next:n.next,s=s==null?this.edges.head:s.next,i=i.next;let l=n==null?this.gverts.next:n.next;this.gverts.erase(n);let r=l;if(r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=r,this.edgeCnt===2){let a=this.edges.pop_unsafe();a.polygon=null,a.next=lt.zpp_pool,lt.zpp_pool=a,a=this.edges.pop_unsafe(),a.polygon=null,a.next=lt.zpp_pool,lt.zpp_pool=a,this.edgeCnt=0}else if(this.edgeCnt!==0){let a=s==null?this.edges.head.elt:s.next.elt;this.edges.erase(s),a.polygon=null,a.next=lt.zpp_pool,lt.zpp_pool=a,this.edgeCnt--}}splice_collinear(){this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real())}splice_collinear_real(){let e=yt._nape;if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)return;let t=null,n=this.lverts.next;for(;n!=null;){let i=n.next==null?this.lverts.next:n.next,l=n.x-i.x,r=n.y-i.y;l*l+r*r<e.Config.epsilon*e.Config.epsilon?(this.cleanup_lvert(n),n=this.lverts.erase(t)):(t=n,n=n.next)}if(this.lverts.next==null)return;let s;for(;;){s=!1;let i=this.lverts.next;for(;i!=null;){let l=i.next==null?this.lverts.next:i.next,r=l.next==null?this.lverts.next:l.next,a=l.x-i.x,o=l.y-i.y,p=r.x-l.x,h=(r.y-l.y)*a-p*o;h*h>=e.Config.epsilon*e.Config.epsilon||(this.cleanup_lvert(l),this.lverts.erase(i.next==null?null:i),s=!0),i=i.next}if(!s)break}}reverse_vertices(){this.lverts.reverse(),this.gverts.reverse(),this.edges.reverse();let e=this.edges.iterator_at(this.edgeCnt-1),t=this.edges.pop_unsafe();this.edges.insert(e,t),this.reverse_flag=!this.reverse_flag,this.wrap_lverts!=null&&(this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_gverts!=null&&(this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_edges!=null&&(this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag)}valid(){let e=yt._nape,t=yt._zpp;if(this.zip_valid){if(this.zip_valid=!1,this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real()),this.lverts.length<3)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;if(this.validate_lverts(),this.validate_area_inertia(),this.area<e.Config.epsilon)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;{let n=!1,s=!1,i=!0,l=this.lverts.next,r=l;l=l.next;let a=l;for(l=l.next;l!=null;){let o=l,p=o.x-a.x,c=o.y-a.y,h=a.x-r.x,x=(a.y-r.y)*p-h*c;if(x>e.Config.epsilon?s=!0:x<-e.Config.epsilon&&(n=!0),s&&n){i=!1;break}r=a,a=o,l=l.next}if(i){l=this.lverts.next;let o=l,p=o.x-a.x,c=o.y-a.y,h=a.x-r.x,x=(a.y-r.y)*p-h*c;if(x>e.Config.epsilon?s=!0:x<-e.Config.epsilon&&(n=!0),!(s&&n)){r=a,a=o,l=l.next;let y=l,d=y.x-a.x,_=y.y-a.y,f=a.x-r.x,P=(a.y-r.y)*d-f*_;P>e.Config.epsilon?s=!0:P<-e.Config.epsilon&&(n=!0)}}if(s&&n)return t.util.ZPP_Flags.ValidationResult_CONCAVE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_CONCAVE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_CONCAVE;{let o=!0,p=this.lverts.next,c=p;for(p=p.next;p!=null&&o;){let h=p,u=this.lverts.next,x=u.next;for(;x!=null&&o;){let y=x;c!==u&&c!==y&&h!==u&&h!==y&&(o=this._checkNoIntersection(c,h,u,y,e)),u=y,x=x.next}if(o){let y=this.lverts.next;c!==u&&c!==y&&h!==u&&h!==y&&(o=this._checkNoIntersection(c,h,u,y,e))}c=h,p=p.next}if(o){let h=this.lverts.next,u=this.lverts.next,x=u.next;for(;x!=null&&o;){let y=x;c!==u&&c!==y&&h!==u&&h!==y&&(o=this._checkNoIntersection(c,h,u,y,e)),u=y,x=x.next}if(o){let y=this.lverts.next;c!==u&&c!==y&&h!==u&&h!==y&&(o=this._checkNoIntersection(c,h,u,y,e))}}return o?(t.util.ZPP_Flags.ValidationResult_VALID==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_VALID=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_VALID):(t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING)}}}else return this.validation}_checkNoIntersection(e,t,n,s,i){let l=e.x-n.x,r=e.y-n.y,a=t.x-e.x,o=t.y-e.y,p=s.x-n.x,c=s.y-n.y,h=o*p-a*c;if(h*h>i.Config.epsilon){h=1/h;let u=(c*l-p*r)*h;if(u>i.Config.epsilon&&u<1-i.Config.epsilon){let x=(o*l-a*r)*h;if(x>i.Config.epsilon&&x<1-i.Config.epsilon)return!1}}return!0}__validate_aabb(){if(this._validateGverts(),this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let e=this.gverts.next;this.aabb.minx=e.x,this.aabb.miny=e.y,this.aabb.maxx=e.x,this.aabb.maxy=e.y;let t=this.gverts.next.next;for(;t!=null;){let n=t;n.x<this.aabb.minx&&(this.aabb.minx=n.x),n.x>this.aabb.maxx&&(this.aabb.maxx=n.x),n.y<this.aabb.miny&&(this.aabb.miny=n.y),n.y>this.aabb.maxy&&(this.aabb.maxy=n.y),t=t.next}}_force_validate_aabb(){let e=this.body,t=this.lverts.next,n=this.gverts.next,s=t;t=t.next,n.x=e.posx+(e.axisy*s.x-e.axisx*s.y),n.y=e.posy+(s.x*e.axisx+s.y*e.axisy),this.aabb.minx=n.x,this.aabb.miny=n.y,this.aabb.maxx=n.x,this.aabb.maxy=n.y;let i=this.gverts.next.next;for(;i!=null;){let l=i,r=t;t=t.next,l.x=e.posx+(e.axisy*r.x-e.axisx*r.y),l.y=e.posy+(r.x*e.axisx+r.y*e.axisy),l.x<this.aabb.minx&&(this.aabb.minx=l.x),l.x>this.aabb.maxx&&(this.aabb.maxx=l.x),l.y<this.aabb.miny&&(this.aabb.miny=l.y),l.y>this.aabb.maxy&&(this.aabb.maxy=l.y),i=i.next}}__validate_sweepRadius(){let e=0,t=0;this.validate_laxi();let n=this.lverts.next;for(;n!=null;){let i=n,l=i.x*i.x+i.y*i.y;l>e&&(e=l),n=n.next}let s=this.edges.head;for(;s!=null;){let i=s.elt;if(i.lprojection<t&&(t=i.lprojection,t<0))break;s=s.next}t<0&&(t=0),this.sweepRadius=Math.sqrt(e),this.sweepCoef=this.sweepRadius-t}__validate_area_inertia(){if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)this.area=0,this.inertia=0;else{this.area=0;let e=0,t=0,n=this.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let p=n,c=i.y*s.x-i.x*s.y,h=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y);e+=c*h,t+=c,this.area+=i.x*(p.y-s.y),s=i,i=p,n=n.next}n=this.lverts.next;let l=n,r=i.y*s.x-i.x*s.y,a=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y);e+=r*a,t+=r,this.area+=i.x*(l.y-s.y),s=i,i=l,n=n.next;let o=n;r=i.y*s.x-i.x*s.y,a=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y),e+=r*a,t+=r,this.area+=i.x*(o.y-s.y),this.inertia=e/(6*t),this.area*=.5,this.area<0&&(this.area=-this.area,this.reverse_vertices())}}__validate_angDrag(){let e=yt._nape;if(this.lverts.length<3)throw new Error("Error: Polygon's with less than 3 vertices have no meaningful angDrag");this.validate_area_inertia(),this.validate_laxi();let t=0,n=this.edges.head,s=0,i=this.lverts.next,l=i,r=i.next;for(;r!=null;){let a=r,o=n.elt;n=n.next,s+=o.length;let p=a.x-l.x,c=a.y-l.y;t+=o.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*o.lprojection*o.lprojection;let h=-(l.y*o.lnormx-l.x*o.lnormy)/(c*o.lnormx-p*o.lnormy);if(h>0){let u=h>1?1:h,x=l.x,y=l.y;x+=p*u,y+=c*u;let d=o.lnormy*l.x-o.lnormx*l.y,_=o.lnormy*x-o.lnormx*y,f=(_*_*_-d*d*d)/(3*(_-d));t+=f*u*o.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,x=l.x,y=l.y;x+=p*u,y+=c*u;let d=o.lnormy*x-o.lnormx*y,_=o.lnormy*a.x-o.lnormx*a.y,f=(_*_*_-d*d*d)/(3*(_-d));t+=f*e.Config.fluidVacuumDrag*(1-u)*o.length*e.Config.fluidAngularDrag}l=a,r=r.next}{let a=this.lverts.next,o=n.elt;s+=o.length;let p=a.x-l.x,c=a.y-l.y;t+=o.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*o.lprojection*o.lprojection;let h=-(l.y*o.lnormx-l.x*o.lnormy)/(c*o.lnormx-p*o.lnormy);if(h>0){let u=h>1?1:h,x=l.x,y=l.y;x+=p*u,y+=c*u;let d=o.lnormy*l.x-o.lnormx*l.y,_=o.lnormy*x-o.lnormx*y,f=(_*_*_-d*d*d)/(3*(_-d));t+=f*u*o.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,x=l.x,y=l.y;x+=p*u,y+=c*u;let d=o.lnormy*x-o.lnormx*y,_=o.lnormy*a.x-o.lnormx*a.y,f=(_*_*_-d*d*d)/(3*(_-d));t+=f*e.Config.fluidVacuumDrag*(1-u)*o.length*e.Config.fluidAngularDrag}}this.angDrag=t/(this.inertia*s)}__validate_localCOM(){if(this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(this.lverts.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y;else if(this.lverts.next.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y,this.localCOMx+=this.lverts.next.next.x,this.localCOMy+=this.lverts.next.next.y,this.localCOMx*=.5,this.localCOMy*=.5;else{this.localCOMx=0,this.localCOMy=0;let e=0,t=this.lverts.next,n=t;t=t.next;let s=t;for(t=t.next;t!=null;){let a=t;e+=s.x*(a.y-n.y);let o=a.y*s.x-a.x*s.y;this.localCOMx+=(s.x+a.x)*o,this.localCOMy+=(s.y+a.y)*o,n=s,s=a,t=t.next}t=this.lverts.next;let i=t;e+=s.x*(i.y-n.y);let l=i.y*s.x-i.x*s.y;this.localCOMx+=(s.x+i.x)*l,this.localCOMy+=(s.y+i.y)*l,n=s,s=i,t=t.next;let r=t;e+=s.x*(r.y-n.y),l=r.y*s.x-r.x*s.y,this.localCOMx+=(s.x+r.x)*l,this.localCOMy+=(s.y+r.y)*l,e=1/(3*e),this.localCOMx*=e,this.localCOMy*=e}}localCOM_validate(){if(this.lverts.next==null)throw new Error("Error: An empty polygon does not have any meaningful localCOM");this.validate_localCOM()}localCOM_invalidate(e){this.validate_localCOM();let t=e.x-this.localCOMx,n=e.y-this.localCOMy,s=this.lverts.next;for(;s!=null;)s.x+=t,s.y+=n,s=s.next;this.invalidate_lverts()}setupLocalCOM(){let e=yt._zpp,t=yt._nape,n=this.localCOMx,s=this.localCOMy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,this.wrap_localCOM=i,this.wrap_localCOM.zpp_inner._inuse=!0,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this)}__translate(e,t){let n=this.lverts.next;for(;n!=null;)n.x+=e,n.y+=t,n=n.next;this.invalidate_lverts()}__scale(e,t){let n=this.lverts.next;for(;n!=null;)n.x*=e,n.y*=t,n=n.next;this.invalidate_lverts()}__rotate(e,t){let n=this.lverts.next;for(;n!=null;){let s=t*n.x-e*n.y,i=n.x*e+n.y*t;n.x=s,n.y=i,n=n.next}this.invalidate_lverts()}__transform(e){let t=this.lverts.next;for(;t!=null;){let n=e.zpp_inner.a*t.x+e.zpp_inner.b*t.y+e.zpp_inner.tx;t.y=e.zpp_inner.c*t.x+e.zpp_inner.d*t.y+e.zpp_inner.ty,t.x=n,t=t.next}this.invalidate_lverts()}__copy(){let e=yt._nape;this.outer_zn.zpp_inner_zn.wrap_lverts==null&&this.outer_zn.zpp_inner_zn.getlverts();let t=this.outer_zn.zpp_inner_zn.wrap_lverts,n=[],s=t.iterator();for(;s.hasNext();)n.push(s.next());return new e.shape.Polygon(n).zpp_inner_zn}};yt._nape=null,yt._zpp=null,yt._initialized=!1;var Kn=yt;var bi=class bi{constructor(){this.space=null;this.is_sweep=!1;this.sweep=null;this.dynab=null;this.aabbShape=null;this.matrix=null;this.circShape=null}static _initFields(e){e.space=null,e.is_sweep=!1,e.sweep=null,e.dynab=null,e.aabbShape=null,e.matrix=null,e.circShape=null}insert(e){this.is_sweep?this.sweep.__insert(e):this.dynab.__insert(e)}remove(e){this.is_sweep?this.sweep.__remove(e):this.dynab.__remove(e)}sync(e){if(this.is_sweep){if(!this.sweep.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let r=1;l.localCOMx+=l.lverts.next.next.x*r,l.localCOMy+=l.lverts.next.next.y*r;let a=.5;l.localCOMx*=a,l.localCOMy*=a}else{l.localCOMx=0,l.localCOMy=0;let r=0,a=l.lverts.next,o=a;a=a.next;let p=a;for(a=a.next;a!=null;){let d=a;r+=p.x*(d.y-o.y);let _=d.y*p.x-d.x*p.y;l.localCOMx+=(p.x+d.x)*_,l.localCOMy+=(p.y+d.y)*_,o=p,p=d,a=a.next}a=l.lverts.next;let c=a;r+=p.x*(c.y-o.y);let h=c.y*p.x-c.x*p.y;l.localCOMx+=(p.x+c.x)*h,l.localCOMy+=(p.y+c.y)*h,o=p,p=c,a=a.next;let u=a;r+=p.x*(u.y-o.y);let x=u.y*p.x-u.x*p.y;l.localCOMx+=(p.x+u.x)*x,l.localCOMy+=(p.y+u.y)*x,r=1/(3*r);let y=r;l.localCOMx*=y,l.localCOMy*=y}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,s=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-s,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+s}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,r=t.gverts.next;for(;r!=null;){let a=r,o=l;l=l.next,a.x=t.body.posx+(t.body.axisy*o.x-t.body.axisx*o.y),a.y=t.body.posy+(o.x*t.body.axisx+o.y*t.body.axisy),r=r.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next}}}else{let t=this.dynab,n=e.node;if(!n.synced){if(!t.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let i=e.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=!1,i.zip_localCOM){if(i.zip_localCOM=!1,i.type==1){let o=i.polygon;if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(o.lverts.next.next==null)o.localCOMx=o.lverts.next.x,o.localCOMy=o.lverts.next.y;else if(o.lverts.next.next.next==null){o.localCOMx=o.lverts.next.x,o.localCOMy=o.lverts.next.y;let p=1;o.localCOMx+=o.lverts.next.next.x*p,o.localCOMy+=o.lverts.next.next.y*p;let c=.5;o.localCOMx*=c,o.localCOMy*=c}else{o.localCOMx=0,o.localCOMy=0;let p=0,c=o.lverts.next,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let z=c;p+=u.x*(z.y-h.y);let P=z.y*u.x-z.x*u.y;o.localCOMx+=(u.x+z.x)*P,o.localCOMy+=(u.y+z.y)*P,h=u,u=z,c=c.next}c=o.lverts.next;let x=c;p+=u.x*(x.y-h.y);let y=x.y*u.x-x.x*u.y;o.localCOMx+=(u.x+x.x)*y,o.localCOMy+=(u.y+x.y)*y,h=u,u=x,c=c.next;let d=c;p+=u.x*(d.y-h.y);let _=d.y*u.x-d.x*u.y;o.localCOMx+=(u.x+d.x)*_,o.localCOMy+=(u.y+d.y)*_,p=1/(3*p);let f=p;o.localCOMx*=f,o.localCOMy*=f}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let l=i.radius,r=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-r,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+r}else{let i=e.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let o=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=o;o=o.next,c.x=i.body.posx+(i.body.axisy*h.x-i.body.axisx*h.y),c.y=i.body.posy+(h.x*i.body.axisx+h.y*i.body.axisy),p=p.next}}if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let l=i.gverts.next;i.aabb.minx=l.x,i.aabb.miny=l.y,i.aabb.maxx=l.x,i.aabb.maxy=l.y;let r=i.gverts.next.next;for(;r!=null;){let a=r;a.x<i.aabb.minx&&(i.aabb.minx=a.x),a.x>i.aabb.maxx&&(i.aabb.maxx=a.x),a.y<i.aabb.miny&&(i.aabb.miny=a.y),a.y>i.aabb.maxy&&(i.aabb.maxy=a.y),r=r.next}}let s;if(n.dyn==(e.body.type==1?!1:!e.body.component.sleeping)){let i=n.aabb,l=e.aabb;s=!(l.minx>=i.minx&&l.miny>=i.miny&&l.maxx<=i.maxx&&l.maxy<=i.maxy)}else s=!0;s&&(n.synced=!0,n.snext=t.syncs,t.syncs=n)}}}broadphase(e,t){}clear(){}shapesUnderPoint(e,t,n,s){return null}bodiesUnderPoint(e,t,n,s){return null}updateAABBShape(e){let t=bi._zpp,n=bi._nape;if(this.aabbShape==null){t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new n.phys.BodyType,t.util.ZPP_Flags.internal=!1);let r=new n.phys.Body(t.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,a=this.aabbShape=new n.shape.Polygon(n.shape.Polygon.rect(e.minx,e.miny,e.maxx-e.minx,e.maxy-e.miny));r.zpp_inner.reverse_flag?r.push(a):r.unshift(a)}else{let l=this.aabbShape.zpp_inner.aabb,r=(e.maxx-e.minx)/(l.maxx-l.minx),a=(e.maxy-e.miny)/(l.maxy-l.miny);this.matrix==null&&(this.matrix=new n.geom.Mat23);let o=this.matrix;if(r!==r)throw new Error("Error: Mat23::a cannot be NaN");o.zpp_inner.a=r;let p=o.zpp_inner;p._invalidate!=null&&p._invalidate();let c=this.matrix,h=this.matrix;h.zpp_inner.c=0;let u=h.zpp_inner;u._invalidate!=null&&u._invalidate();let x=h.zpp_inner.c;if(x!==x)throw new Error("Error: Mat23::b cannot be NaN");c.zpp_inner.b=x;let y=c.zpp_inner;y._invalidate!=null&&y._invalidate();let d=this.matrix;if(a!==a)throw new Error("Error: Mat23::d cannot be NaN");d.zpp_inner.d=a;let _=d.zpp_inner;_._invalidate!=null&&_._invalidate();let f=this.matrix,z=e.minx-r*l.minx;if(z!==z)throw new Error("Error: Mat23::tx cannot be NaN");f.zpp_inner.tx=z;let P=f.zpp_inner;P._invalidate!=null&&P._invalidate();let k=this.matrix,m=e.miny-a*l.miny;if(m!==m)throw new Error("Error: Mat23::ty cannot be NaN");k.zpp_inner.ty=m;let b=k.zpp_inner;b._invalidate!=null&&b._invalidate(),this.aabbShape.transform(this.matrix)}let s=this.aabbShape.zpp_inner;if(s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let l=s.circle;if(l.zip_worldCOM&&l.body!=null){if(l.zip_worldCOM=!1,l.zip_localCOM){if(l.zip_localCOM=!1,l.type==1){let p=l.polygon;if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(p.lverts.next.next==null)p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;else if(p.lverts.next.next.next==null){p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;let c=1;p.localCOMx+=p.lverts.next.next.x*c,p.localCOMy+=p.lverts.next.next.y*c;let h=.5;p.localCOMx*=h,p.localCOMy*=h}else{p.localCOMx=0,p.localCOMy=0;let c=0,h=p.lverts.next,u=h;h=h.next;let x=h;for(h=h.next;h!=null;){let P=h;c+=x.x*(P.y-u.y);let k=P.y*x.x-P.x*x.y;p.localCOMx+=(x.x+P.x)*k,p.localCOMy+=(x.y+P.y)*k,u=x,x=P,h=h.next}h=p.lverts.next;let y=h;c+=x.x*(y.y-u.y);let d=y.y*x.x-y.x*x.y;p.localCOMx+=(x.x+y.x)*d,p.localCOMy+=(x.y+y.y)*d,u=x,x=y,h=h.next;let _=h;c+=x.x*(_.y-u.y);let f=_.y*x.x-_.x*x.y;p.localCOMx+=(x.x+_.x)*f,p.localCOMy+=(x.y+_.y)*f,c=1/(3*c);let z=c;p.localCOMx*=z,p.localCOMy*=z}}l.wrap_localCOM!=null&&(l.wrap_localCOM.zpp_inner.x=l.localCOMx,l.wrap_localCOM.zpp_inner.y=l.localCOMy)}let o=l.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),l.worldCOMx=l.body.posx+(l.body.axisy*l.localCOMx-l.body.axisx*l.localCOMy),l.worldCOMy=l.body.posy+(l.localCOMx*l.body.axisx+l.localCOMy*l.body.axisy)}let r=l.radius,a=l.radius;l.aabb.minx=l.worldCOMx-r,l.aabb.miny=l.worldCOMy-a,l.aabb.maxx=l.worldCOMx+r,l.aabb.maxy=l.worldCOMy+a}else{let l=s.polygon;if(l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let o=l.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot));let p=l.lverts.next,c=l.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=l.body.posx+(l.body.axisy*u.x-l.body.axisx*u.y),h.y=l.body.posy+(u.x*l.body.axisx+u.y*l.body.axisy),c=c.next}}if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=l.gverts.next;l.aabb.minx=r.x,l.aabb.miny=r.y,l.aabb.maxx=r.x,l.aabb.maxy=r.y;let a=l.gverts.next.next;for(;a!=null;){let o=a;o.x<l.aabb.minx&&(l.aabb.minx=o.x),o.x>l.aabb.maxx&&(l.aabb.maxx=o.x),o.y<l.aabb.miny&&(l.aabb.miny=o.y),o.y>l.aabb.maxy&&(l.aabb.maxy=o.y),a=a.next}}let i=this.aabbShape.zpp_inner.polygon;if(i.zip_gaxi&&i.body!=null){i.zip_gaxi=!1,i.validate_laxi();let l=i.body;if(l.zip_axis&&(l.zip_axis=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot)),i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let h=i.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot));let u=i.lverts.next,x=i.gverts.next;for(;x!=null;){let y=x,d=u;u=u.next,y.x=i.body.posx+(i.body.axisy*d.x-i.body.axisx*d.y),y.y=i.body.posy+(d.x*i.body.axisx+d.y*i.body.axisy),x=x.next}}let r=i.edges.head,a=i.gverts.next,o=a;for(a=a.next;a!=null;){let h=a,u=r.elt;r=r.next,u.gp0=o,u.gp1=h,u.gnormx=i.body.axisy*u.lnormx-i.body.axisx*u.lnormy,u.gnormy=u.lnormx*i.body.axisx+u.lnormy*i.body.axisy,u.gprojection=i.body.posx*u.gnormx+i.body.posy*u.gnormy+u.lprojection,u.wrap_gnorm!=null&&(u.wrap_gnorm.zpp_inner.x=u.gnormx,u.wrap_gnorm.zpp_inner.y=u.gnormy),u.tp0=u.gp0.y*u.gnormx-u.gp0.x*u.gnormy,u.tp1=u.gp1.y*u.gnormx-u.gp1.x*u.gnormy,o=h,a=a.next}let p=i.gverts.next,c=r.elt;r=r.next,c.gp0=o,c.gp1=p,c.gnormx=i.body.axisy*c.lnormx-i.body.axisx*c.lnormy,c.gnormy=c.lnormx*i.body.axisx+c.lnormy*i.body.axisy,c.gprojection=i.body.posx*c.gnormx+i.body.posy*c.gnormy+c.lprojection,c.wrap_gnorm!=null&&(c.wrap_gnorm.zpp_inner.x=c.gnormx,c.wrap_gnorm.zpp_inner.y=c.gnormy),c.tp0=c.gp0.y*c.gnormx-c.gp0.x*c.gnormy,c.tp1=c.gp1.y*c.gnormx-c.gp1.x*c.gnormy}}shapesInAABB(e,t,n,s,i){return null}bodiesInAABB(e,t,n,s,i){return null}updateCircShape(e,t,n){let s=bi._zpp,i=bi._nape;if(this.circShape==null){s.util.ZPP_Flags.BodyType_STATIC==null&&(s.util.ZPP_Flags.internal=!0,s.util.ZPP_Flags.BodyType_STATIC=new i.phys.BodyType,s.util.ZPP_Flags.internal=!1);let a=new i.phys.Body(s.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,o=e,p=t;if(p==null&&(p=0),o==null&&(o=0),o!==o||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let c;if(s.util.ZPP_PubPool.poolVec2==null?c=new i.geom.Vec2:(c=s.util.ZPP_PubPool.poolVec2,s.util.ZPP_PubPool.poolVec2=c.zpp_pool,c.zpp_pool=null,c.zpp_disp=!1,c==s.util.ZPP_PubPool.nextVec2&&(s.util.ZPP_PubPool.nextVec2=null)),c.zpp_inner==null){let u;s.geom.ZPP_Vec2.zpp_pool==null?u=new s.geom.ZPP_Vec2:(u=s.geom.ZPP_Vec2.zpp_pool,s.geom.ZPP_Vec2.zpp_pool=u.next,u.next=null),u.weak=!1,u._immutable=!1,u.x=o,u.y=p,c.zpp_inner=u,c.zpp_inner.outer=c}else{if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=c.zpp_inner;if(u._immutable)throw new Error("Error: Vec2 is immutable");if(u._isimmutable!=null&&u._isimmutable(),o!==o||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let x;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let y=c.zpp_inner;if(y._validate!=null&&y._validate(),c.zpp_inner.x==o){if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let d=c.zpp_inner;d._validate!=null&&d._validate(),x=c.zpp_inner.y==p}else x=!1;if(!x){c.zpp_inner.x=o,c.zpp_inner.y=p;let d=c.zpp_inner;d._invalidate!=null&&d._invalidate(d)}}c.zpp_inner.weak=!1;let h=this.circShape=new i.shape.Circle(n,c);a.zpp_inner.reverse_flag?a.push(h):a.unshift(h)}else{let r=this.circShape.zpp_inner.circle,a=n/r.radius;this.matrix==null&&(this.matrix=new i.geom.Mat23);let o=this.matrix,p=this.matrix;if(a!==a)throw new Error("Error: Mat23::d cannot be NaN");p.zpp_inner.d=a;let c=p.zpp_inner;c._invalidate!=null&&c._invalidate();let h=p.zpp_inner.d;if(h!==h)throw new Error("Error: Mat23::a cannot be NaN");o.zpp_inner.a=h;let u=o.zpp_inner;u._invalidate!=null&&u._invalidate();let x=this.matrix,y=this.matrix;y.zpp_inner.c=0;let d=y.zpp_inner;d._invalidate!=null&&d._invalidate();let _=y.zpp_inner.c;if(_!==_)throw new Error("Error: Mat23::b cannot be NaN");x.zpp_inner.b=_;let f=x.zpp_inner;f._invalidate!=null&&f._invalidate();let z=this.matrix,P=e-a*r.localCOMx;if(P!==P)throw new Error("Error: Mat23::tx cannot be NaN");z.zpp_inner.tx=P;let k=z.zpp_inner;k._invalidate!=null&&k._invalidate();let m=this.matrix,b=t-a*r.localCOMy;if(b!==b)throw new Error("Error: Mat23::ty cannot be NaN");m.zpp_inner.ty=b;let C=m.zpp_inner;C._invalidate!=null&&C._invalidate(),this.circShape.transform(this.matrix)}let l=this.circShape.zpp_inner;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let r=l.circle;if(r.zip_worldCOM&&r.body!=null){if(r.zip_worldCOM=!1,r.zip_localCOM){if(r.zip_localCOM=!1,r.type==1){let c=r.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let h=1;c.localCOMx+=c.lverts.next.next.x*h,c.localCOMy+=c.lverts.next.next.y*h;let u=.5;c.localCOMx*=u,c.localCOMy*=u}else{c.localCOMx=0,c.localCOMy=0;let h=0,u=c.lverts.next,x=u;u=u.next;let y=u;for(u=u.next;u!=null;){let k=u;h+=y.x*(k.y-x.y);let m=k.y*y.x-k.x*y.y;c.localCOMx+=(y.x+k.x)*m,c.localCOMy+=(y.y+k.y)*m,x=y,y=k,u=u.next}u=c.lverts.next;let d=u;h+=y.x*(d.y-x.y);let _=d.y*y.x-d.x*y.y;c.localCOMx+=(y.x+d.x)*_,c.localCOMy+=(y.y+d.y)*_,x=y,y=d,u=u.next;let f=u;h+=y.x*(f.y-x.y);let z=f.y*y.x-f.x*y.y;c.localCOMx+=(y.x+f.x)*z,c.localCOMy+=(y.y+f.y)*z,h=1/(3*h);let P=h;c.localCOMx*=P,c.localCOMy*=P}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let p=r.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),r.worldCOMx=r.body.posx+(r.body.axisy*r.localCOMx-r.body.axisx*r.localCOMy),r.worldCOMy=r.body.posy+(r.localCOMx*r.body.axisx+r.localCOMy*r.body.axisy)}let a=r.radius,o=r.radius;r.aabb.minx=r.worldCOMx-a,r.aabb.miny=r.worldCOMy-o,r.aabb.maxx=r.worldCOMx+a,r.aabb.maxy=r.worldCOMy+o}else{let r=l.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let p=r.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=r.lverts.next,h=r.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=r.body.posx+(r.body.axisy*x.x-r.body.axisx*x.y),u.y=r.body.posy+(x.x*r.body.axisx+x.y*r.body.axisy),h=h.next}}if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let a=r.gverts.next;r.aabb.minx=a.x,r.aabb.miny=a.y,r.aabb.maxx=a.x,r.aabb.maxy=a.y;let o=r.gverts.next.next;for(;o!=null;){let p=o;p.x<r.aabb.minx&&(r.aabb.minx=p.x),p.x>r.aabb.maxx&&(r.aabb.maxx=p.x),p.y<r.aabb.miny&&(r.aabb.miny=p.y),p.y>r.aabb.maxy&&(r.aabb.maxy=p.y),o=o.next}}}shapesInCircle(e,t,n,s,i,l){return null}bodiesInCircle(e,t,n,s,i,l){return null}validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let o=t.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=t.body.posx+(t.body.axisy*u.x-t.body.axisx*u.y),h.y=t.body.posy+(u.x*t.body.axisx+u.y*t.body.axisy),c=c.next}}let s=t.edges.head,i=t.gverts.next,l=i;for(i=i.next;i!=null;){let o=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=o,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,l=o,i=i.next}let r=t.gverts.next,a=s.elt;s=s.next,a.gp0=l,a.gp1=r,a.gnormx=t.body.axisy*a.lnormx-t.body.axisx*a.lnormy,a.gnormy=a.lnormx*t.body.axisx+a.lnormy*t.body.axisy,a.gprojection=t.body.posx*a.gnormx+t.body.posy*a.gnormy+a.lprojection,a.wrap_gnorm!=null&&(a.wrap_gnorm.zpp_inner.x=a.gnormx,a.wrap_gnorm.zpp_inner.y=a.gnormy),a.tp0=a.gp0.y*a.gnormx-a.gp0.x*a.gnormy,a.tp1=a.gp1.y*a.gnormx-a.gp1.x*a.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let r=1;l.localCOMx+=l.lverts.next.next.x*r,l.localCOMy+=l.lverts.next.next.y*r;let a=.5;l.localCOMx*=a,l.localCOMy*=a}else{l.localCOMx=0,l.localCOMy=0;let r=0,a=l.lverts.next,o=a;a=a.next;let p=a;for(a=a.next;a!=null;){let d=a;r+=p.x*(d.y-o.y);let _=d.y*p.x-d.x*p.y;l.localCOMx+=(p.x+d.x)*_,l.localCOMy+=(p.y+d.y)*_,o=p,p=d,a=a.next}a=l.lverts.next;let c=a;r+=p.x*(c.y-o.y);let h=c.y*p.x-c.x*p.y;l.localCOMx+=(p.x+c.x)*h,l.localCOMy+=(p.y+c.y)*h,o=p,p=c,a=a.next;let u=a;r+=p.x*(u.y-o.y);let x=u.y*p.x-u.x*p.y;l.localCOMx+=(p.x+u.x)*x,l.localCOMy+=(p.y+u.y)*x,r=1/(3*r);let y=r;l.localCOMx*=y,l.localCOMy*=y}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,s=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-s,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+s}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,r=t.gverts.next;for(;r!=null;){let a=r,o=l;l=l.next,a.x=t.body.posx+(t.body.axisy*o.x-t.body.axisx*o.y),a.y=t.body.posy+(o.x*t.body.axisx+o.y*t.body.axisy),r=r.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next}}if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let s=1;n.localCOMx+=n.lverts.next.next.x*s,n.localCOMy+=n.lverts.next.next.y*s;let i=.5;n.localCOMx*=i,n.localCOMy*=i}else{n.localCOMx=0,n.localCOMy=0;let s=0,i=n.lverts.next,l=i;i=i.next;let r=i;for(i=i.next;i!=null;){let u=i;s+=r.x*(u.y-l.y);let x=u.y*r.x-u.x*r.y;n.localCOMx+=(r.x+u.x)*x,n.localCOMy+=(r.y+u.y)*x,l=r,r=u,i=i.next}i=n.lverts.next;let a=i;s+=r.x*(a.y-l.y);let o=a.y*r.x-a.x*r.y;n.localCOMx+=(r.x+a.x)*o,n.localCOMy+=(r.y+a.y)*o,l=r,r=a,i=i.next;let p=i;s+=r.x*(p.y-l.y);let c=p.y*r.x-p.x*r.y;n.localCOMx+=(r.x+p.x)*c,n.localCOMy+=(r.y+p.y)*c,s=1/(3*s);let h=s;n.localCOMx*=h,n.localCOMy*=h}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}shapesInShape(e,t,n,s){return null}bodiesInShape(e,t,n,s){return null}rayCast(e,t,n){return null}rayMultiCast(e,t,n,s){return null}};bi._zpp=null,bi._nape=null;var Yn=bi;var Se=class{constructor(){this.aabb=null;this.shape=null;this.dyn=!1;this.parent=null;this.child1=null;this.child2=null;this.height=-1;this.rayt=0;this.next=null;this.mnext=null;this.moved=!1;this.snext=null;this.synced=!1;this.first_sync=!1}alloc(){be.zpp_pool==null?this.aabb=new be:(this.aabb=be.zpp_pool,be.zpp_pool=this.aabb.next,this.aabb.next=null),this.moved=!1,this.synced=!1,this.first_sync=!1}free(){this.height=-1;let e=this.aabb;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e.wrap_min=e.wrap_max=null,e._invalidate=null,e._validate=null,e.next=be.zpp_pool,be.zpp_pool=e,this.child1=this.child2=this.parent=null,this.next=null,this.snext=null,this.mnext=null}isLeaf(){return this.child1==null}};Se.zpp_pool=null;var tt=class{constructor(){this.n1=null;this.n2=null;this.first=!1;this.sleeping=!1;this.id=0;this.di=0;this.arb=null;this.next=null}alloc(){}free(){this.n1=this.n2=null,this.sleeping=!1}};tt.zpp_pool=null;var Mt=class Mt{constructor(){this.root=null}static _initStatics(){Mt.tmpaabb=new be}clear(){if(this.root==null)return;let e=null;for(this.root.next=e,e=this.root;e!=null;){let t=e;e=t.next,t.next=null;let n=t;n.child1==null?(n.shape.node=null,n.shape.removedFromSpace(),n.shape=null):(n.child1!=null&&(n.child1.next=e,e=n.child1),n.child2!=null&&(n.child2.next=e,e=n.child2));let s=n;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Se.zpp_pool,Se.zpp_pool=s}this.root=null}insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else{let t=e.aabb,n=this.root;for(;n.child1!=null;){let o=n.child1,p=n.child2,c=n.aabb,h=(c.maxx-c.minx+(c.maxy-c.miny))*2,u=Mt.tmpaabb,x=n.aabb;u.minx=x.minx<t.minx?x.minx:t.minx,u.miny=x.miny<t.miny?x.miny:t.miny,u.maxx=x.maxx>t.maxx?x.maxx:t.maxx,u.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let y=Mt.tmpaabb,d=(y.maxx-y.minx+(y.maxy-y.miny))*2,_=2*d,f=2*(d-h),z=Mt.tmpaabb,P=o.aabb;z.minx=t.minx<P.minx?t.minx:P.minx,z.miny=t.miny<P.miny?t.miny:P.miny,z.maxx=t.maxx>P.maxx?t.maxx:P.maxx,z.maxy=t.maxy>P.maxy?t.maxy:P.maxy;let k;if(o.child1==null){let v=Mt.tmpaabb;k=(v.maxx-v.minx+(v.maxy-v.miny))*2+f}else{let v=o.aabb,w=(v.maxx-v.minx+(v.maxy-v.miny))*2,O=Mt.tmpaabb;k=(O.maxx-O.minx+(O.maxy-O.miny))*2-w+f}let m=Mt.tmpaabb,b=p.aabb;m.minx=t.minx<b.minx?t.minx:b.minx,m.miny=t.miny<b.miny?t.miny:b.miny,m.maxx=t.maxx>b.maxx?t.maxx:b.maxx,m.maxy=t.maxy>b.maxy?t.maxy:b.maxy;let C;if(p.child1==null){let v=Mt.tmpaabb;C=(v.maxx-v.minx+(v.maxy-v.miny))*2+f}else{let v=p.aabb,w=(v.maxx-v.minx+(v.maxy-v.miny))*2,O=Mt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-w+f}if(_<k&&_<C)break;n=k<C?o:p}let s=n,i=s.parent,l;Se.zpp_pool==null?l=new Se:(l=Se.zpp_pool,Se.zpp_pool=l.next,l.next=null),be.zpp_pool==null?l.aabb=new be:(l.aabb=be.zpp_pool,be.zpp_pool=l.aabb.next,l.aabb.next=null),l.moved=!1,l.synced=!1,l.first_sync=!1,l.parent=i;let r=l.aabb,a=s.aabb;for(r.minx=t.minx<a.minx?t.minx:a.minx,r.miny=t.miny<a.miny?t.miny:a.miny,r.maxx=t.maxx>a.maxx?t.maxx:a.maxx,r.maxy=t.maxy>a.maxy?t.maxy:a.maxy,l.height=s.height+1,i!=null?(i.child1==s?i.child1=l:i.child2=l,l.child1=s,l.child2=e,s.parent=l,e.parent=l):(l.child1=s,l.child2=e,s.parent=l,e.parent=l,this.root=l),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let d=n.child1,_=n.child2,f=_.height-d.height;if(f>1){let z=_.child1,P=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,z.height>P.height){_.child2=z,n.child2=P,P.parent=n;let k=n.aabb,m=d.aabb,b=P.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=n.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=z.height;_.height=1+(M>N?M:N)}else{_.child2=P,n.child2=z,z.parent=n;let k=n.aabb,m=d.aabb,b=z.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=n.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,E=z.height;n.height=1+(O>E?O:E);let M=n.height,N=P.height;_.height=1+(M>N?M:N)}n=_}else if(f<-1){let z=d.child1,P=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,z.height>P.height){d.child2=z,n.child1=P,P.parent=n;let k=n.aabb,m=_.aabb,b=P.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=n.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=z.height;d.height=1+(M>N?M:N)}else{d.child2=P,n.child1=z,z.parent=n;let k=n.aabb,m=_.aabb,b=z.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=n.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,E=z.height;n.height=1+(O>E?O:E);let M=n.height,N=P.height;d.height=1+(M>N?M:N)}n=d}else n=n}let o=n.child1,p=n.child2,c=o.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=o.aabb,y=p.aabb;u.minx=x.minx<y.minx?x.minx:y.minx,u.miny=x.miny<y.miny?x.miny:y.miny,u.maxx=x.maxx>y.maxx?x.maxx:y.maxx,u.maxy=x.maxy>y.maxy?x.maxy:y.maxy,n=n.parent}}}inlined_insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else{let t=e.aabb,n=this.root;for(;n.child1!=null;){let o=n.child1,p=n.child2,c=n.aabb,h=(c.maxx-c.minx+(c.maxy-c.miny))*2,u=Mt.tmpaabb,x=n.aabb;u.minx=x.minx<t.minx?x.minx:t.minx,u.miny=x.miny<t.miny?x.miny:t.miny,u.maxx=x.maxx>t.maxx?x.maxx:t.maxx,u.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let y=Mt.tmpaabb,d=(y.maxx-y.minx+(y.maxy-y.miny))*2,_=2*d,f=2*(d-h),z=Mt.tmpaabb,P=o.aabb;z.minx=t.minx<P.minx?t.minx:P.minx,z.miny=t.miny<P.miny?t.miny:P.miny,z.maxx=t.maxx>P.maxx?t.maxx:P.maxx,z.maxy=t.maxy>P.maxy?t.maxy:P.maxy;let k;if(o.child1==null){let v=Mt.tmpaabb;k=(v.maxx-v.minx+(v.maxy-v.miny))*2+f}else{let v=o.aabb,w=(v.maxx-v.minx+(v.maxy-v.miny))*2,O=Mt.tmpaabb;k=(O.maxx-O.minx+(O.maxy-O.miny))*2-w+f}let m=Mt.tmpaabb,b=p.aabb;m.minx=t.minx<b.minx?t.minx:b.minx,m.miny=t.miny<b.miny?t.miny:b.miny,m.maxx=t.maxx>b.maxx?t.maxx:b.maxx,m.maxy=t.maxy>b.maxy?t.maxy:b.maxy;let C;if(p.child1==null){let v=Mt.tmpaabb;C=(v.maxx-v.minx+(v.maxy-v.miny))*2+f}else{let v=p.aabb,w=(v.maxx-v.minx+(v.maxy-v.miny))*2,O=Mt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-w+f}if(_<k&&_<C)break;n=k<C?o:p}let s=n,i=s.parent,l;Se.zpp_pool==null?l=new Se:(l=Se.zpp_pool,Se.zpp_pool=l.next,l.next=null),be.zpp_pool==null?l.aabb=new be:(l.aabb=be.zpp_pool,be.zpp_pool=l.aabb.next,l.aabb.next=null),l.moved=!1,l.synced=!1,l.first_sync=!1,l.parent=i;let r=l.aabb,a=s.aabb;for(r.minx=t.minx<a.minx?t.minx:a.minx,r.miny=t.miny<a.miny?t.miny:a.miny,r.maxx=t.maxx>a.maxx?t.maxx:a.maxx,r.maxy=t.maxy>a.maxy?t.maxy:a.maxy,l.height=s.height+1,i!=null?(i.child1==s?i.child1=l:i.child2=l,l.child1=s,l.child2=e,s.parent=l,e.parent=l):(l.child1=s,l.child2=e,s.parent=l,e.parent=l,this.root=l),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let d=n.child1,_=n.child2,f=_.height-d.height;if(f>1){let z=_.child1,P=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,z.height>P.height){_.child2=z,n.child2=P,P.parent=n;let k=n.aabb,m=d.aabb,b=P.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=n.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=z.height;_.height=1+(M>N?M:N)}else{_.child2=P,n.child2=z,z.parent=n;let k=n.aabb,m=d.aabb,b=z.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=n.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,E=z.height;n.height=1+(O>E?O:E);let M=n.height,N=P.height;_.height=1+(M>N?M:N)}n=_}else if(f<-1){let z=d.child1,P=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,z.height>P.height){d.child2=z,n.child1=P,P.parent=n;let k=n.aabb,m=_.aabb,b=P.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=n.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=z.height;d.height=1+(M>N?M:N)}else{d.child2=P,n.child1=z,z.parent=n;let k=n.aabb,m=_.aabb,b=z.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=n.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,E=z.height;n.height=1+(O>E?O:E);let M=n.height,N=P.height;d.height=1+(M>N?M:N)}n=d}else n=n}let o=n.child1,p=n.child2,c=o.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=o.aabb,y=p.aabb;u.minx=x.minx<y.minx?x.minx:y.minx,u.miny=x.miny<y.miny?x.miny:y.miny,u.maxx=x.maxx>y.maxx?x.maxx:y.maxx,u.maxy=x.maxy>y.maxy?x.maxy:y.maxy,n=n.parent}}}removeLeaf(e){if(e==this.root)this.root=null;else{let t=e.parent,n=t.parent,s=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=s:n.child2=s,s.parent=n;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=be.zpp_pool,be.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Se.zpp_pool,Se.zpp_pool=i;let r=n;for(;r!=null;){if(r.child1==null||r.height<2)r=r;else{let d=r.child1,_=r.child2,f=_.height-d.height;if(f>1){let z=_.child1,P=_.child2;if(_.child1=r,_.parent=r.parent,r.parent=_,_.parent!=null?_.parent.child1==r?_.parent.child1=_:_.parent.child2=_:this.root=_,z.height>P.height){_.child2=z,r.child2=P,P.parent=r;let k=r.aabb,m=d.aabb,b=P.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=r.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,E=P.height;r.height=1+(O>E?O:E);let M=r.height,N=z.height;_.height=1+(M>N?M:N)}else{_.child2=P,r.child2=z,z.parent=r;let k=r.aabb,m=d.aabb,b=z.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=r.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,E=z.height;r.height=1+(O>E?O:E);let M=r.height,N=P.height;_.height=1+(M>N?M:N)}r=_}else if(f<-1){let z=d.child1,P=d.child2;if(d.child1=r,d.parent=r.parent,r.parent=d,d.parent!=null?d.parent.child1==r?d.parent.child1=d:d.parent.child2=d:this.root=d,z.height>P.height){d.child2=z,r.child1=P,P.parent=r;let k=r.aabb,m=_.aabb,b=P.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=r.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,E=P.height;r.height=1+(O>E?O:E);let M=r.height,N=z.height;d.height=1+(M>N?M:N)}else{d.child2=P,r.child1=z,z.parent=r;let k=r.aabb,m=_.aabb,b=z.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=r.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,E=z.height;r.height=1+(O>E?O:E);let M=r.height,N=P.height;d.height=1+(M>N?M:N)}r=d}else r=r}let a=r,o=a.child1,p=a.child2,c=a.aabb,h=o.aabb,u=p.aabb;c.minx=h.minx<u.minx?h.minx:u.minx,c.miny=h.miny<u.miny?h.miny:u.miny,c.maxx=h.maxx>u.maxx?h.maxx:u.maxx,c.maxy=h.maxy>u.maxy?h.maxy:u.maxy;let x=o.height,y=p.height;a.height=1+(x>y?x:y),r=a.parent}}else{this.root=s,s.parent=null;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=be.zpp_pool,be.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Se.zpp_pool,Se.zpp_pool=i}}}inlined_removeLeaf(e){if(e==this.root){this.root=null;return}else{let t=e.parent,n=t.parent,s=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=s:n.child2=s,s.parent=n;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=be.zpp_pool,be.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Se.zpp_pool,Se.zpp_pool=i;let r=n;for(;r!=null;){if(r.child1==null||r.height<2)r=r;else{let d=r.child1,_=r.child2,f=_.height-d.height;if(f>1){let z=_.child1,P=_.child2;if(_.child1=r,_.parent=r.parent,r.parent=_,_.parent!=null?_.parent.child1==r?_.parent.child1=_:_.parent.child2=_:this.root=_,z.height>P.height){_.child2=z,r.child2=P,P.parent=r;let k=r.aabb,m=d.aabb,b=P.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=r.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,E=P.height;r.height=1+(O>E?O:E);let M=r.height,N=z.height;_.height=1+(M>N?M:N)}else{_.child2=P,r.child2=z,z.parent=r;let k=r.aabb,m=d.aabb,b=z.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=r.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,E=z.height;r.height=1+(O>E?O:E);let M=r.height,N=P.height;_.height=1+(M>N?M:N)}r=_}else if(f<-1){let z=d.child1,P=d.child2;if(d.child1=r,d.parent=r.parent,r.parent=d,d.parent!=null?d.parent.child1==r?d.parent.child1=d:d.parent.child2=d:this.root=d,z.height>P.height){d.child2=z,r.child1=P,P.parent=r;let k=r.aabb,m=_.aabb,b=P.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=r.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,E=P.height;r.height=1+(O>E?O:E);let M=r.height,N=z.height;d.height=1+(M>N?M:N)}else{d.child2=P,r.child1=z,z.parent=r;let k=r.aabb,m=_.aabb,b=z.aabb;k.minx=m.minx<b.minx?m.minx:b.minx,k.miny=m.miny<b.miny?m.miny:b.miny,k.maxx=m.maxx>b.maxx?m.maxx:b.maxx,k.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=r.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,E=z.height;r.height=1+(O>E?O:E);let M=r.height,N=P.height;d.height=1+(M>N?M:N)}r=d}else r=r}let a=r,o=a.child1,p=a.child2,c=a.aabb,h=o.aabb,u=p.aabb;c.minx=h.minx<u.minx?h.minx:u.minx,c.miny=h.miny<u.miny?h.miny:u.miny,c.maxx=h.maxx>u.maxx?h.maxx:u.maxx,c.maxy=h.maxy>u.maxy?h.maxy:u.maxy;let x=o.height,y=p.height;a.height=1+(x>y?x:y),r=a.parent}}else{this.root=s,s.parent=null;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=be.zpp_pool,be.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Se.zpp_pool,Se.zpp_pool=i}}}balance(e){if(e.child1==null||e.height<2)return e;{let t=e.child1,n=e.child2,s=n.height-t.height;if(s>1){let i=n.child1,l=n.child2;if(n.child1=e,n.parent=e.parent,e.parent=n,n.parent!=null?n.parent.child1==e?n.parent.child1=n:n.parent.child2=n:this.root=n,i.height>l.height){n.child2=i,e.child2=l,l.parent=e;let r=e.aabb,a=t.aabb,o=l.aabb;r.minx=a.minx<o.minx?a.minx:o.minx,r.miny=a.miny<o.miny?a.miny:o.miny,r.maxx=a.maxx>o.maxx?a.maxx:o.maxx,r.maxy=a.maxy>o.maxy?a.maxy:o.maxy;let p=n.aabb,c=e.aabb,h=i.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=t.height,x=l.height;e.height=1+(u>x?u:x);let y=e.height,d=i.height;n.height=1+(y>d?y:d)}else{n.child2=l,e.child2=i,i.parent=e;let r=e.aabb,a=t.aabb,o=i.aabb;r.minx=a.minx<o.minx?a.minx:o.minx,r.miny=a.miny<o.miny?a.miny:o.miny,r.maxx=a.maxx>o.maxx?a.maxx:o.maxx,r.maxy=a.maxy>o.maxy?a.maxy:o.maxy;let p=n.aabb,c=e.aabb,h=l.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=t.height,x=i.height;e.height=1+(u>x?u:x);let y=e.height,d=l.height;n.height=1+(y>d?y:d)}return n}else if(s<-1){let i=t.child1,l=t.child2;if(t.child1=e,t.parent=e.parent,e.parent=t,t.parent!=null?t.parent.child1==e?t.parent.child1=t:t.parent.child2=t:this.root=t,i.height>l.height){t.child2=i,e.child1=l,l.parent=e;let r=e.aabb,a=n.aabb,o=l.aabb;r.minx=a.minx<o.minx?a.minx:o.minx,r.miny=a.miny<o.miny?a.miny:o.miny,r.maxx=a.maxx>o.maxx?a.maxx:o.maxx,r.maxy=a.maxy>o.maxy?a.maxy:o.maxy;let p=t.aabb,c=e.aabb,h=i.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=n.height,x=l.height;e.height=1+(u>x?u:x);let y=e.height,d=i.height;t.height=1+(y>d?y:d)}else{t.child2=l,e.child1=i,i.parent=e;let r=e.aabb,a=n.aabb,o=i.aabb;r.minx=a.minx<o.minx?a.minx:o.minx,r.miny=a.miny<o.miny?a.miny:o.miny,r.maxx=a.maxx>o.maxx?a.maxx:o.maxx,r.maxy=a.maxy>o.maxy?a.maxy:o.maxy;let p=t.aabb,c=e.aabb,h=l.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=n.height,x=i.height;e.height=1+(u>x?u:x);let y=e.height,d=l.height;t.height=1+(y>d?y:d)}return t}else return e}}};Mt.tmpaabb=null;var $e=Mt;var fe=class fe extends Yn{constructor(t){super();this.pairs=null;this.syncs=null;this.moves=null;this.treeStack=null;this.treeStack2=null;this.failed=null;this.openlist=null;this.space=t,this.is_sweep=!1,this.dynab=this,this.stree=new $e,this.dtree=new $e}dyn(t){return t.body.type==1?!1:!t.body.component.sleeping}__insert(t){let n;Se.zpp_pool==null?n=new Se:(n=Se.zpp_pool,Se.zpp_pool=n.next,n.next=null),be.zpp_pool==null?n.aabb=new be:(n.aabb=be.zpp_pool,be.zpp_pool=n.aabb.next,n.aabb.next=null),n.moved=!1,n.synced=!1,n.first_sync=!1,n.shape=t,t.node=n,n.synced=!0,n.first_sync=!0,n.snext=this.syncs,this.syncs=n}__remove(t){let n=t.node;if(n.first_sync||(n.dyn?this.dtree.removeLeaf(n):this.stree.removeLeaf(n)),t.node=null,n.synced){let a=null,o=this.syncs;for(;o!=null&&o!=n;)a=o,o=o.snext;a==null?this.syncs=o.snext:a.snext=o.snext,o.snext=null,n.synced=!1}if(n.moved){let a=null,o=this.moves;for(;o!=null&&o!=n;)a=o,o=o.mnext;a==null?this.moves=o.mnext:a.mnext=o.mnext,o.mnext=null,n.moved=!1}let s=null,i=this.pairs;for(;i!=null;){let a=i.next;if(i.n1==n||i.n2==n){s==null?this.pairs=a:s.next=a,i.arb!=null&&(i.arb.pair=null),i.arb=null,i.n1.shape.pairs.remove(i),i.n2.shape.pairs.remove(i);let o=i;o.n1=o.n2=null,o.sleeping=!1,o.next=tt.zpp_pool,tt.zpp_pool=o,i=a;continue}s=i,i=a}for(;t.pairs.head!=null;){let a=t.pairs.pop_unsafe();a.n1==n?a.n2.shape.pairs.remove(a):a.n1.shape.pairs.remove(a),a.arb!=null&&(a.arb.pair=null),a.arb=null;let o=a;o.n1=o.n2=null,o.sleeping=!1,o.next=tt.zpp_pool,tt.zpp_pool=o}let l=n;l.height=-1;let r=l.aabb;r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r.wrap_min=r.wrap_max=null,r._invalidate=null,r._validate=null,r.next=be.zpp_pool,be.zpp_pool=r,l.child1=l.child2=l.parent=null,l.next=null,l.snext=null,l.mnext=null,l.next=Se.zpp_pool,Se.zpp_pool=l}__sync(t){let n=t.node;if(!n.synced){if(!this.space.continuous&&t.zip_aabb&&t.body!=null)if(t.zip_aabb=!1,t.type==0){let i=t.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=!1,i.zip_localCOM){if(i.zip_localCOM=!1,i.type==1){let o=i.polygon;if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(o.lverts.next.next==null)o.localCOMx=o.lverts.next.x,o.localCOMy=o.lverts.next.y;else if(o.lverts.next.next.next==null){o.localCOMx=o.lverts.next.x,o.localCOMy=o.lverts.next.y;let p=1;o.localCOMx+=o.lverts.next.next.x*p,o.localCOMy+=o.lverts.next.next.y*p;let c=.5;o.localCOMx*=c,o.localCOMy*=c}else{o.localCOMx=0,o.localCOMy=0;let p=0,c=o.lverts.next,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let z=c;p+=u.x*(z.y-h.y);let P=z.y*u.x-z.x*u.y;o.localCOMx+=(u.x+z.x)*P,o.localCOMy+=(u.y+z.y)*P,h=u,u=z,c=c.next}c=o.lverts.next;let x=c;p+=u.x*(x.y-h.y);let y=x.y*u.x-x.x*u.y;o.localCOMx+=(u.x+x.x)*y,o.localCOMy+=(u.y+x.y)*y,h=u,u=x,c=c.next;let d=c;p+=u.x*(d.y-h.y);let _=d.y*u.x-d.x*u.y;o.localCOMx+=(u.x+d.x)*_,o.localCOMy+=(u.y+d.y)*_,p=1/(3*p);let f=p;o.localCOMx*=f,o.localCOMy*=f}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let l=i.radius,r=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-r,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+r}else{let i=t.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let o=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=o;o=o.next,c.x=i.body.posx+(i.body.axisy*h.x-i.body.axisx*h.y),c.y=i.body.posy+(h.x*i.body.axisx+h.y*i.body.axisy),p=p.next}}if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let l=i.gverts.next;i.aabb.minx=l.x,i.aabb.miny=l.y,i.aabb.maxx=l.x,i.aabb.maxy=l.y;let r=i.gverts.next.next;for(;r!=null;){let a=r;a.x<i.aabb.minx&&(i.aabb.minx=a.x),a.x>i.aabb.maxx&&(i.aabb.maxx=a.x),a.y<i.aabb.miny&&(i.aabb.miny=a.y),a.y>i.aabb.maxy&&(i.aabb.maxy=a.y),r=r.next}}let s;if(n.dyn==(t.body.type==1?!1:!t.body.component.sleeping)){let i=n.aabb,l=t.aabb;s=!(l.minx>=i.minx&&l.miny>=i.miny&&l.maxx<=i.maxx&&l.maxy<=i.maxy)}else s=!0;s&&(n.synced=!0,n.snext=this.syncs,this.syncs=n)}}sync_broadphase(){if(this.space.validation(),this.syncs!=null)if(this.moves==null){let t=this.syncs;for(;t!=null;){let s=t.shape;if(t.first_sync)t.first_sync=!1;else{let a=t.dyn?this.dtree:this.stree;if(t==a.root)a.root=null;else{let o=t.parent,p=o.parent,c=o.child1==t?o.child2:o.child1;if(p!=null){p.child1==o?p.child1=c:p.child2=c,c.parent=p;let h=o;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Se.zpp_pool,Se.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else{let m=x.child1,b=x.child2,C=b.height-m.height;if(C>1){let v=b.child1,w=b.child2;if(b.child1=x,b.parent=x.parent,x.parent=b,b.parent!=null?b.parent.child1==x?b.parent.child1=b:b.parent.child2=b:a.root=b,v.height>w.height){b.child2=v,x.child2=w,w.parent=x;let O=x.aabb,E=m.aabb,M=w.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=b.aabb,Z=x.aabb,S=v.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=m.height,D=w.height;x.height=1+(V>D?V:D);let T=x.height,G=v.height;b.height=1+(T>G?T:G)}else{b.child2=w,x.child2=v,v.parent=x;let O=x.aabb,E=m.aabb,M=v.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=b.aabb,Z=x.aabb,S=w.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=m.height,D=v.height;x.height=1+(V>D?V:D);let T=x.height,G=w.height;b.height=1+(T>G?T:G)}x=b}else if(C<-1){let v=m.child1,w=m.child2;if(m.child1=x,m.parent=x.parent,x.parent=m,m.parent!=null?m.parent.child1==x?m.parent.child1=m:m.parent.child2=m:a.root=m,v.height>w.height){m.child2=v,x.child1=w,w.parent=x;let O=x.aabb,E=b.aabb,M=w.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=m.aabb,Z=x.aabb,S=v.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=b.height,D=w.height;x.height=1+(V>D?V:D);let T=x.height,G=v.height;m.height=1+(T>G?T:G)}else{m.child2=w,x.child1=v,v.parent=x;let O=x.aabb,E=b.aabb,M=v.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=m.aabb,Z=x.aabb,S=w.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=b.height,D=v.height;x.height=1+(V>D?V:D);let T=x.height,G=w.height;m.height=1+(T>G?T:G)}x=m}else x=x}let y=x.child1,d=x.child2,_=x.aabb,f=y.aabb,z=d.aabb;_.minx=f.minx<z.minx?f.minx:z.minx,_.miny=f.miny<z.miny?f.miny:z.miny,_.maxx=f.maxx>z.maxx?f.maxx:z.maxx,_.maxy=f.maxy>z.maxy?f.maxy:z.maxy;let P=y.height,k=d.height;x.height=1+(P>k?P:k),x=x.parent}}else{a.root=c,c.parent=null;let h=o;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Se.zpp_pool,Se.zpp_pool=h}}}let i=t.aabb;if(!this.space.continuous&&s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let a=s.circle;if(a.zip_worldCOM&&a.body!=null){if(a.zip_worldCOM=!1,a.zip_localCOM){if(a.zip_localCOM=!1,a.type==1){let h=a.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let u=1;h.localCOMx+=h.lverts.next.next.x*u,h.localCOMy+=h.lverts.next.next.y*u;let x=.5;h.localCOMx*=x,h.localCOMy*=x}else{h.localCOMx=0,h.localCOMy=0;let u=0,x=h.lverts.next,y=x;x=x.next;let d=x;for(x=x.next;x!=null;){let m=x;u+=d.x*(m.y-y.y);let b=m.y*d.x-m.x*d.y;h.localCOMx+=(d.x+m.x)*b,h.localCOMy+=(d.y+m.y)*b,y=d,d=m,x=x.next}x=h.lverts.next;let _=x;u+=d.x*(_.y-y.y);let f=_.y*d.x-_.x*d.y;h.localCOMx+=(d.x+_.x)*f,h.localCOMy+=(d.y+_.y)*f,y=d,d=_,x=x.next;let z=x;u+=d.x*(z.y-y.y);let P=z.y*d.x-z.x*d.y;h.localCOMx+=(d.x+z.x)*P,h.localCOMy+=(d.y+z.y)*P,u=1/(3*u);let k=u;h.localCOMx*=k,h.localCOMy*=k}}a.wrap_localCOM!=null&&(a.wrap_localCOM.zpp_inner.x=a.localCOMx,a.wrap_localCOM.zpp_inner.y=a.localCOMy)}let c=a.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),a.worldCOMx=a.body.posx+(a.body.axisy*a.localCOMx-a.body.axisx*a.localCOMy),a.worldCOMy=a.body.posy+(a.localCOMx*a.body.axisx+a.localCOMy*a.body.axisy)}let o=a.radius,p=a.radius;a.aabb.minx=a.worldCOMx-o,a.aabb.miny=a.worldCOMy-p,a.aabb.maxx=a.worldCOMx+o,a.aabb.maxy=a.worldCOMy+p}else{let a=s.polygon;if(a.zip_gverts&&a.body!=null){a.zip_gverts=!1,a.validate_lverts();let c=a.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=a.lverts.next,u=a.gverts.next;for(;u!=null;){let x=u,y=h;h=h.next,x.x=a.body.posx+(a.body.axisy*y.x-a.body.axisx*y.y),x.y=a.body.posy+(y.x*a.body.axisx+y.y*a.body.axisy),u=u.next}}if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let o=a.gverts.next;a.aabb.minx=o.x,a.aabb.miny=o.y,a.aabb.maxx=o.x,a.aabb.maxy=o.y;let p=a.gverts.next.next;for(;p!=null;){let c=p;c.x<a.aabb.minx&&(a.aabb.minx=c.x),c.x>a.aabb.maxx&&(a.aabb.maxx=c.x),c.y<a.aabb.miny&&(a.aabb.miny=c.y),c.y>a.aabb.maxy&&(a.aabb.maxy=c.y),p=p.next}}let l=s.aabb;i.minx=l.minx-3,i.miny=l.miny-3,i.maxx=l.maxx+3,i.maxy=l.maxy+3;let r=(t.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(r.root==null)r.root=t,r.root.parent=null;else{let a=t.aabb,o=r.root;for(;o.child1!=null;){let y=o.child1,d=o.child2,_=o.aabb,f=(_.maxx-_.minx+(_.maxy-_.miny))*2,z=$e.tmpaabb,P=o.aabb;z.minx=P.minx<a.minx?P.minx:a.minx,z.miny=P.miny<a.miny?P.miny:a.miny,z.maxx=P.maxx>a.maxx?P.maxx:a.maxx,z.maxy=P.maxy>a.maxy?P.maxy:a.maxy;let k=$e.tmpaabb,m=(k.maxx-k.minx+(k.maxy-k.miny))*2,b=2*m,C=2*(m-f),v=$e.tmpaabb,w=y.aabb;v.minx=a.minx<w.minx?a.minx:w.minx,v.miny=a.miny<w.miny?a.miny:w.miny,v.maxx=a.maxx>w.maxx?a.maxx:w.maxx,v.maxy=a.maxy>w.maxy?a.maxy:w.maxy;let O;if(y.child1==null){let Z=$e.tmpaabb;O=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=y.aabb,S=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,V=$e.tmpaabb;O=(V.maxx-V.minx+(V.maxy-V.miny))*2-S+C}let E=$e.tmpaabb,M=d.aabb;E.minx=a.minx<M.minx?a.minx:M.minx,E.miny=a.miny<M.miny?a.miny:M.miny,E.maxx=a.maxx>M.maxx?a.maxx:M.maxx,E.maxy=a.maxy>M.maxy?a.maxy:M.maxy;let N;if(d.child1==null){let Z=$e.tmpaabb;N=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=d.aabb,S=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,V=$e.tmpaabb;N=(V.maxx-V.minx+(V.maxy-V.miny))*2-S+C}if(b<O&&b<N)break;o=O<N?y:d}let p=o,c=p.parent,h;Se.zpp_pool==null?h=new Se:(h=Se.zpp_pool,Se.zpp_pool=h.next,h.next=null),be.zpp_pool==null?h.aabb=new be:(h.aabb=be.zpp_pool,be.zpp_pool=h.aabb.next,h.aabb.next=null),h.moved=!1,h.synced=!1,h.first_sync=!1,h.parent=c;let u=h.aabb,x=p.aabb;for(u.minx=a.minx<x.minx?a.minx:x.minx,u.miny=a.miny<x.miny?a.miny:x.miny,u.maxx=a.maxx>x.maxx?a.maxx:x.maxx,u.maxy=a.maxy>x.maxy?a.maxy:x.maxy,h.height=p.height+1,c!=null?(c.child1==p?c.child1=h:c.child2=h,h.child1=p,h.child2=t,p.parent=h,t.parent=h):(h.child1=p,h.child2=t,p.parent=h,t.parent=h,r.root=h),o=t.parent;o!=null;){if(o.child1==null||o.height<2)o=o;else{let m=o.child1,b=o.child2,C=b.height-m.height;if(C>1){let v=b.child1,w=b.child2;if(b.child1=o,b.parent=o.parent,o.parent=b,b.parent!=null?b.parent.child1==o?b.parent.child1=b:b.parent.child2=b:r.root=b,v.height>w.height){b.child2=v,o.child2=w,w.parent=o;let O=o.aabb,E=m.aabb,M=w.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=b.aabb,Z=o.aabb,S=v.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=m.height,D=w.height;o.height=1+(V>D?V:D);let T=o.height,G=v.height;b.height=1+(T>G?T:G)}else{b.child2=w,o.child2=v,v.parent=o;let O=o.aabb,E=m.aabb,M=v.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=b.aabb,Z=o.aabb,S=w.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=m.height,D=v.height;o.height=1+(V>D?V:D);let T=o.height,G=w.height;b.height=1+(T>G?T:G)}o=b}else if(C<-1){let v=m.child1,w=m.child2;if(m.child1=o,m.parent=o.parent,o.parent=m,m.parent!=null?m.parent.child1==o?m.parent.child1=m:m.parent.child2=m:r.root=m,v.height>w.height){m.child2=v,o.child1=w,w.parent=o;let O=o.aabb,E=b.aabb,M=w.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=m.aabb,Z=o.aabb,S=v.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=b.height,D=w.height;o.height=1+(V>D?V:D);let T=o.height,G=v.height;m.height=1+(T>G?T:G)}else{m.child2=w,o.child1=v,v.parent=o;let O=o.aabb,E=b.aabb,M=v.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=m.aabb,Z=o.aabb,S=w.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=b.height,D=v.height;o.height=1+(V>D?V:D);let T=o.height,G=w.height;m.height=1+(T>G?T:G)}o=m}else o=o}let y=o.child1,d=o.child2,_=y.height,f=d.height;o.height=1+(_>f?_:f);let z=o.aabb,P=y.aabb,k=d.aabb;z.minx=P.minx<k.minx?P.minx:k.minx,z.miny=P.miny<k.miny?P.miny:k.miny,z.maxx=P.maxx>k.maxx?P.maxx:k.maxx,z.maxy=P.maxy>k.maxy?P.maxy:k.maxy,o=o.parent}}t.synced=!1,t.moved=!0,t.mnext=t.snext,t.snext=null,t=t.mnext}let n=this.syncs;this.syncs=this.moves,this.moves=n}else for(;this.syncs!=null;){let t=this.syncs;this.syncs=t.snext,t.snext=null;let n=t,s=n.shape;if(n.first_sync)n.first_sync=!1;else{let a=n.dyn?this.dtree:this.stree;if(n==a.root)a.root=null;else{let o=n.parent,p=o.parent,c=o.child1==n?o.child2:o.child1;if(p!=null){p.child1==o?p.child1=c:p.child2=c,c.parent=p;let h=o;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Se.zpp_pool,Se.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else{let m=x.child1,b=x.child2,C=b.height-m.height;if(C>1){let v=b.child1,w=b.child2;if(b.child1=x,b.parent=x.parent,x.parent=b,b.parent!=null?b.parent.child1==x?b.parent.child1=b:b.parent.child2=b:a.root=b,v.height>w.height){b.child2=v,x.child2=w,w.parent=x;let O=x.aabb,E=m.aabb,M=w.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=b.aabb,Z=x.aabb,S=v.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=m.height,D=w.height;x.height=1+(V>D?V:D);let T=x.height,G=v.height;b.height=1+(T>G?T:G)}else{b.child2=w,x.child2=v,v.parent=x;let O=x.aabb,E=m.aabb,M=v.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=b.aabb,Z=x.aabb,S=w.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=m.height,D=v.height;x.height=1+(V>D?V:D);let T=x.height,G=w.height;b.height=1+(T>G?T:G)}x=b}else if(C<-1){let v=m.child1,w=m.child2;if(m.child1=x,m.parent=x.parent,x.parent=m,m.parent!=null?m.parent.child1==x?m.parent.child1=m:m.parent.child2=m:a.root=m,v.height>w.height){m.child2=v,x.child1=w,w.parent=x;let O=x.aabb,E=b.aabb,M=w.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=m.aabb,Z=x.aabb,S=v.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=b.height,D=w.height;x.height=1+(V>D?V:D);let T=x.height,G=v.height;m.height=1+(T>G?T:G)}else{m.child2=w,x.child1=v,v.parent=x;let O=x.aabb,E=b.aabb,M=v.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=m.aabb,Z=x.aabb,S=w.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=b.height,D=v.height;x.height=1+(V>D?V:D);let T=x.height,G=w.height;m.height=1+(T>G?T:G)}x=m}else x=x}let y=x.child1,d=x.child2,_=x.aabb,f=y.aabb,z=d.aabb;_.minx=f.minx<z.minx?f.minx:z.minx,_.miny=f.miny<z.miny?f.miny:z.miny,_.maxx=f.maxx>z.maxx?f.maxx:z.maxx,_.maxy=f.maxy>z.maxy?f.maxy:z.maxy;let P=y.height,k=d.height;x.height=1+(P>k?P:k),x=x.parent}}else{a.root=c,c.parent=null;let h=o;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Se.zpp_pool,Se.zpp_pool=h}}}let i=n.aabb;if(!this.space.continuous&&s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let a=s.circle;if(a.zip_worldCOM&&a.body!=null){if(a.zip_worldCOM=!1,a.zip_localCOM){if(a.zip_localCOM=!1,a.type==1){let h=a.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let u=1;h.localCOMx+=h.lverts.next.next.x*u,h.localCOMy+=h.lverts.next.next.y*u;let x=.5;h.localCOMx*=x,h.localCOMy*=x}else{h.localCOMx=0,h.localCOMy=0;let u=0,x=h.lverts.next,y=x;x=x.next;let d=x;for(x=x.next;x!=null;){let m=x;u+=d.x*(m.y-y.y);let b=m.y*d.x-m.x*d.y;h.localCOMx+=(d.x+m.x)*b,h.localCOMy+=(d.y+m.y)*b,y=d,d=m,x=x.next}x=h.lverts.next;let _=x;u+=d.x*(_.y-y.y);let f=_.y*d.x-_.x*d.y;h.localCOMx+=(d.x+_.x)*f,h.localCOMy+=(d.y+_.y)*f,y=d,d=_,x=x.next;let z=x;u+=d.x*(z.y-y.y);let P=z.y*d.x-z.x*d.y;h.localCOMx+=(d.x+z.x)*P,h.localCOMy+=(d.y+z.y)*P,u=1/(3*u);let k=u;h.localCOMx*=k,h.localCOMy*=k}}a.wrap_localCOM!=null&&(a.wrap_localCOM.zpp_inner.x=a.localCOMx,a.wrap_localCOM.zpp_inner.y=a.localCOMy)}let c=a.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),a.worldCOMx=a.body.posx+(a.body.axisy*a.localCOMx-a.body.axisx*a.localCOMy),a.worldCOMy=a.body.posy+(a.localCOMx*a.body.axisx+a.localCOMy*a.body.axisy)}let o=a.radius,p=a.radius;a.aabb.minx=a.worldCOMx-o,a.aabb.miny=a.worldCOMy-p,a.aabb.maxx=a.worldCOMx+o,a.aabb.maxy=a.worldCOMy+p}else{let a=s.polygon;if(a.zip_gverts&&a.body!=null){a.zip_gverts=!1,a.validate_lverts();let c=a.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=a.lverts.next,u=a.gverts.next;for(;u!=null;){let x=u,y=h;h=h.next,x.x=a.body.posx+(a.body.axisy*y.x-a.body.axisx*y.y),x.y=a.body.posy+(y.x*a.body.axisx+y.y*a.body.axisy),u=u.next}}if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let o=a.gverts.next;a.aabb.minx=o.x,a.aabb.miny=o.y,a.aabb.maxx=o.x,a.aabb.maxy=o.y;let p=a.gverts.next.next;for(;p!=null;){let c=p;c.x<a.aabb.minx&&(a.aabb.minx=c.x),c.x>a.aabb.maxx&&(a.aabb.maxx=c.x),c.y<a.aabb.miny&&(a.aabb.miny=c.y),c.y>a.aabb.maxy&&(a.aabb.maxy=c.y),p=p.next}}let l=s.aabb;i.minx=l.minx-3,i.miny=l.miny-3,i.maxx=l.maxx+3,i.maxy=l.maxy+3;let r=(n.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(r.root==null)r.root=n,r.root.parent=null;else{let a=n.aabb,o=r.root;for(;o.child1!=null;){let y=o.child1,d=o.child2,_=o.aabb,f=(_.maxx-_.minx+(_.maxy-_.miny))*2,z=$e.tmpaabb,P=o.aabb;z.minx=P.minx<a.minx?P.minx:a.minx,z.miny=P.miny<a.miny?P.miny:a.miny,z.maxx=P.maxx>a.maxx?P.maxx:a.maxx,z.maxy=P.maxy>a.maxy?P.maxy:a.maxy;let k=$e.tmpaabb,m=(k.maxx-k.minx+(k.maxy-k.miny))*2,b=2*m,C=2*(m-f),v=$e.tmpaabb,w=y.aabb;v.minx=a.minx<w.minx?a.minx:w.minx,v.miny=a.miny<w.miny?a.miny:w.miny,v.maxx=a.maxx>w.maxx?a.maxx:w.maxx,v.maxy=a.maxy>w.maxy?a.maxy:w.maxy;let O;if(y.child1==null){let Z=$e.tmpaabb;O=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=y.aabb,S=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,V=$e.tmpaabb;O=(V.maxx-V.minx+(V.maxy-V.miny))*2-S+C}let E=$e.tmpaabb,M=d.aabb;E.minx=a.minx<M.minx?a.minx:M.minx,E.miny=a.miny<M.miny?a.miny:M.miny,E.maxx=a.maxx>M.maxx?a.maxx:M.maxx,E.maxy=a.maxy>M.maxy?a.maxy:M.maxy;let N;if(d.child1==null){let Z=$e.tmpaabb;N=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=d.aabb,S=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,V=$e.tmpaabb;N=(V.maxx-V.minx+(V.maxy-V.miny))*2-S+C}if(b<O&&b<N)break;o=O<N?y:d}let p=o,c=p.parent,h;Se.zpp_pool==null?h=new Se:(h=Se.zpp_pool,Se.zpp_pool=h.next,h.next=null),be.zpp_pool==null?h.aabb=new be:(h.aabb=be.zpp_pool,be.zpp_pool=h.aabb.next,h.aabb.next=null),h.moved=!1,h.synced=!1,h.first_sync=!1,h.parent=c;let u=h.aabb,x=p.aabb;for(u.minx=a.minx<x.minx?a.minx:x.minx,u.miny=a.miny<x.miny?a.miny:x.miny,u.maxx=a.maxx>x.maxx?a.maxx:x.maxx,u.maxy=a.maxy>x.maxy?a.maxy:x.maxy,h.height=p.height+1,c!=null?(c.child1==p?c.child1=h:c.child2=h,h.child1=p,h.child2=n,p.parent=h,n.parent=h):(h.child1=p,h.child2=n,p.parent=h,n.parent=h,r.root=h),o=n.parent;o!=null;){if(o.child1==null||o.height<2)o=o;else{let m=o.child1,b=o.child2,C=b.height-m.height;if(C>1){let v=b.child1,w=b.child2;if(b.child1=o,b.parent=o.parent,o.parent=b,b.parent!=null?b.parent.child1==o?b.parent.child1=b:b.parent.child2=b:r.root=b,v.height>w.height){b.child2=v,o.child2=w,w.parent=o;let O=o.aabb,E=m.aabb,M=w.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=b.aabb,Z=o.aabb,S=v.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=m.height,D=w.height;o.height=1+(V>D?V:D);let T=o.height,G=v.height;b.height=1+(T>G?T:G)}else{b.child2=w,o.child2=v,v.parent=o;let O=o.aabb,E=m.aabb,M=v.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=b.aabb,Z=o.aabb,S=w.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=m.height,D=v.height;o.height=1+(V>D?V:D);let T=o.height,G=w.height;b.height=1+(T>G?T:G)}o=b}else if(C<-1){let v=m.child1,w=m.child2;if(m.child1=o,m.parent=o.parent,o.parent=m,m.parent!=null?m.parent.child1==o?m.parent.child1=m:m.parent.child2=m:r.root=m,v.height>w.height){m.child2=v,o.child1=w,w.parent=o;let O=o.aabb,E=b.aabb,M=w.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=m.aabb,Z=o.aabb,S=v.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=b.height,D=w.height;o.height=1+(V>D?V:D);let T=o.height,G=v.height;m.height=1+(T>G?T:G)}else{m.child2=w,o.child1=v,v.parent=o;let O=o.aabb,E=b.aabb,M=v.aabb;O.minx=E.minx<M.minx?E.minx:M.minx,O.miny=E.miny<M.miny?E.miny:M.miny,O.maxx=E.maxx>M.maxx?E.maxx:M.maxx,O.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let N=m.aabb,Z=o.aabb,S=w.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=b.height,D=v.height;o.height=1+(V>D?V:D);let T=o.height,G=w.height;m.height=1+(T>G?T:G)}o=m}else o=o}let y=o.child1,d=o.child2,_=y.height,f=d.height;o.height=1+(_>f?_:f);let z=o.aabb,P=y.aabb,k=d.aabb;z.minx=P.minx<k.minx?P.minx:k.minx,z.miny=P.miny<k.miny?P.miny:k.miny,z.maxx=P.maxx>k.maxx?P.maxx:k.maxx,z.maxy=P.maxy>k.maxy?P.maxy:k.maxy,o=o.parent}}n.synced=!1,n.moved||(n.moved=!0,n.mnext=this.moves,this.moves=n)}}broadphase(t,n){let s=this.syncs;for(;s!=null;){let r=s.shape;if(s.first_sync)s.first_sync=!1;else{let c=s.dyn?this.dtree:this.stree;if(s==c.root)c.root=null;else{let h=s.parent,u=h.parent,x=h.child1==s?h.child2:h.child1;if(u!=null){u.child1==h?u.child1=x:u.child2=x,x.parent=u;let y=h;y.height=-1;let d=y.aabb;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d.wrap_min=d.wrap_max=null,d._invalidate=null,d._validate=null,d.next=be.zpp_pool,be.zpp_pool=d,y.child1=y.child2=y.parent=null,y.next=null,y.snext=null,y.mnext=null,y.next=Se.zpp_pool,Se.zpp_pool=y;let _=u;for(;_!=null;){if(_.child1==null||_.height<2)_=_;else{let v=_.child1,w=_.child2,O=w.height-v.height;if(O>1){let E=w.child1,M=w.child2;if(w.child1=_,w.parent=_.parent,_.parent=w,w.parent!=null?w.parent.child1==_?w.parent.child1=w:w.parent.child2=w:c.root=w,E.height>M.height){w.child2=E,_.child2=M,M.parent=_;let N=_.aabb,Z=v.aabb,S=M.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=w.aabb,D=_.aabb,T=E.aabb;V.minx=D.minx<T.minx?D.minx:T.minx,V.miny=D.miny<T.miny?D.miny:T.miny,V.maxx=D.maxx>T.maxx?D.maxx:T.maxx,V.maxy=D.maxy>T.maxy?D.maxy:T.maxy;let G=v.height,q=M.height;_.height=1+(G>q?G:q);let R=_.height,j=E.height;w.height=1+(R>j?R:j)}else{w.child2=M,_.child2=E,E.parent=_;let N=_.aabb,Z=v.aabb,S=E.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=w.aabb,D=_.aabb,T=M.aabb;V.minx=D.minx<T.minx?D.minx:T.minx,V.miny=D.miny<T.miny?D.miny:T.miny,V.maxx=D.maxx>T.maxx?D.maxx:T.maxx,V.maxy=D.maxy>T.maxy?D.maxy:T.maxy;let G=v.height,q=E.height;_.height=1+(G>q?G:q);let R=_.height,j=M.height;w.height=1+(R>j?R:j)}_=w}else if(O<-1){let E=v.child1,M=v.child2;if(v.child1=_,v.parent=_.parent,_.parent=v,v.parent!=null?v.parent.child1==_?v.parent.child1=v:v.parent.child2=v:c.root=v,E.height>M.height){v.child2=E,_.child1=M,M.parent=_;let N=_.aabb,Z=w.aabb,S=M.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=v.aabb,D=_.aabb,T=E.aabb;V.minx=D.minx<T.minx?D.minx:T.minx,V.miny=D.miny<T.miny?D.miny:T.miny,V.maxx=D.maxx>T.maxx?D.maxx:T.maxx,V.maxy=D.maxy>T.maxy?D.maxy:T.maxy;let G=w.height,q=M.height;_.height=1+(G>q?G:q);let R=_.height,j=E.height;v.height=1+(R>j?R:j)}else{v.child2=M,_.child1=E,E.parent=_;let N=_.aabb,Z=w.aabb,S=E.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=v.aabb,D=_.aabb,T=M.aabb;V.minx=D.minx<T.minx?D.minx:T.minx,V.miny=D.miny<T.miny?D.miny:T.miny,V.maxx=D.maxx>T.maxx?D.maxx:T.maxx,V.maxy=D.maxy>T.maxy?D.maxy:T.maxy;let G=w.height,q=E.height;_.height=1+(G>q?G:q);let R=_.height,j=M.height;v.height=1+(R>j?R:j)}_=v}else _=_}let f=_.child1,z=_.child2,P=_.aabb,k=f.aabb,m=z.aabb;P.minx=k.minx<m.minx?k.minx:m.minx,P.miny=k.miny<m.miny?k.miny:m.miny,P.maxx=k.maxx>m.maxx?k.maxx:m.maxx,P.maxy=k.maxy>m.maxy?k.maxy:m.maxy;let b=f.height,C=z.height;_.height=1+(b>C?b:C),_=_.parent}}else{c.root=x,x.parent=null;let y=h;y.height=-1;let d=y.aabb;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d.wrap_min=d.wrap_max=null,d._invalidate=null,d._validate=null,d.next=be.zpp_pool,be.zpp_pool=d,y.child1=y.child2=y.parent=null,y.next=null,y.snext=null,y.mnext=null,y.next=Se.zpp_pool,Se.zpp_pool=y}}}let a=s.aabb;if(!t.continuous&&r.zip_aabb&&r.body!=null)if(r.zip_aabb=!1,r.type==0){let c=r.circle;if(c.zip_worldCOM&&c.body!=null){if(c.zip_worldCOM=!1,c.zip_localCOM){if(c.zip_localCOM=!1,c.type==1){let y=c.polygon;if(y.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(y.lverts.next.next==null)y.localCOMx=y.lverts.next.x,y.localCOMy=y.lverts.next.y;else if(y.lverts.next.next.next==null){y.localCOMx=y.lverts.next.x,y.localCOMy=y.lverts.next.y;let d=1;y.localCOMx+=y.lverts.next.next.x*d,y.localCOMy+=y.lverts.next.next.y*d;let _=.5;y.localCOMx*=_,y.localCOMy*=_}else{y.localCOMx=0,y.localCOMy=0;let d=0,_=y.lverts.next,f=_;_=_.next;let z=_;for(_=_.next;_!=null;){let v=_;d+=z.x*(v.y-f.y);let w=v.y*z.x-v.x*z.y;y.localCOMx+=(z.x+v.x)*w,y.localCOMy+=(z.y+v.y)*w,f=z,z=v,_=_.next}_=y.lverts.next;let P=_;d+=z.x*(P.y-f.y);let k=P.y*z.x-P.x*z.y;y.localCOMx+=(z.x+P.x)*k,y.localCOMy+=(z.y+P.y)*k,f=z,z=P,_=_.next;let m=_;d+=z.x*(m.y-f.y);let b=m.y*z.x-m.x*z.y;y.localCOMx+=(z.x+m.x)*b,y.localCOMy+=(z.y+m.y)*b,d=1/(3*d);let C=d;y.localCOMx*=C,y.localCOMy*=C}}c.wrap_localCOM!=null&&(c.wrap_localCOM.zpp_inner.x=c.localCOMx,c.wrap_localCOM.zpp_inner.y=c.localCOMy)}let x=c.body;x.zip_axis&&(x.zip_axis=!1,x.axisx=Math.sin(x.rot),x.axisy=Math.cos(x.rot)),c.worldCOMx=c.body.posx+(c.body.axisy*c.localCOMx-c.body.axisx*c.localCOMy),c.worldCOMy=c.body.posy+(c.localCOMx*c.body.axisx+c.localCOMy*c.body.axisy)}let h=c.radius,u=c.radius;c.aabb.minx=c.worldCOMx-h,c.aabb.miny=c.worldCOMy-u,c.aabb.maxx=c.worldCOMx+h,c.aabb.maxy=c.worldCOMy+u}else{let c=r.polygon;if(c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let x=c.body;x.zip_axis&&(x.zip_axis=!1,x.axisx=Math.sin(x.rot),x.axisy=Math.cos(x.rot));let y=c.lverts.next,d=c.gverts.next;for(;d!=null;){let _=d,f=y;y=y.next,_.x=c.body.posx+(c.body.axisy*f.x-c.body.axisx*f.y),_.y=c.body.posy+(f.x*c.body.axisx+f.y*c.body.axisy),d=d.next}}if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let h=c.gverts.next;c.aabb.minx=h.x,c.aabb.miny=h.y,c.aabb.maxx=h.x,c.aabb.maxy=h.y;let u=c.gverts.next.next;for(;u!=null;){let x=u;x.x<c.aabb.minx&&(c.aabb.minx=x.x),x.x>c.aabb.maxx&&(c.aabb.maxx=x.x),x.y<c.aabb.miny&&(c.aabb.miny=x.y),x.y>c.aabb.maxy&&(c.aabb.maxy=x.y),u=u.next}}let o=r.aabb;a.minx=o.minx-3,a.miny=o.miny-3,a.maxx=o.maxx+3,a.maxy=o.maxy+3;let p=(s.dyn=r.body.type==1?!1:!r.body.component.sleeping)?this.dtree:this.stree;if(p.root==null)p.root=s,p.root.parent=null;else{let c=s.aabb,h=p.root;for(;h.child1!=null;){let f=h.child1,z=h.child2,P=h.aabb,k=(P.maxx-P.minx+(P.maxy-P.miny))*2,m=$e.tmpaabb,b=h.aabb;m.minx=b.minx<c.minx?b.minx:c.minx,m.miny=b.miny<c.miny?b.miny:c.miny,m.maxx=b.maxx>c.maxx?b.maxx:c.maxx,m.maxy=b.maxy>c.maxy?b.maxy:c.maxy;let C=$e.tmpaabb,v=(C.maxx-C.minx+(C.maxy-C.miny))*2,w=2*v,O=2*(v-k),E=$e.tmpaabb,M=f.aabb;E.minx=c.minx<M.minx?c.minx:M.minx,E.miny=c.miny<M.miny?c.miny:M.miny,E.maxx=c.maxx>M.maxx?c.maxx:M.maxx,E.maxy=c.maxy>M.maxy?c.maxy:M.maxy;let N;if(f.child1==null){let D=$e.tmpaabb;N=(D.maxx-D.minx+(D.maxy-D.miny))*2+O}else{let D=f.aabb,T=(D.maxx-D.minx+(D.maxy-D.miny))*2,G=$e.tmpaabb;N=(G.maxx-G.minx+(G.maxy-G.miny))*2-T+O}let Z=$e.tmpaabb,S=z.aabb;Z.minx=c.minx<S.minx?c.minx:S.minx,Z.miny=c.miny<S.miny?c.miny:S.miny,Z.maxx=c.maxx>S.maxx?c.maxx:S.maxx,Z.maxy=c.maxy>S.maxy?c.maxy:S.maxy;let V;if(z.child1==null){let D=$e.tmpaabb;V=(D.maxx-D.minx+(D.maxy-D.miny))*2+O}else{let D=z.aabb,T=(D.maxx-D.minx+(D.maxy-D.miny))*2,G=$e.tmpaabb;V=(G.maxx-G.minx+(G.maxy-G.miny))*2-T+O}if(w<N&&w<V)break;h=N<V?f:z}let u=h,x=u.parent,y;Se.zpp_pool==null?y=new Se:(y=Se.zpp_pool,Se.zpp_pool=y.next,y.next=null),be.zpp_pool==null?y.aabb=new be:(y.aabb=be.zpp_pool,be.zpp_pool=y.aabb.next,y.aabb.next=null),y.moved=!1,y.synced=!1,y.first_sync=!1,y.parent=x;let d=y.aabb,_=u.aabb;for(d.minx=c.minx<_.minx?c.minx:_.minx,d.miny=c.miny<_.miny?c.miny:_.miny,d.maxx=c.maxx>_.maxx?c.maxx:_.maxx,d.maxy=c.maxy>_.maxy?c.maxy:_.maxy,y.height=u.height+1,x!=null?(x.child1==u?x.child1=y:x.child2=y,y.child1=u,y.child2=s,u.parent=y,s.parent=y):(y.child1=u,y.child2=s,u.parent=y,s.parent=y,p.root=y),h=s.parent;h!=null;){if(h.child1==null||h.height<2)h=h;else{let v=h.child1,w=h.child2,O=w.height-v.height;if(O>1){let E=w.child1,M=w.child2;if(w.child1=h,w.parent=h.parent,h.parent=w,w.parent!=null?w.parent.child1==h?w.parent.child1=w:w.parent.child2=w:p.root=w,E.height>M.height){w.child2=E,h.child2=M,M.parent=h;let N=h.aabb,Z=v.aabb,S=M.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=w.aabb,D=h.aabb,T=E.aabb;V.minx=D.minx<T.minx?D.minx:T.minx,V.miny=D.miny<T.miny?D.miny:T.miny,V.maxx=D.maxx>T.maxx?D.maxx:T.maxx,V.maxy=D.maxy>T.maxy?D.maxy:T.maxy;let G=v.height,q=M.height;h.height=1+(G>q?G:q);let R=h.height,j=E.height;w.height=1+(R>j?R:j)}else{w.child2=M,h.child2=E,E.parent=h;let N=h.aabb,Z=v.aabb,S=E.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=w.aabb,D=h.aabb,T=M.aabb;V.minx=D.minx<T.minx?D.minx:T.minx,V.miny=D.miny<T.miny?D.miny:T.miny,V.maxx=D.maxx>T.maxx?D.maxx:T.maxx,V.maxy=D.maxy>T.maxy?D.maxy:T.maxy;let G=v.height,q=E.height;h.height=1+(G>q?G:q);let R=h.height,j=M.height;w.height=1+(R>j?R:j)}h=w}else if(O<-1){let E=v.child1,M=v.child2;if(v.child1=h,v.parent=h.parent,h.parent=v,v.parent!=null?v.parent.child1==h?v.parent.child1=v:v.parent.child2=v:p.root=v,E.height>M.height){v.child2=E,h.child1=M,M.parent=h;let N=h.aabb,Z=w.aabb,S=M.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=v.aabb,D=h.aabb,T=E.aabb;V.minx=D.minx<T.minx?D.minx:T.minx,V.miny=D.miny<T.miny?D.miny:T.miny,V.maxx=D.maxx>T.maxx?D.maxx:T.maxx,V.maxy=D.maxy>T.maxy?D.maxy:T.maxy;let G=w.height,q=M.height;h.height=1+(G>q?G:q);let R=h.height,j=E.height;v.height=1+(R>j?R:j)}else{v.child2=M,h.child1=E,E.parent=h;let N=h.aabb,Z=w.aabb,S=E.aabb;N.minx=Z.minx<S.minx?Z.minx:S.minx,N.miny=Z.miny<S.miny?Z.miny:S.miny,N.maxx=Z.maxx>S.maxx?Z.maxx:S.maxx,N.maxy=Z.maxy>S.maxy?Z.maxy:S.maxy;let V=v.aabb,D=h.aabb,T=M.aabb;V.minx=D.minx<T.minx?D.minx:T.minx,V.miny=D.miny<T.miny?D.miny:T.miny,V.maxx=D.maxx>T.maxx?D.maxx:T.maxx,V.maxy=D.maxy>T.maxy?D.maxy:T.maxy;let G=w.height,q=E.height;h.height=1+(G>q?G:q);let R=h.height,j=M.height;v.height=1+(R>j?R:j)}h=v}else h=h}let f=h.child1,z=h.child2,P=f.height,k=z.height;h.height=1+(P>k?P:k);let m=h.aabb,b=f.aabb,C=z.aabb;m.minx=b.minx<C.minx?b.minx:C.minx,m.miny=b.miny<C.miny?b.miny:C.miny,m.maxx=b.maxx>C.maxx?b.maxx:C.maxx,m.maxy=b.maxy>C.maxy?b.maxy:C.maxy,h=h.parent}}s.synced=!1,s=s.snext}for(;this.syncs!=null;){let r=this.syncs;this.syncs=r.snext,r.snext=null;let a=r;if(a.moved)continue;a.moved=!1;let o=a.shape;if(o.body.component.sleeping)continue;let c=a.aabb,h=null;for(this.dtree.root!=null&&(this.dtree.root.next=h,h=this.dtree.root);h!=null;){let u=h;h=u.next,u.next=null;let x=u;if(x!=a)if(x.child1==null){let y=x.shape;if(y.body!=o.body&&!(y.body.type==1&&o.body.type==1)){let d=x.aabb;if(d.miny<=c.maxy&&c.miny<=d.maxy&&d.minx<=c.maxx&&c.minx<=d.maxx){let _,f;o.id<y.id?(_=o.id,f=y.id):(_=y.id,f=o.id);let z=o.pairs.length<y.pairs.length?o:y,P=null,k=z.pairs.head;for(;k!=null;){let E=k.elt;if(E.id==_&&E.di==f){P=E;break}k=k.next}if(P!=null){P.sleeping&&(P.sleeping=!1,P.next=this.pairs,this.pairs=P,P.first=!0);continue}tt.zpp_pool==null?P=new tt:(P=tt.zpp_pool,tt.zpp_pool=P.next,P.next=null),P.n1=a,P.n2=x,P.id=_,P.di=f,P.next=this.pairs,this.pairs=P,P.first=!0;let m=o.pairs,b;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?b=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(b=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b.next,b.next=null),b.elt=P;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=y.pairs,w;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(w=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=P;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++}}}else{let y=x.aabb;y.miny<=c.maxy&&c.miny<=y.maxy&&y.minx<=c.maxx&&c.minx<=y.maxx&&(x.child1!=null&&(x.child1.next=h,h=x.child1),x.child2!=null&&(x.child2.next=h,h=x.child2))}}for(this.stree.root!=null&&(this.stree.root.next=h,h=this.stree.root);h!=null;){let u=h;h=u.next,u.next=null;let x=u;if(x!=a)if(x.child1==null){let y=x.shape;if(y.body!=o.body&&!(y.body.type==1&&o.body.type==1)){let d=x.aabb;if(d.miny<=c.maxy&&c.miny<=d.maxy&&d.minx<=c.maxx&&c.minx<=d.maxx){let _,f;o.id<y.id?(_=o.id,f=y.id):(_=y.id,f=o.id);let z=o.pairs.length<y.pairs.length?o:y,P=null,k=z.pairs.head;for(;k!=null;){let E=k.elt;if(E.id==_&&E.di==f){P=E;break}k=k.next}if(P!=null){P.sleeping&&(P.sleeping=!1,P.next=this.pairs,this.pairs=P,P.first=!0);continue}tt.zpp_pool==null?P=new tt:(P=tt.zpp_pool,tt.zpp_pool=P.next,P.next=null),P.n1=a,P.n2=x,P.id=_,P.di=f,P.next=this.pairs,this.pairs=P,P.first=!0;let m=o.pairs,b;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?b=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(b=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b.next,b.next=null),b.elt=P;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=y.pairs,w;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(w=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=P;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++}}}else{let y=x.aabb;y.miny<=c.maxy&&c.miny<=y.maxy&&y.minx<=c.maxx&&c.minx<=y.maxx&&(x.child1!=null&&(x.child1.next=h,h=x.child1),x.child2!=null&&(x.child2.next=h,h=x.child2))}}}for(;this.moves!=null;){let r=this.moves;this.moves=r.mnext,r.mnext=null;let a=r;a.moved=!1;let o=a.shape;if(o.body.component.sleeping)continue;let c=a.aabb,h=null;for(this.dtree.root!=null&&(this.dtree.root.next=h,h=this.dtree.root);h!=null;){let u=h;h=u.next,u.next=null;let x=u;if(x!=a)if(x.child1==null){let y=x.shape;if(y.body!=o.body&&!(y.body.type==1&&o.body.type==1)){let d=x.aabb;if(d.miny<=c.maxy&&c.miny<=d.maxy&&d.minx<=c.maxx&&c.minx<=d.maxx){let _,f;o.id<y.id?(_=o.id,f=y.id):(_=y.id,f=o.id);let z=o.pairs.length<y.pairs.length?o:y,P=null,k=z.pairs.head;for(;k!=null;){let E=k.elt;if(E.id==_&&E.di==f){P=E;break}k=k.next}if(P!=null){P.sleeping&&(P.sleeping=!1,P.next=this.pairs,this.pairs=P,P.first=!0);continue}tt.zpp_pool==null?P=new tt:(P=tt.zpp_pool,tt.zpp_pool=P.next,P.next=null),P.n1=a,P.n2=x,P.id=_,P.di=f,P.next=this.pairs,this.pairs=P,P.first=!0;let m=o.pairs,b;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?b=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(b=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b.next,b.next=null),b.elt=P;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=y.pairs,w;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(w=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=P;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++}}}else{let y=x.aabb;y.miny<=c.maxy&&c.miny<=y.maxy&&y.minx<=c.maxx&&c.minx<=y.maxx&&(x.child1!=null&&(x.child1.next=h,h=x.child1),x.child2!=null&&(x.child2.next=h,h=x.child2))}}for(this.stree.root!=null&&(this.stree.root.next=h,h=this.stree.root);h!=null;){let u=h;h=u.next,u.next=null;let x=u;if(x!=a)if(x.child1==null){let y=x.shape;if(y.body!=o.body&&!(y.body.type==1&&o.body.type==1)){let d=x.aabb;if(d.miny<=c.maxy&&c.miny<=d.maxy&&d.minx<=c.maxx&&c.minx<=d.maxx){let _,f;o.id<y.id?(_=o.id,f=y.id):(_=y.id,f=o.id);let z=o.pairs.length<y.pairs.length?o:y,P=null,k=z.pairs.head;for(;k!=null;){let E=k.elt;if(E.id==_&&E.di==f){P=E;break}k=k.next}if(P!=null){P.sleeping&&(P.sleeping=!1,P.next=this.pairs,this.pairs=P,P.first=!0);continue}tt.zpp_pool==null?P=new tt:(P=tt.zpp_pool,tt.zpp_pool=P.next,P.next=null),P.n1=a,P.n2=x,P.id=_,P.di=f,P.next=this.pairs,this.pairs=P,P.first=!0;let m=o.pairs,b;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?b=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(b=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b.next,b.next=null),b.elt=P;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=y.pairs,w;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(w=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=P;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++}}}else{let y=x.aabb;y.miny<=c.maxy&&c.miny<=y.maxy&&y.minx<=c.maxx&&c.minx<=y.maxx&&(x.child1!=null&&(x.child1.next=h,h=x.child1),x.child2!=null&&(x.child2.next=h,h=x.child2))}}}let i=null,l=this.pairs;for(;l!=null;){let r;if(l.first)r=!1;else{let x=l.n1.aabb,y=l.n2.aabb;r=!(y.miny<=x.maxy&&x.miny<=y.maxy&&y.minx<=x.maxx&&x.minx<=y.maxx)}if(r){i==null?this.pairs=l.next:i.next=l.next;let x=l.n1.shape.pairs,y=null,d=x.head,_=!1;for(;d!=null;){if(d.elt==l){let C,v;y==null?(C=x.head,v=C.next,x.head=v,x.head==null&&(x.pushmod=!0)):(C=y.next,v=C.next,y.next=v,v==null&&(x.pushmod=!0));let w=C;w.elt=null,w.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w,x.modified=!0,x.length--,x.pushmod=!0,_=!0;break}y=d,d=d.next}let f=l.n2.shape.pairs,z=null,P=f.head,k=!1;for(;P!=null;){if(P.elt==l){let C,v;z==null?(C=f.head,v=C.next,f.head=v,f.head==null&&(f.pushmod=!0)):(C=z.next,v=C.next,z.next=v,v==null&&(f.pushmod=!0));let w=C;w.elt=null,w.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w,f.modified=!0,f.length--,f.pushmod=!0,k=!0;break}z=P,P=P.next}let m=l.next;l.arb!=null&&(l.arb.pair=null),l.arb=null;let b=l;b.n1=b.n2=null,b.sleeping=!1,b.next=tt.zpp_pool,tt.zpp_pool=b,l=m;continue}let a=l.n1.shape,o=a.body,p=l.n2.shape,c=p.body;if(!l.first&&(o.component.sleeping||o.type==1)&&(c.component.sleeping||c.type==1)){l.sleeping=!0,i==null?this.pairs=l.next:i.next=l.next,l=l.next;continue}l.first=!1;let h=a.aabb,u=p.aabb;if(u.miny<=h.maxy&&h.miny<=u.maxy&&u.minx<=h.maxx&&h.minx<=u.maxx){let x=l.arb;n?l.arb=t.narrowPhase(a,p,o.type!=2||c.type!=2,l.arb,!1):l.arb=t.continuousEvent(a,p,o.type!=2||c.type!=2,l.arb,!1),l.arb==null?x!=null&&(x.pair=null):l.arb.pair=l}i=l,l=l.next}}clear(){for(;this.syncs!=null;){let t=this.syncs.snext;this.syncs.snext=null,this.syncs.first_sync&&(this.syncs.shape.node=null,this.syncs.shape.removedFromSpace(),this.syncs.shape=null),this.syncs=t}for(;this.moves!=null;){let t=this.moves.mnext;this.moves.mnext=null,this.moves.first_sync&&(this.moves.shape.node=null,this.moves.shape.removedFromSpace(),this.moves.shape=null),this.moves=t}for(;this.pairs!=null;){let t=this.pairs.next;this.pairs.arb!=null&&(this.pairs.arb.pair=null),this.pairs.arb=null;let n=this.pairs.n1.shape.pairs,s=this.pairs,i=null,l=n.head,r=!1;for(;l!=null;){if(l.elt==s){let x,y;i==null?(x=n.head,y=x.next,n.head=y,n.head==null&&(n.pushmod=!0)):(x=i.next,y=x.next,i.next=y,y==null&&(n.pushmod=!0));let d=x;d.elt=null,d.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d,n.modified=!0,n.length--,n.pushmod=!0,r=!0;break}i=l,l=l.next}let a=this.pairs.n2.shape.pairs,o=this.pairs,p=null,c=a.head,h=!1;for(;c!=null;){if(c.elt==o){let x,y;p==null?(x=a.head,y=x.next,a.head=y,a.head==null&&(a.pushmod=!0)):(x=p.next,y=x.next,p.next=y,y==null&&(a.pushmod=!0));let d=x;d.elt=null,d.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d,a.modified=!0,a.length--,a.pushmod=!0,h=!0;break}p=c,c=c.next}let u=this.pairs;u.n1=u.n2=null,u.sleeping=!1,u.next=tt.zpp_pool,tt.zpp_pool=u,this.pairs=t}this.dtree.clear(),this.stree.clear()}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let r=l,a=i??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h;if(s!=null){let u=p.shape.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.shape.type==0?Ee.circleContains(p.shape.circle,r)&&a.push(p.shape.outer):Ee.polyContains(p.shape.polygon,r)&&a.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h;if(s!=null){let u=p.shape.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.shape.type==0?Ee.circleContains(p.shape.circle,r)&&a.push(p.shape.outer):Ee.polyContains(p.shape.polygon,r)&&a.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let o=r;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=le.zpp_pool,le.zpp_pool=o,a}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let r=l,a=i??new fe._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!a.has(h)){let u;if(s!=null){let x=p.shape.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(p.shape.type==0?Ee.circleContains(p.shape.circle,r)&&a.push(h):Ee.polyContains(p.shape.polygon,r)&&a.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!a.has(h)){let u;if(s!=null){let x=p.shape.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(p.shape.type==0?Ee.circleContains(p.shape.circle,r)&&a.push(h):Ee.polyContains(p.shape.polygon,r)&&a.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let o=r;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=le.zpp_pool,le.zpp_pool=o,a}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,a=l??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),p=o.aabb;if(p.minx>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.maxy)if(o.child1==null){let c;if(i!=null){let h=o.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&a.push(o.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(o);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;h&&a.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=o.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(o.child1==null){let h;if(i!=null){let u=o.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n)if(s)Ee.containTest(this.aabbShape.zpp_inner,o.shape)&&a.push(o.shape.outer);else{let u=o.shape.aabb;(u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy||Ee.testCollide_safe(o.shape,this.aabbShape.zpp_inner))&&a.push(o.shape.outer)}else{let u;if(s){let x=o.shape.aabb;u=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy}else u=!0;u&&a.push(o.shape.outer)}}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),p=o.aabb;if(p.minx>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.maxy)if(o.child1==null){let c;if(i!=null){let h=o.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&a.push(o.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(o);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;h&&a.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=o.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(o.child1==null){let h;if(i!=null){let u=o.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n)if(s)Ee.containTest(this.aabbShape.zpp_inner,o.shape)&&a.push(o.shape.outer);else{let u=o.shape.aabb;(u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy||Ee.testCollide_safe(o.shape,this.aabbShape.zpp_inner))&&a.push(o.shape.outer)}else{let u;if(s){let x=o.shape.aabb;u=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy}else u=!0;u&&a.push(o.shape.outer)}}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}}return a}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,a=l??new fe._nape.phys.BodyList;if(this.failed==null&&(this.failed=new fe._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),p=o.aabb;if(p.minx>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.maxy)if(o.child1==null){let c;if(i!=null){let h=o.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=o.shape.body.outer;a.has(h)||a.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(o);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h){let u=c.shape.body.outer;a.has(u)||a.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=o.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(o.child1==null){let h=o.shape.body.outer,u;if(i!=null){let x=o.shape.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(h)){let x=Ee.containTest(this.aabbShape.zpp_inner,o.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ee.testCollide_safe(o.shape,this.aabbShape.zpp_inner)&&a.push(h);else if(s){if(!this.failed.has(h)){let x=o.shape.aabb,y=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy;!a.has(h)&&y?a.push(h):y||(a.remove(h),this.failed.push(h))}}else{let x;if(a.has(h))x=!1;else{let y=o.shape.aabb;x=y.minx>=r.minx&&y.miny>=r.miny&&y.maxx<=r.maxx&&y.maxy<=r.maxy}x&&a.push(h)}}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),p=o.aabb;if(p.minx>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.maxy)if(o.child1==null){let c;if(i!=null){let h=o.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=o.shape.body.outer;a.has(h)||a.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(o);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h){let u=c.shape.body.outer;a.has(u)||a.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=o.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(o.child1==null){let h=o.shape.body.outer,u;if(i!=null){let x=o.shape.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(h)){let x=Ee.containTest(this.aabbShape.zpp_inner,o.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ee.testCollide_safe(o.shape,this.aabbShape.zpp_inner)&&a.push(h);else if(s){if(!this.failed.has(h)){let x=o.shape.aabb,y=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy;!a.has(h)&&y?a.push(h):y||(a.remove(h),this.failed.push(h))}}else{let x;if(a.has(h))x=!1;else{let y=o.shape.aabb;x=y.minx>=r.minx&&y.miny>=r.miny&&y.maxx<=r.maxx&&y.maxy<=r.maxy}x&&a.push(h)}}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}}return this.failed.clear(),a}shapesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let a=this.circShape.zpp_inner.aabb,o=r??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.maxx)if(p.child1==null){let h;if(l!=null){let u=p.shape.filter;h=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(i?Ee.containTest(this.circShape.zpp_inner,p.shape)&&o.push(p.shape.outer):Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&o.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.maxx)if(p.child1==null){let h;if(l!=null){let u=p.shape.filter;h=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(i?Ee.containTest(this.circShape.zpp_inner,p.shape)&&o.push(p.shape.outer):Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&o.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return o}bodiesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let a=this.circShape.zpp_inner.aabb,o=r??new fe._nape.phys.BodyList;if(this.failed==null&&(this.failed=new fe._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.maxx)if(p.child1==null){let h=p.shape.body.outer,u;if(l!=null){let x=p.shape.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(i){if(!this.failed.has(h)){let x=Ee.containTest(this.circShape.zpp_inner,p.shape);!o.has(h)&&x?o.push(h):x||(o.remove(h),this.failed.push(h))}}else!o.has(h)&&Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&o.push(h)}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.maxx)if(p.child1==null){let h=p.shape.body.outer,u;if(l!=null){let x=p.shape.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(i){if(!this.failed.has(h)){let x=Ee.containTest(this.circShape.zpp_inner,p.shape);!o.has(h)&&x?o.push(h):x||(o.remove(h),this.failed.push(h))}}else!o.has(h)&&Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&o.push(h)}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return this.failed.clear(),o}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),o=a.aabb;if(l.miny<=o.maxy&&o.miny<=l.maxy&&l.minx<=o.maxx&&o.minx<=l.maxx)if(a.child1==null){let p;if(s!=null){let c=a.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ee.containTest(t,a.shape)&&r.push(a.shape.outer):Ee.testCollide_safe(a.shape,t)&&r.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),o=a.aabb;if(l.miny<=o.maxy&&o.miny<=l.maxy&&l.minx<=o.maxx&&o.minx<=l.maxx)if(a.child1==null){let p;if(s!=null){let c=a.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ee.containTest(t,a.shape)&&r.push(a.shape.outer):Ee.testCollide_safe(a.shape,t)&&r.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return r}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new fe._nape.phys.BodyList;if(this.failed==null&&(this.failed=new fe._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),o=a.aabb;if(l.miny<=o.maxy&&o.miny<=l.maxy&&l.minx<=o.maxx&&o.minx<=l.maxx)if(a.child1==null){let p=a.shape.body.outer,c;if(s!=null){let h=a.shape.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;if(c)if(n){if(!this.failed.has(p)){let h=Ee.containTest(t,a.shape);!r.has(p)&&h?r.push(p):h||(r.remove(p),this.failed.push(p))}}else!r.has(p)&&Ee.testCollide_safe(a.shape,t)&&r.push(p)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),o=a.aabb;if(l.miny<=o.maxy&&o.miny<=l.maxy&&l.minx<=o.maxx&&o.minx<=l.maxx)if(a.child1==null){let p=a.shape.body.outer,c;if(s!=null){let h=a.shape.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;if(c)if(n){if(!this.failed.has(p)){let h=Ee.containTest(t,a.shape);!r.has(p)&&h?r.push(p):h||(r.remove(p),this.failed.push(p))}}else!r.has(p)&&Ee.testCollide_safe(a.shape,t)&&r.push(p)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return this.failed.clear(),r}rayCast(t,n,s){this.openlist==null&&(this.openlist=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let i=t.maxdist;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb)){let r=t.aabbsect(this.dtree.root.aabb);if(r>=0&&r<i){this.dtree.root.rayt=r;let a=null,o=this.openlist.head;for(;o!=null;){let x=o.elt;if(this.dtree.root.rayt<x.rayt)break;a=o,o=o.next}let p=this.openlist,c=this.dtree.root,h;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(h=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;a==null?(u.next=p.head,p.head=u):(u.next=a.next,a.next=u),p.pushmod=p.modified=!0,p.length++}}if(this.stree.root!=null&&t.aabbtest(this.stree.root.aabb)){let r=t.aabbsect(this.stree.root.aabb);if(r>=0&&r<i){this.stree.root.rayt=r;let a=null,o=this.openlist.head;for(;o!=null;){let x=o.elt;if(this.stree.root.rayt<x.rayt)break;a=o,o=o.next}let p=this.openlist,c=this.stree.root,h;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(h=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;a==null?(u.next=p.head,p.head=u):(u.next=a.next,a.next=u),p.pushmod=p.modified=!0,p.length++}}let l=null;for(;this.openlist.head!=null;){let r=this.openlist.pop_unsafe();if(r.rayt>=i)break;if(r.child1==null){let a=r.shape,o;if(s!=null){let p=a.filter;o=(p.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&p.collisionGroup)!=0}else o=!0;if(o){let p=a.type==0?t.circlesect(a.circle,n,i):t.aabbtest(a.aabb)?t.polysect(a.polygon,n,i):null;if(p!=null){if(p.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(i=p.zpp_inner.toiDistance,l!=null){if(l.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");l.zpp_inner.free()}l=p}}}else{if(r.child1!=null&&t.aabbtest(r.child1.aabb)){let a=t.aabbsect(r.child1.aabb);if(a>=0&&a<i){r.child1.rayt=a;let o=null,p=this.openlist.head;for(;p!=null;){let y=p.elt;if(r.child1.rayt<y.rayt)break;o=p,p=p.next}let c=this.openlist,h=r.child1,u;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(u=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;o==null?(x.next=c.head,c.head=x):(x.next=o.next,o.next=x),c.pushmod=c.modified=!0,c.length++}}if(r.child2!=null&&t.aabbtest(r.child2.aabb)){let a=t.aabbsect(r.child2.aabb);if(a>=0&&a<i){r.child2.rayt=a;let o=null,p=this.openlist.head;for(;p!=null;){let y=p.elt;if(r.child2.rayt<y.rayt)break;o=p,p=p.next}let c=this.openlist,h=r.child2,u;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(u=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;o==null?(x.next=c.head,c.head=x):(x.next=o.next,o.next=x),c.pushmod=c.modified=!0,c.length++}}}}return this.openlist.clear(),l}rayMultiCast(t,n,s,i){this.openlist==null&&(this.openlist=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let l=t.maxdist>=1/0,r=i??new fe._nape.geom.RayResultList;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb))if(l)this.openlist.add(this.dtree.root);else{let a=t.aabbsect(this.dtree.root.aabb);a>=0&&a<t.maxdist&&this.openlist.add(this.dtree.root)}if(this.stree.root!=null&&t.aabbtest(this.stree.root.aabb))if(l)this.openlist.add(this.stree.root);else{let a=t.aabbsect(this.stree.root.aabb);a>=0&&a<t.maxdist&&this.openlist.add(this.stree.root)}for(;this.openlist.head!=null;){let a=this.openlist.pop_unsafe();if(a.child1==null){let o=a.shape,p;if(s!=null){let c=o.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(o.type==0?t.circlesect2(o.circle,n,r):t.aabbtest(o.aabb)&&t.polysect2(o.polygon,n,r))}else{if(a.child1!=null&&t.aabbtest(a.child1.aabb))if(l)this.openlist.add(a.child1);else{let o=t.aabbsect(a.child1.aabb);o>=0&&o<t.maxdist&&this.openlist.add(a.child1)}if(a.child2!=null&&t.aabbtest(a.child2.aabb))if(l)this.openlist.add(a.child2);else{let o=t.aabbsect(a.child2.aabb);o>=0&&o<t.maxdist&&this.openlist.add(a.child2)}}}return this.openlist.clear(),r}};fe._zpp=null,fe._nape=null,fe.FATTEN=3,fe.VEL_STEPS=2;var zs=fe;var Ds=class Ds{constructor(){this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.comps=null;this.sleep=!1;this.waket=0;this.comps=new Ds._zpp.util.ZNPList_ZPP_Component}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){}alloc(){this.waket=0}};Ds.zpp_pool=null,Ds._zpp=null;var ht=Ds;var Rs=class{constructor(){this.next=null;this.parent=this;this.rank=0;this.isBody=!1;this.body=null;this.constraint=null;this.island=null;this.sleeping=!1;this.waket=0;this.woken=!1;this._inuse=!1}free(){this.body=null,this.constraint=null}alloc(){}reset(){this.sleeping=!1,this.island=null,this.parent=this,this.rank=0}};Rs.zpp_pool=null;var Vn=class Vn{constructor(){this.id=0;this.di=0;this.int1=null;this.int2=null;this.arbiters=null;this.COLLISIONstate=null;this.COLLISIONstamp=null;this.SENSORstate=null;this.SENSORstamp=null;this.FLUIDstate=null;this.FLUIDstamp=null;this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.freed=!1;this.lazydel=!1;this.arbiters=new Vn._zpp.util.ZNPList_ZPP_Arbiter}static get(e,t){let n;return Vn.zpp_pool==null?n=new Vn:(n=Vn.zpp_pool,Vn.zpp_pool=n.next,n.next=null),n.freed=!1,n.lazydel=!1,n.COLLISIONstate=1,n.COLLISIONstamp=0,n.SENSORstate=1,n.SENSORstamp=0,n.FLUIDstate=1,n.FLUIDstamp=0,e.id<t.id?(n.int1=e,n.int2=t):(n.int1=t,n.int2=e),n.id=n.int1.id,n.di=n.int2.id,n}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){this.int1=this.int2=null,this.id=this.di=-1,this.freed=!0}alloc(){this.freed=!1,this.lazydel=!1,this.COLLISIONstate=1,this.COLLISIONstamp=0,this.SENSORstate=1,this.SENSORstamp=0,this.FLUIDstate=1,this.FLUIDstamp=0}add_arb(e){let t=!1,n=this.arbiters.head;for(;n!=null;){if(n.elt==e){t=!0;break}n=n.next}if(t)return!1;{let s=this.arbiters,i,l=Vn._zpp.util.ZNPNode_ZPP_Arbiter;l.zpp_pool==null?i=new l:(i=l.zpp_pool,l.zpp_pool=i.next,i.next=null),i.elt=e;let r=i;return r.next=s.head,s.head=r,s.modified=!0,s.length++,!0}}try_remove_arb(e){let t=this.arbiters,n=null,s=t.head,i=!1;for(;s!=null;){if(s.elt==e){let l,r;n==null?(l=t.head,r=l.next,t.head=r,t.head==null&&(t.pushmod=!0)):(l=n.next,r=l.next,n.next=r,r==null&&(t.pushmod=!0));let a=l;a.elt=null;let o=Vn._zpp.util.ZNPNode_ZPP_Arbiter;a.next=o.zpp_pool,o.zpp_pool=a,t.modified=!0,t.length--,t.pushmod=!0,i=!0;break}n=s,s=s.next}return i}remove_arb(e){let t=this.arbiters,n=null,s=t.head;for(;s!=null;){if(s.elt==e){let i,l;n==null?(i=t.head,l=i.next,t.head=l,t.head==null&&(t.pushmod=!0)):(i=n.next,l=i.next,n.next=l,l==null&&(t.pushmod=!0));let r=i;r.elt=null;let a=Vn._zpp.util.ZNPNode_ZPP_Arbiter;r.next=a.zpp_pool,a.zpp_pool=r,t.modified=!0,t.length--,t.pushmod=!0;break}n=s,s=s.next}}empty_arb(e){let t=!0,n=this.arbiters.head;for(;n!=null;)if((n.elt.type&e)==0){n=n.next;continue}else{t=!1;break}return t}really_empty(){return this.arbiters.head==null}sleeping(){let e=!0,t=this.arbiters.head;for(;t!=null;)if(t.elt.sleeping){t=t.next;continue}else{e=!1;break}return e}};Vn.zpp_pool=null,Vn._zpp=null;var qt=Vn;var ii=class ii{constructor(e){this.cbsets=null;this.space=null;let t=ii._zpp.util.ZPP_Set_ZPP_CbSet;t.zpp_pool==null?this.cbsets=new t:(this.cbsets=t.zpp_pool,t.zpp_pool=this.cbsets.next,this.cbsets.next=null),this.cbsets.lt=ii._zpp.callbacks.ZPP_CbSet.setlt,this.space=e}get(e){if(e.head==null)return null;let t=ii._zpp.callbacks.ZPP_CbSet,n;t.zpp_pool==null?n=new t:(n=t.zpp_pool,t.zpp_pool=n.next,n.next=null);let s=n.cbTypes;n.cbTypes=e;let i=this.cbsets.find_weak(n),l;if(i!=null)l=i.data;else{let a=t.get(e);this.cbsets.insert(a),a.manager=this,l=a}n.cbTypes=s;let r=n;for(r.listeners.clear(),r.zip_listeners=!0,r.bodylisteners.clear(),r.zip_bodylisteners=!0,r.conlisteners.clear(),r.zip_conlisteners=!0;r.cbTypes.head!=null;)r.cbTypes.pop_unsafe().cbsets.remove(r);return r.next=t.zpp_pool,t.zpp_pool=r,l}remove(e){let t=ii._zpp.callbacks.ZPP_CbSetPair;for(this.cbsets.remove(e);e.cbpairs.head!=null;){let n=e.cbpairs.pop_unsafe();n.a!=n.b&&(e==n.a?n.b.cbpairs.remove(n):n.a.cbpairs.remove(n));let s=n;s.a=s.b=null,s.listeners.clear(),s.next=t.zpp_pool,t.zpp_pool=s}e.manager=null}clear(){}validate(){if(!this.cbsets.empty()){let e=this.cbsets.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;)if(e.data.validate(),e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent}}}pair(e,t){let n=ii._zpp.callbacks.ZPP_CbSet,s=ii._zpp.callbacks.ZPP_CbSetPair,i=null,r=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;r!=null;){let a=r.elt;if(a.a==e&&a.b==t||a.a==t&&a.b==e){i=a;break}r=r.next}if(i==null){let a;s.zpp_pool==null?a=new s:(a=s.zpp_pool,s.zpp_pool=a.next,a.next=null),a.zip_listeners=!0,n.setlt(e,t)?(a.a=e,a.b=t):(a.a=t,a.b=e),i=a,e.cbpairs.add(i),t!=e&&t.cbpairs.add(i)}return i.zip_listeners&&(i.zip_listeners=!1,i.__validate()),i}valid_listener(e){return e.space==this.space}};ii._zpp=null;var Ji=ii;var B=class B{constructor(e,t){this.outer=null;this.userData=null;this.gravityx=null;this.gravityy=null;this.wrap_gravity=null;this.bodies=null;this.wrap_bodies=null;this.compounds=null;this.wrap_compounds=null;this.constraints=null;this.wrap_constraints=null;this.kinematics=null;this.bphase=null;this.__static=null;this.global_lin_drag=null;this.global_ang_drag=null;this.stamp=null;this.midstep=null;this.time=null;this.sortcontacts=null;this.c_arbiters_true=null;this.c_arbiters_false=null;this.f_arbiters=null;this.s_arbiters=null;this.wrap_arbiters=null;this.live=null;this.wrap_live=null;this.live_constraints=null;this.wrap_livecon=null;this.staticsleep=null;this.islands=null;this.listeners=null;this.wrap_listeners=null;this.callbacks=null;this.callbackset_list=null;this.cbsets=null;this.convexShapeList=null;this.pre_dt=null;this.toiEvents=null;this.continuous=null;this.precb=null;this.prelisteners=null;this.mrca1=null;this.mrca2=null;this.prelisteners=null,this.precb=null,this.continuous=!1,this.toiEvents=null,this.pre_dt=0,this.convexShapeList=null,this.cbsets=null,this.callbackset_list=null,this.callbacks=null,this.wrap_listeners=null,this.listeners=null,this.islands=null,this.staticsleep=null,this.wrap_livecon=null,this.live_constraints=null,this.wrap_live=null,this.live=null,this.wrap_arbiters=null,this.s_arbiters=null,this.f_arbiters=null,this.c_arbiters_false=null,this.c_arbiters_true=null,this.sortcontacts=!1,this.time=0,this.midstep=!1,this.stamp=0,this.global_ang_drag=0,this.global_lin_drag=0,this.__static=null,this.bphase=null,this.kinematics=null,this.wrap_constraints=null,this.constraints=null,this.wrap_compounds=null,this.compounds=null,this.wrap_bodies=null,this.bodies=null,this.wrap_gravity=null,this.gravityy=0,this.gravityx=0,this.userData=null,this.outer=null,this.toiEvents=new B._zpp.util.ZNPList_ZPP_ToiEvent,this.global_lin_drag=.015,this.global_ang_drag=.015,jt.internal=!0,this.precb=jt._createPreCb(),this.precb.zpp_inner=new jt,jt.internal=!1,this.sortcontacts=!0,this.pre_dt=0;let n;t!=null?(H.Broadphase_DYNAMIC_AABB_TREE==null&&(H.internal=!0,H.Broadphase_DYNAMIC_AABB_TREE=new B._nape.space.Broadphase,H.internal=!1),n=t==H.Broadphase_DYNAMIC_AABB_TREE):n=!0,n?this.bphase=new B._zpp.space.ZPP_DynAABBPhase(this):(H.Broadphase_SWEEP_AND_PRUNE==null&&(H.internal=!0,H.Broadphase_SWEEP_AND_PRUNE=new B._nape.space.Broadphase,H.internal=!1),t==H.Broadphase_SWEEP_AND_PRUNE&&(this.bphase=new B._zpp.space.ZPP_SweepPhase(this))),this.time=0;let s=this;e!=null?(this.gravityx=e.x,this.gravityy=e.y):(this.gravityx=0,this.gravityy=0),this.bodies=new B._zpp.util.ZNPList_ZPP_Body,this.wrap_bodies=B._zpp.util.ZPP_BodyList.get(this.bodies),this.wrap_bodies.zpp_inner.adder=i=>this.bodies_adder(i),this.wrap_bodies.zpp_inner.subber=i=>this.bodies_subber(i),this.wrap_bodies.zpp_inner._modifiable=()=>this.bodies_modifiable(),this.compounds=new B._zpp.util.ZNPList_ZPP_Compound,this.wrap_compounds=B._zpp.util.ZPP_CompoundList.get(this.compounds),this.wrap_compounds.zpp_inner.adder=i=>this.compounds_adder(i),this.wrap_compounds.zpp_inner.subber=i=>this.compounds_subber(i),this.wrap_compounds.zpp_inner._modifiable=()=>this.compounds_modifiable(),this.kinematics=new B._zpp.util.ZNPList_ZPP_Body,this.c_arbiters_true=new B._zpp.util.ZNPList_ZPP_ColArbiter,this.c_arbiters_false=new B._zpp.util.ZNPList_ZPP_ColArbiter,this.f_arbiters=new B._zpp.util.ZNPList_ZPP_FluidArbiter,this.s_arbiters=new B._zpp.util.ZNPList_ZPP_SensorArbiter,this.islands=new ht,this.live=new B._zpp.util.ZNPList_ZPP_Body,this.wrap_live=B._zpp.util.ZPP_BodyList.get(this.live,!0),this.staticsleep=new B._zpp.util.ZNPList_ZPP_Body,this.constraints=new B._zpp.util.ZNPList_ZPP_Constraint,this.wrap_constraints=B._zpp.util.ZPP_ConstraintList.get(this.constraints),this.wrap_constraints.zpp_inner.adder=i=>this.constraints_adder(i),this.wrap_constraints.zpp_inner.subber=i=>this.constraints_subber(i),this.wrap_constraints.zpp_inner._modifiable=()=>this.constraints_modifiable(),this.live_constraints=new B._zpp.util.ZNPList_ZPP_Constraint,this.wrap_livecon=B._zpp.util.ZPP_ConstraintList.get(this.live_constraints,!0),this.__static=vn.__static(),this.__static.zpp_inner.space=this,this.callbacks=new jt,this.midstep=!1,this.listeners=new B._zpp.util.ZNPList_ZPP_Listener,this.wrap_listeners=B._zpp.util.ZPP_ListenerList.get(this.listeners),this.wrap_listeners.zpp_inner.adder=i=>this.listeners_adder(i),this.wrap_listeners.zpp_inner.subber=i=>this.listeners_subber(i),this.wrap_listeners.zpp_inner._modifiable=()=>this.listeners_modifiable(),this.callbackset_list=new qt,this.mrca1=new B._zpp.util.ZNPList_ZPP_Interactor,this.mrca2=new B._zpp.util.ZNPList_ZPP_Interactor,this.prelisteners=new B._zpp.util.ZNPList_ZPP_InteractionListener,this.cbsets=new Ji(this)}getgravity(){let e=this.gravityx,t=this.gravityy;if(t==null&&(t=0),e==null&&(e=0),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(B._zpp.util.ZPP_PubPool.poolVec2==null?n=new B._nape.geom.Vec2:(n=B._zpp.util.ZPP_PubPool.poolVec2,B._zpp.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==B._zpp.util.ZPP_PubPool.nextVec2&&(B._zpp.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y==t}else i=!1;if(!i){n.zpp_inner.x=e,n.zpp_inner.y=t;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}n.zpp_inner.weak=!1,this.wrap_gravity=n,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=s=>this.gravity_invalidate(s),this.wrap_gravity.zpp_inner._validate=()=>this.gravity_validate()}gravity_invalidate(e){if(this.midstep)throw new Error("Error: Space::gravity cannot be set during space step");this.gravityx=e.x,this.gravityy=e.y;let t=new B._zpp.util.ZNPList_ZPP_Compound,n=this.bodies.head;for(;n!=null;){let l=n.elt;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!1)),n=n.next}let s=this.compounds.head;for(;s!=null;){let i=s.elt;t.add(i),s=s.next}for(;t.head!=null;){let i=t.pop_unsafe(),l=i.bodies.head;for(;l!=null;){let o=l.elt;o.world||(o.component.waket=this.stamp+(this.midstep?0:1),o.type==3&&(o.kinematicDelaySleep=!0),o.component.sleeping&&this.really_wake(o,!1)),l=l.next}let r=i.compounds.head;for(;r!=null;){let a=r.elt;t.add(a),r=r.next}}}gravity_validate(){this.wrap_gravity.zpp_inner.x=this.gravityx,this.wrap_gravity.zpp_inner.y=this.gravityy}clear(){for(;this.listeners.head!=null;){let t=this.listeners.pop_unsafe();this.remListener(t)}for(;this.callbackset_list.next!=null;){let t=this.callbackset_list.pop_unsafe();t.arbiters.clear();let n=t;n.int1=n.int2=null,n.id=n.di=-1,n.freed=!0,n.next=qt.zpp_pool,qt.zpp_pool=n}for(;this.c_arbiters_true.head!=null;){let t=this.c_arbiters_true.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,r=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=!0,s.length--,s.pushmod=!0,r=!0;break}i=l,l=l.next}let a=t.b2.arbiters,o=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;o==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=o.next,u=h.next,o.next=u,u==null&&(a.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}o=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;let r=t.innards,a=r.next;r.next=a.next,a._inuse=!1,r.next==null&&(r.pushmod=!0),r.modified=!0,r.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=pt.zpp_pool,pt.zpp_pool=n,t.pre_dt=-1}for(;this.c_arbiters_false.head!=null;){let t=this.c_arbiters_false.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,r=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=!0,s.length--,s.pushmod=!0,r=!0;break}i=l,l=l.next}let a=t.b2.arbiters,o=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;o==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=o.next,u=h.next,o.next=u,u==null&&(a.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}o=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;let r=t.innards,a=r.next;r.next=a.next,a._inuse=!1,r.next==null&&(r.pushmod=!0),r.modified=!0,r.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=pt.zpp_pool,pt.zpp_pool=n,t.pre_dt=-1}for(;this.s_arbiters.head!=null;){let t=this.s_arbiters.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,r=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=!0,s.length--,s.pushmod=!0,r=!0;break}i=l,l=l.next}let a=t.b2.arbiters,o=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;o==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=o.next,u=h.next,o.next=u,u==null&&(a.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}o=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}t.b1=t.b2=null,t.active=!1,t.intchange=!1;let n=t;n.next=Nt.zpp_pool,Nt.zpp_pool=n}for(;this.f_arbiters.head!=null;){let t=this.f_arbiters.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,r=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=!0,s.length--,s.pushmod=!0,r=!0;break}i=l,l=l.next}let a=t.b2.arbiters,o=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;o==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=o.next,u=h.next,o.next=u,u==null&&(a.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}o=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}t.b1=t.b2=null,t.active=!1,t.intchange=!1;let n=t;n.next=zt.zpp_pool,zt.zpp_pool=n,t.pre_dt=-1}for(this.bphase.clear();this.bodies.head!=null;){let t=this.bodies.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let i=n.comps.pop_unsafe();i.sleeping=!1,i.island=null,i.parent=i,i.rank=0}let s=n;s.next=ht.zpp_pool,ht.zpp_pool=s}}t.removedFromSpace(),t.space=null}for(;this.constraints.head!=null;){let t=this.constraints.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let i=n.comps.pop_unsafe();i.sleeping=!1,i.island=null,i.parent=i,i.rank=0}let s=n;s.next=ht.zpp_pool,ht.zpp_pool=s}}t.removedFromSpace(),t.space=null}this.kinematics.clear();let e=new B._zpp.util.ZNPList_ZPP_Compound;for(;this.compounds.head!=null;){let t=this.compounds.pop_unsafe();e.add(t)}for(;e.head!=null;){let t=e.pop_unsafe();t.removedFromSpace(),t.space=null;let n=t.bodies.head;for(;n!=null;){let l=n.elt;if(l.component!=null){let r=l.component.island;if(r!=null){for(;r.comps.head!=null;){let o=r.comps.pop_unsafe();o.sleeping=!1,o.island=null,o.parent=o,o.rank=0}let a=r;a.next=ht.zpp_pool,ht.zpp_pool=a}}l.removedFromSpace(),l.space=null,n=n.next}let s=t.constraints.head;for(;s!=null;){let l=s.elt;if(l.component!=null){let r=l.component.island;if(r!=null){for(;r.comps.head!=null;){let o=r.comps.pop_unsafe();o.sleeping=!1,o.island=null,o.parent=o,o.rank=0}let a=r;a.next=ht.zpp_pool,ht.zpp_pool=a}}l.removedFromSpace(),l.space=null,s=s.next}let i=t.compounds.head;for(;i!=null;){let l=i.elt;e.add(l),i=i.next}}this.staticsleep.clear(),this.live.clear(),this.live_constraints.clear(),this.stamp=0,this.time=0,this.mrca1.clear(),this.mrca2.clear(),this.prelisteners.clear(),this.cbsets.clear()}bodies_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_bodies.remove(e),this.addBody(e.zpp_inner),!0):!1}bodies_subber(e){this.remBody(e.zpp_inner)}bodies_modifiable(){if(this.midstep)throw new Error("Error: Space::bodies cannot be set during space step()")}compounds_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.wrap_compounds.remove(e),this.addCompound(e.zpp_inner),!0):!1}compounds_subber(e){this.remCompound(e.zpp_inner)}compounds_modifiable(){if(this.midstep)throw new Error("Error: Space::compounds cannot be set during space step()")}constraints_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_constraints.remove(e),this.addConstraint(e.zpp_inner),!0):!1}constraints_subber(e){this.remConstraint(e.zpp_inner)}constraints_modifiable(){if(this.midstep)throw new Error("Error: Space::constraints cannot be set during space step()")}listeners_adder(e){return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_listeners.remove(e),this.addListener(e.zpp_inner),!0):!1}listeners_subber(e){this.remListener(e.zpp_inner)}listeners_modifiable(){if(this.midstep)throw new Error("Error: Space::listeners cannot be set during space step()")}revoke_listener(e){}unrevoke_listener(e){}addListener(e){e.space=this,e.addedToSpace();let t=e.interaction!=null}remListener(e){let t=e.interaction!=null;e.removedFromSpace(),e.space=null}add_callbackset(e){let t=e.int1.cbsets,n;B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?n=new B._zpp.util.ZNPNode_ZPP_CallbackSet:(n=B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=n.next,n.next=null),n.elt=e;let s=n;s.next=t.head,t.head=s,t.modified=!0,t.length++;let i=e.int2.cbsets,l;B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?l=new B._zpp.util.ZNPNode_ZPP_CallbackSet:(l=B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;r.next=i.head,i.head=r,i.modified=!0,i.length++;let a=this.callbackset_list;e._inuse=!0;let o=e;o.next=a.next,a.next=o,a.modified=!0,a.length++}remove_callbackset(e){e.lazydel=!0;let t=e.int1.cbsets,n=null,s=t.head,i=!1;for(;s!=null;){if(s.elt==e){let p,c;n==null?(p=t.head,c=p.next,t.head=c,t.head==null&&(t.pushmod=!0)):(p=n.next,c=p.next,n.next=c,c==null&&(t.pushmod=!0));let h=p;h.elt=null,h.next=B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=h,t.modified=!0,t.length--,t.pushmod=!0,i=!0;break}n=s,s=s.next}let l=e.int2.cbsets,r=null,a=l.head,o=!1;for(;a!=null;){if(a.elt==e){let p,c;r==null?(p=l.head,c=p.next,l.head=c,l.head==null&&(l.pushmod=!0)):(p=r.next,c=p.next,r.next=c,c==null&&(l.pushmod=!0));let h=p;h.elt=null,h.next=B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=h,l.modified=!0,l.length--,l.pushmod=!0,o=!0;break}r=a,a=a.next}}transmitType(e,t){let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!1)),e.type==2?this.live.remove(e):e.type==3?(this.kinematics.remove(e),this.staticsleep.remove(e)):e.type==1&&this.staticsleep.remove(e),e.type=t,e.type==3&&this.kinematics.add(e),e.type==1&&this.static_validation(e),e.component.sleeping=!0;let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0))}added_shape(e,t){if(t==null&&(t=!1),!t){let n=e.body;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!1))}this.bphase.insert(e),e.addedToSpace()}removed_shape(e,t){t==null&&(t=!1);let n=e.body;t||n.wake();let s=null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(l.ws1==e||l.ws2==e){if(l.present!=0){this.MRCA_chains(l.ws1,l.ws2);let a=this.mrca1.head;for(;a!=null;){let o=a.elt,p=this.mrca2.head;for(;p!=null;){let c=p.elt,h=o.cbSet,u=c.cbSet;h.validate(),u.validate();let x=h.manager,y=null,_=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;_!=null;){let C=_.elt;if(C.a==h&&C.b==u||C.a==u&&C.b==h){y=C;break}_=_.next}if(y==null){let C;Ne.zpp_pool==null?C=new Ne:(C=Ne.zpp_pool,Ne.zpp_pool=C.next,C.next=null),C.zip_listeners=!0,dt.setlt(h,u)?(C.a=h,C.b=u):(C.a=u,C.b=h),y=C,h.cbpairs.add(y),u!=h&&u.cbpairs.add(y)}if(y.zip_listeners&&(y.zip_listeners=!1,y.__validate()),y.listeners.head==null){p=p.next;continue}let f=B._zpp.phys.ZPP_Interactor.get(o,c);f.remove_arb(l),l.present--;let z=h.manager,P=null,m=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;m!=null;){let C=m.elt;if(C.a==h&&C.b==u||C.a==u&&C.b==h){P=C;break}m=m.next}if(P==null){let C;Ne.zpp_pool==null?C=new Ne:(C=Ne.zpp_pool,Ne.zpp_pool=C.next,C.next=null),C.zip_listeners=!0,dt.setlt(h,u)?(C.a=h,C.b=u):(C.a=u,C.b=h),P=C,h.cbpairs.add(P),u!=h&&u.cbpairs.add(P)}P.zip_listeners&&(P.zip_listeners=!1,P.__validate());let b=P.listeners.head;for(;b!=null;){let C=b.elt;if(C.event==1&&(C.itype&l.type)!=0&&f.empty_arb(C.itype)){let v=this.push_callback(C);v.event=1;let w=f.int1,O=f.int2,E,M=C.options1,N=w.cbTypes;if(M.nonemptyintersection(N,M.includes)&&!M.nonemptyintersection(N,M.excludes)){let Z=C.options2,S=O.cbTypes;E=Z.nonemptyintersection(S,Z.includes)&&!Z.nonemptyintersection(S,Z.excludes)}else E=!1;E?(v.int1=w,v.int2=O):(v.int1=O,v.int2=w),v.set=f}b=b.next}f.arbiters.head==null&&this.remove_callbackset(f),p=p.next}a=a.next}}if(l.b1!=n&&l.b1.type==2){let a=l.b1;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(l.b2!=n&&l.b2.type==2){let a=l.b2;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(l.cleared=!0,n==null||l.b2==n){let a=l.b1.arbiters,o=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;o==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=o.next,u=h.next,o.next=u,u==null&&(a.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}o=p,p=p.next}}if(n==null||l.b1==n){let a=l.b2.arbiters,o=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;o==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=o.next,u=h.next,o.next=u,u==null&&(a.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}o=p,p=p.next}}l.pair!=null&&(l.pair.arb=null,l.pair=null),l.active=!1,this.f_arbiters.modified=!0,i=n.arbiters.erase(s);continue}s=i,i=i.next}this.bphase.remove(e),e.removedFromSpace()}addConstraint(e){e.space=this,e.addedToSpace(),e.active&&(e.component.sleeping=!0,this.wake_constraint(e,!0))}remConstraint(e){e.active&&(this.wake_constraint(e,!0),this.live_constraints.remove(e)),e.removedFromSpace(),e.space=null}addCompound(e){e.space=this,e.addedToSpace();let t=e.bodies.head;for(;t!=null;){let i=t.elt;this.addBody(i),t=t.next}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.addConstraint(i),n=n.next}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.addCompound(i),s=s.next}}remCompound(e){let t=e.bodies.head;for(;t!=null;){let i=t.elt;this.remBody(i),t=t.next}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.remConstraint(i),n=n.next}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.remCompound(i),s=s.next}e.removedFromSpace(),e.space=null}addBody(e,t){t==null&&(t=-1),e.space=this,e.addedToSpace(),e.component.sleeping=!0;let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!0));let s=e.shapes.head;for(;s!=null;){let i=s.elt,l=!0;if(l==null&&(l=!1),!l){let r=i.body;r.world||(r.component.waket=this.stamp+(this.midstep?0:1),r.type==3&&(r.kinematicDelaySleep=!0),r.component.sleeping&&this.really_wake(r,!1))}this.bphase.insert(i),i.addedToSpace(),s=s.next}e.type==1?this.static_validation(e):e.type!=2&&t!=3&&this.kinematics.add(e)}remBody(e,t){if(t==null&&(t=-1),e.type==1){let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0)),this.staticsleep.remove(e)}else if(e.type==2){let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0)),this.live.remove(e)}else{t!=3&&this.kinematics.remove(e);let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0)),this.staticsleep.remove(e)}let n=e.shapes.head;for(;n!=null;){let s=n.elt;this.removed_shape(s,!0),n=n.next}e.removedFromSpace(),e.space=null}shapesUnderPoint(e,t,n,s){return this.bphase.shapesUnderPoint(e,t,n,s)}bodiesUnderPoint(e,t,n,s){return this.bphase.bodiesUnderPoint(e,t,n,s)}shapesInAABB(e,t,n,s,i){return this.bphase.shapesInAABB(e.zpp_inner,t,n,s,i)}bodiesInAABB(e,t,n,s,i){return this.bphase.bodiesInAABB(e.zpp_inner,t,n,s,i)}shapesInCircle(e,t,n,s,i){let l=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=e.zpp_inner;r._validate!=null&&r._validate();let a=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;return o._validate!=null&&o._validate(),l.shapesInCircle(a,e.zpp_inner.y,t,n,s,i)}bodiesInCircle(e,t,n,s,i){let l=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=e.zpp_inner;r._validate!=null&&r._validate();let a=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;return o._validate!=null&&o._validate(),l.bodiesInCircle(a,e.zpp_inner.y,t,n,s,i)}shapesInShape(e,t,n,s){return this.bphase.shapesInShape(e,t,n,s)}bodiesInShape(e,t,n,s){return this.bphase.bodiesInShape(e,t,n,s)}rayCast(e,t,n){return this.bphase.rayCast(e.zpp_inner,t,n==null?null:n.zpp_inner)}rayMultiCast(e,t,n,s){return this.bphase.rayMultiCast(e.zpp_inner,t,n==null?null:n.zpp_inner,s)}convexCast(e,t,n,s){let i;if(B._zpp.geom.ZPP_ToiEvent.zpp_pool==null?i=new B._zpp.geom.ZPP_ToiEvent:(i=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=i.next,i.next=null),i.failed=!1,i.s1=i.s2=null,i.arbiter=null,e.type==0){let V=e.circle;if(V.zip_worldCOM&&V.body!=null){if(V.zip_worldCOM=!1,V.zip_localCOM){if(V.zip_localCOM=!1,V.type==1){let T=V.polygon;if(T.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(T.lverts.next.next==null)T.localCOMx=T.lverts.next.x,T.localCOMy=T.lverts.next.y;else if(T.lverts.next.next.next==null){T.localCOMx=T.lverts.next.x,T.localCOMy=T.lverts.next.y;let G=1;T.localCOMx+=T.lverts.next.next.x*G,T.localCOMy+=T.lverts.next.next.y*G;let q=.5;T.localCOMx*=q,T.localCOMy*=q}else{T.localCOMx=0,T.localCOMy=0;let G=0,q=T.lverts.next,R=q;q=q.next;let j=q;for(q=q.next;q!=null;){let ee=q;G+=j.x*(ee.y-R.y);let J=ee.y*j.x-ee.x*j.y;T.localCOMx+=(j.x+ee.x)*J,T.localCOMy+=(j.y+ee.y)*J,R=j,j=ee,q=q.next}q=T.lverts.next;let A=q;G+=j.x*(A.y-R.y);let W=A.y*j.x-A.x*j.y;T.localCOMx+=(j.x+A.x)*W,T.localCOMy+=(j.y+A.y)*W,R=j,j=A,q=q.next;let Q=q;G+=j.x*(Q.y-R.y);let Y=Q.y*j.x-Q.x*j.y;T.localCOMx+=(j.x+Q.x)*Y,T.localCOMy+=(j.y+Q.y)*Y,G=1/(3*G);let X=G;T.localCOMx*=X,T.localCOMy*=X}}V.wrap_localCOM!=null&&(V.wrap_localCOM.zpp_inner.x=V.localCOMx,V.wrap_localCOM.zpp_inner.y=V.localCOMy)}let D=V.body;D.zip_axis&&(D.zip_axis=!1,D.axisx=Math.sin(D.rot),D.axisy=Math.cos(D.rot)),V.worldCOMx=V.body.posx+(V.body.axisy*V.localCOMx-V.body.axisx*V.localCOMy),V.worldCOMy=V.body.posy+(V.localCOMx*V.body.axisx+V.localCOMy*V.body.axisy)}}else{let V=e.polygon;if(V.zip_gaxi&&V.body!=null){V.zip_gaxi=!1,V.validate_laxi();let D=V.body;if(D.zip_axis&&(D.zip_axis=!1,D.axisx=Math.sin(D.rot),D.axisy=Math.cos(D.rot)),V.zip_gverts&&V.body!=null){V.zip_gverts=!1,V.validate_lverts();let A=V.body;A.zip_axis&&(A.zip_axis=!1,A.axisx=Math.sin(A.rot),A.axisy=Math.cos(A.rot));let W=V.lverts.next,Q=V.gverts.next;for(;Q!=null;){let Y=Q,X=W;W=W.next,Y.x=V.body.posx+(V.body.axisy*X.x-V.body.axisx*X.y),Y.y=V.body.posy+(X.x*V.body.axisx+X.y*V.body.axisy),Q=Q.next}}let T=V.edges.head,G=V.gverts.next,q=G;for(G=G.next;G!=null;){let A=G,W=T.elt;T=T.next,W.gp0=q,W.gp1=A,W.gnormx=V.body.axisy*W.lnormx-V.body.axisx*W.lnormy,W.gnormy=W.lnormx*V.body.axisx+W.lnormy*V.body.axisy,W.gprojection=V.body.posx*W.gnormx+V.body.posy*W.gnormy+W.lprojection,W.wrap_gnorm!=null&&(W.wrap_gnorm.zpp_inner.x=W.gnormx,W.wrap_gnorm.zpp_inner.y=W.gnormy),W.tp0=W.gp0.y*W.gnormx-W.gp0.x*W.gnormy,W.tp1=W.gp1.y*W.gnormx-W.gp1.x*W.gnormy,q=A,G=G.next}let R=V.gverts.next,j=T.elt;T=T.next,j.gp0=q,j.gp1=R,j.gnormx=V.body.axisy*j.lnormx-V.body.axisx*j.lnormy,j.gnormy=j.lnormx*V.body.axisx+j.lnormy*V.body.axisy,j.gprojection=V.body.posx*j.gnormx+V.body.posy*j.gnormy+j.lprojection,j.wrap_gnorm!=null&&(j.wrap_gnorm.zpp_inner.x=j.gnormx,j.wrap_gnorm.zpp_inner.y=j.gnormy),j.tp0=j.gp0.y*j.gnormx-j.gp0.x*j.gnormy,j.tp1=j.gp1.y*j.gnormx-j.gp1.x*j.gnormy}}let l=e.body,r=l.posx,a=l.posy;l.sweepTime=0,l.sweep_angvel=l.angvel;let o=t-l.sweepTime;if(o!=0){l.sweepTime=t;let V=o;if(l.posx+=l.velx*V,l.posy+=l.vely*V,l.angvel!=0){let D=l.sweep_angvel*o;if(l.rot+=D,D*D>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let T=D*D,G=1-.5*T,q=1-T*T/8,R=(G*l.axisx+D*l.axisy)*q;l.axisy=(G*l.axisy-D*l.axisx)*q,l.axisx=R}}}let p=l.posx,c=l.posy;e.validate_sweepRadius();let h=e.sweepRadius,u;be.zpp_pool==null?u=new be:(u=be.zpp_pool,be.zpp_pool=u.next,u.next=null);let x=r,y=p;u.minx=(x<y?x:y)-h;let d=r,_=p;u.maxx=(d>_?d:_)+h;let f=a,z=c;u.miny=(f<z?f:z)-h;let P=a,k=c;u.maxy=(P>k?P:k)+h;let m=this.convexShapeList=this.bphase.shapesInAABB(u,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),b=u;b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b.wrap_min=b.wrap_max=null,b._invalidate=null,b._validate=null,b.next=be.zpp_pool,be.zpp_pool=b;let C=0,v=0;C=0,v=0;let w=0,O=0;w=0,O=0;let E=null,M=t+1;m.zpp_inner.valmod();let N=B._nape.shape.ShapeIterator.get(m);for(;;){N.zpp_inner.zpp_inner.valmod();let V=N.zpp_inner;V.zpp_inner.valmod(),V.zpp_inner.zip_length&&(V.zpp_inner.zip_length=!1,V.zpp_inner.user_length=V.zpp_inner.inner.length);let D=V.zpp_inner.user_length;N.zpp_critical=!0;let T;if(N.zpp_i<D?T=!0:(N.zpp_next=B._nape.shape.ShapeIterator.zpp_pool,B._nape.shape.ShapeIterator.zpp_pool=N,N.zpp_inner=null,T=!1),!T)break;N.zpp_critical=!1;let G=N.zpp_inner.at(N.zpp_i++);if(G!=e.outer&&(G.zpp_inner.body!=null?G.zpp_inner.body.outer:null)!=l.outer){if(i.s1=e,i.s2=G.zpp_inner,s){G.zpp_inner.validate_sweepRadius(),(G.zpp_inner.body!=null?G.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(G.zpp_inner.body!=null?G.zpp_inner.body.outer:null).zpp_inner.angvel,(G.zpp_inner.body!=null?G.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,wn.dynamicSweep(i,t,0,0,!0);let q=(G.zpp_inner.body!=null?G.zpp_inner.body.outer:null).zpp_inner,R=0-q.sweepTime;if(R!=0){q.sweepTime=0;let W=R;if(q.posx+=q.velx*W,q.posy+=q.vely*W,q.angvel!=0){let Q=q.sweep_angvel*R;if(q.rot+=Q,Q*Q>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else{let Y=Q*Q,X=1-.5*Y,ee=1-Y*Y/8,J=(X*q.axisx+Q*q.axisy)*ee;q.axisy=(X*q.axisy-Q*q.axisx)*ee,q.axisx=J}}}let j=(G.zpp_inner.body!=null?G.zpp_inner.body.outer:null).zpp_inner,A=G.zpp_inner;if(A.type==0)A.worldCOMx=j.posx+(j.axisy*A.localCOMx-j.axisx*A.localCOMy),A.worldCOMy=j.posy+(A.localCOMx*j.axisx+A.localCOMy*j.axisy);else{let W=A.polygon,Q=W.lverts.next,Y=W.gverts.next;for(;Y!=null;){let I=Y,U=Q;Q=Q.next,I.x=j.posx+(j.axisy*U.x-j.axisx*U.y),I.y=j.posy+(U.x*j.axisx+U.y*j.axisy),Y=Y.next}let X=W.edges.head,ee=W.gverts.next,J=ee;for(ee=ee.next;ee!=null;){let I=ee,U=X.elt;X=X.next,U.gnormx=j.axisy*U.lnormx-j.axisx*U.lnormy,U.gnormy=U.lnormx*j.axisx+U.lnormy*j.axisy,U.gprojection=j.posx*U.gnormx+j.posy*U.gnormy+U.lprojection,U.tp0=J.y*U.gnormx-J.x*U.gnormy,U.tp1=I.y*U.gnormx-I.x*U.gnormy,J=I,ee=ee.next}let L=W.gverts.next,F=X.elt;X=X.next,F.gnormx=j.axisy*F.lnormx-j.axisx*F.lnormy,F.gnormy=F.lnormx*j.axisx+F.lnormy*j.axisy,F.gprojection=j.posx*F.gnormx+j.posy*F.gnormy+F.lprojection,F.tp0=J.y*F.gnormx-J.x*F.gnormy,F.tp1=L.y*F.gnormx-L.x*F.gnormy}}else wn.staticSweep(i,t,0,0);i.toi*=t,i.toi>0&&i.toi<M&&(M=i.toi,C=i.axis.x,v=i.axis.y,w=i.c2.x,O=i.c2.y,E=G)}}m.clear();let Z=i;Z.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=Z;let S=0-l.sweepTime;if(S!=0){l.sweepTime=0;let V=S;if(l.posx+=l.velx*V,l.posy+=l.vely*V,l.angvel!=0){let D=l.sweep_angvel*S;if(l.rot+=D,D*D>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let T=D*D,G=1-.5*T,q=1-T*T/8,R=(G*l.axisx+D*l.axisy)*q;l.axisy=(G*l.axisy-D*l.axisx)*q,l.axisx=R}}}if(e.type==0)e.worldCOMx=l.posx+(l.axisy*e.localCOMx-l.axisx*e.localCOMy),e.worldCOMy=l.posy+(e.localCOMx*l.axisx+e.localCOMy*l.axisy);else{let V=e.polygon,D=V.lverts.next,T=V.gverts.next;for(;T!=null;){let W=T,Q=D;D=D.next,W.x=l.posx+(l.axisy*Q.x-l.axisx*Q.y),W.y=l.posy+(Q.x*l.axisx+Q.y*l.axisy),T=T.next}let G=V.edges.head,q=V.gverts.next,R=q;for(q=q.next;q!=null;){let W=q,Q=G.elt;G=G.next,Q.gnormx=l.axisy*Q.lnormx-l.axisx*Q.lnormy,Q.gnormy=Q.lnormx*l.axisx+Q.lnormy*l.axisy,Q.gprojection=l.posx*Q.gnormx+l.posy*Q.gnormy+Q.lprojection,Q.tp0=R.y*Q.gnormx-R.x*Q.gnormy,Q.tp1=W.y*Q.gnormx-W.x*Q.gnormy,R=W,q=q.next}let j=V.gverts.next,A=G.elt;G=G.next,A.gnormx=l.axisy*A.lnormx-l.axisx*A.lnormy,A.gnormy=A.lnormx*l.axisx+A.lnormy*l.axisy,A.gprojection=l.posx*A.gnormx+l.posy*A.gnormy+A.lprojection,A.tp0=R.y*A.gnormx-R.x*A.gnormy,A.tp1=j.y*A.gnormx-j.x*A.gnormy}if(M<=t){let V=-C,D=-v;if(D==null&&(D=0),V==null&&(V=0),V!=V||D!=D)throw new Error("Error: Vec2 components cannot be NaN");let T;if(B._zpp.util.ZPP_PubPool.poolVec2==null?T=new B._nape.geom.Vec2:(T=B._zpp.util.ZPP_PubPool.poolVec2,B._zpp.util.ZPP_PubPool.poolVec2=T.zpp_pool,T.zpp_pool=null,T.zpp_disp=!1,T==B._zpp.util.ZPP_PubPool.nextVec2&&(B._zpp.util.ZPP_PubPool.nextVec2=null)),T.zpp_inner==null){let j;le.zpp_pool==null?j=new le:(j=le.zpp_pool,le.zpp_pool=j.next,j.next=null),j.weak=!1,j._immutable=!1,j.x=V,j.y=D,T.zpp_inner=j,T.zpp_inner.outer=T}else{if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let j=T.zpp_inner;if(j._immutable)throw new Error("Error: Vec2 is immutable");if(j._isimmutable!=null&&j._isimmutable(),V!=V||D!=D)throw new Error("Error: Vec2 components cannot be NaN");let A;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let W=T.zpp_inner;if(W._validate!=null&&W._validate(),T.zpp_inner.x==V){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Q=T.zpp_inner;Q._validate!=null&&Q._validate(),A=T.zpp_inner.y==D}else A=!1;if(!A){T.zpp_inner.x=V,T.zpp_inner.y=D;let Q=T.zpp_inner;Q._invalidate!=null&&Q._invalidate(Q)}}T.zpp_inner.weak=!1;let G=w,q=O;if(q==null&&(q=0),G==null&&(G=0),G!=G||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let R;if(B._zpp.util.ZPP_PubPool.poolVec2==null?R=new B._nape.geom.Vec2:(R=B._zpp.util.ZPP_PubPool.poolVec2,B._zpp.util.ZPP_PubPool.poolVec2=R.zpp_pool,R.zpp_pool=null,R.zpp_disp=!1,R==B._zpp.util.ZPP_PubPool.nextVec2&&(B._zpp.util.ZPP_PubPool.nextVec2=null)),R.zpp_inner==null){let j;le.zpp_pool==null?j=new le:(j=le.zpp_pool,le.zpp_pool=j.next,j.next=null),j.weak=!1,j._immutable=!1,j.x=G,j.y=q,R.zpp_inner=j,R.zpp_inner.outer=R}else{if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let j=R.zpp_inner;if(j._immutable)throw new Error("Error: Vec2 is immutable");if(j._isimmutable!=null&&j._isimmutable(),G!=G||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let A;if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let W=R.zpp_inner;if(W._validate!=null&&W._validate(),R.zpp_inner.x==G){if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Q=R.zpp_inner;Q._validate!=null&&Q._validate(),A=R.zpp_inner.y==q}else A=!1;if(!A){R.zpp_inner.x=G,R.zpp_inner.y=q;let Q=R.zpp_inner;Q._invalidate!=null&&Q._invalidate(Q)}}return R.zpp_inner.weak=!1,B._zpp.geom.ZPP_ConvexRayResult.getConvex(T,R,M,E)}else return null}prepareCast(e){if(e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let s=t.polygon;if(s.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(s.lverts.next.next==null)s.localCOMx=s.lverts.next.x,s.localCOMy=s.lverts.next.y;else if(s.lverts.next.next.next==null){s.localCOMx=s.lverts.next.x,s.localCOMy=s.lverts.next.y;let i=1;s.localCOMx+=s.lverts.next.next.x*i,s.localCOMy+=s.lverts.next.next.y*i;let l=.5;s.localCOMx*=l,s.localCOMy*=l}else{s.localCOMx=0,s.localCOMy=0;let i=0,l=s.lverts.next,r=l;l=l.next;let a=l;for(l=l.next;l!=null;){let x=l;i+=a.x*(x.y-r.y);let y=x.y*a.x-x.x*a.y;s.localCOMx+=(a.x+x.x)*y,s.localCOMy+=(a.y+x.y)*y,r=a,a=x,l=l.next}l=s.lverts.next;let o=l;i+=a.x*(o.y-r.y);let p=o.y*a.x-o.x*a.y;s.localCOMx+=(a.x+o.x)*p,s.localCOMy+=(a.y+o.y)*p,r=a,a=o,l=l.next;let c=l;i+=a.x*(c.y-r.y);let h=c.y*a.x-c.x*a.y;s.localCOMx+=(a.x+c.x)*h,s.localCOMy+=(a.y+c.y)*h,i=1/(3*i);let u=i;s.localCOMx*=u,s.localCOMy*=u}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let n=t.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}}else{let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let o=t.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=t.body.posx+(t.body.axisy*u.x-t.body.axisx*u.y),h.y=t.body.posy+(u.x*t.body.axisx+u.y*t.body.axisy),c=c.next}}let s=t.edges.head,i=t.gverts.next,l=i;for(i=i.next;i!=null;){let o=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=o,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,l=o,i=i.next}let r=t.gverts.next,a=s.elt;s=s.next,a.gp0=l,a.gp1=r,a.gnormx=t.body.axisy*a.lnormx-t.body.axisx*a.lnormy,a.gnormy=a.lnormx*t.body.axisx+a.lnormy*t.body.axisy,a.gprojection=t.body.posx*a.gnormx+t.body.posy*a.gnormy+a.lprojection,a.wrap_gnorm!=null&&(a.wrap_gnorm.zpp_inner.x=a.gnormx,a.wrap_gnorm.zpp_inner.y=a.gnormy),a.tp0=a.gp0.y*a.gnormx-a.gp0.x*a.gnormy,a.tp1=a.gp1.y*a.gnormx-a.gp1.x*a.gnormy}}}convexMultiCast(e,t,n,s,i){let l;if(B._zpp.geom.ZPP_ToiEvent.zpp_pool==null?l=new B._zpp.geom.ZPP_ToiEvent:(l=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=l.next,l.next=null),l.failed=!1,l.s1=l.s2=null,l.arbiter=null,e.type==0){let M=e.circle;if(M.zip_worldCOM&&M.body!=null){if(M.zip_worldCOM=!1,M.zip_localCOM){if(M.zip_localCOM=!1,M.type==1){let Z=M.polygon;if(Z.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(Z.lverts.next.next==null)Z.localCOMx=Z.lverts.next.x,Z.localCOMy=Z.lverts.next.y;else if(Z.lverts.next.next.next==null){Z.localCOMx=Z.lverts.next.x,Z.localCOMy=Z.lverts.next.y;let S=1;Z.localCOMx+=Z.lverts.next.next.x*S,Z.localCOMy+=Z.lverts.next.next.y*S;let V=.5;Z.localCOMx*=V,Z.localCOMy*=V}else{Z.localCOMx=0,Z.localCOMy=0;let S=0,V=Z.lverts.next,D=V;V=V.next;let T=V;for(V=V.next;V!=null;){let W=V;S+=T.x*(W.y-D.y);let Q=W.y*T.x-W.x*T.y;Z.localCOMx+=(T.x+W.x)*Q,Z.localCOMy+=(T.y+W.y)*Q,D=T,T=W,V=V.next}V=Z.lverts.next;let G=V;S+=T.x*(G.y-D.y);let q=G.y*T.x-G.x*T.y;Z.localCOMx+=(T.x+G.x)*q,Z.localCOMy+=(T.y+G.y)*q,D=T,T=G,V=V.next;let R=V;S+=T.x*(R.y-D.y);let j=R.y*T.x-R.x*T.y;Z.localCOMx+=(T.x+R.x)*j,Z.localCOMy+=(T.y+R.y)*j,S=1/(3*S);let A=S;Z.localCOMx*=A,Z.localCOMy*=A}}M.wrap_localCOM!=null&&(M.wrap_localCOM.zpp_inner.x=M.localCOMx,M.wrap_localCOM.zpp_inner.y=M.localCOMy)}let N=M.body;N.zip_axis&&(N.zip_axis=!1,N.axisx=Math.sin(N.rot),N.axisy=Math.cos(N.rot)),M.worldCOMx=M.body.posx+(M.body.axisy*M.localCOMx-M.body.axisx*M.localCOMy),M.worldCOMy=M.body.posy+(M.localCOMx*M.body.axisx+M.localCOMy*M.body.axisy)}}else{let M=e.polygon;if(M.zip_gaxi&&M.body!=null){M.zip_gaxi=!1,M.validate_laxi();let N=M.body;if(N.zip_axis&&(N.zip_axis=!1,N.axisx=Math.sin(N.rot),N.axisy=Math.cos(N.rot)),M.zip_gverts&&M.body!=null){M.zip_gverts=!1,M.validate_lverts();let G=M.body;G.zip_axis&&(G.zip_axis=!1,G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot));let q=M.lverts.next,R=M.gverts.next;for(;R!=null;){let j=R,A=q;q=q.next,j.x=M.body.posx+(M.body.axisy*A.x-M.body.axisx*A.y),j.y=M.body.posy+(A.x*M.body.axisx+A.y*M.body.axisy),R=R.next}}let Z=M.edges.head,S=M.gverts.next,V=S;for(S=S.next;S!=null;){let G=S,q=Z.elt;Z=Z.next,q.gp0=V,q.gp1=G,q.gnormx=M.body.axisy*q.lnormx-M.body.axisx*q.lnormy,q.gnormy=q.lnormx*M.body.axisx+q.lnormy*M.body.axisy,q.gprojection=M.body.posx*q.gnormx+M.body.posy*q.gnormy+q.lprojection,q.wrap_gnorm!=null&&(q.wrap_gnorm.zpp_inner.x=q.gnormx,q.wrap_gnorm.zpp_inner.y=q.gnormy),q.tp0=q.gp0.y*q.gnormx-q.gp0.x*q.gnormy,q.tp1=q.gp1.y*q.gnormx-q.gp1.x*q.gnormy,V=G,S=S.next}let D=M.gverts.next,T=Z.elt;Z=Z.next,T.gp0=V,T.gp1=D,T.gnormx=M.body.axisy*T.lnormx-M.body.axisx*T.lnormy,T.gnormy=T.lnormx*M.body.axisx+T.lnormy*M.body.axisy,T.gprojection=M.body.posx*T.gnormx+M.body.posy*T.gnormy+T.lprojection,T.wrap_gnorm!=null&&(T.wrap_gnorm.zpp_inner.x=T.gnormx,T.wrap_gnorm.zpp_inner.y=T.gnormy),T.tp0=T.gp0.y*T.gnormx-T.gp0.x*T.gnormy,T.tp1=T.gp1.y*T.gnormx-T.gp1.x*T.gnormy}}let r=e.body,a=r.posx,o=r.posy;r.sweepTime=0,r.sweep_angvel=r.angvel;let p=t-r.sweepTime;if(p!=0){r.sweepTime=t;let M=p;if(r.posx+=r.velx*M,r.posy+=r.vely*M,r.angvel!=0){let N=r.sweep_angvel*p;if(r.rot+=N,N*N>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let Z=N*N,S=1-.5*Z,V=1-Z*Z/8,D=(S*r.axisx+N*r.axisy)*V;r.axisy=(S*r.axisy-N*r.axisx)*V,r.axisx=D}}}let c=r.posx,h=r.posy;e.validate_sweepRadius();let u=e.sweepRadius,x;be.zpp_pool==null?x=new be:(x=be.zpp_pool,be.zpp_pool=x.next,x.next=null);let y=a,d=c;x.minx=(y<d?y:d)-u;let _=a,f=c;x.maxx=(_>f?_:f)+u;let z=o,P=h;x.miny=(z<P?z:P)-u;let k=o,m=h;x.maxy=(k>m?k:m)+u;let b=this.convexShapeList=this.bphase.shapesInAABB(x,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),C=x;C.outer!=null&&(C.outer.zpp_inner=null,C.outer=null),C.wrap_min=C.wrap_max=null,C._invalidate=null,C._validate=null,C.next=be.zpp_pool,be.zpp_pool=C;let v=i??new B._nape.geom.ConvexResultList;b.zpp_inner.valmod();let w=B._nape.shape.ShapeIterator.get(b);for(;;){w.zpp_inner.zpp_inner.valmod();let M=w.zpp_inner;M.zpp_inner.valmod(),M.zpp_inner.zip_length&&(M.zpp_inner.zip_length=!1,M.zpp_inner.user_length=M.zpp_inner.inner.length);let N=M.zpp_inner.user_length;w.zpp_critical=!0;let Z;if(w.zpp_i<N?Z=!0:(w.zpp_next=B._nape.shape.ShapeIterator.zpp_pool,B._nape.shape.ShapeIterator.zpp_pool=w,w.zpp_inner=null,Z=!1),!Z)break;w.zpp_critical=!1;let S=w.zpp_inner.at(w.zpp_i++);if(S!=e.outer&&(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null)!=r.outer){if(l.s1=e,l.s2=S.zpp_inner,s){S.zpp_inner.validate_sweepRadius(),(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner.angvel,(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,wn.dynamicSweep(l,t,0,0,!0);let V=(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner,D=0-V.sweepTime;if(D!=0){V.sweepTime=0;let q=D;if(V.posx+=V.velx*q,V.posy+=V.vely*q,V.angvel!=0){let R=V.sweep_angvel*D;if(V.rot+=R,R*R>1e-4)V.axisx=Math.sin(V.rot),V.axisy=Math.cos(V.rot);else{let j=R*R,A=1-.5*j,W=1-j*j/8,Q=(A*V.axisx+R*V.axisy)*W;V.axisy=(A*V.axisy-R*V.axisx)*W,V.axisx=Q}}}let T=(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner,G=S.zpp_inner;if(G.type==0)G.worldCOMx=T.posx+(T.axisy*G.localCOMx-T.axisx*G.localCOMy),G.worldCOMy=T.posy+(G.localCOMx*T.axisx+G.localCOMy*T.axisy);else{let q=G.polygon,R=q.lverts.next,j=q.gverts.next;for(;j!=null;){let ee=j,J=R;R=R.next,ee.x=T.posx+(T.axisy*J.x-T.axisx*J.y),ee.y=T.posy+(J.x*T.axisx+J.y*T.axisy),j=j.next}let A=q.edges.head,W=q.gverts.next,Q=W;for(W=W.next;W!=null;){let ee=W,J=A.elt;A=A.next,J.gnormx=T.axisy*J.lnormx-T.axisx*J.lnormy,J.gnormy=J.lnormx*T.axisx+J.lnormy*T.axisy,J.gprojection=T.posx*J.gnormx+T.posy*J.gnormy+J.lprojection,J.tp0=Q.y*J.gnormx-Q.x*J.gnormy,J.tp1=ee.y*J.gnormx-ee.x*J.gnormy,Q=ee,W=W.next}let Y=q.gverts.next,X=A.elt;A=A.next,X.gnormx=T.axisy*X.lnormx-T.axisx*X.lnormy,X.gnormy=X.lnormx*T.axisx+X.lnormy*T.axisy,X.gprojection=T.posx*X.gnormx+T.posy*X.gnormy+X.lprojection,X.tp0=Q.y*X.gnormx-Q.x*X.gnormy,X.tp1=Y.y*X.gnormx-Y.x*X.gnormy}}else wn.staticSweep(l,t,0,0);if(l.toi*=t,l.toi>0){let V=-l.axis.x,D=-l.axis.y;if(D==null&&(D=0),V==null&&(V=0),V!=V||D!=D)throw new Error("Error: Vec2 components cannot be NaN");let T;if(B._zpp.util.ZPP_PubPool.poolVec2==null?T=new B._nape.geom.Vec2:(T=B._zpp.util.ZPP_PubPool.poolVec2,B._zpp.util.ZPP_PubPool.poolVec2=T.zpp_pool,T.zpp_pool=null,T.zpp_disp=!1,T==B._zpp.util.ZPP_PubPool.nextVec2&&(B._zpp.util.ZPP_PubPool.nextVec2=null)),T.zpp_inner==null){let ee;le.zpp_pool==null?ee=new le:(ee=le.zpp_pool,le.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=V,ee.y=D,T.zpp_inner=ee,T.zpp_inner.outer=T}else{if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=T.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),V!=V||D!=D)throw new Error("Error: Vec2 components cannot be NaN");let J;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=T.zpp_inner;if(L._validate!=null&&L._validate(),T.zpp_inner.x==V){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=T.zpp_inner;F._validate!=null&&F._validate(),J=T.zpp_inner.y==D}else J=!1;if(!J){T.zpp_inner.x=V,T.zpp_inner.y=D;let F=T.zpp_inner;F._invalidate!=null&&F._invalidate(F)}}T.zpp_inner.weak=!1;let G=l.c2.x,q=l.c2.y;if(q==null&&(q=0),G==null&&(G=0),G!=G||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let R;if(B._zpp.util.ZPP_PubPool.poolVec2==null?R=new B._nape.geom.Vec2:(R=B._zpp.util.ZPP_PubPool.poolVec2,B._zpp.util.ZPP_PubPool.poolVec2=R.zpp_pool,R.zpp_pool=null,R.zpp_disp=!1,R==B._zpp.util.ZPP_PubPool.nextVec2&&(B._zpp.util.ZPP_PubPool.nextVec2=null)),R.zpp_inner==null){let ee;le.zpp_pool==null?ee=new le:(ee=le.zpp_pool,le.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=G,ee.y=q,R.zpp_inner=ee,R.zpp_inner.outer=R}else{if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=R.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),G!=G||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let J;if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=R.zpp_inner;if(L._validate!=null&&L._validate(),R.zpp_inner.x==G){if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=R.zpp_inner;F._validate!=null&&F._validate(),J=R.zpp_inner.y==q}else J=!1;if(!J){R.zpp_inner.x=G,R.zpp_inner.y=q;let F=R.zpp_inner;F._invalidate!=null&&F._invalidate(F)}}R.zpp_inner.weak=!1;let j=B._zpp.geom.ZPP_ConvexRayResult.getConvex(T,R,l.toi,S),A=null,W=v.zpp_inner.inner.head;for(;W!=null;){let ee=W.elt;if(j.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(ee.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(j.zpp_inner.toiDistance<ee.zpp_inner.toiDistance)break;A=W,W=W.next}let Q=v.zpp_inner.inner,Y;B._zpp.util.ZNPNode_ConvexResult.zpp_pool==null?Y=new B._zpp.util.ZNPNode_ConvexResult:(Y=B._zpp.util.ZNPNode_ConvexResult.zpp_pool,B._zpp.util.ZNPNode_ConvexResult.zpp_pool=Y.next,Y.next=null),Y.elt=j;let X=Y;A==null?(X.next=Q.head,Q.head=X):(X.next=A.next,A.next=X),Q.pushmod=Q.modified=!0,Q.length++}}}b.clear();let O=l;O.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=O;let E=0-r.sweepTime;if(E!=0){r.sweepTime=0;let M=E;if(r.posx+=r.velx*M,r.posy+=r.vely*M,r.angvel!=0){let N=r.sweep_angvel*E;if(r.rot+=N,N*N>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let Z=N*N,S=1-.5*Z,V=1-Z*Z/8,D=(S*r.axisx+N*r.axisy)*V;r.axisy=(S*r.axisy-N*r.axisx)*V,r.axisx=D}}}if(e.type==0)e.worldCOMx=r.posx+(r.axisy*e.localCOMx-r.axisx*e.localCOMy),e.worldCOMy=r.posy+(e.localCOMx*r.axisx+e.localCOMy*r.axisy);else{let M=e.polygon,N=M.lverts.next,Z=M.gverts.next;for(;Z!=null;){let q=Z,R=N;N=N.next,q.x=r.posx+(r.axisy*R.x-r.axisx*R.y),q.y=r.posy+(R.x*r.axisx+R.y*r.axisy),Z=Z.next}let S=M.edges.head,V=M.gverts.next,D=V;for(V=V.next;V!=null;){let q=V,R=S.elt;S=S.next,R.gnormx=r.axisy*R.lnormx-r.axisx*R.lnormy,R.gnormy=R.lnormx*r.axisx+R.lnormy*r.axisy,R.gprojection=r.posx*R.gnormx+r.posy*R.gnormy+R.lprojection,R.tp0=D.y*R.gnormx-D.x*R.gnormy,R.tp1=q.y*R.gnormx-q.x*R.gnormy,D=q,V=V.next}let T=M.gverts.next,G=S.elt;S=S.next,G.gnormx=r.axisy*G.lnormx-r.axisx*G.lnormy,G.gnormy=G.lnormx*r.axisx+G.lnormy*r.axisy,G.gprojection=r.posx*G.gnormx+r.posy*G.gnormy+G.lprojection,G.tp0=D.y*G.gnormx-D.x*G.gnormy,G.tp1=T.y*G.gnormx-T.x*G.gnormy}return v}push_callback(e){let t;return jt.zpp_pool==null?t=new jt:(t=jt.zpp_pool,jt.zpp_pool=t.next,t.next=null),this.callbacks.push(t),t.listener=e,t}step(e,t,n){if(this.midstep)throw new Error("Error: ... REALLY?? you're going to call space.step() inside of space.step()? COME ON!!");if(this.time+=e,this.pre_dt=e,this.midstep=!0,this.stamp++,this.validation(),this.bphase.broadphase(this,!0),this.prestep(e),this.sortcontacts){let h=this.c_arbiters_false;if(h.head!=null&&h.head.next!=null){let u=h.head,x=null,y=null,d=null,_=null,f=1,z,P,k;for(;;){for(z=0,y=u,u=null,x=u;y!=null;){for(++z,d=y,P=0,k=f;d!=null&&P<f;)++P,d=d.next;for(;P>0||k>0&&d!=null;)P==0?(_=d,d=d.next,--k):k==0||d==null||!(y.elt.active&&d.elt.active)||y.elt.oc1.dist<d.elt.oc1.dist?(_=y,y=y.next,--P):(_=d,d=d.next,--k),x!=null?x.next=_:u=_,x=_;y=d}if(x.next=null,f<<=1,!(z>1))break}h.head=u,h.modified=!0,h.pushmod=!0}}this.updateVel(e),this.warmStart(),this.iterateVel(t);let s=this.kinematics.head;for(;s!=null;){let h=s.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,s=s.next}let i=this.live.head;for(;i!=null;){let h=i.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,i=i.next}this.updatePos(e),this.continuous=!0,this.continuousCollisions(e),this.continuous=!1,this.iteratePos(n);let l=this.kinematics.head;for(;l!=null;){let h=l.elt,u=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),x=h.pre_rot!=h.rot;if(u){let y=h.shapes.head;for(;y!=null;){let d=y.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),y=y.next}h.zip_worldCOM=!0}if(x){h.zip_axis=!0;let y=h.shapes.head;for(;y!=null;){let d=y.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),y=y.next}h.zip_worldCOM=!0}l=l.next}let r=this.live.head;for(;r!=null;){let h=r.elt,u=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),x=h.pre_rot!=h.rot;if(u){let y=h.shapes.head;for(;y!=null;){let d=y.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),y=y.next}h.zip_worldCOM=!0}if(x){h.zip_axis=!0;let y=h.shapes.head;for(;y!=null;){let d=y.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),y=y.next}h.zip_worldCOM=!0}r=r.next}let a=null,o=this.staticsleep.head;for(;o!=null;){let h=o.elt;if(h.type!=3||h.velx==0&&h.vely==0&&h.angvel==0){if(h.kinematicDelaySleep){h.kinematicDelaySleep=!1,o=o.next;continue}h.component.sleeping=!0;let u=this.staticsleep,x,y;a==null?(x=u.head,y=x.next,u.head=y,u.head==null&&(u.pushmod=!0)):(x=a.next,y=x.next,a.next=y,y==null&&(u.pushmod=!0));let d=x;d.elt=null,d.next=B._zpp.util.ZNPNode_ZPP_Body.zpp_pool,B._zpp.util.ZNPNode_ZPP_Body.zpp_pool=d,u.modified=!0,u.length--,u.pushmod=!0,o=y;continue}a=o,o=o.next}this.doForests(e),this.sleepArbiters(),this.midstep=!1;let p=null,c=this.callbackset_list.next;for(;c!=null;){let h=c;if(h.arbiters.head==null){let b=this.callbackset_list,C,v;p==null?(C=b.next,v=C.next,b.next=v,b.next==null&&(b.pushmod=!0)):(C=p.next,v=C.next,p.next=v,v==null&&(b.pushmod=!0)),C._inuse=!1,b.modified=!0,b.length--,b.pushmod=!0,c=v;let w=h;w.int1=w.int2=null,w.id=w.di=-1,w.freed=!0,w.next=qt.zpp_pool,qt.zpp_pool=w;continue}let u;u=!0;let x=h.arbiters.head;for(;x!=null;)if(x.elt.sleeping){x=x.next;continue}else{u=!1;break}let y=u,d=h.int1.cbSet,_=h.int2.cbSet,f=d.manager,z=null,k=(d.cbpairs.length<_.cbpairs.length?d.cbpairs:_.cbpairs).head;for(;k!=null;){let b=k.elt;if(b.a==d&&b.b==_||b.a==_&&b.b==d){z=b;break}k=k.next}if(z==null){let b;Ne.zpp_pool==null?b=new Ne:(b=Ne.zpp_pool,Ne.zpp_pool=b.next,b.next=null),b.zip_listeners=!0,dt.setlt(d,_)?(b.a=d,b.b=_):(b.a=_,b.b=d),z=b,d.cbpairs.add(z),_!=d&&_.cbpairs.add(z)}z.zip_listeners&&(z.zip_listeners=!1,z.__validate());let m=z.listeners.head;for(;m!=null;){let b=m.elt;if(b.event==6&&(!y||b.allowSleepingCallbacks)&&!h.empty_arb(b.itype)){let C=this.push_callback(b);C.event=6;let v=h.int1,w=h.int2,O,E=b.options1,M=v.cbTypes;if(E.nonemptyintersection(M,E.includes)&&!E.nonemptyintersection(M,E.excludes)){let N=b.options2,Z=w.cbTypes;O=N.nonemptyintersection(Z,N.includes)&&!N.nonemptyintersection(Z,N.excludes)}else O=!1;O?(C.int1=v,C.int2=w):(C.int1=w,C.int2=v),C.set=h}m=m.next}p=c,c=c.next}for(;!this.callbacks.empty();){let h=this.callbacks.pop();h.listener.type==0?h.listener.body.handler(h.wrapper_body()):h.listener.type==1?h.listener.constraint.handler(h.wrapper_con()):h.listener.type==2&&h.listener.interaction.handleri(h.wrapper_int());let u=h;u.int1=u.int2=null,u.body=null,u.constraint=null,u.listener=null,u.wrap_arbiters!=null&&(u.wrap_arbiters.zpp_inner.inner=null),u.set=null,u.next=jt.zpp_pool,jt.zpp_pool=u}}continuousCollisions(e){let t=2*Math.PI/e;this.bphase.broadphase(this,!1);let n=0;for(;n<1&&this.toiEvents.head!=null;){let l=null,r=2,a=!1,o=null,p=null,c=this.toiEvents.head;for(;c!=null;){let _=c.elt,f=_.s1.body,z=_.s2.body;if(f.sweepFrozen&&z.sweepFrozen)if(_.toi!=0&&Ee.testCollide_safe(_.s1,_.s2))_.toi=0;else{c=this.toiEvents.erase(p);let P=_;P.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}if(_.frozen1!=f.sweepFrozen||_.frozen2!=z.sweepFrozen)if(_.kinematic){c=this.toiEvents.erase(p);let P=_;P.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}else{if(_.frozen1=f.sweepFrozen,_.frozen2=z.sweepFrozen,_.frozen1){let P=_.s1;_.s1=_.s2,_.s2=P,_.frozen1=!1,_.frozen2=!0}if(wn.staticSweep(_,e,0,B._nape.Config.collisionSlopCCD),_.toi<0){c=this.toiEvents.erase(p);let P=_;P.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}}_.toi>=0&&(_.toi<r||!a&&_.kinematic)&&(l=_,r=_.toi,a=_.kinematic,o=p),p=c,c=c.next}if(l==null)break;this.toiEvents.erase(o),n=l.toi;let h=l.s1.body,u=l.s2.body;if(!h.sweepFrozen){let _=n*e,f=_-h.sweepTime;if(f!=0){h.sweepTime=_;let P=f;if(h.posx+=h.velx*P,h.posy+=h.vely*P,h.angvel!=0){let k=h.sweep_angvel*f;if(h.rot+=k,k*k>1e-4)h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot);else{let m=k*k,b=1-.5*m,C=1-m*m/8,v=(b*h.axisx+k*h.axisy)*C;h.axisy=(b*h.axisy-k*h.axisx)*C,h.axisx=v}}}let z=l.s1;if(z.type==0)z.worldCOMx=h.posx+(h.axisy*z.localCOMx-h.axisx*z.localCOMy),z.worldCOMy=h.posy+(z.localCOMx*h.axisx+z.localCOMy*h.axisy);else{let P=z.polygon,k=P.lverts.next,m=P.gverts.next;for(;m!=null;){let E=m,M=k;k=k.next,E.x=h.posx+(h.axisy*M.x-h.axisx*M.y),E.y=h.posy+(M.x*h.axisx+M.y*h.axisy),m=m.next}let b=P.edges.head,C=P.gverts.next,v=C;for(C=C.next;C!=null;){let E=C,M=b.elt;b=b.next,M.gnormx=h.axisy*M.lnormx-h.axisx*M.lnormy,M.gnormy=M.lnormx*h.axisx+M.lnormy*h.axisy,M.gprojection=h.posx*M.gnormx+h.posy*M.gnormy+M.lprojection,M.tp0=v.y*M.gnormx-v.x*M.gnormy,M.tp1=E.y*M.gnormx-E.x*M.gnormy,v=E,C=C.next}let w=P.gverts.next,O=b.elt;b=b.next,O.gnormx=h.axisy*O.lnormx-h.axisx*O.lnormy,O.gnormy=O.lnormx*h.axisx+O.lnormy*h.axisy,O.gprojection=h.posx*O.gnormx+h.posy*O.gnormy+O.lprojection,O.tp0=v.y*O.gnormx-v.x*O.gnormy,O.tp1=w.y*O.gnormx-w.x*O.gnormy}}if(!u.sweepFrozen){let _=n*e,f=_-u.sweepTime;if(f!=0){u.sweepTime=_;let P=f;if(u.posx+=u.velx*P,u.posy+=u.vely*P,u.angvel!=0){let k=u.sweep_angvel*f;if(u.rot+=k,k*k>1e-4)u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot);else{let m=k*k,b=1-.5*m,C=1-m*m/8,v=(b*u.axisx+k*u.axisy)*C;u.axisy=(b*u.axisy-k*u.axisx)*C,u.axisx=v}}}let z=l.s2;if(z.type==0)z.worldCOMx=u.posx+(u.axisy*z.localCOMx-u.axisx*z.localCOMy),z.worldCOMy=u.posy+(z.localCOMx*u.axisx+z.localCOMy*u.axisy);else{let P=z.polygon,k=P.lverts.next,m=P.gverts.next;for(;m!=null;){let E=m,M=k;k=k.next,E.x=u.posx+(u.axisy*M.x-u.axisx*M.y),E.y=u.posy+(M.x*u.axisx+M.y*u.axisy),m=m.next}let b=P.edges.head,C=P.gverts.next,v=C;for(C=C.next;C!=null;){let E=C,M=b.elt;b=b.next,M.gnormx=u.axisy*M.lnormx-u.axisx*M.lnormy,M.gnormy=M.lnormx*u.axisx+M.lnormy*u.axisy,M.gprojection=u.posx*M.gnormx+u.posy*M.gnormy+M.lprojection,M.tp0=v.y*M.gnormx-v.x*M.gnormy,M.tp1=E.y*M.gnormx-E.x*M.gnormy,v=E,C=C.next}let w=P.gverts.next,O=b.elt;b=b.next,O.gnormx=u.axisy*O.lnormx-u.axisx*O.lnormy,O.gnormy=O.lnormx*u.axisx+O.lnormy*u.axisy,O.gprojection=u.posx*O.gnormx+u.posy*O.gnormy+O.lprojection,O.tp0=v.y*O.gnormx-v.x*O.gnormy,O.tp1=w.y*O.gnormx-w.x*O.gnormy}}let x=l.arbiter==null,y=this.narrowPhase(l.s1,l.s2,!0,l.arbiter,!0);if(y==null)l.arbiter!=null&&l.arbiter.pair!=null&&(l.arbiter.pair.arb=null,l.arbiter.pair=null);else if(!this.presteparb(y,e,!0)&&y.type==Ve.COL&&y.active&&(y.immState&1)!=0){let _=y.colarb,f=_.nx*_.c1.jnAcc-_.ny*_.c1.jtAcc,z=_.ny*_.c1.jnAcc+_.nx*_.c1.jtAcc,P=_.b1.imass;_.b1.velx-=f*P,_.b1.vely-=z*P,_.b1.angvel-=_.b1.iinertia*(z*_.c1.r1x-f*_.c1.r1y);let k=_.b2.imass;if(_.b2.velx+=f*k,_.b2.vely+=z*k,_.b2.angvel+=_.b2.iinertia*(z*_.c1.r2x-f*_.c1.r2y),_.hc2){let pe=_.nx*_.c2.jnAcc-_.ny*_.c2.jtAcc,ce=_.ny*_.c2.jnAcc+_.nx*_.c2.jtAcc,ae=_.b1.imass;_.b1.velx-=pe*ae,_.b1.vely-=ce*ae,_.b1.angvel-=_.b1.iinertia*(ce*_.c2.r1x-pe*_.c2.r1y);let ue=_.b2.imass;_.b2.velx+=pe*ue,_.b2.vely+=ce*ue,_.b2.angvel+=_.b2.iinertia*(ce*_.c2.r2x-pe*_.c2.r2y)}_.b2.angvel+=_.jrAcc*_.b2.iinertia,_.b1.angvel-=_.jrAcc*_.b1.iinertia;let m=y.colarb,b=m.k1x+m.b2.velx-m.c1.r2y*m.b2.angvel-(m.b1.velx-m.c1.r1y*m.b1.angvel),C=m.k1y+m.b2.vely+m.c1.r2x*m.b2.angvel-(m.b1.vely+m.c1.r1x*m.b1.angvel),v=(C*m.nx-b*m.ny+m.surfacex)*m.c1.tMass,w=m.c1.friction*m.c1.jnAcc,O=m.c1.jtAcc,E=O-v;E>w?E=w:E<-w&&(E=-w),v=E-O,m.c1.jtAcc=E;let M=-m.ny*v,N=m.nx*v;if(m.b2.velx+=M*m.b2.imass,m.b2.vely+=N*m.b2.imass,m.b1.velx-=M*m.b1.imass,m.b1.vely-=N*m.b1.imass,m.b2.angvel+=m.rt1b*v*m.b2.iinertia,m.b1.angvel-=m.rt1a*v*m.b1.iinertia,m.hc2){let pe=m.k2x+m.b2.velx-m.c2.r2y*m.b2.angvel-(m.b1.velx-m.c2.r1y*m.b1.angvel),ce=m.k2y+m.b2.vely+m.c2.r2x*m.b2.angvel-(m.b1.vely+m.c2.r1x*m.b1.angvel);v=(ce*m.nx-pe*m.ny+m.surfacex)*m.c2.tMass,w=m.c2.friction*m.c2.jnAcc,O=m.c2.jtAcc,E=O-v,E>w?E=w:E<-w&&(E=-w),v=E-O,m.c2.jtAcc=E,M=-m.ny*v,N=m.nx*v,m.b2.velx+=M*m.b2.imass,m.b2.vely+=N*m.b2.imass,m.b1.velx-=M*m.b1.imass,m.b1.vely-=N*m.b1.imass,m.b2.angvel+=m.rt2b*v*m.b2.iinertia,m.b1.angvel-=m.rt2a*v*m.b1.iinertia,b=m.k1x+m.b2.velx-m.c1.r2y*m.b2.angvel-(m.b1.velx-m.c1.r1y*m.b1.angvel),C=m.k1y+m.b2.vely+m.c1.r2x*m.b2.angvel-(m.b1.vely+m.c1.r1x*m.b1.angvel),pe=m.k2x+m.b2.velx-m.c2.r2y*m.b2.angvel-(m.b1.velx-m.c2.r1y*m.b1.angvel),ce=m.k2y+m.b2.vely+m.c2.r2x*m.b2.angvel-(m.b1.vely+m.c2.r1x*m.b1.angvel);let ae=m.c1.jnAcc,ue=m.c2.jnAcc,ne=b*m.nx+C*m.ny+m.surfacey+m.c1.bounce-(m.Ka*ae+m.Kb*ue),he=pe*m.nx+ce*m.ny+m.surfacey+m.c2.bounce-(m.Kb*ae+m.Kc*ue),ye=-(m.kMassa*ne+m.kMassb*he),de=-(m.kMassb*ne+m.kMassc*he);ye>=0&&de>=0?(ne=ye-ae,he=de-ue,m.c1.jnAcc=ye,m.c2.jnAcc=de):(ye=-m.c1.nMass*ne,ye>=0&&m.Kb*ye+he>=0?(ne=ye-ae,he=-ue,m.c1.jnAcc=ye,m.c2.jnAcc=0):(de=-m.c2.nMass*he,de>=0&&m.Kb*de+ne>=0?(ne=-ae,he=de-ue,m.c1.jnAcc=0,m.c2.jnAcc=de):ne>=0&&he>=0?(ne=-ae,he=-ue,m.c1.jnAcc=m.c2.jnAcc=0):(ne=0,he=0))),v=ne+he,M=m.nx*v,N=m.ny*v,m.b2.velx+=M*m.b2.imass,m.b2.vely+=N*m.b2.imass,m.b1.velx-=M*m.b1.imass,m.b1.vely-=N*m.b1.imass,m.b2.angvel+=(m.rn1b*ne+m.rn2b*he)*m.b2.iinertia,m.b1.angvel-=(m.rn1a*ne+m.rn2a*he)*m.b1.iinertia}else m.radius!=0&&(v=(m.b2.angvel-m.b1.angvel)*m.rMass,w=m.rfric*m.c1.jnAcc,O=m.jrAcc,m.jrAcc-=v,m.jrAcc>w?m.jrAcc=w:m.jrAcc<-w&&(m.jrAcc=-w),v=m.jrAcc-O,m.b2.angvel+=v*m.b2.iinertia,m.b1.angvel-=v*m.b1.iinertia),b=m.k1x+m.b2.velx-m.c1.r2y*m.b2.angvel-(m.b1.velx-m.c1.r1y*m.b1.angvel),C=m.k1y+m.b2.vely+m.c1.r2x*m.b2.angvel-(m.b1.vely+m.c1.r1x*m.b1.angvel),v=(m.c1.bounce+(m.nx*b+m.ny*C)+m.surfacey)*m.c1.nMass,O=m.c1.jnAcc,E=O-v,E<0&&(E=0),v=E-O,m.c1.jnAcc=E,M=m.nx*v,N=m.ny*v,m.b2.velx+=M*m.b2.imass,m.b2.vely+=N*m.b2.imass,m.b1.velx-=M*m.b1.imass,m.b1.vely-=N*m.b1.imass,m.b2.angvel+=m.rn1b*v*m.b2.iinertia,m.b1.angvel-=m.rn1a*v*m.b1.iinertia;let Z=y.colarb,S=Z.k1x+Z.b2.velx-Z.c1.r2y*Z.b2.angvel-(Z.b1.velx-Z.c1.r1y*Z.b1.angvel),V=Z.k1y+Z.b2.vely+Z.c1.r2x*Z.b2.angvel-(Z.b1.vely+Z.c1.r1x*Z.b1.angvel),D=(V*Z.nx-S*Z.ny+Z.surfacex)*Z.c1.tMass,T=Z.c1.friction*Z.c1.jnAcc,G=Z.c1.jtAcc,q=G-D;q>T?q=T:q<-T&&(q=-T),D=q-G,Z.c1.jtAcc=q;let R=-Z.ny*D,j=Z.nx*D;if(Z.b2.velx+=R*Z.b2.imass,Z.b2.vely+=j*Z.b2.imass,Z.b1.velx-=R*Z.b1.imass,Z.b1.vely-=j*Z.b1.imass,Z.b2.angvel+=Z.rt1b*D*Z.b2.iinertia,Z.b1.angvel-=Z.rt1a*D*Z.b1.iinertia,Z.hc2){let pe=Z.k2x+Z.b2.velx-Z.c2.r2y*Z.b2.angvel-(Z.b1.velx-Z.c2.r1y*Z.b1.angvel),ce=Z.k2y+Z.b2.vely+Z.c2.r2x*Z.b2.angvel-(Z.b1.vely+Z.c2.r1x*Z.b1.angvel);D=(ce*Z.nx-pe*Z.ny+Z.surfacex)*Z.c2.tMass,T=Z.c2.friction*Z.c2.jnAcc,G=Z.c2.jtAcc,q=G-D,q>T?q=T:q<-T&&(q=-T),D=q-G,Z.c2.jtAcc=q,R=-Z.ny*D,j=Z.nx*D,Z.b2.velx+=R*Z.b2.imass,Z.b2.vely+=j*Z.b2.imass,Z.b1.velx-=R*Z.b1.imass,Z.b1.vely-=j*Z.b1.imass,Z.b2.angvel+=Z.rt2b*D*Z.b2.iinertia,Z.b1.angvel-=Z.rt2a*D*Z.b1.iinertia,S=Z.k1x+Z.b2.velx-Z.c1.r2y*Z.b2.angvel-(Z.b1.velx-Z.c1.r1y*Z.b1.angvel),V=Z.k1y+Z.b2.vely+Z.c1.r2x*Z.b2.angvel-(Z.b1.vely+Z.c1.r1x*Z.b1.angvel),pe=Z.k2x+Z.b2.velx-Z.c2.r2y*Z.b2.angvel-(Z.b1.velx-Z.c2.r1y*Z.b1.angvel),ce=Z.k2y+Z.b2.vely+Z.c2.r2x*Z.b2.angvel-(Z.b1.vely+Z.c2.r1x*Z.b1.angvel);let ae=Z.c1.jnAcc,ue=Z.c2.jnAcc,ne=S*Z.nx+V*Z.ny+Z.surfacey+Z.c1.bounce-(Z.Ka*ae+Z.Kb*ue),he=pe*Z.nx+ce*Z.ny+Z.surfacey+Z.c2.bounce-(Z.Kb*ae+Z.Kc*ue),ye=-(Z.kMassa*ne+Z.kMassb*he),de=-(Z.kMassb*ne+Z.kMassc*he);ye>=0&&de>=0?(ne=ye-ae,he=de-ue,Z.c1.jnAcc=ye,Z.c2.jnAcc=de):(ye=-Z.c1.nMass*ne,ye>=0&&Z.Kb*ye+he>=0?(ne=ye-ae,he=-ue,Z.c1.jnAcc=ye,Z.c2.jnAcc=0):(de=-Z.c2.nMass*he,de>=0&&Z.Kb*de+ne>=0?(ne=-ae,he=de-ue,Z.c1.jnAcc=0,Z.c2.jnAcc=de):ne>=0&&he>=0?(ne=-ae,he=-ue,Z.c1.jnAcc=Z.c2.jnAcc=0):(ne=0,he=0))),D=ne+he,R=Z.nx*D,j=Z.ny*D,Z.b2.velx+=R*Z.b2.imass,Z.b2.vely+=j*Z.b2.imass,Z.b1.velx-=R*Z.b1.imass,Z.b1.vely-=j*Z.b1.imass,Z.b2.angvel+=(Z.rn1b*ne+Z.rn2b*he)*Z.b2.iinertia,Z.b1.angvel-=(Z.rn1a*ne+Z.rn2a*he)*Z.b1.iinertia}else Z.radius!=0&&(D=(Z.b2.angvel-Z.b1.angvel)*Z.rMass,T=Z.rfric*Z.c1.jnAcc,G=Z.jrAcc,Z.jrAcc-=D,Z.jrAcc>T?Z.jrAcc=T:Z.jrAcc<-T&&(Z.jrAcc=-T),D=Z.jrAcc-G,Z.b2.angvel+=D*Z.b2.iinertia,Z.b1.angvel-=D*Z.b1.iinertia),S=Z.k1x+Z.b2.velx-Z.c1.r2y*Z.b2.angvel-(Z.b1.velx-Z.c1.r1y*Z.b1.angvel),V=Z.k1y+Z.b2.vely+Z.c1.r2x*Z.b2.angvel-(Z.b1.vely+Z.c1.r1x*Z.b1.angvel),D=(Z.c1.bounce+(Z.nx*S+Z.ny*V)+Z.surfacey)*Z.c1.nMass,G=Z.c1.jnAcc,q=G-D,q<0&&(q=0),D=q-G,Z.c1.jnAcc=q,R=Z.nx*D,j=Z.ny*D,Z.b2.velx+=R*Z.b2.imass,Z.b2.vely+=j*Z.b2.imass,Z.b1.velx-=R*Z.b1.imass,Z.b1.vely-=j*Z.b1.imass,Z.b2.angvel+=Z.rn1b*D*Z.b2.iinertia,Z.b1.angvel-=Z.rn1a*D*Z.b1.iinertia;let A=y.colarb,W=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),Q=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),Y=(Q*A.nx-W*A.ny+A.surfacex)*A.c1.tMass,X=A.c1.friction*A.c1.jnAcc,ee=A.c1.jtAcc,J=ee-Y;J>X?J=X:J<-X&&(J=-X),Y=J-ee,A.c1.jtAcc=J;let L=-A.ny*Y,F=A.nx*Y;if(A.b2.velx+=L*A.b2.imass,A.b2.vely+=F*A.b2.imass,A.b1.velx-=L*A.b1.imass,A.b1.vely-=F*A.b1.imass,A.b2.angvel+=A.rt1b*Y*A.b2.iinertia,A.b1.angvel-=A.rt1a*Y*A.b1.iinertia,A.hc2){let pe=A.k2x+A.b2.velx-A.c2.r2y*A.b2.angvel-(A.b1.velx-A.c2.r1y*A.b1.angvel),ce=A.k2y+A.b2.vely+A.c2.r2x*A.b2.angvel-(A.b1.vely+A.c2.r1x*A.b1.angvel);Y=(ce*A.nx-pe*A.ny+A.surfacex)*A.c2.tMass,X=A.c2.friction*A.c2.jnAcc,ee=A.c2.jtAcc,J=ee-Y,J>X?J=X:J<-X&&(J=-X),Y=J-ee,A.c2.jtAcc=J,L=-A.ny*Y,F=A.nx*Y,A.b2.velx+=L*A.b2.imass,A.b2.vely+=F*A.b2.imass,A.b1.velx-=L*A.b1.imass,A.b1.vely-=F*A.b1.imass,A.b2.angvel+=A.rt2b*Y*A.b2.iinertia,A.b1.angvel-=A.rt2a*Y*A.b1.iinertia,W=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),Q=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),pe=A.k2x+A.b2.velx-A.c2.r2y*A.b2.angvel-(A.b1.velx-A.c2.r1y*A.b1.angvel),ce=A.k2y+A.b2.vely+A.c2.r2x*A.b2.angvel-(A.b1.vely+A.c2.r1x*A.b1.angvel);let ae=A.c1.jnAcc,ue=A.c2.jnAcc,ne=W*A.nx+Q*A.ny+A.surfacey+A.c1.bounce-(A.Ka*ae+A.Kb*ue),he=pe*A.nx+ce*A.ny+A.surfacey+A.c2.bounce-(A.Kb*ae+A.Kc*ue),ye=-(A.kMassa*ne+A.kMassb*he),de=-(A.kMassb*ne+A.kMassc*he);ye>=0&&de>=0?(ne=ye-ae,he=de-ue,A.c1.jnAcc=ye,A.c2.jnAcc=de):(ye=-A.c1.nMass*ne,ye>=0&&A.Kb*ye+he>=0?(ne=ye-ae,he=-ue,A.c1.jnAcc=ye,A.c2.jnAcc=0):(de=-A.c2.nMass*he,de>=0&&A.Kb*de+ne>=0?(ne=-ae,he=de-ue,A.c1.jnAcc=0,A.c2.jnAcc=de):ne>=0&&he>=0?(ne=-ae,he=-ue,A.c1.jnAcc=A.c2.jnAcc=0):(ne=0,he=0))),Y=ne+he,L=A.nx*Y,F=A.ny*Y,A.b2.velx+=L*A.b2.imass,A.b2.vely+=F*A.b2.imass,A.b1.velx-=L*A.b1.imass,A.b1.vely-=F*A.b1.imass,A.b2.angvel+=(A.rn1b*ne+A.rn2b*he)*A.b2.iinertia,A.b1.angvel-=(A.rn1a*ne+A.rn2a*he)*A.b1.iinertia}else A.radius!=0&&(Y=(A.b2.angvel-A.b1.angvel)*A.rMass,X=A.rfric*A.c1.jnAcc,ee=A.jrAcc,A.jrAcc-=Y,A.jrAcc>X?A.jrAcc=X:A.jrAcc<-X&&(A.jrAcc=-X),Y=A.jrAcc-ee,A.b2.angvel+=Y*A.b2.iinertia,A.b1.angvel-=Y*A.b1.iinertia),W=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),Q=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),Y=(A.c1.bounce+(A.nx*W+A.ny*Q)+A.surfacey)*A.c1.nMass,ee=A.c1.jnAcc,J=ee-Y,J<0&&(J=0),Y=J-ee,A.c1.jnAcc=J,L=A.nx*Y,F=A.ny*Y,A.b2.velx+=L*A.b2.imass,A.b2.vely+=F*A.b2.imass,A.b1.velx-=L*A.b1.imass,A.b1.vely-=F*A.b1.imass,A.b2.angvel+=A.rn1b*Y*A.b2.iinertia,A.b1.angvel-=A.rn1a*Y*A.b1.iinertia;let I=y.colarb,U=I.k1x+I.b2.velx-I.c1.r2y*I.b2.angvel-(I.b1.velx-I.c1.r1y*I.b1.angvel),$=I.k1y+I.b2.vely+I.c1.r2x*I.b2.angvel-(I.b1.vely+I.c1.r1x*I.b1.angvel),K=($*I.nx-U*I.ny+I.surfacex)*I.c1.tMass,ie=I.c1.friction*I.c1.jnAcc,re=I.c1.jtAcc,se=re-K;se>ie?se=ie:se<-ie&&(se=-ie),K=se-re,I.c1.jtAcc=se;let te=-I.ny*K,oe=I.nx*K;if(I.b2.velx+=te*I.b2.imass,I.b2.vely+=oe*I.b2.imass,I.b1.velx-=te*I.b1.imass,I.b1.vely-=oe*I.b1.imass,I.b2.angvel+=I.rt1b*K*I.b2.iinertia,I.b1.angvel-=I.rt1a*K*I.b1.iinertia,I.hc2){let pe=I.k2x+I.b2.velx-I.c2.r2y*I.b2.angvel-(I.b1.velx-I.c2.r1y*I.b1.angvel),ce=I.k2y+I.b2.vely+I.c2.r2x*I.b2.angvel-(I.b1.vely+I.c2.r1x*I.b1.angvel);K=(ce*I.nx-pe*I.ny+I.surfacex)*I.c2.tMass,ie=I.c2.friction*I.c2.jnAcc,re=I.c2.jtAcc,se=re-K,se>ie?se=ie:se<-ie&&(se=-ie),K=se-re,I.c2.jtAcc=se,te=-I.ny*K,oe=I.nx*K,I.b2.velx+=te*I.b2.imass,I.b2.vely+=oe*I.b2.imass,I.b1.velx-=te*I.b1.imass,I.b1.vely-=oe*I.b1.imass,I.b2.angvel+=I.rt2b*K*I.b2.iinertia,I.b1.angvel-=I.rt2a*K*I.b1.iinertia,U=I.k1x+I.b2.velx-I.c1.r2y*I.b2.angvel-(I.b1.velx-I.c1.r1y*I.b1.angvel),$=I.k1y+I.b2.vely+I.c1.r2x*I.b2.angvel-(I.b1.vely+I.c1.r1x*I.b1.angvel),pe=I.k2x+I.b2.velx-I.c2.r2y*I.b2.angvel-(I.b1.velx-I.c2.r1y*I.b1.angvel),ce=I.k2y+I.b2.vely+I.c2.r2x*I.b2.angvel-(I.b1.vely+I.c2.r1x*I.b1.angvel);let ae=I.c1.jnAcc,ue=I.c2.jnAcc,ne=U*I.nx+$*I.ny+I.surfacey+I.c1.bounce-(I.Ka*ae+I.Kb*ue),he=pe*I.nx+ce*I.ny+I.surfacey+I.c2.bounce-(I.Kb*ae+I.Kc*ue),ye=-(I.kMassa*ne+I.kMassb*he),de=-(I.kMassb*ne+I.kMassc*he);ye>=0&&de>=0?(ne=ye-ae,he=de-ue,I.c1.jnAcc=ye,I.c2.jnAcc=de):(ye=-I.c1.nMass*ne,ye>=0&&I.Kb*ye+he>=0?(ne=ye-ae,he=-ue,I.c1.jnAcc=ye,I.c2.jnAcc=0):(de=-I.c2.nMass*he,de>=0&&I.Kb*de+ne>=0?(ne=-ae,he=de-ue,I.c1.jnAcc=0,I.c2.jnAcc=de):ne>=0&&he>=0?(ne=-ae,he=-ue,I.c1.jnAcc=I.c2.jnAcc=0):(ne=0,he=0))),K=ne+he,te=I.nx*K,oe=I.ny*K,I.b2.velx+=te*I.b2.imass,I.b2.vely+=oe*I.b2.imass,I.b1.velx-=te*I.b1.imass,I.b1.vely-=oe*I.b1.imass,I.b2.angvel+=(I.rn1b*ne+I.rn2b*he)*I.b2.iinertia,I.b1.angvel-=(I.rn1a*ne+I.rn2a*he)*I.b1.iinertia}else I.radius!=0&&(K=(I.b2.angvel-I.b1.angvel)*I.rMass,ie=I.rfric*I.c1.jnAcc,re=I.jrAcc,I.jrAcc-=K,I.jrAcc>ie?I.jrAcc=ie:I.jrAcc<-ie&&(I.jrAcc=-ie),K=I.jrAcc-re,I.b2.angvel+=K*I.b2.iinertia,I.b1.angvel-=K*I.b1.iinertia),U=I.k1x+I.b2.velx-I.c1.r2y*I.b2.angvel-(I.b1.velx-I.c1.r1y*I.b1.angvel),$=I.k1y+I.b2.vely+I.c1.r2x*I.b2.angvel-(I.b1.vely+I.c1.r1x*I.b1.angvel),K=(I.c1.bounce+(I.nx*U+I.ny*$)+I.surfacey)*I.c1.nMass,re=I.c1.jnAcc,se=re-K,se<0&&(se=0),K=se-re,I.c1.jnAcc=se,te=I.nx*K,oe=I.ny*K,I.b2.velx+=te*I.b2.imass,I.b2.vely+=oe*I.b2.imass,I.b1.velx-=te*I.b1.imass,I.b1.vely-=oe*I.b1.imass,I.b2.angvel+=I.rn1b*K*I.b2.iinertia,I.b1.angvel-=I.rn1a*K*I.b1.iinertia;h.sweep_angvel=h.angvel%t,u.sweep_angvel=u.angvel%t}if(y!=null&&y.active&&(y.immState&1)!=0&&y.type==Ve.COL){if(!h.sweepFrozen&&h.type!=3)if(h.sweepFrozen=!0,l.failed)h.angvel=h.sweep_angvel=0;else if(l.slipped){let _=h;_.sweep_angvel*=B._nape.Config.angularCCDSlipScale,h.angvel=_.sweep_angvel}else h.angvel=h.sweep_angvel;if(!u.sweepFrozen&&u.type!=3)if(u.sweepFrozen=!0,l.failed)u.angvel=u.sweep_angvel=0;else if(l.slipped){let _=u;_.sweep_angvel*=B._nape.Config.angularCCDSlipScale,u.angvel=_.sweep_angvel}else u.angvel=u.sweep_angvel}let d=l;d.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=d}for(;this.toiEvents.head!=null;){let r=this.toiEvents.pop_unsafe();r.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=r}let s=this.kinematics.head;for(;s!=null;){let l=s.elt,r=e-l.sweepTime;if(r!=0){l.sweepTime=e;let a=r;if(l.posx+=l.velx*a,l.posy+=l.vely*a,l.angvel!=0){let o=l.sweep_angvel*r;if(l.rot+=o,o*o>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=o*o,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+o*l.axisy)*h;l.axisy=(c*l.axisy-o*l.axisx)*h,l.axisx=u}}}l.sweepTime=0,s=s.next}let i=this.live.head;for(;i!=null;){let l=i.elt;if(!l.sweepFrozen){let r=e-l.sweepTime;if(r!=0){l.sweepTime=e;let a=r;if(l.posx+=l.velx*a,l.posy+=l.vely*a,l.angvel!=0){let o=l.sweep_angvel*r;if(l.rot+=o,o*o>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=o*o,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+o*l.axisy)*h;l.axisy=(c*l.axisy-o*l.axisx)*h,l.axisx=u}}}}l.sweepTime=0,i=i.next}}continuousEvent(e,t,n,s,i){if(e.body.sweepFrozen&&t.body.sweepFrozen||e.body.disableCCD||t.body.disableCCD)return s;let l;if(s!=null&&s.colarb==null)l=!0;else{let o=e.body,p=t.body,c;c=!1;let h=o.constraints.head;for(;h!=null;){let y=h.elt;if(y.ignore&&y.pair_exists(o.id,p.id)){c=!0;break}h=h.next}let u,x;if(c)x=!1;else{let y=e;for(;y!=null&&y.group==null;)y.ishape!=null?y=y.ishape.body:y.icompound!=null?y=y.icompound.compound:y=y.ibody.compound;let d=y==null?null:y.group,_;if(d==null)_=!1;else{let f=t;for(;f!=null&&f.group==null;)f.ishape!=null?f=f.ishape.body:f.icompound!=null?f=f.icompound.compound:f=f.ibody.compound;let z=f==null?null:f.group;if(z==null)_=!1;else{let P=!1;for(;d!=null&&z!=null;){if(d==z){P=d.ignore;break}d.depth<z.depth?z=z.group:d=d.group}_=P}}x=!_}if(x){let y;if(e.sensorEnabled||t.sensorEnabled){let d=e.filter,_=t.filter;y=(d.sensorMask&_.sensorGroup)!=0&&(_.sensorMask&d.sensorGroup)!=0}else y=!1;if(y)u=2;else{let d;if(e.fluidEnabled||t.fluidEnabled){let _=e.filter,f=t.filter;d=(_.fluidMask&f.fluidGroup)!=0&&(f.fluidMask&_.fluidGroup)!=0}else d=!1;if(d&&!(o.imass==0&&p.imass==0&&o.iinertia==0&&p.iinertia==0))u=0;else{let _=e.filter,f=t.filter;u=(_.collisionMask&f.collisionGroup)!=0&&(f.collisionMask&_.collisionGroup)!=0&&!(o.imass==0&&p.imass==0&&o.iinertia==0&&p.iinertia==0)?1:-1}}}else u=-1;l=u<=0}if(l)return s;let r=e.body,a=t.body;if(n||r.bullet||a.bullet){let o;B._zpp.geom.ZPP_ToiEvent.zpp_pool==null?o=new B._zpp.geom.ZPP_ToiEvent:(o=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=o.next,o.next=null),o.failed=!1,o.s1=o.s2=null,o.arbiter=null;let p=r.type==3||a.type==3;if(n&&!p)e.body.type!=2?(o.s2=e,o.s1=t):(o.s1=e,o.s2=t),o.kinematic=!1,wn.staticSweep(o,this.pre_dt,0,B._nape.Config.collisionSlopCCD);else if(o.s1=e,o.s2=t,o.kinematic=p,o.s1.body.sweepFrozen||o.s2.body.sweepFrozen){if(o.s1.body.sweepFrozen){let c=o.s1;o.s1=o.s2,o.s2=c,o.frozen1=!1,o.frozen2=!0}wn.staticSweep(o,this.pre_dt,0,B._nape.Config.collisionSlopCCD)}else wn.dynamicSweep(o,this.pre_dt,0,B._nape.Config.collisionSlopCCD,!1);if(n&&o.toi<0||o.failed){let c=o;c.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=c}else this.toiEvents.add(o),o.frozen1=o.s1.body.sweepFrozen,o.frozen2=o.s2.body.sweepFrozen,o.arbiter=s!=null?s.colarb:null}return s}bodyCbWake(e){if(e.type==2&&e.cbSet!=null)if(this.midstep){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let s=this.push_callback(n);s.event=2,s.body=e,t=t.next}}else e.component.woken=!0}bodyCbSleep(e){if(e.type==2&&e.cbSet!=null){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let s=this.push_callback(n);s.event=3,s.body=e,t=t.next}}}constraintCbWake(e){if(e.cbSet!=null)if(this.midstep){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let s=this.push_callback(n);s.event=2,s.constraint=e,t=t.next}}else e.component.woken=!0}constraintCbSleep(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let s=this.push_callback(n);s.event=3,s.constraint=e,t=t.next}}}constraintCbBreak(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=4){t=t.next;continue}let s=this.push_callback(n);s.event=4,s.constraint=e,t=t.next}}}nullListenerType(e,t){let n=new B._zpp.util.ZNPList_ZPP_Interactor,s=e.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next}if(e!=t){let i=t.interactors.head;for(;i!=null;){let l=i.elt;n.add(l),i=i.next}}for(;n.head!=null;){let i=n.pop_unsafe();if(i.icompound!=null){let l=i.icompound,r=l.bodies.head;for(;r!=null;){let o=r.elt;n.add(o),r=r.next}let a=l.compounds.head;for(;a!=null;){let o=a.elt;n.add(o),a=a.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,r=i.ishape!=null?i.ishape:null,a=l.arbiters.head;for(;a!=null;){let o=a.elt;if(o.present==0){a=a.next;continue}if(r!=null&&!(o.ws1==r||o.ws2==r)){a=a.next;continue}this.MRCA_chains(o.ws1,o.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let h=this.mrca2.head;for(;h!=null;){let u=h.elt;if(c.cbSet==e&&u.cbSet!=t||c.cbSet==t&&u.cbSet!=e){h=h.next;continue}let x=B._zpp.phys.ZPP_Interactor.get(c,u);if(x!=null){for(;x.arbiters.head!=null;){let y=x.arbiters.pop_unsafe();y.present--}this.remove_callbackset(x)}h=h.next}p=p.next}a=a.next}}}}nullInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,s=n.bodies.head;for(;s!=null;){let l=s.elt;this.nullInteractorType(l,t),s=s.next}let i=n.compounds.head;for(;i!=null;){let l=i.elt;this.nullInteractorType(l,t),i=i.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,s=e.ishape!=null?e.ishape:null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(l.present==0){i=i.next;continue}if(s!=null&&!(l.ws1==s||l.ws2==s)){i=i.next;continue}this.MRCA_chains(l.ws1,l.ws2);let r=this.mrca1.head;for(;r!=null;){let a=r.elt,o=this.mrca2.head;for(;o!=null;){let p=o.elt;if(a!=t&&p!=t){o=o.next;continue}let c=B._zpp.phys.ZPP_Interactor.get(a,p);c!=null&&(l.present--,c.remove_arb(l),c.arbiters.head==null&&this.remove_callbackset(c)),o=o.next}r=r.next}i=i.next}}}freshListenerType(e,t){let n=new B._zpp.util.ZNPList_ZPP_Interactor,s=e.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next}if(e!=t){let i=t.interactors.head;for(;i!=null;){let l=i.elt;n.add(l),i=i.next}}for(;n.head!=null;){let i=n.pop_unsafe();if(i.icompound!=null){let l=i.icompound,r=l.bodies.head;for(;r!=null;){let o=r.elt;n.add(o),r=r.next}let a=l.compounds.head;for(;a!=null;){let o=a.elt;n.add(o),a=a.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,r=i.ishape!=null?i.ishape:null,a=l.arbiters.head;for(;a!=null;){let o=a.elt;if(!o.presentable){a=a.next;continue}if(r!=null&&!(o.ws1==r||o.ws2==r)){a=a.next;continue}this.MRCA_chains(o.ws1,o.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let h=this.mrca2.head;for(;h!=null;){let u=h.elt;if(c.cbSet==e&&u.cbSet!=t||c.cbSet==t&&u.cbSet!=e){h=h.next;continue}let x=B._zpp.phys.ZPP_Interactor.get(c,u);x==null&&(x=qt.get(c,u),this.add_callbackset(x));let y,d;d=!1;let _=x.arbiters.head;for(;_!=null;){if(_.elt==o){d=!0;break}_=_.next}if(d)y=!1;else{let f=x.arbiters,z;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?z=new B._zpp.util.ZNPNode_ZPP_Arbiter:(z=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=z.next,z.next=null),z.elt=o;let P=z;P.next=f.head,f.head=P,f.modified=!0,f.length++,y=!0}y&&o.present++,h=h.next}p=p.next}a=a.next}}}}freshInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,s=n.bodies.head;for(;s!=null;){let l=s.elt;this.freshInteractorType(l,t),s=s.next}let i=n.compounds.head;for(;i!=null;){let l=i.elt;this.freshInteractorType(l,t),i=i.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,s=e.ishape!=null?e.ishape:null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(!l.presentable){i=i.next;continue}if(s!=null&&!(l.ws1==s||l.ws2==s)){i=i.next;continue}this.MRCA_chains(l.ws1,l.ws2);let r=this.mrca1.head;for(;r!=null;){let a=r.elt,o=this.mrca2.head;for(;o!=null;){let p=o.elt;if(a!=t&&p!=t){o=o.next;continue}let c=a.cbSet,h=p.cbSet;c.validate(),h.validate();let u=c.manager,x=null,d=(c.cbpairs.length<h.cbpairs.length?c.cbpairs:h.cbpairs).head;for(;d!=null;){let _=d.elt;if(_.a==c&&_.b==h||_.a==h&&_.b==c){x=_;break}d=d.next}if(x==null){let _;Ne.zpp_pool==null?_=new Ne:(_=Ne.zpp_pool,Ne.zpp_pool=_.next,_.next=null),_.zip_listeners=!0,dt.setlt(c,h)?(_.a=c,_.b=h):(_.a=h,_.b=c),x=_,c.cbpairs.add(x),h!=c&&h.cbpairs.add(x)}if(x.zip_listeners&&(x.zip_listeners=!1,x.__validate()),x.listeners.head!=null){let _=B._zpp.phys.ZPP_Interactor.get(a,p);_==null&&(_=qt.get(a,p),this.add_callbackset(_));let f,z;z=!1;let P=_.arbiters.head;for(;P!=null;){if(P.elt==l){z=!0;break}P=P.next}if(z)f=!1;else{let k=_.arbiters,m;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?m=new B._zpp.util.ZNPNode_ZPP_Arbiter:(m=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=m.next,m.next=null),m.elt=l;let b=m;b.next=k.head,k.head=b,k.modified=!0,k.length++,f=!0}f&&l.present++}o=o.next}r=r.next}i=i.next}}}wakeCompound(e){let t=e.bodies.head;for(;t!=null;){let l=t.elt;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!1)),t=t.next}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.wake_constraint(i),n=n.next}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.wakeCompound(i),s=s.next}}wakeIsland(e){for(;e.comps.head!=null;){let n=e.comps.pop_unsafe();if(n.waket=this.stamp+(this.midstep?0:1),n.isBody){let s=n.body;this.live.add(s);let i=s.arbiters.head;for(;i!=null;){let l=i.elt;if(l.sleeping)if(l.sleeping=!1,l.up_stamp+=this.stamp-l.sleep_stamp,l.type==Ve.COL){let r=l.colarb;if(r.stat){let a=this.c_arbiters_true,o;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(o=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=o.next,o.next=null),o.elt=r;let p=o;p.next=a.head,a.head=p,a.modified=!0,a.length++}else{let a=this.c_arbiters_false,o;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(o=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=o.next,o.next=null),o.elt=r;let p=o;p.next=a.head,a.head=p,a.modified=!0,a.length++}}else if(l.type==Ve.FLUID){let r=this.f_arbiters,a=l.fluidarb,o;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(o=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=o.next,o.next=null),o.elt=a;let p=o;p.next=r.head,r.head=p,r.modified=!0,r.length++}else{let r=this.s_arbiters,a=l.sensorarb,o;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(o=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=o.next,o.next=null),o.elt=a;let p=o;p.next=r.head,r.head=p,r.modified=!0,r.length++}i=i.next}if(this.bodyCbWake(s),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0,s.type!=1){let l=s.shapes.head;for(;l!=null;){let r=l.elt;r.node!=null&&this.bphase.sync(r),l=l.next}}}else{let s=n.constraint,i=this.live_constraints,l;B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?l=new B._zpp.util.ZNPNode_ZPP_Constraint:(l=B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=l.next,l.next=null),l.elt=s;let r=l;r.next=i.head,i.head=r,i.modified=!0,i.length++,this.constraintCbWake(s),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0}}let t=e;t.next=ht.zpp_pool,ht.zpp_pool=t}non_inlined_wake(e,t){t==null&&(t=!1);let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,t))}really_wake(e,t){if(t==null&&(t=!1),e.component.island==null){if(e.component.sleeping=!1,e.type==3||e.type==1){let i=this.staticsleep,l;B._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?l=new B._zpp.util.ZNPNode_ZPP_Body:(l=B._zpp.util.ZNPNode_ZPP_Body.zpp_pool,B._zpp.util.ZNPNode_ZPP_Body.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;r.next=i.head,i.head=r,i.modified=!0,i.length++}else{let i=this.live,l;B._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?l=new B._zpp.util.ZNPNode_ZPP_Body:(l=B._zpp.util.ZNPNode_ZPP_Body.zpp_pool,B._zpp.util.ZNPNode_ZPP_Body.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;r.next=i.head,i.head=r,i.modified=!0,i.length++}let n=e.constraints.head;for(;n!=null;){let i=n.elt;i.space==this&&this.wake_constraint(i),n=n.next}let s=e.arbiters.head;for(;s!=null;){let i=s.elt;if(i.sleeping)if(i.sleeping=!1,i.up_stamp+=this.stamp+(this.midstep?0:1)-i.sleep_stamp,i.type==Ve.COL){let l=i.colarb;if(l.stat){let r=this.c_arbiters_true,a;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(a=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=l;let o=a;o.next=r.head,r.head=o,r.modified=!0,r.length++}else{let r=this.c_arbiters_false,a;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(a=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=l;let o=a;o.next=r.head,r.head=o,r.modified=!0,r.length++}}else if(i.type==Ve.FLUID){let l=this.f_arbiters,r=i.fluidarb,a;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?a=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(a=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let o=a;o.next=l.head,l.head=o,l.modified=!0,l.length++}else{let l=this.s_arbiters,r=i.sensorarb,a;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?a=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(a=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let o=a;o.next=l.head,l.head=o,l.modified=!0,l.length++}if(i.type!=Ve.SENSOR&&!i.cleared&&i.up_stamp>=this.stamp&&(i.immState&1)!=0){if(i.b1.type==2&&i.b1.component.sleeping){let l=i.b1;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!1))}if(i.b2.type==2&&i.b2.component.sleeping){let l=i.b2;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!1))}}s=s.next}if(!t&&e.type==2&&this.bodyCbWake(e),!t&&!this.bphase.is_sweep&&e.type!=1){let i=e.shapes.head;for(;i!=null;){let l=i.elt;l.node!=null&&this.bphase.sync(l),i=i.next}}}else this.wakeIsland(e.component.island)}wake_constraint(e,t){if(t==null&&(t=!1),e.active)if(e.component.waket=this.stamp+(this.midstep?0:1),e.component.sleeping){if(e.component.island==null){e.component.sleeping=!1;let n=this.live_constraints,s;B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?s=new B._zpp.util.ZNPNode_ZPP_Constraint:(s=B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=s.next,s.next=null),s.elt=e;let i=s;i.next=n.head,n.head=i,n.modified=!0,n.length++,e.wake_connected(),t||this.constraintCbWake(e)}else this.wakeIsland(e.component.island);return!0}else return!1;else return!1}doForests(e){let t=this.c_arbiters_false.head;for(;t!=null;){let i=t.elt;if(!i.cleared&&i.up_stamp==this.stamp&&(i.immState&1)!=0&&i.b1.type==2&&i.b2.type==2){let l;if(i.b1.component==i.b1.component.parent)l=i.b1.component;else{let a=i.b1.component,o=null;for(;a!=a.parent;){let p=a.parent;a.parent=o,o=a,a=p}for(;o!=null;){let p=o.parent;o.parent=a,o=p}l=a}let r;if(i.b2.component==i.b2.component.parent)r=i.b2.component;else{let a=i.b2.component,o=null;for(;a!=a.parent;){let p=a.parent;a.parent=o,o=a,a=p}for(;o!=null;){let p=o.parent;o.parent=a,o=p}r=a}l!=r&&(l.rank<r.rank?l.parent=r:l.rank>r.rank?r.parent=l:(r.parent=l,l.rank++))}t=t.next}let n=this.f_arbiters.head;for(;n!=null;){let i=n.elt;if(!i.cleared&&i.up_stamp==this.stamp&&(i.immState&1)!=0&&i.b1.type==2&&i.b2.type==2){let l;if(i.b1.component==i.b1.component.parent)l=i.b1.component;else{let a=i.b1.component,o=null;for(;a!=a.parent;){let p=a.parent;a.parent=o,o=a,a=p}for(;o!=null;){let p=o.parent;o.parent=a,o=p}l=a}let r;if(i.b2.component==i.b2.component.parent)r=i.b2.component;else{let a=i.b2.component,o=null;for(;a!=a.parent;){let p=a.parent;a.parent=o,o=a,a=p}for(;o!=null;){let p=o.parent;o.parent=a,o=p}r=a}l!=r&&(l.rank<r.rank?l.parent=r:l.rank>r.rank?r.parent=l:(r.parent=l,l.rank++))}n=n.next}let s=this.live_constraints.head;for(;s!=null;)s.elt.forest(),s=s.next;for(;this.live.head!=null;){let i=this.live,l=i.head.elt;i.pop();let r=l,a=r.component,o;if(a==a.parent)o=a;else{let x=a,y=null;for(;x!=x.parent;){let d=x.parent;x.parent=y,y=x,x=d}for(;y!=null;){let d=y.parent;y.parent=x,y=d}o=x}if(o.island==null){ht.zpp_pool==null?o.island=new ht:(o.island=ht.zpp_pool,ht.zpp_pool=o.island.next,o.island.next=null),o.island.waket=0;let x=this.islands,y=o.island;y._inuse=!0;let d=y;d.next=x.next,x.next=d,x.modified=!0,x.length++,o.island.sleep=!0}a.island=o.island;let p=a.island.comps,c;B._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new B._zpp.util.ZNPNode_ZPP_Component:(c=B._zpp.util.ZNPNode_ZPP_Component.zpp_pool,B._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=a;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++;let u=r.atRest(e);a.island.sleep=a.island.sleep&&u,a.waket>a.island.waket&&(a.island.waket=a.waket)}for(;this.live_constraints.head!=null;){let i=this.live_constraints,l=i.head.elt;i.pop();let a=l.component,o;if(a==a.parent)o=a;else{let u=a,x=null;for(;u!=u.parent;){let y=u.parent;u.parent=x,x=u,u=y}for(;x!=null;){let y=x.parent;x.parent=u,x=y}o=u}a.island=o.island;let p=a.island.comps,c;B._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new B._zpp.util.ZNPNode_ZPP_Component:(c=B._zpp.util.ZNPNode_ZPP_Component.zpp_pool,B._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=a;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++,a.waket>a.island.waket&&(a.island.waket=a.waket)}for(;this.islands.next!=null;){let i=this.islands,l=i.next;i.pop();let r=l;if(r.sleep){let a=r.comps.head;for(;a!=null;){let o=a.elt;if(o.isBody){let p=o.body;p.velx=0,p.vely=0,p.angvel=0,o.sleeping=!0;let c=p.shapes.head;for(;c!=null;){let h=c.elt;this.bphase.sync(h),c=c.next}this.bodyCbSleep(p)}else{let p=o.constraint;this.constraintCbSleep(p),o.sleeping=!0}a=a.next}}else{for(;r.comps.head!=null;){let o=r.comps,p=o.head.elt;o.pop();let c=p;if(c.waket=r.waket,c.isBody){let h=this.live,u=c.body,x;B._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?x=new B._zpp.util.ZNPNode_ZPP_Body:(x=B._zpp.util.ZNPNode_ZPP_Body.zpp_pool,B._zpp.util.ZNPNode_ZPP_Body.zpp_pool=x.next,x.next=null),x.elt=u;let y=x;y.next=h.head,h.head=y,h.modified=!0,h.length++}else{let h=this.live_constraints,u=c.constraint,x;B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?x=new B._zpp.util.ZNPNode_ZPP_Constraint:(x=B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=x.next,x.next=null),x.elt=u;let y=x;y.next=h.head,h.head=y,h.modified=!0,h.length++}c.sleeping=!1,c.island=null,c.parent=c,c.rank=0}let a=r;a.next=ht.zpp_pool,ht.zpp_pool=a}}}sleepArbiters(){let e=null,t=this.c_arbiters_true,n=t.head,s=this.c_arbiters_false!=null;for(s&&n==null&&(s=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);n!=null;){let u=n.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=!0;let x,y;e==null?(x=t.head,y=x.next,t.head=y,t.head==null&&(t.pushmod=!0)):(x=e.next,y=x.next,e.next=y,y==null&&(t.pushmod=!0));let d=x;d.elt=null,d.next=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=d,t.modified=!0,t.length--,t.pushmod=!0,n=y,s&&n==null&&(s=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);continue}e=n,n=n.next,s&&n==null&&(s=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null)}let i=null,l=this.f_arbiters,r=l.head,a=!1;for(a&&r==null&&(a=!1,l=null,i=null);r!=null;){let u=r.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=!0;let x,y;i==null?(x=l.head,y=x.next,l.head=y,l.head==null&&(l.pushmod=!0)):(x=i.next,y=x.next,i.next=y,y==null&&(l.pushmod=!0));let d=x;d.elt=null,d.next=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=d,l.modified=!0,l.length--,l.pushmod=!0,r=y,a&&r==null&&(a=!1,l=null,i=null);continue}i=r,r=r.next,a&&r==null&&(a=!1,l=null,i=null)}let o=null,p=this.s_arbiters,c=p.head,h=!1;for(h&&c==null&&(h=!1,p=null,o=null);c!=null;){let u=c.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=!0;let x,y;o==null?(x=p.head,y=x.next,p.head=y,p.head==null&&(p.pushmod=!0)):(x=o.next,y=x.next,o.next=y,y==null&&(p.pushmod=!0));let d=x;d.elt=null,d.next=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=d,p.modified=!0,p.length--,p.pushmod=!0,c=y,h&&c==null&&(h=!1,p=null,o=null);continue}o=c,c=c.next,h&&c==null&&(h=!1,p=null,o=null)}}static_validation(e){if(e.shapes.head!=null){if(e.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(e.zip_aabb){e.zip_aabb=!1,e.aabb.minx=1/0,e.aabb.miny=1/0,e.aabb.maxx=-1/0,e.aabb.maxy=-1/0;let n=e.shapes.head;for(;n!=null;){let s=n.elt;if(s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let r=s.circle;if(r.zip_worldCOM&&r.body!=null){if(r.zip_worldCOM=!1,r.zip_localCOM){if(r.zip_localCOM=!1,r.type==1){let c=r.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let h=1;c.localCOMx+=c.lverts.next.next.x*h,c.localCOMy+=c.lverts.next.next.y*h;let u=.5;c.localCOMx*=u,c.localCOMy*=u}else{c.localCOMx=0,c.localCOMy=0;let h=0,u=c.lverts.next,x=u;u=u.next;let y=u;for(u=u.next;u!=null;){let k=u;h+=y.x*(k.y-x.y);let m=k.y*y.x-k.x*y.y;c.localCOMx+=(y.x+k.x)*m,c.localCOMy+=(y.y+k.y)*m,x=y,y=k,u=u.next}u=c.lverts.next;let d=u;h+=y.x*(d.y-x.y);let _=d.y*y.x-d.x*y.y;c.localCOMx+=(y.x+d.x)*_,c.localCOMy+=(y.y+d.y)*_,x=y,y=d,u=u.next;let f=u;h+=y.x*(f.y-x.y);let z=f.y*y.x-f.x*y.y;c.localCOMx+=(y.x+f.x)*z,c.localCOMy+=(y.y+f.y)*z,h=1/(3*h);let P=h;c.localCOMx*=P,c.localCOMy*=P}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let p=r.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),r.worldCOMx=r.body.posx+(r.body.axisy*r.localCOMx-r.body.axisx*r.localCOMy),r.worldCOMy=r.body.posy+(r.localCOMx*r.body.axisx+r.localCOMy*r.body.axisy)}let a=r.radius,o=r.radius;r.aabb.minx=r.worldCOMx-a,r.aabb.miny=r.worldCOMy-o,r.aabb.maxx=r.worldCOMx+a,r.aabb.maxy=r.worldCOMy+o}else{let r=s.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let p=r.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=r.lverts.next,h=r.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=r.body.posx+(r.body.axisy*x.x-r.body.axisx*x.y),u.y=r.body.posy+(x.x*r.body.axisx+x.y*r.body.axisy),h=h.next}}if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let a=r.gverts.next;r.aabb.minx=a.x,r.aabb.miny=a.y,r.aabb.maxx=a.x,r.aabb.maxy=a.y;let o=r.gverts.next.next;for(;o!=null;){let p=o;p.x<r.aabb.minx&&(r.aabb.minx=p.x),p.x>r.aabb.maxx&&(r.aabb.maxx=p.x),p.y<r.aabb.miny&&(r.aabb.miny=p.y),p.y>r.aabb.maxy&&(r.aabb.maxy=p.y),o=o.next}}let i=e.aabb,l=s.aabb;l.minx<i.minx&&(i.minx=l.minx),l.maxx>i.maxx&&(i.maxx=l.maxx),l.miny<i.miny&&(i.miny=l.miny),l.maxy>i.maxy&&(i.maxy=l.maxy),n=n.next}}}if(e.validate_mass(),e.validate_inertia(),e.velx!=0||e.vely!=0||e.angvel!=0)throw new Error("Error: Static body cannot have any real velocity, only kinematic or surface velocities");let t=e.shapes.head;for(;t!=null;){let n=t.elt;if(n.type==1){let s=n.polygon;s.zip_sanitation&&(s.zip_sanitation=!1,s.splice_collinear_real());let i=n.polygon.valid();if(H.ValidationResult_VALID==null&&(H.internal=!0,H.ValidationResult_VALID=new B._nape.shape.ValidationResult,H.internal=!1),i!=H.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+n.polygon.outer.toString()+" is invalid : "+i.toString());let l=n.polygon;if(l.zip_gaxi&&l.body!=null){l.zip_gaxi=!1,l.validate_laxi();let r=l.body;if(r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let u=l.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let x=l.lverts.next,y=l.gverts.next;for(;y!=null;){let d=y,_=x;x=x.next,d.x=l.body.posx+(l.body.axisy*_.x-l.body.axisx*_.y),d.y=l.body.posy+(_.x*l.body.axisx+_.y*l.body.axisy),y=y.next}}let a=l.edges.head,o=l.gverts.next,p=o;for(o=o.next;o!=null;){let u=o,x=a.elt;a=a.next,x.gp0=p,x.gp1=u,x.gnormx=l.body.axisy*x.lnormx-l.body.axisx*x.lnormy,x.gnormy=x.lnormx*l.body.axisx+x.lnormy*l.body.axisy,x.gprojection=l.body.posx*x.gnormx+l.body.posy*x.gnormy+x.lprojection,x.wrap_gnorm!=null&&(x.wrap_gnorm.zpp_inner.x=x.gnormx,x.wrap_gnorm.zpp_inner.y=x.gnormy),x.tp0=x.gp0.y*x.gnormx-x.gp0.x*x.gnormy,x.tp1=x.gp1.y*x.gnormx-x.gp1.x*x.gnormy,p=u,o=o.next}let c=l.gverts.next,h=a.elt;a=a.next,h.gp0=p,h.gp1=c,h.gnormx=l.body.axisy*h.lnormx-l.body.axisx*h.lnormy,h.gnormy=h.lnormx*l.body.axisx+h.lnormy*l.body.axisy,h.gprojection=l.body.posx*h.gnormx+l.body.posy*h.gnormy+h.lprojection,h.wrap_gnorm!=null&&(h.wrap_gnorm.zpp_inner.x=h.gnormx,h.wrap_gnorm.zpp_inner.y=h.gnormy),h.tp0=h.gp0.y*h.gnormx-h.gp0.x*h.gnormy,h.tp1=h.gp1.y*h.gnormx-h.gp1.x*h.gnormy}}t=t.next}e.sweepFrozen=!0}validation(){let e=this.cbsets;if(!e.cbsets.empty()){let i=e.cbsets.parent;for(;i.prev!=null;)i=i.prev;for(;i!=null;)if(i.data.validate(),i.next!=null)for(i=i.next;i.prev!=null;)i=i.prev;else{for(;i.parent!=null&&i==i.parent.next;)i=i.parent;i=i.parent}}let t=this.live.head;for(;t!=null;){let i=t.elt;i.sweepRadius=0;let l=i.shapes.head;for(;l!=null;){let a=l.elt;if(a.type==1){let o=a.polygon;o.zip_sanitation&&(o.zip_sanitation=!1,o.splice_collinear_real());let p=a.polygon.valid();if(H.ValidationResult_VALID==null&&(H.internal=!0,H.ValidationResult_VALID=new B._nape.shape.ValidationResult,H.internal=!1),p!=H.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+a.polygon.outer.toString()+" is invalid : "+p.toString());let c=a.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=!1,c.validate_laxi();let h=c.body;if(h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let f=c.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let z=c.lverts.next,P=c.gverts.next;for(;P!=null;){let k=P,m=z;z=z.next,k.x=c.body.posx+(c.body.axisy*m.x-c.body.axisx*m.y),k.y=c.body.posy+(m.x*c.body.axisx+m.y*c.body.axisy),P=P.next}}let u=c.edges.head,x=c.gverts.next,y=x;for(x=x.next;x!=null;){let f=x,z=u.elt;u=u.next,z.gp0=y,z.gp1=f,z.gnormx=c.body.axisy*z.lnormx-c.body.axisx*z.lnormy,z.gnormy=z.lnormx*c.body.axisx+z.lnormy*c.body.axisy,z.gprojection=c.body.posx*z.gnormx+c.body.posy*z.gnormy+z.lprojection,z.wrap_gnorm!=null&&(z.wrap_gnorm.zpp_inner.x=z.gnormx,z.wrap_gnorm.zpp_inner.y=z.gnormy),z.tp0=z.gp0.y*z.gnormx-z.gp0.x*z.gnormy,z.tp1=z.gp1.y*z.gnormx-z.gp1.x*z.gnormy,y=f,x=x.next}let d=c.gverts.next,_=u.elt;u=u.next,_.gp0=y,_.gp1=d,_.gnormx=c.body.axisy*_.lnormx-c.body.axisx*_.lnormy,_.gnormy=_.lnormx*c.body.axisx+_.lnormy*c.body.axisy,_.gprojection=c.body.posx*_.gnormx+c.body.posy*_.gnormy+_.lprojection,_.wrap_gnorm!=null&&(_.wrap_gnorm.zpp_inner.x=_.gnormx,_.wrap_gnorm.zpp_inner.y=_.gnormy),_.tp0=_.gp0.y*_.gnormx-_.gp0.x*_.gnormy,_.tp1=_.gp1.y*_.gnormx-_.gp1.x*_.gnormy}}a.validate_sweepRadius(),a.sweepRadius>i.sweepRadius&&(i.sweepRadius=a.sweepRadius),l=l.next}if(i.validate_mass(),i.validate_inertia(),i.shapes.head!=null){if(i.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(i.zip_aabb){i.zip_aabb=!1,i.aabb.minx=1/0,i.aabb.miny=1/0,i.aabb.maxx=-1/0,i.aabb.maxy=-1/0;let a=i.shapes.head;for(;a!=null;){let o=a.elt;if(o.zip_aabb&&o.body!=null)if(o.zip_aabb=!1,o.type==0){let h=o.circle;if(h.zip_worldCOM&&h.body!=null){if(h.zip_worldCOM=!1,h.zip_localCOM){if(h.zip_localCOM=!1,h.type==1){let d=h.polygon;if(d.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(d.lverts.next.next==null)d.localCOMx=d.lverts.next.x,d.localCOMy=d.lverts.next.y;else if(d.lverts.next.next.next==null){d.localCOMx=d.lverts.next.x,d.localCOMy=d.lverts.next.y;let _=1;d.localCOMx+=d.lverts.next.next.x*_,d.localCOMy+=d.lverts.next.next.y*_;let f=.5;d.localCOMx*=f,d.localCOMy*=f}else{d.localCOMx=0,d.localCOMy=0;let _=0,f=d.lverts.next,z=f;f=f.next;let P=f;for(f=f.next;f!=null;){let w=f;_+=P.x*(w.y-z.y);let O=w.y*P.x-w.x*P.y;d.localCOMx+=(P.x+w.x)*O,d.localCOMy+=(P.y+w.y)*O,z=P,P=w,f=f.next}f=d.lverts.next;let k=f;_+=P.x*(k.y-z.y);let m=k.y*P.x-k.x*P.y;d.localCOMx+=(P.x+k.x)*m,d.localCOMy+=(P.y+k.y)*m,z=P,P=k,f=f.next;let b=f;_+=P.x*(b.y-z.y);let C=b.y*P.x-b.x*P.y;d.localCOMx+=(P.x+b.x)*C,d.localCOMy+=(P.y+b.y)*C,_=1/(3*_);let v=_;d.localCOMx*=v,d.localCOMy*=v}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy)}let y=h.body;y.zip_axis&&(y.zip_axis=!1,y.axisx=Math.sin(y.rot),y.axisy=Math.cos(y.rot)),h.worldCOMx=h.body.posx+(h.body.axisy*h.localCOMx-h.body.axisx*h.localCOMy),h.worldCOMy=h.body.posy+(h.localCOMx*h.body.axisx+h.localCOMy*h.body.axisy)}let u=h.radius,x=h.radius;h.aabb.minx=h.worldCOMx-u,h.aabb.miny=h.worldCOMy-x,h.aabb.maxx=h.worldCOMx+u,h.aabb.maxy=h.worldCOMy+x}else{let h=o.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let y=h.body;y.zip_axis&&(y.zip_axis=!1,y.axisx=Math.sin(y.rot),y.axisy=Math.cos(y.rot));let d=h.lverts.next,_=h.gverts.next;for(;_!=null;){let f=_,z=d;d=d.next,f.x=h.body.posx+(h.body.axisy*z.x-h.body.axisx*z.y),f.y=h.body.posy+(z.x*h.body.axisx+z.y*h.body.axisy),_=_.next}}if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let u=h.gverts.next;h.aabb.minx=u.x,h.aabb.miny=u.y,h.aabb.maxx=u.x,h.aabb.maxy=u.y;let x=h.gverts.next.next;for(;x!=null;){let y=x;y.x<h.aabb.minx&&(h.aabb.minx=y.x),y.x>h.aabb.maxx&&(h.aabb.maxx=y.x),y.y<h.aabb.miny&&(h.aabb.miny=y.y),y.y>h.aabb.maxy&&(h.aabb.maxy=y.y),x=x.next}}let p=i.aabb,c=o.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),a=a.next}}i.validate_worldCOM()}if(i.validate_gravMass(),i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),!i.nomove&&i.type==2&&i.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!i.norotate&&i.type==2&&i.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");if(i.component.woken&&i.cbSet!=null){let a=i.cbSet.bodylisteners.head;for(;a!=null;){let o=a.elt;if(o.event!=2){a=a.next;continue}let p=this.push_callback(o);p.event=2,p.body=i,a=a.next}}i.component.woken=!1;let r=i.shapes.head;for(;r!=null;){let a=r.elt;this.bphase.sync(a),r=r.next}t=t.next}let n=this.kinematics.head;for(;n!=null;){let i=n.elt;i.sweepRadius=0;let l=i.shapes.head;for(;l!=null;){let a=l.elt;if(a.type==1){let o=a.polygon;o.zip_sanitation&&(o.zip_sanitation=!1,o.splice_collinear_real());let p=a.polygon.valid();if(H.ValidationResult_VALID==null&&(H.internal=!0,H.ValidationResult_VALID=new B._nape.shape.ValidationResult,H.internal=!1),p!=H.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+a.polygon.outer.toString()+" is invalid : "+p.toString());let c=a.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=!1,c.validate_laxi();let h=c.body;if(h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let f=c.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let z=c.lverts.next,P=c.gverts.next;for(;P!=null;){let k=P,m=z;z=z.next,k.x=c.body.posx+(c.body.axisy*m.x-c.body.axisx*m.y),k.y=c.body.posy+(m.x*c.body.axisx+m.y*c.body.axisy),P=P.next}}let u=c.edges.head,x=c.gverts.next,y=x;for(x=x.next;x!=null;){let f=x,z=u.elt;u=u.next,z.gp0=y,z.gp1=f,z.gnormx=c.body.axisy*z.lnormx-c.body.axisx*z.lnormy,z.gnormy=z.lnormx*c.body.axisx+z.lnormy*c.body.axisy,z.gprojection=c.body.posx*z.gnormx+c.body.posy*z.gnormy+z.lprojection,z.wrap_gnorm!=null&&(z.wrap_gnorm.zpp_inner.x=z.gnormx,z.wrap_gnorm.zpp_inner.y=z.gnormy),z.tp0=z.gp0.y*z.gnormx-z.gp0.x*z.gnormy,z.tp1=z.gp1.y*z.gnormx-z.gp1.x*z.gnormy,y=f,x=x.next}let d=c.gverts.next,_=u.elt;u=u.next,_.gp0=y,_.gp1=d,_.gnormx=c.body.axisy*_.lnormx-c.body.axisx*_.lnormy,_.gnormy=_.lnormx*c.body.axisx+_.lnormy*c.body.axisy,_.gprojection=c.body.posx*_.gnormx+c.body.posy*_.gnormy+_.lprojection,_.wrap_gnorm!=null&&(_.wrap_gnorm.zpp_inner.x=_.gnormx,_.wrap_gnorm.zpp_inner.y=_.gnormy),_.tp0=_.gp0.y*_.gnormx-_.gp0.x*_.gnormy,_.tp1=_.gp1.y*_.gnormx-_.gp1.x*_.gnormy}}a.validate_sweepRadius(),a.sweepRadius>i.sweepRadius&&(i.sweepRadius=a.sweepRadius),l=l.next}if(i.validate_mass(),i.validate_inertia(),i.shapes.head!=null){if(i.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(i.zip_aabb){i.zip_aabb=!1,i.aabb.minx=1/0,i.aabb.miny=1/0,i.aabb.maxx=-1/0,i.aabb.maxy=-1/0;let a=i.shapes.head;for(;a!=null;){let o=a.elt;if(o.zip_aabb&&o.body!=null)if(o.zip_aabb=!1,o.type==0){let h=o.circle;if(h.zip_worldCOM&&h.body!=null){if(h.zip_worldCOM=!1,h.zip_localCOM){if(h.zip_localCOM=!1,h.type==1){let d=h.polygon;if(d.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(d.lverts.next.next==null)d.localCOMx=d.lverts.next.x,d.localCOMy=d.lverts.next.y;else if(d.lverts.next.next.next==null){d.localCOMx=d.lverts.next.x,d.localCOMy=d.lverts.next.y;let _=1;d.localCOMx+=d.lverts.next.next.x*_,d.localCOMy+=d.lverts.next.next.y*_;let f=.5;d.localCOMx*=f,d.localCOMy*=f}else{d.localCOMx=0,d.localCOMy=0;let _=0,f=d.lverts.next,z=f;f=f.next;let P=f;for(f=f.next;f!=null;){let w=f;_+=P.x*(w.y-z.y);let O=w.y*P.x-w.x*P.y;d.localCOMx+=(P.x+w.x)*O,d.localCOMy+=(P.y+w.y)*O,z=P,P=w,f=f.next}f=d.lverts.next;let k=f;_+=P.x*(k.y-z.y);let m=k.y*P.x-k.x*P.y;d.localCOMx+=(P.x+k.x)*m,d.localCOMy+=(P.y+k.y)*m,z=P,P=k,f=f.next;let b=f;_+=P.x*(b.y-z.y);let C=b.y*P.x-b.x*P.y;d.localCOMx+=(P.x+b.x)*C,d.localCOMy+=(P.y+b.y)*C,_=1/(3*_);let v=_;d.localCOMx*=v,d.localCOMy*=v}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy)}let y=h.body;y.zip_axis&&(y.zip_axis=!1,y.axisx=Math.sin(y.rot),y.axisy=Math.cos(y.rot)),h.worldCOMx=h.body.posx+(h.body.axisy*h.localCOMx-h.body.axisx*h.localCOMy),h.worldCOMy=h.body.posy+(h.localCOMx*h.body.axisx+h.localCOMy*h.body.axisy)}let u=h.radius,x=h.radius;h.aabb.minx=h.worldCOMx-u,h.aabb.miny=h.worldCOMy-x,h.aabb.maxx=h.worldCOMx+u,h.aabb.maxy=h.worldCOMy+x}else{let h=o.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let y=h.body;y.zip_axis&&(y.zip_axis=!1,y.axisx=Math.sin(y.rot),y.axisy=Math.cos(y.rot));let d=h.lverts.next,_=h.gverts.next;for(;_!=null;){let f=_,z=d;d=d.next,f.x=h.body.posx+(h.body.axisy*z.x-h.body.axisx*z.y),f.y=h.body.posy+(z.x*h.body.axisx+z.y*h.body.axisy),_=_.next}}if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let u=h.gverts.next;h.aabb.minx=u.x,h.aabb.miny=u.y,h.aabb.maxx=u.x,h.aabb.maxy=u.y;let x=h.gverts.next.next;for(;x!=null;){let y=x;y.x<h.aabb.minx&&(h.aabb.minx=y.x),y.x>h.aabb.maxx&&(h.aabb.maxx=y.x),y.y<h.aabb.miny&&(h.aabb.miny=y.y),y.y>h.aabb.maxy&&(h.aabb.maxy=y.y),x=x.next}}let p=i.aabb,c=o.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),a=a.next}}i.validate_worldCOM()}if(i.validate_gravMass(),i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),!i.nomove&&i.type==2&&i.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!i.norotate&&i.type==2&&i.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");let r=i.shapes.head;for(;r!=null;){let a=r.elt;this.bphase.sync(a),r=r.next}n=n.next}let s=this.live_constraints.head;for(;s!=null;){let i=s.elt;if(i.active){if(i.validate(),i.component.woken&&i.cbSet!=null){let l=i.cbSet.conlisteners.head;for(;l!=null;){let r=l.elt;if(r.event!=2){l=l.next;continue}let a=this.push_callback(r);a.event=2,a.constraint=i,l=l.next}}i.component.woken=!1}s=s.next}}updateVel(e){let t=null,n=1-e*this.global_lin_drag,s=1-e*this.global_ang_drag,i=this.live.head;for(;i!=null;){let l=i.elt;if(l.smass!=0){let r=e*l.imass;l.velx=n*l.velx+(l.forcex+this.gravityx*l.gravMass)*r,l.vely=n*l.vely+(l.forcey+this.gravityy*l.gravMass)*r}if(l.sinertia!=0){let r=0,a=0;r=l.worldCOMx-l.posx,a=l.worldCOMy-l.posy;let o=l.torque+(this.gravityy*r-this.gravityx*a)*l.gravMass;l.angvel=s*l.angvel+o*e*l.iinertia}t=i,i=i.next}}updatePos(e){let t=2*Math.PI/e,n=this.live.head;for(;n!=null;){let i=n.elt;i.pre_posx=i.posx,i.pre_posy=i.posy,i.pre_rot=i.rot,i.sweepTime=0,i.sweep_angvel=i.angvel%t;let l=e-i.sweepTime;if(l!=0){i.sweepTime=e;let r=l;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let a=i.sweep_angvel*l;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let o=a*a,p=1-.5*o,c=1-o*o/8,h=(p*i.axisx+a*i.axisy)*c;i.axisy=(p*i.axisy-a*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let r=B._nape.Config.staticCCDLinearThreshold*i.sweepRadius,a=B._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>r*r||i.angvel*i.angvel*e*e>a*a||i.type==3){let o=i.sweep_angvel;o<0&&(o=-o);let p=1/o,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,y=u.miny,d=u.maxx,_=u.maxy,f=o*e*h.sweepCoef*.008333333333333333|0;f>8&&(f=8);let z=o*e/f,P=e-i.sweepTime;if(P!=0){i.sweepTime=e;let b=P;if(i.posx+=i.velx*b,i.posy+=i.vely*b,i.angvel!=0){let C=i.sweep_angvel*P;if(i.rot+=C,C*C>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let v=C*C,w=1-.5*v,O=1-v*v/8,E=(w*i.axisx+C*i.axisy)*O;i.axisy=(w*i.axisy-C*i.axisx)*O,i.axisx=E}}}if(h.type==0){let b=h.circle;b.worldCOMx=b.body.posx+(b.body.axisy*b.localCOMx-b.body.axisx*b.localCOMy),b.worldCOMy=b.body.posy+(b.localCOMx*b.body.axisx+b.localCOMy*b.body.axisy),b.aabb.minx=b.worldCOMx-b.radius,b.aabb.miny=b.worldCOMy-b.radius,b.aabb.maxx=b.worldCOMx+b.radius,b.aabb.maxy=b.worldCOMy+b.radius}else{let b=h.polygon,C=b.lverts.next,v=b.gverts.next,w=C;C=C.next,v.x=b.body.posx+(b.body.axisy*w.x-b.body.axisx*w.y),v.y=b.body.posy+(w.x*b.body.axisx+w.y*b.body.axisy),b.aabb.minx=v.x,b.aabb.miny=v.y,b.aabb.maxx=v.x,b.aabb.maxy=v.y;let O=b.gverts.next.next;for(;O!=null;){let E=O,M=C;C=C.next,E.x=b.body.posx+(b.body.axisy*M.x-b.body.axisx*M.y),E.y=b.body.posy+(M.x*b.body.axisx+M.y*b.body.axisy),E.x<b.aabb.minx&&(b.aabb.minx=E.x),E.x>b.aabb.maxx&&(b.aabb.maxx=E.x),E.y<b.aabb.miny&&(b.aabb.miny=E.y),E.y>b.aabb.maxy&&(b.aabb.maxy=E.y),O=O.next}}x<u.minx?u.minx=x:x=u.minx,y<u.miny?u.miny=y:y=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,_>u.maxy?u.maxy=_:_=u.maxy;let k=1,m=f;for(;k<m;){let b=k++,C=z*b*p,v=C-i.sweepTime;if(v!=0){i.sweepTime=C;let w=v;if(i.posx+=i.velx*w,i.posy+=i.vely*w,i.angvel!=0){let O=i.sweep_angvel*v;if(i.rot+=O,O*O>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let E=O*O,M=1-.5*E,N=1-E*E/8,Z=(M*i.axisx+O*i.axisy)*N;i.axisy=(M*i.axisy-O*i.axisx)*N,i.axisx=Z}}}if(h.type==0){let w=h.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else{let w=h.polygon,O=w.lverts.next,E=w.gverts.next,M=O;O=O.next,E.x=w.body.posx+(w.body.axisy*M.x-w.body.axisx*M.y),E.y=w.body.posy+(M.x*w.body.axisx+M.y*w.body.axisy),w.aabb.minx=E.x,w.aabb.miny=E.y,w.aabb.maxx=E.x,w.aabb.maxy=E.y;let N=w.gverts.next.next;for(;N!=null;){let Z=N,S=O;O=O.next,Z.x=w.body.posx+(w.body.axisy*S.x-w.body.axisx*S.y),Z.y=w.body.posy+(S.x*w.body.axisx+S.y*w.body.axisy),Z.x<w.aabb.minx&&(w.aabb.minx=Z.x),Z.x>w.aabb.maxx&&(w.aabb.maxx=Z.x),Z.y<w.aabb.miny&&(w.aabb.miny=Z.y),Z.y>w.aabb.maxy&&(w.aabb.maxy=Z.y),N=N.next}}x<u.minx?u.minx=x:x=u.minx,y<u.miny?u.miny=y:y=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,_>u.maxy?u.maxy=_:_=u.maxy}this.bphase.sync(h),c=c.next}if(i.sweepFrozen=!1,i.type==2&&i.bulletEnabled){let h=B._nape.Config.bulletCCDLinearThreshold*i.sweepRadius,u=B._nape.Config.bulletCCDAngularThreshold;((i.velx*i.velx+i.vely*i.vely)*e*e>h*h||i.angvel*i.angvel*e*e>u*u)&&(i.bullet=!0)}}else i.sweepFrozen=!0,i.bullet=!1}n=n.next}let s=this.kinematics.head;for(;s!=null;){let i=s.elt;i.pre_posx=i.posx,i.pre_posy=i.posy,i.pre_rot=i.rot,i.sweepTime=0,i.sweep_angvel=i.angvel%t;let l=e-i.sweepTime;if(l!=0){i.sweepTime=e;let r=l;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let a=i.sweep_angvel*l;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let o=a*a,p=1-.5*o,c=1-o*o/8,h=(p*i.axisx+a*i.axisy)*c;i.axisy=(p*i.axisy-a*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let r=B._nape.Config.staticCCDLinearThreshold*i.sweepRadius,a=B._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>r*r||i.angvel*i.angvel*e*e>a*a||i.type==3){let o=i.sweep_angvel;o<0&&(o=-o);let p=1/o,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,y=u.miny,d=u.maxx,_=u.maxy,f=o*e*h.sweepCoef*.008333333333333333|0;f>8&&(f=8);let z=o*e/f,P=e-i.sweepTime;if(P!=0){i.sweepTime=e;let b=P;if(i.posx+=i.velx*b,i.posy+=i.vely*b,i.angvel!=0){let C=i.sweep_angvel*P;if(i.rot+=C,C*C>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let v=C*C,w=1-.5*v,O=1-v*v/8,E=(w*i.axisx+C*i.axisy)*O;i.axisy=(w*i.axisy-C*i.axisx)*O,i.axisx=E}}}if(h.type==0){let b=h.circle;b.worldCOMx=b.body.posx+(b.body.axisy*b.localCOMx-b.body.axisx*b.localCOMy),b.worldCOMy=b.body.posy+(b.localCOMx*b.body.axisx+b.localCOMy*b.body.axisy),b.aabb.minx=b.worldCOMx-b.radius,b.aabb.miny=b.worldCOMy-b.radius,b.aabb.maxx=b.worldCOMx+b.radius,b.aabb.maxy=b.worldCOMy+b.radius}else{let b=h.polygon,C=b.lverts.next,v=b.gverts.next,w=C;C=C.next,v.x=b.body.posx+(b.body.axisy*w.x-b.body.axisx*w.y),v.y=b.body.posy+(w.x*b.body.axisx+w.y*b.body.axisy),b.aabb.minx=v.x,b.aabb.miny=v.y,b.aabb.maxx=v.x,b.aabb.maxy=v.y;let O=b.gverts.next.next;for(;O!=null;){let E=O,M=C;C=C.next,E.x=b.body.posx+(b.body.axisy*M.x-b.body.axisx*M.y),E.y=b.body.posy+(M.x*b.body.axisx+M.y*b.body.axisy),E.x<b.aabb.minx&&(b.aabb.minx=E.x),E.x>b.aabb.maxx&&(b.aabb.maxx=E.x),E.y<b.aabb.miny&&(b.aabb.miny=E.y),E.y>b.aabb.maxy&&(b.aabb.maxy=E.y),O=O.next}}x<u.minx?u.minx=x:x=u.minx,y<u.miny?u.miny=y:y=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,_>u.maxy?u.maxy=_:_=u.maxy;let k=1,m=f;for(;k<m;){let b=k++,C=z*b*p,v=C-i.sweepTime;if(v!=0){i.sweepTime=C;let w=v;if(i.posx+=i.velx*w,i.posy+=i.vely*w,i.angvel!=0){let O=i.sweep_angvel*v;if(i.rot+=O,O*O>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let E=O*O,M=1-.5*E,N=1-E*E/8,Z=(M*i.axisx+O*i.axisy)*N;i.axisy=(M*i.axisy-O*i.axisx)*N,i.axisx=Z}}}if(h.type==0){let w=h.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else{let w=h.polygon,O=w.lverts.next,E=w.gverts.next,M=O;O=O.next,E.x=w.body.posx+(w.body.axisy*M.x-w.body.axisx*M.y),E.y=w.body.posy+(M.x*w.body.axisx+M.y*w.body.axisy),w.aabb.minx=E.x,w.aabb.miny=E.y,w.aabb.maxx=E.x,w.aabb.maxy=E.y;let N=w.gverts.next.next;for(;N!=null;){let Z=N,S=O;O=O.next,Z.x=w.body.posx+(w.body.axisy*S.x-w.body.axisx*S.y),Z.y=w.body.posy+(S.x*w.body.axisx+S.y*w.body.axisy),Z.x<w.aabb.minx&&(w.aabb.minx=Z.x),Z.x>w.aabb.maxx&&(w.aabb.maxx=Z.x),Z.y<w.aabb.miny&&(w.aabb.miny=Z.y),Z.y>w.aabb.maxy&&(w.aabb.maxy=Z.y),N=N.next}}x<u.minx?u.minx=x:x=u.minx,y<u.miny?u.miny=y:y=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,_>u.maxy?u.maxy=_:_=u.maxy}this.bphase.sync(h),c=c.next}if(i.sweepFrozen=!1,i.type==2&&i.bulletEnabled){let h=B._nape.Config.bulletCCDLinearThreshold*i.sweepRadius,u=B._nape.Config.bulletCCDAngularThreshold;((i.velx*i.velx+i.vely*i.vely)*e*e>h*h||i.angvel*i.angvel*e*e>u*u)&&(i.bullet=!0)}}else i.sweepFrozen=!0,i.bullet=!1}s=s.next}}presteparb(e,t,n){if(n==null&&(n=!1),!e.cleared&&e.b1.component.sleeping&&e.b2.component.sleeping)return e.sleep_stamp=this.stamp,e.sleeping=!0,!0;if(!e.cleared||e.present!=0||e.intchange){let i=!n&&e.up_stamp==this.stamp-1&&!e.cleared&&!e.intchange,l=e.fresh&&!e.cleared&&!e.intchange;if(i&&(e.endGenerated=this.stamp),l||i||e.cleared||e.intchange){let r=e.ws1,a=e.ws2,o=this.mrca1;for(;o.head!=null;){let x=o.head;o.head=x.next;let y=x;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y,o.head==null&&(o.pushmod=!0),o.modified=!0,o.length--}o.pushmod=!0;let p=this.mrca2;for(;p.head!=null;){let x=p.head;p.head=x.next;let y=x;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y,p.head==null&&(p.pushmod=!0),p.modified=!0,p.length--}if(p.pushmod=!0,r.cbSet!=null){let x=this.mrca1,y;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?y=new B._zpp.util.ZNPNode_ZPP_Interactor:(y=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y.next,y.next=null),y.elt=r;let d=y;d.next=x.head,x.head=d,x.modified=!0,x.length++}if(r.body.cbSet!=null){let x=this.mrca1,y=r.body,d;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new B._zpp.util.ZNPNode_ZPP_Interactor:(d=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=y;let _=d;_.next=x.head,x.head=_,x.modified=!0,x.length++}if(a.cbSet!=null){let x=this.mrca2,y;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?y=new B._zpp.util.ZNPNode_ZPP_Interactor:(y=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y.next,y.next=null),y.elt=a;let d=y;d.next=x.head,x.head=d,x.modified=!0,x.length++}if(a.body.cbSet!=null){let x=this.mrca2,y=a.body,d;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new B._zpp.util.ZNPNode_ZPP_Interactor:(d=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=y;let _=d;_.next=x.head,x.head=_,x.modified=!0,x.length++}let c=r.body.compound,h=a.body.compound;for(;c!=h;){let x=c==null?0:c.depth,y=h==null?0:h.depth;if(x<y){if(h.cbSet!=null){let d=this.mrca2,_;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_Interactor:(_=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=h;let f=_;f.next=d.head,d.head=f,d.modified=!0,d.length++}h=h.compound}else{if(c.cbSet!=null){let d=this.mrca1,_;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_Interactor:(_=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=c;let f=_;f.next=d.head,d.head=f,d.modified=!0,d.length++}c=c.compound}}let u=this.mrca1.head;for(;u!=null;){let x=u.elt,y=this.mrca2.head;for(;y!=null;){let d=y.elt,_=x.cbSet,f=d.cbSet,z=_.manager,P=null,m=(_.cbpairs.length<f.cbpairs.length?_.cbpairs:f.cbpairs).head;for(;m!=null;){let C=m.elt;if(C.a==_&&C.b==f||C.a==f&&C.b==_){P=C;break}m=m.next}if(P==null){let C;Ne.zpp_pool==null?C=new Ne:(C=Ne.zpp_pool,Ne.zpp_pool=C.next,C.next=null),C.zip_listeners=!0,dt.setlt(_,f)?(C.a=_,C.b=f):(C.a=f,C.b=_),P=C,_.cbpairs.add(P),f!=_&&f.cbpairs.add(P)}if(P.zip_listeners&&(P.zip_listeners=!1,P.__validate()),P.listeners.head==null){y=y.next;continue}let b=B._zpp.phys.ZPP_Interactor.get(x,d);if(l||e.intchange){b==null&&(b=qt.get(x,d),this.add_callbackset(b));let C=_.manager,v=null,O=(_.cbpairs.length<f.cbpairs.length?_.cbpairs:f.cbpairs).head;for(;O!=null;){let S=O.elt;if(S.a==_&&S.b==f||S.a==f&&S.b==_){v=S;break}O=O.next}if(v==null){let S;Ne.zpp_pool==null?S=new Ne:(S=Ne.zpp_pool,Ne.zpp_pool=S.next,S.next=null),S.zip_listeners=!0,dt.setlt(_,f)?(S.a=_,S.b=f):(S.a=f,S.b=_),v=S,_.cbpairs.add(v),f!=_&&f.cbpairs.add(v)}v.zip_listeners&&(v.zip_listeners=!1,v.__validate());let E=v.listeners.head;for(;E!=null;){let S=E.elt;if(S.event==0&&(S.itype&e.type)!=0&&b.empty_arb(S.itype)){let V=this.push_callback(S);V.event=0;let D=b.int1,T=b.int2,G,q=S.options1,R=D.cbTypes;if(q.nonemptyintersection(R,q.includes)&&!q.nonemptyintersection(R,q.excludes)){let j=S.options2,A=T.cbTypes;G=j.nonemptyintersection(A,j.includes)&&!j.nonemptyintersection(A,j.excludes)}else G=!1;G?(V.int1=D,V.int2=T):(V.int1=T,V.int2=D),V.set=b}E=E.next}let M,N;N=!1;let Z=b.arbiters.head;for(;Z!=null;){if(Z.elt==e){N=!0;break}Z=Z.next}if(N)M=!1;else{let S=b.arbiters,V;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?V=new B._zpp.util.ZNPNode_ZPP_Arbiter:(V=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=V.next,V.next=null),V.elt=e;let D=V;D.next=S.head,S.head=D,S.modified=!0,S.length++,M=!0}M&&e.present++}else{e.present--,b.remove_arb(e);let C=_.manager,v=null,O=(_.cbpairs.length<f.cbpairs.length?_.cbpairs:f.cbpairs).head;for(;O!=null;){let M=O.elt;if(M.a==_&&M.b==f||M.a==f&&M.b==_){v=M;break}O=O.next}if(v==null){let M;Ne.zpp_pool==null?M=new Ne:(M=Ne.zpp_pool,Ne.zpp_pool=M.next,M.next=null),M.zip_listeners=!0,dt.setlt(_,f)?(M.a=_,M.b=f):(M.a=f,M.b=_),v=M,_.cbpairs.add(v),f!=_&&f.cbpairs.add(v)}v.zip_listeners&&(v.zip_listeners=!1,v.__validate());let E=v.listeners.head;for(;E!=null;){let M=E.elt;if(M.event==1&&(M.itype&e.type)!=0&&b.empty_arb(M.itype)){let N=this.push_callback(M);N.event=1;let Z=b.int1,S=b.int2,V,D=M.options1,T=Z.cbTypes;if(D.nonemptyintersection(T,D.includes)&&!D.nonemptyintersection(T,D.excludes)){let G=M.options2,q=S.cbTypes;V=G.nonemptyintersection(q,G.includes)&&!G.nonemptyintersection(q,G.excludes)}else V=!1;V?(N.int1=Z,N.int2=S):(N.int1=S,N.int2=Z),N.set=b}E=E.next}b.arbiters.head==null&&this.remove_callbackset(b)}y=y.next}u=u.next}}e.fresh=!1,e.intchange=!1}if(e.cleared||e.up_stamp+(e.type==Ve.COL?B._nape.Config.arbiterExpirationDelay:0)<this.stamp){if(e.type==Ve.SENSOR){let i=e.sensorarb;if(!i.cleared){let r=i.b1.arbiters,a=null,o=r.head,p=!1;for(;o!=null;){if(o.elt==i){let y,d;a==null?(y=r.head,d=y.next,r.head=d,r.head==null&&(r.pushmod=!0)):(y=a.next,d=y.next,a.next=d,d==null&&(r.pushmod=!0));let _=y;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,r.modified=!0,r.length--,r.pushmod=!0,p=!0;break}a=o,o=o.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let y,d;h==null?(y=c.head,d=y.next,c.head=d,c.head==null&&(c.pushmod=!0)):(y=h.next,d=y.next,h.next=d,d==null&&(c.pushmod=!0));let _=y;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,c.modified=!0,c.length--,c.pushmod=!0,x=!0;break}h=u,u=u.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let l=i;l.next=Nt.zpp_pool,Nt.zpp_pool=l}else if(e.type==Ve.FLUID){let i=e.fluidarb;if(!i.cleared){let r=i.b1.arbiters,a=null,o=r.head,p=!1;for(;o!=null;){if(o.elt==i){let y,d;a==null?(y=r.head,d=y.next,r.head=d,r.head==null&&(r.pushmod=!0)):(y=a.next,d=y.next,a.next=d,d==null&&(r.pushmod=!0));let _=y;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,r.modified=!0,r.length--,r.pushmod=!0,p=!0;break}a=o,o=o.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let y,d;h==null?(y=c.head,d=y.next,c.head=d,c.head==null&&(c.pushmod=!0)):(y=h.next,d=y.next,h.next=d,d==null&&(c.pushmod=!0));let _=y;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,c.modified=!0,c.length--,c.pushmod=!0,x=!0;break}h=u,u=u.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let l=i;l.next=zt.zpp_pool,zt.zpp_pool=l,i.pre_dt=-1}else{let i=e.colarb;if(!i.cleared){let r=i.b1.arbiters,a=null,o=r.head,p=!1;for(;o!=null;){if(o.elt==i){let y,d;a==null?(y=r.head,d=y.next,r.head=d,r.head==null&&(r.pushmod=!0)):(y=a.next,d=y.next,a.next=d,d==null&&(r.pushmod=!0));let _=y;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,r.modified=!0,r.length--,r.pushmod=!0,p=!0;break}a=o,o=o.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let y,d;h==null?(y=c.head,d=y.next,c.head=d,c.head==null&&(c.pushmod=!0)):(y=h.next,d=y.next,h.next=d,d==null&&(c.pushmod=!0));let _=y;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,c.modified=!0,c.length--,c.pushmod=!0,x=!0;break}h=u,u=u.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}for(i.b1=i.b2=null,i.active=!1,i.intchange=!1;i.contacts.next!=null;){let r=i.contacts,a=r.next;r.pop();let o=a;o.arbiter=null,o.next=Pe.zpp_pool,Pe.zpp_pool=o;let p=i.innards,c=p.next;p.next=c.next,c._inuse=!1,p.next==null&&(p.pushmod=!0),p.modified=!0,p.length--}let l=i;l.userdef_dyn_fric=!1,l.userdef_stat_fric=!1,l.userdef_restitution=!1,l.userdef_rfric=!1,l.__ref_edge1=l.__ref_edge2=null,l.next=pt.zpp_pool,pt.zpp_pool=l,i.pre_dt=-1}return!0}let s=e.active;if(e.active=e.presentable=e.up_stamp==this.stamp,(e.immState&1)!=0){if(e.active&&e.type!=Ve.SENSOR)if(e.colarb!=null){let i=e.colarb;i.invalidated&&(i.invalidated=!1,i.userdef_restitution||(i.s1.material.elasticity<=-1/0||i.s2.material.elasticity<=-1/0?i.restitution=0:i.s1.material.elasticity>=1/0||i.s2.material.elasticity>=1/0?i.restitution=1:i.restitution=(i.s1.material.elasticity+i.s2.material.elasticity)/2,i.restitution<0&&(i.restitution=0),i.restitution>1&&(i.restitution=1)),i.userdef_dyn_fric||(i.dyn_fric=Math.sqrt(i.s1.material.dynamicFriction*i.s2.material.dynamicFriction)),i.userdef_stat_fric||(i.stat_fric=Math.sqrt(i.s1.material.staticFriction*i.s2.material.staticFriction)),i.userdef_rfric||(i.rfric=Math.sqrt(i.s1.material.rollingFriction*i.s2.material.rollingFriction))),i.pre_dt==-1&&(i.pre_dt=t);let l=t/i.pre_dt;i.pre_dt=t;let r=i.b1.smass+i.b2.smass;i.hc2=!1;let a=!0,p=i.b1.type!=2||i.b2.type!=2?i.continuous?B._nape.Config.contactContinuousStaticBiasCoef:B._nape.Config.contactStaticBiasCoef:i.continuous?B._nape.Config.contactContinuousBiasCoef:B._nape.Config.contactBiasCoef;i.biasCoef=p,i.continuous=!1;let c=null,h=null,u=i.innards.next,x=i.contacts.next;for(;x!=null;){let d=x;if(d.stamp+B._nape.Config.arbiterExpirationDelay<i.stamp){let z=i.contacts,P,k;c==null?(P=z.next,k=P.next,z.next=k,z.next==null&&(z.pushmod=!0)):(P=c.next,k=P.next,c.next=k,k==null&&(z.pushmod=!0)),P._inuse=!1,z.modified=!0,z.length--,z.pushmod=!0,x=k;let m=i.innards,b,C;h==null?(b=m.next,C=b.next,m.next=C,m.next==null&&(m.pushmod=!0)):(b=h.next,C=b.next,h.next=C,C==null&&(m.pushmod=!0)),b._inuse=!1,m.modified=!0,m.length--,m.pushmod=!0,u=C;let v=d;v.arbiter=null,v.next=Pe.zpp_pool,Pe.zpp_pool=v;continue}let _=d.inner,f=d.active;if(d.active=d.stamp==i.stamp,d.active){a?(a=!1,i.c1=_,i.oc1=d):(i.hc2=!0,i.c2=_,i.oc2=d),_.r2x=d.px-i.b2.posx,_.r2y=d.py-i.b2.posy,_.r1x=d.px-i.b1.posx,_.r1y=d.py-i.b1.posy;let z=_.r2x*i.nx+_.r2y*i.ny,P=r+i.b2.sinertia*(z*z),k=_.r1x*i.nx+_.r1y*i.ny;P+=i.b1.sinertia*(k*k),_.tMass=P<B._nape.Config.epsilon*B._nape.Config.epsilon?0:1/P;let m=i.ny*_.r2x-i.nx*_.r2y,b=r+i.b2.sinertia*(m*m),C=i.ny*_.r1x-i.nx*_.r1y;b+=i.b1.sinertia*(C*C),_.nMass=b<B._nape.Config.epsilon*B._nape.Config.epsilon?0:1/b;let v=0,w=0,O=i.b2.angvel+i.b2.kinangvel;v=i.b2.velx+i.b2.kinvelx-_.r2y*O,w=i.b2.vely+i.b2.kinvely+_.r2x*O,O=i.b1.angvel+i.b1.kinangvel,v-=i.b1.velx+i.b1.kinvelx-_.r1y*O,w-=i.b1.vely+i.b1.kinvely+_.r1x*O;let E=i.nx*v+i.ny*w;d.elasticity=i.restitution,_.bounce=E*d.elasticity,_.bounce>-B._nape.Config.elasticThreshold&&(_.bounce=0),E=w*i.nx-v*i.ny;let M=B._nape.Config.staticFrictionThreshold;E*E>M*M?_.friction=i.dyn_fric:_.friction=i.stat_fric,_.jnAcc*=l,_.jtAcc*=l}f!=d.active&&(i.contacts.modified=!0),c=x,h=u,u=u.next,x=x.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let d=i.c1;i.c1=i.c2,i.c2=d;let _=i.oc1;i.oc1=i.oc2,i.oc2=_,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(a=!0)}else i.hpc2=!1;if(i.jrAcc*=l,a||(i.rn1a=i.ny*i.c1.r1x-i.nx*i.c1.r1y,i.rt1a=i.c1.r1x*i.nx+i.c1.r1y*i.ny,i.rn1b=i.ny*i.c1.r2x-i.nx*i.c1.r2y,i.rt1b=i.c1.r2x*i.nx+i.c1.r2y*i.ny,i.k1x=i.b2.kinvelx-i.c1.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c1.r1y*i.b1.kinangvel),i.k1y=i.b2.kinvely+i.c1.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c1.r1x*i.b1.kinangvel)),i.hc2)if(i.rn2a=i.ny*i.c2.r1x-i.nx*i.c2.r1y,i.rt2a=i.c2.r1x*i.nx+i.c2.r1y*i.ny,i.rn2b=i.ny*i.c2.r2x-i.nx*i.c2.r2y,i.rt2b=i.c2.r2x*i.nx+i.c2.r2y*i.ny,i.k2x=i.b2.kinvelx-i.c2.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c2.r1y*i.b1.kinangvel),i.k2y=i.b2.kinvely+i.c2.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c2.r1x*i.b1.kinangvel),i.kMassa=r+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=r+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=r+i.b1.sinertia*i.rn2a*i.rn2a+i.b2.sinertia*i.rn2b*i.rn2b,i.kMassa*i.kMassa+2*i.kMassb*i.kMassb+i.kMassc*i.kMassc<B._nape.Config.illConditionedThreshold*(i.kMassa*i.kMassc-i.kMassb*i.kMassb)){i.Ka=i.kMassa,i.Kb=i.kMassb,i.Kc=i.kMassc;let _=i.kMassa*i.kMassc-i.kMassb*i.kMassb;if(_!=_)i.kMassa=i.kMassb=i.kMassc=0;else if(_==0){let f=0;i.kMassa!=0?i.kMassa=1/i.kMassa:(i.kMassa=0,f|=1),i.kMassc!=0?i.kMassc=1/i.kMassc:(i.kMassc=0,f|=2),i.kMassb=0}else{_=1/_;let f=i.kMassc*_;i.kMassc=i.kMassa*_,i.kMassa=f,i.kMassb*=-_}}else{if(i.hc2=!1,i.oc2.dist<i.oc1.dist){let _=i.c1;i.c1=i.c2,i.c2=_}i.oc2.active=!1,i.contacts.modified=!0}i.surfacex=i.b2.svelx,i.surfacey=i.b2.svely;let y=1;i.surfacex+=i.b1.svelx*y,i.surfacey+=i.b1.svely*y,i.surfacex=-i.surfacex,i.surfacey=-i.surfacey,i.rMass=i.b1.sinertia+i.b2.sinertia,i.rMass!=0&&(i.rMass=1/i.rMass),a&&(e.active=!1)}else{let i=e.fluidarb;i.pre_dt==-1&&(i.pre_dt=t);let l=t/i.pre_dt;i.pre_dt=t,i.r1x=i.centroidx-i.b1.posx,i.r1y=i.centroidy-i.b1.posy,i.r2x=i.centroidx-i.b2.posx,i.r2y=i.centroidy-i.b2.posy;let r=0,a=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(r=i.ws1.fluidProperties.gravityx,a=i.ws1.fluidProperties.gravityy):(r=this.gravityx,a=this.gravityy);let o=0,p=0;i.ws2.fluidEnabled&&i.ws2.fluidProperties.wrap_gravity!=null?(o=i.ws2.fluidProperties.gravityx,p=i.ws2.fluidProperties.gravityy):(o=this.gravityx,p=this.gravityy);let c=0,h=0;if(i.ws1.fluidEnabled&&i.ws2.fluidEnabled){let y=i.overlap*i.ws1.fluidProperties.density,d=i.overlap*i.ws2.fluidProperties.density;if(y>d){let _=y+d;c-=r*_,h-=a*_}else if(y<d){let _=y+d;c+=o*_,h+=p*_}else{let _=0,f=0;_=r+o,f=a+p;let z=.5;if(_*=z,f*=z,i.ws1.worldCOMx*_+i.ws1.worldCOMy*f>i.ws2.worldCOMx*_+i.ws2.worldCOMy*f){let P=y+d;c-=_*P,h-=f*P}else{let P=y+d;c+=_*P,h+=f*P}}}else if(i.ws1.fluidEnabled){let d=i.overlap*i.ws1.fluidProperties.density;c-=r*d,h-=a*d}else if(i.ws2.fluidEnabled){let d=i.overlap*i.ws2.fluidProperties.density;c+=o*d,h+=p*d}let u=t;if(c*=u,h*=u,i.buoyx=c,i.buoyy=h,i.b1.type==2){let y=i.b1.imass;i.b1.velx-=c*y,i.b1.vely-=h*y,i.b1.angvel-=(h*i.r1x-c*i.r1y)*i.b1.iinertia}if(i.b2.type==2){let y=i.b2.imass;i.b2.velx+=c*y,i.b2.vely+=h*y,i.b2.angvel+=(h*i.r2x-c*i.r2y)*i.b2.iinertia}if((!i.ws1.fluidEnabled||i.ws1.fluidProperties.viscosity==0)&&(!i.ws2.fluidEnabled||i.ws2.fluidProperties.viscosity==0))i.nodrag=!0,i.dampx=0,i.dampy=0,i.adamp=0;else{i.nodrag=!1;let y=0;if(i.ws1.fluidEnabled&&(i.ws2.validate_angDrag(),y+=i.ws1.fluidProperties.viscosity*i.ws2.angDrag*i.overlap/i.ws2.area),i.ws2.fluidEnabled&&(i.ws1.validate_angDrag(),y+=i.ws2.fluidProperties.viscosity*i.ws1.angDrag*i.overlap/i.ws1.area),y!=0){let z=i.b1.sinertia+i.b2.sinertia;z!=0?i.wMass=1/z:i.wMass=0,y*=4e-4;let P=2*Math.PI*y;i.agamma=1/(t*P*(2+P*t));let k=1/(1+i.agamma),m=t*P*P*i.agamma;i.agamma*=k,i.wMass*=k}else i.wMass=0,i.agamma=0;let d=i.b2.velx+i.b2.kinvelx-i.r2y*(i.b2.angvel+i.b2.kinangvel)-(i.b1.velx+i.b1.kinvelx-i.r1y*(i.b2.angvel+i.b2.kinangvel)),_=i.b2.vely+i.b2.kinvely+i.r2x*(i.b2.angvel+i.b2.kinangvel)-(i.b1.vely+i.b1.kinvely+i.r1x*(i.b1.angvel+i.b1.kinangvel));if(!(d*d+_*_<B._nape.Config.epsilon*B._nape.Config.epsilon)){let z=d*d+_*_,k=1/Math.sqrt(z);d*=k,_*=k,i.nx=d,i.ny=_}let f=0;if(i.ws1.fluidEnabled){let z=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)f-=z*i.ws2.circle.radius*B._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else{let P=i.ws2.polygon,k=0,m=0,b=P.edges.head;for(;b!=null;){let C=b.elt;k+=C.length;let v=z*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);v>0&&(v*=-B._nape.Config.fluidVacuumDrag,v=v),m-=v*.5*B._nape.Config.fluidLinearDrag,b=b.next}f+=m/k}}if(i.ws2.fluidEnabled){let z=-i.ws2.fluidProperties.viscosity*i.overlap/i.ws1.area;if(i.ws1.type==0)f-=z*i.ws1.circle.radius*B._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else{let P=i.ws1.polygon,k=0,m=0,b=P.edges.head;for(;b!=null;){let C=b.elt;k+=C.length;let v=z*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);v>0&&(v*=-B._nape.Config.fluidVacuumDrag,v=v),m-=v*.5*B._nape.Config.fluidLinearDrag,b=b.next}f+=m/k}}if(f!=0){let z=i.b1.smass+i.b2.smass,P=0,k=0,m=0;if(P=z,k=0,m=z,i.b1.sinertia!=0){let E=i.r1x*i.b1.sinertia,M=i.r1y*i.b1.sinertia;P+=M*i.r1y,k+=-M*i.r1x,m+=E*i.r1x}if(i.b2.sinertia!=0){let E=i.r2x*i.b2.sinertia,M=i.r2y*i.b2.sinertia;P+=M*i.r2y,k+=-M*i.r2x,m+=E*i.r2x}let b=P*m-k*k;if(b!=b)m=0,k=m,P=k;else if(b==0){let E=0;P!=0?P=1/P:(P=0,E|=1),m!=0?m=1/m:(m=0,E|=2),k=0}else{b=1/b;let E=m*b;m=P*b,P=E,k*=-b}i.vMassa=P,i.vMassb=k,i.vMassc=m;let C,v=2*Math.PI*f;i.lgamma=1/(t*v*(2+v*t));let w=1/(1+i.lgamma);C=t*v*v*i.lgamma,i.lgamma*=w;let O=w;i.vMassa*=O,i.vMassb*=O,i.vMassc*=O}else i.vMassa=0,i.vMassb=0,i.vMassc=0,i.lgamma=0}let x=l;i.dampx*=x,i.dampy*=x,i.adamp*=l}}else if(e.colarb!=null){let i=e.colarb,l=!0,r=null,a=null,o=i.innards.next;i.hc2=!1;let p=i.contacts.next;for(;p!=null;){let c=p;if(c.stamp+B._nape.Config.arbiterExpirationDelay<i.stamp){let x=i.contacts,y,d;r==null?(y=x.next,d=y.next,x.next=d,x.next==null&&(x.pushmod=!0)):(y=r.next,d=y.next,r.next=d,d==null&&(x.pushmod=!0)),y._inuse=!1,x.modified=!0,x.length--,x.pushmod=!0,p=d;let _=i.innards,f,z;a==null?(f=_.next,z=f.next,_.next=z,_.next==null&&(_.pushmod=!0)):(f=a.next,z=f.next,a.next=z,z==null&&(_.pushmod=!0)),f._inuse=!1,_.modified=!0,_.length--,_.pushmod=!0,o=z;let P=c;P.arbiter=null,P.next=Pe.zpp_pool,Pe.zpp_pool=P;continue}let h=c.inner,u=c.active;c.active=c.stamp==i.stamp,c.active&&(l?(l=!1,i.c1=h,i.oc1=c):(i.hc2=!0,i.c2=h,i.oc2=c)),u!=c.active&&(i.contacts.modified=!0),r=p,a=o,o=o.next,p=p.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let c=i.c1;i.c1=i.c2,i.c2=c;let h=i.oc1;i.oc1=i.oc2,i.oc2=h,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(l=!0)}else i.hpc2=!1;l&&(e.active=!1)}return s!=e.active&&(e.b1.arbiters.modified=!0,e.b2.arbiters.modified=!0,this.c_arbiters_true.modified=this.c_arbiters_false.modified=!0,this.s_arbiters.modified=this.f_arbiters.modified=!0),!1}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let d=n.elt;if(d.preStep(e)){n=this.live_constraints.erase(t),d.broken(),this.constraintCbBreak(d),d.removeOnBreak?(d.component.sleeping=!0,this.midstep=!1,d.compound!=null?d.compound.wrap_constraints.remove(d.outer):this.wrap_constraints.remove(d.outer),this.midstep=!0):d.active=!1,d.clearcache();continue}t=n,n=n.next}let s=null,i=this.c_arbiters_true,l=i.head,r=this.c_arbiters_false!=null;for(r&&l==null&&(r=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);l!=null;){let d=l.elt;if(this.presteparb(d,e)){let _,f;s==null?(_=i.head,f=_.next,i.head=f,i.head==null&&(i.pushmod=!0)):(_=s.next,f=_.next,s.next=f,f==null&&(i.pushmod=!0));let z=_;z.elt=null,z.next=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=z,i.modified=!0,i.length--,i.pushmod=!0,l=f,r&&l==null&&(r=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);continue}s=l,l=l.next,r&&l==null&&(r=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null)}let a=null,o=this.f_arbiters,p=o.head,c=!1;for(c&&p==null&&(c=!1,o=null,a=null);p!=null;){let d=p.elt;if(this.presteparb(d,e)){let _,f;a==null?(_=o.head,f=_.next,o.head=f,o.head==null&&(o.pushmod=!0)):(_=a.next,f=_.next,a.next=f,f==null&&(o.pushmod=!0));let z=_;z.elt=null,z.next=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=z,o.modified=!0,o.length--,o.pushmod=!0,p=f,c&&p==null&&(c=!1,o=null,a=null);continue}a=p,p=p.next,c&&p==null&&(c=!1,o=null,a=null)}let h=null,u=this.s_arbiters,x=u.head,y=!1;for(y&&x==null&&(y=!1,u=null,h=null);x!=null;){let d=x.elt;if(this.presteparb(d,e)){let _,f;h==null?(_=u.head,f=_.next,u.head=f,u.head==null&&(u.pushmod=!0)):(_=h.next,f=_.next,h.next=f,f==null&&(u.pushmod=!0));let z=_;z.elt=null,z.next=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=z,u.modified=!0,u.length--,u.pushmod=!0,x=f,y&&x==null&&(y=!1,u=null,h=null);continue}h=x,x=x.next,y&&x==null&&(y=!1,u=null,h=null)}}warmStart(){let e=this.f_arbiters.head;for(;e!=null;){let i=e.elt;if(i.active&&(i.immState&1)!=0){let l=i.b1.imass;i.b1.velx-=i.dampx*l,i.b1.vely-=i.dampy*l;let r=i.b2.imass;i.b2.velx+=i.dampx*r,i.b2.vely+=i.dampy*r,i.b1.angvel-=i.b1.iinertia*(i.dampy*i.r1x-i.dampx*i.r1y),i.b2.angvel+=i.b2.iinertia*(i.dampy*i.r2x-i.dampx*i.r2y),i.b1.angvel-=i.adamp*i.b1.iinertia,i.b2.angvel+=i.adamp*i.b2.iinertia}e=e.next}let t=this.c_arbiters_false.head,n=!0;for(t==null&&(t=this.c_arbiters_true.head,n=!1);t!=null;){let i=t.elt;if(i.active&&(i.immState&1)!=0){let l=i.nx*i.c1.jnAcc-i.ny*i.c1.jtAcc,r=i.ny*i.c1.jnAcc+i.nx*i.c1.jtAcc,a=i.b1.imass;i.b1.velx-=l*a,i.b1.vely-=r*a,i.b1.angvel-=i.b1.iinertia*(r*i.c1.r1x-l*i.c1.r1y);let o=i.b2.imass;if(i.b2.velx+=l*o,i.b2.vely+=r*o,i.b2.angvel+=i.b2.iinertia*(r*i.c1.r2x-l*i.c1.r2y),i.hc2){let p=i.nx*i.c2.jnAcc-i.ny*i.c2.jtAcc,c=i.ny*i.c2.jnAcc+i.nx*i.c2.jtAcc,h=i.b1.imass;i.b1.velx-=p*h,i.b1.vely-=c*h,i.b1.angvel-=i.b1.iinertia*(c*i.c2.r1x-p*i.c2.r1y);let u=i.b2.imass;i.b2.velx+=p*u,i.b2.vely+=c*u,i.b2.angvel+=i.b2.iinertia*(c*i.c2.r2x-p*i.c2.r2y)}i.b2.angvel+=i.jrAcc*i.b2.iinertia,i.b1.angvel-=i.jrAcc*i.b1.iinertia}t=t.next,n&&t==null&&(t=this.c_arbiters_true.head,n=!1)}let s=this.live_constraints.head;for(;s!=null;)s.elt.warmStart(),s=s.next}iterateVel(e){let t=0,n=e;for(;t<n;){let s=t++,i=this.f_arbiters.head;for(;i!=null;){let p=i.elt;if(p.active&&(p.immState&1)!=0&&!p.nodrag){let c=p.b1.angvel+p.b1.kinangvel,h=p.b2.angvel+p.b2.kinangvel,u=p.b1.velx+p.b1.kinvelx-p.r1y*c-(p.b2.velx+p.b2.kinvelx-p.r2y*h),x=p.b1.vely+p.b1.kinvely+p.r1x*c-(p.b2.vely+p.b2.kinvely+p.r2x*h),y=p.vMassa*u+p.vMassb*x;x=p.vMassb*u+p.vMassc*x,u=y;let d=p.lgamma;u-=p.dampx*d,x-=p.dampy*d;let _=1;p.dampx+=u*_,p.dampy+=x*_;let f=p.b1.imass;p.b1.velx-=u*f,p.b1.vely-=x*f;let z=p.b2.imass;p.b2.velx+=u*z,p.b2.vely+=x*z,p.b1.angvel-=p.b1.iinertia*(x*p.r1x-u*p.r1y),p.b2.angvel+=p.b2.iinertia*(x*p.r2x-u*p.r2y);let P=(c-h)*p.wMass-p.adamp*p.agamma;p.adamp+=P,p.b1.angvel-=P*p.b1.iinertia,p.b2.angvel+=P*p.b2.iinertia}i=i.next}let l=null,r=this.live_constraints.head;for(;r!=null;){let p=r.elt;if(p.applyImpulseVel()){r=this.live_constraints.erase(l),p.broken(),this.constraintCbBreak(p),p.removeOnBreak?(p.component.sleeping=!0,this.midstep=!1,p.compound!=null?p.compound.wrap_constraints.remove(p.outer):this.wrap_constraints.remove(p.outer),this.midstep=!0):p.active=!1,p.clearcache();continue}l=r,r=r.next}let a=this.c_arbiters_false.head,o=!0;for(a==null&&(a=this.c_arbiters_true.head,o=!1);a!=null;){let p=a.elt;if(p.active&&(p.immState&1)!=0){let c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),h=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),u=(h*p.nx-c*p.ny+p.surfacex)*p.c1.tMass,x=p.c1.friction*p.c1.jnAcc,y=p.c1.jtAcc,d=y-u;d>x?d=x:d<-x&&(d=-x),u=d-y,p.c1.jtAcc=d;let _=-p.ny*u,f=p.nx*u;if(p.b2.velx+=_*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=_*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rt1b*u*p.b2.iinertia,p.b1.angvel-=p.rt1a*u*p.b1.iinertia,p.hc2){let z=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),P=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);u=(P*p.nx-z*p.ny+p.surfacex)*p.c2.tMass,x=p.c2.friction*p.c2.jnAcc,y=p.c2.jtAcc,d=y-u,d>x?d=x:d<-x&&(d=-x),u=d-y,p.c2.jtAcc=d,_=-p.ny*u,f=p.nx*u,p.b2.velx+=_*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=_*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rt2b*u*p.b2.iinertia,p.b1.angvel-=p.rt2a*u*p.b1.iinertia,c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),h=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),z=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),P=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);let k=p.c1.jnAcc,m=p.c2.jnAcc,b=c*p.nx+h*p.ny+p.surfacey+p.c1.bounce-(p.Ka*k+p.Kb*m),C=z*p.nx+P*p.ny+p.surfacey+p.c2.bounce-(p.Kb*k+p.Kc*m),v=-(p.kMassa*b+p.kMassb*C),w=-(p.kMassb*b+p.kMassc*C);v>=0&&w>=0?(b=v-k,C=w-m,p.c1.jnAcc=v,p.c2.jnAcc=w):(v=-p.c1.nMass*b,v>=0&&p.Kb*v+C>=0?(b=v-k,C=-m,p.c1.jnAcc=v,p.c2.jnAcc=0):(w=-p.c2.nMass*C,w>=0&&p.Kb*w+b>=0?(b=-k,C=w-m,p.c1.jnAcc=0,p.c2.jnAcc=w):b>=0&&C>=0?(b=-k,C=-m,p.c1.jnAcc=p.c2.jnAcc=0):(b=0,C=0))),u=b+C,_=p.nx*u,f=p.ny*u,p.b2.velx+=_*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=_*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=(p.rn1b*b+p.rn2b*C)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*b+p.rn2a*C)*p.b1.iinertia}else p.radius!=0&&(u=(p.b2.angvel-p.b1.angvel)*p.rMass,x=p.rfric*p.c1.jnAcc,y=p.jrAcc,p.jrAcc-=u,p.jrAcc>x?p.jrAcc=x:p.jrAcc<-x&&(p.jrAcc=-x),u=p.jrAcc-y,p.b2.angvel+=u*p.b2.iinertia,p.b1.angvel-=u*p.b1.iinertia),c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),h=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),u=(p.c1.bounce+(p.nx*c+p.ny*h)+p.surfacey)*p.c1.nMass,y=p.c1.jnAcc,d=y-u,d<0&&(d=0),u=d-y,p.c1.jnAcc=d,_=p.nx*u,f=p.ny*u,p.b2.velx+=_*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=_*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rn1b*u*p.b2.iinertia,p.b1.angvel-=p.rn1a*u*p.b1.iinertia}a=a.next,o&&a==null&&(a=this.c_arbiters_true.head,o=!1)}}}iteratePos(e){let t=0,n=e;for(;t<n;){let s=t++,i=null,l=this.live_constraints.head;for(;l!=null;){let o=l.elt;if(!o.__velocity&&o.stiff&&o.applyImpulsePos()){l=this.live_constraints.erase(i),o.broken(),this.constraintCbBreak(o),o.removeOnBreak?(o.component.sleeping=!0,this.midstep=!1,o.compound!=null?o.compound.wrap_constraints.remove(o.outer):this.wrap_constraints.remove(o.outer),this.midstep=!0):o.active=!1,o.clearcache();continue}i=l,l=l.next}let r=this.c_arbiters_false.head,a=!0;for(r==null&&(r=this.c_arbiters_true.head,a=!1);r!=null;){let o=r.elt;if(o.active&&(o.immState&1)!=0)if(o.ptype==2){let p=o.c1,c=0,h=0;c=o.b2.axisy*p.lr2x-o.b2.axisx*p.lr2y,h=p.lr2x*o.b2.axisx+p.lr2y*o.b2.axisy;let u=1;c+=o.b2.posx*u,h+=o.b2.posy*u;let x=0,y=0;x=o.b1.axisy*p.lr1x-o.b1.axisx*p.lr1y,y=p.lr1x*o.b1.axisx+p.lr1y*o.b1.axisy;let d=1;x+=o.b1.posx*d,y+=o.b1.posy*d;let _=0,f=0;_=c-x,f=h-y;let z=Math.sqrt(_*_+f*f),P=o.radius-B._nape.Config.collisionSlop,k=z-P;if(_*o.nx+f*o.ny<0&&(_=-_,f=-f,k-=o.radius),k<0)if(z<B._nape.Config.epsilon)o.b1.smass!=0?o.b1.posx+=B._nape.Config.epsilon*10:o.b2.posx+=B._nape.Config.epsilon*10;else{let m=1/z;_*=m,f*=m;let b=.5*(x+c),C=.5*(y+h),v=z-P;x=b-o.b1.posx,y=C-o.b1.posy,c=b-o.b2.posx,h=C-o.b2.posy;let w=f*x-_*y,O=f*c-_*h,E=o.b2.smass+O*O*o.b2.sinertia+o.b1.smass+w*w*o.b1.sinertia;if(E!=0){let M=-o.biasCoef*v/E,N=0,Z=0,S=M;N=_*S,Z=f*S;let V=o.b1.imass;o.b1.posx-=N*V,o.b1.posy-=Z*V;let D=o.b1,T=-w*o.b1.iinertia*M;if(D.rot+=T,T*T>1e-4)D.axisx=Math.sin(D.rot),D.axisy=Math.cos(D.rot);else{let j=T*T,A=1-.5*j,W=1-j*j/8,Q=(A*D.axisx+T*D.axisy)*W;D.axisy=(A*D.axisy-T*D.axisx)*W,D.axisx=Q}let G=o.b2.imass;o.b2.posx+=N*G,o.b2.posy+=Z*G;let q=o.b2,R=O*o.b2.iinertia*M;if(q.rot+=R,R*R>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else{let j=R*R,A=1-.5*j,W=1-j*j/8,Q=(A*q.axisx+R*q.axisy)*W;q.axisy=(A*q.axisy-R*q.axisx)*W,q.axisx=Q}}}}else{let p=0,c=0,h,u=0,x=0,y=0,d=0;if(o.ptype==0){p=o.b1.axisy*o.lnormx-o.b1.axisx*o.lnormy,c=o.lnormx*o.b1.axisx+o.lnormy*o.b1.axisy,h=o.lproj+(p*o.b1.posx+c*o.b1.posy),u=o.b2.axisy*o.c1.lr1x-o.b2.axisx*o.c1.lr1y,x=o.c1.lr1x*o.b2.axisx+o.c1.lr1y*o.b2.axisy;let z=1;if(u+=o.b2.posx*z,x+=o.b2.posy*z,o.hpc2){y=o.b2.axisy*o.c2.lr1x-o.b2.axisx*o.c2.lr1y,d=o.c2.lr1x*o.b2.axisx+o.c2.lr1y*o.b2.axisy;let P=1;y+=o.b2.posx*P,d+=o.b2.posy*P}}else{p=o.b2.axisy*o.lnormx-o.b2.axisx*o.lnormy,c=o.lnormx*o.b2.axisx+o.lnormy*o.b2.axisy,h=o.lproj+(p*o.b2.posx+c*o.b2.posy),u=o.b1.axisy*o.c1.lr1x-o.b1.axisx*o.c1.lr1y,x=o.c1.lr1x*o.b1.axisx+o.c1.lr1y*o.b1.axisy;let z=1;if(u+=o.b1.posx*z,x+=o.b1.posy*z,o.hpc2){y=o.b1.axisy*o.c2.lr1x-o.b1.axisx*o.c2.lr1y,d=o.c2.lr1x*o.b1.axisx+o.c2.lr1y*o.b1.axisy;let P=1;y+=o.b1.posx*P,d+=o.b1.posy*P}}let _=u*p+x*c-h-o.radius;_+=B._nape.Config.collisionSlop;let f=0;if(o.hpc2&&(f=y*p+d*c-h-o.radius,f+=B._nape.Config.collisionSlop),_<0||f<0){o.rev&&(p=-p,c=-c);let z=0,P=0;z=u-o.b1.posx,P=x-o.b1.posy;let k=0,m=0;k=u-o.b2.posx,m=x-o.b2.posy;let b=0,C=0,v=0,w=0;if(o.hpc2){b=y-o.b1.posx,C=d-o.b1.posy,v=y-o.b2.posx,w=d-o.b2.posy;let O=c*z-p*P,E=c*k-p*m,M=c*b-p*C,N=c*v-p*w,Z=o.b1.smass+o.b2.smass;o.kMassa=Z+o.b1.sinertia*O*O+o.b2.sinertia*E*E,o.kMassb=Z+o.b1.sinertia*O*M+o.b2.sinertia*E*N,o.kMassc=Z+o.b1.sinertia*M*M+o.b2.sinertia*N*N;let S=0,V=0,D=0;S=o.kMassa,V=o.kMassb,D=o.kMassc;let T=_*o.biasCoef,G=f*o.biasCoef;for(;;){let q=0,R=0;q=T,R=G,q=-q,R=-R;let j=o.kMassa*o.kMassc-o.kMassb*o.kMassb;if(j!=j)R=0,q=R;else if(j==0)o.kMassa!=0?q/=o.kMassa:q=0,o.kMassc!=0?R/=o.kMassc:R=0;else{j=1/j;let Q=j*(o.kMassc*q-o.kMassb*R);R=j*(o.kMassa*R-o.kMassb*q),q=Q}if(q>=0&&R>=0){let Q=(q+R)*o.b1.imass;o.b1.posx-=p*Q,o.b1.posy-=c*Q;let Y=o.b1,X=-o.b1.iinertia*(O*q+M*R);if(Y.rot+=X,X*X>1e-4)Y.axisx=Math.sin(Y.rot),Y.axisy=Math.cos(Y.rot);else{let F=X*X,I=1-.5*F,U=1-F*F/8,$=(I*Y.axisx+X*Y.axisy)*U;Y.axisy=(I*Y.axisy-X*Y.axisx)*U,Y.axisx=$}let ee=(q+R)*o.b2.imass;o.b2.posx+=p*ee,o.b2.posy+=c*ee;let J=o.b2,L=o.b2.iinertia*(E*q+N*R);if(J.rot+=L,L*L>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let F=L*L,I=1-.5*F,U=1-F*F/8,$=(I*J.axisx+L*J.axisy)*U;J.axisy=(I*J.axisy-L*J.axisx)*U,J.axisx=$}break}q=-T/S,R=0;let A=V*q+G;if(q>=0&&A>=0){let Q=(q+R)*o.b1.imass;o.b1.posx-=p*Q,o.b1.posy-=c*Q;let Y=o.b1,X=-o.b1.iinertia*(O*q+M*R);if(Y.rot+=X,X*X>1e-4)Y.axisx=Math.sin(Y.rot),Y.axisy=Math.cos(Y.rot);else{let F=X*X,I=1-.5*F,U=1-F*F/8,$=(I*Y.axisx+X*Y.axisy)*U;Y.axisy=(I*Y.axisy-X*Y.axisx)*U,Y.axisx=$}let ee=(q+R)*o.b2.imass;o.b2.posx+=p*ee,o.b2.posy+=c*ee;let J=o.b2,L=o.b2.iinertia*(E*q+N*R);if(J.rot+=L,L*L>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let F=L*L,I=1-.5*F,U=1-F*F/8,$=(I*J.axisx+L*J.axisy)*U;J.axisy=(I*J.axisy-L*J.axisx)*U,J.axisx=$}break}q=0,R=-G/D;let W=V*R+T;if(R>=0&&W>=0){let Q=(q+R)*o.b1.imass;o.b1.posx-=p*Q,o.b1.posy-=c*Q;let Y=o.b1,X=-o.b1.iinertia*(O*q+M*R);if(Y.rot+=X,X*X>1e-4)Y.axisx=Math.sin(Y.rot),Y.axisy=Math.cos(Y.rot);else{let F=X*X,I=1-.5*F,U=1-F*F/8,$=(I*Y.axisx+X*Y.axisy)*U;Y.axisy=(I*Y.axisy-X*Y.axisx)*U,Y.axisx=$}let ee=(q+R)*o.b2.imass;o.b2.posx+=p*ee,o.b2.posy+=c*ee;let J=o.b2,L=o.b2.iinertia*(E*q+N*R);if(J.rot+=L,L*L>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let F=L*L,I=1-.5*F,U=1-F*F/8,$=(I*J.axisx+L*J.axisy)*U;J.axisy=(I*J.axisy-L*J.axisx)*U,J.axisx=$}break}break}}else{let O=c*z-p*P,E=c*k-p*m,M=o.b2.smass+E*E*o.b2.sinertia+o.b1.smass+O*O*o.b1.sinertia;if(M!=0){let N=-o.biasCoef*_/M,Z=0,S=0,V=N;Z=p*V,S=c*V;let D=o.b1.imass;o.b1.posx-=Z*D,o.b1.posy-=S*D;let T=o.b1,G=-O*o.b1.iinertia*N;if(T.rot+=G,G*G>1e-4)T.axisx=Math.sin(T.rot),T.axisy=Math.cos(T.rot);else{let A=G*G,W=1-.5*A,Q=1-A*A/8,Y=(W*T.axisx+G*T.axisy)*Q;T.axisy=(W*T.axisy-G*T.axisx)*Q,T.axisx=Y}let q=o.b2.imass;o.b2.posx+=Z*q,o.b2.posy+=S*q;let R=o.b2,j=E*o.b2.iinertia*N;if(R.rot+=j,j*j>1e-4)R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.rot);else{let A=j*j,W=1-.5*A,Q=1-A*A/8,Y=(W*R.axisx+j*R.axisy)*Q;R.axisy=(W*R.axisy-j*R.axisx)*Q,R.axisx=Y}}}}}r=r.next,a&&r==null&&(r=this.c_arbiters_true.head,a=!1)}}}group_ignore(e,t){let n=e;for(;n!=null&&n.group==null;)n.ishape!=null?n=n.ishape.body:n.icompound!=null?n=n.icompound.compound:n=n.ibody.compound;let s=n==null?null:n.group;if(s==null)return!1;{let i=t;for(;i!=null&&i.group==null;)i.ishape!=null?i=i.ishape.body:i.icompound!=null?i=i.icompound.compound:i=i.ibody.compound;let l=i==null?null:i.group;if(l==null)return!1;{let r=!1;for(;s!=null&&l!=null;){if(s==l){r=s.ignore;break}s.depth<l.depth?l=l.group:s=s.group}return r}}}interactionType(e,t,n,s){let i;i=!1;let l=n.constraints.head;for(;l!=null;){let a=l.elt;if(a.ignore&&a.pair_exists(n.id,s.id)){i=!0;break}l=l.next}let r;if(i)r=!1;else{let a=e;for(;a!=null&&a.group==null;)a.ishape!=null?a=a.ishape.body:a.icompound!=null?a=a.icompound.compound:a=a.ibody.compound;let o=a==null?null:a.group,p;if(o==null)p=!1;else{let c=t;for(;c!=null&&c.group==null;)c.ishape!=null?c=c.ishape.body:c.icompound!=null?c=c.icompound.compound:c=c.ibody.compound;let h=c==null?null:c.group;if(h==null)p=!1;else{let u=!1;for(;o!=null&&h!=null;){if(o==h){u=o.ignore;break}o.depth<h.depth?h=h.group:o=o.group}p=u}}r=!p}if(r){let a;if(e.sensorEnabled||t.sensorEnabled){let o=e.filter,p=t.filter;a=(o.sensorMask&p.sensorGroup)!=0&&(p.sensorMask&o.sensorGroup)!=0}else a=!1;if(a)return 2;{let o;if(e.fluidEnabled||t.fluidEnabled){let p=e.filter,c=t.filter;o=(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0}else o=!1;if(o&&!(n.imass==0&&s.imass==0&&n.iinertia==0&&s.iinertia==0))return 0;{let p=e.filter,c=t.filter;return(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!(n.imass==0&&s.imass==0&&n.iinertia==0&&s.iinertia==0)?1:-1}}}else return-1}narrowPhase(e,t,n,s,i){let l=null,r=e.body,a=t.body,o;o=!1;let p=r.constraints.head;for(;p!=null;){let u=p.elt;if(u.ignore&&u.pair_exists(r.id,a.id)){o=!0;break}p=p.next}let c,h;if(o)h=!1;else{let u=e;for(;u!=null&&u.group==null;)u.ishape!=null?u=u.ishape.body:u.icompound!=null?u=u.icompound.compound:u=u.ibody.compound;let x=u==null?null:u.group,y;if(x==null)y=!1;else{let d=t;for(;d!=null&&d.group==null;)d.ishape!=null?d=d.ishape.body:d.icompound!=null?d=d.icompound.compound:d=d.ibody.compound;let _=d==null?null:d.group;if(_==null)y=!1;else{let f=!1;for(;x!=null&&_!=null;){if(x==_){f=x.ignore;break}x.depth<_.depth?_=_.group:x=x.group}y=f}}h=!y}if(h){let u;if(e.sensorEnabled||t.sensorEnabled){let x=e.filter,y=t.filter;u=(x.sensorMask&y.sensorGroup)!=0&&(y.sensorMask&x.sensorGroup)!=0}else u=!1;if(u)c=2;else{let x;if(e.fluidEnabled||t.fluidEnabled){let y=e.filter,d=t.filter;x=(y.fluidMask&d.fluidGroup)!=0&&(d.fluidMask&y.fluidGroup)!=0}else x=!1;if(x&&!(r.imass==0&&a.imass==0&&r.iinertia==0&&a.iinertia==0))c=0;else{let y=e.filter,d=t.filter;c=(y.collisionMask&d.collisionGroup)!=0&&(d.collisionMask&y.collisionGroup)!=0&&!(r.imass==0&&a.imass==0&&r.iinertia==0&&a.iinertia==0)?1:-1}}}else c=-1;if(c!=-1){let u,x;e.type>t.type?(u=t,x=e):e.type==t.type?e.id<t.id?(u=e,x=t):(x=e,u=t):(u=e,x=t);let y=u==t;if(c==0){let d;if(s==null){let k=null,b=(r.arbiters.length<a.arbiters.length?r:a).arbiters.head;for(;b!=null;){let C=b.elt;if(C.id==u.id&&C.di==x.id){k=C;break}b=b.next}d=k}else d=s;let _=d==null,f,z=!1;if(_)zt.zpp_pool==null?f=new zt:(f=zt.zpp_pool,zt.zpp_pool=f.next,f.next=null);else if(d.fluidarb==null){d.cleared=!0;{let m=d.b1.arbiters,b=null,C=m.head,v=!1;for(;C!=null;){if(C.elt==d){let w,O;b==null?(w=m.head,O=w.next,m.head=O,m.head==null&&(m.pushmod=!0)):(w=b.next,O=w.next,b.next=O,O==null&&(m.pushmod=!0));let E=w;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,m.modified=!0,m.length--,m.pushmod=!0,v=!0;break}b=C,C=C.next}}{let m=d.b2.arbiters,b=null,C=m.head,v=!1;for(;C!=null;){if(C.elt==d){let w,O;b==null?(w=m.head,O=w.next,m.head=O,m.head==null&&(m.pushmod=!0)):(w=b.next,O=w.next,b.next=O,O==null&&(m.pushmod=!0));let E=w;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,m.modified=!0,m.length--,m.pushmod=!0,v=!0;break}b=C,C=C.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,zt.zpp_pool==null?f=new zt:(f=zt.zpp_pool,zt.zpp_pool=f.next,f.next=null),f.intchange=!0,_=!0,z=!0}else f=d.fluidarb;let P=4;if(_||f.stamp!=this.stamp||i)if(f.stamp=this.stamp,Ee.flowCollide(u,x,f)){if(_){let k=x.id;f.b1=e.body,f.ws1=e,f.b2=t.body,f.ws2=t,f.id=u.id,f.di=k;let m=f.b1.arbiters,b;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?b=new B._zpp.util.ZNPNode_ZPP_Arbiter:(b=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b.next,b.next=null),b.elt=f;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=f.b2.arbiters,w;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?w=new B._zpp.util.ZNPNode_ZPP_Arbiter:(w=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=w.next,w.next=null),w.elt=f;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++,f.active=!0,f.present=0,f.cleared=!1,f.sleeping=!1,f.fresh=!1,f.presentable=!1,f.nx=0,f.ny=1,f.dampx=0,f.dampy=0,f.adamp=0;let E=this.f_arbiters,M;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?M=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(M=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=M.next,M.next=null),M.elt=f;let N=M;N.next=E.head,E.head=N,E.modified=!0,E.length++,f.fresh=!z}else f.fresh=f.up_stamp<this.stamp-1||f.endGenerated==this.stamp&&i;if(f.up_stamp=f.stamp,f.fresh||(f.immState&4)==0){f.immState=1;let k=!1,m=f.ws1.id>f.ws2.id?f.ws2:f.ws1,b=f.ws1.id>f.ws2.id?f.ws1:f.ws2,C=this.mrca1;for(;C.head!=null;){let M=C.head;C.head=M.next;let N=M;N.elt=null,N.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N,C.head==null&&(C.pushmod=!0),C.modified=!0,C.length--}C.pushmod=!0;let v=this.mrca2;for(;v.head!=null;){let M=v.head;v.head=M.next;let N=M;N.elt=null,N.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N,v.head==null&&(v.pushmod=!0),v.modified=!0,v.length--}if(v.pushmod=!0,m.cbSet!=null){let M=this.mrca1,N;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new B._zpp.util.ZNPNode_ZPP_Interactor:(N=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=m;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(m.body.cbSet!=null){let M=this.mrca1,N=m.body,Z;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?Z=new B._zpp.util.ZNPNode_ZPP_Interactor:(Z=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z.next,Z.next=null),Z.elt=N;let S=Z;S.next=M.head,M.head=S,M.modified=!0,M.length++}if(b.cbSet!=null){let M=this.mrca2,N;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new B._zpp.util.ZNPNode_ZPP_Interactor:(N=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=b;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(b.body.cbSet!=null){let M=this.mrca2,N=b.body,Z;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?Z=new B._zpp.util.ZNPNode_ZPP_Interactor:(Z=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z.next,Z.next=null),Z.elt=N;let S=Z;S.next=M.head,M.head=S,M.modified=!0,M.length++}let w=m.body.compound,O=b.body.compound;for(;w!=O;){let M=w==null?0:w.depth,N=O==null?0:O.depth;if(M<N){if(O.cbSet!=null){let Z=this.mrca2,S;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new B._zpp.util.ZNPNode_ZPP_Interactor:(S=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=O;let V=S;V.next=Z.head,Z.head=V,Z.modified=!0,Z.length++}O=O.compound}else{if(w.cbSet!=null){let Z=this.mrca1,S;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new B._zpp.util.ZNPNode_ZPP_Interactor:(S=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=w;let V=S;V.next=Z.head,Z.head=V,Z.modified=!0,Z.length++}w=w.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,N=this.mrca2.head;for(;N!=null;){let Z=N.elt,S=M.cbSet,V=Z.cbSet,D=S.manager,T=null,q=(S.cbpairs.length<V.cbpairs.length?S.cbpairs:V.cbpairs).head;for(;q!=null;){let L=q.elt;if(L.a==S&&L.b==V||L.a==V&&L.b==S){T=L;break}q=q.next}if(T==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=!0,dt.setlt(S,V)?(L.a=S,L.b=V):(L.a=V,L.b=S),T=L,S.cbpairs.add(T),V!=S&&V.cbpairs.add(T)}if(T.zip_listeners&&(T.zip_listeners=!1,T.__validate()),T.listeners.head==null){N=N.next;continue}let R=null,j=null,A=this.prelisteners;for(;A.head!=null;){let L=A.head;A.head=L.next;let F=L;F.elt=null,F.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=F,A.head==null&&(A.pushmod=!0),A.modified=!0,A.length--}A.pushmod=!0;let W=null,Q=S.manager,Y=null,ee=(S.cbpairs.length<V.cbpairs.length?S.cbpairs:V.cbpairs).head;for(;ee!=null;){let L=ee.elt;if(L.a==S&&L.b==V||L.a==V&&L.b==S){Y=L;break}ee=ee.next}if(Y==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=!0,dt.setlt(S,V)?(L.a=S,L.b=V):(L.a=V,L.b=S),Y=L,S.cbpairs.add(Y),V!=S&&V.cbpairs.add(Y)}Y.zip_listeners&&(Y.zip_listeners=!1,Y.__validate());let J=Y.listeners.head;for(;J!=null;){let L=J.elt;if(L.event==5&&(L.itype&P)!=0){let F=this.prelisteners,I;B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?I=new B._zpp.util.ZNPNode_ZPP_InteractionListener:(I=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=I.next,I.next=null),I.elt=L;let U=I;W==null?(U.next=F.head,F.head=U):(U.next=W.next,W.next=U),F.pushmod=F.modified=!0,F.length++,W=U,k=k||!L.pure}J=J.next}if(this.prelisteners.head==null){N=N.next;continue}if(R=B._zpp.phys.ZPP_Interactor.get(M,Z),R==null&&(j=qt.get(M,Z),this.add_callbackset(j)),R==null||(R.FLUIDstamp!=this.stamp||i)&&(R.FLUIDstate&4)==0){if(j!=null&&(R=j),R!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(R.COLLISIONstamp=this.stamp,R.SENSORstamp=this.stamp,R.FLUIDstamp=this.stamp):R.FLUIDstamp=this.stamp,U=U.next}f.mutable=!0,f.wrap_position!=null&&(f.wrap_position.zpp_inner._immutable=!1);let L=f.active;f.active=!0;let F=!1;this.precb.zpp_inner.pre_arbiter=f,this.precb.zpp_inner.set=R;let I=this.prelisteners.head;for(;I!=null;){let U=I.elt;this.precb.zpp_inner.listener=U;let $=this.precb.zpp_inner,K=R.int1,ie=R.int2,re,se=U.options1,te=K.cbTypes;if(se.nonemptyintersection(te,se.includes)&&!se.nonemptyintersection(te,se.excludes)){let pe=U.options2,ce=ie.cbTypes;re=pe.nonemptyintersection(ce,pe.includes)&&!pe.nonemptyintersection(ce,pe.excludes)}else re=!1;re?($.int1=K,$.int2=ie):($.int1=ie,$.int2=K),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let oe=U.handlerp(this.precb);if(oe!=null){let pe;H.PreFlag_ACCEPT==null&&(H.internal=!0,H.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,H.internal=!1),oe==H.PreFlag_ACCEPT?pe=5:(H.PreFlag_ACCEPT_ONCE==null&&(H.internal=!0,H.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,H.internal=!1),oe==H.PreFlag_ACCEPT_ONCE?pe=1:(H.PreFlag_IGNORE==null&&(H.internal=!0,H.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,H.internal=!1),pe=oe==H.PreFlag_IGNORE?6:2)),f.immState=pe}I=I.next}if(f.mutable=!1,f.wrap_position!=null&&(f.wrap_position.zpp_inner._immutable=!0),f.active=L,R!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7&&(R.COLLISIONstate=f.immState,R.SENSORstate=f.immState),R.FLUIDstate=f.immState,U=U.next}}else R==null?(f.immState&4)==0&&(f.immState=1):f.immState=R.FLUIDstate;N=N.next}E=E.next}if(k&&(f.immState&4)==0){if(f.b1.type==2){let M=f.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}if(f.b1.type==2){let M=f.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}}}if((f.immState&1)!=0){if(f.b1.type==2&&f.b1.component.sleeping){let k=f.b1;k.world||(k.component.waket=this.stamp+(this.midstep?0:1),k.type==3&&(k.kinematicDelaySleep=!0),k.component.sleeping&&this.really_wake(k,!1))}if(f.b2.type==2&&f.b2.component.sleeping){let k=f.b2;k.world||(k.component.waket=this.stamp+(this.midstep?0:1),k.type==3&&(k.kinematicDelaySleep=!0),k.component.sleeping&&this.really_wake(k,!1))}}if(f.sleeping){f.sleeping=!1;let k=this.f_arbiters,m;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?m=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(m=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=m.next,m.next=null),m.elt=f;let b=m;b.next=k.head,k.head=b,k.modified=!0,k.length++}l=f}else if(_){let k=f;k.next=zt.zpp_pool,zt.zpp_pool=k,l=null}else l=f;else l=f}else if(c==1){let d=n?this.c_arbiters_true:this.c_arbiters_false,_;if(s==null){let m=null,C=(r.arbiters.length<a.arbiters.length?r:a).arbiters.head;for(;C!=null;){let v=C.elt;if(v.id==u.id&&v.di==x.id){m=v;break}C=C.next}_=m}else _=s;let f=_==null,z,P=!1;if(f)pt.zpp_pool==null?z=new pt:(z=pt.zpp_pool,pt.zpp_pool=z.next,z.next=null),z.stat=n;else if(_.colarb==null){_.cleared=!0;{let b=_.b1.arbiters,C=null,v=b.head,w=!1;for(;v!=null;){if(v.elt==_){let O,E;C==null?(O=b.head,E=O.next,b.head=E,b.head==null&&(b.pushmod=!0)):(O=C.next,E=O.next,C.next=E,E==null&&(b.pushmod=!0));let M=O;M.elt=null,M.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,b.modified=!0,b.length--,b.pushmod=!0,w=!0;break}C=v,v=v.next}}{let b=_.b2.arbiters,C=null,v=b.head,w=!1;for(;v!=null;){if(v.elt==_){let O,E;C==null?(O=b.head,E=O.next,b.head=E,b.head==null&&(b.pushmod=!0)):(O=C.next,E=O.next,C.next=E,E==null&&(b.pushmod=!0));let M=O;M.elt=null,M.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,b.modified=!0,b.length--,b.pushmod=!0,w=!0;break}C=v,v=v.next}}_.pair!=null&&(_.pair.arb=null,_.pair=null),_.active=!1,this.f_arbiters.modified=!0,pt.zpp_pool==null?z=new pt:(z=pt.zpp_pool,pt.zpp_pool=z.next,z.next=null),z.intchange=!0,z.stat=n,f=!0,P=!0}else z=_.colarb,y=u!=z.s1,z.stat!=n&&(z.stat=n,z.sleeping||((n?this.c_arbiters_false:this.c_arbiters_true).remove(z),d.add(z)));let k=1;if(f||z.stamp!=this.stamp||i)if(z.stamp=this.stamp,Ee.contactCollide(u,x,z,y)){if(f){let m=x.id;z.b1=e.body,z.ws1=e,z.b2=t.body,z.ws2=t,z.id=u.id,z.di=m;let b=z.b1.arbiters,C;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?C=new B._zpp.util.ZNPNode_ZPP_Arbiter:(C=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=C.next,C.next=null),C.elt=z;let v=C;v.next=b.head,b.head=v,b.modified=!0,b.length++;let w=z.b2.arbiters,O;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?O=new B._zpp.util.ZNPNode_ZPP_Arbiter:(O=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=O.next,O.next=null),O.elt=z;let E=O;E.next=w.head,w.head=E,w.modified=!0,w.length++,z.active=!0,z.present=0,z.cleared=!1,z.sleeping=!1,z.fresh=!1,z.presentable=!1,z.s1=e,z.s2=t,z.userdef_restitution||(z.s1.material.elasticity<=-1/0||z.s2.material.elasticity<=-1/0?z.restitution=0:z.s1.material.elasticity>=1/0||z.s2.material.elasticity>=1/0?z.restitution=1:z.restitution=(z.s1.material.elasticity+z.s2.material.elasticity)/2,z.restitution<0&&(z.restitution=0),z.restitution>1&&(z.restitution=1)),z.userdef_dyn_fric||(z.dyn_fric=Math.sqrt(z.s1.material.dynamicFriction*z.s2.material.dynamicFriction)),z.userdef_stat_fric||(z.stat_fric=Math.sqrt(z.s1.material.staticFriction*z.s2.material.staticFriction)),z.userdef_rfric||(z.rfric=Math.sqrt(z.s1.material.rollingFriction*z.s2.material.rollingFriction));let M;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?M=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(M=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=M.next,M.next=null),M.elt=z;let N=M;N.next=d.head,d.head=N,d.modified=!0,d.length++,z.fresh=!P}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&i;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let m=!1,b=z.ws1.id>z.ws2.id?z.ws2:z.ws1,C=z.ws1.id>z.ws2.id?z.ws1:z.ws2,v=this.mrca1;for(;v.head!=null;){let N=v.head;v.head=N.next;let Z=N;Z.elt=null,Z.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z,v.head==null&&(v.pushmod=!0),v.modified=!0,v.length--}v.pushmod=!0;let w=this.mrca2;for(;w.head!=null;){let N=w.head;w.head=N.next;let Z=N;Z.elt=null,Z.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z,w.head==null&&(w.pushmod=!0),w.modified=!0,w.length--}if(w.pushmod=!0,b.cbSet!=null){let N=this.mrca1,Z;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?Z=new B._zpp.util.ZNPNode_ZPP_Interactor:(Z=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z.next,Z.next=null),Z.elt=b;let S=Z;S.next=N.head,N.head=S,N.modified=!0,N.length++}if(b.body.cbSet!=null){let N=this.mrca1,Z=b.body,S;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new B._zpp.util.ZNPNode_ZPP_Interactor:(S=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=Z;let V=S;V.next=N.head,N.head=V,N.modified=!0,N.length++}if(C.cbSet!=null){let N=this.mrca2,Z;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?Z=new B._zpp.util.ZNPNode_ZPP_Interactor:(Z=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z.next,Z.next=null),Z.elt=C;let S=Z;S.next=N.head,N.head=S,N.modified=!0,N.length++}if(C.body.cbSet!=null){let N=this.mrca2,Z=C.body,S;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new B._zpp.util.ZNPNode_ZPP_Interactor:(S=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=Z;let V=S;V.next=N.head,N.head=V,N.modified=!0,N.length++}let O=b.body.compound,E=C.body.compound;for(;O!=E;){let N=O==null?0:O.depth,Z=E==null?0:E.depth;if(N<Z){if(E.cbSet!=null){let S=this.mrca2,V;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?V=new B._zpp.util.ZNPNode_ZPP_Interactor:(V=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=V.next,V.next=null),V.elt=E;let D=V;D.next=S.head,S.head=D,S.modified=!0,S.length++}E=E.compound}else{if(O.cbSet!=null){let S=this.mrca1,V;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?V=new B._zpp.util.ZNPNode_ZPP_Interactor:(V=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=V.next,V.next=null),V.elt=O;let D=V;D.next=S.head,S.head=D,S.modified=!0,S.length++}O=O.compound}}let M=this.mrca1.head;for(;M!=null;){let N=M.elt,Z=this.mrca2.head;for(;Z!=null;){let S=Z.elt,V=N.cbSet,D=S.cbSet,T=V.manager,G=null,R=(V.cbpairs.length<D.cbpairs.length?V.cbpairs:D.cbpairs).head;for(;R!=null;){let F=R.elt;if(F.a==V&&F.b==D||F.a==D&&F.b==V){G=F;break}R=R.next}if(G==null){let F;Ne.zpp_pool==null?F=new Ne:(F=Ne.zpp_pool,Ne.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,dt.setlt(V,D)?(F.a=V,F.b=D):(F.a=D,F.b=V),G=F,V.cbpairs.add(G),D!=V&&D.cbpairs.add(G)}if(G.zip_listeners&&(G.zip_listeners=!1,G.__validate()),G.listeners.head==null){Z=Z.next;continue}let j=null,A=null,W=this.prelisteners;for(;W.head!=null;){let F=W.head;W.head=F.next;let I=F;I.elt=null,I.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=I,W.head==null&&(W.pushmod=!0),W.modified=!0,W.length--}W.pushmod=!0;let Q=null,Y=V.manager,X=null,J=(V.cbpairs.length<D.cbpairs.length?V.cbpairs:D.cbpairs).head;for(;J!=null;){let F=J.elt;if(F.a==V&&F.b==D||F.a==D&&F.b==V){X=F;break}J=J.next}if(X==null){let F;Ne.zpp_pool==null?F=new Ne:(F=Ne.zpp_pool,Ne.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,dt.setlt(V,D)?(F.a=V,F.b=D):(F.a=D,F.b=V),X=F,V.cbpairs.add(X),D!=V&&D.cbpairs.add(X)}X.zip_listeners&&(X.zip_listeners=!1,X.__validate());let L=X.listeners.head;for(;L!=null;){let F=L.elt;if(F.event==5&&(F.itype&k)!=0){let I=this.prelisteners,U;B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?U=new B._zpp.util.ZNPNode_ZPP_InteractionListener:(U=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=U.next,U.next=null),U.elt=F;let $=U;Q==null?($.next=I.head,I.head=$):($.next=Q.next,Q.next=$),I.pushmod=I.modified=!0,I.length++,Q=$,m=m||!F.pure}L=L.next}if(this.prelisteners.head==null){Z=Z.next;continue}if(j=B._zpp.phys.ZPP_Interactor.get(N,S),j==null&&(A=qt.get(N,S),this.add_callbackset(A)),j==null||(j.COLLISIONstamp!=this.stamp||i)&&(j.COLLISIONstate&4)==0){if(A!=null&&(j=A),j!=null){let te=this.prelisteners.head;for(;te!=null;)te.elt.itype==7?(j.COLLISIONstamp=this.stamp,j.SENSORstamp=this.stamp,j.FLUIDstamp=this.stamp):j.COLLISIONstamp=this.stamp,te=te.next}z.mutable=!0,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!1),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!1);let F=z.active;z.active=!0;let I=!1,U=!0,$=null,K=null,ie=z.innards.next;z.hc2=!1;let re=z.contacts.next;for(;re!=null;){let te=re;if(te.stamp+B._nape.Config.arbiterExpirationDelay<z.stamp){let ce=z.contacts,ae,ue;$==null?(ae=ce.next,ue=ae.next,ce.next=ue,ce.next==null&&(ce.pushmod=!0)):(ae=$.next,ue=ae.next,$.next=ue,ue==null&&(ce.pushmod=!0)),ae._inuse=!1,ce.modified=!0,ce.length--,ce.pushmod=!0,re=ue;let ne=z.innards,he,ye;K==null?(he=ne.next,ye=he.next,ne.next=ye,ne.next==null&&(ne.pushmod=!0)):(he=K.next,ye=he.next,K.next=ye,ye==null&&(ne.pushmod=!0)),he._inuse=!1,ne.modified=!0,ne.length--,ne.pushmod=!0,ie=ye;let de=te;de.arbiter=null,de.next=Pe.zpp_pool,Pe.zpp_pool=de;continue}let oe=te.inner,pe=te.active;te.active=te.stamp==z.stamp,te.active&&(U?(U=!1,z.c1=oe,z.oc1=te):(z.hc2=!0,z.c2=oe,z.oc2=te)),pe!=te.active&&(z.contacts.modified=!0),$=re,K=ie,ie=ie.next,re=re.next}if(z.hc2){if(z.hpc2=!0,z.oc1.posOnly){let te=z.c1;z.c1=z.c2,z.c2=te;let oe=z.oc1;z.oc1=z.oc2,z.oc2=oe,z.hc2=!1}else z.oc2.posOnly&&(z.hc2=!1);z.oc1.posOnly&&(U=!0)}else z.hpc2=!1;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=j;let se=this.prelisteners.head;for(;se!=null;){let te=se.elt;this.precb.zpp_inner.listener=te;let oe=this.precb.zpp_inner,pe=j.int1,ce=j.int2,ae,ue=te.options1,ne=pe.cbTypes;if(ue.nonemptyintersection(ne,ue.includes)&&!ue.nonemptyintersection(ne,ue.excludes)){let ye=te.options2,de=ce.cbTypes;ae=ye.nonemptyintersection(de,ye.includes)&&!ye.nonemptyintersection(de,ye.excludes)}else ae=!1;ae?(oe.int1=pe,oe.int2=ce):(oe.int1=ce,oe.int2=pe),this.precb.zpp_inner.pre_swapped=N!=this.precb.zpp_inner.int1;let he=te.handlerp(this.precb);if(he!=null){let ye;H.PreFlag_ACCEPT==null&&(H.internal=!0,H.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,H.internal=!1),he==H.PreFlag_ACCEPT?ye=5:(H.PreFlag_ACCEPT_ONCE==null&&(H.internal=!0,H.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,H.internal=!1),he==H.PreFlag_ACCEPT_ONCE?ye=1:(H.PreFlag_IGNORE==null&&(H.internal=!0,H.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,H.internal=!1),ye=he==H.PreFlag_IGNORE?6:2)),z.immState=ye}se=se.next}if(z.mutable=!1,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!0),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!0),z.active=F,j!=null){let te=this.prelisteners.head;for(;te!=null;)te.elt.itype==7?(j.COLLISIONstate=z.immState,j.SENSORstate=z.immState,j.FLUIDstate=z.immState):j.COLLISIONstate=z.immState,te=te.next}}else j==null?(z.immState&4)==0&&(z.immState=1):z.immState=j.COLLISIONstate;Z=Z.next}M=M.next}if(m&&(z.immState&4)==0){if(z.b1.type==2){let N=z.b1;N.world||(N.component.waket=this.stamp+(this.midstep?0:1),N.type==3&&(N.kinematicDelaySleep=!0),N.component.sleeping&&this.really_wake(N,!1))}if(z.b1.type==2){let N=z.b2;N.world||(N.component.waket=this.stamp+(this.midstep?0:1),N.type==3&&(N.kinematicDelaySleep=!0),N.component.sleeping&&this.really_wake(N,!1))}}}if((z.immState&1)!=0){if(z.b1.type==2&&z.b1.component.sleeping){let m=z.b1;m.world||(m.component.waket=this.stamp+(this.midstep?0:1),m.type==3&&(m.kinematicDelaySleep=!0),m.component.sleeping&&this.really_wake(m,!1))}if(z.b2.type==2&&z.b2.component.sleeping){let m=z.b2;m.world||(m.component.waket=this.stamp+(this.midstep?0:1),m.type==3&&(m.kinematicDelaySleep=!0),m.component.sleeping&&this.really_wake(m,!1))}}if(z.sleeping){z.sleeping=!1;let m;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?m=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(m=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=m.next,m.next=null),m.elt=z;let b=m;b.next=d.head,d.head=b,d.modified=!0,d.length++}l=z}else if(f){let m=z;m.userdef_dyn_fric=!1,m.userdef_stat_fric=!1,m.userdef_restitution=!1,m.userdef_rfric=!1,m.__ref_edge1=m.__ref_edge2=null,m.next=pt.zpp_pool,pt.zpp_pool=m,l=null}else l=z;else l=z}else{let d;if(s==null){let k=null,b=(r.arbiters.length<a.arbiters.length?r:a).arbiters.head;for(;b!=null;){let C=b.elt;if(C.id==u.id&&C.di==x.id){k=C;break}b=b.next}d=k}else d=s;let _=d==null,f,z=!1;if(_)Nt.zpp_pool==null?f=new Nt:(f=Nt.zpp_pool,Nt.zpp_pool=f.next,f.next=null);else if(d.sensorarb==null){d.cleared=!0;{let m=d.b1.arbiters,b=null,C=m.head,v=!1;for(;C!=null;){if(C.elt==d){let w,O;b==null?(w=m.head,O=w.next,m.head=O,m.head==null&&(m.pushmod=!0)):(w=b.next,O=w.next,b.next=O,O==null&&(m.pushmod=!0));let E=w;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,m.modified=!0,m.length--,m.pushmod=!0,v=!0;break}b=C,C=C.next}}{let m=d.b2.arbiters,b=null,C=m.head,v=!1;for(;C!=null;){if(C.elt==d){let w,O;b==null?(w=m.head,O=w.next,m.head=O,m.head==null&&(m.pushmod=!0)):(w=b.next,O=w.next,b.next=O,O==null&&(m.pushmod=!0));let E=w;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,m.modified=!0,m.length--,m.pushmod=!0,v=!0;break}b=C,C=C.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Nt.zpp_pool==null?f=new Nt:(f=Nt.zpp_pool,Nt.zpp_pool=f.next,f.next=null),f.intchange=!0,_=!0,z=!0}else f=d.sensorarb;let P=2;if(_||f.stamp!=this.stamp||i)if(f.stamp=this.stamp,Ee.testCollide(u,x)){if(_){let k=x.id;f.b1=e.body,f.ws1=e,f.b2=t.body,f.ws2=t,f.id=u.id,f.di=k;let m=f.b1.arbiters,b;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?b=new B._zpp.util.ZNPNode_ZPP_Arbiter:(b=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b.next,b.next=null),b.elt=f;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=f.b2.arbiters,w;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?w=new B._zpp.util.ZNPNode_ZPP_Arbiter:(w=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=w.next,w.next=null),w.elt=f;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++,f.active=!0,f.present=0,f.cleared=!1,f.sleeping=!1,f.fresh=!1,f.presentable=!1;let E=this.s_arbiters,M;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?M=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(M=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=M.next,M.next=null),M.elt=f;let N=M;N.next=E.head,E.head=N,E.modified=!0,E.length++,f.fresh=!z}else f.fresh=f.up_stamp<this.stamp-1||f.endGenerated==this.stamp&&i;if(f.up_stamp=f.stamp,f.fresh||(f.immState&4)==0){f.immState=1;let k=!1,m=f.ws1.id>f.ws2.id?f.ws2:f.ws1,b=f.ws1.id>f.ws2.id?f.ws1:f.ws2,C=this.mrca1;for(;C.head!=null;){let M=C.head;C.head=M.next;let N=M;N.elt=null,N.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N,C.head==null&&(C.pushmod=!0),C.modified=!0,C.length--}C.pushmod=!0;let v=this.mrca2;for(;v.head!=null;){let M=v.head;v.head=M.next;let N=M;N.elt=null,N.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N,v.head==null&&(v.pushmod=!0),v.modified=!0,v.length--}if(v.pushmod=!0,m.cbSet!=null){let M=this.mrca1,N;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new B._zpp.util.ZNPNode_ZPP_Interactor:(N=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=m;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(m.body.cbSet!=null){let M=this.mrca1,N=m.body,Z;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?Z=new B._zpp.util.ZNPNode_ZPP_Interactor:(Z=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z.next,Z.next=null),Z.elt=N;let S=Z;S.next=M.head,M.head=S,M.modified=!0,M.length++}if(b.cbSet!=null){let M=this.mrca2,N;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new B._zpp.util.ZNPNode_ZPP_Interactor:(N=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=b;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(b.body.cbSet!=null){let M=this.mrca2,N=b.body,Z;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?Z=new B._zpp.util.ZNPNode_ZPP_Interactor:(Z=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z.next,Z.next=null),Z.elt=N;let S=Z;S.next=M.head,M.head=S,M.modified=!0,M.length++}let w=m.body.compound,O=b.body.compound;for(;w!=O;){let M=w==null?0:w.depth,N=O==null?0:O.depth;if(M<N){if(O.cbSet!=null){let Z=this.mrca2,S;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new B._zpp.util.ZNPNode_ZPP_Interactor:(S=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=O;let V=S;V.next=Z.head,Z.head=V,Z.modified=!0,Z.length++}O=O.compound}else{if(w.cbSet!=null){let Z=this.mrca1,S;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new B._zpp.util.ZNPNode_ZPP_Interactor:(S=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=w;let V=S;V.next=Z.head,Z.head=V,Z.modified=!0,Z.length++}w=w.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,N=this.mrca2.head;for(;N!=null;){let Z=N.elt,S=M.cbSet,V=Z.cbSet,D=S.manager,T=null,q=(S.cbpairs.length<V.cbpairs.length?S.cbpairs:V.cbpairs).head;for(;q!=null;){let L=q.elt;if(L.a==S&&L.b==V||L.a==V&&L.b==S){T=L;break}q=q.next}if(T==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=!0,dt.setlt(S,V)?(L.a=S,L.b=V):(L.a=V,L.b=S),T=L,S.cbpairs.add(T),V!=S&&V.cbpairs.add(T)}if(T.zip_listeners&&(T.zip_listeners=!1,T.__validate()),T.listeners.head==null){N=N.next;continue}let R=null,j=null,A=this.prelisteners;for(;A.head!=null;){let L=A.head;A.head=L.next;let F=L;F.elt=null,F.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=F,A.head==null&&(A.pushmod=!0),A.modified=!0,A.length--}A.pushmod=!0;let W=null,Q=S.manager,Y=null,ee=(S.cbpairs.length<V.cbpairs.length?S.cbpairs:V.cbpairs).head;for(;ee!=null;){let L=ee.elt;if(L.a==S&&L.b==V||L.a==V&&L.b==S){Y=L;break}ee=ee.next}if(Y==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=!0,dt.setlt(S,V)?(L.a=S,L.b=V):(L.a=V,L.b=S),Y=L,S.cbpairs.add(Y),V!=S&&V.cbpairs.add(Y)}Y.zip_listeners&&(Y.zip_listeners=!1,Y.__validate());let J=Y.listeners.head;for(;J!=null;){let L=J.elt;if(L.event==5&&(L.itype&P)!=0){let F=this.prelisteners,I;B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?I=new B._zpp.util.ZNPNode_ZPP_InteractionListener:(I=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=I.next,I.next=null),I.elt=L;let U=I;W==null?(U.next=F.head,F.head=U):(U.next=W.next,W.next=U),F.pushmod=F.modified=!0,F.length++,W=U,k=k||!L.pure}J=J.next}if(this.prelisteners.head==null){N=N.next;continue}if(R=B._zpp.phys.ZPP_Interactor.get(M,Z),R==null&&(j=qt.get(M,Z),this.add_callbackset(j)),R==null||(R.SENSORstamp!=this.stamp||i)&&(R.SENSORstate&4)==0){if(j!=null&&(R=j),R!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(R.COLLISIONstamp=this.stamp,R.SENSORstamp=this.stamp,R.FLUIDstamp=this.stamp):R.SENSORstamp=this.stamp,U=U.next}let L=f.active;f.active=!0;let F=!1;this.precb.zpp_inner.pre_arbiter=f,this.precb.zpp_inner.set=R;let I=this.prelisteners.head;for(;I!=null;){let U=I.elt;this.precb.zpp_inner.listener=U;let $=this.precb.zpp_inner,K=R.int1,ie=R.int2,re,se=U.options1,te=K.cbTypes;if(se.nonemptyintersection(te,se.includes)&&!se.nonemptyintersection(te,se.excludes)){let pe=U.options2,ce=ie.cbTypes;re=pe.nonemptyintersection(ce,pe.includes)&&!pe.nonemptyintersection(ce,pe.excludes)}else re=!1;re?($.int1=K,$.int2=ie):($.int1=ie,$.int2=K),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let oe=U.handlerp(this.precb);if(oe!=null){let pe;H.PreFlag_ACCEPT==null&&(H.internal=!0,H.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,H.internal=!1),oe==H.PreFlag_ACCEPT?pe=5:(H.PreFlag_ACCEPT_ONCE==null&&(H.internal=!0,H.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,H.internal=!1),oe==H.PreFlag_ACCEPT_ONCE?pe=1:(H.PreFlag_IGNORE==null&&(H.internal=!0,H.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,H.internal=!1),pe=oe==H.PreFlag_IGNORE?6:2)),f.immState=pe}I=I.next}if(f.active=L,R!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(R.COLLISIONstate=f.immState,R.SENSORstate=f.immState,R.FLUIDstate=f.immState):R.SENSORstate=f.immState,U=U.next}}else R==null?(f.immState&4)==0&&(f.immState=1):f.immState=R.SENSORstate;N=N.next}E=E.next}if(k&&(f.immState&4)==0){if(f.b1.type!=1){let M=f.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}if(f.b2.type!=1){let M=f.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}}}if(f.sleeping){f.sleeping=!1;let k=this.s_arbiters,m;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?m=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(m=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=m.next,m.next=null),m.elt=f;let b=m;b.next=k.head,k.head=b,k.modified=!0,k.length++}l=f}else if(_){let k=f;k.next=Nt.zpp_pool,Nt.zpp_pool=k,l=null}else l=f;else l=f}}return l}MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let r=n.head;n.head=r.next;let a=r;a.elt=null,a.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let r=s.head;s.head=r.next;let a=r;a.elt=null,a.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let r=this.mrca1,a;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new B._zpp.util.ZNPNode_ZPP_Interactor:(a=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=e;let o=a;o.next=r.head,r.head=o,r.modified=!0,r.length++}if(e.body.cbSet!=null){let r=this.mrca1,a=e.body,o;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_Interactor:(o=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=a;let p=o;p.next=r.head,r.head=p,r.modified=!0,r.length++}if(t.cbSet!=null){let r=this.mrca2,a;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new B._zpp.util.ZNPNode_ZPP_Interactor:(a=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=t;let o=a;o.next=r.head,r.head=o,r.modified=!0,r.length++}if(t.body.cbSet!=null){let r=this.mrca2,a=t.body,o;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_Interactor:(o=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=a;let p=o;p.next=r.head,r.head=p,r.modified=!0,r.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let r=i==null?0:i.depth,a=l==null?0:l.depth;if(r<a){if(l.cbSet!=null){let o=this.mrca2,p;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new B._zpp.util.ZNPNode_ZPP_Interactor:(p=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=l;let c=p;c.next=o.head,o.head=c,o.modified=!0,o.length++}l=l.compound}else{if(i.cbSet!=null){let o=this.mrca1,p;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new B._zpp.util.ZNPNode_ZPP_Interactor:(p=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=i;let c=p;c.next=o.head,o.head=c,o.modified=!0,o.length++}i=i.compound}}}inlined_MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let r=n.head;n.head=r.next;let a=r;a.elt=null,a.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let r=s.head;s.head=r.next;let a=r;a.elt=null,a.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let r=this.mrca1,a;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new B._zpp.util.ZNPNode_ZPP_Interactor:(a=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=e;let o=a;o.next=r.head,r.head=o,r.modified=!0,r.length++}if(e.body.cbSet!=null){let r=this.mrca1,a=e.body,o;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_Interactor:(o=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=a;let p=o;p.next=r.head,r.head=p,r.modified=!0,r.length++}if(t.cbSet!=null){let r=this.mrca2,a;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new B._zpp.util.ZNPNode_ZPP_Interactor:(a=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=t;let o=a;o.next=r.head,r.head=o,r.modified=!0,r.length++}if(t.body.cbSet!=null){let r=this.mrca2,a=t.body,o;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_Interactor:(o=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=a;let p=o;p.next=r.head,r.head=p,r.modified=!0,r.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let r=i==null?0:i.depth,a=l==null?0:l.depth;if(r<a){if(l.cbSet!=null){let o=this.mrca2,p;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new B._zpp.util.ZNPNode_ZPP_Interactor:(p=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=l;let c=p;c.next=o.head,o.head=c,o.modified=!0,o.length++}l=l.compound}else{if(i.cbSet!=null){let o=this.mrca1,p;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new B._zpp.util.ZNPNode_ZPP_Interactor:(p=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=i;let c=p;c.next=o.head,o.head=c,o.modified=!0,o.length++}i=i.compound}}}};B._zpp=null,B._nape=null;var si=B;var In=class{constructor(){this.aabb=null;this.shape=null;this.prev=null;this.next=null}free(){this.prev=null,this.shape=null,this.aabb=null}alloc(){}gt(e){return this.aabb.minx>e.aabb.minx}};In.zpp_pool=null;var $t=class $t extends Yn{constructor(t){super();this.failed=null;this.list=null;this.space=t,this.is_sweep=!0,this.sweep=this}__insert(t){let n;In.zpp_pool==null?n=new In:(n=In.zpp_pool,In.zpp_pool=n.next,n.next=null),t.sweep=n,n.shape=t,n.aabb=t.aabb,n.next=this.list,this.list!=null&&(this.list.prev=n),this.list=n}__remove(t){let n=t.sweep;n.prev==null?this.list=n.next:n.prev.next=n.next,n.next!=null&&(n.next.prev=n.prev),t.sweep=null;let s=n;s.prev=null,s.shape=null,s.aabb=null,s.next=In.zpp_pool,In.zpp_pool=s}__sync(t){if(!this.space.continuous&&t.zip_aabb&&t.body!=null)if(t.zip_aabb=!1,t.type==0){let n=t.circle;if(n.zip_worldCOM&&n.body!=null){if(n.zip_worldCOM=!1,n.zip_localCOM){if(n.zip_localCOM=!1,n.type==1){let r=n.polygon;if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(r.lverts.next.next==null)r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;else if(r.lverts.next.next.next==null){r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;let a=1;r.localCOMx+=r.lverts.next.next.x*a,r.localCOMy+=r.lverts.next.next.y*a;let o=.5;r.localCOMx*=o,r.localCOMy*=o}else{r.localCOMx=0,r.localCOMy=0;let a=0,o=r.lverts.next,p=o;o=o.next;let c=o;for(o=o.next;o!=null;){let _=o;a+=c.x*(_.y-p.y);let f=_.y*c.x-_.x*c.y;r.localCOMx+=(c.x+_.x)*f,r.localCOMy+=(c.y+_.y)*f,p=c,c=_,o=o.next}o=r.lverts.next;let h=o;a+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;r.localCOMx+=(c.x+h.x)*u,r.localCOMy+=(c.y+h.y)*u,p=c,c=h,o=o.next;let x=o;a+=c.x*(x.y-p.y);let y=x.y*c.x-x.x*c.y;r.localCOMx+=(c.x+x.x)*y,r.localCOMy+=(c.y+x.y)*y,a=1/(3*a);let d=a;r.localCOMx*=d,r.localCOMy*=d}}n.wrap_localCOM!=null&&(n.wrap_localCOM.zpp_inner.x=n.localCOMx,n.wrap_localCOM.zpp_inner.y=n.localCOMy)}let l=n.body;l.zip_axis&&(l.zip_axis=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot)),n.worldCOMx=n.body.posx+(n.body.axisy*n.localCOMx-n.body.axisx*n.localCOMy),n.worldCOMy=n.body.posy+(n.localCOMx*n.body.axisx+n.localCOMy*n.body.axisy)}let s=n.radius,i=n.radius;n.aabb.minx=n.worldCOMx-s,n.aabb.miny=n.worldCOMy-i,n.aabb.maxx=n.worldCOMx+s,n.aabb.maxy=n.worldCOMy+i}else{let n=t.polygon;if(n.zip_gverts&&n.body!=null){n.zip_gverts=!1,n.validate_lverts();let l=n.body;l.zip_axis&&(l.zip_axis=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot));let r=n.lverts.next,a=n.gverts.next;for(;a!=null;){let o=a,p=r;r=r.next,o.x=n.body.posx+(n.body.axisy*p.x-n.body.axisx*p.y),o.y=n.body.posy+(p.x*n.body.axisx+p.y*n.body.axisy),a=a.next}}if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let s=n.gverts.next;n.aabb.minx=s.x,n.aabb.miny=s.y,n.aabb.maxx=s.x,n.aabb.maxy=s.y;let i=n.gverts.next.next;for(;i!=null;){let l=i;l.x<n.aabb.minx&&(n.aabb.minx=l.x),l.x>n.aabb.maxx&&(n.aabb.maxx=l.x),l.y<n.aabb.miny&&(n.aabb.miny=l.y),l.y>n.aabb.maxy&&(n.aabb.maxy=l.y),i=i.next}}}sync_broadphase(){if(this.space.validation(),this.list!=null){let t=this.list.next;for(;t!=null;){let n=t.next,s=t.prev;if(s!=null&&t.aabb.minx>s.aabb.minx){t=n;continue}for(;s.prev!=null&&s.prev.aabb.minx>t.aabb.minx;)s=s.prev;let i=t.prev;i.next=t.next,t.next!=null&&(t.next.prev=i),s.prev==null?(t.prev=null,this.list=t,t.next=s,s.prev=t):(t.prev=s.prev,s.prev=t,t.prev.next=t,t.next=s),t=n}}}sync_broadphase_fast(){let t=this.list.next;for(;t!=null;){let n=t.next,s=t.prev;if(s!=null&&t.aabb.minx>s.aabb.minx){t=n;continue}for(;s.prev!=null&&s.prev.aabb.minx>t.aabb.minx;)s=s.prev;let i=t.prev;i.next=t.next,t.next!=null&&(t.next.prev=i),s.prev==null?(t.prev=null,this.list=t,t.next=s,s.prev=t):(t.prev=s.prev,s.prev=t,t.prev.next=t,t.next=s),t=n}}broadphase(t,n){if(this.list!=null){let s=this.list.next;for(;s!=null;){let l=s.next,r=s.prev;if(r!=null&&s.aabb.minx>r.aabb.minx){s=l;continue}for(;r.prev!=null&&r.prev.aabb.minx>s.aabb.minx;)r=r.prev;let a=s.prev;a.next=s.next,s.next!=null&&(s.next.prev=a),r.prev==null?(s.prev=null,this.list=s,s.next=r,r.prev=s):(s.prev=r.prev,r.prev=s,s.prev.next=s,s.next=r),s=l}let i=this.list;for(;i!=null;){let l=i.next,r=i.shape,a=r.body,o=i.aabb.maxx;for(;l!=null&&!(l.aabb.minx>o);){let p=l.shape,c=p.body;if(c==a){l=l.next;continue}if(a.type==1&&c.type==1){l=l.next;continue}if(a.component.sleeping&&c.component.sleeping){l=l.next;continue}let h=r.aabb,u=p.aabb;u.miny>h.maxy||h.miny>u.maxy||(n?t.narrowPhase(r,p,a.type!=2||c.type!=2,null,!1):t.continuousEvent(r,p,a.type!=2||c.type!=2,null,!1)),l=l.next}i=i.next}}}clear(){for(;this.list!=null;)this.list.shape.removedFromSpace(),this.__remove(this.list.shape)}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let r=l,a=i??new $t._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.minx>t;)o=o.next;for(;o!=null&&o.aabb.minx<=t;){if(o.aabb.maxx>=t&&o.aabb.miny<=n&&o.aabb.maxy>=n){let c=o.shape,h;if(s!=null){let u=c.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(c.type==0?Ee.circleContains(c.circle,r)&&a.push(c.outer):Ee.polyContains(c.polygon,r)&&a.push(c.outer))}o=o.next}let p=r;return p.outer!=null&&(p.outer.zpp_inner=null,p.outer=null),p._isimmutable=null,p._validate=null,p._invalidate=null,p.next=le.zpp_pool,le.zpp_pool=p,a}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let r=l,a=i??new $t._nape.phys.BodyList,o=this.list;for(;o!=null&&o.aabb.minx>t;)o=o.next;for(;o!=null&&o.aabb.minx<=t;){if(o.aabb.maxx>=t&&o.aabb.miny<=n&&o.aabb.maxy>=n){let c=o.shape,h=c.body.outer;if(!a.has(h)){let u;if(s!=null){let x=c.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(c.type==0?Ee.circleContains(c.circle,r)&&a.push(h):Ee.polyContains(c.polygon,r)&&a.push(h))}}o=o.next}let p=r;return p.outer!=null&&(p.outer.zpp_inner=null,p.outer=null),p._isimmutable=null,p._validate=null,p._invalidate=null,p.next=le.zpp_pool,le.zpp_pool=p,a}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,a=l??new $t._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.maxx<r.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=r.maxx;){let p=o.shape,c;if(i!=null){let h=p.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c)if(n)if(s)Ee.containTest(this.aabbShape.zpp_inner,p)&&a.push(p.outer);else{let h=o.aabb;if(h.minx>=r.minx&&h.miny>=r.miny&&h.maxx<=r.maxx&&h.maxy<=r.maxy)a.push(p.outer);else{let u=o.aabb;r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx&&Ee.testCollide_safe(p,this.aabbShape.zpp_inner)&&a.push(p.outer)}}else{let h;if(s){let u=o.aabb;h=u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy}else{let u=o.aabb;h=r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx}h&&a.push(p.outer)}o=o.next}return a}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,a=l??new $t._nape.phys.BodyList;this.failed==null&&(this.failed=new $t._nape.phys.BodyList);let o=this.list;for(;o!=null&&o.aabb.maxx<r.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=r.maxx;){let p=o.shape,c=p.body.outer,h=o.aabb;if(r.miny<=h.maxy&&h.miny<=r.maxy&&r.minx<=h.maxx&&h.minx<=r.maxx){let u;if(i!=null){let x=p.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(c)){let x=Ee.containTest(this.aabbShape.zpp_inner,p);!a.has(c)&&x?a.push(c):x||(a.remove(c),this.failed.push(c))}}else!a.has(c)&&Ee.testCollide_safe(p,this.aabbShape.zpp_inner)&&a.push(c);else if(s){if(!this.failed.has(c)){let x=p.aabb,y=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy;!a.has(c)&&y?a.push(c):y||(a.remove(c),this.failed.push(c))}}else{let x;if(a.has(c))x=!1;else{let y=p.aabb;x=y.minx>=r.minx&&y.miny>=r.miny&&y.maxx<=r.maxx&&y.maxy<=r.maxy}x&&a.push(c)}}o=o.next}return this.failed.clear(),a}shapesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let a=this.circShape.zpp_inner.aabb,o=r??new $t._nape.shape.ShapeList,p=this.list;for(;p!=null&&p.aabb.maxx<a.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=a.maxx;){let c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.maxx){let h=p.shape,u;if(l!=null){let x=h.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(i?Ee.containTest(this.circShape.zpp_inner,h)&&o.push(h.outer):Ee.testCollide_safe(h,this.circShape.zpp_inner)&&o.push(h.outer))}p=p.next}return o}bodiesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let a=this.circShape.zpp_inner.aabb,o=r??new $t._nape.phys.BodyList;this.failed==null&&(this.failed=new $t._nape.phys.BodyList);let p=this.list;for(;p!=null&&p.aabb.maxx<a.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=a.maxx;){let c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.maxx){let h=p.shape,u=h.body.outer,x;if(l!=null){let y=h.filter;x=(y.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&y.collisionGroup)!=0}else x=!0;if(x)if(i){if(!this.failed.has(u)){let y=Ee.containTest(this.circShape.zpp_inner,h);!o.has(u)&&y?o.push(u):y||(o.remove(u),this.failed.push(u))}}else!o.has(u)&&Ee.testCollide_safe(h,this.circShape.zpp_inner)&&o.push(u)}p=p.next}return this.failed.clear(),o}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new $t._nape.shape.ShapeList,a=this.list;for(;a!=null&&a.aabb.maxx<l.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=l.maxx;){let o=a.aabb;if(l.miny<=o.maxy&&o.miny<=l.maxy&&l.minx<=o.maxx&&o.minx<=l.maxx){let p=a.shape,c;if(s!=null){let h=p.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;c&&(n?Ee.containTest(t,p)&&r.push(p.outer):Ee.testCollide_safe(p,t)&&r.push(p.outer))}a=a.next}return r}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new $t._nape.phys.BodyList;this.failed==null&&(this.failed=new $t._nape.phys.BodyList);let a=this.list;for(;a!=null&&a.aabb.maxx<l.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=l.maxx;){let o=a.aabb;if(l.miny<=o.maxy&&o.miny<=l.maxy&&l.minx<=o.maxx&&o.minx<=l.maxx){let p=a.shape,c=p.body.outer,h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n){if(!this.failed.has(c)){let u=Ee.containTest(t,p);!r.has(c)&&u?r.push(c):u||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ee.testCollide_safe(t,p)&&r.push(c)}a=a.next}return this.failed.clear(),r}rayCast(t,n,s){this.sync_broadphase(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,r=null;if(t.dirx==0){let o=this.list;for(;o!=null&&o.aabb.minx<=i.minx;){let p,c=o.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=o.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;if(p){let h=t.aabbsect(o.aabb);if(h>=0&&h<l){let u=o.shape.type==0?t.circlesect(o.shape.circle,n,l):t.polysect(o.shape.polygon,n,l);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=u.zpp_inner.toiDistance,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free()}r=u}}}o=o.next}}else if(t.dirx<0){let o=this.list,p=null;for(;o!=null&&o.aabb.minx<=i.maxx;)p=o,o=o.next;for(o=p;o!=null;){let c,h=o.aabb;if(i.miny<=h.maxy&&h.miny<=i.maxy&&i.minx<=h.maxx&&h.minx<=i.maxx)if(s!=null){let u=o.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;else c=!1;if(c){let u=t.aabbsect(o.aabb);if(u>=0&&u<l){let x=o.shape.type==0?t.circlesect(o.shape.circle,n,l):t.polysect(o.shape.polygon,n,l);if(x!=null){if(x.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=x.zpp_inner.toiDistance,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free()}r=x}}}o=o.prev}}else{let o=this.list;for(;o!=null&&o.aabb.minx<=i.maxx&&o.aabb.minx<t.originx+t.dirx*l;){let p,c=o.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=o.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;if(p){let h=t.aabbsect(o.aabb);if(h>=0&&h<l){let u=o.shape.type==0?t.circlesect(o.shape.circle,n,l):t.polysect(o.shape.polygon,n,l);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=u.zpp_inner.toiDistance,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free()}r=u}}}o=o.next}}let a=i;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a.wrap_min=a.wrap_max=null,a._invalidate=null,a._validate=null,a.next=be.zpp_pool,be.zpp_pool=a,r}rayMultiCast(t,n,s,i){this.sync_broadphase(),t.validate_dir();let l=t.rayAABB(),r=i??new $t._nape.geom.RayResultList;if(t.dirx==0){let o=this.list;for(;o!=null&&o.aabb.minx<=l.minx;){let p,c=o.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=o.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(o.aabb)>=0&&(o.shape.type==0?t.circlesect2(o.shape.circle,n,r):t.polysect2(o.shape.polygon,n,r)),o=o.next}}else if(t.dirx<0){let o=this.list,p=null;for(;o!=null&&o.aabb.minx<=l.maxx;)p=o,o=o.next;for(o=p;o!=null;){let c,h=o.aabb;if(l.miny<=h.maxy&&h.miny<=l.maxy&&l.minx<=h.maxx&&h.minx<=l.maxx)if(s!=null){let u=o.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;else c=!1;c&&t.aabbsect(o.aabb)>=0&&(o.shape.type==0?t.circlesect2(o.shape.circle,n,r):t.polysect2(o.shape.polygon,n,r)),o=o.prev}}else{let o=this.list;for(;o!=null&&o.aabb.minx<=l.maxx;){let p,c=o.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=o.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(o.aabb)>=0&&(o.shape.type==0?t.circlesect2(o.shape.circle,n,r):t.polysect2(o.shape.polygon,n,r)),o=o.next}}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a.wrap_min=a.wrap_max=null,a._invalidate=null,a._validate=null,a.next=be.zpp_pool,be.zpp_pool=a,r}};$t._zpp=null,$t._nape=null;var Ps=$t;function Dl(){let g={},e={};return g.callbacks={},g.constraint={},g.dynamics={},g.geom={},g.phys={},g.shape={},g.space={},g.util={},e.ZPP_Const=ri,e.ZPP_ID=un,e.callbacks||(e.callbacks={}),jt._nape=g,jt._zpp=e,e.callbacks.ZPP_Callback=jt,dt._zpp=e,e.callbacks.ZPP_CbSet=dt,Ne._zpp=e,e.callbacks.ZPP_CbSetPair=Ne,e.util||(e.util={}),Fl(e),fn._zpp=e,e.callbacks.ZPP_CbType=fn,e.util.ZPP_Flags=H,Tt._nape=g,Tt._zpp=e,e.callbacks.ZPP_Listener=Tt,e.callbacks.ZPP_BodyListener=nl,e.callbacks.ZPP_ConstraintListener=il,e.callbacks.ZPP_InteractionListener=sl,ys._nape=g,ys._zpp=e,e.callbacks.ZPP_OptionType=ys,e.constraint||(e.constraint={}),Me._nape=g,Me._zpp=e,e.constraint.ZPP_Constraint=Me,e.constraint.ZPP_AngleJoint=Je,e.constraint.ZPP_CopyHelper=Fn,e.constraint.ZPP_DistanceJoint=ci,e.constraint.ZPP_LineJoint=hi,e.constraint.ZPP_MotorJoint=ui,e.constraint.ZPP_PivotJoint=xi,e.constraint.ZPP_PulleyJoint=di,e.constraint.ZPP_UserConstraint=ll,e.constraint.ZPP_UserBody=ms,e.constraint.ZPP_WeldJoint=_i,e.dynamics||(e.dynamics={}),Ve._nape=g,Ve._zpp=e,e.dynamics.ZPP_Arbiter=Ve,e.dynamics.ZPP_SensorArbiter=Nt,zt._nape=g,zt._zpp=e,e.dynamics.ZPP_FluidArbiter=zt,pt._nape=g,pt._zpp=e,e.dynamics.ZPP_ColArbiter=pt,e.dynamics.ZPP_IContact=yi,Pe._nape=g,Pe._zpp=e,e.dynamics.ZPP_Contact=Pe,ct._nape=g,ct._zpp=e,e.dynamics.ZPP_InteractionFilter=ct,js._zpp=e,e.dynamics.ZPP_InteractionGroup=js,Un._nape=g,Un._zpp=e,e.dynamics.ZPP_SpaceArbiterList=Un,e.geom||(e.geom={}),be._nape=g,be._zpp=e,e.geom.ZPP_AABB=be,e.geom.ZPP_Collide=Ee,e.geom.ZPP_Convex=ol,e.geom.ZPP_ConvexRayResult=dn,e.geom.ZPP_CutVert=Qe,e.geom.ZPP_CutInt=st,e.geom.ZPP_Cutter=rl,e.geom.ZPP_Geom=bs,e.geom.ZPP_GeomVert=ve,ve._createVec2Fn=function(){return new g.geom.Vec2},e.geom.ZPP_GeomPoly=al,e.geom.ZPP_MarchSpan=Sn,e.geom.ZPP_MarchPair=An,Ts._init(e,g),e.geom.ZPP_MarchingSquares=Ts,Ls._nape=g,e.geom.ZPP_Mat23=Ls,e.geom.ZPP_MatMN=Bi,e.geom.ZPP_Monotone=pl,e.geom.ZPP_PartitionVertex=Ge,e.geom.ZPP_PartitionedPoly=ji,e.geom.ZPP_Ray=cl,e.geom.ZPP_SimpleVert=ke,e.geom.ZPP_SimpleSeg=At,e.geom.ZPP_SimpleEvent=ge,e.geom.ZPP_SimpleSweep=Di,e.geom.ZPP_Simple=hl,e.geom.ZPP_SimplifyV=Pn,e.geom.ZPP_SimplifyP=Te,e.geom.ZPP_Simplify=ul,e.geom.ZPP_ToiEvent=Fs,e.geom.ZPP_SweepDistance=wn,e.geom.ZPP_PartitionPair=Ot,e.geom.ZPP_Triangular=xl,e.geom.ZPP_Vec2=le,ti._zpp=e,e.geom.ZPP_Vec3=ti,e.geom.ZPP_VecMath=dl,e.phys||(e.phys={}),e.phys.ZPP_Interactor=Jt,Jt._init(e,g),vn._init(e,g),e.phys.ZPP_Body=vn,Dn._nape=g,Dn._zpp=e,Dn._init(),e.phys.ZPP_Compound=Dn,gn._nape=g,gn._zpp=e,e.phys.ZPP_FluidProperties=gn,Ae._nape=g,Ae._zpp=e,e.phys.ZPP_Material=Ae,e.shape||(e.shape={}),ni._nape=g,ni._zpp=e,ni._init(),e.shape.ZPP_Shape=ni,Wn._nape=g,Wn._zpp=e,Wn._init(),e.shape.ZPP_Circle=Wn,lt._nape=g,lt._zpp=e,e.shape.ZPP_Edge=lt,Kn._nape=g,Kn._zpp=e,Kn._init(),e.shape.ZPP_Polygon=Kn,e.space||(e.space={}),Yn._zpp=e,Yn._nape=g,e.space.ZPP_Broadphase=Yn,e.space.ZPP_AABBNode=Se,e.space.ZPP_AABBPair=tt,e.space.ZPP_AABBTree=$e,zs._zpp=e,zs._nape=g,e.space.ZPP_DynAABBPhase=zs,ht._zpp=e,e.space.ZPP_Island=ht,e.space.ZPP_Component=Rs,qt._zpp=e,e.space.ZPP_CallbackSet=qt,Ji._zpp=e,e.space.ZPP_CbSetManager=Ji,si._zpp=e,si._nape=g,e.space.ZPP_Space=si,e.space.ZPP_SweepData=In,Ps._zpp=e,Ps._nape=g,e.space.ZPP_SweepPhase=Ps,e.util.ZNPArray2_Float=as,e.util.ZNPArray2_ZPP_GeomVert=ps,e.util.ZNPArray2_ZPP_MarchPair=cs,e.util.Hashable2_Boolfalse=je,e.util.FastHash2_Hashable2_Boolfalse=Oi,e.util.ZPP_Math=el,e.util.ZPP_PubPool=_e,e.callbacks.ZPP_InteractionListener._initStatics(e),e.geom.ZPP_Collide._initStatics(e),e.space.ZPP_AABBTree._initStatics(),g.__zpp=e,g}var _l;function me(){return _l||(_l=Dl()),_l}var Rl=!1;function Gl(){if(Rl)return;let g=_l;if(!g?.callbacks?.CbEvent||!g?.callbacks?.CbType||!g?.callbacks?.ListenerType||!g?.dynamics?.ArbiterType||!g?.phys?.BodyType||!g?.shape?.ShapeType)return;Rl=!0;let e=g.__zpp;e.callbacks.ZPP_CbType._initEnums(g),e.callbacks.ZPP_Listener._initEnums(g,e.util.ZPP_Flags),e.dynamics.ZPP_Arbiter._initEnums(g,e.util.ZPP_Flags),e.phys.ZPP_Body._initEnums(g,e.util.ZPP_Flags),e.shape.ZPP_Shape._initEnums(g,e.util.ZPP_Flags)}var Jl=new WeakMap;function Ze(g,e){if(!g)return null;let t=Jl.get(g);return t||(t=e(g),Jl.set(g,t)),t}var Ie=class g{constructor(e=0,t=0){this.zpp_pool=null;this.zpp_disp=!1;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;le.zpp_pool==null?n=new le:(n=le.zpp_pool,le.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,this.zpp_inner=n,n.outer=this}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}_checkImmutable(){this.zpp_inner.immutable()}_validate(){this.zpp_inner.validate()}_invalidate(){this.zpp_inner.invalidate()}static _disposeWeak(e){e.zpp_inner.weak&&e.dispose()}_setXY(e,t){if(this._checkDisposed(),this._checkImmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");this._validate(),(this.zpp_inner.x!==e||this.zpp_inner.y!==t)&&(this.zpp_inner.x=e,this.zpp_inner.y=t,this._invalidate())}static _poolGet(e,t,n){let s;if(_e.poolVec2==null?s=new g:(s=_e.poolVec2,_e.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===_e.nextVec2&&(_e.nextVec2=null)),s.zpp_inner==null){let i;le.zpp_pool==null?i=new le:(i=le.zpp_pool,le.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=e,i.y=t,s.zpp_inner=i,i.outer=s}else s.zpp_inner.immutable(),s.zpp_inner.validate(),(s.zpp_inner.x!==e||s.zpp_inner.y!==t)&&(s.zpp_inner.x=e,s.zpp_inner.y=t,s.zpp_inner.invalidate());return s.zpp_inner.weak=n,s}static _wrap(e){return e instanceof g?e:e?e instanceof le?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?g._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=!1){if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");return g._poolGet(e,t,n)}static weak(e=0,t=0){if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");return g._poolGet(e,t,!0)}static fromPolar(e,t,n=!1){if(e!==e)throw new Error("Error: Vec2::length cannot be NaN");if(t!==t)throw new Error("Error: Vec2::angle cannot be NaN");let s=e*Math.cos(t),i=e*Math.sin(t);return g._poolGet(s,i,n)}static fromAngle(e,t=!1){return g.fromPolar(1,e,t)}static lerp(e,t,n,s=!1){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot lerp with null Vec2");if(n!==n)throw new Error("Error: Cannot lerp with NaN t");e.zpp_inner.validate(),t.zpp_inner.validate();let i=e.zpp_inner.x+n*(t.zpp_inner.x-e.zpp_inner.x),l=e.zpp_inner.y+n*(t.zpp_inner.y-e.zpp_inner.y),r=g._poolGet(i,l,s);return g._disposeWeak(e),g._disposeWeak(t),r}static eq(e,t,n=0){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null){let r=e==null&&t==null;return e!=null&&g._disposeWeak(e),t!=null&&g._disposeWeak(t),r}e.zpp_inner.validate(),t.zpp_inner.validate();let s=e.zpp_inner.x-t.zpp_inner.x,i=e.zpp_inner.y-t.zpp_inner.y,l=(s<0?-s:s)<=n&&(i<0?-i:i)<=n;return g._disposeWeak(e),g._disposeWeak(t),l}static dsq(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,s=e.zpp_inner.y;t.zpp_inner.validate();let i=t.zpp_inner.x,l=t.zpp_inner.y,r=n-i,a=s-l,o=r*r+a*a;return g._disposeWeak(e),g._disposeWeak(t),o}static distance(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,s=e.zpp_inner.y;t.zpp_inner.validate();let i=t.zpp_inner.x,l=t.zpp_inner.y,r=n-i,a=s-l,o=Math.sqrt(r*r+a*a);return g._disposeWeak(e),g._disposeWeak(t),o}get x(){return this._checkDisposed(),this._validate(),this.zpp_inner.x}set x(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.x!==e){if(e!==e)throw new Error("Error: Vec2::x cannot be NaN");this.zpp_inner.x=e,this._invalidate()}}get y(){return this._checkDisposed(),this._validate(),this.zpp_inner.y}set y(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.y!==e){if(e!==e)throw new Error("Error: Vec2::y cannot be NaN");this.zpp_inner.y=e,this._invalidate()}}get length(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return Math.sqrt(e*e+t*t)}set length(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::length cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,s=t*t+n*n;if(s===0)throw new Error("Error: Cannot set length of a zero vector");let i=e/Math.sqrt(s);this._setXY(t*i,n*i),this._invalidate()}get angle(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e===t&&e===0?0:Math.atan2(t,e)}set angle(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::angle cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,s=Math.sqrt(t*t+n*n),i=s*Math.cos(e),l=s*Math.sin(e);this._setXY(i,l)}lsq(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e*e+t*t}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");e.zpp_inner.validate();let t=e.zpp_inner.x,n=e.zpp_inner.y;return this._setXY(t,n),g._disposeWeak(e),this}setxy(e,t){return this._checkDisposed(),this._checkImmutable(),this._setXY(e,t),this}clone(){return this.copy()}equals(e,t=0){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)return!1;this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,s=this.zpp_inner.y-e.zpp_inner.y;return(n<0?-n:n)<=t&&(s<0?-s:s)<=t}copy(e=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y;return g._poolGet(t,n,e)}rotate(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Cannot rotate Vec2 by NaN");if(e%(Math.PI*2)!==0){let t=Math.sin(e),n=Math.cos(e),s=n*this.zpp_inner.x-t*this.zpp_inner.y;this.zpp_inner.y=this.zpp_inner.x*t+this.zpp_inner.y*n,this.zpp_inner.x=s,this._invalidate()}return this}reflect(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this._validate();let n=this.zpp_inner.x,s=this.zpp_inner.y;if(Math.sqrt(n*n+s*s)===0)throw new Error("Error: Cannot reflect in zero vector");let i=g._poolGet(n,s,!0);i.normalise();let l=e.sub(i.muleq(2*i.dot(e)),t);return g._disposeWeak(e),l}normalise(){this._checkDisposed(),this._checkImmutable(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y,n=e*e+t*t;if(Math.sqrt(n)===0)throw new Error("Error: Cannot normalise vector of length 0");let s=1/Math.sqrt(n);return this._setXY(e*s,t*s),this._invalidate(),this}unit(e=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,s=t*t+n*n;if(Math.sqrt(s)===0)throw new Error("Error: Cannot normalise vector of length 0");let i=1/Math.sqrt(s);return g._poolGet(t*i,n*i,e)}add(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x+e.zpp_inner.x,s=this.zpp_inner.y+e.zpp_inner.y,i=g._poolGet(n,s,t);return g._disposeWeak(e),i}addMul(e,t,n=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let s=this.zpp_inner.x+e.zpp_inner.x*t,i=this.zpp_inner.y+e.zpp_inner.y*t,l=g._poolGet(s,i,n);return g._disposeWeak(e),l}sub(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot subtract null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,s=this.zpp_inner.y-e.zpp_inner.y,i=g._poolGet(n,s,t);return g._disposeWeak(e),i}mul(e,t=!1){if(this._checkDisposed(),e!==e)throw new Error("Error: Cannot multiply with NaN");this._validate();let n=this.zpp_inner.x*e,s=this.zpp_inner.y*e;return g._poolGet(n,s,t)}addeq(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x+e.zpp_inner.x,n=this.zpp_inner.y+e.zpp_inner.y;return this._setXY(t,n),g._disposeWeak(e),this}subeq(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot subtract null vectors");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x-e.zpp_inner.x,n=this.zpp_inner.y-e.zpp_inner.y;return this._setXY(t,n),g._disposeWeak(e),this}muleq(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Cannot multiply with NaN");this._validate();let t=this.zpp_inner.x*e,n=this.zpp_inner.y*e;return this._setXY(t,n),this}dot(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot take dot product with null vector");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x*e.zpp_inner.x+this.zpp_inner.y*e.zpp_inner.y;return g._disposeWeak(e),t}cross(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot take cross product with null vector");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x*e.zpp_inner.y-this.zpp_inner.y*e.zpp_inner.x;return g._disposeWeak(e),t}perp(e=!1){this._checkDisposed(),this._validate();let t=-this.zpp_inner.y,n=this.zpp_inner.x;return g._poolGet(t,n,e)}dispose(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),this.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let e=this.zpp_inner;e.outer=null,this.zpp_inner=null,this.zpp_pool=null,_e.nextVec2!=null?_e.nextVec2.zpp_pool=this:_e.poolVec2=this,_e.nextVec2=this,this.zpp_disp=!0,e.free(),e.next=le.zpp_pool,le.zpp_pool=e}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};le._wrapFn=g=>Ze(g,e=>{let t=Object.create(Ie.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Bo=me();Bo.geom.Vec2=Ie;var li=class g{constructor(e=0,t=0,n=0){this.zpp_pool=null;this.zpp_disp=!1;let s=new ti;this.zpp_inner=s,s.outer=this,s.x=e,s.y=t,s.z=n}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!")}_checkImmutable(){if(this.zpp_inner.immutable)throw new Error("Error: Vec3 is immutable")}static _wrap(e){return e instanceof g?e:e?e instanceof ti?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?g._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=0){let s;return _e.poolVec3==null?s=new g:(s=_e.poolVec3,_e.poolVec3=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===_e.nextVec3&&(_e.nextVec3=null)),s.setxyz(e,t,n),s.zpp_inner.immutable=!1,s.zpp_inner._validate=null,s}get x(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.x}set x(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e}get y(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.y}set y(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.y=e}get z(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.z}set z(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.z=e}get length(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return Math.sqrt(e*e+t*t+n*n)}set length(e){if(this._checkDisposed(),e!==e)throw new Error("Error: Vec3::length cannot be NaN");this.zpp_inner.validate();let{x:t,y:n,z:s}=this.zpp_inner,i=t*t+n*n+s*s;if(i===0)throw new Error("Error: Cannot set length of a zero vector");let l=e/Math.sqrt(i);this._checkImmutable(),this.zpp_inner.x=t*l,this.zpp_inner.y=n*l,this.zpp_inner.z=s*l}lsq(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return e*e+t*t+n*n}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot assign null Vec3");return e.zpp_inner.validate(),this.setxyz(e.zpp_inner.x,e.zpp_inner.y,e.zpp_inner.z)}setxyz(e,t,n){return this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e,this._checkImmutable(),this.zpp_inner.y=t,this._checkImmutable(),this.zpp_inner.z=n,this}equals(e,t=0){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)return!1;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,s=this.zpp_inner.y-e.zpp_inner.y,i=this.zpp_inner.z-e.zpp_inner.z;return(n<0?-n:n)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t}clone(){return this._checkDisposed(),this.zpp_inner.validate(),g.get(this.zpp_inner.x,this.zpp_inner.y,this.zpp_inner.z)}xy(e=!1){return this._checkDisposed(),this.zpp_inner.validate(),Ie.get(this.zpp_inner.x,this.zpp_inner.y,e)}dispose(){if(this.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(this.zpp_inner.immutable)throw new Error("Error: This Vec3 is not disposable");this.zpp_pool=null,_e.nextVec3!=null?_e.nextVec3.zpp_pool=this:_e.poolVec3=this,_e.nextVec3=this,this.zpp_disp=!0}toString(){return this._checkDisposed(),this.zpp_inner.validate(),"{ x: "+this.zpp_inner.x+" y: "+this.zpp_inner.y+" z: "+this.zpp_inner.z+" }"}};ti._wrapFn=g=>Ze(g,e=>{let t=Object.create(li.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Gs=class g{get _inner(){return this}constructor(e=0,t=0,n=0,s=0){if(e!==e||t!==t)throw new Error("Error: AABB position cannot be NaN");if(n!==n||s!==s)throw new Error("Error: AABB dimensions cannot be NaN");let i;be.zpp_pool==null?i=new be:(i=be.zpp_pool,be.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=t,i.maxx=e+n,i.maxy=t+s,this.zpp_inner=i,i.outer=this}static fromPoints(e){if(e==null||e.length===0)throw new Error("Error: AABB::fromPoints requires at least one point");let t=e[0];if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");t.zpp_inner.validate();let n=t.zpp_inner.x,s=t.zpp_inner.y,i=n,l=s;for(let r=1;r<e.length;r++){let a=e[r];if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(a==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");a.zpp_inner.validate();let o=a.zpp_inner.x,p=a.zpp_inner.y;o<n&&(n=o),p<s&&(s=p),o>i&&(i=o),p>l&&(l=p)}return new g(n,s,i-n,l-s)}static _wrap(e){return e instanceof g?e:e?e instanceof be?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?g._wrap(e.zpp_inner):null:null}get x(){return this.zpp_inner.validate(),this.zpp_inner.minx}set x(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::x cannot be NaN");this.zpp_inner.maxx+=e-this.zpp_inner.minx,this.zpp_inner.minx=e,this.zpp_inner.invalidate()}}get y(){return this.zpp_inner.validate(),this.zpp_inner.miny}set y(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::y cannot be NaN");this.zpp_inner.maxy+=e-this.zpp_inner.miny,this.zpp_inner.miny=e,this.zpp_inner.invalidate()}}get width(){return this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx}set width(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::width cannot be NaN");if(e<0)throw new Error("Error: AABB::width ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxx=this.zpp_inner.minx+e,this.zpp_inner.invalidate()}}get height(){return this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny}set height(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::height cannot be NaN");if(e<0)throw new Error("Error: AABB::height ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxy=this.zpp_inner.miny+e,this.zpp_inner.invalidate()}}get min(){return this.zpp_inner.getmin(),this.zpp_inner.wrap_min}set min(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::min");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::min components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::min components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let s=e.zpp_inner.x;this.zpp_inner.getmax();let i=this.zpp_inner.wrap_max;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),s>i.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.y;this.zpp_inner.getmin();let r=this.zpp_inner.wrap_max;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(r.zpp_inner._validate!=null&&r.zpp_inner._validate(),l>r.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let a=this.zpp_inner.wrap_min;this._assignVec2(a,e),e.zpp_inner.weak&&this._disposeVec2(e)}get max(){return this.zpp_inner.getmax(),this.zpp_inner.wrap_max}set max(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::max");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::max components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::max components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let s=e.zpp_inner.x;this.zpp_inner.getmin();let i=this.zpp_inner.wrap_min;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),s<i.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.y;this.zpp_inner.getmin();let r=this.zpp_inner.wrap_min;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(r.zpp_inner._validate!=null&&r.zpp_inner._validate(),l<r.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let a=this.zpp_inner.wrap_max;this._assignVec2(a,e),e.zpp_inner.weak&&this._disposeVec2(e)}_assignVec2(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=e.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t==null)throw new Error("Error: Cannot assign null Vec2");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let s=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let i=t.zpp_inner.y;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e.zpp_inner._validate!=null&&e.zpp_inner._validate(),e.zpp_inner.x==s){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate(),r=e.zpp_inner.y==i}else r=!1;r||(e.zpp_inner.x=s,e.zpp_inner.y=i,e.zpp_inner._invalidate!=null&&e.zpp_inner._invalidate(e.zpp_inner))}_disposeVec2(e){let n=me().zpp_nape;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=e.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let i=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let l=e;l.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=l:n.util.ZPP_PubPool.poolVec2=l,n.util.ZPP_PubPool.nextVec2=l,l.zpp_disp=!0;let r=i;r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r}clone(){return this.copy()}equals(e,t=0){if(e==null)return!1;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.minx-e.zpp_inner.minx,s=this.zpp_inner.miny-e.zpp_inner.miny,i=this.zpp_inner.maxx-e.zpp_inner.maxx,l=this.zpp_inner.maxy-e.zpp_inner.maxy;return(n<0?-n:n)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t&&(l<0?-l:l)<=t}copy(){this.zpp_inner.validate();let e=this.zpp_inner;return be.get(e.minx,e.miny,e.maxx,e.maxy).wrapper()}toString(){return this.zpp_inner.validate(),this.zpp_inner.toString()}};be._wrapFn=g=>Ze(g,e=>{let t=Object.create(Gs.prototype);return t.zpp_inner=e,e.outer=t,t});var yl=class{constructor(e,t){this._inner=e,this._wrap=t}get length(){return this._inner.length}at(e){return this._wrap(this._inner.at(e))}add(e){this._inner.add(e._inner??e)}remove(e){this._inner.remove(e._inner??e)}has(e){return this._inner.has(e._inner??e)}clear(){this._inner.clear()}get empty(){return this._inner.empty()}push(e){this._inner.push(e._inner??e)}pop(){return this._wrap(this._inner.pop())}shift(){return this._wrap(this._inner.shift())}unshift(e){this._inner.unshift(e._inner??e)}*[Symbol.iterator](){for(let e=0;e<this.length;e++)yield this.at(e)}toArray(){return[...this]}forEach(e){for(let t=0;t<this.length;t++)e(this.at(t),t)}toString(){return this._inner.toString()}};var Zn=class g{get _inner(){return this}constructor(e=1,t=1){let n;if(gn.zpp_pool==null?n=new gn:(n=gn.zpp_pool,gn.zpp_pool=n.next,n.next=null),this.zpp_inner=n,n.outer=this,e!=n.density*1e3){if(e!==e)throw new Error("Error: FluidProperties::density cannot be NaN");n.density=e/1e3,n.invalidate()}if(t!=n.viscosity){if(t!==t)throw new Error("Error: FluidProperties::viscosity cannot be NaN");if(t<0)throw new Error("Error: FluidProperties::viscosity ("+t+") must be >= 0");n.viscosity=t/1,n.invalidate()}}static _wrap(e){return e instanceof g?e:e?e instanceof gn?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?g._wrap(e.zpp_inner):null:null}get density(){return this.zpp_inner.density*1e3}set density(e){if(e!=this.zpp_inner.density*1e3){if(e!==e)throw new Error("Error: FluidProperties::density cannot be NaN");this.zpp_inner.density=e/1e3,this.zpp_inner.invalidate()}}get viscosity(){return this.zpp_inner.viscosity}set viscosity(e){if(e!=this.zpp_inner.viscosity){if(e!==e)throw new Error("Error: FluidProperties::viscosity cannot be NaN");if(e<0)throw new Error("Error: FluidProperties::viscosity ("+e+") must be >= 0");this.zpp_inner.viscosity=e/1,this.zpp_inner.invalidate()}}get gravity(){return this.zpp_inner.wrap_gravity}set gravity(e){let n=me().zpp_nape;if(e==null){if(this.zpp_inner.wrap_gravity!=null){this.zpp_inner.wrap_gravity.zpp_inner._inuse=!1;let s=this.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),s.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let l=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let r=s;r.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=r:n.util.ZPP_PubPool.poolVec2=r,n.util.ZPP_PubPool.nextVec2=r,r.zpp_disp=!0;let a=l;a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=a,this.zpp_inner.wrap_gravity=null}}else{if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity();let s=this.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;l._validate!=null&&l._validate();let r=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=e.zpp_inner;a._validate!=null&&a._validate();let o=e.zpp_inner.y;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=s.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),r!=r||o!=o)throw new Error("Error: Vec2 components cannot be NaN");let c;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=s.zpp_inner;if(h._validate!=null&&h._validate(),s.zpp_inner.x==r){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=s.zpp_inner;u._validate!=null&&u._validate(),c=s.zpp_inner.y==o}else c=!1;if(!c){s.zpp_inner.x=r,s.zpp_inner.y=o;let u=s.zpp_inner;u._invalidate!=null&&u._invalidate(u)}if(e.zpp_inner.weak){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=e.zpp_inner;if(u._immutable)throw new Error("Error: Vec2 is immutable");if(u._isimmutable!=null&&u._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let x=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let y=e;y.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=y:n.util.ZPP_PubPool.poolVec2=y,n.util.ZPP_PubPool.nextVec2=y,y.zpp_disp=!0;let d=x;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=d}}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get shapes(){if(this.zpp_inner.wrap_shapes==null){let e=me();this.zpp_inner.wrap_shapes=e.zpp_nape.util.ZPP_ShapeList.get(this.zpp_inner.shapes,!0)}return this.zpp_inner.wrap_shapes}copy(){let t=me().zpp_nape,n=new g(this.zpp_inner.density*1e3,this.zpp_inner.viscosity);this.zpp_inner.userData!=null&&(n.zpp_inner.userData={...this.zpp_inner.userData});let s=this.zpp_inner.wrap_gravity;if(s==null){if(n.zpp_inner.wrap_gravity!=null){n.zpp_inner.wrap_gravity.zpp_inner._inuse=!1;let i=n.zpp_inner.wrap_gravity;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),i.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let r=i.zpp_inner;i.zpp_inner.outer=null,i.zpp_inner=null;let a=i;a.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=a:t.util.ZPP_PubPool.poolVec2=a,t.util.ZPP_PubPool.nextVec2=a,a.zpp_disp=!0;let o=r;o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=o,n.zpp_inner.wrap_gravity=null}}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");n.zpp_inner.wrap_gravity==null&&n.zpp_inner.getgravity();let i=n.zpp_inner.wrap_gravity;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),s==null)throw new Error("Error: Cannot assign null Vec2");if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=s.zpp_inner;r._validate!=null&&r._validate();let a=s.zpp_inner.x;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=s.zpp_inner;o._validate!=null&&o._validate();let p=s.zpp_inner.y;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=i.zpp_inner;if(c._immutable)throw new Error("Error: Vec2 is immutable");if(c._isimmutable!=null&&c._isimmutable(),a!=a||p!=p)throw new Error("Error: Vec2 components cannot be NaN");let h;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=i.zpp_inner;if(u._validate!=null&&u._validate(),i.zpp_inner.x==a){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=i.zpp_inner;x._validate!=null&&x._validate(),h=i.zpp_inner.y==p}else h=!1;if(!h){i.zpp_inner.x=a,i.zpp_inner.y=p;let x=i.zpp_inner;x._invalidate!=null&&x._invalidate(x)}if(s.zpp_inner.weak){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=s.zpp_inner;if(x._immutable)throw new Error("Error: Vec2 is immutable");if(x._isimmutable!=null&&x._isimmutable(),s.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let y=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let d=s;d.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=d:t.util.ZPP_PubPool.poolVec2=d,t.util.ZPP_PubPool.nextVec2=d,d.zpp_disp=!0;let _=y;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=_}}return n}toString(){return"{ density: "+this.zpp_inner.density*1e3+" viscosity: "+this.zpp_inner.viscosity+" gravity: "+String(this.zpp_inner.wrap_gravity)+" }"}};gn._wrapFn=g=>Ze(g,e=>{let t=Object.create(Zn.prototype);return t.zpp_inner=e,e.outer=t,t});var jo=me();jo.phys.FluidProperties=Zn;var Js,ml,bl;function ql(g){Js=g}var qs=class qs{constructor(){this._inner=void 0,this.zpp_inner_i=null}static _wrap(e){return e?e instanceof qs?e:e.isBody&&e.isBody()&&Js?Js(e):e.isShape&&e.isShape()&&ml?ml(e):e.isCompound&&e.isCompound()&&bl?bl(e):Ze(e,t=>{let n=Object.create(qs.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i??t,n}):null}get id(){return this.zpp_inner_i.id}get userData(){return this.zpp_inner_i.userData==null&&(this.zpp_inner_i.userData={}),this.zpp_inner_i.userData}get group(){return this.zpp_inner_i.group==null?null:this.zpp_inner_i.group.outer}set group(e){this.zpp_inner_i.immutable_midstep("Interactor::group"),this.zpp_inner_i.setGroup(e==null?null:e.zpp_inner)}get cbTypes(){return this.zpp_inner_i.wrap_cbTypes==null&&this.zpp_inner_i.setupcbTypes(),this.zpp_inner_i.wrap_cbTypes}get castBody(){if(this.zpp_inner_i.ibody!=null){let e=this.zpp_inner_i.ibody.outer;return Js?Js(e):e}return null}get castShape(){if(this.zpp_inner_i.ishape!=null){let e=this.zpp_inner_i.ishape.outer;return ml?ml(e):e}return null}get castCompound(){if(this.zpp_inner_i.icompound!=null){let e=this.zpp_inner_i.icompound.outer;return bl?bl(e):e}return null}isShape(){return this.zpp_inner_i.ishape!=null}isBody(){return this.zpp_inner_i.ibody!=null}isCompound(){return this.zpp_inner_i.icompound!=null}toString(){return""}};qs.zpp_internalAlloc=!1;var fi=qs;var Us,Ws;function Ul(g){Us=g}function Wl(g){Ws=g}var zi=class g extends fi{constructor(){super()}static _wrap(e){if(!e)return null;let t=e.isCircle?e.isCircle()?0:e.isPolygon?.()?1:-1:e.zpp_inner?.type??-1;return t===0&&Us?Us(e):t===1&&Ws?Ws(e):e.outer?e.outer:Ze(e,n=>{let s=Object.create(g.prototype);return s._inner=n,s.zpp_inner=n.zpp_inner??n,s.zpp_inner_i=n.zpp_inner_i??n,s})}get type(){return ni.types[this.zpp_inner.type]}isCircle(){return this.zpp_inner.type===0}isPolygon(){return this.zpp_inner.type===1}get body(){let e=this.zpp_inner;return e.body!=null?e.body.outer:null}set body(e){let t=this.zpp_inner;t.immutable_midstep("Shape::body");let n=t.body!=null?t.body.outer:null;if(n!==e&&(t.body!=null&&n.zpp_inner.wrap_shapes.remove(this),e!=null)){let s=e.zpp_inner.wrap_shapes;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}}get castCircle(){let e=this.zpp_inner;if(e.type===0){let t=e.circle.outer_zn;return Us?Us(t):t}return null}get castPolygon(){let e=this.zpp_inner;if(e.type===1){let t=e.polygon.outer_zn;return Ws?Ws(t):t}return null}get worldCOM(){let e=this.zpp_inner;return e.wrap_worldCOM==null&&this._setupWorldCOM(),e.wrap_worldCOM}get localCOM(){let e=this.zpp_inner;return e.wrap_localCOM==null&&(e.type===0?e.circle.setupLocalCOM():e.polygon.setupLocalCOM()),e.wrap_localCOM}set localCOM(e){let t=this.zpp_inner;if(t.immutable_midstep("Body::localCOM"),e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Shape::localCOM cannot be null");t.wrap_localCOM==null&&(t.type===0?t.circle.setupLocalCOM():t.polygon.setupLocalCOM()),t.wrap_localCOM.set(e),e.zpp_inner.weak&&e.dispose()}get area(){let e=this.zpp_inner;return e.validate_area_inertia(),e.area}get inertia(){let e=this.zpp_inner;return e.validate_area_inertia(),e.inertia}get angDrag(){let e=this.zpp_inner;return e.validate_angDrag(),e.angDrag}get material(){return this.zpp_inner.material.wrapper()}set material(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::material"),e==null)throw new Error("Error: Cannot assign null as Shape material");t.setMaterial(e.zpp_inner)}get filter(){return this.zpp_inner.filter.wrapper()}set filter(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::filter"),e==null)throw new Error("Error: Cannot assign null as Shape filter");t.setFilter(e.zpp_inner)}get fluidProperties(){let e=this.zpp_inner;return e.immutable_midstep("Shape::fluidProperties"),e.fluidProperties==null&&e.setFluid(new Zn().zpp_inner),e.fluidProperties.wrapper()}set fluidProperties(e){let t=this.zpp_inner;if(e==null)throw new Error("Error: Cannot assign null as Shape fluidProperties, disable fluids by setting fluidEnabled to false");t.setFluid(e.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new Zn().zpp_inner)}get cbTypes(){this.zpp_inner_i.wrap_cbTypes==null&&this.zpp_inner_i.setupcbTypes();let e=this.zpp_inner_i.wrap_cbTypes;return{_inner:e,add(t){e.add(t._inner)},remove(t){e.remove(t._inner)},has(t){return e.has(t._inner)},clear(){e.clear()},get length(){return e.length}}}get fluidEnabled(){return this.zpp_inner.fluidEnabled}set fluidEnabled(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::fluidEnabled"),t.fluidEnabled=e,e&&t.fluidProperties==null){let n=new Zn;t.setFluid(n.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new Zn().zpp_inner),t.fluidProperties.wrapper()}t.wake()}get sensorEnabled(){return this.zpp_inner.sensorEnabled}set sensorEnabled(e){let t=this.zpp_inner;t.immutable_midstep("Shape::sensorEnabled"),t.sensorEnabled=e,t.wake()}get bounds(){return this.zpp_inner.aabb.wrapper()}translate(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::translate()"),e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Cannot displace Shape by null Vec2");if(e.lsq()>0){let n=e.zpp_inner;n._validate!=null&&n._validate();let s=n.x;n._validate!=null&&n._validate();let i=n.y;(t.type===0?t.circle:t.polygon).__translate(s,i)}return e.zpp_inner.weak&&e.dispose(),this}scale(e,t){let n=this.zpp_inner,s=me();if(n.immutable_midstep("Shape::scale()"),n.body!=null&&n.body.space!=null&&n.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e!==e||t!==t)throw new Error("Error: Cannot scale Shape by NaN");if(e===0||t===0)throw new Error("Error: Cannot Scale shape by a factor of 0");if(n.type===0){let i=e*e-t*t;if(i*i<s.Config.epsilon*s.Config.epsilon)n.circle.__scale(e,t);else throw new Error("Error: Cannot perform a non equal scaling on a Circle")}else n.polygon.__scale(e,t);return this}rotate(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::rotate()"),t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e!==e)throw new Error("Error: Cannot rotate Shape by NaN");if(e%(2*Math.PI)!==0){let s=Math.cos(e),i=Math.sin(e);t.type===0?t.circle.__rotate(i,s):t.polygon.__rotate(i,s)}return this}transform(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::transform()"),t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Cannot transform Shape by null matrix");let n=e._inner??e;if(n.singular())throw new Error("Error: Cannot transform Shape by a singular matrix");if(t.type===0)if(n.equiorthogonal())t.circle.__transform(n);else throw new Error("Error: Cannot transform Circle by a non equiorthogonal matrix");else t.polygon.__transform(n);return this}contains(e){let t=this.zpp_inner;if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Cannot check null point for containment");if((t.body!=null?t.body.outer:null)==null)throw new Error("Error: Shape is not well defined without a Body");bs.validateShape(t);let n=e.zpp_inner;n._validate!=null&&n._validate();let s=Ee.shapeContains(t,n);return n.weak&&e.dispose(),s}copy(){let e=this.zpp_inner.copy();return e instanceof g?e:g._wrap(e)}toString(){return(this.zpp_inner.type===0?"Circle":"Polygon")+"#"+this.zpp_inner_i.id}_setupWorldCOM(){let e=me(),t=this.zpp_inner,n=t.worldCOMx,s=t.worldCOMy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(_e.poolVec2==null?i=new e.geom.Vec2:(i=_e.poolVec2,_e.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i===_e.nextVec2&&(_e.nextVec2=null)),i.zpp_inner==null){let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,t.wrap_worldCOM=i,t.wrap_worldCOM.zpp_inner._inuse=!0,t.wrap_worldCOM.zpp_inner._immutable=!0,t.wrap_worldCOM.zpp_inner._validate=t.getworldCOM.bind(t)}};var Sl=class{constructor(){this.user_length=0;this.zip_length=!1;this.push_ite=null;this.at_ite=null;this.at_index=0;this.reverse_flag=!1;this.dontremove=!1;this.subber=null;this.post_adder=null;this.adder=null;this._modifiable=null;this._validate=null;this._invalidate=null;this._invalidated=!1;this.immutable=!1;this.inner=null;this.outer=null;this._invalidated=!0}valmod(){this.validate(),this.inner.modified&&(this.inner.pushmod&&(this.push_ite=null),this.at_ite=null,this.inner.modified=!1,this.inner.pushmod=!1,this.zip_length=!0)}modified(){this.zip_length=!0,this.at_ite=null,this.push_ite=null}modify_test(){this._modifiable!=null&&this._modifiable()}validate(){this._invalidated&&(this._invalidated=!1,this._validate!=null&&this._validate())}invalidate(){this._invalidated=!0,this._invalidate!=null&&this._invalidate(this)}};function kn(g,e,t,n){let s=me(),i=s.__zpp;class l extends Sl{constructor(){super(),this.inner=new i.util[g]}static get(a,o=!1){let p=new s[e][t];return p.zpp_inner.inner=a,o&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}}return l.internal=!1,i.util[n]=l,l}var Al=null,To=null,Vl=null;Al=kn("ZNPList_ZPP_Constraint","constraint","ConstraintList","ZPP_ConstraintList");kn("ZNPList_ZPP_Body","phys","BodyList","ZPP_BodyList");To=kn("ZNPList_ZPP_Interactor","phys","InteractorList","ZPP_InteractorList");kn("ZNPList_ZPP_Compound","phys","CompoundList","ZPP_CompoundList");kn("ZNPList_ZPP_Listener","callbacks","ListenerList","ZPP_ListenerList");kn("ZNPList_ZPP_CbType","callbacks","CbTypeList","ZPP_CbTypeList");kn("ZNPList_ZPP_GeomPoly","geom","GeomPolyList","ZPP_GeomPolyList");kn("ZNPList_RayResult","geom","RayResultList","ZPP_RayResultList");kn("ZNPList_ConvexResult","geom","ConvexResultList","ZPP_ConvexResultList");kn("ZNPList_ZPP_Edge","shape","EdgeList","ZPP_EdgeList");kn("ZNPList_ZPP_Shape","shape","ShapeList","ZPP_ShapeList");kn("ZNPList_ZPP_InteractionGroup","dynamics","InteractionGroupList","ZPP_InteractionGroupList");Vl=kn("ZNPList_ZPP_Arbiter","dynamics","ArbiterList","ZPP_ArbiterList");function Rn(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Gn(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Bn(g){if(g!=null&&g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}function En(g){g.zpp_inner.weak&&g.dispose()}function ws(g,e,t,n,s){if(Bn(t),t==null)throw new Error("Error: Body::"+g+" cannot be null");return e==null&&n!=null&&(n(),e=s()),e.set(t),e}function fl(g,e,t){return Ie.get(g,e,t)}function en(g,e){return H[g]==null&&(H.internal=!0,H[g]=e(),H.internal=!1),H[g]}var We=class g extends fi{constructor(t,n){super();this.debugDraw=!0;let s=new vn;this.zpp_inner=s,s.outer=this,s.outer_i=this,this.zpp_inner_i=s,this._inner=this,n!=null?(Bn(n),s.posx=Rn(n),s.posy=Gn(n)):(s.posx=0,s.posy=0);let i=me(),l;if(t==null?l=en("BodyType_DYNAMIC",()=>new i.phys.BodyType):l=t,s.immutable_midstep("Body::type"),s.world)throw new Error("Error: Space::world is immutable");if(vn.types[s.type]!==l){if(l==null)throw new Error("Error: Cannot use null BodyType");let r=Kl(l,i);r===1&&s.space!=null&&(s.velx=0,s.vely=0,s.angvel=0),s.invalidate_type(),s.space!=null?s.space.transmitType(s,r):s.type=r}n!=null&&En(n),s.insert_cbtype(fn.ANY_BODY.zpp_inner)}static _wrap(t){return t?t instanceof g?t:t instanceof vn?Ze(t,n=>{let s=Object.create(g.prototype);return s.zpp_inner=n,n.outer=s,n.outer_i=s,s.zpp_inner_i=n,s._inner=s,s.debugDraw=!0,s}):t.zpp_inner?g._wrap(t.zpp_inner):Ze(t,n=>{let s=Object.create(g.prototype);return s._inner=n,s}):null}get type(){return vn.types[this.zpp_inner.type]}set type(t){let n=this.zpp_inner;if(n.immutable_midstep("Body::type"),n.world)throw new Error("Error: Space::world is immutable");if(vn.types[n.type]!==t){if(t==null)throw new Error("Error: Cannot use null BodyType");let s=me(),i=Kl(t,s);i===1&&n.space!=null&&(n.velx=0,n.vely=0,n.angvel=0),n.invalidate_type(),n.space!=null?n.space.transmitType(n,i):n.type=i}}isStatic(){return this.zpp_inner.type===1}isDynamic(){return this.zpp_inner.type===2}isKinematic(){return this.zpp_inner.type===3}get position(){return this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),this.zpp_inner.wrap_pos}set position(t){ws("position",this.zpp_inner.wrap_pos,t,()=>this.zpp_inner.setupPosition(),()=>this.zpp_inner.wrap_pos),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition()}get rotation(){return this.zpp_inner.rot}set rotation(t){let n=this.zpp_inner;if(n.immutable_midstep("Body::rotation"),n.world)throw new Error("Error: Space::world is immutable");if(n.type===1&&n.space!=null)throw new Error("Error: Static objects cannot be rotated once inside a Space");if(n.rot!==t){if(t!==t)throw new Error("Error: Body::rotation cannot be NaN");n.rot=t,n.invalidate_rot(),n.wake()}}get velocity(){return this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity(),this.zpp_inner.wrap_vel}set velocity(t){ws("velocity",this.zpp_inner.wrap_vel,t,()=>this.zpp_inner.setupVelocity(),()=>this.zpp_inner.wrap_vel),this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity()}get angularVel(){return this.zpp_inner.angvel}set angularVel(t){let n=this.zpp_inner;if(n.world)throw new Error("Error: Space::world is immutable");if(n.angvel!==t){if(t!==t)throw new Error("Error: Body::angularVel cannot be NaN");if(n.type===1)throw new Error("Error: A static object cannot be given a velocity");n.angvel=t,n.wake()}}get kinematicVel(){return this.zpp_inner.wrap_kinvel==null&&this.zpp_inner.setupkinvel(),this.zpp_inner.wrap_kinvel}set kinematicVel(t){ws("kinematicVel",this.zpp_inner.wrap_kinvel,t,()=>this.zpp_inner.setupkinvel(),()=>this.zpp_inner.wrap_kinvel),this.zpp_inner.wrap_kinvel==null&&this.zpp_inner.setupkinvel()}get kinAngVel(){return this.zpp_inner.kinangvel}set kinAngVel(t){let n=this.zpp_inner;if(n.world)throw new Error("Error: Space::world is immutable");if(n.kinangvel!==t){if(t!==t)throw new Error("Error: Body::kinAngVel cannot be NaN");n.kinangvel=t,n.wake()}}get surfaceVel(){return this.zpp_inner.wrap_svel==null&&this.zpp_inner.setupsvel(),this.zpp_inner.wrap_svel}set surfaceVel(t){ws("surfaceVel",this.zpp_inner.wrap_svel,t,()=>this.zpp_inner.setupsvel(),()=>this.zpp_inner.wrap_svel),this.zpp_inner.wrap_svel==null&&this.zpp_inner.setupsvel()}get force(){return this.zpp_inner.wrap_force==null&&this.zpp_inner.setupForce(),this.zpp_inner.wrap_force}set force(t){ws("force",this.zpp_inner.wrap_force,t,()=>this.zpp_inner.setupForce(),()=>this.zpp_inner.wrap_force),this.zpp_inner.wrap_force==null&&this.zpp_inner.setupForce()}get torque(){return this.zpp_inner.torque}set torque(t){let n=this.zpp_inner;if(n.world)throw new Error("Error: Space::world is immutable");if(n.type!==2)throw new Error("Error: Non-dynamic body cannot have torque applied.");if(t!==t)throw new Error("Error: Body::torque cannot be NaN");n.torque!==t&&(n.torque=t,n.wake())}get mass(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(this.zpp_inner.validate_mass(),this.zpp_inner.massMode===0&&this.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");return this.zpp_inner.cmass}set mass(t){if(this.zpp_inner.immutable_midstep("Body::mass"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: Mass cannot be NaN");if(t<=0)throw new Error("Error: Mass must be strictly positive");if(t>=1/0)throw new Error("Error: Mass cannot be infinite, use allowMovement = false instead");this.zpp_inner.massMode=1,this.zpp_inner.cmass=t,this.zpp_inner.invalidate_mass()}get inertia(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no inertia");if(this.zpp_inner.validate_inertia(),this.zpp_inner.inertiaMode===0&&this.zpp_inner.shapes.head==null)throw new Error("Error: Given current inertia mode flag, Body::inertia only makes sense if Body contains Shapes");return this.zpp_inner.cinertia}set inertia(t){if(this.zpp_inner.immutable_midstep("Body::inertia"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: Inertia cannot be NaN");if(t<=0)throw new Error("Error: Inertia must be strictly positive");if(t>=1/0)throw new Error("Error: Inertia cannot be infinite, use allowRotation = false instead");this.zpp_inner.inertiaMode=1,this.zpp_inner.cinertia=t,this.zpp_inner.invalidate_inertia()}get constraintMass(){return this.zpp_inner.world||this.zpp_inner.validate_mass(),this.zpp_inner.smass}get constraintInertia(){return this.zpp_inner.world||this.zpp_inner.validate_inertia(),this.zpp_inner.sinertia}get gravMass(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no gravMass");if(this.zpp_inner.validate_gravMass(),this.zpp_inner.shapes.head==null&&this.zpp_inner.massMode===0&&this.zpp_inner.gravMassMode!==1)throw new Error("Error: Given current mass/gravMass modes; Body::gravMass only makes sense if it contains Shapes");return this.zpp_inner.gravMass}set gravMass(t){if(this.zpp_inner.immutable_midstep("Body::gravMass"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: gravMass cannot be NaN");this.zpp_inner.gravMassMode=1,this.zpp_inner.gravMass=t,this.zpp_inner.invalidate_gravMass()}get gravMassScale(){if(this.zpp_inner.validate_gravMassScale(),this.zpp_inner.shapes.head==null&&this.zpp_inner.massMode===0&&this.zpp_inner.gravMassMode!==2)throw new Error("Error: Given current mass/gravMass modes; Body::gravMassScale only makes sense if it contains Shapes");return this.zpp_inner.gravMassScale}set gravMassScale(t){if(this.zpp_inner.immutable_midstep("Body::gravMassScale"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: gravMassScale cannot be NaN");this.zpp_inner.gravMassMode=2,this.zpp_inner.gravMassScale=t,this.zpp_inner.invalidate_gravMassScale()}get isBullet(){return this.zpp_inner.bulletEnabled}set isBullet(t){this.zpp_inner.bulletEnabled=t}get disableCCD(){return this.zpp_inner.disableCCD}set disableCCD(t){this.zpp_inner.disableCCD=t}get allowMovement(){return!this.zpp_inner.nomove}set allowMovement(t){this.zpp_inner.immutable_midstep("Body::"+(t==null?"null":""+t)),!this.zpp_inner.nomove!==t&&(this.zpp_inner.nomove=!t,this.zpp_inner.invalidate_mass())}get allowRotation(){return!this.zpp_inner.norotate}set allowRotation(t){this.zpp_inner.immutable_midstep("Body::"+(t==null?"null":""+t)),!this.zpp_inner.norotate!==t&&(this.zpp_inner.norotate=!t,this.zpp_inner.invalidate_inertia())}get isSleeping(){if(this.zpp_inner.space==null)throw new Error("Error: isSleeping makes no sense if the object is not contained within a Space");return this.zpp_inner.component.sleeping}get shapes(){return new yl(this.zpp_inner.wrap_shapes,zi._wrap)}get space(){return this.zpp_inner.space==null?null:Xn._wrap(this.zpp_inner.space.outer)}set space(t){let n=t!=null?t._inner??t:null;if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let s=this.zpp_inner.space==null?null:this.zpp_inner.space.outer;if(s!==n&&(s!=null&&(this.zpp_inner.component.woken=!1,s.zpp_inner.wrap_bodies.remove(this)),n!=null)){let i=n.zpp_inner.wrap_bodies;i.zpp_inner.reverse_flag?i.push(this):i.unshift(this)}}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(t){let n=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(n!==t&&(n?.zpp_inner.wrap_bodies.remove(this),t!=null)){let s=t.zpp_inner.wrap_bodies;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}}get bounds(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no bounds");return Gs._wrap(this.zpp_inner.aabb.wrapper())}get constraintVelocity(){return this.zpp_inner.wrapcvel==null&&this.zpp_inner.setup_cvel(),this.zpp_inner.wrapcvel}get localCOM(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no localCOM");if(this.zpp_inner.wrap_localCOM==null){let t=Ie.get(this.zpp_inner.localCOMx,this.zpp_inner.localCOMy);this.zpp_inner.wrap_localCOM=t,t.zpp_inner._inuse=!0,t.zpp_inner._immutable=!0,t.zpp_inner._validate=()=>this.zpp_inner.getlocalCOM()}return this.zpp_inner.wrap_localCOM}get worldCOM(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");if(this.zpp_inner.wrap_worldCOM==null){let t=Ie.get(this.zpp_inner.worldCOMx,this.zpp_inner.worldCOMy);this.zpp_inner.wrap_worldCOM=t,t.zpp_inner._inuse=!0,t.zpp_inner._immutable=!0,t.zpp_inner._validate=()=>this.zpp_inner.getworldCOM()}return this.zpp_inner.wrap_worldCOM}get massMode(){let t=me(),n=en("MassMode_DEFAULT",()=>new t.phys.MassMode),s=en("MassMode_FIXED",()=>new t.phys.MassMode);return[n,s][this.zpp_inner.massMode]}set massMode(t){let n=me();if(this.zpp_inner.immutable_midstep("Body::massMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: cannot use null massMode");let s=en("MassMode_DEFAULT",()=>new n.phys.MassMode);this.zpp_inner.massMode=t===s?0:1,this.zpp_inner.invalidate_mass()}get inertiaMode(){let t=me(),n=en("InertiaMode_DEFAULT",()=>new t.phys.InertiaMode),s=en("InertiaMode_FIXED",()=>new t.phys.InertiaMode);return[n,s][this.zpp_inner.inertiaMode]}set inertiaMode(t){let n=me();if(this.zpp_inner.immutable_midstep("Body::inertiaMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot use null InertiaMode");let s=en("InertiaMode_FIXED",()=>new n.phys.InertiaMode);this.zpp_inner.inertiaMode=t===s?1:0,this.zpp_inner.invalidate_inertia()}get gravMassMode(){let t=me(),n=en("GravMassMode_DEFAULT",()=>new t.phys.GravMassMode),s=en("GravMassMode_FIXED",()=>new t.phys.GravMassMode),i=en("GravMassMode_SCALED",()=>new t.phys.GravMassMode);return[n,s,i][this.zpp_inner.gravMassMode]}set gravMassMode(t){let n=me();if(this.zpp_inner.immutable_midstep("Body::gravMassMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot use null gravMassMode");let s=en("GravMassMode_SCALED",()=>new n.phys.GravMassMode);if(t===s)this.zpp_inner.gravMassMode=2;else{let i=en("GravMassMode_DEFAULT",()=>new n.phys.GravMassMode);this.zpp_inner.gravMassMode=t===i?0:1}this.zpp_inner.invalidate_gravMass()}copy(){if(this.zpp_inner.world)throw new Error("Error: Space::world cannot be copied");return this.zpp_inner.copy()}toString(){let t=this.zpp_inner;return(t.world?"(space::world":"("+(t.type===2?"dynamic":t.type===1?"static":"kinematic"))+")#"+this.zpp_inner_i.id}integrate(t){if(t!==t)throw new Error("Cannot integrate by NaN time");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t===0)return this;let n=this.zpp_inner;n.sweepTime=0,n.sweep_angvel=n.angvel;let s=t-n.sweepTime;if(s!==0&&(n.sweepTime=t,n.posx+=n.velx*s,n.posy+=n.vely*s,n.angvel!==0)){let i=n.sweep_angvel*s;if(n.rot+=i,i*i>1e-4)n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot);else{let l=i*i,r=1-.5*l,a=1-l*l/8,o=(r*n.axisx+i*n.axisy)*a;n.axisy=(r*n.axisy-i*n.axisx)*a,n.axisx=o}}return Yl(n),n.zip_worldCOM=!0,n.zip_axis=!0,Yl(n),n.zip_worldCOM=!0,n.sweepTime=0,this}localPointToWorld(t,n=!1){if(Bn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Rn(t),i=Gn(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,r=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return En(t),fl(l+this.zpp_inner.posx,r+this.zpp_inner.posy,n)}worldPointToLocal(t,n=!1){if(Bn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Rn(t)-this.zpp_inner.posx,i=Gn(t)-this.zpp_inner.posy,l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,r=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return En(t),fl(l,r,n)}localVectorToWorld(t,n=!1){if(Bn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Rn(t),i=Gn(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,r=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return En(t),fl(l,r,n)}worldVectorToLocal(t,n=!1){if(Bn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Rn(t),i=Gn(t),l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,r=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return En(t),fl(l,r,n)}applyImpulse(t,n,s=!1){if(Bn(t),n!=null&&Bn(n),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot apply null impulse to Body");if(s&&this.isSleeping)return En(t),n!=null&&En(n),this;this.zpp_inner.validate_mass();let i=this.zpp_inner.imass,l=Rn(t),r=Gn(t);if(this.zpp_inner.velx+=l*i,this.zpp_inner.vely+=r*i,n!=null){let a=Rn(n)-this.zpp_inner.posx,o=Gn(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(r*a-l*o)*this.zpp_inner.iinertia,En(n)}return s||this.zpp_inner.type===2&&this.zpp_inner.wake(),En(t),this}applyAngularImpulse(t,n=!1){if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");return n&&this.isSleeping?this:(this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=t*this.zpp_inner.iinertia,n||this.zpp_inner.type===2&&this.zpp_inner.wake(),this)}setVelocityFromTarget(t,n,s){if(Bn(t),t==null)throw new Error("Cannot set velocity for null target position");if(s===0)throw new Error("deltaTime cannot be 0 for setVelocityFromTarget");let i=1/s;this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity(),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let l=t.sub(this.zpp_inner.wrap_pos,!0).muleq(i);this.zpp_inner.wrap_vel.set(l);let r=(n-this.zpp_inner.rot)*i;if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.angvel!==r){if(r!==r)throw new Error("Error: Body::angularVel cannot be NaN");if(this.zpp_inner.type===1)throw new Error("Error: A static object cannot be given a velocity");this.zpp_inner.angvel=r,this.zpp_inner.wake()}return En(t),this}translateShapes(t){if(this.zpp_inner.immutable_midstep("Body::translateShapes()"),Bn(t),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot displace by null Vec2");let n=t.zpp_inner.weak;t.zpp_inner.weak=!1;let s=this.zpp_inner.shapes.head;for(;s!=null;)s.elt.outer.translate(t),s=s.next;return t.zpp_inner.weak=n,En(t),this}rotateShapes(t){if(this.zpp_inner.immutable_midstep("Body::rotateShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.rotate(t),n=n.next;return this}scaleShapes(t,n){if(this.zpp_inner.immutable_midstep("Body::scaleShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let s=this.zpp_inner.shapes.head;for(;s!=null;)s.elt.outer.scale(t,n),s=s.next;return this}transformShapes(t){if(this.zpp_inner.immutable_midstep("Body::transformShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.transform(t),n=n.next;return this}align(){if(this.zpp_inner.immutable_midstep("Body::align()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.shapes.head==null)throw new Error("Error: Cannot align empty Body");this.zpp_inner.validate_localCOM();let t=Ie.get(-this.zpp_inner.localCOMx,-this.zpp_inner.localCOMy);this.translateShapes(t);let n=this.localVectorToWorld(t);return this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),this.zpp_inner.wrap_pos.subeq(n),this.zpp_inner.pre_posx<1/0&&(this.zpp_inner.pre_posx-=Rn(n),this.zpp_inner.pre_posy-=Gn(n)),t.dispose(),n.dispose(),this}rotate(t,n){if(Bn(t),t==null)throw new Error("Error: Cannot rotate about a null Vec2");if(n!==n)throw new Error("Error: Cannot rotate by NaN radians");let s=t.zpp_inner.weak;t.zpp_inner.weak=!1,this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let i=this.zpp_inner.wrap_pos.sub(t);i.rotate(n);let l=t.add(i,!0);ws("position",this.zpp_inner.wrap_pos,l,()=>this.zpp_inner.setupPosition(),()=>this.zpp_inner.wrap_pos),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),i.dispose();{let r=this.zpp_inner.rot+n,a=this.zpp_inner;if(a.immutable_midstep("Body::rotation"),a.world)throw new Error("Error: Space::world is immutable");if(a.type===1&&a.space!=null)throw new Error("Error: Static objects cannot be rotated once inside a Space");if(a.rot!==r){if(r!==r)throw new Error("Error: Body::rotation cannot be NaN");a.rot=r,a.invalidate_rot(),a.wake()}}return t.zpp_inner.weak=s,En(t),this}setShapeMaterials(t){if(this.zpp_inner.immutable_midstep("Body::setShapeMaterials()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let s=n.elt.outer;if(s.zpp_inner.immutable_midstep("Shape::material"),t==null)throw new Error("Error: Cannot assign null as Shape material");s.zpp_inner.setMaterial(t.zpp_inner),s.zpp_inner.material.wrapper(),n=n.next}return this}setShapeFilters(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFilters()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let s=n.elt.outer;if(s.zpp_inner.immutable_midstep("Shape::filter"),t==null)throw new Error("Error: Cannot assign null as Shape filter");s.zpp_inner.setFilter(t.zpp_inner),s.zpp_inner.filter.wrapper(),n=n.next}return this}setShapeFluidProperties(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFluidProperties()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=me(),s=this.zpp_inner.shapes.head;for(;s!=null;){let i=s.elt.outer;if(t==null)throw new Error("Error: Cannot assign null as Shape fluidProperties, disable fluids by setting fluidEnabled to false");i.zpp_inner.setFluid(t.zpp_inner),i.zpp_inner.immutable_midstep("Shape::fluidProperties"),i.zpp_inner.fluidProperties==null&&i.zpp_inner.setFluid(new n.phys.FluidProperties().zpp_inner),i.zpp_inner.fluidProperties.wrapper(),s=s.next}return this}contains(t){if(Bn(t),t==null)throw new Error("Error: Cannot check containment of null point");let n=t.zpp_inner.weak;t.zpp_inner.weak=!1;let s=!1,i=this.zpp_inner.shapes.head;for(;i!=null;){if(i.elt.outer.contains(t)){s=!0;break}i=i.next}return t.zpp_inner.weak=n,En(t),s}connectedBodies(t=-1,n=null){return this.zpp_inner.connectedBodies(t,n)}interactingBodies(t=null,n=-1,s=null){let i;if(t==null)i=Ve.COL|Ve.SENSOR|Ve.FLUID;else{let l=me(),r=en("InteractionType_COLLISION",()=>new l.callbacks.InteractionType);if(t===r)i=Ve.COL;else{let a=en("InteractionType_SENSOR",()=>new l.callbacks.InteractionType);i=t===a?Ve.SENSOR:Ve.FLUID}}return this.zpp_inner.interactingBodies(i,s)}normalImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ve.COL,s=>s.collisionArbiter.normalImpulse(this,n),t)}tangentImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ve.COL,s=>s.collisionArbiter.tangentImpulse(this,n),t)}totalContactsImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ve.COL,s=>s.collisionArbiter.totalImpulse(this,n),t)}rollingImpulse(t=null,n=!1){let s=0,l=this._getArbiters().iterator();for(;;){l.zpp_inner.zpp_inner.valmod();let r=l.zpp_inner.zpp_gl();if(l.zpp_critical=!0,l.zpp_i>=r){l.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1;let a=l.zpp_inner.at(l.zpp_i++),o=a.zpp_inner;o.type===Ve.COL&&(t!=null&&o.b2!==t.zpp_inner&&o.b1!==t.zpp_inner||(s+=a.collisionArbiter.rollingImpulse(this,n)))}return s}buoyancyImpulse(t=null){return this._arbiterImpulseQuery(Ve.FLUID,n=>n.fluidArbiter.buoyancyImpulse(this),t)}dragImpulse(t=null){return this._arbiterImpulseQuery(Ve.FLUID,n=>n.fluidArbiter.dragImpulse(this),t)}totalFluidImpulse(t=null){return this._arbiterImpulseQuery(Ve.FLUID,n=>n.fluidArbiter.totalImpulse(this),t)}constraintsImpulse(){let t=0,n=0,s=0,i=this.zpp_inner.constraints.head;for(;i!=null;){let r=i.elt.outer.bodyImpulse(this),a=r.zpp_inner;a._validate!=null&&a._validate(),t+=a.x,a._validate!=null&&a._validate(),n+=a.y,a._validate!=null&&a._validate(),s+=a.z,r.dispose(),i=i.next}return li.get(t,n,s)}totalImpulse(t=null,n=!1){let s=0,i=0,l=0,a=this._getArbiters().iterator();for(;;){a.zpp_inner.zpp_inner.valmod();let p=a.zpp_inner.zpp_gl();if(a.zpp_critical=!0,a.zpp_i>=p){a.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=a,a.zpp_inner=null;break}a.zpp_critical=!1;let h=a.zpp_inner.at(a.zpp_i++).zpp_inner;if(h.type===Ve.SENSOR||t!=null&&h.b2!==t.zpp_inner&&h.b1!==t.zpp_inner)continue;let u=h.wrapper().totalImpulse(this,n),x=u.zpp_inner;x._validate!=null&&x._validate(),s+=x.x,x._validate!=null&&x._validate(),i+=x.y,x._validate!=null&&x._validate(),l+=x.z,u.dispose()}let o=this.zpp_inner.constraints.head;for(;o!=null;){let p=o.elt;if(p.outer.active){let c=p.outer.bodyImpulse(this),h=c.zpp_inner;h._validate!=null&&h._validate(),s+=h.x,h._validate!=null&&h._validate(),i+=h.y,h._validate!=null&&h._validate(),l+=h.z,c.dispose()}o=o.next}return li.get(s,i,l)}crushFactor(){if(this.zpp_inner.space==null)throw new Error("Error: Makes no sense to see how much an object not taking part in a simulation is being crushed");let t=0,n=Ie.get(0,0),i=this._getArbiters().iterator();for(;;){i.zpp_inner.zpp_inner.valmod();let x=i.zpp_inner.zpp_gl();if(i.zpp_critical=!0,i.zpp_i>=x){i.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1;let d=i.zpp_inner.at(i.zpp_i++).totalImpulse(this),_=d.xy();n.addeq(_);let f=Rn(_),z=Gn(_);t+=Math.sqrt(f*f+z*z),_.dispose(),d.dispose()}let r=this._getConstraints();r.zpp_inner.valmod();let a=me().constraint.ConstraintIterator.get(r);for(;;){a.zpp_inner.zpp_inner.valmod();let x=a.zpp_inner;x.zpp_inner.valmod(),x.zpp_inner.zip_length&&(x.zpp_inner.zip_length=!1,x.zpp_inner.user_length=x.zpp_inner.inner.length);let y=x.zpp_inner.user_length;if(a.zpp_critical=!0,a.zpp_i>=y){a.zpp_next=me().constraint.ConstraintIterator.zpp_pool,me().constraint.ConstraintIterator.zpp_pool=a,a.zpp_inner=null;break}a.zpp_critical=!1;let _=a.zpp_inner.at(a.zpp_i++).bodyImpulse(this),f=_.xy();n.addeq(f);let z=Rn(f),P=Gn(f);t+=Math.sqrt(z*z+P*P),f.dispose(),_.dispose()}let o=Rn(n),p=Gn(n),c=Math.sqrt(o*o+p*p),h=this.mass,u=(t-c)/(h*this.zpp_inner.space.pre_dt);return n.dispose(),u}_getArbiters(){return this.zpp_inner.wrap_arbiters==null&&(this.zpp_inner.wrap_arbiters=Vl.get(this.zpp_inner.arbiters,!0)),this.zpp_inner.wrap_arbiters}_getConstraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=Al.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}_arbiterImpulseQuery(t,n,s){let i=0,l=0,r=0,o=this._getArbiters().iterator();for(;;){o.zpp_inner.zpp_inner.valmod();let p=o.zpp_inner.zpp_gl();if(o.zpp_critical=!0,o.zpp_i>=p){o.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let c=o.zpp_inner.at(o.zpp_i++),h=c.zpp_inner;if(h.type!==t||s!=null&&h.b2!==s.zpp_inner&&h.b1!==s.zpp_inner)continue;let u=n(c),x=u.zpp_inner;x._validate!=null&&x._validate(),i+=x.x,x._validate!=null&&x._validate(),l+=x.y,x._validate!=null&&x._validate(),r+=x.z,u.dispose()}return li.get(i,l,r)}};function Kl(g,e){let t=en("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(g===t)return 2;let n=en("BodyType_KINEMATIC",()=>new e.phys.BodyType);return g===n?3:1}function Yl(g){let e=g.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}}var Lo=me();Lo.phys.Body=We;ql(g=>We._wrap(g));var Pi={SHAPES:1,JOINTS:2,CONTACTS:4,AABB:8,CENTER_OF_MASS:16,VELOCITIES:32,ALL:63};var Xn=class g{constructor(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=e==null?null:e.zpp_inner;this.zpp_inner=new si(n,t),this.zpp_inner.outer=this,e!=null&&e.zpp_inner?.weak&&e.dispose()}get _inner(){return this}static _wrap(e){return e?e instanceof g?e:e instanceof si?e.outer?e.outer:Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?.outer?e.zpp_inner.outer:Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n}):null}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get gravity(){return this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity(),this.zpp_inner.wrap_gravity}set gravity(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Space::gravity cannot be null");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity(),this.zpp_inner.wrap_gravity.set(e),e.zpp_inner?.weak&&e.dispose()}get broadphase(){return this.zpp_inner.bphase.is_sweep?(H.Broadphase_SWEEP_AND_PRUNE==null&&(H.internal=!0,H.Broadphase_SWEEP_AND_PRUNE=new(me()).space.Broadphase,H.internal=!1),H.Broadphase_SWEEP_AND_PRUNE):(H.Broadphase_DYNAMIC_AABB_TREE==null&&(H.internal=!0,H.Broadphase_DYNAMIC_AABB_TREE=new(me()).space.Broadphase,H.internal=!1),H.Broadphase_DYNAMIC_AABB_TREE)}get sortContacts(){return this.zpp_inner.sortcontacts}set sortContacts(e){this.zpp_inner.sortcontacts=e}get worldAngularDrag(){return this.zpp_inner.global_ang_drag}set worldAngularDrag(e){if(e!==e)throw new Error("Error: Space::worldAngularDrag cannot be NaN");this.zpp_inner.global_ang_drag=e}get worldLinearDrag(){return this.zpp_inner.global_lin_drag}set worldLinearDrag(e){if(e!==e)throw new Error("Error: Space::worldLinearDrag cannot be NaN");this.zpp_inner.global_lin_drag=e}get compounds(){return this.zpp_inner.wrap_compounds}get bodies(){return this.zpp_inner.wrap_bodies}get liveBodies(){return this.zpp_inner.wrap_live}get constraints(){return this.zpp_inner.wrap_constraints}get liveConstraints(){return this.zpp_inner.wrap_livecon}get world(){return We._wrap(this.zpp_inner.__static)}get arbiters(){if(this.zpp_inner.wrap_arbiters==null){let e=new Un;e.space=this.zpp_inner,this.zpp_inner.wrap_arbiters=e}return this.zpp_inner.wrap_arbiters}get listeners(){return this.zpp_inner.wrap_listeners}get timeStamp(){return this.zpp_inner.stamp}get elapsedTime(){return this.zpp_inner.time}step(e,t=10,n=10){if(e!==e)throw new Error("Error: deltaTime cannot be NaN");if(e<=0)throw new Error("Error: deltaTime must be strictly positive");if(t<=0)throw new Error("Error: must use atleast one velocity iteration");if(n<=0)throw new Error("Error: must use atleast one position iteration");this.zpp_inner.step(e,t,n)}clear(){if(this.zpp_inner.midstep)throw new Error("Error: Space::clear() cannot be called during space step()");this.zpp_inner.clear()}visitBodies(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitBodies");let t=me(),n=this.zpp_inner.wrap_bodies;n.zpp_inner.valmod();let s=t.phys.BodyIterator.get(n);for(;;){s.zpp_inner.zpp_inner.valmod();let r=s.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=a){s.zpp_next=t.phys.BodyIterator.zpp_pool,t.phys.BodyIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1,e(s.zpp_inner.at(s.zpp_i++))}let i=this.zpp_inner.wrap_compounds;i.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(i);for(;;){l.zpp_inner.zpp_inner.valmod();let r=l.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=a){l.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,l.zpp_inner.at(l.zpp_i++).visitBodies(e)}}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitConstraints");let t=me(),n=this.zpp_inner.wrap_constraints;n.zpp_inner.valmod();let s=t.constraint.ConstraintIterator.get(n);for(;;){s.zpp_inner.zpp_inner.valmod();let r=s.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=a){s.zpp_next=t.constraint.ConstraintIterator.zpp_pool,t.constraint.ConstraintIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1,e(s.zpp_inner.at(s.zpp_i++))}let i=this.zpp_inner.wrap_compounds;i.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(i);for(;;){l.zpp_inner.zpp_inner.valmod();let r=l.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=a){l.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,l.zpp_inner.at(l.zpp_i++).visitConstraints(e)}}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitCompounds");let t=me(),n=this.zpp_inner.wrap_compounds;n.zpp_inner.valmod();let s=t.phys.CompoundIterator.get(n);for(;;){s.zpp_inner.zpp_inner.valmod();let i=s.zpp_inner;i.zpp_inner.valmod(),i.zpp_inner.zip_length&&(i.zpp_inner.zip_length=!1,i.zpp_inner.user_length=i.zpp_inner.inner.length);let l=i.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=l){s.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1;let r=s.zpp_inner.at(s.zpp_i++);e(r),r.visitCompounds(e)}}interactionType(e,t){if(e==null||t==null)throw new Error("Error: Cannot evaluate interaction type for null shapes");let n=e.zpp_inner,s=t.zpp_inner;if((n.body!=null?n.body.outer:null)==null||(s.body!=null?s.body.outer:null)==null)throw new Error("Error: Cannot evaluate interaction type for shapes not part of a Body");let i=n.body,l=s.body;if(i.type==1&&l.type==1||i.outer==l.outer)return null;let r=!1,a=i.constraints.head;for(;a!=null;){let u=a.elt;if(u.ignore&&u.pair_exists(i.id,l.id)){r=!0;break}a=a.next}let o;if(r)o=!1;else{let u=n;for(;u!=null&&u.group==null;)u.ishape!=null?u=u.ishape.body:u.icompound!=null?u=u.icompound.compound:u=u.ibody.compound;let x=u==null?null:u.group,y;if(x==null)y=!1;else{let d=s;for(;d!=null&&d.group==null;)d.ishape!=null?d=d.ishape.body:d.icompound!=null?d=d.icompound.compound:d=d.ibody.compound;let _=d==null?null:d.group;if(_==null)y=!1;else{let f=!1;for(;x!=null&&_!=null;){if(x==_){f=x.ignore;break}x.depth<_.depth?_=_.group:x=x.group}y=f}}o=!y}if(!o)return null;let p=n.filter,c=s.filter,h=i.imass==0&&l.imass==0&&i.iinertia==0&&l.iinertia==0;return(n.sensorEnabled||s.sensorEnabled)&&(p.sensorMask&c.sensorGroup)!=0&&(c.sensorMask&p.sensorGroup)!=0?(H.InteractionType_SENSOR==null&&(H.internal=!0,H.InteractionType_SENSOR=new(me()).callbacks.InteractionType,H.internal=!1),H.InteractionType_SENSOR):(n.fluidEnabled||s.fluidEnabled)&&(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0&&!h?(H.InteractionType_FLUID==null&&(H.internal=!0,H.InteractionType_FLUID=new(me()).callbacks.InteractionType,H.internal=!1),H.InteractionType_FLUID):(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!h?(H.InteractionType_COLLISION==null&&(H.internal=!0,H.InteractionType_COLLISION=new(me()).callbacks.InteractionType,H.internal=!1),H.InteractionType_COLLISION):null}shapesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes under a null point :)");let s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,r=t==null?null:t.zpp_inner??t,a=this.zpp_inner.shapesUnderPoint(i,l,r,n);return s.weak&&e.dispose(),a}bodiesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects under a null point :)");let s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,r=t==null?null:t.zpp_inner??t,a=this.zpp_inner.bodiesUnderPoint(i,l,r,n);return s.weak&&e.dispose(),a}shapesInAABB(e,t=!1,n=!0,s,i){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null AABB :)");let l=e.zpp_inner;if(l._validate!=null&&l._validate(),l.maxx-l.minx==0||l.maxy-l.miny==0)throw new Error("Error: Cannot evaluate shapes in degenerate AABB :/");let r=s==null?null:s.zpp_inner??s;return this.zpp_inner.shapesInAABB(e,n,t,r,i)}bodiesInAABB(e,t=!1,n=!0,s,i){if(e==null)throw new Error("Error: Cannot evaluate objects in a null AABB :)");let l=e.zpp_inner;if(l._validate!=null&&l._validate(),l.maxx-l.minx==0||l.maxy-l.miny==0)throw new Error("Error: Cannot evaluate objects in degenerate AABB :/");let r=s==null?null:s.zpp_inner??s;return this.zpp_inner.bodiesInAABB(e,n,t,r,i)}shapesInCircle(e,t,n=!1,s,i){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let l=s==null?null:s.zpp_inner??s,r=this.zpp_inner.shapesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),r}bodiesInCircle(e,t,n=!1,s,i){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let l=s==null?null:s.zpp_inner??s,r=this.zpp_inner.bodiesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),r}shapesInShape(e,t=!1,n,s){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null shapes :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(i.type==1){let r=i.polygon.valid();if(H.ValidationResult_VALID==null&&(H.internal=!0,H.ValidationResult_VALID=new(me()).shape.ValidationResult,H.internal=!1),r!=H.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+r.toString())}let l=n==null?null:n.zpp_inner??n;return this.zpp_inner.shapesInShape(i,t,l,s)}bodiesInShape(e,t=!1,n,s){if(e==null)throw new Error("Error: Cannot evaluate bodies in a null shapes :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(i.type==1){let r=i.polygon.valid();if(H.ValidationResult_VALID==null&&(H.internal=!0,H.ValidationResult_VALID=new(me()).shape.ValidationResult,H.internal=!1),r!=H.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+r.toString())}let l=n==null?null:n.zpp_inner??n;return this.zpp_inner.bodiesInShape(i,t,l,s)}shapesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let s=me(),i=n??new s.shape.ShapeList,l=e.zpp_inner.wrap_shapes;l.zpp_inner.valmod();let r=s.shape.ShapeIterator.get(l);for(;;){r.zpp_inner.zpp_inner.valmod();let a=r.zpp_inner;a.zpp_inner.valmod(),a.zpp_inner.zip_length&&(a.zpp_inner.zip_length=!1,a.zpp_inner.user_length=a.zpp_inner.inner.length);let o=a.zpp_inner.user_length;if(r.zpp_critical=!0,r.zpp_i>=o){r.zpp_next=s.shape.ShapeIterator.zpp_pool,s.shape.ShapeIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let p=r.zpp_inner.at(r.zpp_i++);this.shapesInShape(p,!1,t,i)}return i}bodiesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let s=me(),i=n??new s.phys.BodyList,l=e.zpp_inner.wrap_shapes;l.zpp_inner.valmod();let r=s.shape.ShapeIterator.get(l);for(;;){r.zpp_inner.zpp_inner.valmod();let a=r.zpp_inner;a.zpp_inner.valmod(),a.zpp_inner.zip_length&&(a.zpp_inner.zip_length=!1,a.zpp_inner.user_length=a.zpp_inner.inner.length);let o=a.zpp_inner.user_length;if(r.zpp_critical=!0,r.zpp_i>=o){r.zpp_next=s.shape.ShapeIterator.zpp_pool,s.shape.ShapeIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let p=r.zpp_inner.at(r.zpp_i++);this.bodiesInShape(p,!1,t,i)}return i}convexCast(e,t,n=!1,s){if(e==null)throw new Error("Error: Cannot cast null shape :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexCast(i,t,s,n)}convexMultiCast(e,t,n=!1,s,i){if(e==null)throw new Error("Error: Cannot cast null shape :)");let l=e.zpp_inner;if((l.body!=null?l.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexMultiCast(l,t,s,n,i)}rayCast(e,t=!1,n){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayCast(e,t,n)}rayMultiCast(e,t=!1,n,s){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayMultiCast(e,t,n,s)}debugDraw(e,t=Pi.ALL){if(e==null)throw new Error("Error: drawer cannot be null for Space::debugDraw");let n=(t&Pi.SHAPES)!==0,s=(t&Pi.JOINTS)!==0,i=(t&Pi.CONTACTS)!==0,l=(t&Pi.AABB)!==0,r=(t&Pi.CENTER_OF_MASS)!==0,a=(t&Pi.VELOCITIES)!==0,o=4283417591,p=4287669422,c=4294948685,h=4289058471,u=4293874512,x=1157627903,y=4294961979,d=4291728344;if(this.visitBodies(_=>{let f=_.zpp_inner,z=f.type===2,k=f.type===1?p:z?o:c;if(n){let m=f.shapes.head;for(;m!=null;){let b=m.elt;if(b.type===0){let C=b.circle;b.zip_worldCOM&&b.validate_worldCOM();let v=b.worldCOMx,w=b.worldCOMy,O=C.radius,E=f.rot,M=v+Math.cos(E)*O,N=w+Math.sin(E)*O,Z={x:v,y:w},S={x:M,y:N};z?e.drawSolidCircle(Z,O,S,k):e.drawCircle(Z,O,k)}else if(b.type===1){let C=b.polygon;C.zip_gverts&&C.validate_gverts();let v=[],w=C.gverts.next;for(;w!=null;)v.push({x:w.x,y:w.y}),w=w.next;v.length>=3&&(z?e.drawSolidPolygon(v,k):e.drawPolygon(v,k))}m=m.next}}if(l&&!f.world){let m=f.aabb,b=m.minx,C=m.miny,v=m.maxx,w=m.maxy;e.drawSegment({x:b,y:C},{x:v,y:C},x),e.drawSegment({x:v,y:C},{x:v,y:w},x),e.drawSegment({x:v,y:w},{x:b,y:w},x),e.drawSegment({x:b,y:w},{x:b,y:C},x)}if(r&&!f.world&&(f.validate_worldCOM(),e.drawPoint({x:f.worldCOMx,y:f.worldCOMy},y)),a&&!f.world&&z){let m=f.posx,b=f.posy;e.drawSegment({x:m,y:b},{x:m+f.velx,y:b+f.vely},d)}}),s&&this.visitConstraints(_=>{if(!_.debugDraw)return;let f=_.zpp_inner,z=f.b1,P=f.b2,k=f.a1worldx??(z!=null?z.posx:0),m=f.a1worldy??(z!=null?z.posy:0),b=f.a2worldx??(P!=null?P.posx:0),C=f.a2worldy??(P!=null?P.posy:0);e.drawSegment({x:k,y:m},{x:b,y:C},h),e.drawPoint({x:k,y:m},h),e.drawPoint({x:b,y:C},h)}),i){let _=f=>{if(f==null)return;let z=f.head;for(;z!=null;){let P=z.elt;if(P!=null){let k=P.nx,m=P.ny,b=P.contacts?.next;for(;b!=null;){let C=b.px,v=b.py;e.drawPoint({x:C,y:v},u),e.drawSegment({x:C,y:v},{x:C+k*8,y:v+m*8},u),b=b.next}}z=z.next}};_(this.zpp_inner.c_arbiters_true),_(this.zpp_inner.c_arbiters_false)}}toString(){return`Space(bodies=${this.bodies.length})`}};var jn=class g{constructor(){if(!H.internal)throw new Error("Error: Cannot instantiate BodyType derp!")}static get STATIC(){return H.BodyType_STATIC==null&&(H.internal=!0,H.BodyType_STATIC=new g,H.internal=!1),H.BodyType_STATIC}static get DYNAMIC(){return H.BodyType_DYNAMIC==null&&(H.internal=!0,H.BodyType_DYNAMIC=new g,H.internal=!1),H.BodyType_DYNAMIC}static get KINEMATIC(){return H.BodyType_KINEMATIC==null&&(H.internal=!0,H.BodyType_KINEMATIC=new g,H.internal=!1),H.BodyType_KINEMATIC}toString(){return this===H.BodyType_STATIC?"STATIC":this===H.BodyType_DYNAMIC?"DYNAMIC":this===H.BodyType_KINEMATIC?"KINEMATIC":""}},Fo=me();Fo.phys.BodyType=jn;Gl();var qi=class g{constructor(){if(!H.internal)throw new Error("Error: Cannot instantiate MassMode derp!")}static get DEFAULT(){return H.MassMode_DEFAULT==null&&(H.internal=!0,H.MassMode_DEFAULT=new g,H.internal=!1),H.MassMode_DEFAULT}static get FIXED(){return H.MassMode_FIXED==null&&(H.internal=!0,H.MassMode_FIXED=new g,H.internal=!1),H.MassMode_FIXED}toString(){return this===H.MassMode_DEFAULT?"DEFAULT":this===H.MassMode_FIXED?"FIXED":""}},Do=me();Do.phys.MassMode=qi;var Ui=class g{constructor(){if(!H.internal)throw new Error("Error: Cannot instantiate InertiaMode derp!")}static get DEFAULT(){return H.InertiaMode_DEFAULT==null&&(H.internal=!0,H.InertiaMode_DEFAULT=new g,H.internal=!1),H.InertiaMode_DEFAULT}static get FIXED(){return H.InertiaMode_FIXED==null&&(H.internal=!0,H.InertiaMode_FIXED=new g,H.internal=!1),H.InertiaMode_FIXED}toString(){return this===H.InertiaMode_DEFAULT?"DEFAULT":this===H.InertiaMode_FIXED?"FIXED":""}},Ro=me();Ro.phys.InertiaMode=Ui;var oi=class g{constructor(){if(!H.internal)throw new Error("Error: Cannot instantiate GravMassMode derp!")}static get DEFAULT(){return H.GravMassMode_DEFAULT==null&&(H.internal=!0,H.GravMassMode_DEFAULT=new g,H.internal=!1),H.GravMassMode_DEFAULT}static get FIXED(){return H.GravMassMode_FIXED==null&&(H.internal=!0,H.GravMassMode_FIXED=new g,H.internal=!1),H.GravMassMode_FIXED}static get SCALED(){return H.GravMassMode_SCALED==null&&(H.internal=!0,H.GravMassMode_SCALED=new g,H.internal=!1),H.GravMassMode_SCALED}toString(){return this===H.GravMassMode_DEFAULT?"DEFAULT":this===H.GravMassMode_FIXED?"FIXED":this===H.GravMassMode_SCALED?"SCALED":""}},Go=me();Go.phys.GravMassMode=oi;var wi=class g extends zi{constructor(e=50,t,n,s){super();let i=me(),l=new Wn;if(this.zpp_inner_zn=l,this.zpp_inner=l,this.zpp_inner_i=l,l.outer=this,l.outer_zn=this,l.outer_i=this,this._inner=this,e!==l.radius){if(e!==e)throw new Error("Error: Circle::radius cannot be NaN");if(e<i.Config.epsilon)throw new Error("Error: Circle::radius ("+e+") must be > Config.epsilon");if(e>ri.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");l.radius=e,l.invalidate_radius()}if(t!=null){if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=t.zpp_inner;r._validate!=null&&r._validate(),l.localCOMx=r.x,r._validate!=null&&r._validate(),l.localCOMy=r.y,r.weak&&t.dispose()}else l.localCOMx=0,l.localCOMy=0;n==null?Ae.zpp_pool!=null?(l.material=Ae.zpp_pool,Ae.zpp_pool=l.material.next,l.material.next=null):l.material=new Ae:(l.immutable_midstep("Shape::material"),l.setMaterial(n.zpp_inner),l.material.wrapper()),s==null?ct.zpp_pool!=null?(l.filter=ct.zpp_pool,ct.zpp_pool=l.filter.next,l.filter.next=null):l.filter=new ct:(l.immutable_midstep("Shape::filter"),l.setFilter(s.zpp_inner),l.filter.wrapper()),l.insert_cbtype(fn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof g?e:e instanceof Wn?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner_zn=t,n.zpp_inner=t,n.zpp_inner_i=t,t.outer=n,t.outer_zn=n,t.outer_i=n,n._inner=n,n}):e.zpp_inner_zn?g._wrap(e.zpp_inner_zn):Ze(e,t=>{let n=Object.create(g.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i,n}):null}get radius(){return this.zpp_inner_zn.radius}set radius(e){let t=this.zpp_inner_zn,n=me();if(this.zpp_inner.immutable_midstep("Circle::radius"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modifiy radius of Circle contained in static object once added to space");if(e!==t.radius){if(e!==e)throw new Error("Error: Circle::radius cannot be NaN");if(e<n.Config.epsilon)throw new Error("Error: Circle::radius ("+e+") must be > Config.epsilon");if(e>ri.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}};Ul(g=>wi._wrap(g));var Jo=me();Jo.shape.Circle=wi;var vi=class g extends zi{constructor(e,t,n){super();let s=me();if(e==null)throw new Error("Error: localVerts cannot be null");let i=new Kn;if(this.zpp_inner_zn=i,this.zpp_inner=i,this.zpp_inner_i=i,i.outer=this,i.outer_zn=this,i.outer_i=this,this._inner=this,Array.isArray(e)){for(let l of e){if(l==null)throw new Error("Error: Array<Vec2> contains null objects");if(!(l instanceof Ie))throw new Error("Error: Array<Vec2> contains non Vec2 objects");if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.wrap_lverts==null&&i.getlverts();let r=l.zpp_inner;r._validate!=null&&r._validate();let a=r.x;r._validate!=null&&r._validate();let o=r.y,p=new Ie(a,o);i.wrap_lverts.push(p)}for(let l=e.length-1;l>=0;l--)e[l].zpp_inner?.weak&&(e[l].dispose(),e.splice(l,1))}else if(e instanceof s.geom.Vec2List){let l=e,r=l.iterator();for(;;){r.zpp_inner.zpp_inner.valmod();let c=r.zpp_inner.zpp_gl();if(r.zpp_critical=!0,r.zpp_i>=c){r.zpp_next=s.geom.Vec2Iterator.zpp_pool,s.geom.Vec2Iterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let h=r.zpp_inner.at(r.zpp_i++);if(h==null)throw new Error("Error: Vec2List contains null objects");if(h.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.wrap_lverts==null&&i.getlverts();let u=h.zpp_inner;u._validate!=null&&u._validate();let x=u.x;u._validate!=null&&u._validate();let y=u.y,d=new Ie(x,y);i.wrap_lverts.push(d)}l.zpp_inner._validate!=null&&l.zpp_inner._validate();let a=l.zpp_inner.inner,o=null,p=a.head;for(;p!=null;){let c=p.elt;c.outer?.zpp_inner?.weak?(p=a.erase(o),c.outer.zpp_inner.weak&&c.outer.dispose()):(o=p,p=p.next)}}else if(e instanceof s.geom.GeomPoly){let l=e.zpp_inner.vertices;if(l!=null){let r=l;do{i.wrap_lverts==null&&i.getlverts();let a=new Ie(r.x,r.y);i.wrap_lverts.push(a),r=r.next}while(r!==l)}}else throw new Error("Error: Invalid type for polygon object, should be Array<Vec2>, Vec2List, GeomPoly or for flash10+ flash.Vector<Vec2>");t==null?Ae.zpp_pool!=null?(i.material=Ae.zpp_pool,Ae.zpp_pool=i.material.next,i.material.next=null):i.material=new Ae:(i.immutable_midstep("Shape::material"),i.setMaterial(t.zpp_inner),i.material.wrapper()),n==null?ct.zpp_pool!=null?(i.filter=ct.zpp_pool,ct.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new ct:(i.immutable_midstep("Shape::filter"),i.setFilter(n.zpp_inner),i.filter.wrapper()),i.insert_cbtype(fn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof g?e:e instanceof Kn?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner_zn=t,n.zpp_inner=t,n.zpp_inner_i=t,t.outer=n,t.outer_zn=n,t.outer_i=n,n._inner=n,n}):e.zpp_inner_zn?g._wrap(e.zpp_inner_zn):Ze(e,t=>{let n=Object.create(g.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i,n}):null}static rect(e,t,n,s,i=!1){if(e!==e||t!==t||n!==n||s!==s)throw new Error("Error: Polygon.rect cannot accept NaN arguments");let l=new Ie(e,t);l.zpp_inner.weak=i;let r=new Ie(e+n,t);r.zpp_inner.weak=i;let a=new Ie(e+n,t+s);a.zpp_inner.weak=i;let o=new Ie(e,t+s);return o.zpp_inner.weak=i,[l,r,a,o]}static box(e,t=e,n=!1){if(e!==e||t!==t)throw new Error("Error: Polygon.box cannot accept NaN arguments");return g.rect(-e/2,-t/2,e,t,n)}static regular(e,t,n,s=0,i=!1){if(e!==e||t!==t||s!==s)throw new Error("Error: Polygon.regular cannot accept NaN arguments");let l=[],r=Math.PI*2/n;for(let a=0;a<n;a++){let o=a*r+s,p=Math.cos(o)*e,c=Math.sin(o)*t,h=new Ie(p,c);h.zpp_inner.weak=i,l.push(h)}return l}get localVerts(){return this.zpp_inner_zn.wrap_lverts==null&&this.zpp_inner_zn.getlverts(),this.zpp_inner_zn.wrap_lverts}get worldVerts(){return this.zpp_inner_zn.wrap_gverts==null&&this.zpp_inner_zn.getgverts(),this.zpp_inner_zn.wrap_gverts}get edges(){return this.zpp_inner_zn.wrap_edges==null&&this.zpp_inner_zn.getedges(),this.zpp_inner_zn.wrap_edges}validity(){return this.zpp_inner_zn.valid()}};Wl(g=>vi._wrap(g));var qo=me();qo.shape.Polygon=vi;var Wi=class g{get _inner(){return this}constructor(e=0,t=1,n=2,s=1,i=.001){let l;if(Ae.zpp_pool==null?l=new Ae:(l=Ae.zpp_pool,Ae.zpp_pool=l.next,l.next=null),this.zpp_inner=l,l.outer=this,e!==l.elasticity){if(e!==e)throw new Error("Error: Material::elasticity cannot be NaN");l.elasticity=e,l.invalidate(Ae.WAKE|Ae.ARBITERS)}if(t!==l.dynamicFriction){if(t!==t)throw new Error("Error: Material::dynamicFriction cannot be NaN");if(t<0)throw new Error("Error: Material::dynamicFriction cannot be negative");l.dynamicFriction=t,l.invalidate(Ae.WAKE|Ae.ANGDRAG|Ae.ARBITERS)}if(n!==l.staticFriction){if(n!==n)throw new Error("Error: Material::staticFriction cannot be NaN");if(n<0)throw new Error("Error: Material::staticFriction cannot be negative");l.staticFriction=n,l.invalidate(Ae.WAKE|Ae.ARBITERS)}if(s!==l.density*1e3){if(s!==s)throw new Error("Error: Material::density cannot be NaN");if(s<0)throw new Error("Error: Material::density must be positive");l.density=s/1e3,l.invalidate(Ae.WAKE|Ae.PROPS)}if(i!==l.rollingFriction){if(i!==i)throw new Error("Error: Material::rollingFriction cannot be NaN");if(i<0)throw new Error("Error: Material::rollingFriction cannot be negative");l.rollingFriction=i,l.invalidate(Ae.WAKE|Ae.ARBITERS)}}static _wrap(e){return e instanceof g?e:e?e instanceof Ae?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?g._wrap(e.zpp_inner):null:null}get elasticity(){return this.zpp_inner.elasticity}set elasticity(e){if(e!==this.zpp_inner.elasticity){if(e!==e)throw new Error("Error: Material::elasticity cannot be NaN");this.zpp_inner.elasticity=e,this.zpp_inner.invalidate(Ae.WAKE|Ae.ARBITERS)}}get dynamicFriction(){return this.zpp_inner.dynamicFriction}set dynamicFriction(e){if(e!==this.zpp_inner.dynamicFriction){if(e!==e)throw new Error("Error: Material::dynamicFriction cannot be NaN");if(e<0)throw new Error("Error: Material::dynamicFriction cannot be negative");this.zpp_inner.dynamicFriction=e,this.zpp_inner.invalidate(Ae.WAKE|Ae.ANGDRAG|Ae.ARBITERS)}}get staticFriction(){return this.zpp_inner.staticFriction}set staticFriction(e){if(e!==this.zpp_inner.staticFriction){if(e!==e)throw new Error("Error: Material::staticFriction cannot be NaN");if(e<0)throw new Error("Error: Material::staticFriction cannot be negative");this.zpp_inner.staticFriction=e,this.zpp_inner.invalidate(Ae.WAKE|Ae.ARBITERS)}}get density(){return this.zpp_inner.density*1e3}set density(e){if(e!==this.zpp_inner.density*1e3){if(e!==e)throw new Error("Error: Material::density cannot be NaN");if(e<0)throw new Error("Error: Material::density must be positive");this.zpp_inner.density=e/1e3,this.zpp_inner.invalidate(Ae.WAKE|Ae.PROPS)}}get rollingFriction(){return this.zpp_inner.rollingFriction}set rollingFriction(e){if(e!==this.zpp_inner.rollingFriction){if(e!==e)throw new Error("Error: Material::rollingFriction cannot be NaN");if(e<0)throw new Error("Error: Material::rollingFriction cannot be negative");this.zpp_inner.rollingFriction=e,this.zpp_inner.invalidate(Ae.WAKE|Ae.ARBITERS)}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}copy(){let e=new g(this.zpp_inner.elasticity,this.zpp_inner.dynamicFriction,this.zpp_inner.staticFriction,this.zpp_inner.density*1e3,this.zpp_inner.rollingFriction);return this.zpp_inner.userData!=null&&(e.zpp_inner.userData={...this.zpp_inner.userData}),e}toString(){return"{ elasticity: "+this.zpp_inner.elasticity+" dynamicFriction: "+this.zpp_inner.dynamicFriction+" staticFriction: "+this.zpp_inner.staticFriction+" density: "+this.zpp_inner.density*1e3+" rollingFriction: "+this.zpp_inner.rollingFriction+" }"}static wood(){return new g(.4,.2,.38,.7,.005)}static steel(){return new g(.2,.57,.74,7.8,.001)}static ice(){return new g(.3,.03,.1,.9,1e-4)}static rubber(){return new g(.8,1,1.4,1.5,.01)}static glass(){return new g(.4,.4,.94,2.6,.002)}static sand(){return new g(-1,.45,.6,1.6,16)}};Ae._wrapFn=g=>Ze(g,e=>{let t=Object.create(Wi.prototype);return t.zpp_inner=e,e.outer=t,t});var Ki=class g{get _inner(){return this}constructor(e=1,t=-1,n=1,s=-1,i=1,l=-1){let r;ct.zpp_pool==null?r=new ct:(r=ct.zpp_pool,ct.zpp_pool=r.next,r.next=null),this.zpp_inner=r,r.outer=this,r.collisionGroup!=e&&(r.collisionGroup=e,r.invalidate()),r.collisionMask!=t&&(r.collisionMask=t,r.invalidate()),r.sensorGroup!=n&&(r.sensorGroup=n,r.invalidate()),r.sensorMask!=s&&(r.sensorMask=s,r.invalidate()),r.fluidGroup!=i&&(r.fluidGroup=i,r.invalidate()),r.fluidMask!=l&&(r.fluidMask=l,r.invalidate())}static _wrap(e){return e instanceof g?e:e?e instanceof ct?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?g._wrap(e.zpp_inner):null:null}get collisionGroup(){return this.zpp_inner.collisionGroup}set collisionGroup(e){this.zpp_inner.collisionGroup!=e&&(this.zpp_inner.collisionGroup=e,this.zpp_inner.invalidate())}get collisionMask(){return this.zpp_inner.collisionMask}set collisionMask(e){this.zpp_inner.collisionMask!=e&&(this.zpp_inner.collisionMask=e,this.zpp_inner.invalidate())}get sensorGroup(){return this.zpp_inner.sensorGroup}set sensorGroup(e){this.zpp_inner.sensorGroup!=e&&(this.zpp_inner.sensorGroup=e,this.zpp_inner.invalidate())}get sensorMask(){return this.zpp_inner.sensorMask}set sensorMask(e){this.zpp_inner.sensorMask!=e&&(this.zpp_inner.sensorMask=e,this.zpp_inner.invalidate())}get fluidGroup(){return this.zpp_inner.fluidGroup}set fluidGroup(e){this.zpp_inner.fluidGroup!=e&&(this.zpp_inner.fluidGroup=e,this.zpp_inner.invalidate())}get fluidMask(){return this.zpp_inner.fluidMask}set fluidMask(e){this.zpp_inner.fluidMask!=e&&(this.zpp_inner.fluidMask=e,this.zpp_inner.invalidate())}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get shapes(){if(this.zpp_inner.wrap_shapes==null){let e=me();this.zpp_inner.wrap_shapes=e.zpp_nape.util.ZPP_ShapeList.get(this.zpp_inner.shapes,!0)}return this.zpp_inner.wrap_shapes}shouldCollide(e){if(e==null)throw new Error("Error: filter argument cannot be null for shouldCollide");return this.zpp_inner.shouldCollide(e.zpp_inner)}shouldSense(e){if(e==null)throw new Error("Error: filter argument cannot be null for shouldSense");return this.zpp_inner.shouldSense(e.zpp_inner)}shouldFlow(e){if(e==null)throw new Error("Error: filter argument cannot be null for shouldFlow");return this.zpp_inner.shouldFlow(e.zpp_inner)}copy(){return new g(this.zpp_inner.collisionGroup,this.zpp_inner.collisionMask,this.zpp_inner.sensorGroup,this.zpp_inner.sensorMask,this.zpp_inner.fluidGroup,this.zpp_inner.fluidMask)}toString(){let e=(t,n)=>{let s="",i="0123456789ABCDEF",l=t;do s=i.charAt(l&15)+s,l>>>=4;while(l>0);for(;s.length<n;)s="0"+s;return s};return"{ collision: "+e(this.zpp_inner.collisionGroup,8)+"~"+e(this.zpp_inner.collisionMask,8)+" sensor: "+e(this.zpp_inner.sensorGroup,8)+"~"+e(this.zpp_inner.sensorMask,8)+" fluid: "+e(this.zpp_inner.fluidGroup,8)+"~"+e(this.zpp_inner.fluidMask,8)+" }"}};ct._wrapFn=g=>Ze(g,e=>{let t=Object.create(Ki.prototype);return t.zpp_inner=e,e.outer=t,t});var gi=class g{constructor(){if(!H.internal)throw new Error("Error: Cannot instantiate Broadphase derp!")}static get DYNAMIC_AABB_TREE(){return H.Broadphase_DYNAMIC_AABB_TREE==null&&(H.internal=!0,H.Broadphase_DYNAMIC_AABB_TREE=new g,H.internal=!1),H.Broadphase_DYNAMIC_AABB_TREE}static get SWEEP_AND_PRUNE(){return H.Broadphase_SWEEP_AND_PRUNE==null&&(H.internal=!0,H.Broadphase_SWEEP_AND_PRUNE=new g,H.internal=!1),H.Broadphase_SWEEP_AND_PRUNE}toString(){return this===H.Broadphase_DYNAMIC_AABB_TREE?"DYNAMIC_AABB_TREE":this===H.Broadphase_SWEEP_AND_PRUNE?"SWEEP_AND_PRUNE":""}};var Yi=class Yi{constructor(){this.debugDraw=!0;this._inner=this}static _wrap(e){return e==null?null:e instanceof Yi?e:e.zpp_inner?.outer instanceof Yi?e.zpp_inner.outer:Ze(e,t=>{let n=Object.create(Yi.prototype);return n.zpp_inner=t.zpp_inner??t,n._inner=t,n.zpp_inner.outer=n,n.debugDraw=t.debugDraw??!0,n})}get space(){return this.zpp_inner.space==null?null:this.zpp_inner.space.outer}set space(e){if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");if((this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=e)if(this.zpp_inner.component!=null&&(this.zpp_inner.component.woken=!1),this.zpp_inner.clearcache(),this.zpp_inner.space!=null&&this.zpp_inner.space.wrap_constraints.remove(this),e!=null){let s=(e._inner?.zpp_inner??e.zpp_inner).wrap_constraints;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}else this.zpp_inner.space=null}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(e){let t=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(t!=e&&(t?.zpp_inner.wrap_constraints.remove(this),e!=null)){let s=e.zpp_inner.wrap_constraints;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}}get active(){return this.zpp_inner.active}set active(e){this.zpp_inner.active!=e&&(this.zpp_inner.component!=null&&(this.zpp_inner.component.woken=!1),this.zpp_inner.clearcache(),e?(this.zpp_inner.active=e,this.zpp_inner.activate(),this.zpp_inner.space!=null&&(this.zpp_inner.component!=null&&(this.zpp_inner.component.sleeping=!0),this.zpp_inner.space.wake_constraint(this.zpp_inner,!0))):(this.zpp_inner.space!=null&&(this.zpp_inner.wake(),this.zpp_inner.space.live_constraints.remove(this.zpp_inner)),this.zpp_inner.active=e,this.zpp_inner.deactivate()))}get ignore(){return this.zpp_inner.ignore}set ignore(e){this.zpp_inner.ignore!=e&&(this.zpp_inner.ignore=e,this.zpp_inner.wake())}get stiff(){return this.zpp_inner.stiff}set stiff(e){this.zpp_inner.stiff!=e&&(this.zpp_inner.stiff=e,this.zpp_inner.wake())}get frequency(){return this.zpp_inner.frequency}set frequency(e){if(e!==e)throw new Error("Error: Constraint::Frequency cannot be NaN");if(e<=0)throw new Error("Error: Constraint::Frequency must be >0");this.zpp_inner.frequency!=e&&(this.zpp_inner.frequency=e,this.zpp_inner.stiff||this.zpp_inner.wake())}get damping(){return this.zpp_inner.damping}set damping(e){if(e!==e)throw new Error("Error: Constraint::Damping cannot be Nan");if(e<0)throw new Error("Error: Constraint::Damping must be >=0");this.zpp_inner.damping!=e&&(this.zpp_inner.damping=e,this.zpp_inner.stiff||this.zpp_inner.wake())}get maxForce(){return this.zpp_inner.maxForce}set maxForce(e){if(e!==e)throw new Error("Error: Constraint::maxForce cannot be NaN");if(e<0)throw new Error("Error: Constraint::maxForce must be >=0");this.zpp_inner.maxForce!=e&&(this.zpp_inner.maxForce=e,this.zpp_inner.wake())}get maxError(){return this.zpp_inner.maxError}set maxError(e){if(e!==e)throw new Error("Error: Constraint::maxError cannot be NaN");if(e<0)throw new Error("Error: Constraint::maxError must be >=0");this.zpp_inner.maxError!=e&&(this.zpp_inner.maxError=e,this.zpp_inner.wake())}get breakUnderForce(){return this.zpp_inner.breakUnderForce}set breakUnderForce(e){this.zpp_inner.breakUnderForce!=e&&(this.zpp_inner.breakUnderForce=e,this.zpp_inner.wake())}get breakUnderError(){return this.zpp_inner.breakUnderError}set breakUnderError(e){this.zpp_inner.breakUnderError!=e&&(this.zpp_inner.breakUnderError=e,this.zpp_inner.wake())}get removeOnBreak(){return this.zpp_inner.removeOnBreak}set removeOnBreak(e){this.zpp_inner.removeOnBreak=e}get isSleeping(){if(this.zpp_inner.space==null||!this.zpp_inner.active)throw new Error("Error: isSleeping only makes sense if constraint is active and inside a space");return this.zpp_inner.component.sleeping}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get cbTypes(){return this.zpp_inner.wrap_cbTypes==null&&this.zpp_inner.setupcbTypes(),this.zpp_inner.wrap_cbTypes}impulse(){return null}bodyImpulse(e){return null}visitBodies(e){}copy(){return Yi._wrap(this.zpp_inner.copy())}toString(){return"{Constraint}"}};Yi.zpp_internalAlloc=!1;var tn=Yi;function Xl(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Hl(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.y}function zl(g){g.zpp_inner.weak&&g.dispose()}var Xi=class g extends tn{constructor(e,t,n,s){super();let i=new xi;if(this.zpp_inner=i,i.outer=this,i.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(i.a1localx=Xl(n),i.a1localy=Hl(n),zl(n),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::anchor2 cannot be null");i.a2localx=Xl(s),i.a2localy=Hl(s),zl(s)}static _wrap(e){return e==null?null:e instanceof g?e:e.zpp_inner?.outer instanceof g?e.zpp_inner.outer:e instanceof xi?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:We._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:We._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),zl(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),zl(e)}impulse(){let e=me(),t=new e.geom.MatMN(2,1);return t.zpp_inner.x[0]=this.zpp_inner.jAccx,t.zpp_inner.x[1]=this.zpp_inner.jAccy,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};xi._wrapFn=g=>Ze(g,e=>{let t=Object.create(Xi.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Ql(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.x}function $l(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Pl(g){g.zpp_inner.weak&&g.dispose()}var Hi=class g extends tn{constructor(e,t,n,s,i,l){super();let r=new ci;if(this.zpp_inner=r,r.outer=this,r.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");let a=Ql(n),o=$l(n);if(r.a1localx=a,r.a1localy=o,Pl(n),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::anchor2 cannot be null");let p=Ql(s),c=$l(s);if(r.a2localx=p,r.a2localy=c,Pl(s),this.zpp_inner.immutable_midstep("DistanceJoint::jointMin"),i!==i)throw new Error("Error: DistanceJoint::jointMin cannot be NaN");if(i<0)throw new Error("Error: DistanceJoint::jointMin must be >= 0");if(r.jointMin!=i&&(r.jointMin=i,r.wake()),this.zpp_inner.immutable_midstep("DistanceJoint::jointMax"),l!==l)throw new Error("Error: DistanceJoint::jointMax cannot be NaN");if(l<0)throw new Error("Error: DistanceJoint::jointMax must be >= 0");r.jointMax!=l&&(r.jointMax=l,r.wake())}static _wrap(e){return e==null?null:e instanceof g?e:e.zpp_inner?.outer instanceof g?e.zpp_inner.outer:e instanceof ci?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:We._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:We._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),Pl(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),Pl(e)}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("DistanceJoint::jointMin"),e!==e)throw new Error("Error: DistanceJoint::jointMin cannot be NaN");if(e<0)throw new Error("Error: DistanceJoint::jointMin must be >= 0");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("DistanceJoint::jointMax"),e!==e)throw new Error("Error: DistanceJoint::jointMax cannot be NaN");if(e<0)throw new Error("Error: DistanceJoint::jointMax must be >= 0");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}isSlack(){if(this.zpp_inner.b1==null||this.zpp_inner.b2==null)throw new Error("Error: Cannot compute slack for DistanceJoint if either body is null.");return this.zpp_inner.is_slack()}impulse(){let e=me(),t=new e.geom.MatMN(1,1);if(0>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return t.zpp_inner.x[0*t.zpp_inner.n]=this.zpp_inner.jAcc,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};ci._wrapFn=g=>Ze(g,e=>{let t=Object.create(Hi.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var Qi=class g extends tn{constructor(e,t,n,s,i=1){super();let l=new Je;if(this.zpp_inner=l,l.outer=this,l.outer_zn=this,this._setBody1(e),this._setBody2(t),this.zpp_inner.immutable_midstep("AngleJoint::jointMin"),n!==n)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(l.jointMin!=n&&(l.jointMin=n,l.wake()),this.zpp_inner.immutable_midstep("AngleJoint::jointMax"),s!==s)throw new Error("Error: AngleJoint::jointMax cannot be NaN");if(l.jointMax!=s&&(l.jointMax=s,l.wake()),this.zpp_inner.immutable_midstep("AngleJoint::ratio"),i!==i)throw new Error("Error: AngleJoint::ratio cannot be NaN");l.ratio!=i&&(l.ratio=i,l.wake())}static _wrap(e){return e==null?null:e instanceof g?e:e.zpp_inner?.outer instanceof g?e.zpp_inner.outer:e instanceof Je?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:We._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:We._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("AngleJoint::jointMin"),e!==e)throw new Error("Error: AngleJoint::jointMin cannot be NaN");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("AngleJoint::jointMax"),e!==e)throw new Error("Error: AngleJoint::jointMax cannot be NaN");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}get ratio(){return this.zpp_inner.ratio}set ratio(e){if(this.zpp_inner.immutable_midstep("AngleJoint::ratio"),e!==e)throw new Error("Error: AngleJoint::ratio cannot be NaN");this.zpp_inner.ratio!=e&&(this.zpp_inner.ratio=e,this.zpp_inner.wake())}isSlack(){if(this.zpp_inner.b1==null||this.zpp_inner.b2==null)throw new Error("Error: Cannot compute slack for AngleJoint if either body is null.");return this.zpp_inner.is_slack()}impulse(){let e=me(),t=new e.geom.MatMN(1,1);if(0>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return t.zpp_inner.x[0*t.zpp_inner.n]=this.zpp_inner.jAcc,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};Je._wrapFn=g=>Ze(g,e=>{let t=Object.create(Qi.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var $i=class g extends tn{constructor(e,t,n=0,s=1){super();let i=new ui;if(this.zpp_inner=i,i.outer=this,i.outer_zn=this,this._setBody1(e),this._setBody2(t),this.zpp_inner.immutable_midstep("MotorJoint::rate"),n!==n)throw new Error("Error: MotorJoint::rate cannot be NaN");if(i.rate!=n&&(i.rate=n,i.wake()),this.zpp_inner.immutable_midstep("MotorJoint::ratio"),s!==s)throw new Error("Error: MotorJoint::ratio cannot be NaN");i.ratio!=s&&(i.ratio=s,i.wake())}static _wrap(e){return e==null?null:e instanceof g?e:e.zpp_inner?.outer instanceof g?e.zpp_inner.outer:e instanceof ui?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:We._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:We._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get rate(){return this.zpp_inner.rate}set rate(e){if(this.zpp_inner.immutable_midstep("MotorJoint::rate"),e!==e)throw new Error("Error: MotorJoint::rate cannot be NaN");this.zpp_inner.rate!=e&&(this.zpp_inner.rate=e,this.zpp_inner.wake())}get ratio(){return this.zpp_inner.ratio}set ratio(e){if(this.zpp_inner.immutable_midstep("MotorJoint::ratio"),e!==e)throw new Error("Error: MotorJoint::ratio cannot be NaN");this.zpp_inner.ratio!=e&&(this.zpp_inner.ratio=e,this.zpp_inner.wake())}impulse(){let e=me(),t=new e.geom.MatMN(1,1);if(0>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return t.zpp_inner.x[0*t.zpp_inner.n]=this.zpp_inner.jAcc,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};ui._wrapFn=g=>Ze(g,e=>{let t=Object.create($i.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Il(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Bl(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.y}function vs(g){g.zpp_inner.weak&&g.dispose()}var es=class g extends tn{constructor(e,t,n,s,i,l,r){super();let a=new hi;if(this.zpp_inner=a,a.outer=this,a.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(a.a1localx=Il(n),a.a1localy=Bl(n),vs(n),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::anchor2 cannot be null");if(a.a2localx=Il(s),a.a2localy=Bl(s),vs(s),i?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i==null)throw new Error("Error: Constraint::direction cannot be null");if(a.nlocalx=Il(i),a.nlocaly=Bl(i),a.zip_n=!0,vs(i),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),l!==l)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(a.jointMin!=l&&(a.jointMin=l,a.wake()),this.zpp_inner.immutable_midstep("LineJoint::jointMax"),r!==r)throw new Error("Error: AngleJoint::jointMax cannot be NaN");a.jointMax!=r&&(a.jointMax=r,a.wake())}static _wrap(e){return e==null?null:e instanceof g?e:e.zpp_inner?.outer instanceof g?e.zpp_inner.outer:e instanceof hi?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:We._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:We._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),vs(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),vs(e)}get direction(){return this.zpp_inner.wrap_n==null&&this.zpp_inner.setup_n(),this.zpp_inner.wrap_n}set direction(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::direction cannot be null");this.zpp_inner.wrap_n==null&&this.zpp_inner.setup_n(),this.zpp_inner.wrap_n.set(e),vs(e)}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("LineJoint::jointMin"),e!==e)throw new Error("Error: AngleJoint::jointMin cannot be NaN");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("LineJoint::jointMax"),e!==e)throw new Error("Error: AngleJoint::jointMax cannot be NaN");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}impulse(){let e=me(),t=new e.geom.MatMN(2,1);return t.zpp_inner.x[0]=this.zpp_inner.jAccx,t.zpp_inner.x[1]=this.zpp_inner.jAccy,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};hi._wrapFn=g=>Ze(g,e=>{let t=Object.create(es.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var Ks=class g{get _inner(){return this}constructor(e,t){if(e<=0||t<=0)throw new Error("Error: MatMN::dimensions cannot be < 1");this.zpp_inner=new Bi(e,t),this.zpp_inner.outer=this}static _wrap(e){return e instanceof g?e:e?e instanceof Bi?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?g._wrap(e.zpp_inner):null:null}get rows(){return this.zpp_inner.m}get cols(){return this.zpp_inner.n}x(e,t){if(e<0||t<0||e>=this.zpp_inner.m||t>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return this.zpp_inner.x[e*this.zpp_inner.n+t]}setx(e,t,n){if(e<0||t<0||e>=this.zpp_inner.m||t>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return this.zpp_inner.x[e*this.zpp_inner.n+t]=n}equals(e,t=0){if(e==null||this.zpp_inner.m!==e.zpp_inner.m||this.zpp_inner.n!==e.zpp_inner.n)return!1;for(let n=0;n<this.zpp_inner.x.length;n++){let s=this.zpp_inner.x[n]-e.zpp_inner.x[n];if((s<0?-s:s)>t)return!1}return!0}clone(){let e=new g(this.zpp_inner.m,this.zpp_inner.n);for(let t=0;t<this.zpp_inner.x.length;t++)e.zpp_inner.x[t]=this.zpp_inner.x[t];return e}toString(){let e="{ ",t=!0;for(let n=0;n<this.zpp_inner.m;n++){t||(e+="; "),t=!1;for(let s=0;s<this.zpp_inner.n;s++){if(n<0||s<0||n>=this.zpp_inner.m||s>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");e+=this.zpp_inner.x[n*this.zpp_inner.n+s]+" "}}return e+="}",e}transpose(){let e=new g(this.zpp_inner.n,this.zpp_inner.m);for(let t=0;t<this.zpp_inner.m;t++)for(let n=0;n<this.zpp_inner.n;n++)e.zpp_inner.x[n*e.zpp_inner.n+t]=this.zpp_inner.x[t*this.zpp_inner.n+n];return e}mul(e){let t=e;if(this.zpp_inner.n!==t.zpp_inner.m)throw new Error("Error: Matrix dimensions aren't compatible");let n=new g(this.zpp_inner.m,t.zpp_inner.n);for(let s=0;s<this.zpp_inner.m;s++)for(let i=0;i<t.zpp_inner.n;i++){let l=0;for(let r=0;r<this.zpp_inner.n;r++)l+=this.zpp_inner.x[s*this.zpp_inner.n+r]*t.zpp_inner.x[r*t.zpp_inner.n+i];n.zpp_inner.x[s*n.zpp_inner.n+i]=l}return n}},Uo=me();Uo.geom.MatMN=Ks;function Ys(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Xs(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Hs(g){g.zpp_inner.weak&&g.dispose()}var ts=class g extends tn{constructor(e,t,n,s,i,l,r,a,o,p,c=1){super();let h=new di;if(this.zpp_inner=h,h.outer=this,h.outer_zn=this,this._setBody1(e),this._setBody2(t),this._setBody3(n),this._setBody4(s),this._setAnchorInit(i,"anchor1",(u,x)=>{h.a1localx=u,h.a1localy=x}),this._setAnchorInit(l,"anchor2",(u,x)=>{h.a2localx=u,h.a2localy=x}),this._setAnchorInit(r,"anchor3",(u,x)=>{h.a3localx=u,h.a3localy=x}),this._setAnchorInit(a,"anchor4",(u,x)=>{h.a4localx=u,h.a4localy=x}),h.immutable_midstep("PulleyJoint::jointMin"),o!==o)throw new Error("Error: PulleyJoint::jointMin cannot be NaN");if(o<0)throw new Error("Error: PulleyJoint::jointMin must be >= 0");if(h.jointMin!=o&&(h.jointMin=o,h.wake()),h.immutable_midstep("PulleyJoint::jointMax"),p!==p)throw new Error("Error: PulleyJoint::jointMax cannot be NaN");if(p<0)throw new Error("Error: PulleyJoint::jointMax must be >= 0");if(h.jointMax!=p&&(h.jointMax=p,h.wake()),h.immutable_midstep("PulleyJoint::ratio"),c!==c)throw new Error("Error: PulleyJoint::ratio cannot be NaN");h.ratio!=c&&(h.ratio=c,h.wake())}_setAnchorInit(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::"+t+" cannot be null");n(Ys(e),Xs(e)),Hs(e)}static _wrap(e){return e==null?null:e instanceof g?e:e.zpp_inner?.outer instanceof g?e.zpp_inner.outer:e instanceof di?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:We._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}get body2(){return this.zpp_inner.b2==null?null:We._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}get body3(){return this.zpp_inner.b3==null?null:We._wrap(this.zpp_inner.b3)}set body3(e){this._setBody3(e)}get body4(){return this.zpp_inner.b4==null?null:We._wrap(this.zpp_inner.b4)}set body4(e){this._setBody4(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b3!=this.zpp_inner.b1&&this.zpp_inner.b4!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&this.zpp_inner.b3!=t&&this.zpp_inner.b4!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b3!=this.zpp_inner.b2&&this.zpp_inner.b4!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&this.zpp_inner.b3!=t&&this.zpp_inner.b4!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}_setBody3(e){this.zpp_inner.immutable_midstep("Constraint::body3");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b3&&(this.zpp_inner.b3!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b3&&this.zpp_inner.b2!=this.zpp_inner.b3&&this.zpp_inner.b4!=this.zpp_inner.b3&&this.zpp_inner.b3.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b3.wake()),this.zpp_inner.b3=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&this.zpp_inner.b2!=t&&this.zpp_inner.b4!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}_setBody4(e){this.zpp_inner.immutable_midstep("Constraint::body4");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b4&&(this.zpp_inner.b4!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b4&&this.zpp_inner.b2!=this.zpp_inner.b4&&this.zpp_inner.b3!=this.zpp_inner.b4&&this.zpp_inner.b4.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b4.wake()),this.zpp_inner.b4=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&this.zpp_inner.b2!=t&&this.zpp_inner.b3!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),Ys(e),Xs(e),this.zpp_inner.wrap_a1.set(e),Hs(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),Ys(e),Xs(e),this.zpp_inner.wrap_a2.set(e),Hs(e)}get anchor3(){return this.zpp_inner.wrap_a3==null&&this.zpp_inner.setup_a3(),this.zpp_inner.wrap_a3}set anchor3(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor3 cannot be null");this.zpp_inner.wrap_a3==null&&this.zpp_inner.setup_a3(),Ys(e),Xs(e),this.zpp_inner.wrap_a3.set(e),Hs(e)}get anchor4(){return this.zpp_inner.wrap_a4==null&&this.zpp_inner.setup_a4(),this.zpp_inner.wrap_a4}set anchor4(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor4 cannot be null");this.zpp_inner.wrap_a4==null&&this.zpp_inner.setup_a4(),Ys(e),Xs(e),this.zpp_inner.wrap_a4.set(e),Hs(e)}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("PulleyJoint::jointMin"),e!==e)throw new Error("Error: PulleyJoint::jointMin cannot be NaN");if(e<0)throw new Error("Error: PulleyJoint::jointMin must be >= 0");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("PulleyJoint::jointMax"),e!==e)throw new Error("Error: PulleyJoint::jointMax cannot be NaN");if(e<0)throw new Error("Error: PulleyJoint::jointMax must be >= 0");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}get ratio(){return this.zpp_inner.ratio}set ratio(e){if(this.zpp_inner.immutable_midstep("PulleyJoint::ratio"),e!==e)throw new Error("Error: PulleyJoint::ratio cannot be NaN");this.zpp_inner.ratio!=e&&(this.zpp_inner.ratio=e,this.zpp_inner.wake())}isSlack(){if(this.zpp_inner.b1==null||this.zpp_inner.b2==null||this.zpp_inner.b3==null||this.zpp_inner.b4==null)throw new Error("Error: Cannot compute slack for PulleyJoint if either body is null.");return this.zpp_inner.slack}impulse(){let e=new Ks(1,1);if(0>=e.zpp_inner.m||0>=e.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return e.zpp_inner.x[0*e.zpp_inner.n]=this.zpp_inner.jAcc,e}bodyImpulse(e){if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let t=this.zpp_inner.b1?.outer??null,n=this.zpp_inner.b2?.outer??null,s=this.zpp_inner.b3?.outer??null,i=this.zpp_inner.b4?.outer??null;if(e!=t&&e!=n&&e!=s&&e!=i)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):li.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1?.outer??null,n=this.zpp_inner.b2?.outer??null,s=this.zpp_inner.b3?.outer??null,i=this.zpp_inner.b4?.outer??null;t!=null&&e(t),n!=null&&n!=t&&e(n),s!=null&&s!=t&&s!=n&&e(s),i!=null&&i!=t&&i!=n&&i!=s&&e(i)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};di._wrapFn=g=>Ze(g,e=>{let t=Object.create(ts.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function eo(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.x}function to(g){if(g.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=g.zpp_inner;return e._validate!=null&&e._validate(),e.y}function wl(g){g.zpp_inner.weak&&g.dispose()}var ns=class g extends tn{constructor(e,t,n,s,i=0){super();let l=new _i;if(this.zpp_inner=l,l.outer=this,l.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(l.a1localx=eo(n),l.a1localy=to(n),wl(n),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::anchor2 cannot be null");if(l.a2localx=eo(s),l.a2localy=to(s),wl(s),this.zpp_inner.immutable_midstep("WeldJoint::phase"),i!==i)throw new Error("Error: WeldJoint::phase cannot be NaN");l.phase!=i&&(l.phase=i,l.wake())}static _wrap(e){return e==null?null:e instanceof g?e:e.zpp_inner?.outer instanceof g?e.zpp_inner.outer:e instanceof _i?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:We._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:We._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),wl(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),wl(e)}get phase(){return this.zpp_inner.phase}set phase(e){if(this.zpp_inner.immutable_midstep("WeldJoint::phase"),e!==e)throw new Error("Error: WeldJoint::phase cannot be NaN");this.zpp_inner.phase!=e&&(this.zpp_inner.phase=e,this.zpp_inner.wake())}impulse(){let e=me(),t=new e.geom.MatMN(3,1);return t.zpp_inner.x[0]=this.zpp_inner.jAccx,t.zpp_inner.x[1]=this.zpp_inner.jAccy,t.zpp_inner.x[2]=this.zpp_inner.jAccz,t}bodyImpulse(e){let t=me();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};_i._wrapFn=g=>Ze(g,e=>{let t=Object.create(ns.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var Hn=class g extends fi{constructor(){super();let e=new Dn;this.zpp_inner=e,e.outer=this,e.outer_i=this,this.zpp_inner_i=e,this._inner=this,e.insert_cbtype(fn.ANY_COMPOUND.zpp_inner)}static _wrap(e){return e?e instanceof g?e:e instanceof Dn?Ze(e,t=>{let n=Object.create(g.prototype);return n.zpp_inner=t,t.outer=n,t.outer_i=n,n.zpp_inner_i=t,n._inner=n,n}):e.zpp_inner?g._wrap(e.zpp_inner):Ze(e,t=>{let n=Object.create(g.prototype);return n._inner=t,n}):null}get bodies(){return this.zpp_inner.wrap_bodies}get constraints(){return this.zpp_inner.wrap_constraints}get compounds(){return this.zpp_inner.wrap_compounds}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(e){this.zpp_inner.immutable_midstep("Compound::compound");let t=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(t!==e&&(t?.zpp_inner.wrap_compounds.remove(this),e!=null)){let n=e.zpp_inner.wrap_compounds;n.zpp_inner.reverse_flag?n.push(this):n.unshift(this)}}get space(){return this.zpp_inner.space==null?null:Xn._wrap(this.zpp_inner.space.outer)}set space(e){if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");this.zpp_inner.immutable_midstep("Compound::space");let t=this.zpp_inner.space==null?null:this.zpp_inner.space.outer;if(t!==e?._inner&&(t?.zpp_inner.wrap_compounds.remove(this),e!=null)){let n=e._inner.zpp_inner.wrap_compounds;n.zpp_inner.reverse_flag?n.push(this):n.unshift(this)}}copy(){return this.zpp_inner.copy()}breakApart(){this.zpp_inner.breakApart()}visitBodies(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitBodies");let t=this.zpp_inner.wrap_bodies,n=t.length;for(let l=0;l<n;l++)e(t.at(l));let s=this.zpp_inner.wrap_compounds,i=s.length;for(let l=0;l<i;l++)s.at(l).visitBodies(e)}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitConstraints");let t=this.zpp_inner.wrap_constraints,n=t.length;for(let l=0;l<n;l++)e(t.at(l));let s=this.zpp_inner.wrap_compounds,i=s.length;for(let l=0;l<i;l++)s.at(l).visitConstraints(e)}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitConstraints");let t=this.zpp_inner.wrap_compounds,n=t.length;for(let s=0;s<n;s++){let i=t.at(s);e(i),i.visitCompounds(e)}}COM(e=!1){let t=new Ie(0,0),n=0;if(this.visitBodies(s=>{if(s.zpp_inner.wrap_shapes.zpp_inner.inner.head!=null){if(s.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");s.zpp_inner.wrap_worldCOM==null&&s.zpp_inner.getworldCOM();let l=s.zpp_inner.wrap_worldCOM;if(s.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(s.zpp_inner.validate_mass(),s.zpp_inner.massMode==0&&s.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");let r=s.zpp_inner.cmass;t.addeq(l.mul(r,!0)),n+=r}}),n===0)throw new Error("Error: COM of an empty Compound is undefined silly");return t.muleq(1/n),e&&(t.zpp_inner.weak=!0),t}translate(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot translate by null Vec2");let t=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(n=>{n.zpp_inner.wrap_pos==null&&n.zpp_inner.setupPosition(),n.zpp_inner.wrap_pos.addeq(e)}),e.zpp_inner.weak=t,e.zpp_inner.weak&&e.dispose(),this}rotate(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot rotate about a null Vec2");if(t!==t)throw new Error("Error: Cannot rotate by NaN radians");let n=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(s=>{s.rotate(e,t)}),e.zpp_inner.weak=n,e.zpp_inner.weak&&e.dispose(),this}toString(){return"Compound"+this.zpp_inner.id}};Dn._wrapFn=g=>Ze(g,e=>{let t=Object.create(Hn.prototype);return t.zpp_inner=e,e.outer=t,e.outer_i=t,t.zpp_inner_i=e,t._inner=t,t});Object.defineProperty(Hn.prototype,"bodies",{get:function(){return this.zpp_inner.wrap_bodies},configurable:!0});Object.defineProperty(Hn.prototype,"constraints",{get:function(){return this.zpp_inner.wrap_constraints},configurable:!0});Object.defineProperty(Hn.prototype,"compounds",{get:function(){return this.zpp_inner.wrap_compounds},configurable:!0});function ss(g){return Ie.get(g.x,g.y)}function an(g){return Ie.weak(g.x,g.y)}function Wo(g){return new Wi(g.elasticity,g.dynamicFriction,g.staticFriction,g.density,g.rollingFriction)}function Ko(g){let e=new Ki;return e.collisionGroup=g.collisionGroup,e.collisionMask=g.collisionMask,e.sensorGroup=g.sensorGroup,e.sensorMask=g.sensorMask,e.fluidGroup=g.fluidGroup,e.fluidMask=g.fluidMask,e}function Yo(g){let e=new Zn(g.density,g.viscosity);return g.gravity!=null&&(e.gravity=ss(g.gravity)),e}function Xo(g){let e=Wo(g.material),t=Ko(g.filter),n;if(g.type==="circle"){let s=ss(g.localCOM);n=new wi(g.radius,s,e,t)}else{let s=g.localVerts.map(i=>ss(i));n=new vi(s,e,t)}return n.sensorEnabled=g.sensorEnabled,n.fluidEnabled=g.fluidEnabled,g.fluidEnabled&&g.fluidProperties!=null&&(n.fluidProperties=Yo(g.fluidProperties)),n}function Ho(g){let e=g.type==="STATIC"?jn.STATIC:g.type==="KINEMATIC"?jn.KINEMATIC:jn.DYNAMIC,t=new We(e,an(g.position));t.rotation=g.rotation,g.type!=="STATIC"&&(t.velocity=ss(g.velocity),t.angularVel=g.angularVel),t.kinematicVel=ss(g.kinematicVel),t.kinAngVel=g.kinAngVel,t.surfaceVel=ss(g.surfaceVel),g.type==="DYNAMIC"&&(t.force=ss(g.force),t.torque=g.torque),g.massMode==="FIXED"&&g.mass!=null?t.mass=g.mass:g.massMode==="DEFAULT"&&(t.massMode=qi.DEFAULT),g.inertiaMode==="FIXED"&&g.inertia!=null?t.inertia=g.inertia:g.inertiaMode==="DEFAULT"&&(t.inertiaMode=Ui.DEFAULT),g.gravMassMode==="SCALED"?(t.gravMassMode=oi.SCALED,t.gravMassScale=g.gravMassScale):g.gravMassMode==="FIXED"&&(t.gravMassMode=oi.FIXED),t.allowMovement=g.allowMovement,t.allowRotation=g.allowRotation,t.isBullet=g.bullet;for(let n of g.shapes)Xo(n).body=t;return g.userData!=null&&Object.assign(t.userData,g.userData),t}function is(g,e){g.active=e.active,g.ignore=e.ignore,g.stiff=e.stiff,g.frequency=e.frequency,g.damping=e.damping,g.maxForce=e.maxForce,g.maxError=e.maxError,g.breakUnderForce=e.breakUnderForce,g.breakUnderError=e.breakUnderError,g.removeOnBreak=e.removeOnBreak,e.userData!=null&&Object.assign(g.userData,e.userData)}function Qo(g,e){let t=g.body1Id!=null?e[g.body1Id]??null:null,n=g.body2Id!=null?e[g.body2Id]??null:null;switch(g.type){case"PivotJoint":{let s=new Xi(t,n,an(g.anchor1),an(g.anchor2));return is(s,g),s}case"DistanceJoint":{let s=new Hi(t,n,an(g.anchor1),an(g.anchor2),g.jointMin,g.jointMax);return is(s,g),s}case"AngleJoint":{let s=new Qi(t,n,g.jointMin,g.jointMax,g.ratio);return is(s,g),s}case"MotorJoint":{let s=new $i(t,n,g.rate,g.ratio);return is(s,g),s}case"LineJoint":{let s=new es(t,n,an(g.anchor1),an(g.anchor2),an(g.direction),g.jointMin,g.jointMax);return is(s,g),s}case"PulleyJoint":{let s=new ts(t,n,null,null,an(g.anchor1),an(g.anchor2),an(g.anchor3),an(g.anchor4),g.jointMin,g.jointMax,g.ratio);return is(s,g),s}case"WeldJoint":{let s=new ns(t,n,an(g.anchor1),an(g.anchor2),g.phase);return is(s,g),s}}}function no(g){if(g.version!==1)throw new Error(`nape-js serialization: unsupported snapshot version ${g.version} (expected ${1})`);let e=g.broadphase==="SWEEP_AND_PRUNE"?gi.SWEEP_AND_PRUNE:gi.DYNAMIC_AABB_TREE,t=new Xn(an(g.gravity),e);t.worldLinearDrag=g.worldLinearDrag,t.worldAngularDrag=g.worldAngularDrag,t.sortContacts=g.sortContacts;let n=g.bodies.map(Ho),s=g.constraints.map(r=>Qo(r,n)),i=new Set,l=new Set;for(let r of g.compounds){let a=new Hn;for(let o of r.bodyIds)n[o].compound=a,i.add(o);for(let o of r.constraintIndices)s[o].compound=a,l.add(o);a.space=t}for(let r=0;r<n.length;r++)i.has(r)||(n[r].space=t);for(let r=0;r<s.length;r++)l.has(r)||(s[r].space=t);return t}var vl=class{constructor(e=4096){this.pos=0;this.buf=new ArrayBuffer(e),this.view=new DataView(this.buf)}ensure(e){let t=this.pos+e;if(t<=this.buf.byteLength)return;let n=this.buf.byteLength;for(;n<t;)n*=2;let s=new ArrayBuffer(n);new Uint8Array(s).set(new Uint8Array(this.buf)),this.buf=s,this.view=new DataView(this.buf)}writeUint8(e){this.ensure(1),this.view.setUint8(this.pos,e),this.pos+=1}writeUint16(e){this.ensure(2),this.view.setUint16(this.pos,e,!0),this.pos+=2}writeUint32(e){this.ensure(4),this.view.setUint32(this.pos,e,!0),this.pos+=4}writeInt32(e){this.ensure(4),this.view.setInt32(this.pos,e,!0),this.pos+=4}writeFloat64(e){this.ensure(8),this.view.setFloat64(this.pos,e,!0),this.pos+=8}writeBool(e){this.writeUint8(e?1:0)}finish(){return new Uint8Array(this.buf,0,this.pos)}};var $o=1312903237,gs=1,er=0,tr=1,nr=2,ir=3,sr=4,lr=5,or=6;function rr(g,e){g.writeFloat64(e.elasticity),g.writeFloat64(e.dynamicFriction),g.writeFloat64(e.staticFriction),g.writeFloat64(e.density),g.writeFloat64(e.rollingFriction)}function ar(g,e){g.writeInt32(e.collisionGroup),g.writeInt32(e.collisionMask),g.writeInt32(e.sensorGroup),g.writeInt32(e.sensorMask),g.writeInt32(e.fluidGroup),g.writeInt32(e.fluidMask)}function pr(g,e){if(e==null)return;g.writeFloat64(e.density),g.writeFloat64(e.viscosity);let t=e.gravity;g.writeBool(t!=null),t!=null&&(g.writeFloat64(t.x),g.writeFloat64(t.y))}function cr(g,e){if(e.isCircle()){g.writeUint8(0);let i=e;g.writeFloat64(i.radius);let l=e.localCOM;g.writeFloat64(l.x),g.writeFloat64(l.y)}else{g.writeUint8(1);let l=e.localVerts,r=l.length;g.writeUint16(r);for(let a=0;a<r;a++){let o=l.at(a);g.writeFloat64(o.x),g.writeFloat64(o.y)}}rr(g,e.material),ar(g,e.filter);let t=e.fluidEnabled,n=t&&e.fluidProperties!=null,s=(e.sensorEnabled?1:0)|(t?2:0)|(n?4:0);g.writeUint8(s),n&&pr(g,e.fluidProperties)}function hr(g,e){let t=e.zpp_inner;g.writeUint8(t.type),g.writeFloat64(e.position.x),g.writeFloat64(e.position.y),g.writeFloat64(e.rotation),g.writeFloat64(e.velocity.x),g.writeFloat64(e.velocity.y),g.writeFloat64(e.angularVel),g.writeFloat64(e.kinematicVel.x),g.writeFloat64(e.kinematicVel.y),g.writeFloat64(e.kinAngVel),g.writeFloat64(e.surfaceVel.x),g.writeFloat64(e.surfaceVel.y),g.writeFloat64(e.force.x),g.writeFloat64(e.force.y),g.writeFloat64(t.type===2?e.torque:0),g.writeUint8(t.massMode),g.writeFloat64(t.massMode===1?t.cmass:0),g.writeUint8(t.inertiaMode),g.writeFloat64(t.inertiaMode===1?t.cinertia:0),g.writeUint8(t.gravMassMode),g.writeFloat64(t.gravMassScale);let n=(e.allowMovement?1:0)|(e.allowRotation?2:0)|(e.isBullet?4:0);g.writeUint8(n);let s=e.shapes,i=s.length;g.writeUint16(i);for(let l=0;l<i;l++)cr(g,s.at(l))}var io={PivotJoint:er,DistanceJoint:tr,AngleJoint:nr,MotorJoint:ir,LineJoint:sr,PulleyJoint:lr,WeldJoint:or};function ls(g,e,t,n,s){let i=n!=null?t.get(n.zpp_inner.id)??-1:-1,l=s!=null?t.get(s.zpp_inner.id)??-1:-1;g.writeInt32(i),g.writeInt32(l);let r=e.zpp_inner,a=(r.active?1:0)|(r.ignore?2:0)|(r.stiff?4:0)|(r.breakUnderForce?8:0)|(r.breakUnderError?16:0)|(r.removeOnBreak?32:0);g.writeUint8(a),g.writeFloat64(r.frequency),g.writeFloat64(r.damping),g.writeFloat64(r.maxForce),g.writeFloat64(r.maxError)}function ur(g,e,t){let n=e.constructor?.name??"",s=io[n];if(s===void 0)return!1;switch(g.writeUint8(s),n){case"PivotJoint":{let i=e;ls(g,e,t,i.body1,i.body2),g.writeFloat64(i.anchor1.x),g.writeFloat64(i.anchor1.y),g.writeFloat64(i.anchor2.x),g.writeFloat64(i.anchor2.y);break}case"DistanceJoint":{let i=e;ls(g,e,t,i.body1,i.body2),g.writeFloat64(i.anchor1.x),g.writeFloat64(i.anchor1.y),g.writeFloat64(i.anchor2.x),g.writeFloat64(i.anchor2.y),g.writeFloat64(i.jointMin),g.writeFloat64(i.jointMax);break}case"AngleJoint":{let i=e;ls(g,e,t,i.body1,i.body2),g.writeFloat64(i.jointMin),g.writeFloat64(i.jointMax),g.writeFloat64(i.ratio);break}case"MotorJoint":{let i=e;ls(g,e,t,i.body1,i.body2),g.writeFloat64(i.rate),g.writeFloat64(i.ratio);break}case"LineJoint":{let i=e;ls(g,e,t,i.body1,i.body2),g.writeFloat64(i.anchor1.x),g.writeFloat64(i.anchor1.y),g.writeFloat64(i.anchor2.x),g.writeFloat64(i.anchor2.y),g.writeFloat64(i.direction.x),g.writeFloat64(i.direction.y),g.writeFloat64(i.jointMin),g.writeFloat64(i.jointMax);break}case"PulleyJoint":{let i=e;ls(g,e,t,i.body1,i.body2),g.writeFloat64(i.anchor1.x),g.writeFloat64(i.anchor1.y),g.writeFloat64(i.anchor2.x),g.writeFloat64(i.anchor2.y),g.writeFloat64(i.anchor3.x),g.writeFloat64(i.anchor3.y),g.writeFloat64(i.anchor4.x),g.writeFloat64(i.anchor4.y),g.writeFloat64(i.jointMin),g.writeFloat64(i.jointMax),g.writeFloat64(i.ratio);break}case"WeldJoint":{let i=e;ls(g,e,t,i.body1,i.body2),g.writeFloat64(i.anchor1.x),g.writeFloat64(i.anchor1.y),g.writeFloat64(i.anchor2.x),g.writeFloat64(i.anchor2.y),g.writeFloat64(i.phase);break}}return!0}function so(g){let e=new vl,t=[],n=new Map,s=new Map;function i(d){let _=d.zpp_inner.id;if(n.has(_))return;let f=t.length;s.set(d,f),n.set(_,f),t.push(d)}let l=g.bodies,r=l.length;for(let d=0;d<r;d++)i(l.at(d));let a=g.compounds,o=a.length;for(let d=0;d<o;d++){let f=a.at(d).bodies,z=f.length;for(let P=0;P<z;P++)i(f.at(P))}let p=[],c=new Map;function h(d){if(c.has(d))return;let _=d.constructor?.name??"";io[_]!==void 0&&(c.set(d,p.length),p.push(d))}let u=g.constraints,x=u.length;for(let d=0;d<x;d++)h(u.at(d));for(let d=0;d<o;d++){let f=a.at(d).constraints,z=f.length;for(let P=0;P<z;P++)h(f.at(P))}e.writeUint32($o),e.writeUint16(gs),e.writeUint32(t.length),e.writeUint32(p.length),e.writeUint32(o);let y=g.gravity;e.writeFloat64(y.x),e.writeFloat64(y.y),e.writeFloat64(g.worldLinearDrag),e.writeFloat64(g.worldAngularDrag),e.writeBool(g.sortContacts),e.writeUint8(g.zpp_inner.bphase.is_sweep?0:1);for(let d=0;d<t.length;d++)hr(e,t[d]);for(let d=0;d<p.length;d++)ur(e,p[d],n);for(let d=0;d<o;d++){let _=a.at(d),f=_.bodies,z=f.length;e.writeUint16(z);for(let b=0;b<z;b++){let C=f.at(b),v=s.get(C)??0;e.writeUint32(v)}let P=_.constraints,k=P.length,m=0;for(let b=0;b<k;b++){let C=P.at(b);c.has(C)&&m++}e.writeUint16(m);for(let b=0;b<k;b++){let C=P.at(b),v=c.get(C);v!=null&&e.writeUint32(v)}e.writeUint16(0)}return e.finish()}var gl=class{constructor(e){this.pos=0;this.view=new DataView(e.buffer,e.byteOffset,e.byteLength)}readUint8(){let e=this.view.getUint8(this.pos);return this.pos+=1,e}readUint16(){let e=this.view.getUint16(this.pos,!0);return this.pos+=2,e}readUint32(){let e=this.view.getUint32(this.pos,!0);return this.pos+=4,e}readInt32(){let e=this.view.getInt32(this.pos,!0);return this.pos+=4,e}readFloat64(){let e=this.view.getFloat64(this.pos,!0);return this.pos+=8,e}readBool(){return this.readUint8()!==0}};var lo=1312903237,xr=0,dr=1,_r=2,yr=3,mr=4,br=5,fr=6,zr={1:jn.STATIC,2:jn.DYNAMIC,3:jn.KINEMATIC};function oo(g){let e=g.readFloat64(),t=g.readFloat64(),n=g.readFloat64(),s=g.readFloat64(),i=g.readFloat64();return new Wi(e,t,n,s,i)}function ro(g){let e=new Ki;return e.collisionGroup=g.readInt32(),e.collisionMask=g.readInt32(),e.sensorGroup=g.readInt32(),e.sensorMask=g.readInt32(),e.fluidGroup=g.readInt32(),e.fluidMask=g.readInt32(),e}function Pr(g){let e=g.readFloat64(),t=g.readFloat64(),n=new Zn(e,t);return g.readBool()&&(n.gravity=Ie.get(g.readFloat64(),g.readFloat64())),n}function wr(g){let e=g.readUint8(),t;if(e===0){let i=g.readFloat64(),l=g.readFloat64(),r=g.readFloat64(),a=oo(g),o=ro(g);t=new wi(i,Ie.weak(l,r),a,o)}else{let i=g.readUint16(),l=[];for(let o=0;o<i;o++)l.push(Ie.get(g.readFloat64(),g.readFloat64()));let r=oo(g),a=ro(g);t=new vi(l,r,a)}let n=g.readUint8();return t.sensorEnabled=(n&1)!==0,t.fluidEnabled=(n&2)!==0,(n&4)!==0&&(t.fluidProperties=Pr(g)),t}function vr(g){let e=g.readUint8(),t=zr[e]??jn.DYNAMIC,n=g.readFloat64(),s=g.readFloat64(),i=g.readFloat64(),l=new We(t,Ie.weak(n,s));l.rotation=i;let r=g.readFloat64(),a=g.readFloat64(),o=g.readFloat64();e!==1&&(l.velocity=Ie.get(r,a),l.angularVel=o),l.kinematicVel=Ie.get(g.readFloat64(),g.readFloat64()),l.kinAngVel=g.readFloat64(),l.surfaceVel=Ie.get(g.readFloat64(),g.readFloat64());let p=g.readFloat64(),c=g.readFloat64(),h=g.readFloat64();e===2&&(l.force=Ie.get(p,c),l.torque=h);let u=g.readUint8(),x=g.readFloat64();u===1&&x!==0?l.mass=x:u===0&&(l.massMode=qi.DEFAULT);let y=g.readUint8(),d=g.readFloat64();y===1&&d!==0?l.inertia=d:y===0&&(l.inertiaMode=Ui.DEFAULT);let _=g.readUint8(),f=g.readFloat64();_===2?(l.gravMassMode=oi.SCALED,l.gravMassScale=f):_===1&&(l.gravMassMode=oi.FIXED);let z=g.readUint8();l.allowMovement=(z&1)!==0,l.allowRotation=(z&2)!==0,l.isBullet=(z&4)!==0;let P=g.readUint16();for(let k=0;k<P;k++)wr(g).body=l;return l}function gr(g){let e=g.readInt32(),t=g.readInt32(),n=g.readUint8(),s=g.readFloat64(),i=g.readFloat64(),l=g.readFloat64(),r=g.readFloat64();return{body1Id:e,body2Id:t,active:(n&1)!==0,ignore:(n&2)!==0,stiff:(n&4)!==0,breakUnderForce:(n&8)!==0,breakUnderError:(n&16)!==0,removeOnBreak:(n&32)!==0,frequency:s,damping:i,maxForce:l,maxError:r}}function os(g,e){g.active=e.active,g.ignore=e.ignore,g.stiff=e.stiff,g.frequency=e.frequency,g.damping=e.damping,g.maxForce=e.maxForce,g.maxError=e.maxError,g.breakUnderForce=e.breakUnderForce,g.breakUnderError=e.breakUnderError,g.removeOnBreak=e.removeOnBreak}function Cr(g,e){let t=g.readUint8(),n=gr(g),s=n.body1Id>=0?e[n.body1Id]??null:null,i=n.body2Id>=0?e[n.body2Id]??null:null;switch(t){case xr:{let l=g.readFloat64(),r=g.readFloat64(),a=g.readFloat64(),o=g.readFloat64(),p=new Xi(s,i,Ie.weak(l,r),Ie.weak(a,o));return os(p,n),p}case dr:{let l=g.readFloat64(),r=g.readFloat64(),a=g.readFloat64(),o=g.readFloat64(),p=g.readFloat64(),c=g.readFloat64(),h=new Hi(s,i,Ie.weak(l,r),Ie.weak(a,o),p,c);return os(h,n),h}case _r:{let l=g.readFloat64(),r=g.readFloat64(),a=g.readFloat64(),o=new Qi(s,i,l,r,a);return os(o,n),o}case yr:{let l=g.readFloat64(),r=g.readFloat64(),a=new $i(s,i,l,r);return os(a,n),a}case mr:{let l=g.readFloat64(),r=g.readFloat64(),a=g.readFloat64(),o=g.readFloat64(),p=g.readFloat64(),c=g.readFloat64(),h=g.readFloat64(),u=g.readFloat64(),x=new es(s,i,Ie.weak(l,r),Ie.weak(a,o),Ie.weak(p,c),h,u);return os(x,n),x}case br:{let l=g.readFloat64(),r=g.readFloat64(),a=g.readFloat64(),o=g.readFloat64(),p=g.readFloat64(),c=g.readFloat64(),h=g.readFloat64(),u=g.readFloat64(),x=g.readFloat64(),y=g.readFloat64(),d=g.readFloat64(),_=new ts(s,i,null,null,Ie.weak(l,r),Ie.weak(a,o),Ie.weak(p,c),Ie.weak(h,u),x,y,d);return os(_,n),_}case fr:{let l=g.readFloat64(),r=g.readFloat64(),a=g.readFloat64(),o=g.readFloat64(),p=g.readFloat64(),c=new ns(s,i,Ie.weak(l,r),Ie.weak(a,o),p);return os(c,n),c}default:throw new Error(`nape-js binary: unknown constraint type tag ${t}`)}}function ao(g){let e=new gl(g),t=e.readUint32();if(t!==lo)throw new Error(`nape-js binary: invalid magic bytes 0x${t.toString(16)} (expected 0x${lo.toString(16)})`);let n=e.readUint16();if(n!==gs)throw new Error(`nape-js binary: unsupported version ${n} (expected ${gs})`);let s=e.readUint32(),i=e.readUint32(),l=e.readUint32(),r=e.readFloat64(),a=e.readFloat64(),o=e.readFloat64(),p=e.readFloat64(),c=e.readBool(),u=e.readUint8()===0?gi.SWEEP_AND_PRUNE:gi.DYNAMIC_AABB_TREE,x=new Xn(Ie.weak(r,a),u);x.worldLinearDrag=o,x.worldAngularDrag=p,x.sortContacts=c;let y=new Array(s);for(let z=0;z<s;z++)y[z]=vr(e);let d=new Array(i);for(let z=0;z<i;z++)d[z]=Cr(e,y);let _=new Set,f=new Set;for(let z=0;z<l;z++){let P=new Hn,k=e.readUint16();for(let C=0;C<k;C++){let v=e.readUint32();y[v].compound=P,_.add(v)}let m=e.readUint16();for(let C=0;C<m;C++){let v=e.readUint32();d[v].compound=P,f.add(v)}let b=e.readUint16();for(let C=0;C<b;C++)e.readUint32();P.space=x}for(let z=0;z<s;z++)_.has(z)||(y[z].space=x);for(let z=0;z<i;z++)f.has(z)||(d[z].space=x);return x}0&&(module.exports={BINARY_SNAPSHOT_VERSION,SNAPSHOT_VERSION,spaceFromBinary,spaceFromJSON,spaceToBinary,spaceToJSON});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|