@newkrok/nape-js 3.16.2 → 3.18.0
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-CzVZh3d_.d.cts → ConvexResult-DafossGq.d.cts} +19 -0
- package/dist/{ConvexResult-CzVZh3d_.d.ts → ConvexResult-DafossGq.d.ts} +19 -0
- package/dist/{chunk-ON6LCM4U.js → chunk-SQVUZDT6.js} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/serialization/index.cjs +1 -1
- package/dist/serialization/index.d.cts +1 -1
- package/dist/serialization/index.d.ts +1 -1
- package/dist/serialization/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Bl=Object.defineProperty;var fo=Object.getOwnPropertyDescriptor;var zo=Object.getOwnPropertyNames;var Po=Object.prototype.hasOwnProperty;var wo=(v,e)=>{for(var t in e)Bl(v,t,{get:e[t],enumerable:!0})},vo=(v,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of zo(e))!Po.call(v,s)&&s!==t&&Bl(v,s,{get:()=>e[s],enumerable:!(n=fo(e,s))||n.enumerable});return v};var go=v=>vo(Bl({},"__esModule",{value:!0}),v);var jr={};wo(jr,{BINARY_SNAPSHOT_VERSION:()=>Os,SNAPSHOT_VERSION:()=>Ss,spaceFromBinary:()=>bo,spaceFromJSON:()=>xo,spaceToBinary:()=>yo,spaceToJSON:()=>Yl});module.exports=go(jr);var Ss=1;function ht(v){return{x:v.x,y:v.y}}function Kl(v){if(v==null)return null;try{let e=JSON.stringify(v);return e==="{}"?null:JSON.parse(e)}catch{return null}}function Co(v){return{elasticity:v.elasticity,dynamicFriction:v.dynamicFriction,staticFriction:v.staticFriction,density:v.density,rollingFriction:v.rollingFriction}}function Mo(v){return{collisionGroup:v.collisionGroup,collisionMask:v.collisionMask,sensorGroup:v.sensorGroup,sensorMask:v.sensorMask,fluidGroup:v.fluidGroup,fluidMask:v.fluidMask}}function Zo(v){if(v==null)return null;let e=v.gravity;return{density:v.density,viscosity:v.viscosity,gravity:e!=null?ht(e):null}}function ko(v){let e=Co(v.material),t=Mo(v.filter),n=v.fluidEnabled,s=n?Zo(v.fluidProperties):null,i=v.sensorEnabled;if(v.isCircle()){let l=v,o=v.localCOM;return{type:"circle",radius:l.radius,localCOM:ht(o),material:e,filter:t,sensorEnabled:i,fluidEnabled:n,fluidProperties:s}}else if(v.isCapsule()){let l=v,o=v.localCOM;return{type:"capsule",width:l.width,height:l.height,localCOM:ht(o),material:e,filter:t,sensorEnabled:i,fluidEnabled:n,fluidProperties:s}}else{let o=v.localVerts,r=[],a=o.length;for(let p=0;p<a;p++)r.push(ht(o.at(p)));return{type:"polygon",localVerts:r,material:e,filter:t,sensorEnabled:i,fluidEnabled:n,fluidProperties:s}}}var Eo={1:"STATIC",2:"DYNAMIC",3:"KINEMATIC"},No={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},Oo={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},So={0:"DEFAULT",1:"FIXED",2:"SCALED"};function Ao(v,e){let t=v.zpp_inner,n=No[t.massMode]??"DEFAULT",s=Oo[t.inertiaMode]??"DEFAULT",i=So[t.gravMassMode]??"DEFAULT",l=[],o=v.shapes,r=o.length;for(let a=0;a<r;a++)l.push(ko(o.at(a)));return{id:e,type:Eo[t.type]??"DYNAMIC",position:ht(v.position),rotation:v.rotation,velocity:ht(v.velocity),angularVel:v.angularVel,kinematicVel:ht(v.kinematicVel),kinAngVel:v.kinAngVel,surfaceVel:ht(v.surfaceVel),force:ht(v.force),torque:t.type===2?v.torque:0,massMode:n,mass:n==="FIXED"?t.cmass:null,inertiaMode:s,inertia:s==="FIXED"?t.cinertia:null,gravMassMode:i,gravMassScale:t.gravMassScale,allowMovement:v.allowMovement,allowRotation:v.allowRotation,bullet:v.isBullet,shapes:l,userData:Kl(t.userData)}}function Ii(v,e,t,n){let s=v.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:Kl(s.userData)}}function Vo(v,e){switch(v.constructor?.name??""){case"PivotJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"PivotJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2)}}case"DistanceJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"DistanceJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2),jointMin:n.jointMin,jointMax:n.jointMax}}case"AngleJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"AngleJoint",jointMin:n.jointMin,jointMax:n.jointMax,ratio:n.ratio}}case"MotorJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"MotorJoint",rate:n.rate,ratio:n.ratio}}case"LineJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"LineJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2),direction:ht(n.direction),jointMin:n.jointMin,jointMax:n.jointMax}}case"PulleyJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"PulleyJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2),anchor3:ht(n.anchor3),anchor4:ht(n.anchor4),jointMin:n.jointMin,jointMax:n.jointMax,ratio:n.ratio}}case"WeldJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"WeldJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2),phase:n.phase}}default:return null}}function Yl(v){let e=[],t=new Map,n=new Map;function s(b){let f=b.zpp_inner.id;if(n.has(f))return;let P=e.length;t.set(b,P),n.set(f,P),e.push(Ao(b,P))}let i=v.bodies,l=i.length;for(let b=0;b<l;b++)s(i.at(b));let o=v.compounds,r=o.length;for(let b=0;b<r;b++){let P=o.at(b).bodies,k=P.length;for(let _=0;_<k;_++)s(P.at(_))}let a=[],p=new Map;function c(b){if(p.has(b))return;let f=Vo(b,n);f!=null&&(p.set(b,a.length),a.push(f))}let h=v.constraints,u=h.length;for(let b=0;b<u;b++)c(h.at(b));for(let b=0;b<r;b++){let P=o.at(b).constraints,k=P.length;for(let _=0;_<k;_++)c(P.at(_))}let x=[];for(let b=0;b<r;b++){let f=o.at(b),P=[],k=f.bodies,_=k.length;for(let g=0;g<_;g++){let O=k.at(g),E=t.get(O);E!=null&&P.push(E)}let z=[],C=f.constraints,w=C.length;for(let g=0;g<w;g++){let O=C.at(g),E=p.get(O);E!=null&&z.push(E)}x.push({bodyIds:P,constraintIndices:z,childIndices:[]})}let d=v.zpp_inner.bphase.is_sweep?"SWEEP_AND_PRUNE":"DYNAMIC_AABB_TREE",y=v.gravity;return{version:1,gravity:ht(y),worldLinearDrag:v.worldLinearDrag,worldAngularDrag:v.worldAngularDrag,sortContacts:v.sortContacts,deterministic:v.deterministic,broadphase:d,bodies:e,constraints:a,compounds:x}}var qn=class{static POSINF(){return 1/0}static NEGINF(){return-1/0}};qn.FMAX=1e100;var gt=class gt{static Constraint(){return gt._Constraint++}static Interactor(){return gt._Interactor++}static CbType(){return gt._CbType++}static CbSet(){return gt._CbSet++}static Listener(){return gt._Listener++}static ZPP_SimpleVert(){return gt._ZPP_SimpleVert++}static ZPP_SimpleSeg(){return gt._ZPP_SimpleSeg++}static Space(){return gt._Space++}static InteractionGroup(){return gt._InteractionGroup++}};gt._Constraint=0,gt._Interactor=0,gt._CbType=0,gt._CbSet=0,gt._Listener=0,gt._ZPP_SimpleVert=0,gt._ZPP_SimpleSeg=0,gt._Space=0,gt._InteractionGroup=0;var yn=gt;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.ShapeType_CAPSULE=null,H.Broadphase_DYNAMIC_AABB_TREE=null,H.Broadphase_SWEEP_AND_PRUNE=null,H.Broadphase_SPATIAL_HASH=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_ShapeType_CAPSULE=2,H.id_Broadphase_DYNAMIC_AABB_TREE=0,H.id_Broadphase_SWEEP_AND_PRUNE=1,H.id_Broadphase_SPATIAL_HASH=2,H.id_ArbiterType_COLLISION=1,H.id_ArbiterType_SENSOR=2,H.id_ArbiterType_FLUID=4;var al=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 ye=class{};ye.poolGeomPoly=null,ye.nextGeomPoly=null,ye.poolVec2=null,ye.nextVec2=null,ye.poolVec3=null,ye.nextVec3=null;var As=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}},ds=class extends As{},_s=class extends As{},ys=class extends As{};var wn=class wn{constructor(){this.value=!1;this.next=null;this.hnext=null;this.id=0;this.di=0}static _alloc(){if(wn.zpp_pool==null)return new wn;let e=wn.zpp_pool;return wn.zpp_pool=e.next,e.next=null,e}static get(e,t,n){let s=wn._alloc();return s.id=e,s.di=t,s.value=n,s}static getpersist(e,t){let n=wn._alloc();return n.id=e,n.di=t,n}static ordered_get(e,t,n){if(e<=t){let s=wn._alloc();return s.id=e,s.di=t,s.value=n,s}else{let s=wn._alloc();return s.id=t,s.di=e,s.value=n,s}}static ordered_get_persist(e,t){if(e<=t){let n=wn._alloc();return n.id=e,n.di=t,n}else{let n=wn._alloc();return n.id=t,n.di=e,n}}free(){}alloc(){}};wn.zpp_pool=null;var Te=wn;var Io=1048576,Bi=1048575,ji=106039,Ti=class{constructor(){this.cnt=0;this.cnt=0,this.table=new Array(Io).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*ji+t&Bi];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*ji+t&Bi];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*ji+t&Bi];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*ji+e.di&Bi,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*ji+e.di&Bi,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*ji+e.di&Bi,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*ji+t&Bi}};var Vs=class{constructor(){this.elt=null;this.next=null}alloc(){}free(){this.elt=null}elem(){return this.elt}};Vs.zpp_pool=null;var dt=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}};dt.prototype.inlined_add=dt.prototype.add;dt.prototype.inlined_insert=dt.prototype.insert;dt.prototype.inlined_pop=dt.prototype.pop;dt.prototype.inlined_pop_unsafe=dt.prototype.pop_unsafe;dt.prototype.inlined_erase=dt.prototype.erase;dt.prototype.inlined_remove=dt.prototype.remove;dt.prototype.inlined_try_remove=dt.prototype.try_remove;dt.prototype.inlined_clear=dt.prototype.clear;dt.prototype.inlined_has=dt.prototype.has;var Is=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,o=i.next;s.colour=0,e.colour=t.colour=1,e.next=l,l!=null&&(l.parent=e);let r=t.data;t.data=i.data,i.data=r,this.swapped!=null&&this.swapped(t.data,i.data),i.prev=o,o!=null&&(o.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,o=i.prev;s.colour=0,e.colour=t.colour=1,e.prev=l,l!=null&&(l.parent=e);let r=t.data;t.data=i.data,i.data=r,this.swapped!=null&&this.swapped(t.data,i.data),i.next=o,o!=null&&(o.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,o,r,a,p;t==n.prev?(l=n,p=n.next,e==t.prev?(s=e,i=t,o=e.prev,r=e.next,a=t.next):(s=t,i=e,o=t.prev,r=e.prev,a=e.next)):(s=n,o=n.prev,e==t.prev?(i=e,l=t,r=e.prev,a=e.next,p=t.next):(i=t,l=e,r=t.prev,a=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=o,o!=null&&(o.parent=s),s.next=r,r!=null&&(r.parent=s),i.prev=s,s!=null&&(s.parent=i),i.next=l,l!=null&&(l.parent=i),l.prev=a,a!=null&&(a.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}};Is.zpp_pool=null;var _i=null,pl=null,ms=null,jl=null,Bo=null,Tl=null,bs=null,$t=null,fs=null,Xn=null,zs=null,Ps=null,Ll=null,jo=null,To=null,Lo=null,Do=null,Fo=null,Ro=null,Go=null,qo=null;function Je(v){let e=class extends Vs{};return e.zpp_pool=null,e}function Ue(v,e){let t=class extends dt{};return t._NodeClass=e,t}function di(v){let e=class extends Is{};return e.zpp_pool=null,e}function Xl(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;To=v.util.ZNPList_ZPP_InteractionListener=Ue("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),Lo=v.util.ZNPList_ZPP_BodyListener=Ue("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),Do=v.util.ZNPList_ZPP_ConstraintListener=Ue("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),Fo=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),Go=v.util.ZNPList_ZPP_CbSet=Ue("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),jo=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),qo=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),_i=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),pl=v.util.ZNPList_ZPP_PartitionedPoly,v.util.ZNPList_ZPP_GeomVert=Ue("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),ms=v.util.ZNPList_ZPP_GeomVert,v.util.ZNPList_ZPP_SimpleVert=Ue("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),Ll=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),bs=v.util.ZNPNode_RayResult,Tl=v.util.ZNPList_ZPP_SimpleVert,v.util.ZPP_Set_ZPP_Body=di("ZPP_Body"),v.util.ZPP_Set_ZPP_CbSetPair=di("ZPP_CbSetPair"),v.util.ZPP_Set_ZPP_PartitionVertex=di("ZPP_PartitionVertex"),zs=v.util.ZPP_Set_ZPP_PartitionVertex,v.util.ZPP_Set_ZPP_PartitionPair=di("ZPP_PartitionPair"),Ps=v.util.ZPP_Set_ZPP_PartitionPair,v.util.ZPP_Set_ZPP_SimpleVert=di("ZPP_SimpleVert"),$t=v.util.ZPP_Set_ZPP_SimpleVert,v.util.ZPP_Set_ZPP_SimpleSeg=di("ZPP_SimpleSeg"),fs=v.util.ZPP_Set_ZPP_SimpleSeg,v.util.ZPP_Set_ZPP_SimpleEvent=di("ZPP_SimpleEvent"),Xn=v.util.ZPP_Set_ZPP_SimpleEvent,v.util.ZPP_Set_ZPP_CbSet=di("ZPP_CbSet")}var zt=class zt{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&&(zt.internal=!0,this.outer_body=zt._createBodyCb(),zt.internal=!1,this.outer_body.zpp_inner=this),this.outer_body}wrapper_con(){return this.outer_con==null&&(zt.internal=!0,this.outer_con=zt._createConCb(),zt.internal=!1,this.outer_con.zpp_inner=this),this.outer_con}wrapper_int(){let e=zt._zpp;return this.outer_int==null&&(zt.internal=!0,this.outer_int=zt._createIntCb(),zt.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=zt._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}};zt._nape=null,zt._zpp=null,zt.internal=!1,zt.zpp_pool=null,zt._createBodyCb=null,zt._createConCb=null,zt._createIntCb=null,zt._createPreCb=null;var Tt=zt;var Jt=class Jt{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=Jt._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;Jt.zpp_pool==null?t=new Jt:(t=Jt.zpp_pool,Jt.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 o=e.options2,r=n.cbTypes;s=o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)}else s=!1;if(s)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=Jt._zpp,s=null,l=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;l!=null;){let o=l.elt;if(o.a==e&&o.b==t||o.a==t&&o.b==e){s=o;break}l=l.next}if(s==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,Jt.setlt(e,t)?(o.a=e,o.b=t):(o.a=t,o.b=e),s=o,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 Jt.findOrCreatePair(e,t).listeners.head==null}static single_intersection(e,t,n){let i=Jt.findOrCreatePair(e,t).listeners.head;return i!=null&&i.elt==n?i.next==null:!1}static find_all(e,t,n,s){let l=Jt.findOrCreatePair(e,t).listeners.head;for(;l!=null;){let o=l.elt;o.event==n&&s(o),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=Jt._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 o=l.elt;if(i!=null&&i.elt==o)l=l.next,s=i,i=i.next;else{let r;if(i!=null){let a=i.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;s==null?(c.next=a.head,a.head=c):(c.next=s.next,s.next=c),a.pushmod=a.modified=!0,a.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=Jt._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 o=l.elt;if(i!=null&&i.elt==o)l=l.next,s=i,i=i.next;else{let r;if(i!=null){let a=i.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 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=Jt._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 o=l.elt;if(i!=null&&i.elt==o)l=l.next,s=i,i=i.next;else{let r;if(i!=null){let a=i.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 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(){}};Jt._zpp=null,Jt.zpp_pool=null;var _t=Jt;var Jn=class Jn{constructor(){this.a=null;this.b=null;this.next=null;this.zip_listeners=!1;this.listeners=null;let e=Jn._zpp;this.listeners=new e.util.ZNPList_ZPP_InteractionListener}static get(e,t){let n=Jn._zpp,s;return Jn.zpp_pool==null?s=new Jn:(s=Jn.zpp_pool,Jn.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=Jn._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 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,s=t.elt;if(n==s){let i,l,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;l=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else l=!1;if(l)i=!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,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}}};Jn._zpp=null,Jn.zpp_pool=null;var Ne=Jn;var an=class an{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=an._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){an.ANY_SHAPE=new e.callbacks.CbType,an.ANY_BODY=new e.callbacks.CbType,an.ANY_COMPOUND=new e.callbacks.CbType,an.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=an._zpp,n=null,s=this.listeners.head;for(;s!=null;){let r=s.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.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 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=an._zpp,n=null,s=this.bodylisteners.head;for(;s!=null;){let r=s.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.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 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=an._zpp,n=null,s=this.conlisteners.head;for(;s!=null;){let r=s.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.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 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}};an._zpp=null,an.ANY_SHAPE=null,an.ANY_BODY=null,an.ANY_COMPOUND=null,an.ANY_CONSTRAINT=null;var pn=an;var oi=class oi{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=yn.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()),oi.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()),oi.events=[t.CbEvent_BEGIN,t.CbEvent_END,t.CbEvent_WAKE,t.CbEvent_SLEEP,t.CbEvent_BREAK,t.CbEvent_PRE,t.CbEvent_ONGOING]}};oi._nape=null,oi._zpp=null,oi.internal=!1,oi.types=[],oi.events=[];var Lt=oi;var cl=class extends Lt{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=Lt._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 o=s.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;i==null?(a.next=o.head,o.head=a):(a.next=i.next,i.next=a),o.pushmod=o.modified=!0,o.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 hl=class extends Lt{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=Lt._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 o=s.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;i==null?(a.next=o.head,o.head=a):(a.next=i.next,i.next=a),o.pushmod=o.modified=!0,o.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 Ct=class Ct extends Lt{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=Lt._zpp,l=Ct.UCbSet,o=Ct.VCbSet,r=Ct.WCbSet,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,h=p.elt;if(c==h){let u=this._allocCbSetNode(i);u.elt=c,u.next=r.head,r.head=u,r.modified=!0,r.length++,a=a.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++,a=a.next}else{let u=this._allocCbSetNode(i);u.elt=h,u.next=o.head,o.head=u,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbSetNode(i);c.elt=a.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,a=a.next}for(;p!=null;){let c=this._allocCbSetNode(i);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.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(;o.head!=null;){let c=o.pop_unsafe(),h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe();s(c,c);let h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}}CbTypeset(t,n,s){let i=Lt._zpp,l=Ct.UCbType,o=Ct.VCbType,r=Ct.WCbType,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,h=p.elt;if(c==h){let u=this._allocCbTypeNode(i);u.elt=c,u.next=r.head,r.head=u,r.modified=!0,r.length++,a=a.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++,a=a.next}else{let u=this._allocCbTypeNode(i);u.elt=h,u.next=o.head,o.head=u,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbTypeNode(i);c.elt=a.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,a=a.next}for(;p!=null;){let c=this._allocCbTypeNode(i);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.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(;o.head!=null;){let c=o.pop_unsafe(),h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe();s(c,c);let h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}}with_uniquesets(t){let n=Lt._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,o)=>{this.CbSetset(l.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),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 o=l.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=l.parent;a!=null&&(l==a.prev?a.prev=null:a.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=a}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=Lt._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 o=s.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;i==null?(a.next=o.head,o.head=a):(a.next=i.next,i.next=a),o.pushmod=o.modified=!0,o.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){Ct.UCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.VCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.WCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.UCbType=new t.util.ZNPList_ZPP_CbType,Ct.VCbType=new t.util.ZNPList_ZPP_CbType,Ct.WCbType=new t.util.ZNPList_ZPP_CbType}};Ct.UCbSet=null,Ct.VCbSet=null,Ct.WCbSet=null,Ct.UCbType=null,Ct.VCbType=null,Ct.WCbType=null;var ul=Ct;var Hn=class Hn{constructor(){this.outer=null;this.handler=null;this.includes=null;this.excludes=null;this.wrap_includes=null;this.wrap_excludes=null;let e=Hn._zpp;this.includes=new e.util.ZNPList_ZPP_CbType,this.excludes=new e.util.ZNPList_ZPP_CbType}static argument(e){let t=Hn._nape;return e==null?new t.callbacks.OptionType:e instanceof t.callbacks.OptionType?e:new t.callbacks.OptionType().including(e)}setup_includes(){let e=Hn._zpp;this.wrap_includes=e.util.ZPP_CbTypeList.get(this.includes,!0)}setup_excludes(){let e=Hn._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,o=s.elt;if(l===o){n=!0;break}else l.id<o.id?i=i.next:s=s.next}return n}insertOrdered(e,t){let n=Hn._zpp,s=null,i=e.head;for(;i!=null;){let o=i.elt;if(t.id<o.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=Hn._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 o=l.zpp_inner.user_length;i.zpp_critical=!0;let r;if(i.zpp_i<o?r=!0:(i.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,r=!1),!r)break;i.zpp_critical=!1;let a=i.zpp_inner.at(i.zpp_i++);this.append_type(e,a.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 o=l;this.append_type(e,o.zpp_inner)}}else throw new Error("Error: Cannot append non-CbType or CbType list value")}};Hn._nape=null,Hn._zpp=null;var ws=Hn;var vn=class vn{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=vn._zpp;this.id=yn.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=vn._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=vn._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 r=s.elt;if(e.id<r.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 o=l;n==null?(o.next=i.head,i.head=o):(o.next=n.next,n.next=o),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=vn._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=vn._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=vn._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=vn._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 m=i.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 d=m.zpp_inner.user_length;i.zpp_critical=!0;let y;if(i.zpp_i<d?y=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,y=!1),!y)break;i.zpp_critical=!1;let b=i.zpp_inner.at(i.zpp_i++);e.zpp_inner.wrap_cbTypes==null&&e.zpp_inner.setupcbTypes();let f=e.zpp_inner.wrap_cbTypes;f.zpp_inner.reverse_flag?f.push(b):f.unshift(b)}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 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 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=vn._findRoot(e),s=vn._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}};vn._nape=null,vn._zpp=null;var Ze=vn;var Un=class v{constructor(){this.id=0;this.bc=null;this.cb=null}static dict(e,t){let n=new v;return n.id=e,n.bc=t,n}static todo(e,t){let n=new v;return n.id=e,n.cb=t,n}};var Bs=class Bs extends Ze{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=Bs._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 o=t[l];if(++l,o.id==this.b1.id){i=o.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(Un.todo(this.b1.id,o=>{s.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let o=t[l];if(++l,o.id==this.b2.id){i=o.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(Un.todo(this.b2.id,o=>{s.zpp_inner.b2=o.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 o=1/(1+this.gamma),r=t*l*l*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-i*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,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 o=this.b1,r=-this.scale*l*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,h=1-.5*c,u=1-c*c/8,x=(h*o.axisx+r*o.axisy)*u;o.axisy=(h*o.axisy-r*o.axisx)*u,o.axisx=x}let a=this.b2,p=this.ratio*this.scale*l*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,h=1-.5*c,u=1-c*c/8,x=(h*a.axisx+p*a.axisy)*u;a.axisy=(h*a.axisy-p*a.axisx)*u,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 s=n*n,i=1-.5*s,l=1-s*s/8,o=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=o}}static _copyBody(t,n,s,i,l){if(t!=null&&s!=null){let o=null;for(let r=0;r<t.length;r++){let a=t[r];if(a.id==s.id){o=a.bc;break}}o!=null?i.zpp_inner_zn[l]=o.zpp_inner:n.push(Un.todo(s.id,function(r){i.zpp_inner_zn[l]=r.zpp_inner}))}}};Bs._wrapFn=null,Bs._createFn=null;var qe=Bs;var Nt=class Nt{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 Nt.zpp_pool==null?s=new Nt:(s=Nt.zpp_pool,Nt.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(Nt._wrapFn)this.outer=Nt._wrapFn(this);else{this.outer=new Nt._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=Nt.zpp_pool,Nt.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 Nt.zpp_pool==null?n=new Nt:(n=Nt.zpp_pool,Nt.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+" }"}};Nt.zpp_pool=null,Nt._nape=null,Nt._zpp=null,Nt._wrapFn=null;var ae=Nt;var Li=class Li extends Ze{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<Ze._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=Ze._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=Li._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=Li._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 o=Li._createFn(null,null,i,l.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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._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<Ze._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 o=1/(1+this.gamma),r=t*l*l*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-i*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,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,o,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s),p=r*r+a*a;if(p<Ze._nape.Config.epsilon)r=0,a=0,p=0,o=!0;else{p=Math.sqrt(p);let h=1/p;r*=h,a*=h,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<Ze._nape.Config.constraintLinearSlop*Ze._nape.Config.constraintLinearSlop)return!1;if(c*=.5,c*c>6){let m=this.b1.smass+this.b2.smass;if(m>Ze._nape.Config.epsilon){let d=.75/m;if(t=-c*d,this.equal||t<0){let y=t*this.b1.imass;this.b1.posx-=r*y,this.b1.posy-=a*y;let b=t*this.b2.imass;this.b2.posx+=r*b,this.b2.posy+=a*b,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s);let f=r*r+a*a;if(f<Ze._nape.Config.epsilon)r=0,a=0,f=0;else{f=Math.sqrt(f);let P=1/f;r*=P,a*=P,this.equal?f-=this.jointMax:f<this.jointMin?(f=this.jointMin-f,r=-r,a=-a):f>this.jointMax?f-=this.jointMax:(r=0,a=0,f=0)}c=f,c*=.5}}}let h=a*n-r*s,u=a*i-r*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 m=this.b1.imass*t;this.b1.posx-=r*m,this.b1.posy-=a*m;let d=this.b2.imass*t;this.b2.posx+=r*d,this.b2.posy+=a*d,qe._rotateBody(this.b1,-h*this.b1.iinertia*t),qe._rotateBody(this.b2,u*this.b2.iinertia*t)}}return!1}draw(t){}static _setupAnchorVec2(t,n,s,i){let l=Ze._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(ye.poolVec2==null?a=new l.geom.Vec2:(a=ye.poolVec2,ye.poolVec2=a.zpp_pool,a.zpp_pool=null,a.zpp_disp=!1,a==ye.nextVec2&&(ye.nextVec2=null)),a.zpp_inner==null){let p;ae.zpp_pool==null?p=new ae:(p=ae.zpp_pool,ae.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 h=a.zpp_inner;if(h._validate!=null&&h._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 u=a.zpp_inner;u._validate!=null&&u._validate(),c=a.zpp_inner.y==r}else c=!1;if(!c){a.zpp_inner.x=o,a.zpp_inner.y=r;let u=a.zpp_inner;u._invalidate!=null&&u._invalidate(u)}}return a.zpp_inner.weak=!1,a.zpp_inner._inuse=!0,a.zpp_inner._validate=s,a.zpp_inner._invalidate=i,a}};Li._wrapFn=null,Li._createFn=null;var yi=Li;var js=class js extends Ze{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=Ze._nape,o=Ze._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 l.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 h=r.zpp_inner;h._validate!=null&&h._validate(),c=r.zpp_inner.y==n}else c=!1;if(!c){r.zpp_inner.x=t,r.zpp_inner.y=n;let h=r.zpp_inner;h._invalidate!=null&&h._invalidate(h)}}return r.zpp_inner.weak=!1,r.zpp_inner._inuse=!0,r.zpp_inner._validate=s,r.zpp_inner._invalidate=i,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,s=1/Math.sqrt(t);this.nlocalx*=s,this.nlocaly*=s}}bodyImpulse(t){let n=Ze._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 o=l.zpp_inner_zn.wrap_a2,r=this.outer_zn;r.zpp_inner_zn.wrap_n==null&&r.zpp_inner_zn.setup_n();let a=js._createFn(null,null,i,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=Ze._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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._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,o=this.nrelx*s+this.nrely*i;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=s+this.a1relx,a=i+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 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+o*o>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),m=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=o;let y=-m;this.biasx*=y,this.biasy*=y;let b=this.maxError,f=this.biasx*this.biasx+this.biasy*this.biasy;if(f>b*b){let P=b*(1/Math.sqrt(f));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,o=this.biasy-i,r=this.kMassa*l+this.kMassb*o;o=this.kMassb*l+this.kMassc*o,l=r;let a=this.gamma;l-=this.jAccx*a,o-=this.jAccy*a;let p=this.jAccx,c=this.jAccy;if(this.jAccx+=l,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 b=this.jMax,f=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(f>b*b){let P=b*(1/Math.sqrt(f));this.jAccx*=P,this.jAccy*=P}}let h=this.jAccx-p,u=this.jAccy-c,x=this.scale*this.nrelx*u-this.nrely*h,m=this.nrelx*h+this.scale*this.nrely*u,d=this.b1.imass;this.b1.velx-=x*d,this.b1.vely-=m*d;let y=this.b2.imass;return this.b2.velx+=x*y,this.b2.vely+=m*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=Ze._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,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-i,p=this.b2.posy+r-this.b1.posy-l,c,h=p*n-a*s,u=n*a+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,m,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 A=.8/Z,S=A*(s*h-c*n*u),L=A*(n*h*c-s*h),T=this.b1.imass;this.b1.posx-=S*T,this.b1.posy-=L*T;let G=this.b2.imass;this.b2.posx+=S*G,this.b2.posy+=L*G,a=this.b2.posx+o-this.b1.posx-i,p=this.b2.posy+r-this.b1.posy-l,h=p*n-a*s,u=n*a+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 y=a+i,b=p+l,f=n*y+s*b,P=b*n-y*s,k=n*o+s*r,_=r*n-o*s,z=this.b1.smass+this.b2.smass+f*f*this.b1.sinertia+k*k*this.b2.sinertia,C=-c*(f*P*this.b1.sinertia+k*_*this.b2.sinertia),w=c*c*(this.b1.smass+this.b2.smass+P*P*this.b1.sinertia+_*_*this.b2.sinertia);x=-h,m=-u;let g=z*w-C*C;if(g!==g)m=0,x=m;else if(g==0)z!=0?x/=z:x=0,w!=0?m/=w:m=0;else{let Z=1/g,A=Z*(w*x-C*m);m=Z*(z*m-C*x),x=A}m>0&&(m=0);let O=c*n*m-s*x,E=n*x+c*s*m,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,qe._rotateBody(this.b1,(c*P*m-f*x)*this.b1.iinertia),qe._rotateBody(this.b2,(k*x-c*_*m)*this.b2.iinertia),!1}draw(t){}};js._wrapFn=null,js._createFn=null;var mi=js;var Ts=class Ts extends Ze{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=Ts._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 o=t[l];if(++l,o.id==this.b1.id){i=o.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(Un.todo(this.b1.id,o=>{s.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let o=t[l];if(++l,o.id==this.b2.id){i=o.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(Un.todo(this.b2.id,o=>{s.zpp_inner.b2=o.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}};Ts._wrapFn=null,Ts._createFn=null;var bi=Ts;var Ls=class Ls extends Ze{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=Ze._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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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 o=Ls._createFn(null,null,i,l.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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._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 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 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 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,l=r}else{let r=1/i,a=this.kMassc*r;this.kMassc=this.kMassa*r,this.kMassa=a,this.kMassb*=-r,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 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 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 m=u*(1/Math.sqrt(x));this.biasx*=m,this.biasy*=m}}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)),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 o=this.gamma;s-=this.jAccx*o,i-=this.jAccy*o;let r=this.jAccx,a=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 m=u*(1/Math.sqrt(x));this.jAccx*=m,this.jAccy*=m}}s=this.jAccx-r,i=this.jAccy-a;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=Ze._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,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s);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 z=this.b1.smass+this.b2.smass;if(z>t.Config.epsilon){let C=.75/z;p=-o*C,c=-r*C;let w=20,g=p*p+c*c;if(g>w*w){let N=w*(1/Math.sqrt(g));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,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s);let M=.5;o*=M,r*=M}}let h=this.b1.smass+this.b2.smass,u=h,x=0,m=h;if(this.b1.sinertia!=0){let z=n*this.b1.sinertia,C=s*this.b1.sinertia;u+=C*s,x+=-C*n,m+=z*n}if(this.b2.sinertia!=0){let z=i*this.b2.sinertia,C=l*this.b2.sinertia;u+=C*l,x+=-C*i,m+=z*i}p=-o,c=-r;let d=6,y=p*p+c*c;if(y>d*d){let z=d*(1/Math.sqrt(y));p*=z,c*=z}let b=u*m-x*x;if(b!=b)c=0,p=0;else if(b==0)u!=0?p/=u:p=0,m!=0?c/=m:c=0;else{let z=1/b,C=z*(m*p-x*c);c=z*(u*c-x*p),p=C}let f=this.b1.imass;this.b1.posx-=p*f,this.b1.posy-=c*f;let P=this.b2.imass;this.b2.posx+=p*P,this.b2.posy+=c*P;let k=-(c*n-p*s)*this.b1.iinertia;qe._rotateBody(this.b1,k);let _=(c*i-p*l)*this.b2.iinertia;return qe._rotateBody(this.b2,_),!1}draw(t){}};Ls._wrapFn=null,Ls._createFn=null;var fi=Ls;var Ds=class Ds extends Ze{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),o=Math.sqrt(n*n+s*s),r=Math.sqrt(i*i+l*l),a=o+this.ratio*r;return this.equal||a<this.jointMin||a>this.jointMax?t=!1:t=!0,t}bodyImpulse(t){let n=Ze._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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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 o=l.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=Ds._createFn(null,null,null,null,i,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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component),this.b3.type==2&&Ze._unionComponents(this.b3.component,this.component),this.b4.type==2&&Ze._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),o=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),r=Math.sqrt(s*s+i*i),a=Math.sqrt(l*l+o*o);if(r!=0){let h=1/r;this.n12x=s*h,this.n12y=i*h}if(a!=0){let h=1/a;this.n34x=l*h,this.n34y=o*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=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 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 m=1/(1+this.gamma),d=t*x*x*this.gamma;this.gamma*=m,this.kMass*=m,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 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=Ze._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,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,h,u=this.n12x,x=this.n12y,m=this.n34x,d=this.n34y,y=this.b2.posx+l-(this.b1.posx+s),b=this.b2.posy+o-(this.b1.posy+i),f=this.b4.posx+p-(this.b3.posx+r),P=this.b4.posy+c-(this.b3.posy+a),k=Math.sqrt(y*y+b*b),_=Math.sqrt(f*f+P*P);if(k!=0){let w=1/k;u=y*w,x=b*w}if(_!=0){let w=1/_;m=f*w,d=P*w;let g=this.ratio;m*=g,d*=g}else{let w=this.ratio/Math.sqrt(m*m+d*d);m*=w,d*=w}let z=k+this.ratio*_;this.equal?(z-=this.jointMax,h=!1):z<this.jointMin?(z=this.jointMin-z,u=-u,x=-x,m=-m,d=-d,h=!1):z>this.jointMax?(z-=this.jointMax,h=!1):(u=0,x=0,m=0,d=0,z=0,h=!0);let C=z;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 A=this.b1.smass+this.b2.smass;if(A>t.Config.epsilon){let S=.75/A;if(n=-C*S,this.equal||n<0){let L=n*this.b1.imass;this.b1.posx-=u*L,this.b1.posy-=x*L;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-=m*G,this.b3.posy-=d*G;let q=n*this.b4.imass;this.b4.posx+=m*q,this.b4.posy+=d*q;let R=this.b2.posx+l-(this.b1.posx+s),j=this.b2.posy+o-(this.b1.posy+i),V=this.b4.posx+p-(this.b3.posx+r),K=this.b4.posy+c-(this.b3.posy+a),$=Math.sqrt(R*R+j*j),Y=Math.sqrt(V*V+K*K);if($!=0){let ee=1/$;u=R*ee,x=j*ee}if(Y!=0){let ee=1/Y;m=V*ee,d=K*ee;let J=this.ratio;m*=J,d*=J}else{let ee=this.ratio/Math.sqrt(m*m+d*d);m*=ee,d*=ee}let X=$+this.ratio*Y;this.equal?X-=this.jointMax:X<this.jointMin?(X=this.jointMin-X,u=-u,x=-x,m=-m,d=-d):X>this.jointMax?X-=this.jointMax:(u=0,x=0,m=0,d=0,X=0),C=X,C*=.5}}}let w=x*s-u*i,g=x*l-u*o,O=d*r-m*a,E=d*p-m*c,M=this.ratio*this.ratio,N=this.b1.smass+this.b2.smass+M*(this.b3.smass+this.b4.smass)+this.b1.sinertia*w*w+this.b2.sinertia*g*g+this.b3.sinertia*O*O+this.b4.sinertia*E*E;this.b1==this.b4&&(N-=2*((u*m+x*d)*this.b1.smass+w*E*this.b1.sinertia)),this.b1==this.b3&&(N+=2*((u*m+x*d)*this.b1.smass+w*O*this.b1.sinertia)),this.b2==this.b3&&(N-=2*((u*m+x*d)*this.b2.smass+g*O*this.b2.sinertia)),this.b2==this.b4&&(N+=2*((u*m+x*d)*this.b2.smass+g*E*this.b2.sinertia));let Z=N;if(Z!=0&&(Z=1/Z),n=-C*Z,this.equal||n<0){let A=this.b1.imass*n;this.b1.posx-=u*A,this.b1.posy-=x*A;let S=this.b2.imass*n;this.b2.posx+=u*S,this.b2.posy+=x*S;let L=this.b3.imass*n;this.b3.posx-=m*L,this.b3.posy-=d*L;let T=this.b4.imass*n;this.b4.posx+=m*T,this.b4.posy+=d*T,qe._rotateBody(this.b1,-w*this.b1.iinertia*n),qe._rotateBody(this.b2,g*this.b2.iinertia*n),qe._rotateBody(this.b3,-O*this.b3.iinertia*n),qe._rotateBody(this.b4,E*this.b4.iinertia*n)}}return!1}draw(t){}};Ds._wrapFn=null,Ds._createFn=null;var zi=Ds;var vs=class{constructor(e,t){this.cnt=0;this.body=null;this.cnt=e,this.body=t}};var xl=class extends Ze{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=Ze._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 vs(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=Ze._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 o=i.parent;i.parent=l,l=i,i=o}for(;l!=null;){let o=l.parent;l.parent=i,l=o}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 o=i.parent;i.parent=l,l=i,i=o}for(;l!=null;){let o=l.parent;l.parent=i,l=o}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 o=this.bodies[l].body;for(let r=l+1;r<i;r++){let a=this.bodies[r].body;if(o.id===t&&a.id===n||o.id===n&&a.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 o=0;o<s-1;o++)i+=this.L[s*this.dim+o]*this.L[s*this.dim+o];let l=Math.sqrt(t[n++]-i);if(this.L[s*this.dim+s]=l,l!==0){l=1/l;for(let o=s+1;o<this.dim;o++){let r=0;for(let a=0;a<s-1;a++)r+=this.L[o*this.dim+a]*this.L[s*this.dim+a];this.L[o*this.dim+s]=l*(t[n++]-r)}}else{for(let o=s+1;o<this.dim;o++)this.L[o*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 o=0;o<s;o++)i-=t[s*this.dim+o]*this.y[o];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 o=this.y[i];for(let r=i+1;r<this.dim;r++)o-=t[r*this.dim+i]*n[r];n[i]=o/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 o=0;o<this.dim;o++)this.bias[o]*=-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,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(),i.velx=l+o.zpp_inner.x*s;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 h=c.zpp_inner;h._validate!=null&&h._validate(),a.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let d=m.zpp_inner;d._validate!=null&&d._validate(),u.angvel=x+m.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,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(),i.velx=l+o.zpp_inner.x*s;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 h=c.zpp_inner;h._validate!=null&&h._validate(),a.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let d=m.zpp_inner;d._validate!=null&&d._validate(),u.angvel=x+m.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<Ze._nape.Config.constraintLinearSlop*Ze._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,o=l.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(),l.posx=o+r.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 m=x.zpp_inner;m._validate!=null&&m._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 y=d*d,b=1-.5*y,f=1-y*y/8,P=(b*s.axisx+d*s.axisy)*f;s.axisy=(b*s.axisy-d*s.axisx)*f,s.axisx=P}}return!1}draw(t){this.outer_zn.__draw(t)}};var Fs=class Fs extends Ze{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=Ze._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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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 o=Fs._createFn(null,null,i,l.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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._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 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 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 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,l=o}else{let o=1/i,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),h=o*(this.kMassb*this.kMassc-this.kMassa*this.kMasse),u=o*(this.kMassa*this.kMassd-this.kMassb*this.kMassb);this.kMassa=r,this.kMassb=a,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 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 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,o=this.biasz-s,r=this.kMassa*i+this.kMassb*l+this.kMassc*o,a=this.kMassb*i+this.kMassd*l+this.kMasse*o;o=this.kMassc*i+this.kMasse*l+this.kMassf*o,i=r,l=a,i-=this.jAccx*this.gamma,l-=this.jAccy*this.gamma,o-=this.jAccz*this.gamma;let p=this.jAccx,c=this.jAccy,h=this.jAccz;if(this.jAccx+=i,this.jAccy+=l,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 m=this.jMax,d=this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz;if(d>m*m){let y=m*(1/Math.sqrt(d));this.jAccx*=y,this.jAccy*=y,this.jAccz*=y}}i=this.jAccx-p,l=this.jAccy-c,o=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+o)*this.b1.iinertia,this.b2.angvel+=(l*this.a2relx-i*this.a2rely+o)*this.b2.iinertia,!1}applyImpulsePos(){let t=Ze._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,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,p,c,h;if(this.breakUnderError&&o*o+r*r+a*a>this.maxError*this.maxError)return!0;let u=!0;o*o+r*r<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(u=!1,o=0,r=0);let x=t.Config.constraintAngularSlop;if(a*a<x*x)if(u)a=0;else return!1;if(o*=.5,r*=.5,a*=.5,o*o+r*r>6){let S=this.b1.smass+this.b2.smass;if(S>t.Config.epsilon){let L=.75/S;p=-o*L,c=-r*L;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,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,o*=.5,r*=.5,a*=.5}}let m=this.b1.smass+this.b2.smass,d=m,y=0,b=m,f=0,P=0,k=0;if(this.b1.sinertia!=0){let S=n*this.b1.sinertia,L=s*this.b1.sinertia;d+=L*s,y+=-L*n,b+=S*n,f+=-L,P+=S,k+=this.b1.sinertia}if(this.b2.sinertia!=0){let S=i*this.b2.sinertia,L=l*this.b2.sinertia;d+=L*l,y+=-L*i,b+=S*i,f+=-L,P+=S,k+=this.b2.sinertia}p=-o,c=-r,h=-a;let _=6,z=p*p+c*c;if(z>_*_){let S=_*(1/Math.sqrt(z));p*=S,c*=S}let w=h<-.25,g=d*(b*k-P*P)+y*(f*P-y*k)+f*(y*P-f*b);if(g!=g)h=0,c=h,p=c;else if(g==0)d!=0?p/=d:p=0,b!=0?c/=b:c=0,k!=0?h/=k:h=0;else{let S=1/g,L=P*f-y*k,T=y*P-f*b,G=y*f-d*P,q=S*(p*(b*k-P*P)+c*L+h*T),R=S*(p*L+c*(d*k-f*f)+h*G);h=S*(p*T+c*G+h*(d*b-y*y)),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;qe._rotateBody(M,N);let Z=this.b2,A=(c*i-p*l+h)*this.b2.iinertia;return qe._rotateBody(Z,A),!1}draw(t){}};Fs._wrapFn=null,Fs._createFn=null;var Pi=Fs;var nt=class nt{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()),nt.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID]}wrapper(){if(this.outer==null){let e=nt._nape;nt.internal=!0,this.type==nt.COL?(this.colarb.outer_zn=nt._createColArb(),this.outer=this.colarb.outer_zn):this.type==nt.FLUID?(this.fluidarb.outer_zn=nt._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,nt.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=nt._zpp;this.cleared=!0,(t==null||this.b2==t)&&nt._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&nt._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=nt._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=s,nt._addToArbiterList(this.b1.arbiters,this,i),nt._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=nt._zpp;this.cleared||(nt._removeFromArbiterList(this.b1.arbiters,this,e),nt._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,o;s==null?(l=e.head,o=l.next,e.head=o,e.head==null&&(e.pushmod=!0)):(l=s.next,o=l.next,s.next=o,o==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}}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++}};nt._nape=null,nt._zpp=null,nt.internal=!1,nt._createColArb=null,nt._createFluidArb=null,nt.COL=1,nt.FLUID=4,nt.SENSOR=2,nt.types=[];var Ie=nt;var Rs=class Rs extends Ie{constructor(){super(),this.next=null,this.type=Ie.SENSOR,this.sensorarb=this}alloc(){}free(){}assign(e,t,n,s){this.sup_assign(e,t,n,s)}retire(){this.sup_retire(),this.next=Rs.zpp_pool,Rs.zpp_pool=this}makemutable(){}makeimmutable(){}};Rs.zpp_pool=null;var Ot=Rs;var Gs=class Gs extends Ie{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=Ie.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=Ie._zpp,n=Ie._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 o=s.zpp_inner;if(o._validate!=null&&o._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 r=s.zpp_inner;r._validate!=null&&r._validate(),l=s.zpp_inner.y==0}else l=!1;if(!l){s.zpp_inner.x=0,s.zpp_inner.y=0;let r=s.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}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=Gs.zpp_pool,Gs.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=Ie._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,o;this.ws1.fluidEnabled&&this.ws1.fluidProperties.wrap_gravity!=null?(l=this.ws1.fluidProperties.gravityx,o=this.ws1.fluidProperties.gravityy):(l=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 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-=o*x}else if(h<u){let x=h+u;p+=r*x,c+=a*x}else{let x=l+r,m=o+a,d=.5;if(x*=d,m*=d,this.ws1.worldCOMx*x+this.ws1.worldCOMy*m>this.ws2.worldCOMx*x+this.ws2.worldCOMy*m){let y=h+u;p-=x*y,c-=m*y}else{let y=h+u;p+=x*y,c+=m*y}}}else if(this.ws1.fluidEnabled){let h=this.overlap*this.ws1.fluidProperties.density;p-=l*h,c-=o*h}else if(this.ws2.fluidEnabled){let h=this.overlap*this.ws2.fluidProperties.density;p+=r*h,c+=a*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 y=2*Math.PI*h;this.agamma=1/(n*y*(2+y*n));let b=1/(1+this.agamma);this.agamma*=b,this.wMass*=b}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,y=1/Math.sqrt(d);this.nx=u*y,this.ny=x*y}let m=0;if(this.ws1.fluidEnabled){let d=-this.ws1.fluidProperties.viscosity*this.overlap/this.ws2.area;if(this.ws2.type==0)m-=d*this.ws2.circle.radius*s.Config.fluidLinearDrag/(2*this.ws2.circle.radius*Math.PI);else{let y=this.ws2.polygon,b=0,f=0,P=y.edges.head;for(;P!=null;){let k=P.elt;b+=k.length;let _=d*k.length*(k.gnormx*this.nx+k.gnormy*this.ny);_>0&&(_*=-s.Config.fluidVacuumDrag),f-=_*.5*s.Config.fluidLinearDrag,P=P.next}m+=f/b}}if(this.ws2.fluidEnabled){let d=-this.ws2.fluidProperties.viscosity*this.overlap/this.ws1.area;if(this.ws1.type==0)m-=d*this.ws1.circle.radius*s.Config.fluidLinearDrag/(2*this.ws1.circle.radius*Math.PI);else{let y=this.ws1.polygon,b=0,f=0,P=y.edges.head;for(;P!=null;){let k=P.elt;b+=k.length;let _=d*k.length*(k.gnormx*this.nx+k.gnormy*this.ny);_>0&&(_*=-s.Config.fluidVacuumDrag),f-=_*.5*s.Config.fluidLinearDrag,P=P.next}m+=f/b}}if(m!=0){let d=this.b1.smass+this.b2.smass,y=d,b=0,f=d;if(this.b1.sinertia!=0){let z=this.r1x*this.b1.sinertia,C=this.r1y*this.b1.sinertia;y+=C*this.r1y,b+=-C*this.r1x,f+=z*this.r1x}if(this.b2.sinertia!=0){let z=this.r2x*this.b2.sinertia,C=this.r2y*this.b2.sinertia;y+=C*this.r2y,b+=-C*this.r2x,f+=z*this.r2x}let P=y*f-b*b;if(P!==P)f=0,b=f,y=b;else if(P==0)y!=0?y=1/y:y=0,f!=0?f=1/f:f=0,b=0;else{let z=1/P,C=f*z;f=y*z,y=C,b*=-z}this.vMassa=y,this.vMassb=b,this.vMassc=f;let k=2*Math.PI*m;this.lgamma=1/(n*k*(2+k*n));let _=1/(1+this.lgamma);this.lgamma*=_,this.vMassa*=_,this.vMassb*=_,this.vMassc*=_}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 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}}};Gs.zpp_pool=null;var Pt=Gs;var wi=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 mn=class mn{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 wi}wrapper(){return this.outer==null&&(mn._wrapFn?this.outer=mn._wrapFn(this):(mn.internal=!0,this.outer=new mn._nape.dynamics.Contact,mn.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=mn._zpp,t=mn._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 o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){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 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}};mn._nape=null,mn._zpp=null,mn.zpp_pool=null,mn.internal=!1,mn._wrapFn=null;var Pe=mn;var wt=class wt extends Ie{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=0;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 wi,this.type=Ie.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=Ie._zpp,n=Ie._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!==s||i!==i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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,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){Pe.zpp_pool==null?a=new Pe:(a=Pe.zpp_pool,Pe.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=s,this.ny=i,a.dist=l,a.stamp=this.stamp,a.posOnly=r,a}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=wt.zpp_pool,wt.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=Ie._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=Ie._nape,n=!0,s=null,i=null,l=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=wt._eraseFromList(this.contacts,s),l=wt._eraseFromList(this.innards,i),r.arbiter=null,r.next=Pe.zpp_pool,Pe.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),s=o,i=l,l=l.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=Ie._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,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,h=this.contacts.next;for(;h!=null;){let u=h;if(u.stamp+n.Config.arbiterExpirationDelay<this.stamp){h=wt._eraseFromList(this.contacts,a),c=wt._eraseFromList(this.innards,p),u.arbiter=null,u.next=Pe.zpp_pool,Pe.zpp_pool=u;continue}let x=u.inner,m=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,y=i+this.b2.sinertia*(d*d);d=x.r1x*this.nx+x.r1y*this.ny,y+=this.b1.sinertia*(d*d),x.tMass=y<n.Config.epsilon*n.Config.epsilon?0:1/y,d=this.ny*x.r2x-this.nx*x.r2y;let b=i+this.b2.sinertia*(d*d);d=this.ny*x.r1x-this.nx*x.r1y,b+=this.b1.sinertia*(d*d),x.nMass=b<n.Config.epsilon*n.Config.epsilon?0:1/b;let f=this.b2.angvel+this.b2.kinangvel,P=this.b2.velx+this.b2.kinvelx-x.r2y*f,k=this.b2.vely+this.b2.kinvely+x.r2x*f;f=this.b1.angvel+this.b1.kinangvel,P-=this.b1.velx+this.b1.kinvelx-x.r1y*f,k-=this.b1.vely+this.b1.kinvely+x.r1x*f;let _=this.nx*P+this.ny*k;u.elasticity=this.restitution,x.bounce=_*u.elasticity,x.bounce>-n.Config.elasticThreshold&&(x.bounce=0);let z=k*this.nx-P*this.ny,C=n.Config.staticFrictionThreshold;z*z>C*C?x.friction=this.dyn_fric:x.friction=this.stat_fric,x.jnAcc*=s,x.jtAcc*=s}m!=u.active&&(this.contacts.modified=!0),a=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 m=1/x,d=this.kMassc*m;this.kMassc=this.kMassa*m,this.kMassa=d,this.kMassb*=-m}}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,o=l-s;o>i?o=i:o<-i&&(o=-i),s=o-l,this.c1.jtAcc=o;let r=-this.ny*s,a=this.nx*s;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*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,o=l-s,o>i?o=i:o<-i&&(o=-i),s=o-l,this.c2.jtAcc=o,r=-this.ny*s,a=this.nx*s,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*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),m=p*this.nx+c*this.ny+this.surfacey+this.c2.bounce-(this.Kb*h+this.Kc*u),d=-(this.kMassa*x+this.kMassb*m),y=-(this.kMassb*x+this.kMassc*m);d>=0&&y>=0?(x=d-h,m=y-u,this.c1.jnAcc=d,this.c2.jnAcc=y):(d=-this.c1.nMass*x,d>=0&&this.Kb*d+m>=0?(x=d-h,m=-u,this.c1.jnAcc=d,this.c2.jnAcc=0):(y=-this.c2.nMass*m,y>=0&&this.Kb*y+x>=0?(x=-h,m=y-u,this.c1.jnAcc=0,this.c2.jnAcc=y):x>=0&&m>=0?(x=-h,m=-u,this.c1.jnAcc=this.c2.jnAcc=0):(x=0,m=0))),s=x+m,r=this.nx*s,a=this.ny*s,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*m)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*x+this.rn2a*m)*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,o=l-s,o<0&&(o=0),s=o-l,this.c1.jnAcc=o,r=this.nx*s,a=this.ny*s,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*s*this.b2.iinertia,this.b1.angvel-=this.rn1a*s*this.b1.iinertia}applyImpulsePos(){let t=Ie._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,o=n.lr1x*this.b1.axisx+n.lr1y*this.b1.axisy;l+=this.b1.posx,o+=this.b1.posy;let r=s-l,a=i-o,p=Math.sqrt(r*r+a*a),c=this.radius-t.Config.collisionSlop,h=p-c;if(r*this.nx+a*this.ny<0&&(r=-r,a=-a,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;r*=u,a*=u;let x=.5*(l+s),m=.5*(o+i),d=p-c;l=x-this.b1.posx,o=m-this.b1.posy,s=x-this.b2.posx,i=m-this.b2.posy;let y=a*l-r*o,b=a*s-r*i,f=this.b2.smass+b*b*this.b2.sinertia+this.b1.smass+y*y*this.b1.sinertia;if(f!=0){let P=-this.biasCoef*d/f,k=r*P,_=a*P;this.b1.posx-=k*this.b1.imass,this.b1.posy-=_*this.b1.imass,wt._rotateBody(this.b1,-y*this.b1.iinertia*P),this.b2.posx+=k*this.b2.imass,this.b2.posy+=_*this.b2.imass,wt._rotateBody(this.b2,b*this.b2.iinertia*P)}}}_applyImpulsePosEdge(t){let n,s,i,l,o,r=0,a=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,o=this.c1.lr1x*this.b2.axisx+this.c1.lr1y*this.b2.axisy,l+=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,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,o=this.c1.lr1x*this.b1.axisx+this.c1.lr1y*this.b1.axisy,l+=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=l*n+o*s-i-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=r*n+a*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=o-this.b1.posy,x=l-this.b2.posx,m=o-this.b2.posy;if(this.hpc2){let d=r-this.b1.posx,y=a-this.b1.posy,b=r-this.b2.posx,f=a-this.b2.posy,P=s*h-n*u,k=s*x-n*m,_=s*d-n*y,z=s*b-n*f,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*_+this.b2.sinertia*k*z,this.kMassc=C+this.b1.sinertia*_*_+this.b2.sinertia*z*z;let w=this.kMassa,g=this.kMassb,O=this.kMassc,E=p*this.biasCoef,M=c*this.biasCoef;for(;;){let N=-E,Z=-M,A=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(A!==A)N=0,Z=0;else if(A==0)this.kMassa!=0?N/=this.kMassa:N=0,this.kMassc!=0?Z/=this.kMassc:Z=0;else{let S=1/A,L=S*(this.kMassc*N-this.kMassb*Z);Z=S*(this.kMassa*Z-this.kMassb*N),N=L}if(N>=0&&Z>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,N,Z,P,_,k,z);break}if(N=-E/w,Z=0,N>=0&&g*N+M>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,N,Z,P,_,k,z);break}if(N=0,Z=-M/O,Z>=0&&g*Z+E>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,N,Z,P,_,k,z);break}break}}else{let d=s*h-n*u,y=s*x-n*m,b=this.b2.smass+y*y*this.b2.sinertia+this.b1.smass+d*d*this.b1.sinertia;if(b!=0){let f=-this.biasCoef*p/b,P=n*f,k=s*f;this.b1.posx-=P*this.b1.imass,this.b1.posy-=k*this.b1.imass,wt._rotateBody(this.b1,-d*this.b1.iinertia*f),this.b2.posx+=P*this.b2.imass,this.b2.posy+=k*this.b2.imass,wt._rotateBody(this.b2,y*this.b2.iinertia*f)}}}}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,o=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=o}}static _applyPosImpulse2(t,n,s,i,l,o,r,a,p,c){let h=(l+o)*t.imass;t.posx-=s*h,t.posy-=i*h,wt._rotateBody(t,-t.iinertia*(r*l+a*o));let u=(l+o)*n.imass;n.posx+=s*u,n.posy+=i*u,wt._rotateBody(n,n.iinertia*(p*l+c*o))}};wt.FACE1=0,wt.FACE2=1,wt.CIRCLE=2,wt.zpp_pool=null;var ut=wt;var Ut=class Ut{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 Ut._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Ut._wrapFn)this.outer=Ut._wrapFn(this);else{this.outer=new Ut._nape.dynamics.InteractionFilter;let e=this.outer.zpp_inner;e.outer=null,e.next=Ut.zpp_pool,Ut.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Ut._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Ut.zpp_pool==null?e=new Ut:(e=Ut.zpp_pool,Ut.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}};Ut.zpp_pool=null,Ut._nape=null,Ut._zpp=null,Ut._wrapFn=null;var it=Ut;var Di=class Di{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=Di._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)}};Di.SHAPE=1,Di.BODY=2,Di._zpp=null,Di._wrapFn=null;var qs=Di;var Qn=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,o=this.space.f_arbiters.head;for(;o!=null;)o.elt.active&&++l,o=o.next;this.lengths[e++]=l,this._length+=l;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 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}};Qn._nape=null,Qn._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,s){let i;return Mt.zpp_pool==null?i=new Mt:(i=Mt.zpp_pool,Mt.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(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,s=Mt._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=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._nape=null,Mt._zpp=null,Mt._wrapFn=null;var be=Mt;var fe=class fe{static get debugCapsule(){return globalThis.__napeDebugCapsule===!0}static _initStatics(e){fe.flowpoly=new e.util.ZNPList_ZPP_Vec2,fe.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?fe.circleContains(e.circle,t):e.type==1?fe.polyContains(e.polygon,t):fe.capsuleContains(e.capsule,t)}static bodyContains(e,t){let n;n=!1;let s=e.shapes.head;for(;s!=null;){let i=s.elt;if(fe.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,o=t.circle.worldCOMy-e.circle.worldCOMy;return l*l+o*o<=i*i}else if(t.type==1){let i;i=!0;let l=t.polygon.gverts.next;for(;l!=null;){let o=l,r=e.circle.radius,a=o.x-e.circle.worldCOMx,p=o.y-e.circle.worldCOMy;if(a*a+p*p<=r*r){l=l.next;continue}else{i=!1;break}}return i}else{let i=t.capsule,l=e.circle.radius-i.radius;if(l<0)return!1;let o=l*l,r=i.spine1x-e.circle.worldCOMx,a=i.spine1y-e.circle.worldCOMy;if(r*r+a*a>o)return!1;let p=i.spine2x-e.circle.worldCOMx,c=i.spine2y-e.circle.worldCOMy;return p*p+c*c<=o}else if(e.type==2)if(t.type==0){let i=e.capsule,l=fe._closestT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,t.circle.worldCOMx,t.circle.worldCOMy),o=i.spine1x+l*(i.spine2x-i.spine1x),r=i.spine1y+l*(i.spine2y-i.spine1y),a=i.radius-t.circle.radius;if(a<0)return!1;let p=t.circle.worldCOMx-o,c=t.circle.worldCOMy-r;return p*p+c*c<=a*a}else return!1;else if(t.type==0){let i;i=!0;let l=e.polygon.edges.head;for(;l!=null;){let o=l.elt;if(o.gnormx*t.circle.worldCOMx+o.gnormy*t.circle.worldCOMy+t.circle.radius<=o.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 o=l.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){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==2)return fe._capsuleContactCollide(e,t,n,s,i);if(e.type==2)return fe._capsuleContactCollide(t,e,n,!s,i);if(t.type==1)if(e.type==1){let l=!0,o=-1e100,r=-1e100,a=-1,p=null,c=null,h=e.polygon.edges.head;for(;h!=null;){let u=h.elt,x=1e100,m=t.polygon.gverts.next;for(;m!=null;){let d=m,y=u.gnormx*d.x+u.gnormy*d.y;if(y<x&&(x=y),x-u.gprojection<=o)break;m=m.next}if(x-=u.gprojection,x>=0){l=!1;break}x>o&&(o=x,p=u,a=1),h=h.next}if(l){let u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,m=1e100,d=e.polygon.gverts.next;for(;d!=null;){let y=d,b=x.gnormx*y.x+x.gnormy*y.y;if(b<m&&(m=b),m-x.gprojection<=o)break;d=d.next}if(m-=x.gprojection,m>=0){l=!1;break}m>o&&(o=m,c=x,a=2),u=u.next}if(l){let x,m,d,y;a==1?(x=e.polygon,m=t.polygon,d=p,y=1):(x=t.polygon,m=e.polygon,d=c,y=-1);let b=null,f=1e100,P=m.edges.head;for(;P!=null;){let q=P.elt,R=d.gnormx*q.gnormx+d.gnormy*q.gnormy;R<f&&(f=R,b=q),P=P.next}let k=b.gp0.x,_=b.gp0.y,z=b.gp1.x,C=b.gp1.y,w=z-k,g=C-_,O=d.gnormy*k-d.gnormx*_,E=d.gnormy*z-d.gnormx*C,M=1/(E-O),N=(-d.tp1-O)*M;if(N>i.Config.epsilon){let q=N;k+=w*q,_+=g*q}let Z=(-d.tp0-E)*M;if(Z<-i.Config.epsilon){let q=Z;z+=w*q,C+=g*q}let A=y,S=d.gnormx*A,L=d.gnormy*A;n.lnormx=d.lnormx,n.lnormy=d.lnormy,n.lproj=d.lprojection,n.radius=0,n.rev=s!=(y==-1),n.ptype=n.rev?1:0;let T=k*d.gnormx+_*d.gnormy-d.gprojection,G=z*d.gnormx+C*d.gnormy-d.gprojection;if(T>0&&G>0)return!1;{s&&(S=-S,L=-L);let q=k-d.gnormx*T*.5,R=_-d.gnormy*T*.5,j=n.rev?1:0,V=T>0;V==null&&(V=!1);let K=null,$=n.contacts.next;for(;$!=null;){let W=$;if(j==W.hash){K=W;break}$=$.next}if(K==null){Pe.zpp_pool==null?K=new Pe:(K=Pe.zpp_pool,Pe.zpp_pool=K.next,K.next=null);let W=K.inner;W.jnAcc=W.jtAcc=0,K.hash=j,K.fresh=!0,K.arbiter=n,n.jrAcc=0;let ie=n.contacts;K._inuse=!0;let oe=K;oe.next=ie.next,ie.next=oe,ie.modified=!0,ie.length++,n.innards.add(W)}else K.fresh=!1;K.px=q,K.py=R,n.nx=S,n.ny=L,K.dist=T,K.stamp=n.stamp,K.posOnly=V;let Y=K,X=1;k-=m.body.posx*X,_-=m.body.posy*X,Y.inner.lr1x=k*m.body.axisy+_*m.body.axisx,Y.inner.lr1y=_*m.body.axisy-k*m.body.axisx;let ee=z-d.gnormx*G*.5,J=C-d.gnormy*G*.5,F=n.rev?0:1,D=G>0;D==null&&(D=!1);let I=null,U=n.contacts.next;for(;U!=null;){let W=U;if(F==W.hash){I=W;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 W=I.inner;W.jnAcc=W.jtAcc=0,I.hash=F,I.fresh=!0,I.arbiter=n,n.jrAcc=0;let ie=n.contacts;I._inuse=!0;let oe=I;oe.next=ie.next,ie.next=oe,ie.modified=!0,ie.length++,n.innards.add(W)}else I.fresh=!1;I.px=ee,I.py=J,n.nx=S,n.ny=L,I.dist=G,I.stamp=n.stamp,I.posOnly=D,Y=I;let Q=1;return z-=m.body.posx*Q,C-=m.body.posy*Q,Y.inner.lr1x=z*m.body.axisy+C*m.body.axisx,Y.inner.lr1y=C*m.body.axisy-z*m.body.axisx,a==1?(n.__ref_edge1=d,n.__ref_edge2=b):(n.__ref_edge2=d,n.__ref_edge1=b),!0}}else return!1}else return!1}else{let l=-1e100,o=-1e100,r=!0,a=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){r=!1;break}x>l&&(l=x,a=u,p=c),c=c.next,h=h.next}if(r){let u=p,x=p.next==null?t.polygon.gverts.next:p.next,m=e.circle.worldCOMy*a.gnormx-e.circle.worldCOMx*a.gnormy;if(m<=u.y*a.gnormx-u.x*a.gnormy){let d=e.circle.radius,y=u.x-e.circle.worldCOMx,b=u.y-e.circle.worldCOMy,f=y*y+b*b,P;if(f>d*d)P=null;else if(f<i.Config.epsilon*i.Config.epsilon){let k=e.circle.worldCOMx,_=e.circle.worldCOMy,z=null,C=n.contacts.next;for(;C!=null;){let w=C;if(w.hash==0){z=w;break}C=C.next}if(z==null){Pe.zpp_pool==null?z=new Pe:(z=Pe.zpp_pool,Pe.zpp_pool=z.next,z.next=null);let w=z.inner;w.jnAcc=w.jtAcc=0,z.hash=0,z.fresh=!0,z.arbiter=n,n.jrAcc=0;let g=n.contacts;z._inuse=!0;let O=z;O.next=g.next,g.next=O,g.modified=!0,g.length++,n.innards.add(w)}else z.fresh=!1;z.px=k,z.py=_,n.nx=1,n.ny=0,z.dist=-d,z.stamp=n.stamp,z.posOnly=!1,P=z}else{let k=1/Math.sqrt(f),_=k<i.Config.epsilon?1e100:1/k,z=.5+(e.circle.radius-.5*d)*k;if(s){let C=e.circle.worldCOMx+y*z,w=e.circle.worldCOMy+b*z,g=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){g=E;break}O=O.next}if(g==null){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let E=g.inner;E.jnAcc=E.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let N=g;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else g.fresh=!1;g.px=C,g.py=w,n.nx=-y*k,n.ny=-b*k,g.dist=_-d,g.stamp=n.stamp,g.posOnly=!1,P=g}else{let C=e.circle.worldCOMx+y*z,w=e.circle.worldCOMy+b*z,g=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){g=E;break}O=O.next}if(g==null){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let E=g.inner;E.jnAcc=E.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let N=g;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else g.fresh=!1;g.px=C,g.py=w,n.nx=y*k,n.ny=b*k,g.dist=_-d,g.stamp=n.stamp,g.posOnly=!1,P=g}}if(P!=null){let k=P.inner;n.ptype=2;let _=u.x-t.polygon.body.posx,z=u.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=-1,s?(k.lr1x=_*t.polygon.body.axisy+z*t.polygon.body.axisx,k.lr1y=z*t.polygon.body.axisy-_*t.polygon.body.axisx,k.lr2x=e.circle.localCOMx,k.lr2y=e.circle.localCOMy):(k.lr2x=_*t.polygon.body.axisy+z*t.polygon.body.axisx,k.lr2y=z*t.polygon.body.axisy-_*t.polygon.body.axisx,k.lr1x=e.circle.localCOMx,k.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return P!=null}else if(m>=x.y*a.gnormx-x.x*a.gnormy){let d=e.circle.radius,y=x.x-e.circle.worldCOMx,b=x.y-e.circle.worldCOMy,f=y*y+b*b,P;if(f>d*d)P=null;else if(f<i.Config.epsilon*i.Config.epsilon){let k=e.circle.worldCOMx,_=e.circle.worldCOMy,z=null,C=n.contacts.next;for(;C!=null;){let w=C;if(w.hash==0){z=w;break}C=C.next}if(z==null){Pe.zpp_pool==null?z=new Pe:(z=Pe.zpp_pool,Pe.zpp_pool=z.next,z.next=null);let w=z.inner;w.jnAcc=w.jtAcc=0,z.hash=0,z.fresh=!0,z.arbiter=n,n.jrAcc=0;let g=n.contacts;z._inuse=!0;let O=z;O.next=g.next,g.next=O,g.modified=!0,g.length++,n.innards.add(w)}else z.fresh=!1;z.px=k,z.py=_,n.nx=1,n.ny=0,z.dist=-d,z.stamp=n.stamp,z.posOnly=!1,P=z}else{let k=1/Math.sqrt(f),_=k<i.Config.epsilon?1e100:1/k,z=.5+(e.circle.radius-.5*d)*k;if(s){let C=e.circle.worldCOMx+y*z,w=e.circle.worldCOMy+b*z,g=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){g=E;break}O=O.next}if(g==null){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let E=g.inner;E.jnAcc=E.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let N=g;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else g.fresh=!1;g.px=C,g.py=w,n.nx=-y*k,n.ny=-b*k,g.dist=_-d,g.stamp=n.stamp,g.posOnly=!1,P=g}else{let C=e.circle.worldCOMx+y*z,w=e.circle.worldCOMy+b*z,g=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){g=E;break}O=O.next}if(g==null){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let E=g.inner;E.jnAcc=E.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let N=g;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else g.fresh=!1;g.px=C,g.py=w,n.nx=y*k,n.ny=b*k,g.dist=_-d,g.stamp=n.stamp,g.posOnly=!1,P=g}}if(P!=null){let k=P.inner;n.ptype=2;let _=x.x-t.polygon.body.posx,z=x.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=1,s?(k.lr1x=_*t.polygon.body.axisy+z*t.polygon.body.axisx,k.lr1y=z*t.polygon.body.axisy-_*t.polygon.body.axisx,k.lr2x=e.circle.localCOMx,k.lr2y=e.circle.localCOMy):(k.lr2x=_*t.polygon.body.axisy+z*t.polygon.body.axisx,k.lr2y=z*t.polygon.body.axisy-_*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,y=a.gnormx*d,b=a.gnormy*d,f=e.circle.worldCOMx-y,P=e.circle.worldCOMy-b,k;if(s){let _=a.gnormx,z=a.gnormy,C=null,w=n.contacts.next;for(;w!=null;){let g=w;if(g.hash==0){C=g;break}w=w.next}if(C==null){Pe.zpp_pool==null?C=new Pe:(C=Pe.zpp_pool,Pe.zpp_pool=C.next,C.next=null);let g=C.inner;g.jnAcc=g.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(g)}else C.fresh=!1;C.px=f,C.py=P,n.nx=_,n.ny=z,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,k=C}else{let _=-a.gnormx,z=-a.gnormy,C=null,w=n.contacts.next;for(;w!=null;){let g=w;if(g.hash==0){C=g;break}w=w.next}if(C==null){Pe.zpp_pool==null?C=new Pe:(C=Pe.zpp_pool,Pe.zpp_pool=C.next,C.next=null);let g=C.inner;g.jnAcc=g.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(g)}else C.fresh=!1;C.px=f,C.py=P,n.nx=_,n.ny=z,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,k=C}return n.ptype=s?0:1,n.lnormx=a.lnormx,n.lnormy=a.lnormy,n.rev=!s,n.lproj=a.lprojection,n.radius=e.circle.radius,k.inner.lr1x=e.circle.localCOMx,k.inner.lr1y=e.circle.localCOMy,n.__ref_edge1=a,n.__ref_vertex=0,!0}}else return!1}else{let l=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>l*l)p=null;else if(a<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 m=x;if(m.hash==0){u=m;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 m=u.inner;m.jnAcc=m.jtAcc=0,u.hash=0,u.fresh=!0,u.arbiter=n,n.jrAcc=0;let d=n.contacts;u._inuse=!0;let y=u;y.next=d.next,d.next=y,d.modified=!0,d.length++,n.innards.add(m)}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(a),h=c<i.Config.epsilon?1e100:1/c,u=.5+(e.circle.radius-.5*l)*c;if(s){let x=e.circle.worldCOMx+o*u,m=e.circle.worldCOMy+r*u,d=null,y=n.contacts.next;for(;y!=null;){let b=y;if(b.hash==0){d=b;break}y=y.next}if(d==null){Pe.zpp_pool==null?d=new Pe:(d=Pe.zpp_pool,Pe.zpp_pool=d.next,d.next=null);let b=d.inner;b.jnAcc=b.jtAcc=0,d.hash=0,d.fresh=!0,d.arbiter=n,n.jrAcc=0;let f=n.contacts;d._inuse=!0;let P=d;P.next=f.next,f.next=P,f.modified=!0,f.length++,n.innards.add(b)}else d.fresh=!1;d.px=x,d.py=m,n.nx=-o*c,n.ny=-r*c,d.dist=h-l,d.stamp=n.stamp,d.posOnly=!1,p=d}else{let x=e.circle.worldCOMx+o*u,m=e.circle.worldCOMy+r*u,d=null,y=n.contacts.next;for(;y!=null;){let b=y;if(b.hash==0){d=b;break}y=y.next}if(d==null){Pe.zpp_pool==null?d=new Pe:(d=Pe.zpp_pool,Pe.zpp_pool=d.next,d.next=null);let b=d.inner;b.jnAcc=b.jtAcc=0,d.hash=0,d.fresh=!0,d.arbiter=n,n.jrAcc=0;let f=n.contacts;d._inuse=!0;let P=d;P.next=f.next,f.next=P,f.modified=!0,f.length++,n.innards.add(b)}else d.fresh=!1;d.px=x,d.py=m,n.nx=o*c,n.ny=r*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(e.type>t.type){let s=e;e=t,t=s}return fe.testCollide(e,t)}static testCollide(e,t){let n=me();if(t.type==2)return fe._capsuleTestCollide(e,t);if(t.type==1)if(e.type==1){let s=!0,i=e.polygon.edges.head;for(;i!=null;){let l=i.elt,o=1e100,r=t.polygon.gverts.next;for(;r!=null;){let a=r,p=l.gnormx*a.x+l.gnormy*a.y;p<o&&(o=p),r=r.next}if(o-=l.gprojection,o>0){s=!1;break}i=i.next}if(s){let l=t.polygon.edges.head;for(;l!=null;){let o=l.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){s=!1;break}l=l.next}return s}else return!1}else{let s=null,i=null,l=!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){l=!1;break}c>o&&(o=c,s=p,i=r),r=r.next,a=a.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,m=p.y-e.circle.worldCOMy;return x*x+m*m<=u*u}else if(h>=c.y*s.gnormx-c.x*s.gnormy){let u=e.circle.radius,x=c.x-e.circle.worldCOMx,m=c.y-e.circle.worldCOMy;return x*x+m*m<=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(e.type==2||t.type==2)return fe._capsuleFlowCollide(e,t,n,s);if(t.type==1)if(e.type==1){let i=[],l=[],o=!0,r=!0,a=e.polygon.edges.head;for(;a!=null;){let p=a.elt,c=1e100,h=0,u=t.polygon.gverts.next;for(;u!=null;){let x=u,m=p.gnormx*x.x+p.gnormy*x.y;m<c&&(c=m),m>=p.gprojection+s.Config.epsilon&&(l[h]=!0,r=!1),++h,u=u.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 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,m=x;x=x.next;let d=x;for(x=x.next;x!=null;){let _=x;u+=d.x*(_.y-m.y);let z=_.y*d.x-_.x*d.y;h.localCOMx+=(d.x+_.x)*z,h.localCOMy+=(d.y+_.y)*z,m=d,d=_,x=x.next}x=h.lverts.next;let y=x;u+=d.x*(y.y-m.y);let b=y.y*d.x-y.x*d.y;h.localCOMx+=(d.x+y.x)*b,h.localCOMy+=(d.y+y.y)*b,m=d,d=y,x=x.next;let f=x;u+=d.x*(f.y-m.y);let P=f.y*d.x-f.x*d.y;h.localCOMx+=(d.x+f.x)*P,h.localCOMy+=(d.y+f.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(o){r=!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 m=x,d=c.gnormx*m.x+c.gnormy*m.y;d<h&&(h=d),d>=c.gprojection+s.Config.epsilon&&(i[u]=!0,r=!1),++u,x=x.next}if(h-=c.gprojection,h>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 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 m=.5;u.localCOMx*=m,u.localCOMy*=m}else{u.localCOMx=0,u.localCOMy=0;let x=0,m=u.lverts.next,d=m;m=m.next;let y=m;for(m=m.next;m!=null;){let z=m;x+=y.x*(z.y-d.y);let C=z.y*y.x-z.x*y.y;u.localCOMx+=(y.x+z.x)*C,u.localCOMy+=(y.y+z.y)*C,d=y,y=z,m=m.next}m=u.lverts.next;let b=m;x+=y.x*(b.y-d.y);let f=b.y*y.x-b.x*y.y;u.localCOMx+=(y.x+b.x)*f,u.localCOMy+=(y.y+b.y)*f,d=y,y=b,m=m.next;let P=m;x+=y.x*(P.y-d.y);let k=P.y*y.x-P.x*y.y;u.localCOMx+=(y.x+P.x)*k,u.localCOMy+=(y.y+P.y)*k,x=1/(3*x);let _=x;u.localCOMx*=_,u.localCOMy*=_}}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(o){for(;fe.flowpoly.head!=null;){let P=fe.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=ae.zpp_pool,ae.zpp_pool=k}}let c=null,h=!1,u=e.polygon.gverts.next,x=0,m=t.polygon.gverts.next,d=0,y=0,b=t.polygon.edgeCnt;for(;y<b;){let P=y++;if(l[P])m=m.next;else{d=P;break}}if(m==null){m=t.polygon.gverts.next,h=!0;let P=0,k=e.polygon.edgeCnt;for(;P<k;){let _=P++;if(i[_])u=u.next;else{x=_;break}}u==null?u=e.polygon.gverts.next:(fe.flowpoly.add(u),c=fe.flowpoly.head.elt)}else fe.flowpoly.add(m),c=fe.flowpoly.head.elt;let f=1;if(fe.flowpoly.head==null){let P=!0,k=e.polygon.gverts.next,_=k,z=k.next;for(;z!=null;){let C=z,w=2,g=!0,O=t.polygon.gverts.next,E=O,M=O.next;for(;M!=null;){let N=M,Z=0,A=_.x-E.x,S=_.y-E.y,L=C.x-_.x,T=C.y-_.y,G=N.x-E.x,q=N.y-E.y,R=T*G-L*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let V=(q*A-G*S)*R;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let K=(T*A-L*S)*R;K>s.Config.epsilon&&K<1-s.Config.epsilon?(Z=V,j=!0):j=!1}else j=!1}else j=!1;j&&Z<w&&(w=Z,m=O),O=M,E=N,M=M.next}if(g)for(;;){M=t.polygon.gverts.next;let N=M,Z=0,A=_.x-E.x,S=_.y-E.y,L=C.x-_.x,T=C.y-_.y,G=N.x-E.x,q=N.y-E.y,R=T*G-L*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let V=(q*A-G*S)*R;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let K=(T*A-L*S)*R;K>s.Config.epsilon&&K<1-s.Config.epsilon?(Z=V,j=!0):j=!1}else j=!1}else j=!1;j&&Z<w&&(w=Z,m=O);break}if(w!=2){let N=w,Z=_.x+(C.x-_.x)*N,A=_.y+(C.y-_.y)*N;c=ae.get(Z,A),fe.flowpoly.add(c),h=!0,u=k,P=!1;break}k=z,_=C,z=z.next}if(P)for(;;){z=e.polygon.gverts.next;let C=z,w=2,g=!0,O=t.polygon.gverts.next,E=O,M=O.next;for(;M!=null;){let N=M,Z=0,A=_.x-E.x,S=_.y-E.y,L=C.x-_.x,T=C.y-_.y,G=N.x-E.x,q=N.y-E.y,R=T*G-L*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let V=(q*A-G*S)*R;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let K=(T*A-L*S)*R;K>s.Config.epsilon&&K<1-s.Config.epsilon?(Z=V,j=!0):j=!1}else j=!1}else j=!1;j&&Z<w&&(w=Z,m=O),O=M,E=N,M=M.next}if(g)for(;;){M=t.polygon.gverts.next;let N=M,Z=0,A=_.x-E.x,S=_.y-E.y,L=C.x-_.x,T=C.y-_.y,G=N.x-E.x,q=N.y-E.y,R=T*G-L*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let V=(q*A-G*S)*R;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let K=(T*A-L*S)*R;K>s.Config.epsilon&&K<1-s.Config.epsilon?(Z=V,j=!0):j=!1}else j=!1}else j=!1;j&&Z<w&&(w=Z,m=O);break}if(w!=2){let N=w,Z=_.x+(C.x-_.x)*N,A=_.y+(C.y-_.y)*N;c=ae.get(Z,A),fe.flowpoly.add(c),h=!0,u=k;break}break}f=2}for(;;)if(h)if(u=u.next,++x,u==null&&(u=e.polygon.gverts.next,x=0),i[x]){let P=fe.flowpoly.head.elt,k=u,_=m,z=m.next;z==null&&(z=t.polygon.gverts.next);let C=-1,w=null,g=0,O=0,E=z,M=z;for(;;){let j=M,V=0,K=_.x-P.x,$=_.y-P.y,Y=j.x-_.x,X=j.y-_.y,ee=k.x-P.x,J=k.y-P.y,F=X*ee-Y*J,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let I=(J*K-ee*$)*F;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*K-Y*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=I,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(w=m,g=d,++O==f){C=V,M=E;break}else C=V;_=j,m=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,V=0,K=_.x-P.x,$=_.y-P.y,Y=j.x-_.x,X=j.y-_.y,ee=k.x-P.x,J=k.y-P.y,F=X*ee-Y*J,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let I=(J*K-ee*$)*F;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*K-Y*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=I,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(w=m,g=d,++O==f){C=V;break}else C=V;_=j,m=M,++d,d>=t.polygon.edgeCnt&&(d=0),M=M.next,M==null&&(M=t.polygon.gverts.next)}if(w==null)break;let N=w,Z=w.next;Z==null&&(Z=t.polygon.gverts.next);let A=Z,S=C,L=N.x+(A.x-N.x)*S,T=N.y+(A.y-N.y)*S,G;if(c!=null){let j=L-c.x,V=T-c.y;G=j*j+V*V<s.Config.epsilon}else G=!1;if(G)break;let q=fe.flowpoly,R=ae.get(L,T);q.add(R),c==null&&(c=fe.flowpoly.head.elt),m=w,d=g,h=!h,f=2}else{let P=u,k;if(c!=null){let _=P.x-c.x,z=P.y-c.y;k=_*_+z*z<s.Config.epsilon}else k=!1;if(k)break;fe.flowpoly.add(P),c==null&&(c=fe.flowpoly.head.elt),f=1}else if(m=m.next,++d,m==null&&(m=t.polygon.gverts.next,d=0),l[d]){let P=fe.flowpoly.head.elt,k=m,_=u,z=u.next;z==null&&(z=e.polygon.gverts.next);let C=-1,w=null,g=0,O=0,E=z,M=z;for(;;){let j=M,V=0,K=_.x-P.x,$=_.y-P.y,Y=j.x-_.x,X=j.y-_.y,ee=k.x-P.x,J=k.y-P.y,F=X*ee-Y*J,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let I=(J*K-ee*$)*F;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*K-Y*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=I,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(w=u,g=x,++O==f){C=V,M=E;break}else C=V;_=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,V=0,K=_.x-P.x,$=_.y-P.y,Y=j.x-_.x,X=j.y-_.y,ee=k.x-P.x,J=k.y-P.y,F=X*ee-Y*J,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let I=(J*K-ee*$)*F;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*K-Y*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=I,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(w=u,g=x,++O==f){C=V;break}else C=V;_=j,u=M,++x,x>=e.polygon.edgeCnt&&(x=0),M=M.next,M==null&&(M=e.polygon.gverts.next)}if(w==null)break;let N=w,Z=w.next;Z==null&&(Z=e.polygon.gverts.next);let A=Z,S=C,L=N.x+(A.x-N.x)*S,T=N.y+(A.y-N.y)*S,G;if(c!=null){let j=L-c.x,V=T-c.y;G=j*j+V*V<s.Config.epsilon}else G=!1;if(G)break;let q=fe.flowpoly,R=ae.get(L,T);q.add(R),c==null&&(c=fe.flowpoly.head.elt),u=w,x=g,h=!h,f=2}else{let P=m,k;if(c!=null){let _=P.x-c.x,z=P.y-c.y;k=_*_+z*z<s.Config.epsilon}else k=!1;if(k)break;fe.flowpoly.add(P),c==null&&(c=fe.flowpoly.head.elt),f=1}if(fe.flowpoly.head!=null&&fe.flowpoly.head.next!=null&&fe.flowpoly.head.next.next!=null){let P=0,k=0,_=0,z=fe.flowpoly.head,C=z.elt;z=z.next;let w=z.elt;for(z=z.next;z!=null;){let A=z.elt;P+=w.x*(A.y-C.y);let S=A.y*w.x-A.x*w.y;k+=(w.x+A.x)*S,_+=(w.y+A.y)*S,C=w,w=A,z=z.next}z=fe.flowpoly.head;let g=z.elt;P+=w.x*(g.y-C.y);let O=g.y*w.x-g.x*w.y;k+=(w.x+g.x)*O,_+=(w.y+g.y)*O,C=w,w=g,z=z.next;let E=z.elt;P+=w.x*(E.y-C.y);let M=E.y*w.x-E.x*w.y;k+=(w.x+E.x)*M,_+=(w.y+E.y)*M,P*=.5;let Z=1/(6*P);return k*=Z,_*=Z,n.overlap=-P,n.centroidx=k,n.centroidy=_,!0}else return!1}else return!1}else return!1}else{let i=[],l=!0,o=null,r=null,a=-1e100,p=!0,c=t.polygon.gverts.next,h=0,u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,m=x.gnormx*e.circle.worldCOMx+x.gnormy*e.circle.worldCOMy;if(m>x.gprojection+e.circle.radius){p=!1;break}else m+e.circle.radius>x.gprojection+s.Config.epsilon&&(l=!1,i[h]=!0);m-=x.gprojection+e.circle.radius,m>a&&(a=m,o=x,r=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=r,m=r.next==null?t.polygon.gverts.next:r.next,d=e.circle.worldCOMy*o.gnormx-e.circle.worldCOMx*o.gnormy,y;if(d<=x.y*o.gnormx-x.x*o.gnormy){let b=e.circle.radius,f=x.x-e.circle.worldCOMx,P=x.y-e.circle.worldCOMy;y=f*f+P*P<=b*b}else if(d>=m.y*o.gnormx-m.x*o.gnormy){let b=e.circle.radius,f=m.x-e.circle.worldCOMx,P=m.y-e.circle.worldCOMy;y=f*f+P*P<=b*b}else y=!0;if(y){let b=[],f=0,P=!0,k=null,_=0,z=t.polygon.gverts.next;for(;z!=null;){let C=z,w=C.x-e.circle.worldCOMx,g=C.y-e.circle.worldCOMy,O=w*w+g*g;(b[f]=O<=e.circle.radius*e.circle.radius)?(_=f,k=z):P=!1,++f,z=z.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 g=C.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 O=1;g.localCOMx+=g.lverts.next.next.x*O,g.localCOMy+=g.lverts.next.next.y*O;let E=.5;g.localCOMx*=E,g.localCOMy*=E}else{g.localCOMx=0,g.localCOMy=0;let O=0,E=g.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;g.localCOMx+=(N.x+G.x)*q,g.localCOMy+=(N.y+G.y)*q,M=N,N=G,E=E.next}E=g.lverts.next;let Z=E;O+=N.x*(Z.y-M.y);let A=Z.y*N.x-Z.x*N.y;g.localCOMx+=(N.x+Z.x)*A,g.localCOMy+=(N.y+Z.y)*A,M=N,N=Z,E=E.next;let S=E;O+=N.x*(S.y-M.y);let L=S.y*N.x-S.x*N.y;g.localCOMx+=(N.x+S.x)*L,g.localCOMy+=(N.y+S.y)*L,O=1/(3*O);let T=O;g.localCOMx*=T,g.localCOMy*=T}}C.wrap_localCOM!=null&&(C.wrap_localCOM.zpp_inner.x=C.localCOMx,C.wrap_localCOM.zpp_inner.y=C.localCOMy)}let w=C.body;w.zip_axis&&(w.zip_axis=!1,w.axisx=Math.sin(w.rot),w.axisy=Math.cos(w.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(;fe.flowpoly.head!=null;){let g=fe.flowpoly.pop_unsafe();if(!g._inuse){let O=g;O.outer!=null&&(O.outer.zpp_inner=null,O.outer=null),O._isimmutable=null,O._validate=null,O._invalidate=null,O.next=ae.zpp_pool,ae.zpp_pool=O}}fe.flowsegs.clear();let C=null,w=1;for(k==null?(k=t.polygon.gverts.next,w=2):(C=k,fe.flowpoly.add(C));w!=0;)if(w==1)if(k=k.next,k==null&&(k=t.polygon.gverts.next),++_,_>=t.polygon.edgeCnt&&(_=0),b[_]){let g=C.x-k.x,O=C.y-k.y;if(g*g+O*O<s.Config.epsilon)break;fe.flowpoly.add(k)}else{let g=fe.flowpoly.head.elt,O=k,E=O.x-g.x,M=O.y-g.y,N=g.x-e.circle.worldCOMx,Z=g.y-e.circle.worldCOMy,A=E*E+M*M,S=2*(N*E+Z*M),L=N*N+Z*Z-e.circle.radius*e.circle.radius,T=Math.sqrt(S*S-4*A*L);A=1/(2*A);let G=(-S-T)*A,q=G<s.Config.epsilon?(-S+T)*A:G,R=0,j=0,V=q;R=g.x+(O.x-g.x)*V,j=g.y+(O.y-g.y)*V;let K=C.x-R,$=C.y-j;if(K*K+$*$<s.Config.epsilon)break;let Y=fe.flowpoly,X=ae.get(R,j);Y.add(X),w=2}else if(w==2){let g=k.next;g==null&&(g=t.polygon.gverts.next);let O=k;w=0;let E=g,M=g;for(;;){let N=M,Z=_+1;if(Z==t.polygon.edgeCnt&&(Z=0),i[_])if(b[Z]){let A=N.x-O.x,S=N.y-O.y,L=O.x-e.circle.worldCOMx,T=O.y-e.circle.worldCOMy,G=A*A+S*S,q=2*(L*A+T*S),R=L*L+T*T-e.circle.radius*e.circle.radius,j=Math.sqrt(q*q-4*G*R);G=1/(2*G);let V=(-q-j)*G,K=V<s.Config.epsilon?(-q+j)*G:V,$=0,Y=0,X=K;$=O.x+(N.x-O.x)*X,Y=O.y+(N.y-O.y)*X;let ee=C.x-$,J=C.y-Y;if(ee*ee+J*J<s.Config.epsilon){w=0,M=E;break}let D=ae.get($,Y);fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(D),fe.flowpoly.add(D),w=1,M=E;break}else{let A=0,S=0,L=N.x-O.x,T=N.y-O.y,G=O.x-e.circle.worldCOMx,q=O.y-e.circle.worldCOMy,R=L*L+T*T,j=2*(G*L+q*T),V=G*G+q*q-e.circle.radius*e.circle.radius,K=j*j-4*R*V,$;if(K*K<s.Config.epsilon?(K<0?A=10:(S=-j/(2*R),A=S),$=!1):(K=Math.sqrt(K),R=1/(2*R),A=(-j-K)*R,S=(-j+K)*R,$=!0),A<1-s.Config.epsilon&&S>s.Config.epsilon){let Y=0,X=0,ee=A;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){w=0,M=E;break}let D=ae.get(Y,X);if(fe.flowpoly.head!=null&&(fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(D)),fe.flowpoly.add(D),C==null&&(C=fe.flowpoly.head.elt),$){let I=0,U=0,Q=S;I=O.x+(N.x-O.x)*Q,U=O.y+(N.y-O.y)*Q;let W=fe.flowpoly,ie=ae.get(I,U);W.add(ie)}}}O=N,k=M,_=Z,M=M.next,M==null&&(M=t.polygon.gverts.next);break}for(;M!=E;){let N=M,Z=_+1;if(Z==t.polygon.edgeCnt&&(Z=0),i[_])if(b[Z]){let A=N.x-O.x,S=N.y-O.y,L=O.x-e.circle.worldCOMx,T=O.y-e.circle.worldCOMy,G=A*A+S*S,q=2*(L*A+T*S),R=L*L+T*T-e.circle.radius*e.circle.radius,j=Math.sqrt(q*q-4*G*R);G=1/(2*G);let V=(-q-j)*G,K=V<s.Config.epsilon?(-q+j)*G:V,$=0,Y=0,X=K;$=O.x+(N.x-O.x)*X,Y=O.y+(N.y-O.y)*X;let ee=C.x-$,J=C.y-Y;if(ee*ee+J*J<s.Config.epsilon){w=0,M=E;break}let D=ae.get($,Y);fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(D),fe.flowpoly.add(D),w=1,M=E;break}else{let A=0,S=0,L=N.x-O.x,T=N.y-O.y,G=O.x-e.circle.worldCOMx,q=O.y-e.circle.worldCOMy,R=L*L+T*T,j=2*(G*L+q*T),V=G*G+q*q-e.circle.radius*e.circle.radius,K=j*j-4*R*V,$;if(K*K<s.Config.epsilon?(K<0?A=10:(S=-j/(2*R),A=S),$=!1):(K=Math.sqrt(K),R=1/(2*R),A=(-j-K)*R,S=(-j+K)*R,$=!0),A<1-s.Config.epsilon&&S>s.Config.epsilon){let Y=0,X=0,ee=A;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){w=0,M=E;break}let D=ae.get(Y,X);if(fe.flowpoly.head!=null&&(fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(D)),fe.flowpoly.add(D),C==null&&(C=fe.flowpoly.head.elt),$){let I=0,U=0,Q=S;I=O.x+(N.x-O.x)*Q,U=O.y+(N.y-O.y)*Q;let W=fe.flowpoly,ie=ae.get(I,U);W.add(ie)}}}O=N,k=M,_=Z,M=M.next,M==null&&(M=t.polygon.gverts.next)}}if(fe.flowpoly.head==null)return!1;if(fe.flowpoly.head.next==null){let g=!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){g=!1;break}O=O.next}return g?(n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0):!1}else{let g=0,O=0,E=0;if(fe.flowpoly.head.next.next!=null){let N=0,Z=0,A=0;N=0;let S=fe.flowpoly.head,L=S.elt;S=S.next;let T=S.elt;for(S=S.next;S!=null;){let Y=S.elt;N+=T.x*(Y.y-L.y);let X=Y.y*T.x-Y.x*T.y;Z+=(T.x+Y.x)*X,A+=(T.y+Y.y)*X,L=T,T=Y,S=S.next}S=fe.flowpoly.head;let G=S.elt;N+=T.x*(G.y-L.y);let q=G.y*T.x-G.x*T.y;Z+=(T.x+G.x)*q,A+=(T.y+G.y)*q,L=T,T=G,S=S.next;let R=S.elt;N+=T.x*(R.y-L.y);let j=R.y*T.x-R.x*T.y;Z+=(T.x+R.x)*j,A+=(T.y+R.y)*j,N*=.5;let K=1/(6*N);Z*=K,A*=K;let $=-N;g+=Z*$,O+=A*$,E-=N}else fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(fe.flowpoly.head.next.elt);for(;fe.flowsegs.head!=null;){let N=fe.flowsegs.pop_unsafe(),Z=fe.flowsegs.pop_unsafe(),A=Z.x-N.x,S=Z.y-N.y,L=A,T=S,G=L*L+T*T,R=1/Math.sqrt(G);L*=R,T*=R;let j=L;L=-T,T=j;let V=N.x+Z.x,K=N.y+Z.y,$=.5;V*=$,K*=$;let Y=1;V-=e.circle.worldCOMx*Y,K-=e.circle.worldCOMy*Y;let X=L*V+T*K,ee=0,J=0,F=X,D=F/e.circle.radius,I=Math.sqrt(1-D*D),U=Math.acos(D);ee=e.circle.radius*(e.circle.radius*U-F*I),J=.6666666666666666*e.circle.radius*I*I*I/(U-D*I),V=e.circle.worldCOMx,K=e.circle.worldCOMy;let Q=J;V+=L*Q,K+=T*Q;let W=ee;g+=V*W,O+=K*W,E+=ee}let M=1/E;return g*=M,O*=M,n.overlap=E,n.centroidx=g,n.centroidy=O,!0}}}else return!1}}else return!1}else{let i=e.circle,l=t.circle,o=l.worldCOMx-i.worldCOMx,r=l.worldCOMy-i.worldCOMy,a=i.radius+l.radius,p=o*o+r*r;if(p>a*a)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 m=0,d=0,y=0,b=0,f=u,P=f/i.radius,k=Math.sqrt(1-P*P),_=Math.acos(P);m=i.radius*(i.radius*_-f*k),d=.6666666666666666*i.radius*k*k*k/(_-P*k);let z=x,C=z/l.radius,w=Math.sqrt(1-C*C),g=Math.acos(C);y=l.radius*(l.radius*g-z*w),b=.6666666666666666*l.radius*w*w*w/(g-C*w);let O=m+y,E=(d*m+(c-b)*y)/O*h;n.overlap=O,n.centroidx=i.worldCOMx+o*E,n.centroidy=i.worldCOMy+r*E}}return!0}}}static capsuleContains(e,t){let n=fe._closestT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.x,t.y),s=e.spine1x+n*(e.spine2x-e.spine1x),i=e.spine1y+n*(e.spine2y-e.spine1y),l=t.x-s,o=t.y-i;return l*l+o*o<e.radius*e.radius}static _closestT(e,t,n,s,i,l){let o=n-e,r=s-t,a=o*o+r*r;if(a<1e-12)return 0;let p=((i-e)*o+(l-t)*r)/a;return p<0&&(p=0),p>1&&(p=1),p}static _closestTT(e,t,n,s,i,l,o,r){let a=n-e,p=s-t,c=o-i,h=r-l,u=e-i,x=t-l,m=a*a+p*p,d=c*c+h*h,y=c*u+h*x,b,f;if(m<1e-12&&d<1e-12)return[0,0];if(m<1e-12)return b=0,f=y/d,f<0&&(f=0),f>1&&(f=1),[b,f];let P=a*u+p*x;if(d<1e-12)return f=0,b=-P/m,b<0&&(b=0),b>1&&(b=1),[b,f];let k=a*c+p*h,_=m*d-k*k;if(_>1e-12)b=(k*y-P*d)/_,b<0&&(b=0),b>1&&(b=1),f=(k*b+y)/d,f<0?(f=0,b=-P/m,b<0&&(b=0),b>1&&(b=1)):f>1&&(f=1,b=(k-P)/m,b<0&&(b=0),b>1&&(b=1));else{let z=1/m,C=-(a*u+p*x)*z,w=C+k*z,g=Math.max(0,Math.min(C,w)),O=Math.min(1,Math.max(C,w));b=g<=O?(g+O)*.5:C<0?0:1,f=(k*b+y)/d,f<0&&(f=0),f>1&&(f=1)}return[b,f]}static _getOrCreateContact(e,t,n){let s=null,i=e.contacts.next;for(;i!=null;){if(t==i.hash){s=i;break}i=i.next}if(s==null){Pe.zpp_pool==null?s=new Pe:(s=Pe.zpp_pool,Pe.zpp_pool=s.next,s.next=null);let l=s.inner;l.jnAcc=l.jtAcc=0,s.hash=t,s.fresh=!0,s.arbiter=e,e.jrAcc=0;let o=e.contacts;s._inuse=!0;let r=s;r.next=o.next,o.next=r,o.modified=!0,o.length++,e.innards.add(l)}else s.fresh=!1;return s}static _capsuleContactCollide(e,t,n,s,i){let l=t.capsule;return e.type==0?fe._circleCapsuleContact(e.circle,l,n,s,i):e.type==1?fe._polyCapsuleContact(e.polygon,l,n,s,i):fe._capsuleCapsuleContact(e.capsule,l,n,s,i)}static _circleCapsuleContact(e,t,n,s,i){let l=fe._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,e.worldCOMx,e.worldCOMy),o=t.spine1x+l*(t.spine2x-t.spine1x),r=t.spine1y+l*(t.spine2y-t.spine1y),a=e.radius+t.radius,p=e.worldCOMx-o,c=e.worldCOMy-r,h=p*p+c*c;if(h>a*a)return!1;let u;if(h<i.Config.epsilon*i.Config.epsilon){let x=(e.worldCOMx+o)*.5,m=(e.worldCOMy+r)*.5;u=fe._getOrCreateContact(n,0,n.stamp),u.px=x,u.py=m,n.nx=1,n.ny=0,u.dist=-a,u.stamp=n.stamp,u.posOnly=!1}else{let x=1/Math.sqrt(h),m=x<i.Config.epsilon?1e100:1/x,d=.5+(e.radius-.5*a)*x,y=e.worldCOMx-p*d,b=e.worldCOMy-c*d;u=fe._getOrCreateContact(n,0,n.stamp),u.px=y,u.py=b,s?(n.nx=p*x,n.ny=c*x):(n.nx=-p*x,n.ny=-c*x),u.dist=m-a,u.stamp=n.stamp,u.posOnly=!1}if(u!=null){let x=u.inner,m=t.localCOMx+(2*l-1)*t.halfLength;return s?(x.lr1x=m,x.lr1y=t.localCOMy,x.lr2x=e.localCOMx,x.lr2y=e.localCOMy):(x.lr1x=e.localCOMx,x.lr1y=e.localCOMy,x.lr2x=m,x.lr2y=t.localCOMy),n.radius=a,n.ptype=2,!0}return!1}static _capsuleCapsuleContact(e,t,n,s,i){let l=e.radius+t.radius,o=i.Config.epsilon,r=(b,f,P)=>{let k=e.spine1x+f*(e.spine2x-e.spine1x),_=e.spine1y+f*(e.spine2y-e.spine1y),z=t.spine1x+P*(t.spine2x-t.spine1x),C=t.spine1y+P*(t.spine2y-t.spine1y),w=z-k,g=C-_,O=w*w+g*g;if(O>l*l)return!1;let E=fe._getOrCreateContact(n,b,n.stamp);if(O<o*o)E.px=(k+z)*.5,E.py=(_+C)*.5,b===0&&(n.nx=1,n.ny=0),E.dist=-l;else{let A=1/Math.sqrt(O),S=1/A,L=w*A,T=g*A,G=.5+(e.radius-.5*l)*A;E.px=k+w*G,E.py=_+g*G,b===0&&(n.nx=s?-L:L,n.ny=s?-T:T),E.dist=S-l}E.stamp=n.stamp,E.posOnly=!1;let M=E.inner,N=e.localCOMx+(2*f-1)*e.halfLength,Z=t.localCOMx+(2*P-1)*t.halfLength;return s?(M.lr1x=Z,M.lr1y=t.localCOMy,M.lr2x=N,M.lr2y=e.localCOMy):(M.lr1x=N,M.lr1y=e.localCOMy,M.lr2x=Z,M.lr2y=t.localCOMy),!0},[a,p]=fe._closestTT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine1x,t.spine1y,t.spine2x,t.spine2y);if(!r(0,a,p))return!1;if(n.radius=l,n.ptype=2,fe.debugCapsule){let b=e.spine1x+a*(e.spine2x-e.spine1x),f=e.spine1y+a*(e.spine2y-e.spine1y),P=t.spine1x+p*(t.spine2x-t.spine1x),k=t.spine1y+p*(t.spine2y-t.spine1y),_=P-b,z=k-f,C=Math.sqrt(_*_+z*z);console.log("[capCap] nx=",n.nx.toFixed(3),"ny=",n.ny.toFixed(3),"dist=",C.toFixed(3),"minDist=",l.toFixed(3),"pen=",(C-l).toFixed(3))}let c=e.spine2x-e.spine1x,h=e.spine2y-e.spine1y,u=t.spine2x-t.spine1x,x=t.spine2y-t.spine1y,m=c*c+h*h,d=u*u+x*x,y=c*x-h*u;if(y*y<.01*m*d&&m>1e-12&&d>1e-12){let b=[[0,fe._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,e.spine1x,e.spine1y)],[1,fe._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,e.spine2x,e.spine2y)],[fe._closestT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine1x,t.spine1y),0],[fe._closestT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine2x,t.spine2y),1]],f=0,P=null;for(let[k,_]of b){let z=k-a,C=z*z;if(C>f+1e-6){let w=e.spine1x+k*(e.spine2x-e.spine1x),g=e.spine1y+k*(e.spine2y-e.spine1y),O=t.spine1x+_*(t.spine2x-t.spine1x),E=t.spine1y+_*(t.spine2y-t.spine1y),M=O-w,N=E-g;M*M+N*N<=l*l&&(f=C,P=[k,_])}}P!=null&&r(1,P[0],P[1])}return!0}static _polyCapsuleContact(e,t,n,s,i){let l=-1e100,o=null,r=null,a=!0,p=e.gverts.next,c=e.edges.head;for(;c!=null;){let E=c.elt,M=E.gnormx*t.spine1x+E.gnormy*t.spine1y,N=E.gnormx*t.spine2x+E.gnormy*t.spine2y,A=(M<N?M:N)-E.gprojection-t.radius;if(A>0){a=!1;break}A>l&&(l=A,o=E,r=p),p=p.next,c=c.next}if(!a)return!1;let h=t.spine2x-t.spine1x,u=t.spine2y-t.spine1y,x=h*h+u*u;if(x>1e-12){let E=Math.sqrt(x),M=-u/E,N=h/E,Z=M*t.spine1x+N*t.spine1y,A=1e100,S=-1e100,L=e.gverts.next;for(;L!=null;){let G=M*L.x+N*L.y;G<A&&(A=G),G>S&&(S=G),L=L.next}if((A>Z+t.radius?A-(Z+t.radius):S<Z-t.radius?Z-t.radius-S:0)>0)return!1}let m=r,d=r.next==null?e.gverts.next:r.next,y=m.y*o.gnormx-m.x*o.gnormy,b=d.y*o.gnormx-d.x*o.gnormy,f=E=>t.localCOMx+(2*E-1)*t.halfLength,P=(E,M)=>{E.lr1x=M,E.lr1y=t.localCOMy,E.lr2x=0,E.lr2y=0},k=(E,M,N,Z)=>{let S=o.gnormx*N+o.gnormy*Z-o.gprojection-t.radius;if(S>0)return;let L=fe._getOrCreateContact(n,E,n.stamp);L.px=N-o.gnormx*(t.radius+S*.5),L.py=Z-o.gnormy*(t.radius+S*.5),L.dist=S,L.stamp=n.stamp,L.posOnly=!1,P(L.inner,f(M))},_=(E,M,N,Z,A)=>{let S=Z-M,L=A-N,T=S*S+L*L;if(T>t.radius*t.radius)return!1;let G=fe._getOrCreateContact(n,0,n.stamp);if(n.radius=t.radius,n.ptype=0,n.__ref_edge1=o,n.__ref_vertex=0,T<i.Config.epsilon*i.Config.epsilon)G.px=M,G.py=N,n.nx=s?-o.gnormx:o.gnormx,n.ny=s?-o.gnormy:o.gnormy,G.dist=-t.radius;else{let q=1/Math.sqrt(T),R=1/q,j=S*q,V=L*q;G.px=M+j*t.radius,G.py=N+V*t.radius,n.nx=s?-j:j,n.ny=s?-V:V,G.dist=R-t.radius}return G.stamp=n.stamp,G.posOnly=!1,P(G.inner,f(E)),!0},z=t.spine1y*o.gnormx-t.spine1x*o.gnormy,C=t.spine2y*o.gnormx-t.spine2x*o.gnormy,w=z>y&&z<b,g=C>y&&C<b;if(!w&&!g){let E=o.gnormx*t.spine1x+o.gnormy*t.spine1y,M=o.gnormx*t.spine2x+o.gnormy*t.spine2y;if(E<=M){if(z<=y){if(_(0,t.spine1x,t.spine1y,m.x,m.y))return!0}else if(_(0,t.spine1x,t.spine1y,d.x,d.y))return!0}else if(C<=y){if(_(1,t.spine2x,t.spine2y,m.x,m.y))return!0}else if(_(1,t.spine2x,t.spine2y,d.x,d.y))return!0;let N=fe._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,t.spine1x+o.gnormx*o.gprojection,t.spine1y+o.gnormy*o.gprojection),Z=(y+b)*.5,A=t.spine1y*o.gnormx-t.spine1x*o.gnormy,L=t.spine2y*o.gnormx-t.spine2x*o.gnormy-A,T=Math.abs(L)>1e-12?(Z-A)/L:.5;T<0&&(T=0),T>1&&(T=1);let G=t.spine1x+T*(t.spine2x-t.spine1x),q=t.spine1y+T*(t.spine2y-t.spine1y);return o.gnormx*G+o.gnormy*q-o.gprojection-t.radius>0?!1:(n.nx=s?-o.gnormx:o.gnormx,n.ny=s?-o.gnormy:o.gnormy,n.radius=t.radius,n.lproj=o.lprojection,n.lnormx=o.lnormx,n.lnormy=o.lnormy,n.ptype=s?1:0,n.rev=s,n.__ref_edge1=o,n.__ref_vertex=0,k(0,T,G,q),n.oc1!=null&&n.oc1.stamp==n.stamp)}n.nx=s?-o.gnormx:o.gnormx,n.ny=s?-o.gnormy:o.gnormy,n.radius=t.radius,n.lproj=o.lprojection,n.lnormx=o.lnormx,n.lnormy=o.lnormy,n.ptype=s?1:0,n.rev=s,n.__ref_edge1=o,n.__ref_vertex=0;let O=0;return w&&k(O++,0,t.spine1x,t.spine1y),g&&k(O,1,t.spine2x,t.spine2y),fe.debugCapsule&&O>0&&console.log("[polyCapsule face] nx=",n.nx.toFixed(3),"ny=",n.ny.toFixed(3),"dist=",n.oc1?.dist?.toFixed(3),"ptype=",n.ptype,"rev=",n.rev,"bestDist=",l.toFixed(3)),O>0||n.oc1!=null&&n.oc1.stamp==n.stamp}static _capsuleTestCollide(e,t){let n=t.capsule;if(e.type==0){let s=fe._closestT(n.spine1x,n.spine1y,n.spine2x,n.spine2y,e.circle.worldCOMx,e.circle.worldCOMy),i=n.spine1x+s*(n.spine2x-n.spine1x),l=n.spine1y+s*(n.spine2y-n.spine1y),o=e.circle.radius+n.radius,r=e.circle.worldCOMx-i,a=e.circle.worldCOMy-l;return r*r+a*a<=o*o}else if(e.type==1){let s=e.polygon.edges.head;for(;s!=null;){let r=s.elt,a=r.gnormx*n.spine1x+r.gnormy*n.spine1y,p=r.gnormx*n.spine2x+r.gnormy*n.spine2y;if((a<p?a:p)-r.gprojection-n.radius>0)return!1;s=s.next}let i=n.spine2x-n.spine1x,l=n.spine2y-n.spine1y,o=i*i+l*l;if(o>1e-12){let r=-l,a=i,p=Math.sqrt(o),c=r/p,h=a/p,u=c*n.spine1x+h*n.spine1y,x=1e100,m=-1e100,d=e.polygon.gverts.next;for(;d!=null;){let y=c*d.x+h*d.y;y<x&&(x=y),y>m&&(m=y),d=d.next}if(x>u+n.radius||m<u-n.radius)return!1}return!0}else{let s=e.capsule,[i,l]=fe._closestTT(s.spine1x,s.spine1y,s.spine2x,s.spine2y,n.spine1x,n.spine1y,n.spine2x,n.spine2y),o=s.spine1x+i*(s.spine2x-s.spine1x),r=s.spine1y+i*(s.spine2y-s.spine1y),a=n.spine1x+l*(n.spine2x-n.spine1x),p=n.spine1y+l*(n.spine2y-n.spine1y),c=s.radius+n.radius,h=a-o,u=p-r;return h*h+u*u<=c*c}}static _capsuleFlowCollide(e,t,n,s){let i=e.type==2?e.capsule:t.capsule,l=e.type==2?t:e,o=i.area||Math.PI*i.radius*i.radius+4*i.halfLength*i.radius;if(l.type==2){let u=l.capsule,[x,m]=fe._closestTT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,u.spine1x,u.spine1y,u.spine2x,u.spine2y),d=i.spine1x+x*(i.spine2x-i.spine1x),y=i.spine1y+x*(i.spine2y-i.spine1y),b=u.spine1x+m*(u.spine2x-u.spine1x),f=u.spine1y+m*(u.spine2y-u.spine1y),P=b-d,k=f-y,_=Math.sqrt(P*P+k*k),z=i.radius+u.radius;if(_>=z)return!1;let C=z-_;return n.overlap=C*Math.min(2*i.radius,2*u.radius)*.5,n.buoyx=(d+b)*.5,n.buoyy=(y+f)*.5,!0}if(l.type==0){let u=l.circle,x=fe._closestT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,u.worldCOMx,u.worldCOMy),m=i.spine1x+x*(i.spine2x-i.spine1x),d=i.spine1y+x*(i.spine2y-i.spine1y),y=u.worldCOMx-m,b=u.worldCOMy-d,f=Math.sqrt(y*y+b*b),P=i.radius+u.radius;if(f>=P)return!1;let k=P-f;return n.overlap=k*Math.min(2*i.radius,2*u.radius)*.5,n.buoyx=(m+u.worldCOMx)*.5,n.buoyy=(d+u.worldCOMy)*.5,!0}let r=l.polygon,a=1e100,p=0,c=0,h=r.edges.head;for(;h!=null;){let u=h.elt,x=u.gnormx*i.spine1x+u.gnormy*i.spine1y,m=u.gnormx*i.spine2x+u.gnormy*i.spine2y,d=x<m?x:m,y=u.gprojection+i.radius-d;if(y<0)return!1;y<a&&(a=y,p=u.gnormx,c=u.gnormy),h=h.next}return n.overlap=a*2*i.radius*.5,n.buoyx=i.worldCOMx,n.buoyy=i.worldCOMy,!0}};fe.flowpoly=null,fe.flowsegs=null;var Ce=fe;var dl=class v{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 o=l,r=o.prev,a=null,p=o.diagonals.head;for(;p!=null;){let c=p.elt,h=p.next==null?o.next:p.next.elt;if(!v.isinner(h,o,r)){a=p,r=c,p=p.next;continue}let u=!0,x=c,m=x.prev,d=null,y=x.diagonals.head;for(;y!=null;){let b=y.elt;if(b==o){let f=y.next==null?x.next:y.next.elt;u=v.isinner(f,x,m);break}m=b,d=y,y=y.next}if(u){p=o.diagonals.erase(a),x.diagonals.erase(d);continue}r=c,a=p,p=p.next}if(l=l.next,l==i)break}}}};var tt=class tt{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;tt.rayPool==null?(tt.internal=!0,i=tt._createRayResult(),i.zpp_inner=new tt,i.zpp_inner.ray=i,tt.internal=!1):(i=tt.rayPool.ray,tt.rayPool=tt.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;tt.convexPool==null?(tt.internal=!0,i=tt._createConvexResult(),i.zpp_inner=new tt,i.zpp_inner.convex=i,tt.internal=!1):(i=tt.convexPool.convex,tt.convexPool=tt.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(){tt._disposeVec2(this.normal),this.position!=null&&tt._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=tt.convexPool,tt.convexPool=this):(this.next=tt.rayPool,tt.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,ye.nextVec2!=null?ye.nextVec2.zpp_pool=e:ye.poolVec2=e,ye.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=ae.zpp_pool,ae.zpp_pool=n}};tt.rayPool=null,tt.convexPool=null,tt.internal=!1,tt._createRayResult=null,tt._createConvexResult=null;var bn=tt;var Fi=class Fi{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 Fi.zpp_pool==null?t=new Fi:(t=Fi.zpp_pool,Fi.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}};Fi.zpp_pool=null;var Qe=Fi;var Ri=class Ri{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,o=!1){let r;return Ri.zpp_pool==null?r=new Ri:(r=Ri.zpp_pool,Ri.zpp_pool=r.next,r.next=null),r.virtualint=l,r.end=t,r.start=n,r.path0=s,r.path1=i,r.time=e,r.vertex=o,r}alloc(){}free(){this.end=this.start=null,this.path0=this.path1=null}};Ri.zpp_pool=null;var lt=Ri;var ri=class ri{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 ri.zpp_pool==null?n=new ri:(n=ri.zpp_pool,ri.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,ye.nextVec2!=null?ye.nextVec2.zpp_pool=s:ye.poolVec2=s,ye.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=ae.zpp_pool,ae.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(ye.poolVec2==null?n=ri._createVec2Fn():(n=ye.poolVec2,ye.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n===ye.nextVec2&&(ye.nextVec2=null)),n.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.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 o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y===t}else i=!1;if(!i){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=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}};ri.zpp_pool=null,ri._createVec2Fn=null;var ge=ri;var et=class et{static run(e,t,n,s,i,l){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 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 m=n.zpp_inner;m._validate!=null&&m._validate();let d=n.zpp_inner.y-h,y=s?0:-1/0,b=i?1:1/0,f=-(h*x-p*d),P=null,k=!1,_=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=_,j.posx=_.x,j.posy=_.y,j.value=j.posy*x-j.posx*d+f,j.positive=j.value>0,j.value==0&&(k=!0);let V=j;if(P==null?V.prev=V.next=V:(V.prev=P,V.next=P.next,P.next.prev=V,P.next=V),P=V,_=_.next,_==e)break}if(k){let j=null,V=P,K=P;if(V!=null){let U=V;for(;;){let Q=U;if(Q.value!=0){j=Q;break}if(U=U.next,U==K)break}}let $,Y;$=x,Y=d;let X=$*$+Y*Y,J=1/Math.sqrt(X);$*=J,Y*=J;let F=$;$=-Y,Y=F;let D=null,I=j;for(;;){if(I.value!=0&&(D==null||I==D.next)){if(D=I,I=I.next,I==j)break;continue}let U=D.value*I.value;if(U==0){if(I=I.next,I==j)break;continue}let Q=D.next,W;if(U>0)W=D.positive;else{let se=Q.next,ne,re;ne=Q.posx+se.posx,re=Q.posy+se.posy;let le=.5;ne*=le,re*=le;let he=ne+$*1e-8,pe=re+Y*1e-8,ce=!1,te=e,ue=e;if(te!=null){let xe=te;for(;;){let _e=xe,ve=_e.prev;if((_e.y<pe&&ve.y>=pe||ve.y<pe&&_e.y>=pe)&&(_e.x<=he||ve.x<=he)&&_e.x+(pe-_e.y)/(ve.y-_e.y)*(ve.x-_e.x)<he&&(ce=!ce),xe=xe.next,xe==ue)break}}W=ce}let ie=Q,oe=I;if(ie!=null){let se=ie;for(;;){let ne=se;if(ne.positive=W,se=se.next,se==oe)break}}if(D=I,I=I.next,I==j)break}for(;!(I.value!=0&&(D==null||I==D.next));){let U=D.value*I.value;if(U==0)break;let Q=D.next,W;if(U>0)W=D.positive;else{let se=Q.next,ne,re;ne=Q.posx+se.posx,re=Q.posy+se.posy;let le=.5;ne*=le,re*=le;let he=ne+$*1e-8,pe=re+Y*1e-8,ce=!1,te=e,ue=e;if(te!=null){let xe=te;for(;;){let _e=xe,ve=_e.prev;if((_e.y<pe&&ve.y>=pe||ve.y<pe&&_e.y>=pe)&&(_e.x<=he||ve.x<=he)&&_e.x+(pe-_e.y)/(ve.y-_e.y)*(ve.x-_e.x)<he&&(ce=!ce),xe=xe.next,xe==ue)break}}W=ce}let ie=Q,oe=I;if(ie!=null){let se=ie;for(;;){let ne=se;if(ne.positive=W,se=se.next,se==oe)break}}break}}et.ints==null&&(et.ints=new r.util.ZNPList_ZPP_CutInt),et.paths==null&&(et.paths=new r.util.ZNPList_ZPP_CutVert);let z=null,C=P.posx,w=P.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=C,g.y=w;let O=g;O.prev=O.next=O,z=O;let E=z,M;Qe.zpp_pool==null?M=new Qe:(M=Qe.zpp_pool,Qe.zpp_pool=M.next,M.next=null),M.vert=z,M.parent=M,M.rank=0,M.used=!1;let N=M;et.paths.add(N);let Z=P;for(;;){let j=Z.next,V=j.posx,K=j.posy,$;ge.zpp_pool==null?$=new ge:($=ge.zpp_pool,ge.zpp_pool=$.next,$.next=null),$.forced=!1,$.x=V,$.y=K;let Y=$;if(Z.positive==j.positive){let X=Y;z==null?(X.prev=X.next=X,z=X):(X.next=z,X.prev=z.prev,z.prev.next=X,z.prev=X)}else{let X=j.posx-Z.posx,ee=j.posy-Z.posy,J=d*X-x*ee;J=1/J;let F=p-Z.posx,D=h-Z.posy,I=(ee*F-X*D)*J;if(I<y||I>b){let U=et.ints,Q=!0;Q==null&&(Q=!1);let W;lt.zpp_pool==null?W=new lt:(W=lt.zpp_pool,lt.zpp_pool=W.next,W.next=null),W.virtualint=Q,W.end=null,W.start=null,W.path0=null,W.path1=null,W.time=I,W.vertex=!1,U.add(W);let ie=Y;z==null?(ie.prev=ie.next=ie,z=ie):(ie.next=z,ie.prev=z.prev,z.prev.next=ie,z.prev=ie)}else if(Z.value==0){let U=z.prev;z=null;let Q=U.x,W=U.y,ie;ge.zpp_pool==null?ie=new ge:(ie=ge.zpp_pool,ge.zpp_pool=ie.next,ie.next=null),ie.forced=!1,ie.x=Q,ie.y=W;let oe=ie;oe.prev=oe.next=oe,z=oe;let se=Y;z==null?(se.prev=se.next=se,z=se):(se.next=z,se.prev=z.prev,z.prev.next=se,z.prev=se);let ne=et.paths.head.elt,re=et.paths,le;Qe.zpp_pool==null?le=new Qe:(le=Qe.zpp_pool,Qe.zpp_pool=le.next,le.next=null),le.vert=z,le.parent=le,le.rank=0,le.used=!1,re.add(le);let he=et.paths.head.elt,pe=et.ints,ce=!0;ce==null&&(ce=!1);let te;lt.zpp_pool==null?te=new lt:(te=lt.zpp_pool,lt.zpp_pool=te.next,te.next=null),te.virtualint=ce,te.end=U,te.start=z,te.path0=ne,te.path1=he,te.time=I,te.vertex=!1,pe.add(te)}else if(j.value==0){let U=Y;z==null?(U.prev=U.next=U,z=U):(U.next=z,U.prev=z.prev,z.prev.next=U,z.prev=U);let Q=z.prev;z=null;let W=j.posx,ie=j.posy,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=W,oe.y=ie;let se=oe;se.prev=se.next=se,z=se;let ne=et.paths.head.elt,re=et.paths,le;Qe.zpp_pool==null?le=new Qe:(le=Qe.zpp_pool,Qe.zpp_pool=le.next,le.next=null),le.vert=z,le.parent=le,le.rank=0,le.used=!1,re.add(le);let he=et.paths.head.elt,pe=et.ints,ce=!0;ce==null&&(ce=!1);let te;lt.zpp_pool==null?te=new lt:(te=lt.zpp_pool,lt.zpp_pool=te.next,te.next=null),te.virtualint=ce,te.end=Q,te.start=z,te.path0=ne,te.path1=he,te.time=I,te.vertex=!1,pe.add(te)}else{let U=(d*F-x*D)*J,Q,W;Q=Z.posx,W=Z.posy;let ie=U;Q+=X*ie,W+=ee*ie;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=Q,oe.y=W;let se=oe;z==null?(se.prev=se.next=se,z=se):(se.next=z,se.prev=z.prev,z.prev.next=se,z.prev=se);let ne=z.prev;z=null;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=Q,re.y=W;let le=re;le.prev=le.next=le,z=le;let he=Y;z==null?(he.prev=he.next=he,z=he):(he.next=z,he.prev=z.prev,z.prev.next=he,z.prev=he);let pe=et.paths.head.elt,ce=et.paths,te;Qe.zpp_pool==null?te=new Qe:(te=Qe.zpp_pool,Qe.zpp_pool=te.next,te.next=null),te.vert=z,te.parent=te,te.rank=0,te.used=!1,ce.add(te);let ue=et.paths.head.elt,xe=et.ints,_e=!1;_e==null&&(_e=!1);let ve;lt.zpp_pool==null?ve=new lt:(ve=lt.zpp_pool,lt.zpp_pool=ve.next,ve.next=null),ve.virtualint=_e,ve.end=ne,ve.start=z,ve.path0=pe,ve.path1=ue,ve.time=I,ve.vertex=!1,xe.add(ve)}}if(Z=Z.next,Z==P)break}let A=z.prev;A.next.prev=E.prev,E.prev.next=A.next,A.next=E,E.prev=A;let S=et.paths.head.elt,L;if(N==N.parent)L=N;else{let j=N,V=null;for(;j!=j.parent;){let K=j.parent;j.parent=V,V=j,j=K}for(;V!=null;){let K=V.parent;V.parent=j,V=K}L=j}let T;if(S==S.parent)T=S;else{let j=S,V=null;for(;j!=j.parent;){let K=j.parent;j.parent=V,V=j,j=K}for(;V!=null;){let K=V.parent;V.parent=j,V=K}T=j}L!=T&&(L.rank<T.rank?L.parent=T:L.rank>T.rank?T.parent=L:(T.parent=L,L.rank++));let G=et.ints;if(G.head!=null&&G.head.next!=null){let j=G.head,V,K,$,Y,X=1,ee,J,F;for(;;){for(ee=0,K=j,j=null,V=j;K!=null;){for(++ee,$=K,J=0,F=X;$!=null&&J<X;)++J,$=$.next;for(;J>0||F>0&&$!=null;)J==0?(Y=$,$=$.next,--F):F==0||$==null||K.elt.time<$.elt.time?(Y=K,K=K.next,--J):(Y=$,$=$.next,--F),V!=null?V.next=Y:j=Y,V=Y;K=$}if(V.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(),V=et.ints.pop_unsafe();if(!j.virtualint&&!V.virtualint){j.end.next.prev=V.start.prev,V.start.prev.next=j.end.next,j.end.next=V.start,V.start.prev=j.end,V.end.next.prev=j.start.prev,j.start.prev.next=V.end.next,V.end.next=j.start,j.start.prev=V.end;let Y;if(j.path0==j.path0.parent)Y=j.path0;else{let F=j.path0,D=null;for(;F!=F.parent;){let I=F.parent;F.parent=D,D=F,F=I}for(;D!=null;){let I=D.parent;D.parent=F,D=I}Y=F}let X;if(V.path1==V.path1.parent)X=V.path1;else{let F=V.path1,D=null;for(;F!=F.parent;){let I=F.parent;F.parent=D,D=F,F=I}for(;D!=null;){let I=D.parent;D.parent=F,D=I}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(j.path1==j.path1.parent)ee=j.path1;else{let F=j.path1,D=null;for(;F!=F.parent;){let I=F.parent;F.parent=D,D=F,F=I}for(;D!=null;){let I=D.parent;D.parent=F,D=I}ee=F}let J;if(V.path0==V.path0.parent)J=V.path0;else{let F=V.path0,D=null;for(;F!=F.parent;){let I=F.parent;F.parent=D,D=F,F=I}for(;D!=null;){let I=D.parent;D.parent=F,D=I}J=F}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&&!V.virtualint){let Y;if(V.end!=null&&V.end.prev==V.end){V.end.next=V.end.prev=null;let J=V.end;if(J.wrap!=null){J.wrap.zpp_inner._inuse=!1;let F=J.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=F.zpp_inner;if(D._immutable)throw new Error("Error: Vec2 is immutable");if(D._isimmutable!=null&&D._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let I=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let U=F;U.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=U:ye.poolVec2=U,ye.nextVec2=U,U.zpp_disp=!0;let Q=I;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=ae.zpp_pool,ae.zpp_pool=Q,J.wrap=null}J.prev=J.next=null,J.next=ge.zpp_pool,ge.zpp_pool=J,Y=null}else{let J=V.end.prev;V.end.prev.next=V.end.next,V.end.next.prev=V.end.prev,V.end.next=V.end.prev=null;let F=V.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,V.end=null,Y=J}if(V.end=Y,!V.vertex)if(V.end!=V.path0.vert){V.start.x=V.end.x,V.start.y=V.end.y;let J;if(V.end!=null&&V.end.prev==V.end){V.end.next=V.end.prev=null;let F=V.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,J=null}else{let F=V.end.prev;V.end.prev.next=V.end.next,V.end.next.prev=V.end.prev,V.end.next=V.end.prev=null;let D=V.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let I=D.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 Q=I.zpp_inner;I.zpp_inner.outer=null,I.zpp_inner=null;let W=I;W.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=W:ye.poolVec2=W,ye.nextVec2=W,W.zpp_disp=!0;let ie=Q;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=ae.zpp_pool,ae.zpp_pool=ie,D.wrap=null}D.prev=D.next=null,D.next=ge.zpp_pool,ge.zpp_pool=D,V.end=null,J=F}V.end=J}else{let J=V.start.next;if(V.start.x=J.x,V.start.y=J.y,J!=null&&J.prev==J){J.next=J.prev=null;let F=J;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}else{J.prev.next=J.next,J.next.prev=J.prev,J.next=J.prev=null;let F=J;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}}V.end.next.prev=V.start.prev,V.start.prev.next=V.end.next,V.end.next=V.start,V.start.prev=V.end;let X;if(V.path0==V.path0.parent)X=V.path0;else{let J=V.path0,F=null;for(;J!=J.parent;){let D=J.parent;J.parent=F,F=J,J=D}for(;F!=null;){let D=F.parent;F.parent=J,F=D}X=J}let ee;if(V.path1==V.path1.parent)ee=V.path1;else{let J=V.path1,F=null;for(;J!=J.parent;){let D=J.parent;J.parent=F,F=J,J=D}for(;F!=null;){let D=F.parent;F.parent=J,F=D}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(V.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 F=J.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=F.zpp_inner;if(D._immutable)throw new Error("Error: Vec2 is immutable");if(D._isimmutable!=null&&D._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let I=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let U=F;U.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=U:ye.poolVec2=U,ye.nextVec2=U,U.zpp_disp=!0;let Q=I;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=ae.zpp_pool,ae.zpp_pool=Q,J.wrap=null}J.prev=J.next=null,J.next=ge.zpp_pool,ge.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 F=j.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,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 F=j.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,J=null}else{let F=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 D=j.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let I=D.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 Q=I.zpp_inner;I.zpp_inner.outer=null,I.zpp_inner=null;let W=I;W.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=W:ye.poolVec2=W,ye.nextVec2=W,W.zpp_disp=!0;let ie=Q;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=ae.zpp_pool,ae.zpp_pool=ie,D.wrap=null}D.prev=D.next=null,D.next=ge.zpp_pool,ge.zpp_pool=D,j.end=null,J=F}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 F=J;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}else{J.prev.next=J.next,J.next.prev=J.prev,J.next=J.prev=null;let F=J;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}}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,F=null;for(;J!=J.parent;){let D=J.parent;J.parent=F,F=J,J=D}for(;F!=null;){let D=F.parent;F.parent=J,F=D}X=J}let ee;if(j.path1==j.path1.parent)ee=j.path1;else{let J=j.path1,F=null;for(;J!=J.parent;){let D=J.parent;J.parent=F,F=J,J=D}for(;F!=null;){let D=F.parent;F.parent=J,F=D}ee=J}X!=ee&&(X.rank<ee.rank?X.parent=ee:X.rank>ee.rank?ee.parent=X:(ee.parent=X,X.rank++))}let K=j;K.end=K.start=null,K.path0=K.path1=null,K.next=lt.zpp_pool,lt.zpp_pool=K;let $=V;$.end=$.start=null,$.path0=$.path1=null,$.next=lt.zpp_pool,lt.zpp_pool=$}let q=l??new o.geom.GeomPolyList,R=et.paths.head;for(;R!=null;){let j=R.elt,V;if(j==j.parent)V=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}V=Y}if(V.used){R=R.next;continue}V.used=!0;let K=V.vert,$=!0;for(;V.vert!=null&&($||K!=V.vert);)if($=!1,K.x==K.next.x&&K.y==K.next.y)if(K==V.vert&&(V.vert=K.next==K?null:K.next,$=!0),K!=null&&K.prev==K)K.next=K.prev=null,K=null;else{let Y=K.next;K.prev.next=K.next,K.next.prev=K.prev,K.next=K.prev=null,K=Y}else K=K.next;if(V.vert!=null){let Y=o.geom.GeomPoly.get();Y.zpp_inner.vertices=V.vert,q.zpp_inner.reverse_flag?q.push(Y):q.unshift(Y)}R=R.next}for(;et.paths.head!=null;){let V=et.paths.pop_unsafe();V.vert=null,V.parent=null,V.next=Qe.zpp_pool,Qe.zpp_pool=V}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 V=P;V.vert=null,V.parent=null,V.next=Qe.zpp_pool,Qe.zpp_pool=V,P=j}return q}};et.ints=null,et.paths=null;var _l=et;var gs=class v{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 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 a=i,p=s.elt;s=s.next,p.gp0=l,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,l=a,i=i.next}let o=t.gverts.next,r=s.elt;r.gp0=l,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;v._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 if(e.type==2)e.capsule.__validate_aabb();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,o=t.gverts.next;for(;o!=null;){let r=o,a=l;l=l.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 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&&v._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&&v._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 o=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*o,e.localCOMy+=(i.y+l.y)*o,s=i,i=l,n=n.next;let r=n;t+=i.x*(r.y-s.y);let a=r.y*i.x-r.x*i.y;e.localCOMx+=(i.x+r.x)*a,e.localCOMy+=(i.y+r.y)*a,t=1/(3*t);let p=t;e.localCOMx*=p,e.localCOMy*=p}}};var yl=class{constructor(e=null){this.outer=null;this.vertices=null;this.outer=e}};var Bn=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}};Bn.zpp_pool=null;var jn=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(){}};jn.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 s=t.zpp_inner;t.zpp_inner.outer=null,t.zpp_inner=null;let i=t;i.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=i:ye.poolVec2=i,ye.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=ae.zpp_pool,ae.zpp_pool=l,e.wrap=null}e.prev=e.next=null,e.next=ge.zpp_pool,ge.zpp_pool=e}static _allocSpan(){let e;return Bn.zpp_pool==null?e=new Bn:(e=Bn.zpp_pool,Bn.zpp_pool=e.next,e.next=null),e.out=!1,e.rank=0,e}static _allocPair(){let e;return jn.zpp_pool==null?e=new jn:(e=jn.zpp_pool,jn.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=jn.zpp_pool,jn.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,o,r,a){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,r&&(ze.map==null?ze.map=new ys(h,x):ze.map.resize(h,x,null)),ze.isos==null?ze.isos=new ds(h+1,x+1):ze.isos.resize(h+1,x+1,0);for(let y=0;y<x+1;y++){let b;if(y==0)b=n;else if(y<=x){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let f=l.zpp_inner;f._validate!=null&&f._validate(),b=n+l.zpp_inner.y*y}else b=i;for(let f=0;f<h+1;f++){let P;if(f==0)P=t;else if(f<=h){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(),P=t+l.zpp_inner.x*f}else P=s;let k=ze.isos,_=e(P,b);k.list[y*k.width+f]=_}}ze.ints==null?ze.ints=new _s(h+1,(x<<1)+1):ze.ints.resize(h+1,(x<<1)+1,null);let m=null;r&&(m=ze._allocSpan(),m.next=null);let d=n;for(let y=0;y<x;y++){let b=d,f;if(y==x-1)f=i;else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let _=l.zpp_inner;_._validate!=null&&_._validate(),f=n+l.zpp_inner.y*(y+1)}d=f;let P=t,k=null;for(let _=0;_<h;_++){let z=P,C;if(_==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*(_+1)}P=C;let w=_==0||!r,g=y==0||!r,O=_==h-1||!r,E=y==x-1||!r,M=ze.me.marchSquare(e,ze.isos,ze.ints,z,b,C,f,_,y,w,g,O,E,o);if(M==null){k=null;continue}if(r){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[y*Z.width+_]=M;let A;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,A=q>=2}else A=!1;A?(ze.me.combLR(k,M),M.span1=k.spanr):(M.span1=ze._allocSpan(),M.span1.next=m,m=M.span1),M.p2!=null?(M.span2=ze._allocSpan(),M.span2.next=m,m=M.span2,M.spanr=M.span2):M.spanr=M.span1;let S=(M.keyr&28)>>2,L=0;(S&1)!=0&&++L,(S&2)!=0&&++L,(S&4)!=0&&++L,L>=2?k=M:k=null}else ze.me.output(a,M.p1),M.p2!=null&&ze.me.output(a,M.p2),ze._freePair(M)}}if(r){for(let y=1;y<x;y++){let b=null;for(let f=0;f<h;f++){let P=ze.map,k=P.list[y*P.width+f];if(k==null){b=null;continue}let z=(k.p2!=null&&k.okey2==14?k.okey2:k.okey1)&7,C=0;if((z&1)!=0&&++C,(z&2)!=0&&++C,(z&4)!=0&&++C,C<2){b=null;continue}let w=ze.map,g=w.list[(y-1)*w.width+f];if(g==null){b=null;continue}let E=((g.p2!=null&&g.okey2==56?g.okey2:g.okey1)&112)>>4,M=0;if((E&1)!=0&&++M,(E&2)!=0&&++M,(E&4)!=0&&++M,M<2){b=null;continue}let N=g.p2!=null&&g.okey2==56?g.span2:g.span1,Z=k.p2!=null&&k.okey2==14?k.span2:k.span1,A=ze._findRoot(N),S=ze._findRoot(Z);A==S?b!=Z&&ze.me.combUD_virtual(g,k):(ze._union(N,Z),ze.me.combUD(g,k)),b=((Z==k.span2?k.okey2:k.okey1)&4)!=0?Z:null}}for(let y=0;y<x;y++)for(let b=0;b<h;b++){let f=ze.map,P=f.list[y*f.width+b];if(P==null)continue;let k=ze._findRoot(P.span1);k.out||(k.out=!0,ze.me.output(a,P.p1)),P.p2!=null&&(k=ze._findRoot(P.span2),k.out||(k.out=!0,ze.me.output(a,P.p2))),ze._freePair(P),f.list[y*f.width+b]=null}for(;m!=null;){let y=m;m=y.next;let b=y;b.parent=b,b.next=Bn.zpp_pool,Bn.zpp_pool=b}}}output(e,t){let n=ze._nape,s;if(t==null||t.next==t||t.next==t.prev)s=!0;else{let o=0,r=t,a=t;if(r!=null){let c=r;for(;;){let h=c;if(o+=h.x*(h.next.y-h.prev.y),c=c.next,c==a)break}}let p=o*.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 o=t.next;t.prev.next=t.next,t.next.prev=t.prev,t.next=t.prev=null,t=o}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,o=(t.okey1&1)==0?l.prev:l,r=i.next,a=o.prev;(e.keyr&4)!=0?(t.pr==t.p1&&(t.pr=i.prev),t.p1=i.prev,i.prev.next=o.next,o.next.prev=i.prev,ze._freeVert(i)):(i.next=o.next,o.next.prev=i),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,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,o,r,a,p,c,h,u,x,m,d,y,b,f){let P=null;for(let k=0;k<8;k++)if((e&1<<k)!=0){let _;if(k==0)_=ze._allocVert(s,i),(x||m)&&(_.forced=!0);else if(k==2)_=ze._allocVert(l,i),(d||m)&&(_.forced=!0);else if(k==4)_=ze._allocVert(l,o),(d||y)&&(_.forced=!0);else if(k==6)_=ze._allocVert(s,o),(x||y)&&(_.forced=!0);else if(k==1){if(_=n.list[(a<<1)*n.width+r],_==null){let z=this.xlerp(s,l,i,p,c,b,f);_=ze._allocVert(z,i),n.list[(a<<1)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);m&&(_.forced=!0),(_.x==s||_.x==l)&&(_.x==s&&(e&1)!=0||_.x==l&&(e&4)!=0)&&(e^=2)}else if(k==5){if(_=n.list[((a<<1)+2)*n.width+r],_==null){let z=this.xlerp(s,l,o,u,h,b,f);_=ze._allocVert(z,o),n.list[((a<<1)+2)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);y&&(_.forced=!0),(_.x==s||_.x==l)&&(_.x==s&&(e&64)!=0||_.x==l&&(e&16)!=0)&&(e^=32)}else if(k==3){if(_=n.list[((a<<1)+1)*n.width+(r+1)],_==null){let z=this.ylerp(i,o,l,c,h,b,f);_=ze._allocVert(l,z),n.list[((a<<1)+1)*n.width+(r+1)]=_}else _=ze._allocVert(_.x,_.y);d&&(_.forced=!0),(_.y==i||_.y==o)&&(_.y==i&&(e&4)!=0||_.y==o&&(e&16)!=0)&&(e^=8)}else{if(_=n.list[((a<<1)+1)*n.width+r],_==null){let z=this.ylerp(i,o,s,p,u,b,f);_=ze._allocVert(s,z),n.list[((a<<1)+1)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);x&&(_.forced=!0),(_.y==i||_.y==o)&&(_.y==i&&(e&1)!=0||_.y==o&&(e&64)!=0)&&(e^=128)}P=ze._pushVert(P,_)}return P!=null&&(P=P.next),{head:P,val:e}}marchSquare(e,t,n,s,i,l,o,r,a,p,c,h,u,x){let m=0,d=t.list[a*t.width+r];d<0&&(m|=8);let y=t.list[a*t.width+(r+1)];y<0&&(m|=4);let b=t.list[(a+1)*t.width+(r+1)];b<0&&(m|=2);let f=t.list[(a+1)*t.width+r];if(f<0&&(m|=1),m==0)return null;let P=ze._allocPair();if(m!=10&&m!=5){let k=ze.look_march[m];P.okey1=k;let _=this._buildPoly(k,t,n,s,i,l,o,r,a,d,y,b,f,p,c,h,u,e,x);P.p1=_.head,k=_.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+o))<0;if(m==10)if(k){let _=187;P.okey1=_;let z=this._buildPoly(_,t,n,s,i,l,o,r,a,d,y,b,f,p,c,h,u,e,x);P.p1=z.head,_=z.val,P.key1=_,ze._isDegenKey(_)&&(_=0,P.key1=0,P.p1=null),_==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let _=131;P.okey1=_;let z=this._buildPoly(_,t,n,s,i,l,o,r,a,d,y,b,f,p,c,h,u,e,x);if(P.p1=z.head,_=z.val,P.key1=_,ze._isDegenKey(_)&&(_=0,P.key1=0,P.p1=null),_!=0){let C=56;P.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,o,r,a,d,y,b,f,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 w=this._buildPoly(C,t,n,s,i,l,o,r,a,d,y,b,f,p,c,h,u,e,x);P.p1=w.head,C=w.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 _=238;P.okey1=_;let z=this._buildPoly(_,t,n,s,i,l,o,r,a,d,y,b,f,p,c,h,u,e,x);P.p1=z.head,_=z.val,P.key1=_,ze._isDegenKey(_)&&(_=0,P.key1=0,P.p1=null),_==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let _=224;P.okey1=_;let z=this._buildPoly(_,t,n,s,i,l,o,r,a,d,y,b,f,p,c,h,u,e,x);if(P.p1=z.head,_=z.val,P.key1=_,ze._isDegenKey(_)&&(_=0,P.key1=0,P.p1=null),_!=0){let C=14;P.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,o,r,a,d,y,b,f,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 w=this._buildPoly(C,t,n,s,i,l,o,r,a,d,y,b,f,p,c,h,u,e,x);P.p1=w.head,C=w.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,o,r,a,p,c,h,u,x,m,d,y,b,f,P){for(let k=0;k<8;k++)if((e&1<<k)!=0){let _;if(k==0)_=ze._allocVert(s,i),(x||m)&&(_.forced=!0);else if(k==2)_=ze._allocVert(l,i),(d||m)&&(_.forced=!0);else if(k==4)_=ze._allocVert(l,o),(d||y)&&(_.forced=!0);else if(k==6)_=ze._allocVert(s,o),(x||y)&&(_.forced=!0);else if(k==1){if(_=n.list[(a<<1)*n.width+r],_==null){let C=this.xlerp(s,l,i,p,c,b,f);_=ze._allocVert(C,i),n.list[(a<<1)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);m&&(_.forced=!0),(_.x==s||_.x==l)&&(_.x==s&&(e&1)!=0||_.x==l&&(e&4)!=0)&&(e^=2)}else if(k==5){if(_=n.list[((a<<1)+2)*n.width+r],_==null){let C=this.xlerp(s,l,o,u,h,b,f);_=ze._allocVert(C,o),n.list[((a<<1)+2)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);y&&(_.forced=!0),(_.x==s||_.x==l)&&(_.x==s&&(e&64)!=0||_.x==l&&(e&16)!=0)&&(e^=32)}else if(k==3){if(_=n.list[((a<<1)+1)*n.width+(r+1)],_==null){let C=this.ylerp(i,o,l,c,h,b,f);_=ze._allocVert(l,C),n.list[((a<<1)+1)*n.width+(r+1)]=_}else _=ze._allocVert(_.x,_.y);d&&(_.forced=!0),(_.y==i||_.y==o)&&(_.y==i&&(e&4)!=0||_.y==o&&(e&16)!=0)&&(e^=8)}else{if(_=n.list[((a<<1)+1)*n.width+r],_==null){let C=this.ylerp(i,o,s,p,u,b,f);_=ze._allocVert(s,C),n.list[((a<<1)+1)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);x&&(_.forced=!0),(_.y==i||_.y==o)&&(_.y==i&&(e&1)!=0||_.y==o&&(e&64)!=0)&&(e^=128)}let z=_;P.p2==null?P.p2=z.prev=z.next=z:(z.prev=P.p2,z.next=P.p2.next,P.p2.next.prev=z,P.p2.next=z),P.p2=z}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,o=l*l<i.Config.epsilon*i.Config.epsilon?.5:n/l;return o<0?o=0:o>1&&(o=1),e+o*(t-e)}}xlerp(e,t,n,s,i,l,o){let r=ze._nape,a;if(s==0)a=e;else if(i==0)a=t;else{let p=s-i,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=l(a,n);if(p==0)break;if(s*p<0?(t=a,i=p):(e=a,s=p),s==0)a=e;else if(i==0)a=t;else{let c=s-i,h=c*c<r.Config.epsilon*r.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),a=e+h*(t-e)}}return a}ylerp(e,t,n,s,i,l,o){let r=ze._nape,a;if(s==0)a=e;else if(i==0)a=t;else{let p=s-i,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=l(n,a);if(p==0)break;if(s*p<0?(t=a,i=p):(e=a,s=p),s==0)a=e;else if(i==0)a=t;else{let c=s-i,h=c*c<r.Config.epsilon*r.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),a=e+h*(t-e)}}return a}};ze.isos=null,ze.ints=null,ze.map=null,ze._zpp=null,ze._nape=null;var Js=ze;var cn=class cn{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 cn.zpp_pool==null?e=new cn:(e=cn.zpp_pool,cn.zpp_pool=e.next,e.next=null),e}static identity(){let e=cn.get();return e.setas(1,0,0,1,0,0),e}wrapper(){if(this.outer==null)if(cn._wrapFn)this.outer=cn._wrapFn(this);else{this.outer=new cn._nape.geom.Mat23;let e=this.outer.zpp_inner;e.next=cn.zpp_pool,cn.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(){}};cn._nape=null,cn._wrapFn=null,cn.zpp_pool=null;var Us=cn;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,s=e*t;for(;n<s;)n++,this.x.push(0)}};var yt=class yt{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=yt.nextId++,this.diagonals=new _i}static get(e){let t;return yt.zpp_pool==null?t=new yt:(t=yt.zpp_pool,yt.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,o=t.y-e.y;return(n?-1:1)*(o*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 yt.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!yt.vert_lt(e,t);if(t==e.next)return yt.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 yt.rightdistance(t,e)>0?!0:yt.rightdistance(t,e.next)>0;else{let n=yt.rightdistance(e,t),s=yt.rightdistance(e,t.next);if(n==0&&s==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*s>=0)return n<0?!0:s<0;let i=yt.rightdistance(t,e),l=yt.rightdistance(t,e.next);return i*l>=0?i>0?!0:l>0:!1}}alloc(){}free(){this.helper=null}copy(){let e;return yt.zpp_pool==null?e=new yt:(e=yt.zpp_pool,yt.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,o=this.diagonals;if(o.head!=null&&o.head.next!=null){let r=o.head,a,p,c,h,u=1,x,m,d;for(;;){for(x=0,p=r,r=null,a=r;p!=null;){for(++x,c=p,m=0,d=u;c!=null&&m<u;)++m,c=c.next;for(;m>0||d>0&&c!=null;){if(m==0)h=c,c=c.next,--d;else if(d==0||c==null)h=p,p=p.next,--m;else{let y;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 b=s*e-n*t;y=(b>0?-1:b==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 b=s*e-n*t,f=b>0?-1:b==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(f*k==1||f*k==0&&(f==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 _=s*e-n*t;y=(_>0?-1:_==0?0:1)==1}else if(f==-1||k==-1)y=k==-1;else if(f==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 _=e*n+t*s;n=c.elt.x-this.x,s=c.elt.y-this.y;let z=e*n+t*s;y=_<0&&z>0?!0:!(z<0&&_>0)}else y=!0}y?(h=p,p=p.next,--m):(h=c,c=c.next,--d)}a!=null?a.next=h:r=h,a=h}p=c}if(a.next=null,u<<=1,!(x>1))break}o.head=r,o.modified=!0,o.pushmod=!0}}};yt.zpp_pool=null,yt.nextId=0;var Ge=yt;var hn=class hn{constructor(e){this.next=null;this.vertices=null;this.init(e)}static getSharedPP(){return hn.sharedPPList==null&&(hn.sharedPPList=new pl),hn.sharedPPList}static getShared(){return hn.sharedGVList==null&&(hn.sharedGVList=new ms),hn.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 o=n;for(;;){let r=o;if(t+=r.x*(r.next.y-r.prev.y),o=o.next,o==s)break}}let i=t*.5>0,l=e;for(;;){let o;if(i){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;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=l.x,r.y=l.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=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,o=e.next.x-e.x,a=(e.next.y-e.y)*i-o*l;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 pl),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 o=this.vertices;o.helper=null,o.next=Ge.zpp_pool,Ge.zpp_pool=o,l=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,l=o}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;hn.zpp_pool==null?n=new hn:(n=hn.zpp_pool,hn.zpp_pool=n.next,n.next=null);let s=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=s.x,r.y=s.y,r.forced=s.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=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,o=n.vertices;if(l!=null){let r=l;for(;;){let a=r;if(i+=a.x*(a.next.y-a.prev.y),r=r.next,r==o)break}}return i*.5!=0&&t.add(n),s}extract(e){if(e==null&&(e=new ms),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 a=s.x,p=s.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 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,o=n;if(l!=null){let a=l;for(;;){let p=a;if(i+=p.x*(p.next.y-p.prev.y),a=a.next,a==o)break}}let r=i*.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,h=a.y-a.next.y;if(c*c+h*h<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 u=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=u}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 h=a.prev,u=a.x-h.x,x=a.y-h.y,m=a.next.x-a.x,y=(a.next.y-a.y)*u-m*x;if(y*y>=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 b=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=b}if(c=!0,a==null){c=!1,n=null;break}}}if(!c)break}}n!=null&&t.add(n)}return s}};hn.zpp_pool=null,hn.sharedPPList=null,hn.sharedGVList=null;var qi=hn;var Fe=class Fe{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,o=n.y-e.y,r;ae.zpp_pool==null?r=new ae:(r=ae.zpp_pool,ae.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=-i-o,r.y=s+l;let a=r,p=a.x*a.x+a.y*a.y,h=1/Math.sqrt(p);return a.x*=h,a.y*=h,o*s-l*i<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=Fe.bisector(e),s=Fe.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 o=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=ae.zpp_pool,ae.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=ae.zpp_pool,ae.zpp_pool=s,o}}static above(e,t){return Fe.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 r=s;for(;;){let a=r;if(a.y<t.y&&(t=a),a.y>n.y&&(n=a),r=r.next,r==i)break}}let l=!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){l=!1;break}if(o=c,p=p.next,p==a)break}}}if(!l)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){l=!1;break}if(o=c,p=p.prev,p==a)break}}}return l}static getShared(){return Fe.sharedPPoly==null&&(Fe.sharedPPoly=new qi),Fe.sharedPPoly}static decompose(e,t){if(t==null?t=new qi(e):t.init(e),t.vertices==null)return t;Fe.queue==null&&(Fe.queue=new _i);let n=t.vertices,s=t.vertices;if(n!=null){let l=n;for(;;){let o=l;Fe.queue.add(o);let r=o.next.x-o.x,a=o.next.y-o.y,p=o.prev.x-o.x,h=(o.prev.y-o.y)*r-p*a>0;if(o.type=Fe.below(o.prev,o)?Fe.below(o.next,o)?h?0:3:4:Fe.below(o,o.next)?h?1:2:4,l=l.next,l==s)break}}let i=Fe.queue;if(i.head!=null&&i.head.next!=null){let l=i.head,o,r,a,p,c=1,h,u,x;for(;;){for(h=0,r=l,l=null,o=l;r!=null;){for(++h,a=r,u=0,x=c;a!=null&&u<c;)++u,a=a.next;for(;u>0||x>0&&a!=null;)u==0?(p=a,a=a.next,--x):x==0||a==null||Fe.above(r.elt,a.elt)?(p=r,r=r.next,--u):(p=a,a=a.next,--x),o!=null?o.next=p:l=p,o=p;r=a}if(o.next=null,c<<=1,!(h>1))break}i.head=l,i.modified=!0,i.pushmod=!0}for(Fe.edges==null&&(zs.zpp_pool==null?Fe.edges=new zs:(Fe.edges=zs.zpp_pool,zs.zpp_pool=Fe.edges.next,Fe.edges.next=null),Fe.edges.lt=Ge.edge_lt,Fe.edges.swapped=Ge.edge_swap);Fe.queue.head!=null;){let l=Fe.queue.pop_unsafe();switch(l.type){case 0:l.helper=l,l.node=Fe.edges.insert(l);break;case 1:{let o=l.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(l,o.helper),Fe.edges.remove_node(o.node),o.helper=null;break}case 2:{let o=l.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(l,o.helper),Fe.edges.remove_node(o.node),o.helper=null;let r=null;if(!Fe.edges.empty()){let p=Fe.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){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(l,a.helper),a.helper=l}break}case 3:{let o=null;if(!Fe.edges.empty()){let a=Fe.edges.parent;for(;a.prev!=null;)a=a.prev;for(;a!=null;){let p=a.data;if(!Ge.vert_lt(p,l)){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(l,r.helper),r.helper=l}l.node=Fe.edges.insert(l),l.helper=l;break}case 4:{let o=l.prev;if(Fe.left_vertex(l)){if(o.helper==null)throw new Error("Fatal error (5): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(l,o.helper),Fe.edges.remove_node(o.node),o.helper=null,l.node=Fe.edges.insert(l),l.helper=l}else{let r=null;if(!Fe.edges.empty()){let p=Fe.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){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(l,a.helper),a.helper=l}break}}}return t}};Fe.queue=null,Fe.edges=null,Fe.sharedPPoly=null;var ml=Fe;var Ji=class Ji{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 Ji.zpp_pool==null?n=new Ji:(n=Ji.zpp_pool,Ji.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(){}};Ji.zpp_pool=null;var St=Ji;var At=class At{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(ye.poolVec2==null?t=new e.geom.Vec2:(t=ye.poolVec2,ye.poolVec2=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t==ye.nextVec2&&(ye.nextVec2=null)),t.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.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 o=t.zpp_inner;o._validate!=null&&o._validate(),i=t.zpp_inner.y==0}else i=!1;if(!i){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=s=>this.origin_invalidate(s);let n;if(ye.poolVec2==null?n=new e.geom.Vec2:(n=ye.poolVec2,ye.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==ye.nextVec2&&(ye.nextVec2=null)),n.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.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 o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){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=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(ye.poolVec2==null?s=new n.geom.Vec2:(s=ye.poolVec2,ye.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==ye.nextVec2&&(ye.nextVec2=null)),s.zpp_inner==null){let i;ae.zpp_pool==null?i=new ae:(i=ae.zpp_pool,ae.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 o=i;for(i=i.next;i!=null;){let u=i;s+=o.x*(u.y-l.y);let x=u.y*o.x-u.x*o.y;n.localCOMx+=(o.x+u.x)*x,n.localCOMy+=(o.y+u.y)*x,l=o,o=u,i=i.next}i=n.lverts.next;let r=i;s+=o.x*(r.y-l.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,l=o,o=r,i=i.next;let p=i;s+=o.x*(p.y-l.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,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,o=1/Math.sqrt(l);return s*=o,i*=o,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 o=s.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=s,s=s.next}let i=e.zpp_inner.inner,l;bs.zpp_pool==null?l=new bs:(l=bs.zpp_pool,bs.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){At._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,o=2*(s*this.dirx+i*this.diry),r=s*s+i*i-e.radius*e.radius,a=o*o-4*l*r;if(a==0){let p=-o/2*l;if((!t||r>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),h=At._allocVec2(c.nx,c.ny);return bn.getRay(h,p,r<=0,e.outer)}else return null}else{a=Math.sqrt(a),l=1/(2*l);let p=(-o-a)*l,c=(-o+a)*l;if(p>0)if(p<n&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=At._allocVec2(h.nx,h.ny);return bn.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=At._allocVec2(h.nx,h.ny);return bn.getRay(u,c,!0,e.outer)}else return null;else return null}}circlesect2(e,t,n){At._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,o=2*(s*this.dirx+i*this.diry),r=s*s+i*i-e.radius*e.radius,a=o*o-4*l*r;if(a==0){let p=-o/2*l;if((!t||r>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),h=At._allocVec2(c.nx,c.ny),u=bn.getRay(h,p,r<=0,e.outer);At._insertSorted(n,u)}}else{a=Math.sqrt(a),l=1/(2*l);let p=(-o-a)*l,c=(-o+a)*l;if(p>0&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=At._allocVec2(h.nx,h.ny),x=bn.getRay(u,p,!1,e.outer);At._insertSorted(n,x)}if(c>0&&c<=this.maxdist&&t){let h=this._circleNormal(c,e,!0),u=At._allocVec2(h.nx,h.ny),x=bn.getRay(u,c,!0,e.outer);At._insertSorted(n,x)}}}polysect(e,t,n){let s=me(),i=n,l=null,o=e.edges.head,r=!0,a=e.gverts.next,p=a,c=a.next;for(;c!=null;){let h=c,u=o.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,m=h.y-p.y,d=p.x-this.originx,y=p.y-this.originy,b=m*this.dirx-x*this.diry;if(b*b>s.Config.epsilon){b=1/b;let f=(m*d-x*y)*b;if(f>0&&f<i&&f<=this.maxdist){let P=(this.diry*d-this.dirx*y)*b;P>-s.Config.epsilon&&P<1+s.Config.epsilon&&(i=f,l=o.elt)}}}o=o.next,p=h,c=c.next}if(r){c=e.gverts.next;let h=c,u=o.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,m=h.y-p.y,d=p.x-this.originx,y=p.y-this.originy,b=m*this.dirx-x*this.diry;if(b*b>s.Config.epsilon){b=1/b;let f=(m*d-x*y)*b;if(f>0&&f<i&&f<=this.maxdist){let P=(this.diry*d-this.dirx*y)*b;P>-s.Config.epsilon&&P<1+s.Config.epsilon&&(i=f,l=o.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 m=At._allocVec2(h,u);return bn.getRay(m,i,x,e.outer)}else return null}polysect2(e,t,n){let s=me(),i=1/0,l=-1,o=null,r=null,a=e.edges.head,p=!0,c=e.gverts.next,h=c,u=c.next;for(;u!=null;){let x=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let d=x.x-h.x,y=x.y-h.y,b=h.x-this.originx,f=h.y-this.originy,P=y*this.dirx-d*this.diry;if(P*P>s.Config.epsilon){P=1/P;let k=(y*b-d*f)*P;if(k>0&&k<=this.maxdist&&(k<i||k>l)){let _=(this.diry*b-this.dirx*f)*P;_>-s.Config.epsilon&&_<1+s.Config.epsilon&&(k<i&&(i=k,o=a.elt),k>l&&(l=k,r=a.elt))}}}a=a.next,h=x,u=u.next}if(p){u=e.gverts.next;let x=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let d=x.x-h.x,y=x.y-h.y,b=h.x-this.originx,f=h.y-this.originy,P=y*this.dirx-d*this.diry;if(P*P>s.Config.epsilon){P=1/P;let k=(y*b-d*f)*P;if(k>0&&k<=this.maxdist&&(k<i||k>l)){let _=(this.diry*b-this.dirx*f)*P;_>-s.Config.epsilon&&_<1+s.Config.epsilon&&(k<i&&(i=k,o=a.elt),k>l&&(l=k,r=a.elt))}}}}if(o!=null){let x=o.gnormx,m=o.gnormy,d=x*this.dirx+m*this.diry>0;d&&(x=-x,m=-m);let y=At._allocVec2(x,m),b=bn.getRay(y,i,d,e.outer);At._insertSorted(n,b)}if(r!=null&&o!=r){let x=r.gnormx,m=r.gnormy,d=x*this.dirx+m*this.diry>0;d&&(x=-x,m=-m);let y=At._allocVec2(x,m),b=bn.getRay(y,l,d,e.outer);At._insertSorted(n,b)}}};At.internal=!1;var bl=At;var vi=class vi{constructor(){this.forced=!1;this.x=0;this.y=0;this.links=null;this.id=0;this.next=null;this.node=null;this.id=yn.ZPP_SimpleVert(),$t.zpp_pool==null?this.links=new $t:(this.links=$t.zpp_pool,$t.zpp_pool=this.links.next,this.links.next=null),this.links.lt=vi.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 vi.zpp_pool==null?n=new vi:(n=vi.zpp_pool,vi.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(){}};vi.zpp_pool=null;var Ee=vi;var Ui=class Ui{constructor(){this.left=null;this.right=null;this.vertices=null;this.id=0;this.next=null;this.prev=null;this.node=null;this.id=yn.ZPP_SimpleSeg(),$t.zpp_pool==null?this.vertices=new $t:(this.vertices=$t.zpp_pool,$t.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 Ui.zpp_pool==null?n=new Ui:(n=Ui.zpp_pool,Ui.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}};Ui.zpp_pool=null;var Vt=Ui;var Wi=class Wi{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 Wi.zpp_pool==null?t=new Wi:(t=Wi.zpp_pool,Wi.zpp_pool=t.next,t.next=null),t.vertex=e,t}free(){this.vertex=null,this.segment=this.segment2=null,this.node=null}alloc(){}};Wi.zpp_pool=null;var Me=Wi;var Ki=class{constructor(){this.sweepx=0;this.tree=null;fs.zpp_pool==null?this.tree=new fs:(this.tree=fs.zpp_pool,fs.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,o,r,a,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,o=s.x-n.x,r=s.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.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,o=l.x-i.x,r=l.y-i.y,a=n.x-i.x,p=n.y-i.y,h=(c?r*a-o*p:p*o-a*r)<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,o=s.x-n.x,r=s.y-n.y,a=l.x-n.x,p=l.y-n.y,(c?r*a-o*p:p*o-a*r)<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,o=s.x-n.x,r=s.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?r*a-o*p:p*o-a*r)<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,o=l.x-i.x,r=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let h=c?r*a-o*p:p*o-a*r;c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let u=c?r*a-o*p:p*o-a*r;return h*u>=0?h>=0:this.sweepx>=n.x}else if(i.x==l.x){c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=c?r*a-o*p:p*o-a*r;c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=c?r*a-o*p:p*o-a*r;return h*u>=0?h<0:this.sweepx<i.x}else{c=s.x<n.x,o=s.x-n.x,r=s.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;c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=(c?r*a-o*p:p*o-a*r)<0;if(h==u)return h;{c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let x=(c?r*a-o*p:p*o-a*r)>=0;c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let m=(c?r*a-o*p:p*o-a*r)>=0;if(x==m)return x;let d=(this.sweepx-n.x)/(s.x-n.x)*(s.y-n.y)+n.y,y=(this.sweepx-i.x)/(l.x-i.x)*(l.y-i.y)+i.y;return d>y}}}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,o=(i.x-n.x)*(s.y-n.y)-(s.x-n.x)*(i.y-n.y),r=(l.x-n.x)*(s.y-n.y)-(s.x-n.x)*(l.y-n.y);if(o*r>0)return!1;{let a=(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!(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,s=e.right,i=t.left,l=t.right,o=s.x-n.x,r=s.y-n.y,a=l.x-i.x,p=l.y-i.y,c=p*o-a*r;if(c==0)return null;c=1/c;let h=i.x-n.x,u=i.y-n.y,x=(p*h-a*u)*c;if(x<0||x>1)return null;let m=(r*h-o*u)*c;if(m<0||m>1)return null;let d;if(m==0||m==1||x==0||x==1){let f=m==0;if(m==1&&f)throw new Error("corner case 1a");if(m==1&&(f=!0),x==0&&f)throw new Error("corner case 1b");if(x==0&&(f=!0),x==1&&f)throw new Error("corner case 1c");d=m==0?i:m==1?l:x==0?n:s}else{let f=.5*(n.x+o*x+i.x+a*m),P=.5*(n.y+r*x+i.y+p*m),k;Ee.zpp_pool==null?k=new Ee:(k=Ee.zpp_pool,Ee.zpp_pool=k.next,k.next=null),k.x=f,k.y=P,d=k}let y;Me.zpp_pool==null?y=new Me:(y=Me.zpp_pool,Me.zpp_pool=y.next,y.next=null),y.vertex=d;let b=y;return b.type=0,b.segment=e,b.segment2=t,b}}};var de=class de{static decompose(e,t){de.sweep==null&&(de.sweep=new Ki,de.inthash=new Ti),de.vertices==null&&($t.zpp_pool==null?de.vertices=new $t:(de.vertices=$t.zpp_pool,$t.zpp_pool=de.vertices.next,de.vertices.next=null),de.vertices.lt=Ee.less_xy,de.vertices.swapped=Ee.swap_nodes),de.queue==null&&(Xn.zpp_pool==null?de.queue=new Xn:(de.queue=Xn.zpp_pool,Xn.zpp_pool=de.queue.next,de.queue.next=null),de.queue.lt=Me.less_xy,de.queue.swapped=Me.swap_nodes);let n=null,s=null,i=e,l=e;if(i!=null){let x=i;for(;;){let m=x,d=m.x,y=m.y,b;Ee.zpp_pool==null?b=new Ee:(b=Ee.zpp_pool,Ee.zpp_pool=b.next,b.next=null),b.x=d,b.y=y;let f=b,P=de.vertices.parent;for(;P!=null;)if(de.vertices.lt(f,P.data))P=P.prev;else if(de.vertices.lt(P.data,f))P=P.next;else break;let k=P;if(k!=null){let _=f;_.links.clear(),_.node=null,_.forced=!1,_.next=Ee.zpp_pool,Ee.zpp_pool=_,f=k.data}else f.node=de.vertices.insert(f);if(s!=null){let _;Me.zpp_pool==null?_=new Me:(_=Me.zpp_pool,Me.zpp_pool=_.next,_.next=null),_.vertex=s;let z=_,C;Me.zpp_pool==null?C=new Me:(C=Me.zpp_pool,Me.zpp_pool=C.next,C.next=null),C.vertex=f;let w=C,g;Me.less_xy(z,w)?(z.type=1,w.type=2,g=Vt.get(s,f)):(z.type=2,w.type=1,g=Vt.get(f,s)),z.segment=w.segment=g,de.queue.insert(z),de.queue.insert(w),s.links.insert(f),f.links.insert(s)}if(s=f,n==null&&(n=f),x=x.next,x==l)break}}let o;Me.zpp_pool==null?o=new Me:(o=Me.zpp_pool,Me.zpp_pool=o.next,o.next=null),o.vertex=s;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=Vt.get(s,n)):(r.type=2,p.type=1,c=Vt.get(n,s)),r.segment=p.segment=c,de.queue.insert(r),de.queue.insert(p),s.links.insert(n),n.links.insert(s),de.ints==null&&(Xn.zpp_pool==null?de.ints=new Xn:(de.ints=Xn.zpp_pool,Xn.zpp_pool=de.ints.next,de.ints.next=null),de.ints.lt=Me.less_xy);!de.queue.empty();){let x=de.queue.pop_front();if(de.sweep.sweepx=x.vertex.x,x.type==1){let d=x.segment;if(de.sweep.add(d),d.next!=null&&d!=null&&!(d.next.id<d.id?de.inthash.has(d.next.id,d.id):de.inthash.has(d.id,d.next.id))){let y=de.sweep.intersection(d.next,d);if(y!=null)if(y.vertex.x>=de.sweep.sweepx){let b=de.queue.parent;for(;b!=null;)if(de.queue.lt(y,b.data))b=b.prev;else if(de.queue.lt(b.data,y))b=b.next;else break;let f=b;if(f==null){let P=de.ints.parent;for(;P!=null;)if(de.ints.lt(y,P.data))P=P.prev;else if(de.ints.lt(P.data,y))P=P.next;else break;let k=P;if(k!=null){let _=y.vertex;_.links.clear(),_.node=null,_.forced=!1,_.next=Ee.zpp_pool,Ee.zpp_pool=_,y.vertex=k.data.vertex,k.data=y,de.queue.insert(y)}else de.queue.insert(y),de.ints.insert(y);if(d.next.id<d.id){let _=de.inthash,z=d.next.id,C=d.id,w;Te.zpp_pool==null?w=new Te:(w=Te.zpp_pool,Te.zpp_pool=w.next,w.next=null),w.id=z,w.di=C;let g=w;g.value=!0,_.add(g)}else{let _=de.inthash,z=d.id,C=d.next.id,w;Te.zpp_pool==null?w=new Te:(w=Te.zpp_pool,Te.zpp_pool=w.next,w.next=null),w.id=z,w.di=C;let g=w;g.value=!0,_.add(g)}}else{let P=f.data;if(P.segment!=y.segment||y.segment2!=P.segment2)throw new Error("corner case 2, shiiiit.");let k=y.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=Ee.zpp_pool,Ee.zpp_pool=k;let _=y;_.vertex=null,_.segment=_.segment2=null,_.node=null,_.next=Me.zpp_pool,Me.zpp_pool=_}}else{let b=y.vertex;b.links.clear(),b.node=null,b.forced=!1,b.next=Ee.zpp_pool,Ee.zpp_pool=b;let f=y;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Me.zpp_pool,Me.zpp_pool=f}}if(d!=null&&d.prev!=null&&!(d.id<d.prev.id?de.inthash.has(d.id,d.prev.id):de.inthash.has(d.prev.id,d.id))){let y=de.sweep.intersection(d,d.prev);if(y!=null)if(y.vertex.x>=de.sweep.sweepx){let b=de.queue.parent;for(;b!=null;)if(de.queue.lt(y,b.data))b=b.prev;else if(de.queue.lt(b.data,y))b=b.next;else break;let f=b;if(f==null){let P=de.ints.parent;for(;P!=null;)if(de.ints.lt(y,P.data))P=P.prev;else if(de.ints.lt(P.data,y))P=P.next;else break;let k=P;if(k!=null){let _=y.vertex;_.links.clear(),_.node=null,_.forced=!1,_.next=Ee.zpp_pool,Ee.zpp_pool=_,y.vertex=k.data.vertex,k.data=y,de.queue.insert(y)}else de.queue.insert(y),de.ints.insert(y);if(d.id<d.prev.id){let _=de.inthash,z=d.id,C=d.prev.id,w;Te.zpp_pool==null?w=new Te:(w=Te.zpp_pool,Te.zpp_pool=w.next,w.next=null),w.id=z,w.di=C;let g=w;g.value=!0,_.add(g)}else{let _=de.inthash,z=d.prev.id,C=d.id,w;Te.zpp_pool==null?w=new Te:(w=Te.zpp_pool,Te.zpp_pool=w.next,w.next=null),w.id=z,w.di=C;let g=w;g.value=!0,_.add(g)}}else{let P=f.data;if(P.segment!=y.segment||y.segment2!=P.segment2)throw new Error("corner case 2, shiiiit.");let k=y.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=Ee.zpp_pool,Ee.zpp_pool=k;let _=y;_.vertex=null,_.segment=_.segment2=null,_.node=null,_.next=Me.zpp_pool,Me.zpp_pool=_}}else{let b=y.vertex;b.links.clear(),b.node=null,b.forced=!1,b.next=Ee.zpp_pool,Ee.zpp_pool=b;let f=y;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Me.zpp_pool,Me.zpp_pool=f}}}else if(x.type==2){let d=x.segment;if(d.node!=null){let y=d.next,b=d.prev;de.sweep.remove(d);let f=d;if(f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=Vt.zpp_pool,Vt.zpp_pool=f,y!=null&&b!=null&&!(y.id<b.id?de.inthash.has(y.id,b.id):de.inthash.has(b.id,y.id))){let P=de.sweep.intersection(y,b);if(P!=null)if(P.vertex.x>=de.sweep.sweepx){let k=de.queue.parent;for(;k!=null;)if(de.queue.lt(P,k.data))k=k.prev;else if(de.queue.lt(k.data,P))k=k.next;else break;let _=k;if(_==null){let z=de.ints.parent;for(;z!=null;)if(de.ints.lt(P,z.data))z=z.prev;else if(de.ints.lt(z.data,P))z=z.next;else break;let C=z;if(C!=null){let w=P.vertex;w.links.clear(),w.node=null,w.forced=!1,w.next=Ee.zpp_pool,Ee.zpp_pool=w,P.vertex=C.data.vertex,C.data=P,de.queue.insert(P)}else de.queue.insert(P),de.ints.insert(P);if(y.id<b.id){let w=de.inthash,g=y.id,O=b.id,E;Te.zpp_pool==null?E=new Te:(E=Te.zpp_pool,Te.zpp_pool=E.next,E.next=null),E.id=g,E.di=O;let M=E;M.value=!0,w.add(M)}else{let w=de.inthash,g=b.id,O=y.id,E;Te.zpp_pool==null?E=new Te:(E=Te.zpp_pool,Te.zpp_pool=E.next,E.next=null),E.id=g,E.di=O;let M=E;M.value=!0,w.add(M)}}else{let z=_.data;if(z.segment!=P.segment||P.segment2!=z.segment2)throw new Error("corner case 2, shiiiit.");let C=P.vertex;C.links.clear(),C.node=null,C.forced=!1,C.next=Ee.zpp_pool,Ee.zpp_pool=C;let w=P;w.vertex=null,w.segment=w.segment2=null,w.node=null,w.next=Me.zpp_pool,Me.zpp_pool=w}}else{let k=P.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=Ee.zpp_pool,Ee.zpp_pool=k;let _=P;_.vertex=null,_.segment=_.segment2=null,_.node=null,_.next=Me.zpp_pool,Me.zpp_pool=_}}}}else{let d=x.vertex,y=d.node==null,b=x.segment,f=x.segment2;if(f.next!=b){let C=b;b=f,f=C}let P=b.vertices.parent;for(;P!=null;)if(b.vertices.lt(d,P.data))P=P.prev;else if(b.vertices.lt(P.data,d))P=P.next;else break;let k=P==null,_=f.vertices.parent;for(;_!=null;)if(f.vertices.lt(d,_.data))_=_.prev;else if(f.vertices.lt(_.data,d))_=_.next;else break;let z=_==null;if(k){let C=b.vertices.insert(d),w=d==b.left?d:b.vertices.predecessor_node(C).data,g=d==b.right?d:b.vertices.successor_node(C).data;w.links.remove(g),d!=w&&w.links.insert(d),g.links.remove(w),d!=g&&g.links.insert(d),d!=w&&d.links.insert(w),d!=g&&d.links.insert(g)}if(z){let C=f.vertices.insert(d),w=d==f.left?d:f.vertices.predecessor_node(C).data,g=d==f.right?d:f.vertices.successor_node(C).data;w.links.remove(g),d!=w&&w.links.insert(d),g.links.remove(w),d!=g&&g.links.insert(d),d!=w&&d.links.insert(w),d!=g&&d.links.insert(g)}if(y&&(d.node=de.vertices.insert(d)),d.forced=!0,y){let C=b.node,w=f.node;C.data=f,w.data=b,b.node=w,f.node=C,f.next=b.next,b.next=f,b.prev=f.prev,f.prev=b,b.prev!=null&&(b.prev.next=b),f.next!=null&&(f.next.prev=f)}if(f.next!=null&&f!=null&&!(f.next.id<f.id?de.inthash.has(f.next.id,f.id):de.inthash.has(f.id,f.next.id))){let C=de.sweep.intersection(f.next,f);if(C!=null)if(C.vertex.x>=de.sweep.sweepx){let w=de.queue.parent;for(;w!=null;)if(de.queue.lt(C,w.data))w=w.prev;else if(de.queue.lt(w.data,C))w=w.next;else break;let g=w;if(g==null){let O=de.ints.parent;for(;O!=null;)if(de.ints.lt(C,O.data))O=O.prev;else if(de.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=Ee.zpp_pool,Ee.zpp_pool=M,C.vertex=E.data.vertex,E.data=C,de.queue.insert(C)}else de.queue.insert(C),de.ints.insert(C);if(f.next.id<f.id){let M=de.inthash,N=f.next.id,Z=f.id,A;Te.zpp_pool==null?A=new Te:(A=Te.zpp_pool,Te.zpp_pool=A.next,A.next=null),A.id=N,A.di=Z;let S=A;S.value=!0,M.add(S)}else{let M=de.inthash,N=f.id,Z=f.next.id,A;Te.zpp_pool==null?A=new Te:(A=Te.zpp_pool,Te.zpp_pool=A.next,A.next=null),A.id=N,A.di=Z;let S=A;S.value=!0,M.add(S)}}else{let O=g.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=Ee.zpp_pool,Ee.zpp_pool=E;let M=C;M.vertex=null,M.segment=M.segment2=null,M.node=null,M.next=Me.zpp_pool,Me.zpp_pool=M}}else{let w=C.vertex;w.links.clear(),w.node=null,w.forced=!1,w.next=Ee.zpp_pool,Ee.zpp_pool=w;let g=C;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Me.zpp_pool,Me.zpp_pool=g}}if(b!=null&&b.prev!=null&&!(b.id<b.prev.id?de.inthash.has(b.id,b.prev.id):de.inthash.has(b.prev.id,b.id))){let C=de.sweep.intersection(b,b.prev);if(C!=null)if(C.vertex.x>=de.sweep.sweepx){let w=de.queue.parent;for(;w!=null;)if(de.queue.lt(C,w.data))w=w.prev;else if(de.queue.lt(w.data,C))w=w.next;else break;let g=w;if(g==null){let O=de.ints.parent;for(;O!=null;)if(de.ints.lt(C,O.data))O=O.prev;else if(de.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=Ee.zpp_pool,Ee.zpp_pool=M,C.vertex=E.data.vertex,E.data=C,de.queue.insert(C)}else de.queue.insert(C),de.ints.insert(C);if(b.id<b.prev.id){let M=de.inthash,N=b.id,Z=b.prev.id,A;Te.zpp_pool==null?A=new Te:(A=Te.zpp_pool,Te.zpp_pool=A.next,A.next=null),A.id=N,A.di=Z;let S=A;S.value=!0,M.add(S)}else{let M=de.inthash,N=b.prev.id,Z=b.id,A;Te.zpp_pool==null?A=new Te:(A=Te.zpp_pool,Te.zpp_pool=A.next,A.next=null),A.id=N,A.di=Z;let S=A;S.value=!0,M.add(S)}}else{let O=g.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=Ee.zpp_pool,Ee.zpp_pool=E;let M=C;M.vertex=null,M.segment=M.segment2=null,M.node=null,M.next=Me.zpp_pool,Me.zpp_pool=M}}else{let w=C.vertex;w.links.clear(),w.node=null,w.forced=!1,w.next=Ee.zpp_pool,Ee.zpp_pool=w;let g=C;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Me.zpp_pool,Me.zpp_pool=g}}de.ints.remove(x)}let m=x;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Me.zpp_pool,Me.zpp_pool=m}let h=0,u=de.inthash.table.length;for(;h<u;){let x=h++,m=de.inthash.table[x];if(m!=null){for(;m!=null;){let d=m.hnext;m.hnext=null;let y=m;y.next=Te.zpp_pool,Te.zpp_pool=y,m=d}de.inthash.table[x]=null}}for(t==null&&(t=new ms);!de.vertices.empty();)de.clip_polygon(de.vertices,t);return t}static clip_polygon(e,t){let n=null,s=e.first(),i=s,l=s.links.parent,o=l.prev==null?l.next:l.prev,r=l.data,a=o.data,p=s.x-r.x,c=s.y-r.y,h=a.x-s.x;(a.y-s.y)*p-h*c<0&&(a=r);let x=s.x,m=s.y,d;ge.zpp_pool==null?d=new ge:(d=ge.zpp_pool,ge.zpp_pool=d.next,d.next=null),d.forced=!1,d.x=x,d.y=m;let y=d;if(n==null)y.prev=y.next=y;else{let f=n,P=f.next;y.prev=f,y.next=P,P.prev=y,f.next=y}for(n=y,n.forced=s.forced;;){if(s.links.remove(a),a.links.remove(s),a==i){if(s.links.empty()){e.remove(s);let z=s;z.links.clear(),z.node=null,z.forced=!1,z.next=Ee.zpp_pool,Ee.zpp_pool=z}break}let f=a.x,P=a.y,k;ge.zpp_pool==null?k=new ge:(k=ge.zpp_pool,ge.zpp_pool=k.next,k.next=null),k.forced=!1,k.x=f,k.y=P;let _=k;if(n==null)_.prev=_.next=_;else{let z=n,C=z.next;_.prev=z,_.next=C,C.prev=_,z.next=_}if(n=_,n.forced=a.forced,a.links.singular()){if(s.links.empty()){e.remove(s);let z=s;z.links.clear(),z.node=null,z.forced=!1,z.next=Ee.zpp_pool,Ee.zpp_pool=z}s=a,a=a.links.parent.data}else{let z=null,C=0;if(!a.links.empty()){let w=a.links.parent;for(;w.prev!=null;)w=w.prev;for(;w!=null;){let g=w.data;if(z==null){z=g;let O=a.x-s.x,E=a.y-s.y,M=g.x-a.x;C=(g.y-a.y)*O-M*E}else{let O=a.x-s.x,E=a.y-s.y,M=g.x-a.x,Z=(g.y-a.y)*O-M*E;if(Z>0&&C<=0)z=g,C=Z;else if(C*Z>=0){let A=a.x-g.x,S=a.y-g.y,L=z.x-a.x;(z.y-a.y)*A-L*S>0&&(z=g,C=Z)}}if(w.next!=null)for(w=w.next;w.prev!=null;)w=w.prev;else{for(;w.parent!=null&&w==w.parent.next;)w=w.parent;w=w.parent}}}if(s.links.empty()){e.remove(s);let w=s;w.links.clear(),w.node=null,w.forced=!1,w.next=Ee.zpp_pool,Ee.zpp_pool=w}s=a,a=z}}e.remove(i);let b=i;b.links.clear(),b.node=null,b.forced=!1,b.next=Ee.zpp_pool,Ee.zpp_pool=b,t.add(n)}static isSimple(e){de.sweep==null&&(de.sweep=new Ki,de.inthash=new Ti);let t=de.list_vertices;t==null&&(t=de.list_vertices=new Tl);let n=e,s=e;if(n!=null){let d=n;for(;;){let y=d,b=y.x,f=y.y,P;if(Ee.zpp_pool==null?P=new Ee:(P=Ee.zpp_pool,Ee.zpp_pool=P.next,P.next=null),P.x=b,P.y=f,t.add(P),d=d.next,d==s)break}}let i=de.list_queue;i==null&&(i=de.list_queue=new Ll);let l=t.head,o=l.elt;for(l=l.next;l!=null;){let d=l.elt,y;Me.zpp_pool==null?y=new Me:(y=Me.zpp_pool,Me.zpp_pool=y.next,y.next=null),y.vertex=o;let b=i.add(y),f;Me.zpp_pool==null?f=new Me:(f=Me.zpp_pool,Me.zpp_pool=f.next,f.next=null),f.vertex=d;let P=i.add(f),k;Me.less_xy(b,P)?(b.type=1,P.type=2,k=Vt.get(o,d)):(b.type=2,P.type=1,k=Vt.get(d,o)),b.segment=P.segment=k,o=d,l=l.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=i.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 h=i.add(c),u;Me.less_xy(p,h)?(p.type=1,h.type=2,u=Vt.get(o,r)):(p.type=2,h.type=1,u=Vt.get(r,o)),p.segment=h.segment=u;let x=i;if(x.head!=null&&x.head.next!=null){let d=x.head,y,b,f,P,k=1,_,z,C;for(;;){for(_=0,b=d,d=null,y=null;b!=null;){for(++_,f=b,z=0,C=k;f!=null&&z<k;)++z,f=f.next;for(;z>0||C>0&&f!=null;)z==0?(P=f,f=f.next,--C):C==0||f==null||Me.less_xy(b.elt,f.elt)?(P=b,b=b.next,--z):(P=f,f=f.next,--C),y!=null?y.next=P:d=P,y=P;b=f}if(y.next=null,k<<=1,!(_>1))break}x.head=d,x.modified=!0,x.pushmod=!0}let m=!0;for(;i.head!=null;){let d=i.pop_unsafe(),y=d.segment;if(d.type==1){if(de.sweep.add(y),de.sweep.intersect(y,y.next)||de.sweep.intersect(y,y.prev)){m=!1;break}}else if(d.type==2){if(de.sweep.intersect(y.prev,y.next)){m=!1;break}de.sweep.remove(y);let f=y;f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=Vt.zpp_pool,Vt.zpp_pool=f}let b=d;b.vertex=null,b.segment=b.segment2=null,b.node=null,b.next=Me.zpp_pool,Me.zpp_pool=b}for(;i.head!=null;){let d=i.pop_unsafe();if(d.type==2){let b=d.segment;b.left=b.right=null,b.prev=null,b.node=null,b.vertices.clear(),b.next=Vt.zpp_pool,Vt.zpp_pool=b}let y=d;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Me.zpp_pool,Me.zpp_pool=y}for(de.sweep.clear();t.head!=null;){let d=t.pop_unsafe();d.links.clear(),d.node=null,d.forced=!1,d.next=Ee.zpp_pool,Ee.zpp_pool=d}return m}};de.sweep=null,de.inthash=null,de.vertices=null,de.queue=null,de.ints=null,de.list_vertices=null,de.list_queue=null;var fl=de;var Yi=class Yi{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 Yi.zpp_pool==null?t=new Yi:(t=Yi.zpp_pool,Yi.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t.flag=!1,t}free(){}alloc(){}};Yi.zpp_pool=null;var gn=Yi;var Xi=class Xi{constructor(){this.next=null;this.min=null;this.max=null}static get(e,t){let n;return Xi.zpp_pool==null?n=new Xi:(n=Xi.zpp_pool,Xi.zpp_pool=n.next,n.next=null),n.min=e,n.max=t,n}free(){this.min=null,this.max=null}alloc(){}};Xi.zpp_pool=null;var Le=Xi;var It=class It{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,o=e.y-t.y;if(s*s+i*i==0)return l*l+o*o;{let a=(l*s+o*i)/(s*s+i*i);if(a<=0)return l*l+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 l-=s*p,o-=i*p,l*l+o*o}}}static simplify(e,t){let n=null,s=null,i=null;t*=t,It.stack==null&&(It.stack=new jl);let l=null,o=null,r=e;for(;;){let p;gn.zpp_pool==null?p=new gn:(p=gn.zpp_pool,gn.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,l!=null){let u=It.stack,x;Le.zpp_pool==null?x=new Le:(x=Le.zpp_pool,Le.zpp_pool=x.next,x.next=null),x.min=l,x.max=c,u.add(x)}else o=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)),r=r.next,r==e)break}if(It.stack.head==null)if(o==null){s.flag=i.flag=!0;let p=It.stack,c;Le.zpp_pool==null?c=new Le:(c=Le.zpp_pool,Le.zpp_pool=c.next,c.next=null),c.min=s,c.max=i,p.add(c);let h=It.stack,u;Le.zpp_pool==null?u=new Le:(u=Le.zpp_pool,Le.zpp_pool=u.next,u.next=null),u.min=i,u.max=s,h.add(u)}else{let p=s.x-o.x+(s.y-o.y);p<0&&(p=-p);let c=i.x-o.x+(i.y-o.y);if(c<0&&(c=-c),p>c){s.flag=o.flag=!0;let h=It.stack,u;Le.zpp_pool==null?u=new Le:(u=Le.zpp_pool,Le.zpp_pool=u.next,u.next=null),u.min=s,u.max=o,h.add(u);let x=It.stack,m;Le.zpp_pool==null?m=new Le:(m=Le.zpp_pool,Le.zpp_pool=m.next,m.next=null),m.min=o,m.max=s,x.add(m)}else{i.flag=o.flag=!0;let h=It.stack,u;Le.zpp_pool==null?u=new Le:(u=Le.zpp_pool,Le.zpp_pool=u.next,u.next=null),u.min=i,u.max=o,h.add(u);let x=It.stack,m;Le.zpp_pool==null?m=new Le:(m=Le.zpp_pool,Le.zpp_pool=m.next,m.next=null),m.min=o,m.max=i,x.add(m)}}else{let p=It.stack,c;Le.zpp_pool==null?c=new Le:(c=Le.zpp_pool,Le.zpp_pool=c.next,c.next=null),c.min=l,c.max=o,p.add(c)}for(;It.stack.head!=null;){let p=It.stack.pop_unsafe(),c=p.min,h=p.max,u=p;u.min=u.max=null,u.next=Le.zpp_pool,Le.zpp_pool=u;let x=t,m=null,d=c.next;for(;d!=h;){let y=It.distance(d,c,h);y>x&&(x=y,m=d),d=d.next}if(m!=null){m.flag=!0;let y=It.stack,b;Le.zpp_pool==null?b=new Le:(b=Le.zpp_pool,Le.zpp_pool=b.next,b.next=null),b.min=c,b.max=m,y.add(b);let f=It.stack,P;Le.zpp_pool==null?P=new Le:(P=Le.zpp_pool,Le.zpp_pool=P.next,P.next=null),P.min=m,P.max=h,f.add(P)}}let a=null;for(;n!=null;){if(n.flag){let p=n.x,c=n.y,h;ge.zpp_pool==null?h=new ge:(h=ge.zpp_pool,ge.zpp_pool=h.next,h.next=null),h.forced=!1,h.x=p,h.y=c;let u=h;a==null?u.prev=u.next=u:(u.prev=a,u.next=a.next,a.next.prev=u,a.next=u),a=u,a.forced=n.forced}if(n!=null&&n.prev==n)n.next=n.prev=null,n.next=gn.zpp_pool,gn.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=gn.zpp_pool,gn.zpp_pool=n,n=p}}return a}};It.stack=null;var zl=It;var Ws=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=ae.get(0,0),this.c2=ae.get(0,0),this.axis=ae.get(0,0)}alloc(){this.failed=!1,this.s1=this.s2=null,this.arbiter=null}free(){}};Ws.zpp_pool=null;function at(v){return v.type===0||v.type===2}function Dt(v){return v.type===0?v.circle.radius:v.capsule.halfLength+v.capsule.radius}var Cn=class{static dynamicSweep(e,t,n,s,i){let l=me();i==null&&(i=!1);let o=e.s1,r=e.s2,a=o.body,p=r.body,c=0,h=0;c=p.velx-a.velx,h=p.vely-a.vely;let u=a.angvel;u<0&&(u=-u);let x=p.angvel;x<0&&(x=-x);let m=o.sweepCoef*u+r.sweepCoef*x;if(!i&&!e.kinematic&&c*c+h*h<l.Config.dynamicSweepLinearThreshold*l.Config.dynamicSweepLinearThreshold&&m<l.Config.dynamicSweepAngularThreshold){e.toi=-1,e.failed=!0;return}let d=e.c1,y=e.c2,b=e.axis,f=n,P=0;for(;;){let Z=f*t,A=Z-a.sweepTime;if(A!=0){a.sweepTime=Z;let Y=A;if(a.posx+=a.velx*Y,a.posy+=a.vely*Y,a.angvel!=0){let X=a.sweep_angvel*A;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,J=1-.5*ee,F=1-ee*ee/8,D=(J*a.axisx+X*a.axisy)*F;a.axisy=(J*a.axisy-X*a.axisx)*F,a.axisx=D}}}if(o.type==0||o.type===2)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 Q=ee,W=X;X=X.next,Q.x=a.posx+(a.axisy*W.x-a.axisx*W.y),Q.y=a.posy+(W.x*a.axisx+W.y*a.axisy),ee=ee.next}let J=Y.edges.head,F=Y.gverts.next,D=F;for(F=F.next;F!=null;){let Q=F,W=J.elt;J=J.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=D.y*W.gnormx-D.x*W.gnormy,W.tp1=Q.y*W.gnormx-Q.x*W.gnormy,D=Q,F=F.next}let I=Y.gverts.next,U=J.elt;J=J.next,U.gnormx=a.axisy*U.lnormx-a.axisx*U.lnormy,U.gnormy=U.lnormx*a.axisx+U.lnormy*a.axisy,U.gprojection=a.posx*U.gnormx+a.posy*U.gnormy+U.lprojection,U.tp0=D.y*U.gnormx-D.x*U.gnormy,U.tp1=I.y*U.gnormx-I.x*U.gnormy}let S=f*t,L=S-p.sweepTime;if(L!=0){p.sweepTime=S;let Y=L;if(p.posx+=p.velx*Y,p.posy+=p.vely*Y,p.angvel!=0){let X=p.sweep_angvel*L;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,F=1-ee*ee/8,D=(J*p.axisx+X*p.axisy)*F;p.axisy=(J*p.axisy-X*p.axisx)*F,p.axisx=D}}}if(r.type==0||r.type===2)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 Q=ee,W=X;X=X.next,Q.x=p.posx+(p.axisy*W.x-p.axisx*W.y),Q.y=p.posy+(W.x*p.axisx+W.y*p.axisy),ee=ee.next}let J=Y.edges.head,F=Y.gverts.next,D=F;for(F=F.next;F!=null;){let Q=F,W=J.elt;J=J.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=D.y*W.gnormx-D.x*W.gnormy,W.tp1=Q.y*W.gnormx-Q.x*W.gnormy,D=Q,F=F.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=D.y*U.gnormx-D.x*U.gnormy,U.tp1=I.y*U.gnormx-I.x*U.gnormy}let T=o,G=r,q=d,R=y;var k;if(at(T)&&at(G)){let Y=T.circle||T.capsule,X=G.circle||G.capsule,ee=Dt(T),J=Dt(G);var _;let F=0,D=0;F=X.worldCOMx-Y.worldCOMx,D=X.worldCOMy-Y.worldCOMy;let I=Math.sqrt(F*F+D*D);if(_=I-(ee+J),_<1e100){if(I==0)F=1,D=0;else{let W=1/I;F*=W,D*=W}let U=ee;q.x=Y.worldCOMx+F*U,q.y=Y.worldCOMy+D*U;let Q=-J;R.x=X.worldCOMx+F*Q,R.y=X.worldCOMy+D*Q,b.x=F,b.y=D}k=_}else{let Y=!1;if(at(T)&&G.type==1){let X=T;T=G,G=X;let ee=q;q=R,R=ee,Y=!0}if(T.type==1&&at(G)){let X=T.polygon,ee=G.circle||G.capsule,J=Dt(G),F=-1e100,D=null,I=X.edges.head;for(;I!=null;){let U=I.elt,Q=U.gnormx*ee.worldCOMx+U.gnormy*ee.worldCOMy-U.gprojection-J;if(Q>1e100){F=Q;break}Q>0?Q>F&&(F=Q,D=U):F<0&&Q>F&&(F=Q,D=U),I=I.next}if(F<1e100){let U=D.gp0,Q=D.gp1,W=ee.worldCOMy*D.gnormx-ee.worldCOMx*D.gnormy;if(W<=U.y*D.gnormx-U.x*D.gnormy){let ie=0,oe=0;ie=ee.worldCOMx-U.x,oe=ee.worldCOMy-U.y;let se=Math.sqrt(ie*ie+oe*oe);if(F=se-J,F<1e100){if(se==0)ie=1,oe=0;else{let le=1/se;ie*=le,oe*=le}let ne=0;q.x=U.x+ie*ne,q.y=U.y+oe*ne;let re=-J;R.x=ee.worldCOMx+ie*re,R.y=ee.worldCOMy+oe*re,b.x=ie,b.y=oe}}else if(W>=Q.y*D.gnormx-Q.x*D.gnormy){let ie=0,oe=0;ie=ee.worldCOMx-Q.x,oe=ee.worldCOMy-Q.y;let se=Math.sqrt(ie*ie+oe*oe);if(F=se-J,F<1e100){if(se==0)ie=1,oe=0;else{let le=1/se;ie*=le,oe*=le}let ne=0;q.x=Q.x+ie*ne,q.y=Q.y+oe*ne;let re=-J;R.x=ee.worldCOMx+ie*re,R.y=ee.worldCOMy+oe*re,b.x=ie,b.y=oe}}else{let ie=-J;R.x=ee.worldCOMx+D.gnormx*ie,R.y=ee.worldCOMy+D.gnormy*ie;let oe=-F;q.x=R.x+D.gnormx*oe,q.y=R.y+D.gnormy*oe,b.x=D.gnormx,b.y=D.gnormy}}Y&&(b.x=-b.x,b.y=-b.y),k=F}else{let X=T.polygon,ee=G.polygon,J=-1e100,F=null,D=null,I=0,U=X.edges.head;for(;U!=null;){let Q=U.elt,W=1e100,ie=ee.gverts.next;for(;ie!=null;){let oe=ie,se=Q.gnormx*oe.x+Q.gnormy*oe.y;se<W&&(W=se),ie=ie.next}if(W-=Q.gprojection,W>1e100){J=W;break}W>0?W>J&&(J=W,F=Q,I=1):J<0&&W>J&&(J=W,F=Q,I=1),U=U.next}if(J<1e100){let Q=ee.edges.head;for(;Q!=null;){let W=Q.elt,ie=1e100,oe=X.gverts.next;for(;oe!=null;){let se=oe,ne=W.gnormx*se.x+W.gnormy*se.y;ne<ie&&(ie=ne),oe=oe.next}if(ie-=W.gprojection,ie>1e100){J=ie;break}ie>0?ie>J&&(J=ie,D=W,I=2):J<0&&ie>J&&(J=ie,D=W,I=2),Q=Q.next}if(J<1e100){var z,C,w;if(I==1)z=X,C=ee,w=F;else{z=ee,C=X,w=D;let se=q;q=R,R=se,Y=!Y}let W=null,ie=1e100,oe=C.edges.head;for(;oe!=null;){let se=oe.elt,ne=w.gnormx*se.gnormx+w.gnormy*se.gnormy;ne<ie&&(ie=ne,W=se),oe=oe.next}if(Y?(b.x=-w.gnormx,b.y=-w.gnormy):(b.x=w.gnormx,b.y=w.gnormy),J>=0){let se=w.gp0,ne=w.gp1,re=W.gp0,le=W.gp1,he=0,pe=0,ce=0,te=0;he=ne.x-se.x,pe=ne.y-se.y,ce=le.x-re.x,te=le.y-re.y;let ue=1/(he*he+pe*pe),xe=1/(ce*ce+te*te),_e=-(he*(se.x-re.x)+pe*(se.y-re.y))*ue,ve=-(he*(se.x-le.x)+pe*(se.y-le.y))*ue,Se=-(ce*(re.x-se.x)+te*(re.y-se.y))*xe,Ve=-(ce*(re.x-ne.x)+te*(re.y-ne.y))*xe;_e<0?_e=0:_e>1&&(_e=1),ve<0?ve=0:ve>1&&(ve=1),Se<0?Se=0:Se>1&&(Se=1),Ve<0?Ve=0:Ve>1&&(Ve=1);let Ke=0,Xe=0,He=_e;Ke=se.x+he*He,Xe=se.y+pe*He;let Re=0,bt=0,vt=ve;Re=se.x+he*vt,bt=se.y+pe*vt;let pt=0,ct=0,rt=Se;pt=re.x+ce*rt,ct=re.y+te*rt;let Ye=0,ft=0,jt=Ve;Ye=re.x+ce*jt,ft=re.y+te*jt;let Gt=0,kt=0;Gt=Ke-re.x,kt=Xe-re.y;let Et=Gt*Gt+kt*kt,zn=0,Yt=0;zn=Re-le.x,Yt=bt-le.y;let xn=zn*zn+Yt*Yt,on=0,dn=0;on=pt-se.x,dn=ct-se.y;let Xt=on*on+dn*dn,Pn=0,Ht=0;Pn=Ye-ne.x,Ht=ft-ne.y;let _n=Pn*Pn+Ht*Ht,qt=0,Qt=0,rn=null;Et<xn?(qt=Ke,Qt=Xe,rn=re):(qt=Re,Qt=bt,rn=le,Et=xn);let li=0,Gn=0,Vn=null;if(Xt<_n?(li=pt,Gn=ct,Vn=se):(li=Ye,Gn=ft,Vn=ne,Xt=_n),Et<Xt?(q.x=qt,q.y=Qt,R.x=rn.x,R.y=rn.y,J=Math.sqrt(Et)):(R.x=li,R.y=Gn,q.x=Vn.x,q.y=Vn.y,J=Math.sqrt(Xt)),J!=0){b.x=R.x-q.x,b.y=R.y-q.y;let In=1/J;b.x*=In,b.y*=In,Y&&(b.x=-b.x,b.y=-b.y)}k=J}else{let se=0,ne=0;se=W.gp0.x,ne=W.gp0.y;let re=0,le=0;re=W.gp1.x,le=W.gp1.y;let he=0,pe=0;he=re-se,pe=le-ne;let ce=w.gnormy*se-w.gnormx*ne,te=w.gnormy*re-w.gnormx*le,ue=1/(te-ce),xe=(-w.tp1-ce)*ue;if(xe>l.Config.epsilon){let Ve=xe;se+=he*Ve,ne+=pe*Ve}let _e=(-w.tp0-te)*ue;if(_e<-l.Config.epsilon){let Ve=_e;re+=he*Ve,le+=pe*Ve}let ve=se*w.gnormx+ne*w.gnormy-w.gprojection,Se=re*w.gnormx+le*w.gnormy-w.gprojection;if(ve<Se){R.x=se,R.y=ne;let Ve=-ve;q.x=R.x+w.gnormx*Ve,q.y=R.y+w.gnormy*Ve,k=ve}else{R.x=re,R.y=le;let Ve=-Se;q.x=R.x+w.gnormx*Ve,q.y=R.y+w.gnormy*Ve,k=Se}}}else k=1e100}else k=1e100}}let j=k+s,V=c*b.x+h*b.y;if(j<l.Config.distanceThresholdCCD){if(i)break;let Y=0,X=0;Y=d.x-a.posx,X=d.y-a.posy;let ee=0,J=0;ee=y.x-p.posx,J=y.y-p.posy;let F=V-a.sweep_angvel*(b.y*Y-b.x*X)+p.sweep_angvel*(b.y*ee-b.x*J);if(F>0&&(e.slipped=!0),F<=0||j<l.Config.distanceThresholdCCD*.5)break}let K=(m-V)*t;if(K<=0){f=-1;break}let $=j/K;if($<1e-6&&($=1e-6),f+=$,f>=1){f=1;let Y=f*t,X=Y-a.sweepTime;if(X!=0){a.sweepTime=Y;let ie=X;if(a.posx+=a.velx*ie,a.posy+=a.vely*ie,a.angvel!=0){let oe=a.sweep_angvel*X;if(a.rot+=oe,oe*oe>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let se=oe*oe,ne=1-.5*se,re=1-se*se/8,le=(ne*a.axisx+oe*a.axisy)*re;a.axisy=(ne*a.axisy-oe*a.axisx)*re,a.axisx=le}}}if(o.type==0||o.type===2)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 ie=o.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ce=se,te=oe;oe=oe.next,ce.x=a.posx+(a.axisy*te.x-a.axisx*te.y),ce.y=a.posy+(te.x*a.axisx+te.y*a.axisy),se=se.next}let ne=ie.edges.head,re=ie.gverts.next,le=re;for(re=re.next;re!=null;){let ce=re,te=ne.elt;ne=ne.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=le.y*te.gnormx-le.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,le=ce,re=re.next}let he=ie.gverts.next,pe=ne.elt;ne=ne.next,pe.gnormx=a.axisy*pe.lnormx-a.axisx*pe.lnormy,pe.gnormy=pe.lnormx*a.axisx+pe.lnormy*a.axisy,pe.gprojection=a.posx*pe.gnormx+a.posy*pe.gnormy+pe.lprojection,pe.tp0=le.y*pe.gnormx-le.x*pe.gnormy,pe.tp1=he.y*pe.gnormx-he.x*pe.gnormy}let ee=f*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 oe=p.sweep_angvel*J;if(p.rot+=oe,oe*oe>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let se=oe*oe,ne=1-.5*se,re=1-se*se/8,le=(ne*p.axisx+oe*p.axisy)*re;p.axisy=(ne*p.axisy-oe*p.axisx)*re,p.axisx=le}}}if(r.type==0||r.type===2)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 ie=r.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ce=se,te=oe;oe=oe.next,ce.x=p.posx+(p.axisy*te.x-p.axisx*te.y),ce.y=p.posy+(te.x*p.axisx+te.y*p.axisy),se=se.next}let ne=ie.edges.head,re=ie.gverts.next,le=re;for(re=re.next;re!=null;){let ce=re,te=ne.elt;ne=ne.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=le.y*te.gnormx-le.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,le=ce,re=re.next}let he=ie.gverts.next,pe=ne.elt;ne=ne.next,pe.gnormx=p.axisy*pe.lnormx-p.axisx*pe.lnormy,pe.gnormy=pe.lnormx*p.axisx+pe.lnormy*p.axisy,pe.gprojection=p.posx*pe.gnormx+p.posy*pe.gnormy+pe.lprojection,pe.tp0=le.y*pe.gnormx-le.x*pe.gnormy,pe.tp1=he.y*pe.gnormx-he.x*pe.gnormy}let F=o,D=r,I=d,U=y;var g;if(at(F)&&at(D)){let ie=F.circle||F.capsule,oe=D.circle||D.capsule,se=Dt(F),ne=Dt(D);var O;let re=0,le=0;re=oe.worldCOMx-ie.worldCOMx,le=oe.worldCOMy-ie.worldCOMy;let he=Math.sqrt(re*re+le*le);if(O=he-(se+ne),O<1e100){if(he==0)re=1,le=0;else{let te=1/he;re*=te,le*=te}let pe=se;I.x=ie.worldCOMx+re*pe,I.y=ie.worldCOMy+le*pe;let ce=-ne;U.x=oe.worldCOMx+re*ce,U.y=oe.worldCOMy+le*ce,b.x=re,b.y=le}g=O}else{let ie=!1;if(at(F)&&D.type==1){let oe=F;F=D,D=oe;let se=I;I=U,U=se,ie=!0}if(F.type==1&&at(D)){let oe=F.polygon,se=D.circle||D.capsule,ne=Dt(D),re=-1e100,le=null,he=oe.edges.head;for(;he!=null;){let pe=he.elt,ce=pe.gnormx*se.worldCOMx+pe.gnormy*se.worldCOMy-pe.gprojection-ne;if(ce>1e100){re=ce;break}ce>0?ce>re&&(re=ce,le=pe):re<0&&ce>re&&(re=ce,le=pe),he=he.next}if(re<1e100){let pe=le.gp0,ce=le.gp1,te=se.worldCOMy*le.gnormx-se.worldCOMx*le.gnormy;if(te<=pe.y*le.gnormx-pe.x*le.gnormy){let ue=0,xe=0;ue=se.worldCOMx-pe.x,xe=se.worldCOMy-pe.y;let _e=Math.sqrt(ue*ue+xe*xe);if(re=_e-ne,re<1e100){if(_e==0)ue=1,xe=0;else{let Ve=1/_e;ue*=Ve,xe*=Ve}let ve=0;I.x=pe.x+ue*ve,I.y=pe.y+xe*ve;let Se=-ne;U.x=se.worldCOMx+ue*Se,U.y=se.worldCOMy+xe*Se,b.x=ue,b.y=xe}}else if(te>=ce.y*le.gnormx-ce.x*le.gnormy){let ue=0,xe=0;ue=se.worldCOMx-ce.x,xe=se.worldCOMy-ce.y;let _e=Math.sqrt(ue*ue+xe*xe);if(re=_e-ne,re<1e100){if(_e==0)ue=1,xe=0;else{let Ve=1/_e;ue*=Ve,xe*=Ve}let ve=0;I.x=ce.x+ue*ve,I.y=ce.y+xe*ve;let Se=-ne;U.x=se.worldCOMx+ue*Se,U.y=se.worldCOMy+xe*Se,b.x=ue,b.y=xe}}else{let ue=-ne;U.x=se.worldCOMx+le.gnormx*ue,U.y=se.worldCOMy+le.gnormy*ue;let xe=-re;I.x=U.x+le.gnormx*xe,I.y=U.y+le.gnormy*xe,b.x=le.gnormx,b.y=le.gnormy}}ie&&(b.x=-b.x,b.y=-b.y),g=re}else{let oe=F.polygon,se=D.polygon,ne=-1e100,re=null,le=null,he=0,pe=oe.edges.head;for(;pe!=null;){let ce=pe.elt,te=1e100,ue=se.gverts.next;for(;ue!=null;){let xe=ue,_e=ce.gnormx*xe.x+ce.gnormy*xe.y;_e<te&&(te=_e),ue=ue.next}if(te-=ce.gprojection,te>1e100){ne=te;break}te>0?te>ne&&(ne=te,re=ce,he=1):ne<0&&te>ne&&(ne=te,re=ce,he=1),pe=pe.next}if(ne<1e100){let ce=se.edges.head;for(;ce!=null;){let te=ce.elt,ue=1e100,xe=oe.gverts.next;for(;xe!=null;){let _e=xe,ve=te.gnormx*_e.x+te.gnormy*_e.y;ve<ue&&(ue=ve),xe=xe.next}if(ue-=te.gprojection,ue>1e100){ne=ue;break}ue>0?ue>ne&&(ne=ue,le=te,he=2):ne<0&&ue>ne&&(ne=ue,le=te,he=2),ce=ce.next}if(ne<1e100){var E,M,N;if(he==1)E=oe,M=se,N=re;else{E=se,M=oe,N=le;let _e=I;I=U,U=_e,ie=!ie}let te=null,ue=1e100,xe=M.edges.head;for(;xe!=null;){let _e=xe.elt,ve=N.gnormx*_e.gnormx+N.gnormy*_e.gnormy;ve<ue&&(ue=ve,te=_e),xe=xe.next}if(ie?(b.x=-N.gnormx,b.y=-N.gnormy):(b.x=N.gnormx,b.y=N.gnormy),ne>=0){let _e=N.gp0,ve=N.gp1,Se=te.gp0,Ve=te.gp1,Ke=0,Xe=0,He=0,Re=0;Ke=ve.x-_e.x,Xe=ve.y-_e.y,He=Ve.x-Se.x,Re=Ve.y-Se.y;let bt=1/(Ke*Ke+Xe*Xe),vt=1/(He*He+Re*Re),pt=-(Ke*(_e.x-Se.x)+Xe*(_e.y-Se.y))*bt,ct=-(Ke*(_e.x-Ve.x)+Xe*(_e.y-Ve.y))*bt,rt=-(He*(Se.x-_e.x)+Re*(Se.y-_e.y))*vt,Ye=-(He*(Se.x-ve.x)+Re*(Se.y-ve.y))*vt;pt<0?pt=0:pt>1&&(pt=1),ct<0?ct=0:ct>1&&(ct=1),rt<0?rt=0:rt>1&&(rt=1),Ye<0?Ye=0:Ye>1&&(Ye=1);let ft=0,jt=0,Gt=pt;ft=_e.x+Ke*Gt,jt=_e.y+Xe*Gt;let kt=0,Et=0,zn=ct;kt=_e.x+Ke*zn,Et=_e.y+Xe*zn;let Yt=0,xn=0,on=rt;Yt=Se.x+He*on,xn=Se.y+Re*on;let dn=0,Xt=0,Pn=Ye;dn=Se.x+He*Pn,Xt=Se.y+Re*Pn;let Ht=0,_n=0;Ht=ft-Se.x,_n=jt-Se.y;let qt=Ht*Ht+_n*_n,Qt=0,rn=0;Qt=kt-Ve.x,rn=Et-Ve.y;let li=Qt*Qt+rn*rn,Gn=0,Vn=0;Gn=Yt-_e.x,Vn=xn-_e.y;let In=Gn*Gn+Vn*Vn,Si=0,Ai=0;Si=dn-ve.x,Ai=Xt-ve.y;let Vi=Si*Si+Ai*Ai,xs=0,Al=0,ol=null;qt<li?(xs=ft,Al=jt,ol=Se):(xs=kt,Al=Et,ol=Ve,qt=li);let Vl=0,Il=0,rl=null;if(In<Vi?(Vl=Yt,Il=xn,rl=_e):(Vl=dn,Il=Xt,rl=ve,In=Vi),qt<In?(I.x=xs,I.y=Al,U.x=ol.x,U.y=ol.y,ne=Math.sqrt(qt)):(U.x=Vl,U.y=Il,I.x=rl.x,I.y=rl.y,ne=Math.sqrt(In)),ne!=0){b.x=U.x-I.x,b.y=U.y-I.y;let Wl=1/ne;b.x*=Wl,b.y*=Wl,ie&&(b.x=-b.x,b.y=-b.y)}g=ne}else{let _e=0,ve=0;_e=te.gp0.x,ve=te.gp0.y;let Se=0,Ve=0;Se=te.gp1.x,Ve=te.gp1.y;let Ke=0,Xe=0;Ke=Se-_e,Xe=Ve-ve;let He=N.gnormy*_e-N.gnormx*ve,Re=N.gnormy*Se-N.gnormx*Ve,bt=1/(Re-He),vt=(-N.tp1-He)*bt;if(vt>l.Config.epsilon){let Ye=vt;_e+=Ke*Ye,ve+=Xe*Ye}let pt=(-N.tp0-Re)*bt;if(pt<-l.Config.epsilon){let Ye=pt;Se+=Ke*Ye,Ve+=Xe*Ye}let ct=_e*N.gnormx+ve*N.gnormy-N.gprojection,rt=Se*N.gnormx+Ve*N.gnormy-N.gprojection;if(ct<rt){U.x=_e,U.y=ve;let Ye=-ct;I.x=U.x+N.gnormx*Ye,I.y=U.y+N.gnormy*Ye,g=ct}else{U.x=Se,U.y=Ve;let Ye=-rt;I.x=U.x+N.gnormx*Ye,I.y=U.y+N.gnormy*Ye,g=rt}}}else g=1e100}else g=1e100}}let Q=g+s,W=c*b.x+h*b.y;if(Q<l.Config.distanceThresholdCCD){if(i)break;let ie=0,oe=0;ie=d.x-a.posx,oe=d.y-a.posy;let se=0,ne=0;se=y.x-p.posx,ne=y.y-p.posy;let re=W-a.sweep_angvel*(b.y*ie-b.x*oe)+p.sweep_angvel*(b.y*se-b.x*ne);if(re>0&&(e.slipped=!0),re<=0||Q<l.Config.distanceThresholdCCD*.5)break}f=-1;break}if(++P>=40){j>s&&(e.failed=!0);break}}e.toi=f}static staticSweep(e,t,n,s){let i=me(),l=e.s1,o=e.s2,r=l.body,a=o.body,p=0,c=0;p=-r.velx,c=-r.vely;let h=r.sweep_angvel;h<0&&(h=-h);let u=l.sweepCoef*h,x=e.c1,m=e.c2,d=e.axis,y=n,b=0;for(;;){let M=y*t,N=M-r.sweepTime;if(N!=0){r.sweepTime=M;let j=N;if(r.posx+=r.velx*j,r.posy+=r.vely*j,r.angvel!=0){let V=r.sweep_angvel*N;if(r.rot+=V,V*V>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let K=V*V,$=1-.5*K,Y=1-K*K/8,X=($*r.axisx+V*r.axisy)*Y;r.axisy=($*r.axisy-V*r.axisx)*Y,r.axisx=X}}}if(l.type==0||l.type===2)l.worldCOMx=r.posx+(r.axisy*l.localCOMx-r.axisx*l.localCOMy),l.worldCOMy=r.posy+(l.localCOMx*r.axisx+l.localCOMy*r.axisy);else{let j=l.polygon,V=j.lverts.next,K=j.gverts.next;for(;K!=null;){let F=K,D=V;V=V.next,F.x=r.posx+(r.axisy*D.x-r.axisx*D.y),F.y=r.posy+(D.x*r.axisx+D.y*r.axisy),K=K.next}let $=j.edges.head,Y=j.gverts.next,X=Y;for(Y=Y.next;Y!=null;){let F=Y,D=$.elt;$=$.next,D.gnormx=r.axisy*D.lnormx-r.axisx*D.lnormy,D.gnormy=D.lnormx*r.axisx+D.lnormy*r.axisy,D.gprojection=r.posx*D.gnormx+r.posy*D.gnormy+D.lprojection,D.tp0=X.y*D.gnormx-X.x*D.gnormy,D.tp1=F.y*D.gnormx-F.x*D.gnormy,X=F,Y=Y.next}let ee=j.gverts.next,J=$.elt;$=$.next,J.gnormx=r.axisy*J.lnormx-r.axisx*J.lnormy,J.gnormy=J.lnormx*r.axisx+J.lnormy*r.axisy,J.gprojection=r.posx*J.gnormx+r.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,A=o,S=x,L=m;var f;if(at(Z)&&at(A)){let j=Z.circle||Z.capsule,V=A.circle||A.capsule,K=Dt(Z),$=Dt(A);var P;let Y=0,X=0;Y=V.worldCOMx-j.worldCOMx,X=V.worldCOMy-j.worldCOMy;let ee=Math.sqrt(Y*Y+X*X);if(P=ee-(j.radius+V.radius),P<1e100){if(ee==0)Y=1,X=0;else{let D=1/ee;Y*=D,X*=D}let J=j.radius;S.x=j.worldCOMx+Y*J,S.y=j.worldCOMy+X*J;let F=-V.radius;L.x=V.worldCOMx+Y*F,L.y=V.worldCOMy+X*F,d.x=Y,d.y=X}f=P}else{let j=!1;if(at(Z)&&A.type==1){let V=Z;Z=A,A=V;let K=S;S=L,L=K,j=!0}if(Z.type==1&&at(A)){let V=Z.polygon,K=A.circle||A.capsule,$=Dt(A),Y=-1e100,X=null,ee=V.edges.head;for(;ee!=null;){let J=ee.elt,F=J.gnormx*K.worldCOMx+J.gnormy*K.worldCOMy-J.gprojection-$;if(F>1e100){Y=F;break}F>0?F>Y&&(Y=F,X=J):Y<0&&F>Y&&(Y=F,X=J),ee=ee.next}if(Y<1e100){let J=X.gp0,F=X.gp1,D=K.worldCOMy*X.gnormx-K.worldCOMx*X.gnormy;if(D<=J.y*X.gnormx-J.x*X.gnormy){let I=0,U=0;I=K.worldCOMx-J.x,U=K.worldCOMy-J.y;let Q=Math.sqrt(I*I+U*U);if(Y=Q-$,Y<1e100){if(Q==0)I=1,U=0;else{let oe=1/Q;I*=oe,U*=oe}let W=0;S.x=J.x+I*W,S.y=J.y+U*W;let ie=-$;L.x=K.worldCOMx+I*ie,L.y=K.worldCOMy+U*ie,d.x=I,d.y=U}}else if(D>=F.y*X.gnormx-F.x*X.gnormy){let I=0,U=0;I=K.worldCOMx-F.x,U=K.worldCOMy-F.y;let Q=Math.sqrt(I*I+U*U);if(Y=Q-$,Y<1e100){if(Q==0)I=1,U=0;else{let oe=1/Q;I*=oe,U*=oe}let W=0;S.x=F.x+I*W,S.y=F.y+U*W;let ie=-$;L.x=K.worldCOMx+I*ie,L.y=K.worldCOMy+U*ie,d.x=I,d.y=U}}else{let I=-$;L.x=K.worldCOMx+X.gnormx*I,L.y=K.worldCOMy+X.gnormy*I;let U=-Y;S.x=L.x+X.gnormx*U,S.y=L.y+X.gnormy*U,d.x=X.gnormx,d.y=X.gnormy}}j&&(d.x=-d.x,d.y=-d.y),f=Y}else{let V=Z.polygon,K=A.polygon,$=-1e100,Y=null,X=null,ee=0,J=V.edges.head;for(;J!=null;){let F=J.elt,D=1e100,I=K.gverts.next;for(;I!=null;){let U=I,Q=F.gnormx*U.x+F.gnormy*U.y;Q<D&&(D=Q),I=I.next}if(D-=F.gprojection,D>1e100){$=D;break}D>0?D>$&&($=D,Y=F,ee=1):$<0&&D>$&&($=D,Y=F,ee=1),J=J.next}if($<1e100){let F=K.edges.head;for(;F!=null;){let D=F.elt,I=1e100,U=V.gverts.next;for(;U!=null;){let Q=U,W=D.gnormx*Q.x+D.gnormy*Q.y;W<I&&(I=W),U=U.next}if(I-=D.gprojection,I>1e100){$=I;break}I>0?I>$&&($=I,X=D,ee=2):$<0&&I>$&&($=I,X=D,ee=2),F=F.next}if($<1e100){var k,_,z;if(ee==1)k=V,_=K,z=Y;else{k=K,_=V,z=X;let Q=S;S=L,L=Q,j=!j}let D=null,I=1e100,U=_.edges.head;for(;U!=null;){let Q=U.elt,W=z.gnormx*Q.gnormx+z.gnormy*Q.gnormy;W<I&&(I=W,D=Q),U=U.next}if(j?(d.x=-z.gnormx,d.y=-z.gnormy):(d.x=z.gnormx,d.y=z.gnormy),$>=0){let Q=z.gp0,W=z.gp1,ie=D.gp0,oe=D.gp1,se=0,ne=0,re=0,le=0;se=W.x-Q.x,ne=W.y-Q.y,re=oe.x-ie.x,le=oe.y-ie.y;let he=1/(se*se+ne*ne),pe=1/(re*re+le*le),ce=-(se*(Q.x-ie.x)+ne*(Q.y-ie.y))*he,te=-(se*(Q.x-oe.x)+ne*(Q.y-oe.y))*he,ue=-(re*(ie.x-Q.x)+le*(ie.y-Q.y))*pe,xe=-(re*(ie.x-W.x)+le*(ie.y-W.y))*pe;ce<0?ce=0:ce>1&&(ce=1),te<0?te=0:te>1&&(te=1),ue<0?ue=0:ue>1&&(ue=1),xe<0?xe=0:xe>1&&(xe=1);let _e=0,ve=0,Se=ce;_e=Q.x+se*Se,ve=Q.y+ne*Se;let Ve=0,Ke=0,Xe=te;Ve=Q.x+se*Xe,Ke=Q.y+ne*Xe;let He=0,Re=0,bt=ue;He=ie.x+re*bt,Re=ie.y+le*bt;let vt=0,pt=0,ct=xe;vt=ie.x+re*ct,pt=ie.y+le*ct;let rt=0,Ye=0;rt=_e-ie.x,Ye=ve-ie.y;let ft=rt*rt+Ye*Ye,jt=0,Gt=0;jt=Ve-oe.x,Gt=Ke-oe.y;let kt=jt*jt+Gt*Gt,Et=0,zn=0;Et=He-Q.x,zn=Re-Q.y;let Yt=Et*Et+zn*zn,xn=0,on=0;xn=vt-W.x,on=pt-W.y;let dn=xn*xn+on*on,Xt=0,Pn=0,Ht=null;ft<kt?(Xt=_e,Pn=ve,Ht=ie):(Xt=Ve,Pn=Ke,Ht=oe,ft=kt);let _n=0,qt=0,Qt=null;if(Yt<dn?(_n=He,qt=Re,Qt=Q):(_n=vt,qt=pt,Qt=W,Yt=dn),ft<Yt?(S.x=Xt,S.y=Pn,L.x=Ht.x,L.y=Ht.y,$=Math.sqrt(ft)):(L.x=_n,L.y=qt,S.x=Qt.x,S.y=Qt.y,$=Math.sqrt(Yt)),$!=0){d.x=L.x-S.x,d.y=L.y-S.y;let rn=1/$;d.x*=rn,d.y*=rn,j&&(d.x=-d.x,d.y=-d.y)}f=$}else{let Q=0,W=0;Q=D.gp0.x,W=D.gp0.y;let ie=0,oe=0;ie=D.gp1.x,oe=D.gp1.y;let se=0,ne=0;se=ie-Q,ne=oe-W;let re=z.gnormy*Q-z.gnormx*W,le=z.gnormy*ie-z.gnormx*oe,he=1/(le-re),pe=(-z.tp1-re)*he;if(pe>i.Config.epsilon){let xe=pe;Q+=se*xe,W+=ne*xe}let ce=(-z.tp0-le)*he;if(ce<-i.Config.epsilon){let xe=ce;ie+=se*xe,oe+=ne*xe}let te=Q*z.gnormx+W*z.gnormy-z.gprojection,ue=ie*z.gnormx+oe*z.gnormy-z.gprojection;if(te<ue){L.x=Q,L.y=W;let xe=-te;S.x=L.x+z.gnormx*xe,S.y=L.y+z.gnormy*xe,f=te}else{L.x=ie,L.y=oe;let xe=-ue;S.x=L.x+z.gnormx*xe,S.y=L.y+z.gnormy*xe,f=ue}}}else f=1e100}else f=1e100}}let T=f+s,G=p*d.x+c*d.y;if(T<i.Config.distanceThresholdCCD){let j=0,V=0;j=x.x-r.posx,V=x.y-r.posy;let K=G-r.sweep_angvel*(d.y*j-d.x*V);if(K>0&&(e.slipped=!0),K<=0||T<i.Config.distanceThresholdCCD*.5)break}let q=(u-G)*t;if(q<=0){y=-1;break}let R=T/q;if(R<1e-6&&(R=1e-6),y+=R,y>=1){y=1;let j=y*t,V=j-r.sweepTime;if(V!=0){r.sweepTime=j;let F=V;if(r.posx+=r.velx*F,r.posy+=r.vely*F,r.angvel!=0){let D=r.sweep_angvel*V;if(r.rot+=D,D*D>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let I=D*D,U=1-.5*I,Q=1-I*I/8,W=(U*r.axisx+D*r.axisy)*Q;r.axisy=(U*r.axisy-D*r.axisx)*Q,r.axisx=W}}}if(l.type==0||l.type===2)l.worldCOMx=r.posx+(r.axisy*l.localCOMx-r.axisx*l.localCOMy),l.worldCOMy=r.posy+(l.localCOMx*r.axisx+l.localCOMy*r.axisy);else{let F=l.polygon,D=F.lverts.next,I=F.gverts.next;for(;I!=null;){let se=I,ne=D;D=D.next,se.x=r.posx+(r.axisy*ne.x-r.axisx*ne.y),se.y=r.posy+(ne.x*r.axisx+ne.y*r.axisy),I=I.next}let U=F.edges.head,Q=F.gverts.next,W=Q;for(Q=Q.next;Q!=null;){let se=Q,ne=U.elt;U=U.next,ne.gnormx=r.axisy*ne.lnormx-r.axisx*ne.lnormy,ne.gnormy=ne.lnormx*r.axisx+ne.lnormy*r.axisy,ne.gprojection=r.posx*ne.gnormx+r.posy*ne.gnormy+ne.lprojection,ne.tp0=W.y*ne.gnormx-W.x*ne.gnormy,ne.tp1=se.y*ne.gnormx-se.x*ne.gnormy,W=se,Q=Q.next}let ie=F.gverts.next,oe=U.elt;U=U.next,oe.gnormx=r.axisy*oe.lnormx-r.axisx*oe.lnormy,oe.gnormy=oe.lnormx*r.axisx+oe.lnormy*r.axisy,oe.gprojection=r.posx*oe.gnormx+r.posy*oe.gnormy+oe.lprojection,oe.tp0=W.y*oe.gnormx-W.x*oe.gnormy,oe.tp1=ie.y*oe.gnormx-ie.x*oe.gnormy}let K=l,$=o,Y=x,X=m;var C;if(at(K)&&at($)){let F=K.circle||K.capsule,D=$.circle||$.capsule,I=Dt(K),U=Dt($);var w;let Q=0,W=0;Q=D.worldCOMx-F.worldCOMx,W=D.worldCOMy-F.worldCOMy;let ie=Math.sqrt(Q*Q+W*W);if(w=ie-(I+U),w<1e100){if(ie==0)Q=1,W=0;else{let ne=1/ie;Q*=ne,W*=ne}let oe=I;Y.x=F.worldCOMx+Q*oe,Y.y=F.worldCOMy+W*oe;let se=-U;X.x=D.worldCOMx+Q*se,X.y=D.worldCOMy+W*se,d.x=Q,d.y=W}C=w}else{let F=!1;if(at(K)&&$.type==1){let D=K;K=$,$=D;let I=Y;Y=X,X=I,F=!0}if(K.type==1&&at($)){let D=K.polygon,I=$.circle||$.capsule,U=Dt($),Q=-1e100,W=null,ie=D.edges.head;for(;ie!=null;){let oe=ie.elt,se=oe.gnormx*I.worldCOMx+oe.gnormy*I.worldCOMy-oe.gprojection-U;if(se>1e100){Q=se;break}se>0?se>Q&&(Q=se,W=oe):Q<0&&se>Q&&(Q=se,W=oe),ie=ie.next}if(Q<1e100){let oe=W.gp0,se=W.gp1,ne=I.worldCOMy*W.gnormx-I.worldCOMx*W.gnormy;if(ne<=oe.y*W.gnormx-oe.x*W.gnormy){let re=0,le=0;re=I.worldCOMx-oe.x,le=I.worldCOMy-oe.y;let he=Math.sqrt(re*re+le*le);if(Q=he-U,Q<1e100){if(he==0)re=1,le=0;else{let te=1/he;re*=te,le*=te}let pe=0;Y.x=oe.x+re*pe,Y.y=oe.y+le*pe;let ce=-U;X.x=I.worldCOMx+re*ce,X.y=I.worldCOMy+le*ce,d.x=re,d.y=le}}else if(ne>=se.y*W.gnormx-se.x*W.gnormy){let re=0,le=0;re=I.worldCOMx-se.x,le=I.worldCOMy-se.y;let he=Math.sqrt(re*re+le*le);if(Q=he-U,Q<1e100){if(he==0)re=1,le=0;else{let te=1/he;re*=te,le*=te}let pe=0;Y.x=se.x+re*pe,Y.y=se.y+le*pe;let ce=-U;X.x=I.worldCOMx+re*ce,X.y=I.worldCOMy+le*ce,d.x=re,d.y=le}}else{let re=-U;X.x=I.worldCOMx+W.gnormx*re,X.y=I.worldCOMy+W.gnormy*re;let le=-Q;Y.x=X.x+W.gnormx*le,Y.y=X.y+W.gnormy*le,d.x=W.gnormx,d.y=W.gnormy}}F&&(d.x=-d.x,d.y=-d.y),C=Q}else{let D=K.polygon,I=$.polygon,U=-1e100,Q=null,W=null,ie=0,oe=D.edges.head;for(;oe!=null;){let se=oe.elt,ne=1e100,re=I.gverts.next;for(;re!=null;){let le=re,he=se.gnormx*le.x+se.gnormy*le.y;he<ne&&(ne=he),re=re.next}if(ne-=se.gprojection,ne>1e100){U=ne;break}ne>0?ne>U&&(U=ne,Q=se,ie=1):U<0&&ne>U&&(U=ne,Q=se,ie=1),oe=oe.next}if(U<1e100){let se=I.edges.head;for(;se!=null;){let ne=se.elt,re=1e100,le=D.gverts.next;for(;le!=null;){let he=le,pe=ne.gnormx*he.x+ne.gnormy*he.y;pe<re&&(re=pe),le=le.next}if(re-=ne.gprojection,re>1e100){U=re;break}re>0?re>U&&(U=re,W=ne,ie=2):U<0&&re>U&&(U=re,W=ne,ie=2),se=se.next}if(U<1e100){var g,O,E;if(ie==1)g=D,O=I,E=Q;else{g=I,O=D,E=W;let he=Y;Y=X,X=he,F=!F}let ne=null,re=1e100,le=O.edges.head;for(;le!=null;){let he=le.elt,pe=E.gnormx*he.gnormx+E.gnormy*he.gnormy;pe<re&&(re=pe,ne=he),le=le.next}if(F?(d.x=-E.gnormx,d.y=-E.gnormy):(d.x=E.gnormx,d.y=E.gnormy),U>=0){let he=E.gp0,pe=E.gp1,ce=ne.gp0,te=ne.gp1,ue=0,xe=0,_e=0,ve=0;ue=pe.x-he.x,xe=pe.y-he.y,_e=te.x-ce.x,ve=te.y-ce.y;let Se=1/(ue*ue+xe*xe),Ve=1/(_e*_e+ve*ve),Ke=-(ue*(he.x-ce.x)+xe*(he.y-ce.y))*Se,Xe=-(ue*(he.x-te.x)+xe*(he.y-te.y))*Se,He=-(_e*(ce.x-he.x)+ve*(ce.y-he.y))*Ve,Re=-(_e*(ce.x-pe.x)+ve*(ce.y-pe.y))*Ve;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 bt=0,vt=0,pt=Ke;bt=he.x+ue*pt,vt=he.y+xe*pt;let ct=0,rt=0,Ye=Xe;ct=he.x+ue*Ye,rt=he.y+xe*Ye;let ft=0,jt=0,Gt=He;ft=ce.x+_e*Gt,jt=ce.y+ve*Gt;let kt=0,Et=0,zn=Re;kt=ce.x+_e*zn,Et=ce.y+ve*zn;let Yt=0,xn=0;Yt=bt-ce.x,xn=vt-ce.y;let on=Yt*Yt+xn*xn,dn=0,Xt=0;dn=ct-te.x,Xt=rt-te.y;let Pn=dn*dn+Xt*Xt,Ht=0,_n=0;Ht=ft-he.x,_n=jt-he.y;let qt=Ht*Ht+_n*_n,Qt=0,rn=0;Qt=kt-pe.x,rn=Et-pe.y;let li=Qt*Qt+rn*rn,Gn=0,Vn=0,In=null;on<Pn?(Gn=bt,Vn=vt,In=ce):(Gn=ct,Vn=rt,In=te,on=Pn);let Si=0,Ai=0,Vi=null;if(qt<li?(Si=ft,Ai=jt,Vi=he):(Si=kt,Ai=Et,Vi=pe,qt=li),on<qt?(Y.x=Gn,Y.y=Vn,X.x=In.x,X.y=In.y,U=Math.sqrt(on)):(X.x=Si,X.y=Ai,Y.x=Vi.x,Y.y=Vi.y,U=Math.sqrt(qt)),U!=0){d.x=X.x-Y.x,d.y=X.y-Y.y;let xs=1/U;d.x*=xs,d.y*=xs,F&&(d.x=-d.x,d.y=-d.y)}C=U}else{let he=0,pe=0;he=ne.gp0.x,pe=ne.gp0.y;let ce=0,te=0;ce=ne.gp1.x,te=ne.gp1.y;let ue=0,xe=0;ue=ce-he,xe=te-pe;let _e=E.gnormy*he-E.gnormx*pe,ve=E.gnormy*ce-E.gnormx*te,Se=1/(ve-_e),Ve=(-E.tp1-_e)*Se;if(Ve>i.Config.epsilon){let Re=Ve;he+=ue*Re,pe+=xe*Re}let Ke=(-E.tp0-ve)*Se;if(Ke<-i.Config.epsilon){let Re=Ke;ce+=ue*Re,te+=xe*Re}let Xe=he*E.gnormx+pe*E.gnormy-E.gprojection,He=ce*E.gnormx+te*E.gnormy-E.gprojection;if(Xe<He){X.x=he,X.y=pe;let Re=-Xe;Y.x=X.x+E.gnormx*Re,Y.y=X.y+E.gnormy*Re,C=Xe}else{X.x=ce,X.y=te;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 F=0,D=0;F=x.x-r.posx,D=x.y-r.posy;let I=J-r.sweep_angvel*(d.y*F-d.x*D);if(I>0&&(e.slipped=!0),I<=0||ee<i.Config.distanceThresholdCCD*.5)break}y=-1;break}if(++b>=40){T>s&&(e.failed=!0);break}}e.toi=y}static distanceBody(e,t,n,s){let i=me(),l=ae.get(0,0),o=ae.get(0,0),r=ae.get(0,0),a=1e100,p=e.shapes.head;for(;p!=null;){let f=p.elt,P=t.shapes.head;for(;P!=null;){let k=P.elt,_=f,z=k,C=l,w=o,g=a;g==null&&(g=1e100);var c;if(at(_)&&at(z)){let O=_.circle||_.capsule,E=z.circle||z.capsule,M=Dt(_),N=Dt(z);var h;let Z=0,A=0;Z=E.worldCOMx-O.worldCOMx,A=E.worldCOMy-O.worldCOMy;let S=Math.sqrt(Z*Z+A*A);if(h=S-(M+N),h<g){if(S==0)Z=1,A=0;else{let G=1/S;Z*=G,A*=G}let L=M;C.x=O.worldCOMx+Z*L,C.y=O.worldCOMy+A*L;let T=-N;w.x=E.worldCOMx+Z*T,w.y=E.worldCOMy+A*T,r.x=Z,r.y=A}c=h}else{let O=!1;if(at(_)&&z.type==1){let E=_;_=z,z=E;let M=C;C=w,w=M,O=!0}if(_.type==1&&at(z)){let E=_.polygon,M=z.circle||z.capsule,N=Dt(z),Z=-1e100,A=null,S=E.edges.head;for(;S!=null;){let L=S.elt,T=L.gnormx*M.worldCOMx+L.gnormy*M.worldCOMy-L.gprojection-N;if(T>g){Z=T;break}T>0?T>Z&&(Z=T,A=L):Z<0&&T>Z&&(Z=T,A=L),S=S.next}if(Z<g){let L=A.gp0,T=A.gp1,G=M.worldCOMy*A.gnormx-M.worldCOMx*A.gnormy;if(G<=L.y*A.gnormx-L.x*A.gnormy){let q=0,R=0;q=M.worldCOMx-L.x,R=M.worldCOMy-L.y;let j=Math.sqrt(q*q+R*R);if(Z=j-N,Z<g){if(j==0)q=1,R=0;else{let $=1/j;q*=$,R*=$}let V=0;C.x=L.x+q*V,C.y=L.y+R*V;let K=-N;w.x=M.worldCOMx+q*K,w.y=M.worldCOMy+R*K,r.x=q,r.y=R}}else if(G>=T.y*A.gnormx-T.x*A.gnormy){let q=0,R=0;q=M.worldCOMx-T.x,R=M.worldCOMy-T.y;let j=Math.sqrt(q*q+R*R);if(Z=j-N,Z<g){if(j==0)q=1,R=0;else{let $=1/j;q*=$,R*=$}let V=0;C.x=T.x+q*V,C.y=T.y+R*V;let K=-N;w.x=M.worldCOMx+q*K,w.y=M.worldCOMy+R*K,r.x=q,r.y=R}}else{let q=-N;w.x=M.worldCOMx+A.gnormx*q,w.y=M.worldCOMy+A.gnormy*q;let R=-Z;C.x=w.x+A.gnormx*R,C.y=w.y+A.gnormy*R,r.x=A.gnormx,r.y=A.gnormy}}O&&(r.x=-r.x,r.y=-r.y),c=Z}else{let E=_.polygon,M=z.polygon,N=-1e100,Z=null,A=null,S=0,L=E.edges.head;for(;L!=null;){let T=L.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>g){N=G;break}G>0?G>N&&(N=G,Z=T,S=1):N<0&&G>N&&(N=G,Z=T,S=1),L=L.next}if(N<g){let T=M.edges.head;for(;T!=null;){let G=T.elt,q=1e100,R=E.gverts.next;for(;R!=null;){let j=R,V=G.gnormx*j.x+G.gnormy*j.y;V<q&&(q=V),R=R.next}if(q-=G.gprojection,q>g){N=q;break}q>0?q>N&&(N=q,A=G,S=2):N<0&&q>N&&(N=q,A=G,S=2),T=T.next}if(N<g){var u,x,m;if(S==1)u=E,x=M,m=Z;else{u=M,x=E,m=A;let j=C;C=w,w=j,O=!O}let G=null,q=1e100,R=x.edges.head;for(;R!=null;){let j=R.elt,V=m.gnormx*j.gnormx+m.gnormy*j.gnormy;V<q&&(q=V,G=j),R=R.next}if(O?(r.x=-m.gnormx,r.y=-m.gnormy):(r.x=m.gnormx,r.y=m.gnormy),N>=0){let j=m.gp0,V=m.gp1,K=G.gp0,$=G.gp1,Y=0,X=0,ee=0,J=0;Y=V.x-j.x,X=V.y-j.y,ee=$.x-K.x,J=$.y-K.y;let F=1/(Y*Y+X*X),D=1/(ee*ee+J*J),I=-(Y*(j.x-K.x)+X*(j.y-K.y))*F,U=-(Y*(j.x-$.x)+X*(j.y-$.y))*F,Q=-(ee*(K.x-j.x)+J*(K.y-j.y))*D,W=-(ee*(K.x-V.x)+J*(K.y-V.y))*D;I<0?I=0:I>1&&(I=1),U<0?U=0:U>1&&(U=1),Q<0?Q=0:Q>1&&(Q=1),W<0?W=0:W>1&&(W=1);let ie=0,oe=0,se=I;ie=j.x+Y*se,oe=j.y+X*se;let ne=0,re=0,le=U;ne=j.x+Y*le,re=j.y+X*le;let he=0,pe=0,ce=Q;he=K.x+ee*ce,pe=K.y+J*ce;let te=0,ue=0,xe=W;te=K.x+ee*xe,ue=K.y+J*xe;let _e=0,ve=0;_e=ie-K.x,ve=oe-K.y;let Se=_e*_e+ve*ve,Ve=0,Ke=0;Ve=ne-$.x,Ke=re-$.y;let Xe=Ve*Ve+Ke*Ke,He=0,Re=0;He=he-j.x,Re=pe-j.y;let bt=He*He+Re*Re,vt=0,pt=0;vt=te-V.x,pt=ue-V.y;let ct=vt*vt+pt*pt,rt=0,Ye=0,ft=null;Se<Xe?(rt=ie,Ye=oe,ft=K):(rt=ne,Ye=re,ft=$,Se=Xe);let jt=0,Gt=0,kt=null;if(bt<ct?(jt=he,Gt=pe,kt=j):(jt=te,Gt=ue,kt=V,bt=ct),Se<bt?(C.x=rt,C.y=Ye,w.x=ft.x,w.y=ft.y,N=Math.sqrt(Se)):(w.x=jt,w.y=Gt,C.x=kt.x,C.y=kt.y,N=Math.sqrt(bt)),N!=0){r.x=w.x-C.x,r.y=w.y-C.y;let Et=1/N;r.x*=Et,r.y*=Et,O&&(r.x=-r.x,r.y=-r.y)}c=N}else{let j=0,V=0;j=G.gp0.x,V=G.gp0.y;let K=0,$=0;K=G.gp1.x,$=G.gp1.y;let Y=0,X=0;Y=K-j,X=$-V;let ee=m.gnormy*j-m.gnormx*V,J=m.gnormy*K-m.gnormx*$,F=1/(J-ee),D=(-m.tp1-ee)*F;if(D>i.Config.epsilon){let W=D;j+=Y*W,V+=X*W}let I=(-m.tp0-J)*F;if(I<-i.Config.epsilon){let W=I;K+=Y*W,$+=X*W}let U=j*m.gnormx+V*m.gnormy-m.gprojection,Q=K*m.gnormx+$*m.gnormy-m.gprojection;if(U<Q){w.x=j,w.y=V;let W=-U;C.x=w.x+m.gnormx*W,C.y=w.y+m.gnormy*W,c=U}else{w.x=K,w.y=$;let W=-Q;C.x=w.x+m.gnormx*W,C.y=w.y+m.gnormy*W,c=Q}}}else c=g}else c=g}}c<a&&(a=c,n.x=l.x,n.y=l.y,s.x=o.x,s.y=o.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=ae.zpp_pool,ae.zpp_pool=d;let y=o;y.outer!=null&&(y.outer.zpp_inner=null,y.outer=null),y._isimmutable=null,y._validate=null,y._invalidate=null,y.next=ae.zpp_pool,ae.zpp_pool=y;let b=r;return b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b._isimmutable=null,b._validate=null,b._invalidate=null,b.next=ae.zpp_pool,ae.zpp_pool=b,a}static distance(e,t,n,s,i,l){let o=me();if(l==null&&(l=1e100),at(e)&&at(t)){let r=e.circle||e.capsule,a=t.circle||t.capsule,p=Dt(e),c=Dt(t),h,u=0,x=0;u=a.worldCOMx-r.worldCOMx,x=a.worldCOMy-r.worldCOMy;let m=Math.sqrt(u*u+x*x);if(h=m-(p+c),h<l){if(m==0)u=1,x=0;else{let b=1/m;u*=b,x*=b}let d=p;n.x=r.worldCOMx+u*d,n.y=r.worldCOMy+x*d;let y=-c;s.x=a.worldCOMx+u*y,s.y=a.worldCOMy+x*y,i.x=u,i.y=x}return h}else{let r=!1;if(at(e)&&t.type==1){let a=e;e=t,t=a;let p=n;n=s,s=p,r=!0}if(e.type==1&&at(t)){let a=e.polygon,p=t.circle||t.capsule,c=Dt(t),h=-1e100,u=null,x=a.edges.head;for(;x!=null;){let m=x.elt,d=m.gnormx*p.worldCOMx+m.gnormy*p.worldCOMy-m.gprojection-c;if(d>l){h=d;break}d>0?d>h&&(h=d,u=m):h<0&&d>h&&(h=d,u=m),x=x.next}if(h<l){let m=u.gp0,d=u.gp1,y=p.worldCOMy*u.gnormx-p.worldCOMx*u.gnormy;if(y<=m.y*u.gnormx-m.x*u.gnormy){let b=0,f=0;b=p.worldCOMx-m.x,f=p.worldCOMy-m.y;let P=Math.sqrt(b*b+f*f);if(h=P-c,h<l){if(P==0)b=1,f=0;else{let z=1/P;b*=z,f*=z}let k=0;n.x=m.x+b*k,n.y=m.y+f*k;let _=-c;s.x=p.worldCOMx+b*_,s.y=p.worldCOMy+f*_,i.x=b,i.y=f}}else if(y>=d.y*u.gnormx-d.x*u.gnormy){let b=0,f=0;b=p.worldCOMx-d.x,f=p.worldCOMy-d.y;let P=Math.sqrt(b*b+f*f);if(h=P-c,h<l){if(P==0)b=1,f=0;else{let z=1/P;b*=z,f*=z}let k=0;n.x=d.x+b*k,n.y=d.y+f*k;let _=-c;s.x=p.worldCOMx+b*_,s.y=p.worldCOMy+f*_,i.x=b,i.y=f}}else{let b=-c;s.x=p.worldCOMx+u.gnormx*b,s.y=p.worldCOMy+u.gnormy*b;let f=-h;n.x=s.x+u.gnormx*f,n.y=s.y+u.gnormy*f,i.x=u.gnormx,i.y=u.gnormy}}return r&&(i.x=-i.x,i.y=-i.y),h}else{let a=e.polygon,p=t.polygon,c=-1e100,h=null,u=null,x=0,m=a.edges.head;for(;m!=null;){let d=m.elt,y=1e100,b=p.gverts.next;for(;b!=null;){let f=b,P=d.gnormx*f.x+d.gnormy*f.y;P<y&&(y=P),b=b.next}if(y-=d.gprojection,y>l){c=y;break}y>0?y>c&&(c=y,h=d,x=1):c<0&&y>c&&(c=y,h=d,x=1),m=m.next}if(c<l){let d=p.edges.head;for(;d!=null;){let y=d.elt,b=1e100,f=a.gverts.next;for(;f!=null;){let P=f,k=y.gnormx*P.x+y.gnormy*P.y;k<b&&(b=k),f=f.next}if(b-=y.gprojection,b>l){c=b;break}b>0?b>c&&(c=b,u=y,x=2):c<0&&b>c&&(c=b,u=y,x=2),d=d.next}if(c<l){let y,b,f;if(x==1)y=a,b=p,f=h;else{y=p,b=a,f=u;let z=n;n=s,s=z,r=!r}let P=null,k=1e100,_=b.edges.head;for(;_!=null;){let z=_.elt,C=f.gnormx*z.gnormx+f.gnormy*z.gnormy;C<k&&(k=C,P=z),_=_.next}if(r?(i.x=-f.gnormx,i.y=-f.gnormy):(i.x=f.gnormx,i.y=f.gnormy),c>=0){let z=f.gp0,C=f.gp1,w=P.gp0,g=P.gp1,O=0,E=0,M=0,N=0;O=C.x-z.x,E=C.y-z.y,M=g.x-w.x,N=g.y-w.y;let Z=1/(O*O+E*E),A=1/(M*M+N*N),S=-(O*(z.x-w.x)+E*(z.y-w.y))*Z,L=-(O*(z.x-g.x)+E*(z.y-g.y))*Z,T=-(M*(w.x-z.x)+N*(w.y-z.y))*A,G=-(M*(w.x-C.x)+N*(w.y-C.y))*A;S<0?S=0:S>1&&(S=1),L<0?L=0:L>1&&(L=1),T<0?T=0:T>1&&(T=1),G<0?G=0:G>1&&(G=1);let q=0,R=0,j=S;q=z.x+O*j,R=z.y+E*j;let V=0,K=0,$=L;V=z.x+O*$,K=z.y+E*$;let Y=0,X=0,ee=T;Y=w.x+M*ee,X=w.y+N*ee;let J=0,F=0,D=G;J=w.x+M*D,F=w.y+N*D;let I=0,U=0;I=q-w.x,U=R-w.y;let Q=I*I+U*U,W=0,ie=0;W=V-g.x,ie=K-g.y;let oe=W*W+ie*ie,se=0,ne=0;se=Y-z.x,ne=X-z.y;let re=se*se+ne*ne,le=0,he=0;le=J-C.x,he=F-C.y;let pe=le*le+he*he,ce=0,te=0,ue=null;Q<oe?(ce=q,te=R,ue=w):(ce=V,te=K,ue=g,Q=oe);let xe=0,_e=0,ve=null;if(re<pe?(xe=Y,_e=X,ve=z):(xe=J,_e=F,ve=C,re=pe),Q<re?(n.x=ce,n.y=te,s.x=ue.x,s.y=ue.y,c=Math.sqrt(Q)):(s.x=xe,s.y=_e,n.x=ve.x,n.y=ve.y,c=Math.sqrt(re)),c!=0){i.x=s.x-n.x,i.y=s.y-n.y;let Se=1/c;i.x*=Se,i.y*=Se,r&&(i.x=-i.x,i.y=-i.y)}return c}else{let z=0,C=0;z=P.gp0.x,C=P.gp0.y;let w=0,g=0;w=P.gp1.x,g=P.gp1.y;let O=0,E=0;O=w-z,E=g-C;let M=f.gnormy*z-f.gnormx*C,N=f.gnormy*w-f.gnormx*g,Z=1/(N-M),A=(-f.tp1-M)*Z;if(A>o.Config.epsilon){let G=A;z+=O*G,C+=E*G}let S=(-f.tp0-N)*Z;if(S<-o.Config.epsilon){let G=S;w+=O*G,g+=E*G}let L=z*f.gnormx+C*f.gnormy-f.gprojection,T=w*f.gnormx+g*f.gnormy-f.gprojection;if(L<T){s.x=z,s.y=C;let G=-L;return n.x=s.x+f.gnormx*G,n.y=s.y+f.gnormy*G,L}else{s.x=w,s.y=g;let G=-T;return n.x=s.x+f.gnormx*G,n.y=s.y+f.gnormy*G,T}}}else return l}else return l}}}};var De=class De{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,o=t.x-e.x,r=t.y-e.y,a,p,c;return r*i-o*l>=0?c=!0:(i=s.x-n.x,l=s.y-n.y,o=n.x-t.x,r=n.y-t.y,c=r*i-o*l>=0),c?p=!0:(i=e.x-s.x,l=e.y-s.y,o=s.x-n.x,r=s.y-n.y,p=r*i-o*l>=0),p?a=!0:(i=t.x-e.x,l=t.y-e.y,o=e.x-s.x,r=e.y-s.y,a=r*i-o*l>=0),a?!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 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}}De.edgeSet==null&&(Ps.zpp_pool==null?De.edgeSet=new Ps:(De.edgeSet=Ps.zpp_pool,Ps.zpp_pool=De.edgeSet.next,De.edgeSet.next=null),De.edgeSet.lt=St.edge_lt,De.edgeSet.swapped=St.edge_swap);let s;St.zpp_pool==null?s=new St:(s=St.zpp_pool,St.zpp_pool=s.next,s.next=null);let i=e.vertices,l=e.vertices;if(i!=null){let r=i;for(;;){let a=r,p=a.next;a.diagonals.reverse();let c=a.diagonals.head;for(;c!=null;){let h=c.elt;if(h.id<a.id){p=h,c=c.next;continue}let u=c.next==null?a.prev:c.next.elt;if(!De.delaunay(a,p,h,u)){let x;St.zpp_pool==null?x=new St:(x=St.zpp_pool,St.zpp_pool=x.next,x.next=null),x.a=a,x.b=h,a.id<h.id?(x.id=a.id,x.di=h.id):(x.id=h.id,x.di=a.id);let m=x;s.add(m),m.node=De.edgeSet.insert(m)}p=h,c=c.next}if(r=r.next,r==l)break}}for(;s.next!=null;){let r=s.pop_unsafe(),a=r.a,p=r.b,c=a.next,h=null,u=a.diagonals.head;for(;u!=null;){let m=u.elt;if(m==p){u=u.next,h=u==null?a.prev:u.elt;break}c=m,u=u.next}if(a.diagonals.remove(p),p.diagonals.remove(a),p==c.next)c.diagonals.add(h);else{let m=c.diagonals.head;for(;m!=null;){if(m.elt==p){c.diagonals.insert(m,h);break}m=m.next}}if(a==h.next)h.diagonals.add(c);else{let m=h.diagonals.head;for(;m!=null;){if(m.elt==a){h.diagonals.insert(m,c);break}m=m.next}}De.edgeSet.remove_node(r.node);let x=r;x.a=x.b=null,x.node=null,x.next=St.zpp_pool,St.zpp_pool=x}let o=s;o.a=o.b=null,o.node=null,o.next=St.zpp_pool,St.zpp_pool=o}static triangulate(e){let t=e.vertices,n=e.vertices,s=e.vertices.next,i=e.vertices;if(s!=null){let a=s;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==i)break}}De.queue==null&&(De.queue=new _i);let l=n.prev,o=n.next;for(De.queue.add(n);l!=t||o!=t;)l==t||o!=t&&(l.y<o.y||l.y==o.y&&l.x<o.x)?(De.queue.add(o),o.rightchain=!1,o=o.next):(De.queue.add(l),l.rightchain=!0,l=l.prev);De.queue.add(t),De.stack==null&&(De.stack=new _i),De.stack.add(De.queue.pop_unsafe());let r=De.queue.pop_unsafe();for(De.stack.add(r);;){let a=De.queue.pop_unsafe();if(De.queue.head==null)break;if(a.rightchain!=De.stack.head.elt.rightchain){for(;;){let p=De.stack.pop_unsafe();if(De.stack.head==null)break;e.add_diagonal(p,a)}De.stack.add(r)}else{let p=De.stack.pop_unsafe();for(;De.stack.head!=null;){let c=De.stack.head.elt,h=a.x-p.x,u=a.y-p.y,x=p.x-c.x,d=(p.y-c.y)*h-x*u;if(a.rightchain&&d>=0||!a.rightchain&&d<=0)break;e.add_diagonal(c,a),p=c,De.stack.pop()}De.stack.add(p)}De.stack.add(a),r=a}if(De.stack.head!=null)for(De.stack.pop();De.stack.head!=null;){let a=De.stack.pop_unsafe();if(De.stack.head==null)break;e.add_diagonal(n,a)}return e}};De.queue=null,De.stack=null,De.edgeSet=null;var Pl=De;var Cs=class Cs{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&&Cs._wrapFn&&(this.outer=Cs._wrapFn(this)),this.outer}};Cs._zpp=null,Cs._wrapFn=null;var ai=Cs;var wl=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 fn=class fn{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;fn.initFields(this)}static initFields(e){let t=fn._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=yn.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,o=i.head;for(;o!=null;){let r=o.elt;if(r.id==n&&r.di==s){l=r;break}o=o.next}return l}static int_callback(e,t,n){let s=e.int1,i=e.int2,l,o=t.options1,r=s.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=t.options2,p=i.cbTypes;l=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.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=fn._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=fn._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 a=i.elt;if(e.id<a.id)break;s=i,i=i.next}let l=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;s==null?(r.next=l.head,l.head=r):(r.next=s.next,s.next=r),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=_t.zpp_pool,_t.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=fn._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 o=l.zpp_inner.user_length;i.zpp_critical=!0;let r;if(i.zpp_i<o?r=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,r=!1),!r)break;i.zpp_critical=!1;let a=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(a):p.unshift(a)}this.userData!=null&&(e.zpp_inner_i.userData=Object.assign({},this.userData))}static _init(e,t){fn._initialized||(fn._initialized=!0,fn._zpp=e,fn._nape=t)}};fn._nape=null,fn._zpp=null,fn._initialized=!1;var Wt=fn;var je=class je{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=je._zpp;Wt.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=je._nape,t=je._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(je.bodyset==null){let e=je._zpp;je.bodyset=new e.util.ZPP_Set_ZPP_Body,je.bodyset.lt=je.bodysetlt,je.bodystack=new e.util.ZNPList_ZPP_Body}}connectedBodies_cont(e){je.bodyset.try_insert_bool(e.zpp_inner)&&(je.bodystack.add(e.zpp_inner),e.zpp_inner.graph_depth=je.cur_graph_depth+1)}connectedBodies(e,t){let n=je._nape;je.bodyset==null&&this.init_bodysetlist();let s=t??new n.phys.BodyList;for(je.bodystack.add(this),je.bodyset.insert(this),this.graph_depth=0;je.bodystack.head!=null;){let l=je.bodystack.pop_unsafe();if(l.graph_depth===e)continue;je.cur_graph_depth=l.graph_depth;let o=l.constraints.head;for(;o!=null;)o.elt.outer.visitBodies(this.connectedBodies_cont.bind(this)),o=o.next}let i=je.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 o=l.data;if(o!==this){let p=o.outer;s.zpp_inner.reverse_flag?s.push(p):s.unshift(p)}let r=l.parent;r!=null&&(l===r.prev?r.prev=null:r.next=null,l.parent=null);let a=l;a.data=null,a.lt=null,a.next=je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool,je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool=a,l=r}i.parent=null}return s}interactingBodies(e,t){let n=je._nape,s=je._zpp;je.bodyset==null&&this.init_bodysetlist();let i=t??new n.phys.BodyList,l=this.arbiters.head;for(;l!=null;){let r=l.elt;if(!r.sleeping&&(e===4||r.type===e)){let a=r.b1===this?r.b2:r.b1;if(je.bodyset.try_insert_bool(a)){let p=a.outer;i.zpp_inner.reverse_flag?i.push(p):i.unshift(p)}}l=l.next}let o=je.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=s.util.ZPP_Set_ZPP_Body.zpp_pool,s.util.ZPP_Set_ZPP_Body.zpp_pool=p,r=a}o.parent=null}return i}atRest(e){let t=je._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 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)s=!1;else{let c=this.rot-this.pre_rot;s=!(c*c*a>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,o=(i*this.axisx+n*this.axisy)*l;this.axisy=(i*this.axisy-n*this.axisx)*l,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,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,o=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=o.y*c.gnormx-o.x*c.gnormy,c.tp1=p.y*c.gnormx-p.x*c.gnormy,o=p,l=l.next}let r=t.gverts.next,a=i.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,s){let i=je._nape;if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;if(ye.poolVec2==null?l=new i.geom.Vec2:(l=ye.poolVec2,ye.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===ye.nextVec2&&(ye.nextVec2=null)),l.zpp_inner==null){let o;ae.zpp_pool==null?o=new ae:(o=ae.zpp_pool,ae.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=e,o.y=t,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.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;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x===e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),r=l.zpp_inner.y===t):r=!1,r||(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,o=s;s=s.next,l.x=e.body.posx+(e.body.axisy*o.x-e.body.axisx*o.y),l.y=e.body.posy+(o.x*e.body.axisx+o.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 o=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*o,e.localCOMy+=(i.y+l.y)*o,s=i,i=l,n=n.next;let r=n;t+=i.x*(r.y-s.y);let a=r.y*i.x-r.x*i.y;e.localCOMx+=(i.x+r.x)*a,e.localCOMy+=(i.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,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=je._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=je._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 o=l;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}s=i,i=i.next}}copy(){let e=je._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(!je._initialized){je._initialized=!0,je._zpp=e,je._nape=t;for(let n of Object.getOwnPropertyNames(Wt.prototype))n!=="constructor"&&!(n in je.prototype)&&(je.prototype[n]=Wt.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()),je.types=[null,t.BodyType_STATIC,t.BodyType_DYNAMIC,t.BodyType_KINEMATIC]}};je._nape=null,je._zpp=null,je.types=[],je.bodystack=null,je.bodyset=null,je.cur_graph_depth=0,je._initialized=!1;var Mn=je;var en=class en{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=en._zpp;Wt.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=en._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=en._zppOf(e);t.compound=null,this.space!=null&&this.space.remBody(t)}bodies_modifiable(){this.immutable_midstep("Compound::bodies")}constraints_adder(e){let t=en._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=en._zppOf(e);t.compound=null,this.space!=null&&this.space.remConstraint(t)}constraints_modifiable(){this.immutable_midstep("Compound::constraints")}compounds_adder(e){let t=en._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=en._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=en._nape,s=en._zpp,i=e==null;e==null&&(e=[]),t==null&&(t=[]);let l=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)!==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)}o=o.next}let r=this.bodies.head;for(;r!=null;){let p=r.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)}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)!==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)}a=a.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(Wt.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(en.prototype,e)&&(en.prototype[e]=Wt.prototype[e])}};en._nape=null,en._zpp=null,en._wrapFn=null;var Wn=en;var Bt=class Bt{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 Bt._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Bt._wrapFn)this.outer=Bt._wrapFn(this);else{this.outer=new Bt._nape.phys.FluidProperties;let e=this.outer.zpp_inner;e.outer=null,e.next=Bt.zpp_pool,Bt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Bt._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Bt.zpp_pool==null?e=new Bt:(e=Bt.zpp_pool,Bt.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=Bt._zpp,t=Bt._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 o=!1;l._validate!=null&&l._validate(),(l.x!==n||l.y!==s)&&(o=!0),o&&(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}};Bt.zpp_pool=null,Bt._nape=null,Bt._zpp=null,Bt._wrapFn=null;var Zn=Bt;var Ft=class Ft{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 Ft._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Ft._wrapFn)this.outer=Ft._wrapFn(this);else{this.outer=new Ft._nape.phys.Material;let e=this.outer.zpp_inner;e.outer=null,e.next=Ft.zpp_pool,Ft.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Ft._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e=new Ft;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}};Ft.zpp_pool=null,Ft.WAKE=1,Ft.PROPS=2,Ft.ANGDRAG=4,Ft.ARBITERS=8,Ft._nape=null,Ft._zpp=null,Ft._wrapFn=null;var Oe=Ft;var kn=class kn{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.capsule=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()),t.ShapeType_CAPSULE==null&&(t.ShapeType_CAPSULE=n()),kn.types=[t.ShapeType_CIRCLE,t.ShapeType_POLYGON,t.ShapeType_CAPSULE]}_initShape(e){let t=kn._zpp;Wt.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 Oe,this.sweepRadius=this.sweepCoef=0}static _init(){if(!kn._initialized){kn._initialized=!0;for(let e of Object.getOwnPropertyNames(Wt.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(kn.prototype,e)&&(kn.prototype[e]=Wt.prototype[e])}}isCircle(){return this.type===0}isPolygon(){return this.type===1}isCapsule(){return this.type===2}invalidate_sweepRadius(){this.zip_sweepRadius=!0}validate_sweepRadius(){this.zip_sweepRadius&&(this.zip_sweepRadius=!1,this.type===0?this.circle.__validate_sweepRadius():this.type===1?this.polygon.__validate_sweepRadius():this.capsule.__validate_sweepRadius())}clear(){this.type===0?this.circle.__clear():this.type===1?this.polygon.__clear():this.capsule.__clear()}validate_aabb(){this.zip_aabb&&this.body!=null&&(this.zip_aabb=!1,this.type===0?this.circle.__validate_aabb():this.type===1?this.polygon.__validate_aabb():this.capsule.__validate_aabb())}force_validate_aabb(){this.type===0?this.circle._force_validate_aabb():this.type===1?this.polygon._force_validate_aabb():this.capsule._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.type===1?this.polygon.__validate_area_inertia():this.capsule.__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.type===1?this.polygon.__validate_angDrag():this.capsule.__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.type===2)&&(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&Oe.WAKE)!==0&&this.wake(),(e&Oe.ARBITERS)!==0&&this.body!=null&&this.body.refreshArbiters(),(e&Oe.PROPS)!==0&&this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia()),(e&Oe.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=kn._zpp,t=this.type===0?this.circle.__copy():this.type===1?this.polygon.__copy():this.capsule.__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=Oe.zpp_pool,Oe.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}};kn._nape=null,kn._zpp=null,kn.types=[],kn._initialized=!1;var pi=kn;var En=class En{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(En._initialized)return;En._initialized=!0;let t=En._zpp.shape.ZPP_Shape.prototype,n=En.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=En._zpp,t=En._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=En._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=En._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}};En._nape=null,En._zpp=null,En._initialized=!1;var $n=En;var tn=class tn{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&&(tn._wrapFn?this.outer=tn._wrapFn(this):(tn.internal=!0,this.outer=new tn._nape.shape.Edge,tn.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=tn._zpp,t=tn._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=tn._zpp,t=tn._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)}};tn.zpp_pool=null,tn.internal=!1,tn._nape=null,tn._zpp=null,tn._wrapFn=null;var ot=tn;var mt=class mt{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=mt._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(mt._initialized)return;mt._initialized=!0;let t=mt._zpp.shape.ZPP_Shape.prototype,n=mt.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=mt._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 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(s,o),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=mt._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=mt._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=mt._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,m=s.y-h.y,d=Math.sqrt(x*x+m*m);u.length=d;let y=1/d;x*=y,m*=y;let b=x;x=-m,m=b,u.lprojection=x*s.x+m*s.y,u.lnormx=x,u.lnormy=m,u.wrap_lnorm!=null&&(u.wrap_lnorm.zpp_inner.x=x,u.wrap_lnorm.zpp_inner.y=m),s=h,n=n.next}let i=this.lverts.next,l=t.elt;l.lp0=s,l.lp1=i;let o=s.x-i.x,r=s.y-i.y,a=Math.sqrt(o*o+r*r);l.length=a;let p=1/a;o*=p,r*=p;let c=o;o=-r,r=c,l.lprojection=o*s.x+r*s.y,l.lnormx=o,l.lnormy=r,l.wrap_lnorm!=null&&(l.wrap_lnorm.zpp_inner.x=o,l.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,s=n;for(n=n.next;n!=null;){let o=n,r=t.elt;t=t.next,r.gp0=s,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,s=o,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=mt._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 o=l;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=s==null?this.edges.head.elt:s.next.elt;this.edges.erase(s),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=mt._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,o=n.y-i.y;l*l+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 s;for(;;){s=!1;let i=this.lverts.next;for(;i!=null;){let l=i.next==null?this.lverts.next:i.next,o=l.next==null?this.lverts.next:l.next,r=l.x-i.x,a=l.y-i.y,p=o.x-l.x,h=(o.y-l.y)*r-p*a;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=mt._nape,t=mt._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,o=l;l=l.next;let r=l;for(l=l.next;l!=null;){let a=l,p=a.x-r.x,c=a.y-r.y,h=r.x-o.x,x=(r.y-o.y)*p-h*c;if(x>e.Config.epsilon?s=!0:x<-e.Config.epsilon&&(n=!0),s&&n){i=!1;break}o=r,r=a,l=l.next}if(i){l=this.lverts.next;let a=l,p=a.x-r.x,c=a.y-r.y,h=r.x-o.x,x=(r.y-o.y)*p-h*c;if(x>e.Config.epsilon?s=!0:x<-e.Config.epsilon&&(n=!0),!(s&&n)){o=r,r=a,l=l.next;let m=l,d=m.x-r.x,y=m.y-r.y,b=r.x-o.x,P=(r.y-o.y)*d-b*y;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 a=!0,p=this.lverts.next,c=p;for(p=p.next;p!=null&&a;){let h=p,u=this.lverts.next,x=u.next;for(;x!=null&&a;){let m=x;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,x=x.next}if(a){let m=this.lverts.next;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e))}c=h,p=p.next}if(a){let h=this.lverts.next,u=this.lverts.next,x=u.next;for(;x!=null&&a;){let m=x;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,x=x.next}if(a){let m=this.lverts.next;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,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,s,i){let l=e.x-n.x,o=e.y-n.y,r=t.x-e.x,a=t.y-e.y,p=s.x-n.x,c=s.y-n.y,h=a*p-r*c;if(h*h>i.Config.epsilon){h=1/h;let u=(c*l-p*o)*h;if(u>i.Config.epsilon&&u<1-i.Config.epsilon){let x=(a*l-r*o)*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,o=t;t=t.next,l.x=e.posx+(e.axisy*o.x-e.axisx*o.y),l.y=e.posy+(o.x*e.axisx+o.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,o=i.y*s.x-i.x*s.y,r=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+=o*r,t+=o,this.area+=i.x*(l.y-s.y),s=i,i=l,n=n.next;let a=n;o=i.y*s.x-i.x*s.y,r=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+=o*r,t+=o,this.area+=i.x*(a.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=mt._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,o=i.next;for(;o!=null;){let r=o,a=n.elt;n=n.next,s+=a.length;let p=r.x-l.x,c=r.y-l.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let h=-(l.y*a.lnormx-l.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(h>0){let u=h>1?1:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let d=a.lnormy*l.x-a.lnormx*l.y,y=a.lnormy*x-a.lnormx*m,b=(y*y*y-d*d*d)/(3*(y-d));t+=b*u*a.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let d=a.lnormy*x-a.lnormx*m,y=a.lnormy*r.x-a.lnormx*r.y,b=(y*y*y-d*d*d)/(3*(y-d));t+=b*e.Config.fluidVacuumDrag*(1-u)*a.length*e.Config.fluidAngularDrag}l=r,o=o.next}{let r=this.lverts.next,a=n.elt;s+=a.length;let p=r.x-l.x,c=r.y-l.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let h=-(l.y*a.lnormx-l.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(h>0){let u=h>1?1:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let d=a.lnormy*l.x-a.lnormx*l.y,y=a.lnormy*x-a.lnormx*m,b=(y*y*y-d*d*d)/(3*(y-d));t+=b*u*a.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let d=a.lnormy*x-a.lnormx*m,y=a.lnormy*r.x-a.lnormx*r.y,b=(y*y*y-d*d*d)/(3*(y-d));t+=b*e.Config.fluidVacuumDrag*(1-u)*a.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 r=t;e+=s.x*(r.y-n.y);let a=r.y*s.x-r.x*s.y;this.localCOMx+=(s.x+r.x)*a,this.localCOMy+=(s.y+r.y)*a,n=s,s=r,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 o=t;e+=s.x*(o.y-n.y),l=o.y*s.x-o.x*s.y,this.localCOMx+=(s.x+o.x)*l,this.localCOMy+=(s.y+o.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=mt._zpp,t=mt._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=mt._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}};mt._nape=null,mt._zpp=null,mt._initialized=!1;var ei=mt;var Nn=class Nn{constructor(){this.radius=0;this.halfLength=0;this.outer_zn=null;this.spine1x=0;this.spine1y=0;this.spine2x=0;this.spine2y=0;this.radius=0,this.halfLength=0,this.outer_zn=null,this._initShape(2),this.capsule=this,this.zip_localCOM=!1}static _init(){if(Nn._initialized)return;Nn._initialized=!0;let t=Nn._zpp.shape.ZPP_Shape.prototype,n=Nn.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.wake())}invalidate_halfLength(){this.invalidate_area_inertia(),this.invalidate_angDrag(),this.zip_aabb=!0,this.zip_sweepRadius=!0,this.body!=null&&(this.body.zip_aabb=!0,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 Capsule added to a static Body whilst within a Space")}setupLocalCOM(){let e=Nn._zpp,t=Nn._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.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy));let c=this.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),this.worldCOMx=c.posx+(c.axisy*this.localCOMx-c.axisx*this.localCOMy),this.worldCOMy=c.posy+(this.localCOMx*c.axisx+this.localCOMy*c.axisy)}let e=this.body;if(e!=null){e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let c=e.axisy*this.halfLength,h=e.axisx*this.halfLength;this.spine1x=this.worldCOMx-c,this.spine1y=this.worldCOMy-h,this.spine2x=this.worldCOMx+c,this.spine2y=this.worldCOMy+h}let t=this.radius,n=this.spine1x-t,s=this.spine2x-t,i=this.spine1y-t,l=this.spine2y-t,o=this.spine1x+t,r=this.spine2x+t,a=this.spine1y+t,p=this.spine2y+t;this.aabb.minx=n<s?n:s,this.aabb.miny=i<l?i:l,this.aabb.maxx=o>r?o:r,this.aabb.maxy=a>p?a:p}_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);let t=e.axisy*this.halfLength,n=e.axisx*this.halfLength;this.spine1x=this.worldCOMx-t,this.spine1y=this.worldCOMy-n,this.spine2x=this.worldCOMx+t,this.spine2y=this.worldCOMy+n;let s=this.radius,i=this.spine1x-s,l=this.spine2x-s,o=this.spine1y-s,r=this.spine2y-s,a=this.spine1x+s,p=this.spine2x+s,c=this.spine1y+s,h=this.spine2y+s;this.aabb.minx=i<l?i:l,this.aabb.miny=o<r?o:r,this.aabb.maxx=a>p?a:p,this.aabb.maxy=c>h?c:h}__validate_sweepRadius(){let e=Math.sqrt(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy);this.sweepCoef=e+this.halfLength,this.sweepRadius=this.sweepCoef+this.radius}__validate_area_inertia(){let e=this.radius,t=this.halfLength,n=e*e;this.area=Math.PI*n+4*t*e;let s=2*t*(2*e)*(2*e*(2*e)+2*t*(2*t))/12,i=Math.PI*n*(n*.5+t*t);this.inertia=(s+i)/this.area+(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy)}__validate_angDrag(){let e=Nn._nape,t=this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy,n=this.radius*this.radius,s=this.halfLength*this.halfLength,i=this.material.dynamicFriction*e.Config.fluidAngularDragFriction;this.angDrag=(t+2*n+s)*i+.5*e.Config.fluidAngularDrag*(1+e.Config.fluidVacuumDrag)*t,this.angDrag/=2*(t+.5*n+s/3)}__scale(e,t){let n=((e<0?-e:e)+(t<0?-t:t))/2,s=n<0?-n:n;this.radius*=s,this.halfLength*=s,this.invalidate_radius(),this.invalidate_halfLength(),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);let n=Math.sqrt(t);this.radius*=n,this.halfLength*=n;let s=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=s,this.invalidate_radius(),this.invalidate_halfLength(),this.invalidate_localCOM()}__copy(){let e=Nn._nape,t=2*(this.halfLength+this.radius),n=2*this.radius,s=new e.shape.Capsule(t,n).zpp_inner_zn;return s.localCOMx=this.localCOMx,s.localCOMy=this.localCOMy,s.zip_localCOM=!1,s}};Nn._nape=null,Nn._zpp=null,Nn._initialized=!1;var ti=Nn;var gi=class gi{constructor(){this.space=null;this.is_sweep=!1;this.is_spatial_hash=!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.is_spatial_hash=!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 o=1;l.localCOMx+=l.lverts.next.next.x*o,l.localCOMy+=l.lverts.next.next.y*o;let r=.5;l.localCOMx*=r,l.localCOMy*=r}else{l.localCOMx=0,l.localCOMy=0;let o=0,r=l.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let d=r;o+=p.x*(d.y-a.y);let y=d.y*p.x-d.x*p.y;l.localCOMx+=(p.x+d.x)*y,l.localCOMy+=(p.y+d.y)*y,a=p,p=d,r=r.next}r=l.lverts.next;let c=r;o+=p.x*(c.y-a.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,a=p,p=c,r=r.next;let u=r;o+=p.x*(u.y-a.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,o=1/(3*o);let m=o;l.localCOMx*=m,l.localCOMy*=m}}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 if(e.type==2)e.capsule.__validate_aabb();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,o=t.gverts.next;for(;o!=null;){let r=o,a=l;l=l.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 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 a=i.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,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let f=c;p+=u.x*(f.y-h.y);let P=f.y*u.x-f.x*u.y;a.localCOMx+=(u.x+f.x)*P,a.localCOMy+=(u.y+f.y)*P,h=u,u=f,c=c.next}c=a.lverts.next;let x=c;p+=u.x*(x.y-h.y);let m=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*m,a.localCOMy+=(u.y+x.y)*m,h=u,u=x,c=c.next;let d=c;p+=u.x*(d.y-h.y);let y=d.y*u.x-d.x*u.y;a.localCOMx+=(u.x+d.x)*y,a.localCOMy+=(u.y+d.y)*y,p=1/(3*p);let b=p;a.localCOMx*=b,a.localCOMy*=b}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.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,o=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-o,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+o}else if(e.type==2)e.capsule.__validate_aabb();else{let i=e.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let a=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=a;a=a.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 o=i.gverts.next.next;for(;o!=null;){let r=o;r.x<i.aabb.minx&&(i.aabb.minx=r.x),r.x>i.aabb.maxx&&(i.aabb.maxx=r.x),r.y<i.aabb.miny&&(i.aabb.miny=r.y),r.y>i.aabb.maxy&&(i.aabb.maxy=r.y),o=o.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=gi._zpp,n=gi._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 l=this.aabbShape.zpp_inner.aabb,o=(e.maxx-e.minx)/(l.maxx-l.minx),r=(e.maxy-e.miny)/(l.maxy-l.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,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 m=c.zpp_inner;m._invalidate!=null&&m._invalidate();let d=this.matrix;if(r!==r)throw new Error("Error: Mat23::d cannot be NaN");d.zpp_inner.d=r;let y=d.zpp_inner;y._invalidate!=null&&y._invalidate();let b=this.matrix,f=e.minx-o*l.minx;if(f!==f)throw new Error("Error: Mat23::tx cannot be NaN");b.zpp_inner.tx=f;let P=b.zpp_inner;P._invalidate!=null&&P._invalidate();let k=this.matrix,_=e.miny-r*l.miny;if(_!==_)throw new Error("Error: Mat23::ty cannot be NaN");k.zpp_inner.ty=_;let z=k.zpp_inner;z._invalidate!=null&&z._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 m=h;c+=x.x*(m.y-u.y);let d=m.y*x.x-m.x*x.y;p.localCOMx+=(x.x+m.x)*d,p.localCOMy+=(x.y+m.y)*d,u=x,x=m,h=h.next;let y=h;c+=x.x*(y.y-u.y);let b=y.y*x.x-y.x*x.y;p.localCOMx+=(x.x+y.x)*b,p.localCOMy+=(x.y+y.y)*b,c=1/(3*c);let f=c;p.localCOMx*=f,p.localCOMy*=f}}l.wrap_localCOM!=null&&(l.wrap_localCOM.zpp_inner.x=l.localCOMx,l.wrap_localCOM.zpp_inner.y=l.localCOMy)}let a=l.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.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 o=l.radius,r=l.radius;l.aabb.minx=l.worldCOMx-o,l.aabb.miny=l.worldCOMy-r,l.aabb.maxx=l.worldCOMx+o,l.aabb.maxy=l.worldCOMy+r}else{let l=s.polygon;if(l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let a=l.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.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 o=l.gverts.next;l.aabb.minx=o.x,l.aabb.miny=o.y,l.aabb.maxx=o.x,l.aabb.maxy=o.y;let r=l.gverts.next.next;for(;r!=null;){let a=r;a.x<l.aabb.minx&&(l.aabb.minx=a.x),a.x>l.aabb.maxx&&(l.aabb.maxx=a.x),a.y<l.aabb.miny&&(l.aabb.miny=a.y),a.y>l.aabb.maxy&&(l.aabb.maxy=a.y),r=r.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 m=x,d=u;u=u.next,m.x=i.body.posx+(i.body.axisy*d.x-i.body.axisx*d.y),m.y=i.body.posy+(d.x*i.body.axisx+d.y*i.body.axisy),x=x.next}}let o=i.edges.head,r=i.gverts.next,a=r;for(r=r.next;r!=null;){let h=r,u=o.elt;o=o.next,u.gp0=a,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,a=h,r=r.next}let p=i.gverts.next,c=o.elt;o=o.next,c.gp0=a,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=gi._zpp,i=gi._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 r=new i.phys.Body(s.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(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=a,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(),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 m=c.zpp_inner;if(m._validate!=null&&m._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 d=c.zpp_inner;d._validate!=null&&d._validate(),x=c.zpp_inner.y==p}else x=!1;if(!x){c.zpp_inner.x=a,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);r.zpp_inner.reverse_flag?r.push(h):r.unshift(h)}else{let o=this.circShape.zpp_inner.circle,r=n/o.radius;this.matrix==null&&(this.matrix=new i.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 h=p.zpp_inner.d;if(h!==h)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=h;let u=a.zpp_inner;u._invalidate!=null&&u._invalidate();let x=this.matrix,m=this.matrix;m.zpp_inner.c=0;let d=m.zpp_inner;d._invalidate!=null&&d._invalidate();let y=m.zpp_inner.c;if(y!==y)throw new Error("Error: Mat23::b cannot be NaN");x.zpp_inner.b=y;let b=x.zpp_inner;b._invalidate!=null&&b._invalidate();let f=this.matrix,P=e-r*o.localCOMx;if(P!==P)throw new Error("Error: Mat23::tx cannot be NaN");f.zpp_inner.tx=P;let k=f.zpp_inner;k._invalidate!=null&&k._invalidate();let _=this.matrix,z=t-r*o.localCOMy;if(z!==z)throw new Error("Error: Mat23::ty cannot be NaN");_.zpp_inner.ty=z;let C=_.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 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 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 m=u;for(u=u.next;u!=null;){let k=u;h+=m.x*(k.y-x.y);let _=k.y*m.x-k.x*m.y;c.localCOMx+=(m.x+k.x)*_,c.localCOMy+=(m.y+k.y)*_,x=m,m=k,u=u.next}u=c.lverts.next;let d=u;h+=m.x*(d.y-x.y);let y=d.y*m.x-d.x*m.y;c.localCOMx+=(m.x+d.x)*y,c.localCOMy+=(m.y+d.y)*y,x=m,m=d,u=u.next;let b=u;h+=m.x*(b.y-x.y);let f=b.y*m.x-b.x*m.y;c.localCOMx+=(m.x+b.x)*f,c.localCOMy+=(m.y+b.y)*f,h=1/(3*h);let P=h;c.localCOMx*=P,c.localCOMy*=P}}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,h=o.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),u.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),h=h.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,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 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 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 a=i,p=s.elt;s=s.next,p.gp0=l,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,l=a,i=i.next}let o=t.gverts.next,r=s.elt;s=s.next,r.gp0=l,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 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 o=1;l.localCOMx+=l.lverts.next.next.x*o,l.localCOMy+=l.lverts.next.next.y*o;let r=.5;l.localCOMx*=r,l.localCOMy*=r}else{l.localCOMx=0,l.localCOMy=0;let o=0,r=l.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let d=r;o+=p.x*(d.y-a.y);let y=d.y*p.x-d.x*p.y;l.localCOMx+=(p.x+d.x)*y,l.localCOMy+=(p.y+d.y)*y,a=p,p=d,r=r.next}r=l.lverts.next;let c=r;o+=p.x*(c.y-a.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,a=p,p=c,r=r.next;let u=r;o+=p.x*(u.y-a.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,o=1/(3*o);let m=o;l.localCOMx*=m,l.localCOMy*=m}}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,o=t.gverts.next;for(;o!=null;){let r=o,a=l;l=l.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 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 o=i;for(i=i.next;i!=null;){let u=i;s+=o.x*(u.y-l.y);let x=u.y*o.x-u.x*o.y;n.localCOMx+=(o.x+u.x)*x,n.localCOMy+=(o.y+u.y)*x,l=o,o=u,i=i.next}i=n.lverts.next;let r=i;s+=o.x*(r.y-l.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,l=o,o=r,i=i.next;let p=i;s+=o.x*(p.y-l.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,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}};gi._zpp=null,gi._nape=null;var Tn=gi;var Ae=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}};Ae.zpp_pool=null;var st=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;this.gprev=null}alloc(){}free(){this.n1=this.n2=null,this.sleeping=!1,this.gprev=null}};st.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 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=Ae.zpp_pool,Ae.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 a=n.child1,p=n.child2,c=n.aabb,h=(c.maxx-c.minx+(c.maxy-c.miny))*2,u=Zt.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 m=Zt.tmpaabb,d=(m.maxx-m.minx+(m.maxy-m.miny))*2,y=2*d,b=2*(d-h),f=Zt.tmpaabb,P=a.aabb;f.minx=t.minx<P.minx?t.minx:P.minx,f.miny=t.miny<P.miny?t.miny:P.miny,f.maxx=t.maxx>P.maxx?t.maxx:P.maxx,f.maxy=t.maxy>P.maxy?t.maxy:P.maxy;let k;if(a.child1==null){let w=Zt.tmpaabb;k=(w.maxx-w.minx+(w.maxy-w.miny))*2+b}else{let w=a.aabb,g=(w.maxx-w.minx+(w.maxy-w.miny))*2,O=Zt.tmpaabb;k=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+b}let _=Zt.tmpaabb,z=p.aabb;_.minx=t.minx<z.minx?t.minx:z.minx,_.miny=t.miny<z.miny?t.miny:z.miny,_.maxx=t.maxx>z.maxx?t.maxx:z.maxx,_.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let C;if(p.child1==null){let w=Zt.tmpaabb;C=(w.maxx-w.minx+(w.maxy-w.miny))*2+b}else{let w=p.aabb,g=(w.maxx-w.minx+(w.maxy-w.miny))*2,O=Zt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+b}if(y<k&&y<C)break;n=k<C?a:p}let s=n,i=s.parent,l;Ae.zpp_pool==null?l=new Ae:(l=Ae.zpp_pool,Ae.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 o=l.aabb,r=s.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,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,y=n.child2,b=y.height-d.height;if(b>1){let f=y.child1,P=y.child2;if(y.child1=n,y.parent=n.parent,n.parent=y,y.parent!=null?y.parent.child1==n?y.parent.child1=y:y.parent.child2=y:this.root=y,f.height>P.height){y.child2=f,n.child2=P,P.parent=n;let k=n.aabb,_=d.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=n.aabb,g=f.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=f.height;y.height=1+(M>N?M:N)}else{y.child2=P,n.child2=f,f.parent=n;let k=n.aabb,_=d.aabb,z=f.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=n.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=f.height;n.height=1+(O>E?O:E);let M=n.height,N=P.height;y.height=1+(M>N?M:N)}n=y}else if(b<-1){let f=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,f.height>P.height){d.child2=f,n.child1=P,P.parent=n;let k=n.aabb,_=y.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=n.aabb,g=f.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=f.height;d.height=1+(M>N?M:N)}else{d.child2=P,n.child1=f,f.parent=n;let k=n.aabb,_=y.aabb,z=f.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=n.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=f.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 a=n.child1,p=n.child2,c=a.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=a.aabb,m=p.aabb;u.minx=x.minx<m.minx?x.minx:m.minx,u.miny=x.miny<m.miny?x.miny:m.miny,u.maxx=x.maxx>m.maxx?x.maxx:m.maxx,u.maxy=x.maxy>m.maxy?x.maxy:m.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,h=(c.maxx-c.minx+(c.maxy-c.miny))*2,u=Zt.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 m=Zt.tmpaabb,d=(m.maxx-m.minx+(m.maxy-m.miny))*2,y=2*d,b=2*(d-h),f=Zt.tmpaabb,P=a.aabb;f.minx=t.minx<P.minx?t.minx:P.minx,f.miny=t.miny<P.miny?t.miny:P.miny,f.maxx=t.maxx>P.maxx?t.maxx:P.maxx,f.maxy=t.maxy>P.maxy?t.maxy:P.maxy;let k;if(a.child1==null){let w=Zt.tmpaabb;k=(w.maxx-w.minx+(w.maxy-w.miny))*2+b}else{let w=a.aabb,g=(w.maxx-w.minx+(w.maxy-w.miny))*2,O=Zt.tmpaabb;k=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+b}let _=Zt.tmpaabb,z=p.aabb;_.minx=t.minx<z.minx?t.minx:z.minx,_.miny=t.miny<z.miny?t.miny:z.miny,_.maxx=t.maxx>z.maxx?t.maxx:z.maxx,_.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let C;if(p.child1==null){let w=Zt.tmpaabb;C=(w.maxx-w.minx+(w.maxy-w.miny))*2+b}else{let w=p.aabb,g=(w.maxx-w.minx+(w.maxy-w.miny))*2,O=Zt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+b}if(y<k&&y<C)break;n=k<C?a:p}let s=n,i=s.parent,l;Ae.zpp_pool==null?l=new Ae:(l=Ae.zpp_pool,Ae.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 o=l.aabb,r=s.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,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,y=n.child2,b=y.height-d.height;if(b>1){let f=y.child1,P=y.child2;if(y.child1=n,y.parent=n.parent,n.parent=y,y.parent!=null?y.parent.child1==n?y.parent.child1=y:y.parent.child2=y:this.root=y,f.height>P.height){y.child2=f,n.child2=P,P.parent=n;let k=n.aabb,_=d.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=n.aabb,g=f.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=f.height;y.height=1+(M>N?M:N)}else{y.child2=P,n.child2=f,f.parent=n;let k=n.aabb,_=d.aabb,z=f.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=n.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=f.height;n.height=1+(O>E?O:E);let M=n.height,N=P.height;y.height=1+(M>N?M:N)}n=y}else if(b<-1){let f=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,f.height>P.height){d.child2=f,n.child1=P,P.parent=n;let k=n.aabb,_=y.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=n.aabb,g=f.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=f.height;d.height=1+(M>N?M:N)}else{d.child2=P,n.child1=f,f.parent=n;let k=n.aabb,_=y.aabb,z=f.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=n.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=f.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 a=n.child1,p=n.child2,c=a.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=a.aabb,m=p.aabb;u.minx=x.minx<m.minx?x.minx:m.minx,u.miny=x.miny<m.miny?x.miny:m.miny,u.maxx=x.maxx>m.maxx?x.maxx:m.maxx,u.maxy=x.maxy>m.maxy?x.maxy:m.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=Ae.zpp_pool,Ae.zpp_pool=i;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let d=o.child1,y=o.child2,b=y.height-d.height;if(b>1){let f=y.child1,P=y.child2;if(y.child1=o,y.parent=o.parent,o.parent=y,y.parent!=null?y.parent.child1==o?y.parent.child1=y:y.parent.child2=y:this.root=y,f.height>P.height){y.child2=f,o.child2=P,P.parent=o;let k=o.aabb,_=d.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=o.aabb,g=f.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=P.height;o.height=1+(O>E?O:E);let M=o.height,N=f.height;y.height=1+(M>N?M:N)}else{y.child2=P,o.child2=f,f.parent=o;let k=o.aabb,_=d.aabb,z=f.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=o.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=f.height;o.height=1+(O>E?O:E);let M=o.height,N=P.height;y.height=1+(M>N?M:N)}o=y}else if(b<-1){let f=d.child1,P=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,f.height>P.height){d.child2=f,o.child1=P,P.parent=o;let k=o.aabb,_=y.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=o.aabb,g=f.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=P.height;o.height=1+(O>E?O:E);let M=o.height,N=f.height;d.height=1+(M>N?M:N)}else{d.child2=P,o.child1=f,f.parent=o;let k=o.aabb,_=y.aabb,z=f.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=o.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=f.height;o.height=1+(O>E?O:E);let M=o.height,N=P.height;d.height=1+(M>N?M:N)}o=d}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,h=a.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=a.height,m=p.height;r.height=1+(x>m?x:m),o=r.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=Ae.zpp_pool,Ae.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=Ae.zpp_pool,Ae.zpp_pool=i;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let d=o.child1,y=o.child2,b=y.height-d.height;if(b>1){let f=y.child1,P=y.child2;if(y.child1=o,y.parent=o.parent,o.parent=y,y.parent!=null?y.parent.child1==o?y.parent.child1=y:y.parent.child2=y:this.root=y,f.height>P.height){y.child2=f,o.child2=P,P.parent=o;let k=o.aabb,_=d.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=o.aabb,g=f.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=P.height;o.height=1+(O>E?O:E);let M=o.height,N=f.height;y.height=1+(M>N?M:N)}else{y.child2=P,o.child2=f,f.parent=o;let k=o.aabb,_=d.aabb,z=f.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=o.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=f.height;o.height=1+(O>E?O:E);let M=o.height,N=P.height;y.height=1+(M>N?M:N)}o=y}else if(b<-1){let f=d.child1,P=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,f.height>P.height){d.child2=f,o.child1=P,P.parent=o;let k=o.aabb,_=y.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=o.aabb,g=f.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=P.height;o.height=1+(O>E?O:E);let M=o.height,N=f.height;d.height=1+(M>N?M:N)}else{d.child2=P,o.child1=f,f.parent=o;let k=o.aabb,_=y.aabb,z=f.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=o.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=f.height;o.height=1+(O>E?O:E);let M=o.height,N=P.height;d.height=1+(M>N?M:N)}o=d}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,h=a.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=a.height,m=p.height;r.height=1+(x>m?x:m),o=r.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=Ae.zpp_pool,Ae.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 o=e.aabb,r=t.aabb,a=l.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,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 m=e.height,d=i.height;n.height=1+(m>d?m:d)}else{n.child2=l,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,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 m=e.height,d=l.height;n.height=1+(m>d?m: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 o=e.aabb,r=n.aabb,a=l.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,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 m=e.height,d=i.height;t.height=1+(m>d?m:d)}else{t.child2=l,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,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 m=e.height,d=l.height;t.height=1+(m>d?m:d)}return t}else return e}}};Zt.tmpaabb=null;var $e=Zt;var we=class we extends Tn{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}_linkPair(t){t.gprev=null,t.next=this.pairs,this.pairs!=null&&(this.pairs.gprev=t),this.pairs=t}_unlinkPair(t){t.gprev!=null?t.gprev.next=t.next:this.pairs=t.next,t.next!=null&&(t.next.gprev=t.gprev),t.gprev=null,t.next=null}dyn(t){return t.body.type==1?!1:!t.body.component.sleeping}__insert(t){let n;Ae.zpp_pool==null?n=new Ae:(n=Ae.zpp_pool,Ae.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 l=null,o=this.syncs;for(;o!=null&&o!=n;)l=o,o=o.snext;l==null?this.syncs=o.snext:l.snext=o.snext,o.snext=null,n.synced=!1}if(n.moved){let l=null,o=this.moves;for(;o!=null&&o!=n;)l=o,o=o.mnext;l==null?this.moves=o.mnext:l.mnext=o.mnext,o.mnext=null,n.moved=!1}for(;t.pairs.head!=null;){let l=t.pairs.pop_unsafe();l.sleeping||this._unlinkPair(l),l.n1==n?l.n2.shape.pairs.remove(l):l.n1.shape.pairs.remove(l),l.arb!=null&&(l.arb.pair=null),l.arb=null,l.n1=l.n2=null,l.sleeping=!1,l.gprev=null,l.next=st.zpp_pool,st.zpp_pool=l}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=Ae.zpp_pool,Ae.zpp_pool=s}__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 a=i.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,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let f=c;p+=u.x*(f.y-h.y);let P=f.y*u.x-f.x*u.y;a.localCOMx+=(u.x+f.x)*P,a.localCOMy+=(u.y+f.y)*P,h=u,u=f,c=c.next}c=a.lverts.next;let x=c;p+=u.x*(x.y-h.y);let m=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*m,a.localCOMy+=(u.y+x.y)*m,h=u,u=x,c=c.next;let d=c;p+=u.x*(d.y-h.y);let y=d.y*u.x-d.x*u.y;a.localCOMx+=(u.x+d.x)*y,a.localCOMy+=(u.y+d.y)*y,p=1/(3*p);let b=p;a.localCOMx*=b,a.localCOMy*=b}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.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,o=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-o,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+o}else{let i=t.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let a=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=a;a=a.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 o=i.gverts.next.next;for(;o!=null;){let r=o;r.x<i.aabb.minx&&(i.aabb.minx=r.x),r.x>i.aabb.maxx&&(i.aabb.maxx=r.x),r.y<i.aabb.miny&&(i.aabb.miny=r.y),r.y>i.aabb.maxy&&(i.aabb.maxy=r.y),o=o.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 r=t.dyn?this.dtree:this.stree;if(t==r.root)r.root=null;else{let a=t.parent,p=a.parent,c=a.child1==t?a.child2:a.child1;if(p!=null){p.child1==a?p.child1=c:p.child2=c,c.parent=p;let h=a;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=Ae.zpp_pool,Ae.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else{let _=x.child1,z=x.child2,C=z.height-_.height;if(C>1){let w=z.child1,g=z.child2;if(z.child1=x,z.parent=x.parent,x.parent=z,z.parent!=null?z.parent.child1==x?z.parent.child1=z:z.parent.child2=z:r.root=z,w.height>g.height){z.child2=w,x.child2=g,g.parent=x;let O=x.aabb,E=_.aabb,M=g.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=z.aabb,Z=x.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=g.height;x.height=1+(S>L?S:L);let T=x.height,G=w.height;z.height=1+(T>G?T:G)}else{z.child2=g,x.child2=w,w.parent=x;let O=x.aabb,E=_.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=z.aabb,Z=x.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=w.height;x.height=1+(S>L?S:L);let T=x.height,G=g.height;z.height=1+(T>G?T:G)}x=z}else if(C<-1){let w=_.child1,g=_.child2;if(_.child1=x,_.parent=x.parent,x.parent=_,_.parent!=null?_.parent.child1==x?_.parent.child1=_:_.parent.child2=_:r.root=_,w.height>g.height){_.child2=w,x.child1=g,g.parent=x;let O=x.aabb,E=z.aabb,M=g.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=_.aabb,Z=x.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=g.height;x.height=1+(S>L?S:L);let T=x.height,G=w.height;_.height=1+(T>G?T:G)}else{_.child2=g,x.child1=w,w.parent=x;let O=x.aabb,E=z.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=_.aabb,Z=x.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=w.height;x.height=1+(S>L?S:L);let T=x.height,G=g.height;_.height=1+(T>G?T:G)}x=_}else x=x}let m=x.child1,d=x.child2,y=x.aabb,b=m.aabb,f=d.aabb;y.minx=b.minx<f.minx?b.minx:f.minx,y.miny=b.miny<f.miny?b.miny:f.miny,y.maxx=b.maxx>f.maxx?b.maxx:f.maxx,y.maxy=b.maxy>f.maxy?b.maxy:f.maxy;let P=m.height,k=d.height;x.height=1+(P>k?P:k),x=x.parent}}else{r.root=c,c.parent=null;let h=a;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=Ae.zpp_pool,Ae.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 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 h=r.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,m=x;x=x.next;let d=x;for(x=x.next;x!=null;){let _=x;u+=d.x*(_.y-m.y);let z=_.y*d.x-_.x*d.y;h.localCOMx+=(d.x+_.x)*z,h.localCOMy+=(d.y+_.y)*z,m=d,d=_,x=x.next}x=h.lverts.next;let y=x;u+=d.x*(y.y-m.y);let b=y.y*d.x-y.x*d.y;h.localCOMx+=(d.x+y.x)*b,h.localCOMy+=(d.y+y.y)*b,m=d,d=y,x=x.next;let f=x;u+=d.x*(f.y-m.y);let P=f.y*d.x-f.x*d.y;h.localCOMx+=(d.x+f.x)*P,h.localCOMy+=(d.y+f.y)*P,u=1/(3*u);let k=u;h.localCOMx*=k,h.localCOMy*=k}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.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,p=r.radius;r.aabb.minx=r.worldCOMx-a,r.aabb.miny=r.worldCOMy-p,r.aabb.maxx=r.worldCOMx+a,r.aabb.maxy=r.worldCOMy+p}else{let r=s.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=r.lverts.next,u=r.gverts.next;for(;u!=null;){let x=u,m=h;h=h.next,x.x=r.body.posx+(r.body.axisy*m.x-r.body.axisx*m.y),x.y=r.body.posy+(m.x*r.body.axisx+m.y*r.body.axisy),u=u.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 p=r.gverts.next.next;for(;p!=null;){let c=p;c.x<r.aabb.minx&&(r.aabb.minx=c.x),c.x>r.aabb.maxx&&(r.aabb.maxx=c.x),c.y<r.aabb.miny&&(r.aabb.miny=c.y),c.y>r.aabb.maxy&&(r.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 o=(t.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(o.root==null)o.root=t,o.root.parent=null;else{let r=t.aabb,a=o.root;for(;a.child1!=null;){let m=a.child1,d=a.child2,y=a.aabb,b=(y.maxx-y.minx+(y.maxy-y.miny))*2,f=$e.tmpaabb,P=a.aabb;f.minx=P.minx<r.minx?P.minx:r.minx,f.miny=P.miny<r.miny?P.miny:r.miny,f.maxx=P.maxx>r.maxx?P.maxx:r.maxx,f.maxy=P.maxy>r.maxy?P.maxy:r.maxy;let k=$e.tmpaabb,_=(k.maxx-k.minx+(k.maxy-k.miny))*2,z=2*_,C=2*(_-b),w=$e.tmpaabb,g=m.aabb;w.minx=r.minx<g.minx?r.minx:g.minx,w.miny=r.miny<g.miny?r.miny:g.miny,w.maxx=r.maxx>g.maxx?r.maxx:g.maxx,w.maxy=r.maxy>g.maxy?r.maxy:g.maxy;let O;if(m.child1==null){let Z=$e.tmpaabb;O=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=m.aabb,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=$e.tmpaabb;O=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}let E=$e.tmpaabb,M=d.aabb;E.minx=r.minx<M.minx?r.minx:M.minx,E.miny=r.miny<M.miny?r.miny:M.miny,E.maxx=r.maxx>M.maxx?r.maxx:M.maxx,E.maxy=r.maxy>M.maxy?r.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,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=$e.tmpaabb;N=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}if(z<O&&z<N)break;a=O<N?m:d}let p=a,c=p.parent,h;Ae.zpp_pool==null?h=new Ae:(h=Ae.zpp_pool,Ae.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=r.minx<x.minx?r.minx:x.minx,u.miny=r.miny<x.miny?r.miny:x.miny,u.maxx=r.maxx>x.maxx?r.maxx:x.maxx,u.maxy=r.maxy>x.maxy?r.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,o.root=h),a=t.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else{let _=a.child1,z=a.child2,C=z.height-_.height;if(C>1){let w=z.child1,g=z.child2;if(z.child1=a,z.parent=a.parent,a.parent=z,z.parent!=null?z.parent.child1==a?z.parent.child1=z:z.parent.child2=z:o.root=z,w.height>g.height){z.child2=w,a.child2=g,g.parent=a;let O=a.aabb,E=_.aabb,M=g.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=z.aabb,Z=a.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=g.height;a.height=1+(S>L?S:L);let T=a.height,G=w.height;z.height=1+(T>G?T:G)}else{z.child2=g,a.child2=w,w.parent=a;let O=a.aabb,E=_.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=z.aabb,Z=a.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=w.height;a.height=1+(S>L?S:L);let T=a.height,G=g.height;z.height=1+(T>G?T:G)}a=z}else if(C<-1){let w=_.child1,g=_.child2;if(_.child1=a,_.parent=a.parent,a.parent=_,_.parent!=null?_.parent.child1==a?_.parent.child1=_:_.parent.child2=_:o.root=_,w.height>g.height){_.child2=w,a.child1=g,g.parent=a;let O=a.aabb,E=z.aabb,M=g.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=_.aabb,Z=a.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=g.height;a.height=1+(S>L?S:L);let T=a.height,G=w.height;_.height=1+(T>G?T:G)}else{_.child2=g,a.child1=w,w.parent=a;let O=a.aabb,E=z.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=_.aabb,Z=a.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=w.height;a.height=1+(S>L?S:L);let T=a.height,G=g.height;_.height=1+(T>G?T:G)}a=_}else a=a}let m=a.child1,d=a.child2,y=m.height,b=d.height;a.height=1+(y>b?y:b);let f=a.aabb,P=m.aabb,k=d.aabb;f.minx=P.minx<k.minx?P.minx:k.minx,f.miny=P.miny<k.miny?P.miny:k.miny,f.maxx=P.maxx>k.maxx?P.maxx:k.maxx,f.maxy=P.maxy>k.maxy?P.maxy:k.maxy,a=a.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 r=n.dyn?this.dtree:this.stree;if(n==r.root)r.root=null;else{let a=n.parent,p=a.parent,c=a.child1==n?a.child2:a.child1;if(p!=null){p.child1==a?p.child1=c:p.child2=c,c.parent=p;let h=a;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=Ae.zpp_pool,Ae.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else{let _=x.child1,z=x.child2,C=z.height-_.height;if(C>1){let w=z.child1,g=z.child2;if(z.child1=x,z.parent=x.parent,x.parent=z,z.parent!=null?z.parent.child1==x?z.parent.child1=z:z.parent.child2=z:r.root=z,w.height>g.height){z.child2=w,x.child2=g,g.parent=x;let O=x.aabb,E=_.aabb,M=g.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=z.aabb,Z=x.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=g.height;x.height=1+(S>L?S:L);let T=x.height,G=w.height;z.height=1+(T>G?T:G)}else{z.child2=g,x.child2=w,w.parent=x;let O=x.aabb,E=_.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=z.aabb,Z=x.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=w.height;x.height=1+(S>L?S:L);let T=x.height,G=g.height;z.height=1+(T>G?T:G)}x=z}else if(C<-1){let w=_.child1,g=_.child2;if(_.child1=x,_.parent=x.parent,x.parent=_,_.parent!=null?_.parent.child1==x?_.parent.child1=_:_.parent.child2=_:r.root=_,w.height>g.height){_.child2=w,x.child1=g,g.parent=x;let O=x.aabb,E=z.aabb,M=g.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=_.aabb,Z=x.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=g.height;x.height=1+(S>L?S:L);let T=x.height,G=w.height;_.height=1+(T>G?T:G)}else{_.child2=g,x.child1=w,w.parent=x;let O=x.aabb,E=z.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=_.aabb,Z=x.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=w.height;x.height=1+(S>L?S:L);let T=x.height,G=g.height;_.height=1+(T>G?T:G)}x=_}else x=x}let m=x.child1,d=x.child2,y=x.aabb,b=m.aabb,f=d.aabb;y.minx=b.minx<f.minx?b.minx:f.minx,y.miny=b.miny<f.miny?b.miny:f.miny,y.maxx=b.maxx>f.maxx?b.maxx:f.maxx,y.maxy=b.maxy>f.maxy?b.maxy:f.maxy;let P=m.height,k=d.height;x.height=1+(P>k?P:k),x=x.parent}}else{r.root=c,c.parent=null;let h=a;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=Ae.zpp_pool,Ae.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 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 h=r.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,m=x;x=x.next;let d=x;for(x=x.next;x!=null;){let _=x;u+=d.x*(_.y-m.y);let z=_.y*d.x-_.x*d.y;h.localCOMx+=(d.x+_.x)*z,h.localCOMy+=(d.y+_.y)*z,m=d,d=_,x=x.next}x=h.lverts.next;let y=x;u+=d.x*(y.y-m.y);let b=y.y*d.x-y.x*d.y;h.localCOMx+=(d.x+y.x)*b,h.localCOMy+=(d.y+y.y)*b,m=d,d=y,x=x.next;let f=x;u+=d.x*(f.y-m.y);let P=f.y*d.x-f.x*d.y;h.localCOMx+=(d.x+f.x)*P,h.localCOMy+=(d.y+f.y)*P,u=1/(3*u);let k=u;h.localCOMx*=k,h.localCOMy*=k}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.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,p=r.radius;r.aabb.minx=r.worldCOMx-a,r.aabb.miny=r.worldCOMy-p,r.aabb.maxx=r.worldCOMx+a,r.aabb.maxy=r.worldCOMy+p}else{let r=s.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=r.lverts.next,u=r.gverts.next;for(;u!=null;){let x=u,m=h;h=h.next,x.x=r.body.posx+(r.body.axisy*m.x-r.body.axisx*m.y),x.y=r.body.posy+(m.x*r.body.axisx+m.y*r.body.axisy),u=u.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 p=r.gverts.next.next;for(;p!=null;){let c=p;c.x<r.aabb.minx&&(r.aabb.minx=c.x),c.x>r.aabb.maxx&&(r.aabb.maxx=c.x),c.y<r.aabb.miny&&(r.aabb.miny=c.y),c.y>r.aabb.maxy&&(r.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 o=(n.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(o.root==null)o.root=n,o.root.parent=null;else{let r=n.aabb,a=o.root;for(;a.child1!=null;){let m=a.child1,d=a.child2,y=a.aabb,b=(y.maxx-y.minx+(y.maxy-y.miny))*2,f=$e.tmpaabb,P=a.aabb;f.minx=P.minx<r.minx?P.minx:r.minx,f.miny=P.miny<r.miny?P.miny:r.miny,f.maxx=P.maxx>r.maxx?P.maxx:r.maxx,f.maxy=P.maxy>r.maxy?P.maxy:r.maxy;let k=$e.tmpaabb,_=(k.maxx-k.minx+(k.maxy-k.miny))*2,z=2*_,C=2*(_-b),w=$e.tmpaabb,g=m.aabb;w.minx=r.minx<g.minx?r.minx:g.minx,w.miny=r.miny<g.miny?r.miny:g.miny,w.maxx=r.maxx>g.maxx?r.maxx:g.maxx,w.maxy=r.maxy>g.maxy?r.maxy:g.maxy;let O;if(m.child1==null){let Z=$e.tmpaabb;O=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=m.aabb,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=$e.tmpaabb;O=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}let E=$e.tmpaabb,M=d.aabb;E.minx=r.minx<M.minx?r.minx:M.minx,E.miny=r.miny<M.miny?r.miny:M.miny,E.maxx=r.maxx>M.maxx?r.maxx:M.maxx,E.maxy=r.maxy>M.maxy?r.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,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=$e.tmpaabb;N=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}if(z<O&&z<N)break;a=O<N?m:d}let p=a,c=p.parent,h;Ae.zpp_pool==null?h=new Ae:(h=Ae.zpp_pool,Ae.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=r.minx<x.minx?r.minx:x.minx,u.miny=r.miny<x.miny?r.miny:x.miny,u.maxx=r.maxx>x.maxx?r.maxx:x.maxx,u.maxy=r.maxy>x.maxy?r.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,o.root=h),a=n.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else{let _=a.child1,z=a.child2,C=z.height-_.height;if(C>1){let w=z.child1,g=z.child2;if(z.child1=a,z.parent=a.parent,a.parent=z,z.parent!=null?z.parent.child1==a?z.parent.child1=z:z.parent.child2=z:o.root=z,w.height>g.height){z.child2=w,a.child2=g,g.parent=a;let O=a.aabb,E=_.aabb,M=g.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=z.aabb,Z=a.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=g.height;a.height=1+(S>L?S:L);let T=a.height,G=w.height;z.height=1+(T>G?T:G)}else{z.child2=g,a.child2=w,w.parent=a;let O=a.aabb,E=_.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=z.aabb,Z=a.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=w.height;a.height=1+(S>L?S:L);let T=a.height,G=g.height;z.height=1+(T>G?T:G)}a=z}else if(C<-1){let w=_.child1,g=_.child2;if(_.child1=a,_.parent=a.parent,a.parent=_,_.parent!=null?_.parent.child1==a?_.parent.child1=_:_.parent.child2=_:o.root=_,w.height>g.height){_.child2=w,a.child1=g,g.parent=a;let O=a.aabb,E=z.aabb,M=g.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=_.aabb,Z=a.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=g.height;a.height=1+(S>L?S:L);let T=a.height,G=w.height;_.height=1+(T>G?T:G)}else{_.child2=g,a.child1=w,w.parent=a;let O=a.aabb,E=z.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=_.aabb,Z=a.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=w.height;a.height=1+(S>L?S:L);let T=a.height,G=g.height;_.height=1+(T>G?T:G)}a=_}else a=a}let m=a.child1,d=a.child2,y=m.height,b=d.height;a.height=1+(y>b?y:b);let f=a.aabb,P=m.aabb,k=d.aabb;f.minx=P.minx<k.minx?P.minx:k.minx,f.miny=P.miny<k.miny?P.miny:k.miny,f.maxx=P.maxx>k.maxx?P.maxx:k.maxx,f.maxy=P.maxy>k.maxy?P.maxy:k.maxy,a=a.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 l=s.shape;if(s.first_sync)s.first_sync=!1;else{let p=s.dyn?this.dtree:this.stree;if(s==p.root)p.root=null;else{let c=s.parent,h=c.parent,u=c.child1==s?c.child2:c.child1;if(h!=null){h.child1==c?h.child1=u:h.child2=u,u.parent=h;let x=c;x.height=-1;let m=x.aabb;m.outer!=null&&(m.outer.zpp_inner=null,m.outer=null),m.wrap_min=m.wrap_max=null,m._invalidate=null,m._validate=null,m.next=be.zpp_pool,be.zpp_pool=m,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ae.zpp_pool,Ae.zpp_pool=x;let d=h;for(;d!=null;){if(d.child1==null||d.height<2)d=d;else{let C=d.child1,w=d.child2,g=w.height-C.height;if(g>1){let O=w.child1,E=w.child2;if(w.child1=d,w.parent=d.parent,d.parent=w,w.parent!=null?w.parent.child1==d?w.parent.child1=w:w.parent.child2=w:p.root=w,O.height>E.height){w.child2=O,d.child2=E,E.parent=d;let M=d.aabb,N=C.aabb,Z=E.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=w.aabb,S=d.aabb,L=O.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=C.height,G=E.height;d.height=1+(T>G?T:G);let q=d.height,R=O.height;w.height=1+(q>R?q:R)}else{w.child2=E,d.child2=O,O.parent=d;let M=d.aabb,N=C.aabb,Z=O.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=w.aabb,S=d.aabb,L=E.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=C.height,G=O.height;d.height=1+(T>G?T:G);let q=d.height,R=E.height;w.height=1+(q>R?q:R)}d=w}else if(g<-1){let O=C.child1,E=C.child2;if(C.child1=d,C.parent=d.parent,d.parent=C,C.parent!=null?C.parent.child1==d?C.parent.child1=C:C.parent.child2=C:p.root=C,O.height>E.height){C.child2=O,d.child1=E,E.parent=d;let M=d.aabb,N=w.aabb,Z=E.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=C.aabb,S=d.aabb,L=O.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=w.height,G=E.height;d.height=1+(T>G?T:G);let q=d.height,R=O.height;C.height=1+(q>R?q:R)}else{C.child2=E,d.child1=O,O.parent=d;let M=d.aabb,N=w.aabb,Z=O.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=C.aabb,S=d.aabb,L=E.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=w.height,G=O.height;d.height=1+(T>G?T:G);let q=d.height,R=E.height;C.height=1+(q>R?q:R)}d=C}else d=d}let y=d.child1,b=d.child2,f=d.aabb,P=y.aabb,k=b.aabb;f.minx=P.minx<k.minx?P.minx:k.minx,f.miny=P.miny<k.miny?P.miny:k.miny,f.maxx=P.maxx>k.maxx?P.maxx:k.maxx,f.maxy=P.maxy>k.maxy?P.maxy:k.maxy;let _=y.height,z=b.height;d.height=1+(_>z?_:z),d=d.parent}}else{p.root=u,u.parent=null;let x=c;x.height=-1;let m=x.aabb;m.outer!=null&&(m.outer.zpp_inner=null,m.outer=null),m.wrap_min=m.wrap_max=null,m._invalidate=null,m._validate=null,m.next=be.zpp_pool,be.zpp_pool=m,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ae.zpp_pool,Ae.zpp_pool=x}}}let o=s.aabb;if(!t.continuous&&l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let p=l.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 m=1;x.localCOMx+=x.lverts.next.next.x*m,x.localCOMy+=x.lverts.next.next.y*m;let d=.5;x.localCOMx*=d,x.localCOMy*=d}else{x.localCOMx=0,x.localCOMy=0;let m=0,d=x.lverts.next,y=d;d=d.next;let b=d;for(d=d.next;d!=null;){let C=d;m+=b.x*(C.y-y.y);let w=C.y*b.x-C.x*b.y;x.localCOMx+=(b.x+C.x)*w,x.localCOMy+=(b.y+C.y)*w,y=b,b=C,d=d.next}d=x.lverts.next;let f=d;m+=b.x*(f.y-y.y);let P=f.y*b.x-f.x*b.y;x.localCOMx+=(b.x+f.x)*P,x.localCOMy+=(b.y+f.y)*P,y=b,b=f,d=d.next;let k=d;m+=b.x*(k.y-y.y);let _=k.y*b.x-k.x*b.y;x.localCOMx+=(b.x+k.x)*_,x.localCOMy+=(b.y+k.y)*_,m=1/(3*m);let z=m;x.localCOMx*=z,x.localCOMy*=z}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let u=p.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.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,h=p.radius;p.aabb.minx=p.worldCOMx-c,p.aabb.miny=p.worldCOMy-h,p.aabb.maxx=p.worldCOMx+c,p.aabb.maxy=p.worldCOMy+h}else{let p=l.polygon;if(p.zip_gverts&&p.body!=null){p.zip_gverts=!1,p.validate_lverts();let u=p.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let x=p.lverts.next,m=p.gverts.next;for(;m!=null;){let d=m,y=x;x=x.next,d.x=p.body.posx+(p.body.axisy*y.x-p.body.axisx*y.y),d.y=p.body.posy+(y.x*p.body.axisx+y.y*p.body.axisy),m=m.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 h=p.gverts.next.next;for(;h!=null;){let u=h;u.x<p.aabb.minx&&(p.aabb.minx=u.x),u.x>p.aabb.maxx&&(p.aabb.maxx=u.x),u.y<p.aabb.miny&&(p.aabb.miny=u.y),u.y>p.aabb.maxy&&(p.aabb.maxy=u.y),h=h.next}}let r=l.aabb;o.minx=r.minx-3,o.miny=r.miny-3,o.maxx=r.maxx+3,o.maxy=r.maxy+3;let a=(s.dyn=l.body.type==1?!1:!l.body.component.sleeping)?this.dtree:this.stree;if(a.root==null)a.root=s,a.root.parent=null;else{let p=s.aabb,c=a.root;for(;c.child1!=null;){let y=c.child1,b=c.child2,f=c.aabb,P=(f.maxx-f.minx+(f.maxy-f.miny))*2,k=$e.tmpaabb,_=c.aabb;k.minx=_.minx<p.minx?_.minx:p.minx,k.miny=_.miny<p.miny?_.miny:p.miny,k.maxx=_.maxx>p.maxx?_.maxx:p.maxx,k.maxy=_.maxy>p.maxy?_.maxy:p.maxy;let z=$e.tmpaabb,C=(z.maxx-z.minx+(z.maxy-z.miny))*2,w=2*C,g=2*(C-P),O=$e.tmpaabb,E=y.aabb;O.minx=p.minx<E.minx?p.minx:E.minx,O.miny=p.miny<E.miny?p.miny:E.miny,O.maxx=p.maxx>E.maxx?p.maxx:E.maxx,O.maxy=p.maxy>E.maxy?p.maxy:E.maxy;let M;if(y.child1==null){let S=$e.tmpaabb;M=(S.maxx-S.minx+(S.maxy-S.miny))*2+g}else{let S=y.aabb,L=(S.maxx-S.minx+(S.maxy-S.miny))*2,T=$e.tmpaabb;M=(T.maxx-T.minx+(T.maxy-T.miny))*2-L+g}let N=$e.tmpaabb,Z=b.aabb;N.minx=p.minx<Z.minx?p.minx:Z.minx,N.miny=p.miny<Z.miny?p.miny:Z.miny,N.maxx=p.maxx>Z.maxx?p.maxx:Z.maxx,N.maxy=p.maxy>Z.maxy?p.maxy:Z.maxy;let A;if(b.child1==null){let S=$e.tmpaabb;A=(S.maxx-S.minx+(S.maxy-S.miny))*2+g}else{let S=b.aabb,L=(S.maxx-S.minx+(S.maxy-S.miny))*2,T=$e.tmpaabb;A=(T.maxx-T.minx+(T.maxy-T.miny))*2-L+g}if(w<M&&w<A)break;c=M<A?y:b}let h=c,u=h.parent,x;Ae.zpp_pool==null?x=new Ae:(x=Ae.zpp_pool,Ae.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=u;let m=x.aabb,d=h.aabb;for(m.minx=p.minx<d.minx?p.minx:d.minx,m.miny=p.miny<d.miny?p.miny:d.miny,m.maxx=p.maxx>d.maxx?p.maxx:d.maxx,m.maxy=p.maxy>d.maxy?p.maxy:d.maxy,x.height=h.height+1,u!=null?(u.child1==h?u.child1=x:u.child2=x,x.child1=h,x.child2=s,h.parent=x,s.parent=x):(x.child1=h,x.child2=s,h.parent=x,s.parent=x,a.root=x),c=s.parent;c!=null;){if(c.child1==null||c.height<2)c=c;else{let C=c.child1,w=c.child2,g=w.height-C.height;if(g>1){let O=w.child1,E=w.child2;if(w.child1=c,w.parent=c.parent,c.parent=w,w.parent!=null?w.parent.child1==c?w.parent.child1=w:w.parent.child2=w:a.root=w,O.height>E.height){w.child2=O,c.child2=E,E.parent=c;let M=c.aabb,N=C.aabb,Z=E.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=w.aabb,S=c.aabb,L=O.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=C.height,G=E.height;c.height=1+(T>G?T:G);let q=c.height,R=O.height;w.height=1+(q>R?q:R)}else{w.child2=E,c.child2=O,O.parent=c;let M=c.aabb,N=C.aabb,Z=O.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=w.aabb,S=c.aabb,L=E.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=C.height,G=O.height;c.height=1+(T>G?T:G);let q=c.height,R=E.height;w.height=1+(q>R?q:R)}c=w}else if(g<-1){let O=C.child1,E=C.child2;if(C.child1=c,C.parent=c.parent,c.parent=C,C.parent!=null?C.parent.child1==c?C.parent.child1=C:C.parent.child2=C:a.root=C,O.height>E.height){C.child2=O,c.child1=E,E.parent=c;let M=c.aabb,N=w.aabb,Z=E.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=C.aabb,S=c.aabb,L=O.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=w.height,G=E.height;c.height=1+(T>G?T:G);let q=c.height,R=O.height;C.height=1+(q>R?q:R)}else{C.child2=E,c.child1=O,O.parent=c;let M=c.aabb,N=w.aabb,Z=O.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=C.aabb,S=c.aabb,L=E.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=w.height,G=O.height;c.height=1+(T>G?T:G);let q=c.height,R=E.height;C.height=1+(q>R?q:R)}c=C}else c=c}let y=c.child1,b=c.child2,f=y.height,P=b.height;c.height=1+(f>P?f:P);let k=c.aabb,_=y.aabb,z=b.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy,c=c.parent}}s.synced=!1,s=s.snext}for(;this.syncs!=null;){let l=this.syncs;this.syncs=l.snext,l.snext=null;let o=l;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 h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let d,y;r.id<x.id?(d=r.id,y=x.id):(d=x.id,y=r.id);let b=r.pairs.length<x.pairs.length?r:x,f=null,P=b.pairs.head;for(;P!=null;){let O=P.elt;if(O.id==d&&O.di==y){f=O;break}P=P.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}st.zpp_pool==null?f=new st:(f=st.zpp_pool,st.zpp_pool=f.next,f.next=null),f.n1=o,f.n2=u,f.id=d,f.di=y,this._linkPair(f),f.first=!0;let k=r.pairs,_;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?_=new we._zpp.util.ZNPNode_ZPP_AABBPair:(_=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_.next,_.next=null),_.elt=f;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++;let C=x.pairs,w;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new we._zpp.util.ZNPNode_ZPP_AABBPair:(w=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=f;let g=w;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let d,y;r.id<x.id?(d=r.id,y=x.id):(d=x.id,y=r.id);let b=r.pairs.length<x.pairs.length?r:x,f=null,P=b.pairs.head;for(;P!=null;){let O=P.elt;if(O.id==d&&O.di==y){f=O;break}P=P.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}st.zpp_pool==null?f=new st:(f=st.zpp_pool,st.zpp_pool=f.next,f.next=null),f.n1=o,f.n2=u,f.id=d,f.di=y,this._linkPair(f),f.first=!0;let k=r.pairs,_;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?_=new we._zpp.util.ZNPNode_ZPP_AABBPair:(_=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_.next,_.next=null),_.elt=f;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++;let C=x.pairs,w;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new we._zpp.util.ZNPNode_ZPP_AABBPair:(w=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=f;let g=w;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2))}}}for(;this.moves!=null;){let l=this.moves;this.moves=l.mnext,l.mnext=null;let o=l;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 h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let d,y;r.id<x.id?(d=r.id,y=x.id):(d=x.id,y=r.id);let b=r.pairs.length<x.pairs.length?r:x,f=null,P=b.pairs.head;for(;P!=null;){let O=P.elt;if(O.id==d&&O.di==y){f=O;break}P=P.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}st.zpp_pool==null?f=new st:(f=st.zpp_pool,st.zpp_pool=f.next,f.next=null),f.n1=o,f.n2=u,f.id=d,f.di=y,this._linkPair(f),f.first=!0;let k=r.pairs,_;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?_=new we._zpp.util.ZNPNode_ZPP_AABBPair:(_=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_.next,_.next=null),_.elt=f;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++;let C=x.pairs,w;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new we._zpp.util.ZNPNode_ZPP_AABBPair:(w=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=f;let g=w;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let d,y;r.id<x.id?(d=r.id,y=x.id):(d=x.id,y=r.id);let b=r.pairs.length<x.pairs.length?r:x,f=null,P=b.pairs.head;for(;P!=null;){let O=P.elt;if(O.id==d&&O.di==y){f=O;break}P=P.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}st.zpp_pool==null?f=new st:(f=st.zpp_pool,st.zpp_pool=f.next,f.next=null),f.n1=o,f.n2=u,f.id=d,f.di=y,this._linkPair(f),f.first=!0;let k=r.pairs,_;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?_=new we._zpp.util.ZNPNode_ZPP_AABBPair:(_=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_.next,_.next=null),_.elt=f;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++;let C=x.pairs,w;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new we._zpp.util.ZNPNode_ZPP_AABBPair:(w=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=f;let g=w;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2))}}}let i=this.pairs;for(;i!=null;){let l;if(i.first)l=!1;else{let u=i.n1.aabb,x=i.n2.aabb;l=!(x.miny<=u.maxy&&u.miny<=x.maxy&&x.minx<=u.maxx&&u.minx<=x.maxx)}if(l){let u=i.next;this._unlinkPair(i),i.n1.shape.pairs.remove(i),i.n2.shape.pairs.remove(i),i.arb!=null&&(i.arb.pair=null),i.arb=null,i.n1=i.n2=null,i.sleeping=!1,i.gprev=null,i.next=st.zpp_pool,st.zpp_pool=i,i=u;continue}let o=i.n1.shape,r=o.body,a=i.n2.shape,p=a.body;if(!i.first&&(r.component.sleeping||r.type==1)&&(p.component.sleeping||p.type==1)){i.sleeping=!0;let u=i.next;this._unlinkPair(i),i=u;continue}i.first=!1;let c=o.aabb,h=a.aabb;if(h.miny<=c.maxy&&c.miny<=h.maxy&&h.minx<=c.maxx&&c.minx<=h.maxx){let u=i.arb;n?i.arb=t.narrowPhase(o,a,r.type!=2||p.type!=2,i.arb,!1):i.arb=t.continuousEvent(o,a,r.type!=2||p.type!=2,i.arb,!1),i.arb==null?u!=null&&(u.pair=null):i.arb.pair=i}i=i.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,n=this.pairs;n.arb!=null&&(n.arb.pair=null),n.arb=null,n.n1.shape.pairs.remove(n),n.n2.shape.pairs.remove(n),n.n1=n.n2=null,n.sleeping=!1,n.gprev=null,n.next=st.zpp_pool,st.zpp_pool=n,this.pairs=t}this.dtree.clear(),this.stree.clear()}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l;ae.zpp_pool==null?l=new ae:(l=ae.zpp_pool,ae.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,r=i??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.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?Ce.circleContains(p.shape.circle,o)&&r.push(p.shape.outer):Ce.polyContains(p.shape.polygon,o)&&r.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 we._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(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.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?Ce.circleContains(p.shape.circle,o)&&r.push(p.shape.outer):Ce.polyContains(p.shape.polygon,o)&&r.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let a=o;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,r}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l;ae.zpp_pool==null?l=new ae:(l=ae.zpp_pool,ae.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,r=i??new we._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!r.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?Ce.circleContains(p.shape.circle,o)&&r.push(h):Ce.polyContains(p.shape.polygon,o)&&r.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 we._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(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!r.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?Ce.circleContains(p.shape.circle,o)&&r.push(h):Ce.polyContains(p.shape.polygon,o)&&r.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let a=o;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,r}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&r.push(a.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);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&&r.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h;if(i!=null){let u=a.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n)if(s)Ce.containTest(this.aabbShape.zpp_inner,a.shape)&&r.push(a.shape.outer);else{let u=a.shape.aabb;(u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy||Ce.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&r.push(a.shape.outer)}else{let u;if(s){let x=a.shape.aabb;u=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy}else u=!0;u&&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 we._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(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&r.push(a.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);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&&r.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h;if(i!=null){let u=a.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n)if(s)Ce.containTest(this.aabbShape.zpp_inner,a.shape)&&r.push(a.shape.outer);else{let u=a.shape.aabb;(u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy||Ce.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&r.push(a.shape.outer)}else{let u;if(s){let x=a.shape.aabb;u=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy}else u=!0;u&&r.push(a.shape.outer)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}return r}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new we._nape.phys.BodyList;if(this.failed==null&&(this.failed=new we._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=a.shape.body.outer;r.has(h)||r.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);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;r.has(u)||r.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let x=a.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=Ce.containTest(this.aabbShape.zpp_inner,a.shape);!r.has(h)&&x?r.push(h):x||(r.remove(h),this.failed.push(h))}}else!r.has(h)&&Ce.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&r.push(h);else if(s){if(!this.failed.has(h)){let x=a.shape.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(h)&&m?r.push(h):m||(r.remove(h),this.failed.push(h))}}else{let x;if(r.has(h))x=!1;else{let m=a.shape.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(h)}}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 we._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(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=a.shape.body.outer;r.has(h)||r.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);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;r.has(u)||r.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let x=a.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=Ce.containTest(this.aabbShape.zpp_inner,a.shape);!r.has(h)&&x?r.push(h):x||(r.remove(h),this.failed.push(h))}}else!r.has(h)&&Ce.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&r.push(h);else if(s){if(!this.failed.has(h)){let x=a.shape.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(h)&&m?r.push(h):m||(r.remove(h),this.failed.push(h))}}else{let x;if(r.has(h))x=!1;else{let m=a.shape.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(h)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}return this.failed.clear(),r}shapesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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?Ce.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):Ce.testCollide_safe(p.shape,this.circShape.zpp_inner)&&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 we._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.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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?Ce.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):Ce.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return a}bodiesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new we._nape.phys.BodyList;if(this.failed==null&&(this.failed=new we._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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=Ce.containTest(this.circShape.zpp_inner,p.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ce.testCollide_safe(p.shape,this.circShape.zpp_inner)&&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 we._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.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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=Ce.containTest(this.circShape.zpp_inner,p.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ce.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(h)}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p;if(s!=null){let c=r.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ce.containTest(t,r.shape)&&o.push(r.shape.outer):Ce.testCollide_safe(r.shape,t)&&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 we._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(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p;if(s!=null){let c=r.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ce.containTest(t,r.shape)&&o.push(r.shape.outer):Ce.testCollide_safe(r.shape,t)&&o.push(r.shape.outer))}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}return o}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new we._nape.phys.BodyList;if(this.failed==null&&(this.failed=new we._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p=r.shape.body.outer,c;if(s!=null){let h=r.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=Ce.containTest(t,r.shape);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ce.testCollide_safe(r.shape,t)&&o.push(p)}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 we._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(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p=r.shape.body.outer,c;if(s!=null){let h=r.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=Ce.containTest(t,r.shape);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ce.testCollide_safe(r.shape,t)&&o.push(p)}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}return this.failed.clear(),o}rayCast(t,n,s){this.openlist==null&&(this.openlist=new we._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 o=t.aabbsect(this.dtree.root.aabb);if(o>=0&&o<i){this.dtree.root.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(this.dtree.root.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=this.dtree.root,h;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new we._zpp.util.ZNPNode_ZPP_AABBNode:(h=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;r==null?(u.next=p.head,p.head=u):(u.next=r.next,r.next=u),p.pushmod=p.modified=!0,p.length++}}if(this.stree.root!=null&&t.aabbtest(this.stree.root.aabb)){let o=t.aabbsect(this.stree.root.aabb);if(o>=0&&o<i){this.stree.root.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(this.stree.root.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=this.stree.root,h;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new we._zpp.util.ZNPNode_ZPP_AABBNode:(h=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;r==null?(u.next=p.head,p.head=u):(u.next=r.next,r.next=u),p.pushmod=p.modified=!0,p.length++}}let l=null;for(;this.openlist.head!=null;){let o=this.openlist.pop_unsafe();if(o.rayt>=i)break;if(o.child1==null){let r=o.shape,a;if(s!=null){let p=r.filter;a=(p.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&p.collisionGroup)!=0}else a=!0;if(a){let p=r.type==0?t.circlesect(r.circle,n,i):t.aabbtest(r.aabb)?t.polysect(r.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(o.child1!=null&&t.aabbtest(o.child1.aabb)){let r=t.aabbsect(o.child1.aabb);if(r>=0&&r<i){o.child1.rayt=r;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(o.child1.rayt<m.rayt)break;a=p,p=p.next}let c=this.openlist,h=o.child1,u;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new we._zpp.util.ZNPNode_ZPP_AABBNode:(u=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;a==null?(x.next=c.head,c.head=x):(x.next=a.next,a.next=x),c.pushmod=c.modified=!0,c.length++}}if(o.child2!=null&&t.aabbtest(o.child2.aabb)){let r=t.aabbsect(o.child2.aabb);if(r>=0&&r<i){o.child2.rayt=r;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(o.child2.rayt<m.rayt)break;a=p,p=p.next}let c=this.openlist,h=o.child2,u;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new we._zpp.util.ZNPNode_ZPP_AABBNode:(u=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;a==null?(x.next=c.head,c.head=x):(x.next=a.next,a.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 we._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let l=t.maxdist>=1/0,o=i??new we._nape.geom.RayResultList;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb))if(l)this.openlist.add(this.dtree.root);else{let r=t.aabbsect(this.dtree.root.aabb);r>=0&&r<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 r=t.aabbsect(this.stree.root.aabb);r>=0&&r<t.maxdist&&this.openlist.add(this.stree.root)}for(;this.openlist.head!=null;){let r=this.openlist.pop_unsafe();if(r.child1==null){let a=r.shape,p;if(s!=null){let c=a.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(a.type==0?t.circlesect2(a.circle,n,o):t.aabbtest(a.aabb)&&t.polysect2(a.polygon,n,o))}else{if(r.child1!=null&&t.aabbtest(r.child1.aabb))if(l)this.openlist.add(r.child1);else{let a=t.aabbsect(r.child1.aabb);a>=0&&a<t.maxdist&&this.openlist.add(r.child1)}if(r.child2!=null&&t.aabbtest(r.child2.aabb))if(l)this.openlist.add(r.child2);else{let a=t.aabbsect(r.child2.aabb);a>=0&&a<t.maxdist&&this.openlist.add(r.child2)}}}return this.openlist.clear(),o}};we._zpp=null,we._nape=null,we.FATTEN=3,we.VEL_STEPS=2;var Ms=we;var Ks=class Ks{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 Ks._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}};Ks.zpp_pool=null,Ks._zpp=null;var xt=Ks;var Ys=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}};Ys.zpp_pool=null;var Ln=class Ln{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 Ln._zpp.util.ZNPList_ZPP_Arbiter}static get(e,t){let n;return Ln.zpp_pool==null?n=new Ln:(n=Ln.zpp_pool,Ln.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=Ln._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 o=i;return o.next=s.head,s.head=o,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,o;n==null?(l=t.head,o=l.next,t.head=o,t.head==null&&(t.pushmod=!0)):(l=n.next,o=l.next,n.next=o,o==null&&(t.pushmod=!0));let r=l;r.elt=null;let a=Ln._zpp.util.ZNPNode_ZPP_Arbiter;r.next=a.zpp_pool,a.zpp_pool=r,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 o=i;o.elt=null;let r=Ln._zpp.util.ZNPNode_ZPP_Arbiter;o.next=r.zpp_pool,r.zpp_pool=o,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}};Ln.zpp_pool=null,Ln._zpp=null;var Kt=Ln;var ci=class ci{constructor(e){this.cbsets=null;this.space=null;let t=ci._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=ci._zpp.callbacks.ZPP_CbSet.setlt,this.space=e}get(e){if(e.head==null)return null;let t=ci._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 r=t.get(e);this.cbsets.insert(r),r.manager=this,l=r}n.cbTypes=s;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,l}remove(e){let t=ci._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=ci._zpp.callbacks.ZPP_CbSet,s=ci._zpp.callbacks.ZPP_CbSetPair,i=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){i=r;break}o=o.next}if(i==null){let r;s.zpp_pool==null?r=new s:(r=s.zpp_pool,s.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),i=r,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}};ci._zpp=null;var Hi=ci;var B=class B{constructor(e,t){this.outer=null;this.userData=null;this.gravityx=0;this.gravityy=0;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=0;this.global_ang_drag=0;this.stamp=0;this.midstep=!1;this.time=0;this.sortcontacts=!1;this.deterministic=!1;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=0;this.toiEvents=null;this.continuous=!1;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.deterministic=!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,Tt.internal=!0,this.precb=Tt._createPreCb(),this.precb.zpp_inner=new Tt,Tt.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_SPATIAL_HASH==null&&(H.internal=!0,H.Broadphase_SPATIAL_HASH=new B._nape.space.Broadphase,H.internal=!1),t==H.Broadphase_SPATIAL_HASH?this.bphase=new B._zpp.space.ZPP_SpatialHashPhase(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 xt,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=Mn.__static(),this.__static.zpp_inner.space=this,this.callbacks=new Tt,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 Kt,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 Hi(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;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.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 o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y==t}else i=!1;if(!i){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=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 a=l.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)),l=l.next}let o=i.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=Kt.zpp_pool,Kt.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,o=!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,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,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 s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;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=ut.zpp_pool,ut.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,o=!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,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,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 s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;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=ut.zpp_pool,ut.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,o=!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,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,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=Ot.zpp_pool,Ot.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,o=!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,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,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=Pt.zpp_pool,Pt.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=xt.zpp_pool,xt.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=xt.zpp_pool,xt.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 o=l.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=xt.zpp_pool,xt.zpp_pool=r}}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 o=l.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=xt.zpp_pool,xt.zpp_pool=r}}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 o=l;o.next=i.head,i.head=o,i.modified=!0,i.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,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,o=null,r=l.head,a=!1;for(;r!=null;){if(r.elt==e){let p,c;o==null?(p=l.head,c=p.next,l.head=c,l.head==null&&(l.pushmod=!0)):(p=o.next,c=p.next,o.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,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 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 r=this.mrca1.head;for(;r!=null;){let a=r.elt,p=this.mrca2.head;for(;p!=null;){let c=p.elt,h=a.cbSet,u=c.cbSet;h.validate(),u.validate();let x=h.manager,m=null,y=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;y!=null;){let C=y.elt;if(C.a==h&&C.b==u||C.a==u&&C.b==h){m=C;break}y=y.next}if(m==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,_t.setlt(h,u)?(C.a=h,C.b=u):(C.a=u,C.b=h),m=C,h.cbpairs.add(m),u!=h&&u.cbpairs.add(m)}if(m.zip_listeners&&(m.zip_listeners=!1,m.__validate()),m.listeners.head==null){p=p.next;continue}let b=B._zpp.phys.ZPP_Interactor.get(a,c);b.remove_arb(l),l.present--;let f=h.manager,P=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){P=C;break}_=_.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,_t.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 z=P.listeners.head;for(;z!=null;){let C=z.elt;if(C.event==1&&(C.itype&l.type)!=0&&b.empty_arb(C.itype)){let w=this.push_callback(C);w.event=1;let g=b.int1,O=b.int2,E,M=C.options1,N=g.cbTypes;if(M.nonemptyintersection(N,M.includes)&&!M.nonemptyintersection(N,M.excludes)){let Z=C.options2,A=O.cbTypes;E=Z.nonemptyintersection(A,Z.includes)&&!Z.nonemptyintersection(A,Z.excludes)}else E=!1;E?(w.int1=g,w.int2=O):(w.int1=O,w.int2=g),w.set=b}z=z.next}b.arbiters.head==null&&this.remove_callbackset(b),p=p.next}r=r.next}}if(l.b1!=n&&l.b1.type==2){let r=l.b1;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))}if(l.b2!=n&&l.b2.type==2){let r=l.b2;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))}if(l.cleared=!0,n==null||l.b2==n){let r=l.b1.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}}if(n==null||l.b1==n){let r=l.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=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 o=i.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(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 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(),l.shapesInCircle(r,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 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(),l.bodiesInCircle(r,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 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 T=S.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 V=q;G+=j.x*(V.y-R.y);let K=V.y*j.x-V.x*j.y;T.localCOMx+=(j.x+V.x)*K,T.localCOMy+=(j.y+V.y)*K,R=j,j=V,q=q.next;let $=q;G+=j.x*($.y-R.y);let Y=$.y*j.x-$.x*j.y;T.localCOMx+=(j.x+$.x)*Y,T.localCOMy+=(j.y+$.y)*Y,G=1/(3*G);let X=G;T.localCOMx*=X,T.localCOMy*=X}}S.wrap_localCOM!=null&&(S.wrap_localCOM.zpp_inner.x=S.localCOMx,S.wrap_localCOM.zpp_inner.y=S.localCOMy)}let L=S.body;L.zip_axis&&(L.zip_axis=!1,L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.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)}}else if(e.type===2){let S=e.capsule;if(S.zip_worldCOM&&S.body!=null){S.zip_worldCOM=!1,S.zip_localCOM&&(S.zip_localCOM=!1,S.wrap_localCOM!=null&&(S.wrap_localCOM.zpp_inner.x=S.localCOMx,S.wrap_localCOM.zpp_inner.y=S.localCOMy));let L=S.body;L.zip_axis&&(L.zip_axis=!1,L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.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)}}else{let S=e.polygon;if(S.zip_gaxi&&S.body!=null){S.zip_gaxi=!1,S.validate_laxi();let L=S.body;if(L.zip_axis&&(L.zip_axis=!1,L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.rot)),S.zip_gverts&&S.body!=null){S.zip_gverts=!1,S.validate_lverts();let V=S.body;V.zip_axis&&(V.zip_axis=!1,V.axisx=Math.sin(V.rot),V.axisy=Math.cos(V.rot));let K=S.lverts.next,$=S.gverts.next;for(;$!=null;){let Y=$,X=K;K=K.next,Y.x=S.body.posx+(S.body.axisy*X.x-S.body.axisx*X.y),Y.y=S.body.posy+(X.x*S.body.axisx+X.y*S.body.axisy),$=$.next}}let T=S.edges.head,G=S.gverts.next,q=G;for(G=G.next;G!=null;){let V=G,K=T.elt;T=T.next,K.gp0=q,K.gp1=V,K.gnormx=S.body.axisy*K.lnormx-S.body.axisx*K.lnormy,K.gnormy=K.lnormx*S.body.axisx+K.lnormy*S.body.axisy,K.gprojection=S.body.posx*K.gnormx+S.body.posy*K.gnormy+K.lprojection,K.wrap_gnorm!=null&&(K.wrap_gnorm.zpp_inner.x=K.gnormx,K.wrap_gnorm.zpp_inner.y=K.gnormy),K.tp0=K.gp0.y*K.gnormx-K.gp0.x*K.gnormy,K.tp1=K.gp1.y*K.gnormx-K.gp1.x*K.gnormy,q=V,G=G.next}let R=S.gverts.next,j=T.elt;T=T.next,j.gp0=q,j.gp1=R,j.gnormx=S.body.axisy*j.lnormx-S.body.axisx*j.lnormy,j.gnormy=j.lnormx*S.body.axisx+j.lnormy*S.body.axisy,j.gprojection=S.body.posx*j.gnormx+S.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,o=l.posx,r=l.posy;l.sweepTime=0,l.sweep_angvel=l.angvel;let a=t-l.sweepTime;if(a!=0){l.sweepTime=t;let S=a;if(l.posx+=l.velx*S,l.posy+=l.vely*S,l.angvel!=0){let L=l.sweep_angvel*a;if(l.rot+=L,L*L>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let T=L*L,G=1-.5*T,q=1-T*T/8,R=(G*l.axisx+L*l.axisy)*q;l.axisy=(G*l.axisy-L*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=o,m=p;u.minx=(x<m?x:m)-h;let d=o,y=p;u.maxx=(d>y?d:y)+h;let b=r,f=c;u.miny=(b<f?b:f)-h;let P=r,k=c;u.maxy=(P>k?P:k)+h;let _=this.convexShapeList=this.bphase.shapesInAABB(u,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),z=u;z.outer!=null&&(z.outer.zpp_inner=null,z.outer=null),z.wrap_min=z.wrap_max=null,z._invalidate=null,z._validate=null,z.next=be.zpp_pool,be.zpp_pool=z;let C=0,w=0;C=0,w=0;let g=0,O=0;g=0,O=0;let E=null,M=t+1;_.zpp_inner.valmod();let N=B._nape.shape.ShapeIterator.get(_);for(;;){N.zpp_inner.zpp_inner.valmod();let S=N.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 L=S.zpp_inner.user_length;N.zpp_critical=!0;let T;if(N.zpp_i<L?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,Cn.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 K=R;if(q.posx+=q.velx*K,q.posy+=q.vely*K,q.angvel!=0){let $=q.sweep_angvel*R;if(q.rot+=$,$*$>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else{let Y=$*$,X=1-.5*Y,ee=1-Y*Y/8,J=(X*q.axisx+$*q.axisy)*ee;q.axisy=(X*q.axisy-$*q.axisx)*ee,q.axisx=J}}}let j=(G.zpp_inner.body!=null?G.zpp_inner.body.outer:null).zpp_inner,V=G.zpp_inner;if(V.type==0||V.type===2)V.worldCOMx=j.posx+(j.axisy*V.localCOMx-j.axisx*V.localCOMy),V.worldCOMy=j.posy+(V.localCOMx*j.axisx+V.localCOMy*j.axisy);else{let K=V.polygon,$=K.lverts.next,Y=K.gverts.next;for(;Y!=null;){let I=Y,U=$;$=$.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=K.edges.head,ee=K.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 F=K.gverts.next,D=X.elt;X=X.next,D.gnormx=j.axisy*D.lnormx-j.axisx*D.lnormy,D.gnormy=D.lnormx*j.axisx+D.lnormy*j.axisy,D.gprojection=j.posx*D.gnormx+j.posy*D.gnormy+D.lprojection,D.tp0=J.y*D.gnormx-J.x*D.gnormy,D.tp1=F.y*D.gnormx-F.x*D.gnormy}}else Cn.staticSweep(i,t,0,0);i.toi*=t,i.toi>0&&i.toi<M&&(M=i.toi,C=i.axis.x,w=i.axis.y,g=i.c2.x,O=i.c2.y,E=G)}}_.clear();let Z=i;Z.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=Z;let A=0-l.sweepTime;if(A!=0){l.sweepTime=0;let S=A;if(l.posx+=l.velx*S,l.posy+=l.vely*S,l.angvel!=0){let L=l.sweep_angvel*A;if(l.rot+=L,L*L>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let T=L*L,G=1-.5*T,q=1-T*T/8,R=(G*l.axisx+L*l.axisy)*q;l.axisy=(G*l.axisy-L*l.axisx)*q,l.axisx=R}}}if(e.type==0||e.type===2)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 S=e.polygon,L=S.lverts.next,T=S.gverts.next;for(;T!=null;){let K=T,$=L;L=L.next,K.x=l.posx+(l.axisy*$.x-l.axisx*$.y),K.y=l.posy+($.x*l.axisx+$.y*l.axisy),T=T.next}let G=S.edges.head,q=S.gverts.next,R=q;for(q=q.next;q!=null;){let K=q,$=G.elt;G=G.next,$.gnormx=l.axisy*$.lnormx-l.axisx*$.lnormy,$.gnormy=$.lnormx*l.axisx+$.lnormy*l.axisy,$.gprojection=l.posx*$.gnormx+l.posy*$.gnormy+$.lprojection,$.tp0=R.y*$.gnormx-R.x*$.gnormy,$.tp1=K.y*$.gnormx-K.x*$.gnormy,R=K,q=q.next}let j=S.gverts.next,V=G.elt;G=G.next,V.gnormx=l.axisy*V.lnormx-l.axisx*V.lnormy,V.gnormy=V.lnormx*l.axisx+V.lnormy*l.axisy,V.gprojection=l.posx*V.gnormx+l.posy*V.gnormy+V.lprojection,V.tp0=R.y*V.gnormx-R.x*V.gnormy,V.tp1=j.y*V.gnormx-j.x*V.gnormy}if(M<=t){let S=-C,L=-w;if(L==null&&(L=0),S==null&&(S=0),S!=S||L!=L)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;ae.zpp_pool==null?j=new ae:(j=ae.zpp_pool,ae.zpp_pool=j.next,j.next=null),j.weak=!1,j._immutable=!1,j.x=S,j.y=L,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(),S!=S||L!=L)throw new Error("Error: Vec2 components cannot be NaN");let V;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let K=T.zpp_inner;if(K._validate!=null&&K._validate(),T.zpp_inner.x==S){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let $=T.zpp_inner;$._validate!=null&&$._validate(),V=T.zpp_inner.y==L}else V=!1;if(!V){T.zpp_inner.x=S,T.zpp_inner.y=L;let $=T.zpp_inner;$._invalidate!=null&&$._invalidate($)}}T.zpp_inner.weak=!1;let G=g,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;ae.zpp_pool==null?j=new ae:(j=ae.zpp_pool,ae.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 V;if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let K=R.zpp_inner;if(K._validate!=null&&K._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 $=R.zpp_inner;$._validate!=null&&$._validate(),V=R.zpp_inner.y==q}else V=!1;if(!V){R.zpp_inner.x=G,R.zpp_inner.y=q;let $=R.zpp_inner;$._invalidate!=null&&$._invalidate($)}}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,o=l;l=l.next;let r=l;for(l=l.next;l!=null;){let x=l;i+=r.x*(x.y-o.y);let m=x.y*r.x-x.x*r.y;s.localCOMx+=(r.x+x.x)*m,s.localCOMy+=(r.y+x.y)*m,o=r,r=x,l=l.next}l=s.lverts.next;let a=l;i+=r.x*(a.y-o.y);let p=a.y*r.x-a.x*r.y;s.localCOMx+=(r.x+a.x)*p,s.localCOMy+=(r.y+a.y)*p,o=r,r=a,l=l.next;let c=l;i+=r.x*(c.y-o.y);let h=c.y*r.x-c.x*r.y;s.localCOMx+=(r.x+c.x)*h,s.localCOMy+=(r.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 if(e.type===2){let t=e.capsule;if(t.zip_worldCOM&&t.body!=null){t.zip_worldCOM=!1,t.zip_localCOM&&(t.zip_localCOM=!1,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 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 a=i,p=s.elt;s=s.next,p.gp0=l,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,l=a,i=i.next}let o=t.gverts.next,r=s.elt;s=s.next,r.gp0=l,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,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 A=1;Z.localCOMx+=Z.lverts.next.next.x*A,Z.localCOMy+=Z.lverts.next.next.y*A;let S=.5;Z.localCOMx*=S,Z.localCOMy*=S}else{Z.localCOMx=0,Z.localCOMy=0;let A=0,S=Z.lverts.next,L=S;S=S.next;let T=S;for(S=S.next;S!=null;){let K=S;A+=T.x*(K.y-L.y);let $=K.y*T.x-K.x*T.y;Z.localCOMx+=(T.x+K.x)*$,Z.localCOMy+=(T.y+K.y)*$,L=T,T=K,S=S.next}S=Z.lverts.next;let G=S;A+=T.x*(G.y-L.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,L=T,T=G,S=S.next;let R=S;A+=T.x*(R.y-L.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,A=1/(3*A);let V=A;Z.localCOMx*=V,Z.localCOMy*=V}}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 if(e.type===2){let M=e.capsule;if(M.zip_worldCOM&&M.body!=null){M.zip_worldCOM=!1,M.zip_localCOM&&(M.zip_localCOM=!1,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,V=q;q=q.next,j.x=M.body.posx+(M.body.axisy*V.x-M.body.axisx*V.y),j.y=M.body.posy+(V.x*M.body.axisx+V.y*M.body.axisy),R=R.next}}let Z=M.edges.head,A=M.gverts.next,S=A;for(A=A.next;A!=null;){let G=A,q=Z.elt;Z=Z.next,q.gp0=S,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,S=G,A=A.next}let L=M.gverts.next,T=Z.elt;Z=Z.next,T.gp0=S,T.gp1=L,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 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 M=p;if(o.posx+=o.velx*M,o.posy+=o.vely*M,o.angvel!=0){let N=o.sweep_angvel*p;if(o.rot+=N,N*N>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let Z=N*N,A=1-.5*Z,S=1-Z*Z/8,L=(A*o.axisx+N*o.axisy)*S;o.axisy=(A*o.axisy-N*o.axisx)*S,o.axisx=L}}}let c=o.posx,h=o.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 m=r,d=c;x.minx=(m<d?m:d)-u;let y=r,b=c;x.maxx=(y>b?y:b)+u;let f=a,P=h;x.miny=(f<P?f:P)-u;let k=a,_=h;x.maxy=(k>_?k:_)+u;let z=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 w=i??new B._nape.geom.ConvexResultList;z.zpp_inner.valmod();let g=B._nape.shape.ShapeIterator.get(z);for(;;){g.zpp_inner.zpp_inner.valmod();let M=g.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;g.zpp_critical=!0;let Z;if(g.zpp_i<N?Z=!0:(g.zpp_next=B._nape.shape.ShapeIterator.zpp_pool,B._nape.shape.ShapeIterator.zpp_pool=g,g.zpp_inner=null,Z=!1),!Z)break;g.zpp_critical=!1;let A=g.zpp_inner.at(g.zpp_i++);if(A!=e.outer&&(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null)!=o.outer){if(l.s1=e,l.s2=A.zpp_inner,s){A.zpp_inner.validate_sweepRadius(),(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner.angvel,(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,Cn.dynamicSweep(l,t,0,0,!0);let S=(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner,L=0-S.sweepTime;if(L!=0){S.sweepTime=0;let q=L;if(S.posx+=S.velx*q,S.posy+=S.vely*q,S.angvel!=0){let R=S.sweep_angvel*L;if(S.rot+=R,R*R>1e-4)S.axisx=Math.sin(S.rot),S.axisy=Math.cos(S.rot);else{let j=R*R,V=1-.5*j,K=1-j*j/8,$=(V*S.axisx+R*S.axisy)*K;S.axisy=(V*S.axisy-R*S.axisx)*K,S.axisx=$}}}let T=(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner,G=A.zpp_inner;if(G.type==0||G.type===2)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 V=q.edges.head,K=q.gverts.next,$=K;for(K=K.next;K!=null;){let ee=K,J=V.elt;V=V.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=$.y*J.gnormx-$.x*J.gnormy,J.tp1=ee.y*J.gnormx-ee.x*J.gnormy,$=ee,K=K.next}let Y=q.gverts.next,X=V.elt;V=V.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=$.y*X.gnormx-$.x*X.gnormy,X.tp1=Y.y*X.gnormx-Y.x*X.gnormy}}else Cn.staticSweep(l,t,0,0);if(l.toi*=t,l.toi>0){let S=-l.axis.x,L=-l.axis.y;if(L==null&&(L=0),S==null&&(S=0),S!=S||L!=L)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;ae.zpp_pool==null?ee=new ae:(ee=ae.zpp_pool,ae.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=S,ee.y=L,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(),S!=S||L!=L)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 F=T.zpp_inner;if(F._validate!=null&&F._validate(),T.zpp_inner.x==S){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=T.zpp_inner;D._validate!=null&&D._validate(),J=T.zpp_inner.y==L}else J=!1;if(!J){T.zpp_inner.x=S,T.zpp_inner.y=L;let D=T.zpp_inner;D._invalidate!=null&&D._invalidate(D)}}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;ae.zpp_pool==null?ee=new ae:(ee=ae.zpp_pool,ae.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 F=R.zpp_inner;if(F._validate!=null&&F._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 D=R.zpp_inner;D._validate!=null&&D._validate(),J=R.zpp_inner.y==q}else J=!1;if(!J){R.zpp_inner.x=G,R.zpp_inner.y=q;let D=R.zpp_inner;D._invalidate!=null&&D._invalidate(D)}}R.zpp_inner.weak=!1;let j=B._zpp.geom.ZPP_ConvexRayResult.getConvex(T,R,l.toi,A),V=null,K=w.zpp_inner.inner.head;for(;K!=null;){let ee=K.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;V=K,K=K.next}let $=w.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;V==null?(X.next=$.head,$.head=X):(X.next=V.next,V.next=X),$.pushmod=$.modified=!0,$.length++}}}z.clear();let O=l;O.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=O;let E=0-o.sweepTime;if(E!=0){o.sweepTime=0;let M=E;if(o.posx+=o.velx*M,o.posy+=o.vely*M,o.angvel!=0){let N=o.sweep_angvel*E;if(o.rot+=N,N*N>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let Z=N*N,A=1-.5*Z,S=1-Z*Z/8,L=(A*o.axisx+N*o.axisy)*S;o.axisy=(A*o.axisy-N*o.axisx)*S,o.axisx=L}}}if(e.type==0||e.type===2)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 M=e.polygon,N=M.lverts.next,Z=M.gverts.next;for(;Z!=null;){let q=Z,R=N;N=N.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),Z=Z.next}let A=M.edges.head,S=M.gverts.next,L=S;for(S=S.next;S!=null;){let q=S,R=A.elt;A=A.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=L.y*R.gnormx-L.x*R.gnormy,R.tp1=q.y*R.gnormx-q.x*R.gnormy,L=q,S=S.next}let T=M.gverts.next,G=A.elt;A=A.next,G.gnormx=o.axisy*G.lnormx-o.axisx*G.lnormy,G.gnormy=G.lnormx*o.axisx+G.lnormy*o.axisy,G.gprojection=o.posx*G.gnormx+o.posy*G.gnormy+G.lprojection,G.tp0=L.y*G.gnormx-L.x*G.gnormy,G.tp1=T.y*G.gnormx-T.x*G.gnormy}return w}push_callback(e){let t;return Tt.zpp_pool==null?t=new Tt:(t=Tt.zpp_pool,Tt.zpp_pool=t.next,t.next=null),this.callbacks.push(t),t.listener=e,t}_invalidateBodyList(e){let t=e.head;for(;t!=null;){let n=t.elt,s=!(n.posx==n.pre_posx&&n.posy==n.pre_posy),i=n.pre_rot!=n.rot;if(s||i){i&&(n.zip_axis=!0);let l=n.shapes.head;for(;l!=null;){let o=l.elt;o.type==1&&(o.polygon.invalidate_gverts(),o.polygon.invalidate_gaxi()),o.invalidate_worldCOM(),l=l.next}n.zip_worldCOM=!0}t=t.next}}_sortLinkedList(e,t){if(e.head==null||e.head.next==null)return;let n=e.head,s=1;for(;;){let i=0,l=n;n=null;let o=null;for(;l!=null;){i++;let r=l,a=0,p=s;for(;r!=null&&a<s;)a++,r=r.next;for(;a>0||p>0&&r!=null;){let c;a==0?(c=r,r=r.next,p--):p==0||r==null||t(l.elt)<=t(r.elt)?(c=l,l=l.next,a--):(c=r,r=r.next,p--),o!=null?o.next=c:n=c,o=c}l=r}if(o.next=null,s<<=1,i<=1)break}e.head=n,e.modified=!0,e.pushmod=!0}_arbiterSortKey(e){let t=e.s1!=null?e.s1.id:0,n=e.s2!=null?e.s2.id:0,s=t<n?t:n,i=t<n?n:t;return s*1e6+i}_ensureDeterministicOrder(){this.deterministic&&(this._sortLinkedList(this.live,e=>e.id),this._sortLinkedList(this.live_constraints,e=>e.id),this._sortLinkedList(this.c_arbiters_false,e=>this._arbiterSortKey(e)),this._sortLinkedList(this.c_arbiters_true,e=>this._arbiterSortKey(e)),this._sortLinkedList(this.f_arbiters,e=>this._arbiterSortKey(e)))}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!!");this.time+=e,this.pre_dt=e,this.midstep=!0,this.stamp++;try{if(this.validation(),this.bphase.broadphase(this,!0),this._ensureDeterministicOrder(),this.prestep(e),this.sortcontacts){let p=this.c_arbiters_false;if(p.head!=null&&p.head.next!=null){let c=p.head,h=null,u=null,x=null,m=null,d=1,y,b,f;for(;;){for(y=0,u=c,c=null,h=c;u!=null;){for(++y,x=u,b=0,f=d;x!=null&&b<d;)++b,x=x.next;for(;b>0||f>0&&x!=null;)b==0?(m=x,x=x.next,--f):f==0||x==null||(u.elt.active&&x.elt.active?u.elt.oc1.dist<x.elt.oc1.dist:!this.deterministic||this._arbiterSortKey(u.elt)<=this._arbiterSortKey(x.elt))?(m=u,u=u.next,--b):(m=x,x=x.next,--f),h!=null?h.next=m:c=m,h=m;u=x}if(h.next=null,d<<=1,!(y>1))break}p.head=c,p.modified=!0,p.pushmod=!0}}this.updateVel(e),this.warmStart(),this.iterateVel(t);let l=this.kinematics.head;for(;l!=null;){let p=l.elt;p.pre_posx=p.posx,p.pre_posy=p.posy,p.pre_rot=p.rot,l=l.next}let o=this.live.head;for(;o!=null;){let p=o.elt;p.pre_posx=p.posx,p.pre_posy=p.posy,p.pre_rot=p.rot,o=o.next}this.updatePos(e),this.continuous=!0,this.continuousCollisions(e),this.continuous=!1,this.iteratePos(n),this._invalidateBodyList(this.kinematics),this._invalidateBodyList(this.live);let r=null,a=this.staticsleep.head;for(;a!=null;){let p=a.elt;if(p.type!=3||p.velx==0&&p.vely==0&&p.angvel==0){if(p.kinematicDelaySleep){p.kinematicDelaySleep=!1,a=a.next;continue}p.component.sleeping=!0;let c=this.staticsleep,h,u;r==null?(h=c.head,u=h.next,c.head=u,c.head==null&&(c.pushmod=!0)):(h=r.next,u=h.next,r.next=u,u==null&&(c.pushmod=!0));let x=h;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_Body.zpp_pool,B._zpp.util.ZNPNode_ZPP_Body.zpp_pool=x,c.modified=!0,c.length--,c.pushmod=!0,a=u;continue}r=a,a=a.next}this.doForests(e),this.sleepArbiters()}finally{this.midstep=!1}let s=null,i=this.callbackset_list.next;for(;i!=null;){let l=i;if(l.arbiters.head==null){let y=this.callbackset_list,b,f;s==null?(b=y.next,f=b.next,y.next=f,y.next==null&&(y.pushmod=!0)):(b=s.next,f=b.next,s.next=f,f==null&&(y.pushmod=!0)),b._inuse=!1,y.modified=!0,y.length--,y.pushmod=!0,i=f;let P=l;P.int1=P.int2=null,P.id=P.di=-1,P.freed=!0,P.next=Kt.zpp_pool,Kt.zpp_pool=P;continue}let o;o=!0;let r=l.arbiters.head;for(;r!=null;)if(r.elt.sleeping){r=r.next;continue}else{o=!1;break}let a=o,p=l.int1.cbSet,c=l.int2.cbSet,h=p.manager,u=null,m=(p.cbpairs.length<c.cbpairs.length?p.cbpairs:c.cbpairs).head;for(;m!=null;){let y=m.elt;if(y.a==p&&y.b==c||y.a==c&&y.b==p){u=y;break}m=m.next}if(u==null){let y;Ne.zpp_pool==null?y=new Ne:(y=Ne.zpp_pool,Ne.zpp_pool=y.next,y.next=null),y.zip_listeners=!0,_t.setlt(p,c)?(y.a=p,y.b=c):(y.a=c,y.b=p),u=y,p.cbpairs.add(u),c!=p&&c.cbpairs.add(u)}u.zip_listeners&&(u.zip_listeners=!1,u.__validate());let d=u.listeners.head;for(;d!=null;){let y=d.elt;if(y.event==6&&(!a||y.allowSleepingCallbacks)&&!l.empty_arb(y.itype)){let b=this.push_callback(y);b.event=6;let f=l.int1,P=l.int2,k,_=y.options1,z=f.cbTypes;if(_.nonemptyintersection(z,_.includes)&&!_.nonemptyintersection(z,_.excludes)){let C=y.options2,w=P.cbTypes;k=C.nonemptyintersection(w,C.includes)&&!C.nonemptyintersection(w,C.excludes)}else k=!1;k?(b.int1=f,b.int2=P):(b.int1=P,b.int2=f),b.set=l}d=d.next}s=i,i=i.next}for(;!this.callbacks.empty();){let l=this.callbacks.pop();l.listener.type==0?l.listener.body.handler(l.wrapper_body()):l.listener.type==1?l.listener.constraint.handler(l.wrapper_con()):l.listener.type==2&&l.listener.interaction.handleri(l.wrapper_int());let o=l;o.int1=o.int2=null,o.body=null,o.constraint=null,o.listener=null,o.wrap_arbiters!=null&&(o.wrap_arbiters.zpp_inner.inner=null),o.set=null,o.next=Tt.zpp_pool,Tt.zpp_pool=o}}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,o=2,r=!1,a=null,p=null,c=this.toiEvents.head;for(;c!=null;){let y=c.elt,b=y.s1.body,f=y.s2.body;if(b.sweepFrozen&&f.sweepFrozen)if(y.toi!=0&&Ce.testCollide_safe(y.s1,y.s2))y.toi=0;else{c=this.toiEvents.erase(p);let P=y;P.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}if(y.frozen1!=b.sweepFrozen||y.frozen2!=f.sweepFrozen)if(y.kinematic){c=this.toiEvents.erase(p);let P=y;P.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}else{if(y.frozen1=b.sweepFrozen,y.frozen2=f.sweepFrozen,y.frozen1){let P=y.s1;y.s1=y.s2,y.s2=P,y.frozen1=!1,y.frozen2=!0}if(Cn.staticSweep(y,e,0,B._nape.Config.collisionSlopCCD),y.toi<0){c=this.toiEvents.erase(p);let P=y;P.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}}y.toi>=0&&(y.toi<o||!r&&y.kinematic)&&(l=y,o=y.toi,r=y.kinematic,a=p),p=c,c=c.next}if(l==null)break;this.toiEvents.erase(a),n=l.toi;let h=l.s1.body,u=l.s2.body;if(!h.sweepFrozen){let y=n*e,b=y-h.sweepTime;if(b!=0){h.sweepTime=y;let P=b;if(h.posx+=h.velx*P,h.posy+=h.vely*P,h.angvel!=0){let k=h.sweep_angvel*b;if(h.rot+=k,k*k>1e-4)h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot);else{let _=k*k,z=1-.5*_,C=1-_*_/8,w=(z*h.axisx+k*h.axisy)*C;h.axisy=(z*h.axisy-k*h.axisx)*C,h.axisx=w}}}let f=l.s1;if(f.type==0||f.type===2)f.worldCOMx=h.posx+(h.axisy*f.localCOMx-h.axisx*f.localCOMy),f.worldCOMy=h.posy+(f.localCOMx*h.axisx+f.localCOMy*h.axisy);else{let P=f.polygon,k=P.lverts.next,_=P.gverts.next;for(;_!=null;){let E=_,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),_=_.next}let z=P.edges.head,C=P.gverts.next,w=C;for(C=C.next;C!=null;){let E=C,M=z.elt;z=z.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=w.y*M.gnormx-w.x*M.gnormy,M.tp1=E.y*M.gnormx-E.x*M.gnormy,w=E,C=C.next}let g=P.gverts.next,O=z.elt;z=z.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=w.y*O.gnormx-w.x*O.gnormy,O.tp1=g.y*O.gnormx-g.x*O.gnormy}}if(!u.sweepFrozen){let y=n*e,b=y-u.sweepTime;if(b!=0){u.sweepTime=y;let P=b;if(u.posx+=u.velx*P,u.posy+=u.vely*P,u.angvel!=0){let k=u.sweep_angvel*b;if(u.rot+=k,k*k>1e-4)u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot);else{let _=k*k,z=1-.5*_,C=1-_*_/8,w=(z*u.axisx+k*u.axisy)*C;u.axisy=(z*u.axisy-k*u.axisx)*C,u.axisx=w}}}let f=l.s2;if(f.type==0||f.type===2)f.worldCOMx=u.posx+(u.axisy*f.localCOMx-u.axisx*f.localCOMy),f.worldCOMy=u.posy+(f.localCOMx*u.axisx+f.localCOMy*u.axisy);else{let P=f.polygon,k=P.lverts.next,_=P.gverts.next;for(;_!=null;){let E=_,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),_=_.next}let z=P.edges.head,C=P.gverts.next,w=C;for(C=C.next;C!=null;){let E=C,M=z.elt;z=z.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=w.y*M.gnormx-w.x*M.gnormy,M.tp1=E.y*M.gnormx-E.x*M.gnormy,w=E,C=C.next}let g=P.gverts.next,O=z.elt;z=z.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=w.y*O.gnormx-w.x*O.gnormy,O.tp1=g.y*O.gnormx-g.x*O.gnormy}}let x=l.arbiter==null,m=this.narrowPhase(l.s1,l.s2,!0,l.arbiter,!0);if(m==null)l.arbiter!=null&&l.arbiter.pair!=null&&(l.arbiter.pair.arb=null,l.arbiter.pair=null);else if(!this.presteparb(m,e,!0)&&m.type==Ie.COL&&m.active&&(m.immState&1)!=0){let y=m.colarb,b=y.nx*y.c1.jnAcc-y.ny*y.c1.jtAcc,f=y.ny*y.c1.jnAcc+y.nx*y.c1.jtAcc,P=y.b1.imass;y.b1.velx-=b*P,y.b1.vely-=f*P,y.b1.angvel-=y.b1.iinertia*(f*y.c1.r1x-b*y.c1.r1y);let k=y.b2.imass;if(y.b2.velx+=b*k,y.b2.vely+=f*k,y.b2.angvel+=y.b2.iinertia*(f*y.c1.r2x-b*y.c1.r2y),y.hc2){let le=y.nx*y.c2.jnAcc-y.ny*y.c2.jtAcc,he=y.ny*y.c2.jnAcc+y.nx*y.c2.jtAcc,pe=y.b1.imass;y.b1.velx-=le*pe,y.b1.vely-=he*pe,y.b1.angvel-=y.b1.iinertia*(he*y.c2.r1x-le*y.c2.r1y);let ce=y.b2.imass;y.b2.velx+=le*ce,y.b2.vely+=he*ce,y.b2.angvel+=y.b2.iinertia*(he*y.c2.r2x-le*y.c2.r2y)}y.b2.angvel+=y.jrAcc*y.b2.iinertia,y.b1.angvel-=y.jrAcc*y.b1.iinertia;let _=m.colarb,z=_.k1x+_.b2.velx-_.c1.r2y*_.b2.angvel-(_.b1.velx-_.c1.r1y*_.b1.angvel),C=_.k1y+_.b2.vely+_.c1.r2x*_.b2.angvel-(_.b1.vely+_.c1.r1x*_.b1.angvel),w=(C*_.nx-z*_.ny+_.surfacex)*_.c1.tMass,g=_.c1.friction*_.c1.jnAcc,O=_.c1.jtAcc,E=O-w;E>g?E=g:E<-g&&(E=-g),w=E-O,_.c1.jtAcc=E;let M=-_.ny*w,N=_.nx*w;if(_.b2.velx+=M*_.b2.imass,_.b2.vely+=N*_.b2.imass,_.b1.velx-=M*_.b1.imass,_.b1.vely-=N*_.b1.imass,_.b2.angvel+=_.rt1b*w*_.b2.iinertia,_.b1.angvel-=_.rt1a*w*_.b1.iinertia,_.hc2){let le=_.k2x+_.b2.velx-_.c2.r2y*_.b2.angvel-(_.b1.velx-_.c2.r1y*_.b1.angvel),he=_.k2y+_.b2.vely+_.c2.r2x*_.b2.angvel-(_.b1.vely+_.c2.r1x*_.b1.angvel);w=(he*_.nx-le*_.ny+_.surfacex)*_.c2.tMass,g=_.c2.friction*_.c2.jnAcc,O=_.c2.jtAcc,E=O-w,E>g?E=g:E<-g&&(E=-g),w=E-O,_.c2.jtAcc=E,M=-_.ny*w,N=_.nx*w,_.b2.velx+=M*_.b2.imass,_.b2.vely+=N*_.b2.imass,_.b1.velx-=M*_.b1.imass,_.b1.vely-=N*_.b1.imass,_.b2.angvel+=_.rt2b*w*_.b2.iinertia,_.b1.angvel-=_.rt2a*w*_.b1.iinertia,z=_.k1x+_.b2.velx-_.c1.r2y*_.b2.angvel-(_.b1.velx-_.c1.r1y*_.b1.angvel),C=_.k1y+_.b2.vely+_.c1.r2x*_.b2.angvel-(_.b1.vely+_.c1.r1x*_.b1.angvel),le=_.k2x+_.b2.velx-_.c2.r2y*_.b2.angvel-(_.b1.velx-_.c2.r1y*_.b1.angvel),he=_.k2y+_.b2.vely+_.c2.r2x*_.b2.angvel-(_.b1.vely+_.c2.r1x*_.b1.angvel);let pe=_.c1.jnAcc,ce=_.c2.jnAcc,te=z*_.nx+C*_.ny+_.surfacey+_.c1.bounce-(_.Ka*pe+_.Kb*ce),ue=le*_.nx+he*_.ny+_.surfacey+_.c2.bounce-(_.Kb*pe+_.Kc*ce),xe=-(_.kMassa*te+_.kMassb*ue),_e=-(_.kMassb*te+_.kMassc*ue);xe>=0&&_e>=0?(te=xe-pe,ue=_e-ce,_.c1.jnAcc=xe,_.c2.jnAcc=_e):(xe=-_.c1.nMass*te,xe>=0&&_.Kb*xe+ue>=0?(te=xe-pe,ue=-ce,_.c1.jnAcc=xe,_.c2.jnAcc=0):(_e=-_.c2.nMass*ue,_e>=0&&_.Kb*_e+te>=0?(te=-pe,ue=_e-ce,_.c1.jnAcc=0,_.c2.jnAcc=_e):te>=0&&ue>=0?(te=-pe,ue=-ce,_.c1.jnAcc=_.c2.jnAcc=0):(te=0,ue=0))),w=te+ue,M=_.nx*w,N=_.ny*w,_.b2.velx+=M*_.b2.imass,_.b2.vely+=N*_.b2.imass,_.b1.velx-=M*_.b1.imass,_.b1.vely-=N*_.b1.imass,_.b2.angvel+=(_.rn1b*te+_.rn2b*ue)*_.b2.iinertia,_.b1.angvel-=(_.rn1a*te+_.rn2a*ue)*_.b1.iinertia}else _.radius!=0&&(w=(_.b2.angvel-_.b1.angvel)*_.rMass,g=_.rfric*_.c1.jnAcc,O=_.jrAcc,_.jrAcc-=w,_.jrAcc>g?_.jrAcc=g:_.jrAcc<-g&&(_.jrAcc=-g),w=_.jrAcc-O,_.b2.angvel+=w*_.b2.iinertia,_.b1.angvel-=w*_.b1.iinertia),z=_.k1x+_.b2.velx-_.c1.r2y*_.b2.angvel-(_.b1.velx-_.c1.r1y*_.b1.angvel),C=_.k1y+_.b2.vely+_.c1.r2x*_.b2.angvel-(_.b1.vely+_.c1.r1x*_.b1.angvel),w=(_.c1.bounce+(_.nx*z+_.ny*C)+_.surfacey)*_.c1.nMass,O=_.c1.jnAcc,E=O-w,E<0&&(E=0),w=E-O,_.c1.jnAcc=E,M=_.nx*w,N=_.ny*w,_.b2.velx+=M*_.b2.imass,_.b2.vely+=N*_.b2.imass,_.b1.velx-=M*_.b1.imass,_.b1.vely-=N*_.b1.imass,_.b2.angvel+=_.rn1b*w*_.b2.iinertia,_.b1.angvel-=_.rn1a*w*_.b1.iinertia;let Z=m.colarb,A=Z.k1x+Z.b2.velx-Z.c1.r2y*Z.b2.angvel-(Z.b1.velx-Z.c1.r1y*Z.b1.angvel),S=Z.k1y+Z.b2.vely+Z.c1.r2x*Z.b2.angvel-(Z.b1.vely+Z.c1.r1x*Z.b1.angvel),L=(S*Z.nx-A*Z.ny+Z.surfacex)*Z.c1.tMass,T=Z.c1.friction*Z.c1.jnAcc,G=Z.c1.jtAcc,q=G-L;q>T?q=T:q<-T&&(q=-T),L=q-G,Z.c1.jtAcc=q;let R=-Z.ny*L,j=Z.nx*L;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*L*Z.b2.iinertia,Z.b1.angvel-=Z.rt1a*L*Z.b1.iinertia,Z.hc2){let le=Z.k2x+Z.b2.velx-Z.c2.r2y*Z.b2.angvel-(Z.b1.velx-Z.c2.r1y*Z.b1.angvel),he=Z.k2y+Z.b2.vely+Z.c2.r2x*Z.b2.angvel-(Z.b1.vely+Z.c2.r1x*Z.b1.angvel);L=(he*Z.nx-le*Z.ny+Z.surfacex)*Z.c2.tMass,T=Z.c2.friction*Z.c2.jnAcc,G=Z.c2.jtAcc,q=G-L,q>T?q=T:q<-T&&(q=-T),L=q-G,Z.c2.jtAcc=q,R=-Z.ny*L,j=Z.nx*L,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*L*Z.b2.iinertia,Z.b1.angvel-=Z.rt2a*L*Z.b1.iinertia,A=Z.k1x+Z.b2.velx-Z.c1.r2y*Z.b2.angvel-(Z.b1.velx-Z.c1.r1y*Z.b1.angvel),S=Z.k1y+Z.b2.vely+Z.c1.r2x*Z.b2.angvel-(Z.b1.vely+Z.c1.r1x*Z.b1.angvel),le=Z.k2x+Z.b2.velx-Z.c2.r2y*Z.b2.angvel-(Z.b1.velx-Z.c2.r1y*Z.b1.angvel),he=Z.k2y+Z.b2.vely+Z.c2.r2x*Z.b2.angvel-(Z.b1.vely+Z.c2.r1x*Z.b1.angvel);let pe=Z.c1.jnAcc,ce=Z.c2.jnAcc,te=A*Z.nx+S*Z.ny+Z.surfacey+Z.c1.bounce-(Z.Ka*pe+Z.Kb*ce),ue=le*Z.nx+he*Z.ny+Z.surfacey+Z.c2.bounce-(Z.Kb*pe+Z.Kc*ce),xe=-(Z.kMassa*te+Z.kMassb*ue),_e=-(Z.kMassb*te+Z.kMassc*ue);xe>=0&&_e>=0?(te=xe-pe,ue=_e-ce,Z.c1.jnAcc=xe,Z.c2.jnAcc=_e):(xe=-Z.c1.nMass*te,xe>=0&&Z.Kb*xe+ue>=0?(te=xe-pe,ue=-ce,Z.c1.jnAcc=xe,Z.c2.jnAcc=0):(_e=-Z.c2.nMass*ue,_e>=0&&Z.Kb*_e+te>=0?(te=-pe,ue=_e-ce,Z.c1.jnAcc=0,Z.c2.jnAcc=_e):te>=0&&ue>=0?(te=-pe,ue=-ce,Z.c1.jnAcc=Z.c2.jnAcc=0):(te=0,ue=0))),L=te+ue,R=Z.nx*L,j=Z.ny*L,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*te+Z.rn2b*ue)*Z.b2.iinertia,Z.b1.angvel-=(Z.rn1a*te+Z.rn2a*ue)*Z.b1.iinertia}else Z.radius!=0&&(L=(Z.b2.angvel-Z.b1.angvel)*Z.rMass,T=Z.rfric*Z.c1.jnAcc,G=Z.jrAcc,Z.jrAcc-=L,Z.jrAcc>T?Z.jrAcc=T:Z.jrAcc<-T&&(Z.jrAcc=-T),L=Z.jrAcc-G,Z.b2.angvel+=L*Z.b2.iinertia,Z.b1.angvel-=L*Z.b1.iinertia),A=Z.k1x+Z.b2.velx-Z.c1.r2y*Z.b2.angvel-(Z.b1.velx-Z.c1.r1y*Z.b1.angvel),S=Z.k1y+Z.b2.vely+Z.c1.r2x*Z.b2.angvel-(Z.b1.vely+Z.c1.r1x*Z.b1.angvel),L=(Z.c1.bounce+(Z.nx*A+Z.ny*S)+Z.surfacey)*Z.c1.nMass,G=Z.c1.jnAcc,q=G-L,q<0&&(q=0),L=q-G,Z.c1.jnAcc=q,R=Z.nx*L,j=Z.ny*L,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*L*Z.b2.iinertia,Z.b1.angvel-=Z.rn1a*L*Z.b1.iinertia;let V=m.colarb,K=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),$=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),Y=($*V.nx-K*V.ny+V.surfacex)*V.c1.tMass,X=V.c1.friction*V.c1.jnAcc,ee=V.c1.jtAcc,J=ee-Y;J>X?J=X:J<-X&&(J=-X),Y=J-ee,V.c1.jtAcc=J;let F=-V.ny*Y,D=V.nx*Y;if(V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=V.rt1b*Y*V.b2.iinertia,V.b1.angvel-=V.rt1a*Y*V.b1.iinertia,V.hc2){let le=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),he=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);Y=(he*V.nx-le*V.ny+V.surfacex)*V.c2.tMass,X=V.c2.friction*V.c2.jnAcc,ee=V.c2.jtAcc,J=ee-Y,J>X?J=X:J<-X&&(J=-X),Y=J-ee,V.c2.jtAcc=J,F=-V.ny*Y,D=V.nx*Y,V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=V.rt2b*Y*V.b2.iinertia,V.b1.angvel-=V.rt2a*Y*V.b1.iinertia,K=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),$=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),le=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),he=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);let pe=V.c1.jnAcc,ce=V.c2.jnAcc,te=K*V.nx+$*V.ny+V.surfacey+V.c1.bounce-(V.Ka*pe+V.Kb*ce),ue=le*V.nx+he*V.ny+V.surfacey+V.c2.bounce-(V.Kb*pe+V.Kc*ce),xe=-(V.kMassa*te+V.kMassb*ue),_e=-(V.kMassb*te+V.kMassc*ue);xe>=0&&_e>=0?(te=xe-pe,ue=_e-ce,V.c1.jnAcc=xe,V.c2.jnAcc=_e):(xe=-V.c1.nMass*te,xe>=0&&V.Kb*xe+ue>=0?(te=xe-pe,ue=-ce,V.c1.jnAcc=xe,V.c2.jnAcc=0):(_e=-V.c2.nMass*ue,_e>=0&&V.Kb*_e+te>=0?(te=-pe,ue=_e-ce,V.c1.jnAcc=0,V.c2.jnAcc=_e):te>=0&&ue>=0?(te=-pe,ue=-ce,V.c1.jnAcc=V.c2.jnAcc=0):(te=0,ue=0))),Y=te+ue,F=V.nx*Y,D=V.ny*Y,V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=(V.rn1b*te+V.rn2b*ue)*V.b2.iinertia,V.b1.angvel-=(V.rn1a*te+V.rn2a*ue)*V.b1.iinertia}else V.radius!=0&&(Y=(V.b2.angvel-V.b1.angvel)*V.rMass,X=V.rfric*V.c1.jnAcc,ee=V.jrAcc,V.jrAcc-=Y,V.jrAcc>X?V.jrAcc=X:V.jrAcc<-X&&(V.jrAcc=-X),Y=V.jrAcc-ee,V.b2.angvel+=Y*V.b2.iinertia,V.b1.angvel-=Y*V.b1.iinertia),K=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),$=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),Y=(V.c1.bounce+(V.nx*K+V.ny*$)+V.surfacey)*V.c1.nMass,ee=V.c1.jnAcc,J=ee-Y,J<0&&(J=0),Y=J-ee,V.c1.jnAcc=J,F=V.nx*Y,D=V.ny*Y,V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=V.rn1b*Y*V.b2.iinertia,V.b1.angvel-=V.rn1a*Y*V.b1.iinertia;let I=m.colarb,U=I.k1x+I.b2.velx-I.c1.r2y*I.b2.angvel-(I.b1.velx-I.c1.r1y*I.b1.angvel),Q=I.k1y+I.b2.vely+I.c1.r2x*I.b2.angvel-(I.b1.vely+I.c1.r1x*I.b1.angvel),W=(Q*I.nx-U*I.ny+I.surfacex)*I.c1.tMass,ie=I.c1.friction*I.c1.jnAcc,oe=I.c1.jtAcc,se=oe-W;se>ie?se=ie:se<-ie&&(se=-ie),W=se-oe,I.c1.jtAcc=se;let ne=-I.ny*W,re=I.nx*W;if(I.b2.velx+=ne*I.b2.imass,I.b2.vely+=re*I.b2.imass,I.b1.velx-=ne*I.b1.imass,I.b1.vely-=re*I.b1.imass,I.b2.angvel+=I.rt1b*W*I.b2.iinertia,I.b1.angvel-=I.rt1a*W*I.b1.iinertia,I.hc2){let le=I.k2x+I.b2.velx-I.c2.r2y*I.b2.angvel-(I.b1.velx-I.c2.r1y*I.b1.angvel),he=I.k2y+I.b2.vely+I.c2.r2x*I.b2.angvel-(I.b1.vely+I.c2.r1x*I.b1.angvel);W=(he*I.nx-le*I.ny+I.surfacex)*I.c2.tMass,ie=I.c2.friction*I.c2.jnAcc,oe=I.c2.jtAcc,se=oe-W,se>ie?se=ie:se<-ie&&(se=-ie),W=se-oe,I.c2.jtAcc=se,ne=-I.ny*W,re=I.nx*W,I.b2.velx+=ne*I.b2.imass,I.b2.vely+=re*I.b2.imass,I.b1.velx-=ne*I.b1.imass,I.b1.vely-=re*I.b1.imass,I.b2.angvel+=I.rt2b*W*I.b2.iinertia,I.b1.angvel-=I.rt2a*W*I.b1.iinertia,U=I.k1x+I.b2.velx-I.c1.r2y*I.b2.angvel-(I.b1.velx-I.c1.r1y*I.b1.angvel),Q=I.k1y+I.b2.vely+I.c1.r2x*I.b2.angvel-(I.b1.vely+I.c1.r1x*I.b1.angvel),le=I.k2x+I.b2.velx-I.c2.r2y*I.b2.angvel-(I.b1.velx-I.c2.r1y*I.b1.angvel),he=I.k2y+I.b2.vely+I.c2.r2x*I.b2.angvel-(I.b1.vely+I.c2.r1x*I.b1.angvel);let pe=I.c1.jnAcc,ce=I.c2.jnAcc,te=U*I.nx+Q*I.ny+I.surfacey+I.c1.bounce-(I.Ka*pe+I.Kb*ce),ue=le*I.nx+he*I.ny+I.surfacey+I.c2.bounce-(I.Kb*pe+I.Kc*ce),xe=-(I.kMassa*te+I.kMassb*ue),_e=-(I.kMassb*te+I.kMassc*ue);xe>=0&&_e>=0?(te=xe-pe,ue=_e-ce,I.c1.jnAcc=xe,I.c2.jnAcc=_e):(xe=-I.c1.nMass*te,xe>=0&&I.Kb*xe+ue>=0?(te=xe-pe,ue=-ce,I.c1.jnAcc=xe,I.c2.jnAcc=0):(_e=-I.c2.nMass*ue,_e>=0&&I.Kb*_e+te>=0?(te=-pe,ue=_e-ce,I.c1.jnAcc=0,I.c2.jnAcc=_e):te>=0&&ue>=0?(te=-pe,ue=-ce,I.c1.jnAcc=I.c2.jnAcc=0):(te=0,ue=0))),W=te+ue,ne=I.nx*W,re=I.ny*W,I.b2.velx+=ne*I.b2.imass,I.b2.vely+=re*I.b2.imass,I.b1.velx-=ne*I.b1.imass,I.b1.vely-=re*I.b1.imass,I.b2.angvel+=(I.rn1b*te+I.rn2b*ue)*I.b2.iinertia,I.b1.angvel-=(I.rn1a*te+I.rn2a*ue)*I.b1.iinertia}else I.radius!=0&&(W=(I.b2.angvel-I.b1.angvel)*I.rMass,ie=I.rfric*I.c1.jnAcc,oe=I.jrAcc,I.jrAcc-=W,I.jrAcc>ie?I.jrAcc=ie:I.jrAcc<-ie&&(I.jrAcc=-ie),W=I.jrAcc-oe,I.b2.angvel+=W*I.b2.iinertia,I.b1.angvel-=W*I.b1.iinertia),U=I.k1x+I.b2.velx-I.c1.r2y*I.b2.angvel-(I.b1.velx-I.c1.r1y*I.b1.angvel),Q=I.k1y+I.b2.vely+I.c1.r2x*I.b2.angvel-(I.b1.vely+I.c1.r1x*I.b1.angvel),W=(I.c1.bounce+(I.nx*U+I.ny*Q)+I.surfacey)*I.c1.nMass,oe=I.c1.jnAcc,se=oe-W,se<0&&(se=0),W=se-oe,I.c1.jnAcc=se,ne=I.nx*W,re=I.ny*W,I.b2.velx+=ne*I.b2.imass,I.b2.vely+=re*I.b2.imass,I.b1.velx-=ne*I.b1.imass,I.b1.vely-=re*I.b1.imass,I.b2.angvel+=I.rn1b*W*I.b2.iinertia,I.b1.angvel-=I.rn1a*W*I.b1.iinertia;h.sweep_angvel=h.angvel%t,u.sweep_angvel=u.angvel%t}if(m!=null&&m.active&&(m.immState&1)!=0&&m.type==Ie.COL){if(!h.sweepFrozen&&h.type!=3)if(h.sweepFrozen=!0,l.failed)h.angvel=h.sweep_angvel=0;else if(l.slipped){let y=h;y.sweep_angvel*=B._nape.Config.angularCCDSlipScale,h.angvel=y.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 y=u;y.sweep_angvel*=B._nape.Config.angularCCDSlipScale,u.angvel=y.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 o=this.toiEvents.pop_unsafe();o.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=o}let s=this.kinematics.head;for(;s!=null;){let l=s.elt,o=e-l.sweepTime;if(o!=0){l.sweepTime=e;let r=o;if(l.posx+=l.velx*r,l.posy+=l.vely*r,l.angvel!=0){let a=l.sweep_angvel*o;if(l.rot+=a,a*a>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=a*a,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+a*l.axisy)*h;l.axisy=(c*l.axisy-a*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 o=e-l.sweepTime;if(o!=0){l.sweepTime=e;let r=o;if(l.posx+=l.velx*r,l.posy+=l.vely*r,l.angvel!=0){let a=l.sweep_angvel*o;if(l.rot+=a,a*a>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=a*a,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+a*l.axisy)*h;l.axisy=(c*l.axisy-a*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 a=e.body,p=t.body,c;c=!1;let h=a.constraints.head;for(;h!=null;){let m=h.elt;if(m.ignore&&m.pair_exists(a.id,p.id)){c=!0;break}h=h.next}let u,x;if(c)x=!1;else{let m=e;for(;m!=null&&m.group==null;)m.ishape!=null?m=m.ishape.body:m.icompound!=null?m=m.icompound.compound:m=m.ibody.compound;let d=m==null?null:m.group,y;if(d==null)y=!1;else{let b=t;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 f=b==null?null:b.group;if(f==null)y=!1;else{let P=!1;for(;d!=null&&f!=null;){if(d==f){P=d.ignore;break}d.depth<f.depth?f=f.group:d=d.group}y=P}}x=!y}if(x){let m;if(e.sensorEnabled||t.sensorEnabled){let d=e.filter,y=t.filter;m=(d.sensorMask&y.sensorGroup)!=0&&(y.sensorMask&d.sensorGroup)!=0}else m=!1;if(m)u=2;else{let d;if(e.fluidEnabled||t.fluidEnabled){let y=e.filter,b=t.filter;d=(y.fluidMask&b.fluidGroup)!=0&&(b.fluidMask&y.fluidGroup)!=0}else d=!1;if(d&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0))u=0;else{let y=e.filter,b=t.filter;u=(y.collisionMask&b.collisionGroup)!=0&&(b.collisionMask&y.collisionGroup)!=0&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0)?1:-1}}}else u=-1;l=u<=0}if(l)return s;let o=e.body,r=t.body;if(n||o.bullet||r.bullet){let a;B._zpp.geom.ZPP_ToiEvent.zpp_pool==null?a=new B._zpp.geom.ZPP_ToiEvent:(a=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._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,Cn.staticSweep(a,this.pre_dt,0,B._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}Cn.staticSweep(a,this.pre_dt,0,B._nape.Config.collisionSlopCCD)}else Cn.dynamicSweep(a,this.pre_dt,0,B._nape.Config.collisionSlopCCD,!1);if(n&&a.toi<0||a.failed){let c=a;c.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._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=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,o=l.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=l.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,o=i.ishape!=null?i.ishape:null,r=l.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 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 m=x.arbiters.pop_unsafe();m.present--}this.remove_callbackset(x)}h=h.next}p=p.next}r=r.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 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=B._zpp.phys.ZPP_Interactor.get(r,p);c!=null&&(l.present--,c.remove_arb(l),c.arbiters.head==null&&this.remove_callbackset(c)),a=a.next}o=o.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,o=l.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=l.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,o=i.ishape!=null?i.ishape:null,r=l.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 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=Kt.get(c,u),this.add_callbackset(x));let m,d;d=!1;let y=x.arbiters.head;for(;y!=null;){if(y.elt==a){d=!0;break}y=y.next}if(d)m=!1;else{let b=x.arbiters,f;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?f=new B._zpp.util.ZNPNode_ZPP_Arbiter:(f=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f.next,f.next=null),f.elt=a;let P=f;P.next=b.head,b.head=P,b.modified=!0,b.length++,m=!0}m&&a.present++,h=h.next}p=p.next}r=r.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 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,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 y=d.elt;if(y.a==c&&y.b==h||y.a==h&&y.b==c){x=y;break}d=d.next}if(x==null){let y;Ne.zpp_pool==null?y=new Ne:(y=Ne.zpp_pool,Ne.zpp_pool=y.next,y.next=null),y.zip_listeners=!0,_t.setlt(c,h)?(y.a=c,y.b=h):(y.a=h,y.b=c),x=y,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 y=B._zpp.phys.ZPP_Interactor.get(r,p);y==null&&(y=Kt.get(r,p),this.add_callbackset(y));let b,f;f=!1;let P=y.arbiters.head;for(;P!=null;){if(P.elt==l){f=!0;break}P=P.next}if(f)b=!1;else{let k=y.arbiters,_;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_Arbiter:(_=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_.next,_.next=null),_.elt=l;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++,b=!0}b&&l.present++}a=a.next}o=o.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==Ie.COL){let o=l.colarb;if(o.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=o;let p=a;p.next=r.head,r.head=p,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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}}else if(l.type==Ie.FLUID){let o=this.f_arbiters,r=l.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 p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}else{let o=this.s_arbiters,r=l.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 p=a;p.next=o.head,o.head=p,o.modified=!0,o.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 o=l.elt;o.node!=null&&this.bphase.sync(o),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 o=l;o.next=i.head,i.head=o,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=xt.zpp_pool,xt.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 o=l;o.next=i.head,i.head=o,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 o=l;o.next=i.head,i.head=o,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==Ie.COL){let l=i.colarb;if(l.stat){let o=this.c_arbiters_true,r;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(r=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=l;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}else{let o=this.c_arbiters_false,r;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(r=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=l;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}}else if(i.type==Ie.FLUID){let l=this.f_arbiters,o=i.fluidarb,r;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(r=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=l.head,l.head=a,l.modified=!0,l.length++}else{let l=this.s_arbiters,o=i.sensorarb,r;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(r=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=l.head,l.head=a,l.modified=!0,l.length++}if(i.type!=Ie.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 r=i.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}l=r}let o;if(i.b2.component==i.b2.component.parent)o=i.b2.component;else{let r=i.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}l!=o&&(l.rank<o.rank?l.parent=o:l.rank>o.rank?o.parent=l:(o.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 r=i.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}l=r}let o;if(i.b2.component==i.b2.component.parent)o=i.b2.component;else{let r=i.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}l!=o&&(l.rank<o.rank?l.parent=o:l.rank>o.rank?o.parent=l:(o.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 o=l,r=o.component,a;if(r==r.parent)a=r;else{let x=r,m=null;for(;x!=x.parent;){let d=x.parent;x.parent=m,m=x,x=d}for(;m!=null;){let d=m.parent;m.parent=x,m=d}a=x}if(a.island==null){xt.zpp_pool==null?a.island=new xt:(a.island=xt.zpp_pool,xt.zpp_pool=a.island.next,a.island.next=null),a.island.waket=0;let x=this.islands,m=a.island;m._inuse=!0;let d=m;d.next=x.next,x.next=d,x.modified=!0,x.length++,a.island.sleep=!0}r.island=a.island;let p=r.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=r;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++;let u=o.atRest(e);r.island.sleep=r.island.sleep&&u,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.live_constraints.head!=null;){let i=this.live_constraints,l=i.head.elt;i.pop();let r=l.component,a;if(r==r.parent)a=r;else{let u=r,x=null;for(;u!=u.parent;){let m=u.parent;u.parent=x,x=u,u=m}for(;x!=null;){let m=x.parent;x.parent=u,x=m}a=u}r.island=a.island;let p=r.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=r;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.islands.next!=null;){let i=this.islands,l=i.next;i.pop();let o=l;if(this.deterministic&&this._sortLinkedList(o.comps,r=>r.isBody?r.body.id:r.constraint.id+1e9),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 h=c.elt;this.bphase.sync(h),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 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 m=x;m.next=h.head,h.head=m,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 m=x;m.next=h.head,h.head=m,h.modified=!0,h.length++}c.sleeping=!1,c.island=null,c.parent=c,c.rank=0}let r=o;r.next=xt.zpp_pool,xt.zpp_pool=r}}}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,m;e==null?(x=t.head,m=x.next,t.head=m,t.head==null&&(t.pushmod=!0)):(x=e.next,m=x.next,e.next=m,m==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=m,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,o=l.head,r=!1;for(r&&o==null&&(r=!1,l=null,i=null);o!=null;){let u=o.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=!0;let x,m;i==null?(x=l.head,m=x.next,l.head=m,l.head==null&&(l.pushmod=!0)):(x=i.next,m=x.next,i.next=m,m==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,o=m,r&&o==null&&(r=!1,l=null,i=null);continue}i=o,o=o.next,r&&o==null&&(r=!1,l=null,i=null)}let a=null,p=this.s_arbiters,c=p.head,h=!1;for(h&&c==null&&(h=!1,p=null,a=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,m;a==null?(x=p.head,m=x.next,p.head=m,p.head==null&&(p.pushmod=!0)):(x=a.next,m=x.next,a.next=m,m==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=m,h&&c==null&&(h=!1,p=null,a=null);continue}a=c,c=c.next,h&&c==null&&(h=!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 s=n.elt;if(s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let o=s.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 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 m=u;for(u=u.next;u!=null;){let k=u;h+=m.x*(k.y-x.y);let _=k.y*m.x-k.x*m.y;c.localCOMx+=(m.x+k.x)*_,c.localCOMy+=(m.y+k.y)*_,x=m,m=k,u=u.next}u=c.lverts.next;let d=u;h+=m.x*(d.y-x.y);let y=d.y*m.x-d.x*m.y;c.localCOMx+=(m.x+d.x)*y,c.localCOMy+=(m.y+d.y)*y,x=m,m=d,u=u.next;let b=u;h+=m.x*(b.y-x.y);let f=b.y*m.x-b.x*m.y;c.localCOMx+=(m.x+b.x)*f,c.localCOMy+=(m.y+b.y)*f,h=1/(3*h);let P=h;c.localCOMx*=P,c.localCOMy*=P}}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 if(s.type===2)s.capsule.__validate_aabb();else{let o=s.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,h=o.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),u.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),h=h.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 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 o=l.body;if(o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.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,m=l.gverts.next;for(;m!=null;){let d=m,y=x;x=x.next,d.x=l.body.posx+(l.body.axisy*y.x-l.body.axisx*y.y),d.y=l.body.posy+(y.x*l.body.axisx+y.y*l.body.axisy),m=m.next}}let r=l.edges.head,a=l.gverts.next,p=a;for(a=a.next;a!=null;){let u=a,x=r.elt;r=r.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,a=a.next}let c=l.gverts.next,h=r.elt;r=r.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 r=l.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(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 : "+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 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 b=c.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot));let f=c.lverts.next,P=c.gverts.next;for(;P!=null;){let k=P,_=f;f=f.next,k.x=c.body.posx+(c.body.axisy*_.x-c.body.axisx*_.y),k.y=c.body.posy+(_.x*c.body.axisx+_.y*c.body.axisy),P=P.next}}let u=c.edges.head,x=c.gverts.next,m=x;for(x=x.next;x!=null;){let b=x,f=u.elt;u=u.next,f.gp0=m,f.gp1=b,f.gnormx=c.body.axisy*f.lnormx-c.body.axisx*f.lnormy,f.gnormy=f.lnormx*c.body.axisx+f.lnormy*c.body.axisy,f.gprojection=c.body.posx*f.gnormx+c.body.posy*f.gnormy+f.lprojection,f.wrap_gnorm!=null&&(f.wrap_gnorm.zpp_inner.x=f.gnormx,f.wrap_gnorm.zpp_inner.y=f.gnormy),f.tp0=f.gp0.y*f.gnormx-f.gp0.x*f.gnormy,f.tp1=f.gp1.y*f.gnormx-f.gp1.x*f.gnormy,m=b,x=x.next}let d=c.gverts.next,y=u.elt;u=u.next,y.gp0=m,y.gp1=d,y.gnormx=c.body.axisy*y.lnormx-c.body.axisx*y.lnormy,y.gnormy=y.lnormx*c.body.axisx+y.lnormy*c.body.axisy,y.gprojection=c.body.posx*y.gnormx+c.body.posy*y.gnormy+y.lprojection,y.wrap_gnorm!=null&&(y.wrap_gnorm.zpp_inner.x=y.gnormx,y.wrap_gnorm.zpp_inner.y=y.gnormy),y.tp0=y.gp0.y*y.gnormx-y.gp0.x*y.gnormy,y.tp1=y.gp1.y*y.gnormx-y.gp1.x*y.gnormy}}r.validate_sweepRadius(),r.sweepRadius>i.sweepRadius&&(i.sweepRadius=r.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 r=i.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 h=a.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 y=1;d.localCOMx+=d.lverts.next.next.x*y,d.localCOMy+=d.lverts.next.next.y*y;let b=.5;d.localCOMx*=b,d.localCOMy*=b}else{d.localCOMx=0,d.localCOMy=0;let y=0,b=d.lverts.next,f=b;b=b.next;let P=b;for(b=b.next;b!=null;){let g=b;y+=P.x*(g.y-f.y);let O=g.y*P.x-g.x*P.y;d.localCOMx+=(P.x+g.x)*O,d.localCOMy+=(P.y+g.y)*O,f=P,P=g,b=b.next}b=d.lverts.next;let k=b;y+=P.x*(k.y-f.y);let _=k.y*P.x-k.x*P.y;d.localCOMx+=(P.x+k.x)*_,d.localCOMy+=(P.y+k.y)*_,f=P,P=k,b=b.next;let z=b;y+=P.x*(z.y-f.y);let C=z.y*P.x-z.x*P.y;d.localCOMx+=(P.x+z.x)*C,d.localCOMy+=(P.y+z.y)*C,y=1/(3*y);let w=y;d.localCOMx*=w,d.localCOMy*=w}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy)}let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.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 if(a.type===2)a.capsule.__validate_aabb();else{let h=a.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot));let d=h.lverts.next,y=h.gverts.next;for(;y!=null;){let b=y,f=d;d=d.next,b.x=h.body.posx+(h.body.axisy*f.x-h.body.axisx*f.y),b.y=h.body.posy+(f.x*h.body.axisx+f.y*h.body.axisy),y=y.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 m=x;m.x<h.aabb.minx&&(h.aabb.minx=m.x),m.x>h.aabb.maxx&&(h.aabb.maxx=m.x),m.y<h.aabb.miny&&(h.aabb.miny=m.y),m.y>h.aabb.maxy&&(h.aabb.maxy=m.y),x=x.next}}let p=i.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}}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 r=i.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=i,r=r.next}}i.component.woken=!1;let o=i.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 i=n.elt;i.sweepRadius=0;let l=i.shapes.head;for(;l!=null;){let r=l.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(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 : "+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 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 b=c.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot));let f=c.lverts.next,P=c.gverts.next;for(;P!=null;){let k=P,_=f;f=f.next,k.x=c.body.posx+(c.body.axisy*_.x-c.body.axisx*_.y),k.y=c.body.posy+(_.x*c.body.axisx+_.y*c.body.axisy),P=P.next}}let u=c.edges.head,x=c.gverts.next,m=x;for(x=x.next;x!=null;){let b=x,f=u.elt;u=u.next,f.gp0=m,f.gp1=b,f.gnormx=c.body.axisy*f.lnormx-c.body.axisx*f.lnormy,f.gnormy=f.lnormx*c.body.axisx+f.lnormy*c.body.axisy,f.gprojection=c.body.posx*f.gnormx+c.body.posy*f.gnormy+f.lprojection,f.wrap_gnorm!=null&&(f.wrap_gnorm.zpp_inner.x=f.gnormx,f.wrap_gnorm.zpp_inner.y=f.gnormy),f.tp0=f.gp0.y*f.gnormx-f.gp0.x*f.gnormy,f.tp1=f.gp1.y*f.gnormx-f.gp1.x*f.gnormy,m=b,x=x.next}let d=c.gverts.next,y=u.elt;u=u.next,y.gp0=m,y.gp1=d,y.gnormx=c.body.axisy*y.lnormx-c.body.axisx*y.lnormy,y.gnormy=y.lnormx*c.body.axisx+y.lnormy*c.body.axisy,y.gprojection=c.body.posx*y.gnormx+c.body.posy*y.gnormy+y.lprojection,y.wrap_gnorm!=null&&(y.wrap_gnorm.zpp_inner.x=y.gnormx,y.wrap_gnorm.zpp_inner.y=y.gnormy),y.tp0=y.gp0.y*y.gnormx-y.gp0.x*y.gnormy,y.tp1=y.gp1.y*y.gnormx-y.gp1.x*y.gnormy}}r.validate_sweepRadius(),r.sweepRadius>i.sweepRadius&&(i.sweepRadius=r.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 r=i.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 h=a.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 y=1;d.localCOMx+=d.lverts.next.next.x*y,d.localCOMy+=d.lverts.next.next.y*y;let b=.5;d.localCOMx*=b,d.localCOMy*=b}else{d.localCOMx=0,d.localCOMy=0;let y=0,b=d.lverts.next,f=b;b=b.next;let P=b;for(b=b.next;b!=null;){let g=b;y+=P.x*(g.y-f.y);let O=g.y*P.x-g.x*P.y;d.localCOMx+=(P.x+g.x)*O,d.localCOMy+=(P.y+g.y)*O,f=P,P=g,b=b.next}b=d.lverts.next;let k=b;y+=P.x*(k.y-f.y);let _=k.y*P.x-k.x*P.y;d.localCOMx+=(P.x+k.x)*_,d.localCOMy+=(P.y+k.y)*_,f=P,P=k,b=b.next;let z=b;y+=P.x*(z.y-f.y);let C=z.y*P.x-z.x*P.y;d.localCOMx+=(P.x+z.x)*C,d.localCOMy+=(P.y+z.y)*C,y=1/(3*y);let w=y;d.localCOMx*=w,d.localCOMy*=w}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy)}let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.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 if(a.type===2)a.capsule.__validate_aabb();else{let h=a.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot));let d=h.lverts.next,y=h.gverts.next;for(;y!=null;){let b=y,f=d;d=d.next,b.x=h.body.posx+(h.body.axisy*f.x-h.body.axisx*f.y),b.y=h.body.posy+(f.x*h.body.axisx+f.y*h.body.axisy),y=y.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 m=x;m.x<h.aabb.minx&&(h.aabb.minx=m.x),m.x>h.aabb.maxx&&(h.aabb.maxx=m.x),m.y<h.aabb.miny&&(h.aabb.miny=m.y),m.y>h.aabb.maxy&&(h.aabb.maxy=m.y),x=x.next}}let p=i.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}}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 o=i.shapes.head;for(;o!=null;){let r=o.elt;this.bphase.sync(r),o=o.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 o=l.elt;if(o.event!=2){l=l.next;continue}let r=this.push_callback(o);r.event=2,r.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 o=e*l.imass;l.velx=n*l.velx+(l.forcex+this.gravityx*l.gravMass)*o,l.vely=n*l.vely+(l.forcey+this.gravityy*l.gravMass)*o}if(l.sinertia!=0){let o=0,r=0;o=l.worldCOMx-l.posx,r=l.worldCOMy-l.posy;let a=l.torque+(this.gravityy*o-this.gravityx*r)*l.gravMass;l.angvel=s*l.angvel+a*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 o=l;if(i.posx+=i.velx*o,i.posy+=i.vely*o,i.angvel!=0){let r=i.sweep_angvel*l;if(i.rot+=r,r*r>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+r*i.axisy)*c;i.axisy=(p*i.axisy-r*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let o=B._nape.Config.staticCCDLinearThreshold*i.sweepRadius,r=B._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>o*o||i.angvel*i.angvel*e*e>r*r||i.type==3){let a=i.sweep_angvel;a<0&&(a=-a);let p=1/a,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,m=u.miny,d=u.maxx,y=u.maxy,b=a*e*h.sweepCoef*.008333333333333333|0;b>8&&(b=8);let f=a*e/b,P=e-i.sweepTime;if(P!=0){i.sweepTime=e;let z=P;if(i.posx+=i.velx*z,i.posy+=i.vely*z,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 w=C*C,g=1-.5*w,O=1-w*w/8,E=(g*i.axisx+C*i.axisy)*O;i.axisy=(g*i.axisy-C*i.axisx)*O,i.axisx=E}}}if(h.type==0){let z=h.circle;z.worldCOMx=z.body.posx+(z.body.axisy*z.localCOMx-z.body.axisx*z.localCOMy),z.worldCOMy=z.body.posy+(z.localCOMx*z.body.axisx+z.localCOMy*z.body.axisy),z.aabb.minx=z.worldCOMx-z.radius,z.aabb.miny=z.worldCOMy-z.radius,z.aabb.maxx=z.worldCOMx+z.radius,z.aabb.maxy=z.worldCOMy+z.radius}else if(h.type===2)h.capsule.__validate_aabb();else{let z=h.polygon,C=z.lverts.next,w=z.gverts.next,g=C;C=C.next,w.x=z.body.posx+(z.body.axisy*g.x-z.body.axisx*g.y),w.y=z.body.posy+(g.x*z.body.axisx+g.y*z.body.axisy),z.aabb.minx=w.x,z.aabb.miny=w.y,z.aabb.maxx=w.x,z.aabb.maxy=w.y;let O=z.gverts.next.next;for(;O!=null;){let E=O,M=C;C=C.next,E.x=z.body.posx+(z.body.axisy*M.x-z.body.axisx*M.y),E.y=z.body.posy+(M.x*z.body.axisx+M.y*z.body.axisy),E.x<z.aabb.minx&&(z.aabb.minx=E.x),E.x>z.aabb.maxx&&(z.aabb.maxx=E.x),E.y<z.aabb.miny&&(z.aabb.miny=E.y),E.y>z.aabb.maxy&&(z.aabb.maxy=E.y),O=O.next}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;let k=1,_=b;for(;k<_;){let z=k++,C=f*z*p,w=C-i.sweepTime;if(w!=0){i.sweepTime=C;let g=w;if(i.posx+=i.velx*g,i.posy+=i.vely*g,i.angvel!=0){let O=i.sweep_angvel*w;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 g=h.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 if(h.type===2)h.capsule.__validate_aabb();else{let g=h.polygon,O=g.lverts.next,E=g.gverts.next,M=O;O=O.next,E.x=g.body.posx+(g.body.axisy*M.x-g.body.axisx*M.y),E.y=g.body.posy+(M.x*g.body.axisx+M.y*g.body.axisy),g.aabb.minx=E.x,g.aabb.miny=E.y,g.aabb.maxx=E.x,g.aabb.maxy=E.y;let N=g.gverts.next.next;for(;N!=null;){let Z=N,A=O;O=O.next,Z.x=g.body.posx+(g.body.axisy*A.x-g.body.axisx*A.y),Z.y=g.body.posy+(A.x*g.body.axisx+A.y*g.body.axisy),Z.x<g.aabb.minx&&(g.aabb.minx=Z.x),Z.x>g.aabb.maxx&&(g.aabb.maxx=Z.x),Z.y<g.aabb.miny&&(g.aabb.miny=Z.y),Z.y>g.aabb.maxy&&(g.aabb.maxy=Z.y),N=N.next}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,y>u.maxy?u.maxy=y:y=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 o=l;if(i.posx+=i.velx*o,i.posy+=i.vely*o,i.angvel!=0){let r=i.sweep_angvel*l;if(i.rot+=r,r*r>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+r*i.axisy)*c;i.axisy=(p*i.axisy-r*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let o=B._nape.Config.staticCCDLinearThreshold*i.sweepRadius,r=B._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>o*o||i.angvel*i.angvel*e*e>r*r||i.type==3){let a=i.sweep_angvel;a<0&&(a=-a);let p=1/a,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,m=u.miny,d=u.maxx,y=u.maxy,b=a*e*h.sweepCoef*.008333333333333333|0;b>8&&(b=8);let f=a*e/b,P=e-i.sweepTime;if(P!=0){i.sweepTime=e;let z=P;if(i.posx+=i.velx*z,i.posy+=i.vely*z,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 w=C*C,g=1-.5*w,O=1-w*w/8,E=(g*i.axisx+C*i.axisy)*O;i.axisy=(g*i.axisy-C*i.axisx)*O,i.axisx=E}}}if(h.type==0){let z=h.circle;z.worldCOMx=z.body.posx+(z.body.axisy*z.localCOMx-z.body.axisx*z.localCOMy),z.worldCOMy=z.body.posy+(z.localCOMx*z.body.axisx+z.localCOMy*z.body.axisy),z.aabb.minx=z.worldCOMx-z.radius,z.aabb.miny=z.worldCOMy-z.radius,z.aabb.maxx=z.worldCOMx+z.radius,z.aabb.maxy=z.worldCOMy+z.radius}else if(h.type===2)h.capsule.__validate_aabb();else{let z=h.polygon,C=z.lverts.next,w=z.gverts.next,g=C;C=C.next,w.x=z.body.posx+(z.body.axisy*g.x-z.body.axisx*g.y),w.y=z.body.posy+(g.x*z.body.axisx+g.y*z.body.axisy),z.aabb.minx=w.x,z.aabb.miny=w.y,z.aabb.maxx=w.x,z.aabb.maxy=w.y;let O=z.gverts.next.next;for(;O!=null;){let E=O,M=C;C=C.next,E.x=z.body.posx+(z.body.axisy*M.x-z.body.axisx*M.y),E.y=z.body.posy+(M.x*z.body.axisx+M.y*z.body.axisy),E.x<z.aabb.minx&&(z.aabb.minx=E.x),E.x>z.aabb.maxx&&(z.aabb.maxx=E.x),E.y<z.aabb.miny&&(z.aabb.miny=E.y),E.y>z.aabb.maxy&&(z.aabb.maxy=E.y),O=O.next}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;let k=1,_=b;for(;k<_;){let z=k++,C=f*z*p,w=C-i.sweepTime;if(w!=0){i.sweepTime=C;let g=w;if(i.posx+=i.velx*g,i.posy+=i.vely*g,i.angvel!=0){let O=i.sweep_angvel*w;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 g=h.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=h.polygon,O=g.lverts.next,E=g.gverts.next,M=O;O=O.next,E.x=g.body.posx+(g.body.axisy*M.x-g.body.axisx*M.y),E.y=g.body.posy+(M.x*g.body.axisx+M.y*g.body.axisy),g.aabb.minx=E.x,g.aabb.miny=E.y,g.aabb.maxx=E.x,g.aabb.maxy=E.y;let N=g.gverts.next.next;for(;N!=null;){let Z=N,A=O;O=O.next,Z.x=g.body.posx+(g.body.axisy*A.x-g.body.axisx*A.y),Z.y=g.body.posy+(A.x*g.body.axisx+A.y*g.body.axisy),Z.x<g.aabb.minx&&(g.aabb.minx=Z.x),Z.x>g.aabb.maxx&&(g.aabb.maxx=Z.x),Z.y<g.aabb.miny&&(g.aabb.miny=Z.y),Z.y>g.aabb.maxy&&(g.aabb.maxy=Z.y),N=N.next}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,y>u.maxy?u.maxy=y:y=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 o=e.ws1,r=e.ws2,a=this.mrca1;for(;a.head!=null;){let x=a.head;a.head=x.next;let m=x;m.elt=null,m.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m,a.head==null&&(a.pushmod=!0),a.modified=!0,a.length--}a.pushmod=!0;let p=this.mrca2;for(;p.head!=null;){let x=p.head;p.head=x.next;let m=x;m.elt=null,m.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m,p.head==null&&(p.pushmod=!0),p.modified=!0,p.length--}if(p.pushmod=!0,o.cbSet!=null){let x=this.mrca1,m;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?m=new B._zpp.util.ZNPNode_ZPP_Interactor:(m=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m.next,m.next=null),m.elt=o;let d=m;d.next=x.head,x.head=d,x.modified=!0,x.length++}if(o.body.cbSet!=null){let x=this.mrca1,m=o.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=m;let y=d;y.next=x.head,x.head=y,x.modified=!0,x.length++}if(r.cbSet!=null){let x=this.mrca2,m;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?m=new B._zpp.util.ZNPNode_ZPP_Interactor:(m=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m.next,m.next=null),m.elt=r;let d=m;d.next=x.head,x.head=d,x.modified=!0,x.length++}if(r.body.cbSet!=null){let x=this.mrca2,m=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=m;let y=d;y.next=x.head,x.head=y,x.modified=!0,x.length++}let c=o.body.compound,h=r.body.compound;for(;c!=h;){let x=c==null?0:c.depth,m=h==null?0:h.depth;if(x<m){if(h.cbSet!=null){let d=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=h;let b=y;b.next=d.head,d.head=b,d.modified=!0,d.length++}h=h.compound}else{if(c.cbSet!=null){let d=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=c;let b=y;b.next=d.head,d.head=b,d.modified=!0,d.length++}c=c.compound}}let u=this.mrca1.head;for(;u!=null;){let x=u.elt,m=this.mrca2.head;for(;m!=null;){let d=m.elt,y=x.cbSet,b=d.cbSet,f=y.manager,P=null,_=(y.cbpairs.length<b.cbpairs.length?y.cbpairs:b.cbpairs).head;for(;_!=null;){let C=_.elt;if(C.a==y&&C.b==b||C.a==b&&C.b==y){P=C;break}_=_.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,_t.setlt(y,b)?(C.a=y,C.b=b):(C.a=b,C.b=y),P=C,y.cbpairs.add(P),b!=y&&b.cbpairs.add(P)}if(P.zip_listeners&&(P.zip_listeners=!1,P.__validate()),P.listeners.head==null){m=m.next;continue}let z=B._zpp.phys.ZPP_Interactor.get(x,d);if(l||e.intchange){z==null&&(z=Kt.get(x,d),this.add_callbackset(z));let C=y.manager,w=null,O=(y.cbpairs.length<b.cbpairs.length?y.cbpairs:b.cbpairs).head;for(;O!=null;){let A=O.elt;if(A.a==y&&A.b==b||A.a==b&&A.b==y){w=A;break}O=O.next}if(w==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,_t.setlt(y,b)?(A.a=y,A.b=b):(A.a=b,A.b=y),w=A,y.cbpairs.add(w),b!=y&&b.cbpairs.add(w)}w.zip_listeners&&(w.zip_listeners=!1,w.__validate());let E=w.listeners.head;for(;E!=null;){let A=E.elt;if(A.event==0&&(A.itype&e.type)!=0&&z.empty_arb(A.itype)){let S=this.push_callback(A);S.event=0;let L=z.int1,T=z.int2,G,q=A.options1,R=L.cbTypes;if(q.nonemptyintersection(R,q.includes)&&!q.nonemptyintersection(R,q.excludes)){let j=A.options2,V=T.cbTypes;G=j.nonemptyintersection(V,j.includes)&&!j.nonemptyintersection(V,j.excludes)}else G=!1;G?(S.int1=L,S.int2=T):(S.int1=T,S.int2=L),S.set=z}E=E.next}let M,N;N=!1;let Z=z.arbiters.head;for(;Z!=null;){if(Z.elt==e){N=!0;break}Z=Z.next}if(N)M=!1;else{let A=z.arbiters,S;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?S=new B._zpp.util.ZNPNode_ZPP_Arbiter:(S=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=S.next,S.next=null),S.elt=e;let L=S;L.next=A.head,A.head=L,A.modified=!0,A.length++,M=!0}M&&e.present++}else{e.present--,z.remove_arb(e);let C=y.manager,w=null,O=(y.cbpairs.length<b.cbpairs.length?y.cbpairs:b.cbpairs).head;for(;O!=null;){let M=O.elt;if(M.a==y&&M.b==b||M.a==b&&M.b==y){w=M;break}O=O.next}if(w==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,_t.setlt(y,b)?(M.a=y,M.b=b):(M.a=b,M.b=y),w=M,y.cbpairs.add(w),b!=y&&b.cbpairs.add(w)}w.zip_listeners&&(w.zip_listeners=!1,w.__validate());let E=w.listeners.head;for(;E!=null;){let M=E.elt;if(M.event==1&&(M.itype&e.type)!=0&&z.empty_arb(M.itype)){let N=this.push_callback(M);N.event=1;let Z=z.int1,A=z.int2,S,L=M.options1,T=Z.cbTypes;if(L.nonemptyintersection(T,L.includes)&&!L.nonemptyintersection(T,L.excludes)){let G=M.options2,q=A.cbTypes;S=G.nonemptyintersection(q,G.includes)&&!G.nonemptyintersection(q,G.excludes)}else S=!1;S?(N.int1=Z,N.int2=A):(N.int1=A,N.int2=Z),N.set=z}E=E.next}z.arbiters.head==null&&this.remove_callbackset(z)}m=m.next}u=u.next}}e.fresh=!1,e.intchange=!1}if(e.cleared||e.up_stamp+(e.type==Ie.COL?B._nape.Config.arbiterExpirationDelay:0)<this.stamp){if(e.type==Ie.SENSOR){let i=e.sensorarb;if(!i.cleared){let o=i.b1.arbiters,r=null,a=o.head,p=!1;for(;a!=null;){if(a.elt==i){let m,d;r==null?(m=o.head,d=m.next,o.head=d,o.head==null&&(o.pushmod=!0)):(m=r.next,d=m.next,r.next=d,d==null&&(o.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}r=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let m,d;h==null?(m=c.head,d=m.next,c.head=d,c.head==null&&(c.pushmod=!0)):(m=h.next,d=m.next,h.next=d,d==null&&(c.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,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=Ot.zpp_pool,Ot.zpp_pool=l}else if(e.type==Ie.FLUID){let i=e.fluidarb;if(!i.cleared){let o=i.b1.arbiters,r=null,a=o.head,p=!1;for(;a!=null;){if(a.elt==i){let m,d;r==null?(m=o.head,d=m.next,o.head=d,o.head==null&&(o.pushmod=!0)):(m=r.next,d=m.next,r.next=d,d==null&&(o.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}r=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let m,d;h==null?(m=c.head,d=m.next,c.head=d,c.head==null&&(c.pushmod=!0)):(m=h.next,d=m.next,h.next=d,d==null&&(c.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,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=Pt.zpp_pool,Pt.zpp_pool=l,i.pre_dt=-1}else{let i=e.colarb;if(!i.cleared){let o=i.b1.arbiters,r=null,a=o.head,p=!1;for(;a!=null;){if(a.elt==i){let m,d;r==null?(m=o.head,d=m.next,o.head=d,o.head==null&&(o.pushmod=!0)):(m=r.next,d=m.next,r.next=d,d==null&&(o.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}r=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let m,d;h==null?(m=c.head,d=m.next,c.head=d,c.head==null&&(c.pushmod=!0)):(m=h.next,d=m.next,h.next=d,d==null&&(c.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,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 o=i.contacts,r=o.next;o.pop();let a=r;a.arbiter=null,a.next=Pe.zpp_pool,Pe.zpp_pool=a;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=ut.zpp_pool,ut.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!=Ie.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 o=i.b1.smass+i.b2.smass;i.hc2=!1;let r=!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 f=i.contacts,P,k;c==null?(P=f.next,k=P.next,f.next=k,f.next==null&&(f.pushmod=!0)):(P=c.next,k=P.next,c.next=k,k==null&&(f.pushmod=!0)),P._inuse=!1,f.modified=!0,f.length--,f.pushmod=!0,x=k;let _=i.innards,z,C;h==null?(z=_.next,C=z.next,_.next=C,_.next==null&&(_.pushmod=!0)):(z=h.next,C=z.next,h.next=C,C==null&&(_.pushmod=!0)),z._inuse=!1,_.modified=!0,_.length--,_.pushmod=!0,u=C;let w=d;w.arbiter=null,w.next=Pe.zpp_pool,Pe.zpp_pool=w;continue}let y=d.inner,b=d.active;if(d.active=d.stamp==i.stamp,d.active){r?(r=!1,i.c1=y,i.oc1=d):(i.hc2=!0,i.c2=y,i.oc2=d),y.r2x=d.px-i.b2.posx,y.r2y=d.py-i.b2.posy,y.r1x=d.px-i.b1.posx,y.r1y=d.py-i.b1.posy;let f=y.r2x*i.nx+y.r2y*i.ny,P=o+i.b2.sinertia*(f*f),k=y.r1x*i.nx+y.r1y*i.ny;P+=i.b1.sinertia*(k*k),y.tMass=P<B._nape.Config.epsilon*B._nape.Config.epsilon?0:1/P;let _=i.ny*y.r2x-i.nx*y.r2y,z=o+i.b2.sinertia*(_*_),C=i.ny*y.r1x-i.nx*y.r1y;z+=i.b1.sinertia*(C*C),y.nMass=z<B._nape.Config.epsilon*B._nape.Config.epsilon?0:1/z;let w=0,g=0,O=i.b2.angvel+i.b2.kinangvel;w=i.b2.velx+i.b2.kinvelx-y.r2y*O,g=i.b2.vely+i.b2.kinvely+y.r2x*O,O=i.b1.angvel+i.b1.kinangvel,w-=i.b1.velx+i.b1.kinvelx-y.r1y*O,g-=i.b1.vely+i.b1.kinvely+y.r1x*O;let E=i.nx*w+i.ny*g;d.elasticity=i.restitution,y.bounce=E*d.elasticity,y.bounce>-B._nape.Config.elasticThreshold&&(y.bounce=0),E=g*i.nx-w*i.ny;let M=B._nape.Config.staticFrictionThreshold;E*E>M*M?y.friction=i.dyn_fric:y.friction=i.stat_fric,y.jnAcc*=l,y.jtAcc*=l}b!=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 y=i.oc1;i.oc1=i.oc2,i.oc2=y,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(r=!0)}else i.hpc2=!1;if(i.jrAcc*=l,r||(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=o+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=o+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=o+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 y=i.kMassa*i.kMassc-i.kMassb*i.kMassb;if(y!=y)i.kMassa=i.kMassb=i.kMassc=0;else if(y==0){let b=0;i.kMassa!=0?i.kMassa=1/i.kMassa:(i.kMassa=0,b|=1),i.kMassc!=0?i.kMassc=1/i.kMassc:(i.kMassc=0,b|=2),i.kMassb=0}else{y=1/y;let b=i.kMassc*y;i.kMassc=i.kMassa*y,i.kMassa=b,i.kMassb*=-y}}else{if(i.hc2=!1,i.oc2.dist<i.oc1.dist){let y=i.c1;i.c1=i.c2,i.c2=y}i.oc2.active=!1,i.contacts.modified=!0}i.surfacex=i.b2.svelx,i.surfacey=i.b2.svely;let m=1;i.surfacex+=i.b1.svelx*m,i.surfacey+=i.b1.svely*m,i.surfacex=-i.surfacex,i.surfacey=-i.surfacey,i.rMass=i.b1.sinertia+i.b2.sinertia,i.rMass!=0&&(i.rMass=1/i.rMass),r&&(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 o=0,r=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(o=i.ws1.fluidProperties.gravityx,r=i.ws1.fluidProperties.gravityy):(o=this.gravityx,r=this.gravityy);let a=0,p=0;i.ws2.fluidEnabled&&i.ws2.fluidProperties.wrap_gravity!=null?(a=i.ws2.fluidProperties.gravityx,p=i.ws2.fluidProperties.gravityy):(a=this.gravityx,p=this.gravityy);let c=0,h=0;if(i.ws1.fluidEnabled&&i.ws2.fluidEnabled){let m=i.overlap*i.ws1.fluidProperties.density,d=i.overlap*i.ws2.fluidProperties.density;if(m>d){let y=m+d;c-=o*y,h-=r*y}else if(m<d){let y=m+d;c+=a*y,h+=p*y}else{let y=0,b=0;y=o+a,b=r+p;let f=.5;if(y*=f,b*=f,i.ws1.worldCOMx*y+i.ws1.worldCOMy*b>i.ws2.worldCOMx*y+i.ws2.worldCOMy*b){let P=m+d;c-=y*P,h-=b*P}else{let P=m+d;c+=y*P,h+=b*P}}}else if(i.ws1.fluidEnabled){let d=i.overlap*i.ws1.fluidProperties.density;c-=o*d,h-=r*d}else if(i.ws2.fluidEnabled){let d=i.overlap*i.ws2.fluidProperties.density;c+=a*d,h+=p*d}let u=t;if(c*=u,h*=u,i.buoyx=c,i.buoyy=h,i.b1.type==2){let m=i.b1.imass;i.b1.velx-=c*m,i.b1.vely-=h*m,i.b1.angvel-=(h*i.r1x-c*i.r1y)*i.b1.iinertia}if(i.b2.type==2){let m=i.b2.imass;i.b2.velx+=c*m,i.b2.vely+=h*m,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 m=0;if(i.ws1.fluidEnabled&&(i.ws2.validate_angDrag(),m+=i.ws1.fluidProperties.viscosity*i.ws2.angDrag*i.overlap/i.ws2.area),i.ws2.fluidEnabled&&(i.ws1.validate_angDrag(),m+=i.ws2.fluidProperties.viscosity*i.ws1.angDrag*i.overlap/i.ws1.area),m!=0){let f=i.b1.sinertia+i.b2.sinertia;f!=0?i.wMass=1/f:i.wMass=0,m*=4e-4;let P=2*Math.PI*m;i.agamma=1/(t*P*(2+P*t));let k=1/(1+i.agamma),_=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)),y=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+y*y<B._nape.Config.epsilon*B._nape.Config.epsilon)){let f=d*d+y*y,k=1/Math.sqrt(f);d*=k,y*=k,i.nx=d,i.ny=y}let b=0;if(i.ws1.fluidEnabled){let f=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)b-=f*i.ws2.circle.radius*B._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else if(i.ws2.type===2){let P=i.ws2.capsule.radius;b-=f*P*B._nape.Config.fluidLinearDrag/(2*P*Math.PI)}else{let P=i.ws2.polygon,k=0,_=0,z=P.edges.head;for(;z!=null;){let C=z.elt;k+=C.length;let w=f*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);w>0&&(w*=-B._nape.Config.fluidVacuumDrag,w=w),_-=w*.5*B._nape.Config.fluidLinearDrag,z=z.next}b+=_/k}}if(i.ws2.fluidEnabled){let f=-i.ws2.fluidProperties.viscosity*i.overlap/i.ws1.area;if(i.ws1.type==0)b-=f*i.ws1.circle.radius*B._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else if(i.ws1.type===2){let P=i.ws1.capsule.radius;b-=f*P*B._nape.Config.fluidLinearDrag/(2*P*Math.PI)}else{let P=i.ws1.polygon,k=0,_=0,z=P.edges.head;for(;z!=null;){let C=z.elt;k+=C.length;let w=f*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);w>0&&(w*=-B._nape.Config.fluidVacuumDrag,w=w),_-=w*.5*B._nape.Config.fluidLinearDrag,z=z.next}b+=_/k}}if(b!=0){let f=i.b1.smass+i.b2.smass,P=0,k=0,_=0;if(P=f,k=0,_=f,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,_+=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,_+=E*i.r2x}let z=P*_-k*k;if(z!=z)_=0,k=_,P=k;else if(z==0){let E=0;P!=0?P=1/P:(P=0,E|=1),_!=0?_=1/_:(_=0,E|=2),k=0}else{z=1/z;let E=_*z;_=P*z,P=E,k*=-z}i.vMassa=P,i.vMassb=k,i.vMassc=_;let C,w=2*Math.PI*b;i.lgamma=1/(t*w*(2+w*t));let g=1/(1+i.lgamma);C=t*w*w*i.lgamma,i.lgamma*=g;let O=g;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,o=null,r=null,a=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,m,d;o==null?(m=x.next,d=m.next,x.next=d,x.next==null&&(x.pushmod=!0)):(m=o.next,d=m.next,o.next=d,d==null&&(x.pushmod=!0)),m._inuse=!1,x.modified=!0,x.length--,x.pushmod=!0,p=d;let y=i.innards,b,f;r==null?(b=y.next,f=b.next,y.next=f,y.next==null&&(y.pushmod=!0)):(b=r.next,f=b.next,r.next=f,f==null&&(y.pushmod=!0)),b._inuse=!1,y.modified=!0,y.length--,y.pushmod=!0,a=f;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),o=p,r=a,a=a.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}_prestepArbiterList(e,t,n){let s=null,i=e.head;for(;i!=null;){let l=i.elt;if(this.presteparb(l,n)){let o,r;s==null?(o=e.head,r=o.next,e.head=r,e.head==null&&(e.pushmod=!0)):(o=s.next,r=o.next,s.next=r,r==null&&(e.pushmod=!0)),o.elt=null,o.next=t.zpp_pool,t.zpp_pool=o,e.modified=!0,e.length--,e.pushmod=!0,i=r;continue}s=i,i=i.next}}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let r=n.elt;if(r.preStep(e)){n=this.live_constraints.erase(t),r.broken(),this.constraintCbBreak(r),r.removeOnBreak?(r.component.sleeping=!0,this.midstep=!1,r.compound!=null?r.compound.wrap_constraints.remove(r.outer):this.wrap_constraints.remove(r.outer),this.midstep=!0):r.active=!1,r.clearcache();continue}t=n,n=n.next}let s=null,i=this.c_arbiters_true,l=i.head,o=this.c_arbiters_false!=null;for(o&&l==null&&(o=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);l!=null;){let r=l.elt;if(this.presteparb(r,e)){let a,p;s==null?(a=i.head,p=a.next,i.head=p,i.head==null&&(i.pushmod=!0)):(a=s.next,p=a.next,s.next=p,p==null&&(i.pushmod=!0));let c=a;c.elt=null,c.next=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=c,i.modified=!0,i.length--,i.pushmod=!0,l=p,o&&l==null&&(o=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);continue}s=l,l=l.next,o&&l==null&&(o=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null)}this._prestepArbiterList(this.f_arbiters,B._zpp.util.ZNPNode_ZPP_FluidArbiter,e),this._prestepArbiterList(this.s_arbiters,B._zpp.util.ZNPNode_ZPP_SensorArbiter,e)}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 o=i.b2.imass;i.b2.velx+=i.dampx*o,i.b2.vely+=i.dampy*o,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,o=i.ny*i.c1.jnAcc+i.nx*i.c1.jtAcc,r=i.b1.imass;i.b1.velx-=l*r,i.b1.vely-=o*r,i.b1.angvel-=i.b1.iinertia*(o*i.c1.r1x-l*i.c1.r1y);let a=i.b2.imass;if(i.b2.velx+=l*a,i.b2.vely+=o*a,i.b2.angvel+=i.b2.iinertia*(o*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),m=p.vMassa*u+p.vMassb*x;x=p.vMassb*u+p.vMassc*x,u=m;let d=p.lgamma;u-=p.dampx*d,x-=p.dampy*d;let y=1;p.dampx+=u*y,p.dampy+=x*y;let b=p.b1.imass;p.b1.velx-=u*b,p.b1.vely-=x*b;let f=p.b2.imass;p.b2.velx+=u*f,p.b2.vely+=x*f,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,o=this.live_constraints.head;for(;o!=null;){let p=o.elt;if(p.applyImpulseVel()){o=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=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),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,m=p.c1.jtAcc,d=m-u;d>x?d=x:d<-x&&(d=-x),u=d-m,p.c1.jtAcc=d;let y=-p.ny*u,b=p.nx*u;if(p.b2.velx+=y*p.b2.imass,p.b2.vely+=b*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=b*p.b1.imass,p.b2.angvel+=p.rt1b*u*p.b2.iinertia,p.b1.angvel-=p.rt1a*u*p.b1.iinertia,p.hc2){let f=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-f*p.ny+p.surfacex)*p.c2.tMass,x=p.c2.friction*p.c2.jnAcc,m=p.c2.jtAcc,d=m-u,d>x?d=x:d<-x&&(d=-x),u=d-m,p.c2.jtAcc=d,y=-p.ny*u,b=p.nx*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=b*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=b*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),f=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,_=p.c2.jnAcc,z=c*p.nx+h*p.ny+p.surfacey+p.c1.bounce-(p.Ka*k+p.Kb*_),C=f*p.nx+P*p.ny+p.surfacey+p.c2.bounce-(p.Kb*k+p.Kc*_),w=-(p.kMassa*z+p.kMassb*C),g=-(p.kMassb*z+p.kMassc*C);w>=0&&g>=0?(z=w-k,C=g-_,p.c1.jnAcc=w,p.c2.jnAcc=g):(w=-p.c1.nMass*z,w>=0&&p.Kb*w+C>=0?(z=w-k,C=-_,p.c1.jnAcc=w,p.c2.jnAcc=0):(g=-p.c2.nMass*C,g>=0&&p.Kb*g+z>=0?(z=-k,C=g-_,p.c1.jnAcc=0,p.c2.jnAcc=g):z>=0&&C>=0?(z=-k,C=-_,p.c1.jnAcc=p.c2.jnAcc=0):(z=0,C=0))),u=z+C,y=p.nx*u,b=p.ny*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=b*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=b*p.b1.imass,p.b2.angvel+=(p.rn1b*z+p.rn2b*C)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*z+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,m=p.jrAcc,p.jrAcc-=u,p.jrAcc>x?p.jrAcc=x:p.jrAcc<-x&&(p.jrAcc=-x),u=p.jrAcc-m,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,m=p.c1.jnAcc,d=m-u,d<0&&(d=0),u=d-m,p.c1.jnAcc=d,y=p.nx*u,b=p.ny*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=b*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=b*p.b1.imass,p.b2.angvel+=p.rn1b*u*p.b2.iinertia,p.b1.angvel-=p.rn1a*u*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 s=t++,i=null,l=this.live_constraints.head;for(;l!=null;){let a=l.elt;if(!a.__velocity&&a.stiff&&a.applyImpulsePos()){l=this.live_constraints.erase(i),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}i=l,l=l.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,h=0;c=a.b2.axisy*p.lr2x-a.b2.axisx*p.lr2y,h=p.lr2x*a.b2.axisx+p.lr2y*a.b2.axisy;let u=1;c+=a.b2.posx*u,h+=a.b2.posy*u;let x=0,m=0;x=a.b1.axisy*p.lr1x-a.b1.axisx*p.lr1y,m=p.lr1x*a.b1.axisx+p.lr1y*a.b1.axisy;let d=1;x+=a.b1.posx*d,m+=a.b1.posy*d;let y=0,b=0;y=c-x,b=h-m;let f=Math.sqrt(y*y+b*b),P=a.radius-B._nape.Config.collisionSlop,k=f-P;if(y*a.nx+b*a.ny<0&&(y=-y,b=-b,k-=a.radius),k<0)if(f<B._nape.Config.epsilon)a.b1.smass!=0?a.b1.posx+=B._nape.Config.epsilon*10:a.b2.posx+=B._nape.Config.epsilon*10;else{let _=1/f;y*=_,b*=_;let z=.5*(x+c),C=.5*(m+h),w=f-P;x=z-a.b1.posx,m=C-a.b1.posy,c=z-a.b2.posx,h=C-a.b2.posy;let g=b*x-y*m,O=b*c-y*h,E=a.b2.smass+O*O*a.b2.sinertia+a.b1.smass+g*g*a.b1.sinertia;if(E!=0){let M=-a.biasCoef*w/E,N=0,Z=0,A=M;N=y*A,Z=b*A;let S=a.b1.imass;a.b1.posx-=N*S,a.b1.posy-=Z*S;let L=a.b1,T=-g*a.b1.iinertia*M;if(L.rot+=T,T*T>1e-4)L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.rot);else{let j=T*T,V=1-.5*j,K=1-j*j/8,$=(V*L.axisx+T*L.axisy)*K;L.axisy=(V*L.axisy-T*L.axisx)*K,L.axisx=$}let G=a.b2.imass;a.b2.posx+=N*G,a.b2.posy+=Z*G;let q=a.b2,R=O*a.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,V=1-.5*j,K=1-j*j/8,$=(V*q.axisx+R*q.axisy)*K;q.axisy=(V*q.axisy-R*q.axisx)*K,q.axisx=$}}}}else{let p=0,c=0,h,u=0,x=0,m=0,d=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,h=a.lproj+(p*a.b1.posx+c*a.b1.posy),u=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 f=1;if(u+=a.b2.posx*f,x+=a.b2.posy*f,a.hpc2){m=a.b2.axisy*a.c2.lr1x-a.b2.axisx*a.c2.lr1y,d=a.c2.lr1x*a.b2.axisx+a.c2.lr1y*a.b2.axisy;let P=1;m+=a.b2.posx*P,d+=a.b2.posy*P}}else{p=a.b2.axisy*a.lnormx-a.b2.axisx*a.lnormy,c=a.lnormx*a.b2.axisx+a.lnormy*a.b2.axisy,h=a.lproj+(p*a.b2.posx+c*a.b2.posy),u=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 f=1;if(u+=a.b1.posx*f,x+=a.b1.posy*f,a.hpc2){m=a.b1.axisy*a.c2.lr1x-a.b1.axisx*a.c2.lr1y,d=a.c2.lr1x*a.b1.axisx+a.c2.lr1y*a.b1.axisy;let P=1;m+=a.b1.posx*P,d+=a.b1.posy*P}}let y=u*p+x*c-h-a.radius;y+=B._nape.Config.collisionSlop;let b=0;if(a.hpc2&&(b=m*p+d*c-h-a.radius,b+=B._nape.Config.collisionSlop),y<0||b<0){a.rev&&(p=-p,c=-c);let f=0,P=0;f=u-a.b1.posx,P=x-a.b1.posy;let k=0,_=0;k=u-a.b2.posx,_=x-a.b2.posy;let z=0,C=0,w=0,g=0;if(a.hpc2){z=m-a.b1.posx,C=d-a.b1.posy,w=m-a.b2.posx,g=d-a.b2.posy;let O=c*f-p*P,E=c*k-p*_,M=c*z-p*C,N=c*w-p*g,Z=a.b1.smass+a.b2.smass;a.kMassa=Z+a.b1.sinertia*O*O+a.b2.sinertia*E*E,a.kMassb=Z+a.b1.sinertia*O*M+a.b2.sinertia*E*N,a.kMassc=Z+a.b1.sinertia*M*M+a.b2.sinertia*N*N;let A=0,S=0,L=0;A=a.kMassa,S=a.kMassb,L=a.kMassc;let T=y*a.biasCoef,G=b*a.biasCoef;for(;;){let q=0,R=0;q=T,R=G,q=-q,R=-R;let j=a.kMassa*a.kMassc-a.kMassb*a.kMassb;if(j!=j)R=0,q=R;else if(j==0)a.kMassa!=0?q/=a.kMassa:q=0,a.kMassc!=0?R/=a.kMassc:R=0;else{j=1/j;let $=j*(a.kMassc*q-a.kMassb*R);R=j*(a.kMassa*R-a.kMassb*q),q=$}if(q>=0&&R>=0){let $=(q+R)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let Y=a.b1,X=-a.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 D=X*X,I=1-.5*D,U=1-D*D/8,Q=(I*Y.axisx+X*Y.axisy)*U;Y.axisy=(I*Y.axisy-X*Y.axisx)*U,Y.axisx=Q}let ee=(q+R)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let J=a.b2,F=a.b2.iinertia*(E*q+N*R);if(J.rot+=F,F*F>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let D=F*F,I=1-.5*D,U=1-D*D/8,Q=(I*J.axisx+F*J.axisy)*U;J.axisy=(I*J.axisy-F*J.axisx)*U,J.axisx=Q}break}q=-T/A,R=0;let V=S*q+G;if(q>=0&&V>=0){let $=(q+R)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let Y=a.b1,X=-a.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 D=X*X,I=1-.5*D,U=1-D*D/8,Q=(I*Y.axisx+X*Y.axisy)*U;Y.axisy=(I*Y.axisy-X*Y.axisx)*U,Y.axisx=Q}let ee=(q+R)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let J=a.b2,F=a.b2.iinertia*(E*q+N*R);if(J.rot+=F,F*F>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let D=F*F,I=1-.5*D,U=1-D*D/8,Q=(I*J.axisx+F*J.axisy)*U;J.axisy=(I*J.axisy-F*J.axisx)*U,J.axisx=Q}break}q=0,R=-G/L;let K=S*R+T;if(R>=0&&K>=0){let $=(q+R)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let Y=a.b1,X=-a.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 D=X*X,I=1-.5*D,U=1-D*D/8,Q=(I*Y.axisx+X*Y.axisy)*U;Y.axisy=(I*Y.axisy-X*Y.axisx)*U,Y.axisx=Q}let ee=(q+R)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let J=a.b2,F=a.b2.iinertia*(E*q+N*R);if(J.rot+=F,F*F>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let D=F*F,I=1-.5*D,U=1-D*D/8,Q=(I*J.axisx+F*J.axisy)*U;J.axisy=(I*J.axisy-F*J.axisx)*U,J.axisx=Q}break}break}}else{let O=c*f-p*P,E=c*k-p*_,M=a.b2.smass+E*E*a.b2.sinertia+a.b1.smass+O*O*a.b1.sinertia;if(M!=0){let N=-a.biasCoef*y/M,Z=0,A=0,S=N;Z=p*S,A=c*S;let L=a.b1.imass;a.b1.posx-=Z*L,a.b1.posy-=A*L;let T=a.b1,G=-O*a.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 V=G*G,K=1-.5*V,$=1-V*V/8,Y=(K*T.axisx+G*T.axisy)*$;T.axisy=(K*T.axisy-G*T.axisx)*$,T.axisx=Y}let q=a.b2.imass;a.b2.posx+=Z*q,a.b2.posy+=A*q;let R=a.b2,j=E*a.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 V=j*j,K=1-.5*V,$=1-V*V/8,Y=(K*R.axisx+j*R.axisy)*$;R.axisy=(K*R.axisy-j*R.axisx)*$,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 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 o=!1;for(;s!=null&&l!=null;){if(s==l){o=s.ignore;break}s.depth<l.depth?l=l.group:s=s.group}return o}}}interactionType(e,t,n,s){let i;i=!1;let l=n.constraints.head;for(;l!=null;){let r=l.elt;if(r.ignore&&r.pair_exists(n.id,s.id)){i=!0;break}l=l.next}let o;if(i)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 h=c==null?null:c.group;if(h==null)p=!1;else{let u=!1;for(;a!=null&&h!=null;){if(a==h){u=a.ignore;break}a.depth<h.depth?h=h.group:a=a.group}p=u}}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&&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,o=e.body,r=t.body,a;a=!1;let p=o.constraints.head;for(;p!=null;){let u=p.elt;if(u.ignore&&u.pair_exists(o.id,r.id)){a=!0;break}p=p.next}let c,h;if(a)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,m;if(x==null)m=!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 y=d==null?null:d.group;if(y==null)m=!1;else{let b=!1;for(;x!=null&&y!=null;){if(x==y){b=x.ignore;break}x.depth<y.depth?y=y.group:x=x.group}m=b}}h=!m}if(h){let u;if(e.sensorEnabled||t.sensorEnabled){let x=e.filter,m=t.filter;u=(x.sensorMask&m.sensorGroup)!=0&&(m.sensorMask&x.sensorGroup)!=0}else u=!1;if(u)c=2;else{let x;if(e.fluidEnabled||t.fluidEnabled){let m=e.filter,d=t.filter;x=(m.fluidMask&d.fluidGroup)!=0&&(d.fluidMask&m.fluidGroup)!=0}else x=!1;if(x&&!(o.imass==0&&r.imass==0&&o.iinertia==0&&r.iinertia==0))c=0;else{let m=e.filter,d=t.filter;c=(m.collisionMask&d.collisionGroup)!=0&&(d.collisionMask&m.collisionGroup)!=0&&!(o.imass==0&&r.imass==0&&o.iinertia==0&&r.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 m=u==t;if(c==0){let d;if(s==null){let k=null,z=(o.arbiters.length<r.arbiters.length?o:r).arbiters.head;for(;z!=null;){let C=z.elt;if(C.id==u.id&&C.di==x.id){k=C;break}z=z.next}d=k}else d=s;let y=d==null,b,f=!1;if(y)Pt.zpp_pool==null?b=new Pt:(b=Pt.zpp_pool,Pt.zpp_pool=b.next,b.next=null);else if(d.fluidarb==null){d.cleared=!0;{let _=d.b1.arbiters,z=null,C=_.head,w=!1;for(;C!=null;){if(C.elt==d){let g,O;z==null?(g=_.head,O=g.next,_.head=O,_.head==null&&(_.pushmod=!0)):(g=z.next,O=g.next,z.next=O,O==null&&(_.pushmod=!0));let E=g;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,_.modified=!0,_.length--,_.pushmod=!0,w=!0;break}z=C,C=C.next}}{let _=d.b2.arbiters,z=null,C=_.head,w=!1;for(;C!=null;){if(C.elt==d){let g,O;z==null?(g=_.head,O=g.next,_.head=O,_.head==null&&(_.pushmod=!0)):(g=z.next,O=g.next,z.next=O,O==null&&(_.pushmod=!0));let E=g;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,_.modified=!0,_.length--,_.pushmod=!0,w=!0;break}z=C,C=C.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Pt.zpp_pool==null?b=new Pt:(b=Pt.zpp_pool,Pt.zpp_pool=b.next,b.next=null),b.intchange=!0,y=!0,f=!0}else b=d.fluidarb;let P=4;if(y||b.stamp!=this.stamp||i)if(b.stamp=this.stamp,Ce.flowCollide(u,x,b)){if(y){let k=x.id;b.b1=e.body,b.ws1=e,b.b2=t.body,b.ws2=t,b.id=u.id,b.di=k;let _=b.b1.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=b;let C=z;C.next=_.head,_.head=C,_.modified=!0,_.length++;let w=b.b2.arbiters,g;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?g=new B._zpp.util.ZNPNode_ZPP_Arbiter:(g=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=g.next,g.next=null),g.elt=b;let O=g;O.next=w.head,w.head=O,w.modified=!0,w.length++,b.active=!0,b.present=0,b.cleared=!1,b.sleeping=!1,b.fresh=!1,b.presentable=!1,b.nx=0,b.ny=1,b.dampx=0,b.dampy=0,b.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=b;let N=M;N.next=E.head,E.head=N,E.modified=!0,E.length++,b.fresh=!f}else b.fresh=b.up_stamp<this.stamp-1||b.endGenerated==this.stamp&&i;if(b.up_stamp=b.stamp,b.fresh||(b.immState&4)==0){b.immState=1;let k=!1,_=b.ws1.id>b.ws2.id?b.ws2:b.ws1,z=b.ws1.id>b.ws2.id?b.ws1:b.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 w=this.mrca2;for(;w.head!=null;){let M=w.head;w.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,w.head==null&&(w.pushmod=!0),w.modified=!0,w.length--}if(w.pushmod=!0,_.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=_;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(_.body.cbSet!=null){let M=this.mrca1,N=_.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 A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}if(z.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=z;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(z.body.cbSet!=null){let M=this.mrca2,N=z.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 A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}let g=_.body.compound,O=z.body.compound;for(;g!=O;){let M=g==null?0:g.depth,N=O==null?0:O.depth;if(M<N){if(O.cbSet!=null){let Z=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=O;let S=A;S.next=Z.head,Z.head=S,Z.modified=!0,Z.length++}O=O.compound}else{if(g.cbSet!=null){let Z=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=g;let S=A;S.next=Z.head,Z.head=S,Z.modified=!0,Z.length++}g=g.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,N=this.mrca2.head;for(;N!=null;){let Z=N.elt,A=M.cbSet,S=Z.cbSet,L=A.manager,T=null,q=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;q!=null;){let F=q.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){T=F;break}q=q.next}if(T==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,_t.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),T=F,A.cbpairs.add(T),S!=A&&S.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,V=this.prelisteners;for(;V.head!=null;){let F=V.head;V.head=F.next;let D=F;D.elt=null,D.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=D,V.head==null&&(V.pushmod=!0),V.modified=!0,V.length--}V.pushmod=!0;let K=null,$=A.manager,Y=null,ee=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;ee!=null;){let F=ee.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){Y=F;break}ee=ee.next}if(Y==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,_t.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),Y=F,A.cbpairs.add(Y),S!=A&&S.cbpairs.add(Y)}Y.zip_listeners&&(Y.zip_listeners=!1,Y.__validate());let J=Y.listeners.head;for(;J!=null;){let F=J.elt;if(F.event==5&&(F.itype&P)!=0){let D=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=F;let U=I;K==null?(U.next=D.head,D.head=U):(U.next=K.next,K.next=U),D.pushmod=D.modified=!0,D.length++,K=U,k=k||!F.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=Kt.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}b.mutable=!0,b.wrap_position!=null&&(b.wrap_position.zpp_inner._immutable=!1);let F=b.active;b.active=!0;let D=!1;this.precb.zpp_inner.pre_arbiter=b,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 Q=this.precb.zpp_inner,W=R.int1,ie=R.int2,oe,se=U.options1,ne=W.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=U.options2,he=ie.cbTypes;oe=le.nonemptyintersection(he,le.includes)&&!le.nonemptyintersection(he,le.excludes)}else oe=!1;oe?(Q.int1=W,Q.int2=ie):(Q.int1=ie,Q.int2=W),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let re=U.handlerp(this.precb);if(re!=null){let le;H.PreFlag_ACCEPT==null&&(H.internal=!0,H.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,H.internal=!1),re==H.PreFlag_ACCEPT?le=5:(H.PreFlag_ACCEPT_ONCE==null&&(H.internal=!0,H.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,H.internal=!1),re==H.PreFlag_ACCEPT_ONCE?le=1:(H.PreFlag_IGNORE==null&&(H.internal=!0,H.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,H.internal=!1),le=re==H.PreFlag_IGNORE?6:2)),b.immState=le}I=I.next}if(b.mutable=!1,b.wrap_position!=null&&(b.wrap_position.zpp_inner._immutable=!0),b.active=F,R!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7&&(R.COLLISIONstate=b.immState,R.SENSORstate=b.immState),R.FLUIDstate=b.immState,U=U.next}}else R==null?(b.immState&4)==0&&(b.immState=1):b.immState=R.FLUIDstate;N=N.next}E=E.next}if(k&&(b.immState&4)==0){if(b.b1.type==2){let M=b.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(b.b1.type==2){let M=b.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((b.immState&1)!=0){if(b.b1.type==2&&b.b1.component.sleeping){let k=b.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(b.b2.type==2&&b.b2.component.sleeping){let k=b.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(b.sleeping){b.sleeping=!1;let k=this.f_arbiters,_;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(_=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=_.next,_.next=null),_.elt=b;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++}l=b}else if(y){let k=b;k.next=Pt.zpp_pool,Pt.zpp_pool=k,l=null}else l=b;else l=b}else if(c==1){let d=n?this.c_arbiters_true:this.c_arbiters_false,y;if(s==null){let _=null,C=(o.arbiters.length<r.arbiters.length?o:r).arbiters.head;for(;C!=null;){let w=C.elt;if(w.id==u.id&&w.di==x.id){_=w;break}C=C.next}y=_}else y=s;let b=y==null,f,P=!1;if(b)ut.zpp_pool==null?f=new ut:(f=ut.zpp_pool,ut.zpp_pool=f.next,f.next=null),f.stat=n;else if(y.colarb==null){y.cleared=!0;{let z=y.b1.arbiters,C=null,w=z.head,g=!1;for(;w!=null;){if(w.elt==y){let O,E;C==null?(O=z.head,E=O.next,z.head=E,z.head==null&&(z.pushmod=!0)):(O=C.next,E=O.next,C.next=E,E==null&&(z.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,z.modified=!0,z.length--,z.pushmod=!0,g=!0;break}C=w,w=w.next}}{let z=y.b2.arbiters,C=null,w=z.head,g=!1;for(;w!=null;){if(w.elt==y){let O,E;C==null?(O=z.head,E=O.next,z.head=E,z.head==null&&(z.pushmod=!0)):(O=C.next,E=O.next,C.next=E,E==null&&(z.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,z.modified=!0,z.length--,z.pushmod=!0,g=!0;break}C=w,w=w.next}}y.pair!=null&&(y.pair.arb=null,y.pair=null),y.active=!1,this.f_arbiters.modified=!0,ut.zpp_pool==null?f=new ut:(f=ut.zpp_pool,ut.zpp_pool=f.next,f.next=null),f.intchange=!0,f.stat=n,b=!0,P=!0}else f=y.colarb,m=u!=f.s1,f.stat!=n&&(f.stat=n,f.sleeping||((n?this.c_arbiters_false:this.c_arbiters_true).remove(f),d.add(f)));let k=1;if(b||f.stamp!=this.stamp||i)if(f.stamp=this.stamp,Ce.contactCollide(u,x,f,m)){if(b){let _=x.id;f.b1=e.body,f.ws1=e,f.b2=t.body,f.ws2=t,f.id=u.id,f.di=_;let z=f.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=f;let w=C;w.next=z.head,z.head=w,z.modified=!0,z.length++;let g=f.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=f;let E=O;E.next=g.head,g.head=E,g.modified=!0,g.length++,f.active=!0,f.present=0,f.cleared=!1,f.sleeping=!1,f.fresh=!1,f.presentable=!1,f.s1=e,f.s2=t,f.userdef_restitution||(f.s1.material.elasticity<=-1/0||f.s2.material.elasticity<=-1/0?f.restitution=0:f.s1.material.elasticity>=1/0||f.s2.material.elasticity>=1/0?f.restitution=1:f.restitution=(f.s1.material.elasticity+f.s2.material.elasticity)/2,f.restitution<0&&(f.restitution=0),f.restitution>1&&(f.restitution=1)),f.userdef_dyn_fric||(f.dyn_fric=Math.sqrt(f.s1.material.dynamicFriction*f.s2.material.dynamicFriction)),f.userdef_stat_fric||(f.stat_fric=Math.sqrt(f.s1.material.staticFriction*f.s2.material.staticFriction)),f.userdef_rfric||(f.rfric=Math.sqrt(f.s1.material.rollingFriction*f.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=f;let N=M;N.next=d.head,d.head=N,d.modified=!0,d.length++,f.fresh=!P}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 _=!1,z=f.ws1.id>f.ws2.id?f.ws2:f.ws1,C=f.ws1.id>f.ws2.id?f.ws1:f.ws2,w=this.mrca1;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--}w.pushmod=!0;let g=this.mrca2;for(;g.head!=null;){let N=g.head;g.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,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}if(g.pushmod=!0,z.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=z;let A=Z;A.next=N.head,N.head=A,N.modified=!0,N.length++}if(z.body.cbSet!=null){let N=this.mrca1,Z=z.body,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=Z;let S=A;S.next=N.head,N.head=S,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 A=Z;A.next=N.head,N.head=A,N.modified=!0,N.length++}if(C.body.cbSet!=null){let N=this.mrca2,Z=C.body,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=Z;let S=A;S.next=N.head,N.head=S,N.modified=!0,N.length++}let O=z.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 A=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=E;let L=S;L.next=A.head,A.head=L,A.modified=!0,A.length++}E=E.compound}else{if(O.cbSet!=null){let A=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=O;let L=S;L.next=A.head,A.head=L,A.modified=!0,A.length++}O=O.compound}}let M=this.mrca1.head;for(;M!=null;){let N=M.elt,Z=this.mrca2.head;for(;Z!=null;){let A=Z.elt,S=N.cbSet,L=A.cbSet,T=S.manager,G=null,R=(S.cbpairs.length<L.cbpairs.length?S.cbpairs:L.cbpairs).head;for(;R!=null;){let D=R.elt;if(D.a==S&&D.b==L||D.a==L&&D.b==S){G=D;break}R=R.next}if(G==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,_t.setlt(S,L)?(D.a=S,D.b=L):(D.a=L,D.b=S),G=D,S.cbpairs.add(G),L!=S&&L.cbpairs.add(G)}if(G.zip_listeners&&(G.zip_listeners=!1,G.__validate()),G.listeners.head==null){Z=Z.next;continue}let j=null,V=null,K=this.prelisteners;for(;K.head!=null;){let D=K.head;K.head=D.next;let I=D;I.elt=null,I.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=I,K.head==null&&(K.pushmod=!0),K.modified=!0,K.length--}K.pushmod=!0;let $=null,Y=S.manager,X=null,J=(S.cbpairs.length<L.cbpairs.length?S.cbpairs:L.cbpairs).head;for(;J!=null;){let D=J.elt;if(D.a==S&&D.b==L||D.a==L&&D.b==S){X=D;break}J=J.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,_t.setlt(S,L)?(D.a=S,D.b=L):(D.a=L,D.b=S),X=D,S.cbpairs.add(X),L!=S&&L.cbpairs.add(X)}X.zip_listeners&&(X.zip_listeners=!1,X.__validate());let F=X.listeners.head;for(;F!=null;){let D=F.elt;if(D.event==5&&(D.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=D;let Q=U;$==null?(Q.next=I.head,I.head=Q):(Q.next=$.next,$.next=Q),I.pushmod=I.modified=!0,I.length++,$=Q,_=_||!D.pure}F=F.next}if(this.prelisteners.head==null){Z=Z.next;continue}if(j=B._zpp.phys.ZPP_Interactor.get(N,A),j==null&&(V=Kt.get(N,A),this.add_callbackset(V)),j==null||(j.COLLISIONstamp!=this.stamp||i)&&(j.COLLISIONstate&4)==0){if(V!=null&&(j=V),j!=null){let ne=this.prelisteners.head;for(;ne!=null;)ne.elt.itype==7?(j.COLLISIONstamp=this.stamp,j.SENSORstamp=this.stamp,j.FLUIDstamp=this.stamp):j.COLLISIONstamp=this.stamp,ne=ne.next}f.mutable=!0,f.wrap_normal!=null&&(f.wrap_normal.zpp_inner._immutable=!1),f.wrap_contacts!=null&&(f.wrap_contacts.zpp_inner.immutable=!1);let D=f.active;f.active=!0;let I=!1,U=!0,Q=null,W=null,ie=f.innards.next;f.hc2=!1;let oe=f.contacts.next;for(;oe!=null;){let ne=oe;if(ne.stamp+B._nape.Config.arbiterExpirationDelay<f.stamp){let he=f.contacts,pe,ce;Q==null?(pe=he.next,ce=pe.next,he.next=ce,he.next==null&&(he.pushmod=!0)):(pe=Q.next,ce=pe.next,Q.next=ce,ce==null&&(he.pushmod=!0)),pe._inuse=!1,he.modified=!0,he.length--,he.pushmod=!0,oe=ce;let te=f.innards,ue,xe;W==null?(ue=te.next,xe=ue.next,te.next=xe,te.next==null&&(te.pushmod=!0)):(ue=W.next,xe=ue.next,W.next=xe,xe==null&&(te.pushmod=!0)),ue._inuse=!1,te.modified=!0,te.length--,te.pushmod=!0,ie=xe;let _e=ne;_e.arbiter=null,_e.next=Pe.zpp_pool,Pe.zpp_pool=_e;continue}let re=ne.inner,le=ne.active;ne.active=ne.stamp==f.stamp,ne.active&&(U?(U=!1,f.c1=re,f.oc1=ne):(f.hc2=!0,f.c2=re,f.oc2=ne)),le!=ne.active&&(f.contacts.modified=!0),Q=oe,W=ie,ie=ie.next,oe=oe.next}if(f.hc2){if(f.hpc2=!0,f.oc1.posOnly){let ne=f.c1;f.c1=f.c2,f.c2=ne;let re=f.oc1;f.oc1=f.oc2,f.oc2=re,f.hc2=!1}else f.oc2.posOnly&&(f.hc2=!1);f.oc1.posOnly&&(U=!0)}else f.hpc2=!1;this.precb.zpp_inner.pre_arbiter=f,this.precb.zpp_inner.set=j;let se=this.prelisteners.head;for(;se!=null;){let ne=se.elt;this.precb.zpp_inner.listener=ne;let re=this.precb.zpp_inner,le=j.int1,he=j.int2,pe,ce=ne.options1,te=le.cbTypes;if(ce.nonemptyintersection(te,ce.includes)&&!ce.nonemptyintersection(te,ce.excludes)){let xe=ne.options2,_e=he.cbTypes;pe=xe.nonemptyintersection(_e,xe.includes)&&!xe.nonemptyintersection(_e,xe.excludes)}else pe=!1;pe?(re.int1=le,re.int2=he):(re.int1=he,re.int2=le),this.precb.zpp_inner.pre_swapped=N!=this.precb.zpp_inner.int1;let ue=ne.handlerp(this.precb);if(ue!=null){let xe;H.PreFlag_ACCEPT==null&&(H.internal=!0,H.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,H.internal=!1),ue==H.PreFlag_ACCEPT?xe=5:(H.PreFlag_ACCEPT_ONCE==null&&(H.internal=!0,H.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,H.internal=!1),ue==H.PreFlag_ACCEPT_ONCE?xe=1:(H.PreFlag_IGNORE==null&&(H.internal=!0,H.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,H.internal=!1),xe=ue==H.PreFlag_IGNORE?6:2)),f.immState=xe}se=se.next}if(f.mutable=!1,f.wrap_normal!=null&&(f.wrap_normal.zpp_inner._immutable=!0),f.wrap_contacts!=null&&(f.wrap_contacts.zpp_inner.immutable=!0),f.active=D,j!=null){let ne=this.prelisteners.head;for(;ne!=null;)ne.elt.itype==7?(j.COLLISIONstate=f.immState,j.SENSORstate=f.immState,j.FLUIDstate=f.immState):j.COLLISIONstate=f.immState,ne=ne.next}}else j==null?(f.immState&4)==0&&(f.immState=1):f.immState=j.COLLISIONstate;Z=Z.next}M=M.next}if(_&&(f.immState&4)==0){if(f.b1.type==2){let N=f.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(f.b1.type==2){let N=f.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((f.immState&1)!=0){if(f.b1.type==2&&f.b1.component.sleeping){let _=f.b1;_.world||(_.component.waket=this.stamp+(this.midstep?0:1),_.type==3&&(_.kinematicDelaySleep=!0),_.component.sleeping&&this.really_wake(_,!1))}if(f.b2.type==2&&f.b2.component.sleeping){let _=f.b2;_.world||(_.component.waket=this.stamp+(this.midstep?0:1),_.type==3&&(_.kinematicDelaySleep=!0),_.component.sleeping&&this.really_wake(_,!1))}}if(f.sleeping){f.sleeping=!1;let _;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(_=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=_.next,_.next=null),_.elt=f;let z=_;z.next=d.head,d.head=z,d.modified=!0,d.length++}l=f}else if(b){let _=f;_.userdef_dyn_fric=!1,_.userdef_stat_fric=!1,_.userdef_restitution=!1,_.userdef_rfric=!1,_.__ref_edge1=_.__ref_edge2=null,_.next=ut.zpp_pool,ut.zpp_pool=_,l=null}else l=f;else l=f}else{let d;if(s==null){let k=null,z=(o.arbiters.length<r.arbiters.length?o:r).arbiters.head;for(;z!=null;){let C=z.elt;if(C.id==u.id&&C.di==x.id){k=C;break}z=z.next}d=k}else d=s;let y=d==null,b,f=!1;if(y)Ot.zpp_pool==null?b=new Ot:(b=Ot.zpp_pool,Ot.zpp_pool=b.next,b.next=null);else if(d.sensorarb==null){d.cleared=!0;{let _=d.b1.arbiters,z=null,C=_.head,w=!1;for(;C!=null;){if(C.elt==d){let g,O;z==null?(g=_.head,O=g.next,_.head=O,_.head==null&&(_.pushmod=!0)):(g=z.next,O=g.next,z.next=O,O==null&&(_.pushmod=!0));let E=g;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,_.modified=!0,_.length--,_.pushmod=!0,w=!0;break}z=C,C=C.next}}{let _=d.b2.arbiters,z=null,C=_.head,w=!1;for(;C!=null;){if(C.elt==d){let g,O;z==null?(g=_.head,O=g.next,_.head=O,_.head==null&&(_.pushmod=!0)):(g=z.next,O=g.next,z.next=O,O==null&&(_.pushmod=!0));let E=g;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,_.modified=!0,_.length--,_.pushmod=!0,w=!0;break}z=C,C=C.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Ot.zpp_pool==null?b=new Ot:(b=Ot.zpp_pool,Ot.zpp_pool=b.next,b.next=null),b.intchange=!0,y=!0,f=!0}else b=d.sensorarb;let P=2;if(y||b.stamp!=this.stamp||i)if(b.stamp=this.stamp,Ce.testCollide(u,x)){if(y){let k=x.id;b.b1=e.body,b.ws1=e,b.b2=t.body,b.ws2=t,b.id=u.id,b.di=k;let _=b.b1.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=b;let C=z;C.next=_.head,_.head=C,_.modified=!0,_.length++;let w=b.b2.arbiters,g;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?g=new B._zpp.util.ZNPNode_ZPP_Arbiter:(g=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=g.next,g.next=null),g.elt=b;let O=g;O.next=w.head,w.head=O,w.modified=!0,w.length++,b.active=!0,b.present=0,b.cleared=!1,b.sleeping=!1,b.fresh=!1,b.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=b;let N=M;N.next=E.head,E.head=N,E.modified=!0,E.length++,b.fresh=!f}else b.fresh=b.up_stamp<this.stamp-1||b.endGenerated==this.stamp&&i;if(b.up_stamp=b.stamp,b.fresh||(b.immState&4)==0){b.immState=1;let k=!1,_=b.ws1.id>b.ws2.id?b.ws2:b.ws1,z=b.ws1.id>b.ws2.id?b.ws1:b.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 w=this.mrca2;for(;w.head!=null;){let M=w.head;w.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,w.head==null&&(w.pushmod=!0),w.modified=!0,w.length--}if(w.pushmod=!0,_.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=_;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(_.body.cbSet!=null){let M=this.mrca1,N=_.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 A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}if(z.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=z;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(z.body.cbSet!=null){let M=this.mrca2,N=z.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 A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}let g=_.body.compound,O=z.body.compound;for(;g!=O;){let M=g==null?0:g.depth,N=O==null?0:O.depth;if(M<N){if(O.cbSet!=null){let Z=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=O;let S=A;S.next=Z.head,Z.head=S,Z.modified=!0,Z.length++}O=O.compound}else{if(g.cbSet!=null){let Z=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=g;let S=A;S.next=Z.head,Z.head=S,Z.modified=!0,Z.length++}g=g.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,N=this.mrca2.head;for(;N!=null;){let Z=N.elt,A=M.cbSet,S=Z.cbSet,L=A.manager,T=null,q=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;q!=null;){let F=q.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){T=F;break}q=q.next}if(T==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,_t.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),T=F,A.cbpairs.add(T),S!=A&&S.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,V=this.prelisteners;for(;V.head!=null;){let F=V.head;V.head=F.next;let D=F;D.elt=null,D.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=D,V.head==null&&(V.pushmod=!0),V.modified=!0,V.length--}V.pushmod=!0;let K=null,$=A.manager,Y=null,ee=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;ee!=null;){let F=ee.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){Y=F;break}ee=ee.next}if(Y==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,_t.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),Y=F,A.cbpairs.add(Y),S!=A&&S.cbpairs.add(Y)}Y.zip_listeners&&(Y.zip_listeners=!1,Y.__validate());let J=Y.listeners.head;for(;J!=null;){let F=J.elt;if(F.event==5&&(F.itype&P)!=0){let D=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=F;let U=I;K==null?(U.next=D.head,D.head=U):(U.next=K.next,K.next=U),D.pushmod=D.modified=!0,D.length++,K=U,k=k||!F.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=Kt.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 F=b.active;b.active=!0;let D=!1;this.precb.zpp_inner.pre_arbiter=b,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 Q=this.precb.zpp_inner,W=R.int1,ie=R.int2,oe,se=U.options1,ne=W.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=U.options2,he=ie.cbTypes;oe=le.nonemptyintersection(he,le.includes)&&!le.nonemptyintersection(he,le.excludes)}else oe=!1;oe?(Q.int1=W,Q.int2=ie):(Q.int1=ie,Q.int2=W),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let re=U.handlerp(this.precb);if(re!=null){let le;H.PreFlag_ACCEPT==null&&(H.internal=!0,H.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,H.internal=!1),re==H.PreFlag_ACCEPT?le=5:(H.PreFlag_ACCEPT_ONCE==null&&(H.internal=!0,H.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,H.internal=!1),re==H.PreFlag_ACCEPT_ONCE?le=1:(H.PreFlag_IGNORE==null&&(H.internal=!0,H.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,H.internal=!1),le=re==H.PreFlag_IGNORE?6:2)),b.immState=le}I=I.next}if(b.active=F,R!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(R.COLLISIONstate=b.immState,R.SENSORstate=b.immState,R.FLUIDstate=b.immState):R.SENSORstate=b.immState,U=U.next}}else R==null?(b.immState&4)==0&&(b.immState=1):b.immState=R.SENSORstate;N=N.next}E=E.next}if(k&&(b.immState&4)==0){if(b.b1.type!=1){let M=b.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(b.b2.type!=1){let M=b.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(b.sleeping){b.sleeping=!1;let k=this.s_arbiters,_;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(_=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=_.next,_.next=null),_.elt=b;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++}l=b}else if(y){let k=b;k.next=Ot.zpp_pool,Ot.zpp_pool=k,l=null}else l=b;else l=b}}return l}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=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let o=s.head;s.head=o.next;let r=o;r.elt=null,r.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_Interactor:(r=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._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;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=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;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_Interactor:(r=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._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;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let o=i==null?0:i.depth,r=l==null?0:l.depth;if(o<r){if(l.cbSet!=null){let a=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=a.head,a.head=c,a.modified=!0,a.length++}l=l.compound}else{if(i.cbSet!=null){let a=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=a.head,a.head=c,a.modified=!0,a.length++}i=i.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=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let o=s.head;s.head=o.next;let r=o;r.elt=null,r.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_Interactor:(r=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._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;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=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;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_Interactor:(r=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._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;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let o=i==null?0:i.depth,r=l==null?0:l.depth;if(o<r){if(l.cbSet!=null){let a=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=a.head,a.head=c,a.modified=!0,a.length++}l=l.compound}else{if(i.cbSet!=null){let a=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=a.head,a.head=c,a.modified=!0,a.length++}i=i.compound}}}};B._zpp=null,B._nape=null;var hi=B;var Dn=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}};Dn.zpp_pool=null;var nn=class nn extends Tn{constructor(t){super();this.failed=null;this.list=null;this.space=t,this.is_sweep=!0,this.sweep=this}__insert(t){let n;Dn.zpp_pool==null?n=new Dn:(n=Dn.zpp_pool,Dn.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=Dn.zpp_pool,Dn.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 o=n.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 r=1;o.localCOMx+=o.lverts.next.next.x*r,o.localCOMy+=o.lverts.next.next.y*r;let a=.5;o.localCOMx*=a,o.localCOMy*=a}else{o.localCOMx=0,o.localCOMy=0;let r=0,a=o.lverts.next,p=a;a=a.next;let c=a;for(a=a.next;a!=null;){let y=a;r+=c.x*(y.y-p.y);let b=y.y*c.x-y.x*c.y;o.localCOMx+=(c.x+y.x)*b,o.localCOMy+=(c.y+y.y)*b,p=c,c=y,a=a.next}a=o.lverts.next;let h=a;r+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;o.localCOMx+=(c.x+h.x)*u,o.localCOMy+=(c.y+h.y)*u,p=c,c=h,a=a.next;let x=a;r+=c.x*(x.y-p.y);let m=x.y*c.x-x.x*c.y;o.localCOMx+=(c.x+x.x)*m,o.localCOMy+=(c.y+x.y)*m,r=1/(3*r);let d=r;o.localCOMx*=d,o.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 o=n.lverts.next,r=n.gverts.next;for(;r!=null;){let a=r,p=o;o=o.next,a.x=n.body.posx+(n.body.axisy*p.x-n.body.axisx*p.y),a.y=n.body.posy+(p.x*n.body.axisx+p.y*n.body.axisy),r=r.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,o=s.prev;if(o!=null&&s.aabb.minx>o.aabb.minx){s=l;continue}for(;o.prev!=null&&o.prev.aabb.minx>s.aabb.minx;)o=o.prev;let r=s.prev;r.next=s.next,s.next!=null&&(s.next.prev=r),o.prev==null?(s.prev=null,this.list=s,s.next=o,o.prev=s):(s.prev=o.prev,o.prev=s,s.prev.next=s,s.next=o),s=l}let i=this.list;for(;i!=null;){let l=i.next,o=i.shape,r=o.body,a=i.aabb.maxx;for(;l!=null&&!(l.aabb.minx>a);){let p=l.shape,c=p.body;if(c==r){l=l.next;continue}if(r.type==1&&c.type==1){l=l.next;continue}if(r.component.sleeping&&c.component.sleeping){l=l.next;continue}let h=o.aabb,u=p.aabb;u.miny>h.maxy||h.miny>u.maxy||(n?t.narrowPhase(o,p,r.type!=2||c.type!=2,null,!1):t.continuousEvent(o,p,r.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=ae.get(t,n),o=i??new nn._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.minx>t;)r=r.next;for(;r!=null&&r.aabb.minx<=t;){if(r.aabb.maxx>=t&&r.aabb.miny<=n&&r.aabb.maxy>=n){let p=r.shape,c;if(s!=null){let h=p.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;c&&(p.type==0?Ce.circleContains(p.circle,l)&&o.push(p.outer):Ce.polyContains(p.polygon,l)&&o.push(p.outer))}r=r.next}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,o}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l=ae.get(t,n),o=i??new nn._nape.phys.BodyList,r=this.list;for(;r!=null&&r.aabb.minx>t;)r=r.next;for(;r!=null&&r.aabb.minx<=t;){if(r.aabb.maxx>=t&&r.aabb.miny<=n&&r.aabb.maxy>=n){let p=r.shape,c=p.body.outer;if(!o.has(c)){let h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.type==0?Ce.circleContains(p.circle,l)&&o.push(c):Ce.polyContains(p.polygon,l)&&o.push(c))}}r=r.next}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,o}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new nn._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.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)Ce.containTest(this.aabbShape.zpp_inner,p)&&r.push(p.outer);else{let h=a.aabb;if(h.minx>=o.minx&&h.miny>=o.miny&&h.maxx<=o.maxx&&h.maxy<=o.maxy)r.push(p.outer);else{let u=a.aabb;o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx&&Ce.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(p.outer)}}else{let h;if(s){let u=a.aabb;h=u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy}else{let u=a.aabb;h=o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx}h&&r.push(p.outer)}a=a.next}return r}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._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.shape,c=p.body.outer,h=a.aabb;if(o.miny<=h.maxy&&h.miny<=o.maxy&&o.minx<=h.maxx&&h.minx<=o.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=Ce.containTest(this.aabbShape.zpp_inner,p);!r.has(c)&&x?r.push(c):x||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ce.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(c);else if(s){if(!this.failed.has(c)){let x=p.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(c)&&m?r.push(c):m||(r.remove(c),this.failed.push(c))}}else{let x;if(r.has(c))x=!1;else{let m=p.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(c)}}a=a.next}return this.failed.clear(),r}shapesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new nn._nape.shape.ShapeList,p=this.list;for(;p!=null&&p.aabb.maxx<r.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=r.maxx;){let c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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?Ce.containTest(this.circShape.zpp_inner,h)&&a.push(h.outer):Ce.testCollide_safe(h,this.circShape.zpp_inner)&&a.push(h.outer))}p=p.next}return a}bodiesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._nape.phys.BodyList);let p=this.list;for(;p!=null&&p.aabb.maxx<r.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=r.maxx;){let c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx){let h=p.shape,u=h.body.outer,x;if(l!=null){let m=h.filter;x=(m.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&m.collisionGroup)!=0}else x=!0;if(x)if(i){if(!this.failed.has(u)){let m=Ce.containTest(this.circShape.zpp_inner,h);!a.has(u)&&m?a.push(u):m||(a.remove(u),this.failed.push(u))}}else!a.has(u)&&Ce.testCollide_safe(h,this.circShape.zpp_inner)&&a.push(u)}p=p.next}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new nn._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.maxx<l.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=l.maxx;){let a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=r.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?Ce.containTest(t,p)&&o.push(p.outer):Ce.testCollide_safe(p,t)&&o.push(p.outer))}r=r.next}return o}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._nape.phys.BodyList);let r=this.list;for(;r!=null&&r.aabb.maxx<l.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=l.maxx;){let a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=r.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=Ce.containTest(t,p);!o.has(c)&&u?o.push(c):u||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ce.testCollide_safe(t,p)&&o.push(c)}r=r.next}return this.failed.clear(),o}rayCast(t,n,s){this.sync_broadphase(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,o=null;if(t.dirx==0){let a=this.list;for(;a!=null&&a.aabb.minx<=i.minx;){let p,c=a.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=a.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(a.aabb);if(h>=0&&h<l){let u=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.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,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=u}}}a=a.next}}else if(t.dirx<0){let a=this.list,p=null;for(;a!=null&&a.aabb.minx<=i.maxx;)p=a,a=a.next;for(a=p;a!=null;){let c,h=a.aabb;if(i.miny<=h.maxy&&h.miny<=i.maxy&&i.minx<=h.maxx&&h.minx<=i.maxx)if(s!=null){let u=a.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(a.aabb);if(u>=0&&u<l){let x=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.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,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=x}}}a=a.prev}}else{let a=this.list;for(;a!=null&&a.aabb.minx<=i.maxx&&a.aabb.minx<t.originx+t.dirx*l;){let p,c=a.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=a.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(a.aabb);if(h>=0&&h<l){let u=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.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,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=u}}}a=a.next}}let r=i;return 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,o}rayMultiCast(t,n,s,i){this.sync_broadphase(),t.validate_dir();let l=t.rayAABB(),o=i??new nn._nape.geom.RayResultList;if(t.dirx==0){let a=this.list;for(;a!=null&&a.aabb.minx<=l.minx;){let p,c=a.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,o):t.polysect2(a.shape.polygon,n,o)),a=a.next}}else if(t.dirx<0){let a=this.list,p=null;for(;a!=null&&a.aabb.minx<=l.maxx;)p=a,a=a.next;for(a=p;a!=null;){let c,h=a.aabb;if(l.miny<=h.maxy&&h.miny<=l.maxy&&l.minx<=h.maxx&&h.minx<=l.maxx)if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;else c=!1;c&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,o):t.polysect2(a.shape.polygon,n,o)),a=a.prev}}else{let a=this.list;for(;a!=null&&a.aabb.minx<=l.maxx;){let p,c=a.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,o):t.polysect2(a.shape.polygon,n,o)),a=a.next}}let r=l;return 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,o}};nn._zpp=null,nn._nape=null;var Zs=nn;function Jo(v){v.length=0,this.push(v)}var Rt=class Rt extends Tn{constructor(t,n){super();this.failed=null;this.shapes=[];this.grid=new Map;this.cellPool=[];this.testedPairs=new Set;this.frameCount=0;this.space=t,this.is_sweep=!0,this.is_spatial_hash=!0,this.sweep=this,n!=null&&n>0?(this.cellSize=n,this.fixedCellSize=!0):(this.cellSize=64,this.fixedCellSize=!1),this.invCellSize=1/this.cellSize}cellKey(t,n){return t*73856093^n*19349663}__insert(t){this.shapes.push(t),t.__shIdx=this.shapes.length-1}__remove(t){let n=t.__shIdx,s=this.shapes.length-1;if(n!==s){let i=this.shapes[s];this.shapes[n]=i,i.__shIdx=n}this.shapes.pop(),t.__shIdx=void 0}__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 o=n.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 r=1;o.localCOMx+=o.lverts.next.next.x*r,o.localCOMy+=o.lverts.next.next.y*r;let a=.5;o.localCOMx*=a,o.localCOMy*=a}else{o.localCOMx=0,o.localCOMy=0;let r=0,a=o.lverts.next,p=a;a=a.next;let c=a;for(a=a.next;a!=null;){let y=a;r+=c.x*(y.y-p.y);let b=y.y*c.x-y.x*c.y;o.localCOMx+=(c.x+y.x)*b,o.localCOMy+=(c.y+y.y)*b,p=c,c=y,a=a.next}a=o.lverts.next;let h=a;r+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;o.localCOMx+=(c.x+h.x)*u,o.localCOMy+=(c.y+h.y)*u,p=c,c=h,a=a.next;let x=a;r+=c.x*(x.y-p.y);let m=x.y*c.x-x.x*c.y;o.localCOMx+=(c.x+x.x)*m,o.localCOMy+=(c.y+x.y)*m,r=1/(3*r);let d=r;o.localCOMx*=d,o.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 if(t.type==2)t.capsule.__validate_aabb();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 o=n.lverts.next,r=n.gverts.next;for(;r!=null;){let a=r,p=o;o=o.next,a.x=n.body.posx+(n.body.axisy*p.x-n.body.axisx*p.y),a.y=n.body.posy+(p.x*n.body.axisx+p.y*n.body.axisy),r=r.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}}}autoTuneCellSize(){if(this.fixedCellSize||this.shapes.length===0)return;let t=0,n=0,s=0;for(let o=0;o<this.shapes.length;o++){let r=this.shapes[o].aabb;r!=null&&(t+=r.maxx-r.minx,n+=r.maxy-r.miny,s++)}if(s===0)return;let i=(t+n)/(2*s),l=Math.max(i*2,8);this.cellSize=l,this.invCellSize=1/l}broadphase(t,n){let s=this.shapes.length;if(s===0)return;this.frameCount++,(this.frameCount===1||!this.fixedCellSize&&this.frameCount%Rt.TUNE_INTERVAL===0)&&this.autoTuneCellSize();let i=this.invCellSize,l=this.grid,o=this.cellPool;l.forEach(Jo,o),l.clear();let r=this.testedPairs;r.clear();for(let a=0;a<s;a++){let p=this.shapes[a],c=p.aabb,h=p.__shIdx,u=c.minx*i|0,x=c.miny*i|0,m=c.maxx*i|0,d=c.maxy*i|0;if(u===m&&x===d){let b=u*73856093^x*19349663,f=l.get(b);f===void 0&&(f=o.length>0?o.pop():[],l.set(b,f));let P=f.length,k=p.body,_=k.type,z=k.component.sleeping;for(let C=0;C<P;C++){let w=f[C],g=w.body;if(g===k||_===1&&g.type===1||z&&g.component.sleeping)continue;let O=w.aabb;O.miny>c.maxy||c.miny>O.maxy||O.minx>c.maxx||c.minx>O.maxx||(n?t.narrowPhase(p,w,_!==2||g.type!==2,null,!1):t.continuousEvent(p,w,_!==2||g.type!==2,null,!1))}f.push(p)}else for(let b=u;b<=m;b++)for(let f=x;f<=d;f++){let P=b*73856093^f*19349663,k=l.get(P);k===void 0&&(k=o.length>0?o.pop():[],l.set(P,k));let _=k.length,z=p.body,C=z.type,w=z.component.sleeping;for(let g=0;g<_;g++){let O=k[g],E=O.body;if(E===z||C===1&&E.type===1||w&&E.component.sleeping)continue;let M=O.__shIdx,N=h<M?h:M,Z=h<M?M:h,A=Z*Z+N;if(r.has(A))continue;r.add(A);let S=O.aabb;S.miny>c.maxy||c.miny>S.maxy||S.minx>c.maxx||c.minx>S.maxx||(n?t.narrowPhase(p,O,C!==2||E.type!==2,null,!1):t.continuousEvent(p,O,C!==2||E.type!==2,null,!1))}k.push(p)}}}clear(){for(;this.shapes.length>0;){let t=this.shapes[this.shapes.length-1];t.removedFromSpace(),this.__remove(t)}this.grid.clear(),this.cellPool.length=0,this.testedPairs.clear()}shapesUnderPoint(t,n,s,i){this.space.validation();let l=ae.get(t,n),o=i??new Rt._nape.shape.ShapeList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb;if(c.minx<=t&&c.maxx>=t&&c.miny<=n&&c.maxy>=n){let h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.type==0?Ce.circleContains(p.circle,l)&&o.push(p.outer):Ce.polyContains(p.polygon,l)&&o.push(p.outer))}}let r=l;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=ae.zpp_pool,ae.zpp_pool=r,o}bodiesUnderPoint(t,n,s,i){this.space.validation();let l=ae.get(t,n),o=i??new Rt._nape.phys.BodyList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb;if(c.minx<=t&&c.maxx>=t&&c.miny<=n&&c.maxy>=n){let h=p.body.outer;if(!o.has(h)){let u;if(s!=null){let x=p.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(p.type==0?Ce.circleContains(p.circle,l)&&o.push(h):Ce.polyContains(p.polygon,l)&&o.push(h))}}}let r=l;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=ae.zpp_pool,ae.zpp_pool=r,o}shapesInAABB(t,n,s,i,l){this.space.validation(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new Rt._nape.shape.ShapeList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],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)Ce.containTest(this.aabbShape.zpp_inner,p)&&r.push(p.outer);else{let h=p.aabb;if(h.minx>=o.minx&&h.miny>=o.miny&&h.maxx<=o.maxx&&h.maxy<=o.maxy)r.push(p.outer);else{let u=p.aabb;o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx&&Ce.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(p.outer)}}else{let h;if(s){let u=p.aabb;h=u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy}else{let u=p.aabb;h=o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx}h&&r.push(p.outer)}}return r}bodiesInAABB(t,n,s,i,l){this.space.validation(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new Rt._nape.phys.BodyList;this.failed==null&&(this.failed=new Rt._nape.phys.BodyList);for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.body.outer,h=p.aabb;if(o.miny<=h.maxy&&h.miny<=o.maxy&&o.minx<=h.maxx&&h.minx<=o.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=Ce.containTest(this.aabbShape.zpp_inner,p);!r.has(c)&&x?r.push(c):x||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ce.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(c);else if(s){if(!this.failed.has(c)){let x=p.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(c)&&m?r.push(c):m||(r.remove(c),this.failed.push(c))}}else{let x;if(r.has(c))x=!1;else{let m=p.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(c)}}}return this.failed.clear(),r}shapesInCircle(t,n,s,i,l,o){this.space.validation(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new Rt._nape.shape.ShapeList;for(let p=0;p<this.shapes.length;p++){let c=this.shapes[p],h=c.aabb;if(r.miny<=h.maxy&&h.miny<=r.maxy&&r.minx<=h.maxx&&h.minx<=r.maxx){let u;if(l!=null){let x=c.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(i?Ce.containTest(this.circShape.zpp_inner,c)&&a.push(c.outer):Ce.testCollide_safe(c,this.circShape.zpp_inner)&&a.push(c.outer))}}return a}bodiesInCircle(t,n,s,i,l,o){this.space.validation(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new Rt._nape.phys.BodyList;this.failed==null&&(this.failed=new Rt._nape.phys.BodyList);for(let p=0;p<this.shapes.length;p++){let c=this.shapes[p],h=c.aabb;if(r.miny<=h.maxy&&h.miny<=r.maxy&&r.minx<=h.maxx&&h.minx<=r.maxx){let u=c.body.outer,x;if(l!=null){let m=c.filter;x=(m.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&m.collisionGroup)!=0}else x=!0;if(x)if(i){if(!this.failed.has(u)){let m=Ce.containTest(this.circShape.zpp_inner,c);!a.has(u)&&m?a.push(u):m||(a.remove(u),this.failed.push(u))}}else!a.has(u)&&Ce.testCollide_safe(c,this.circShape.zpp_inner)&&a.push(u)}}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.space.validation(),this.validateShape(t);let l=t.aabb,o=i??new Rt._nape.shape.ShapeList;for(let r=0;r<this.shapes.length;r++){let a=this.shapes[r],p=a.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx){let c;if(s!=null){let h=a.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;c&&(n?Ce.containTest(t,a)&&o.push(a.outer):Ce.testCollide_safe(a,t)&&o.push(a.outer))}}return o}bodiesInShape(t,n,s,i){this.space.validation(),this.validateShape(t);let l=t.aabb,o=i??new Rt._nape.phys.BodyList;this.failed==null&&(this.failed=new Rt._nape.phys.BodyList);for(let r=0;r<this.shapes.length;r++){let a=this.shapes[r],p=a.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx){let c=a.body.outer,h;if(s!=null){let u=a.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=Ce.containTest(t,a);!o.has(c)&&u?o.push(c):u||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ce.testCollide_safe(t,a)&&o.push(c)}}return this.failed.clear(),o}rayCast(t,n,s){this.space.validation(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,o=null;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb,h;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;else h=!1;if(h){let u=t.aabbsect(c);if(u>=0&&u<l){let x=p.type==0?t.circlesect(p.circle,n,l):t.polysect(p.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,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=x}}}}let r=i;return 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,o}rayMultiCast(t,n,s,i){this.space.validation(),t.validate_dir();let l=t.rayAABB(),o=i??new Rt._nape.geom.RayResultList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb,h;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;else h=!1;h&&t.aabbsect(c)>=0&&(p.type==0?t.circlesect2(p.circle,n,o):t.polysect2(p.polygon,n,o))}let r=l;return 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,o}};Rt._zpp=null,Rt._nape=null,Rt.TUNE_INTERVAL=120;var ks=Rt;function Hl(){let v={},e={};return v.callbacks={},v.constraint={},v.dynamics={},v.geom={},v.phys={},v.shape={},v.space={},v.util={},e.ZPP_Const=qn,e.ZPP_ID=yn,e.callbacks||(e.callbacks={}),Tt._nape=v,Tt._zpp=e,e.callbacks.ZPP_Callback=Tt,_t._zpp=e,e.callbacks.ZPP_CbSet=_t,Ne._zpp=e,e.callbacks.ZPP_CbSetPair=Ne,e.util||(e.util={}),Xl(e),pn._zpp=e,e.callbacks.ZPP_CbType=pn,e.util.ZPP_Flags=H,Lt._nape=v,Lt._zpp=e,e.callbacks.ZPP_Listener=Lt,e.callbacks.ZPP_BodyListener=cl,e.callbacks.ZPP_ConstraintListener=hl,e.callbacks.ZPP_InteractionListener=ul,ws._nape=v,ws._zpp=e,e.callbacks.ZPP_OptionType=ws,e.constraint||(e.constraint={}),Ze._nape=v,Ze._zpp=e,e.constraint.ZPP_Constraint=Ze,e.constraint.ZPP_AngleJoint=qe,e.constraint.ZPP_CopyHelper=Un,e.constraint.ZPP_DistanceJoint=yi,e.constraint.ZPP_LineJoint=mi,e.constraint.ZPP_MotorJoint=bi,e.constraint.ZPP_PivotJoint=fi,e.constraint.ZPP_PulleyJoint=zi,e.constraint.ZPP_UserConstraint=xl,e.constraint.ZPP_UserBody=vs,e.constraint.ZPP_WeldJoint=Pi,e.dynamics||(e.dynamics={}),Ie._nape=v,Ie._zpp=e,e.dynamics.ZPP_Arbiter=Ie,e.dynamics.ZPP_SensorArbiter=Ot,Pt._nape=v,Pt._zpp=e,e.dynamics.ZPP_FluidArbiter=Pt,ut._nape=v,ut._zpp=e,e.dynamics.ZPP_ColArbiter=ut,e.dynamics.ZPP_IContact=wi,Pe._nape=v,Pe._zpp=e,e.dynamics.ZPP_Contact=Pe,it._nape=v,it._zpp=e,e.dynamics.ZPP_InteractionFilter=it,qs._zpp=e,e.dynamics.ZPP_InteractionGroup=qs,Qn._nape=v,Qn._zpp=e,e.dynamics.ZPP_SpaceArbiterList=Qn,e.geom||(e.geom={}),be._nape=v,be._zpp=e,e.geom.ZPP_AABB=be,e.geom.ZPP_Collide=Ce,e.geom.ZPP_Convex=dl,e.geom.ZPP_ConvexRayResult=bn,e.geom.ZPP_CutVert=Qe,e.geom.ZPP_CutInt=lt,e.geom.ZPP_Cutter=_l,e.geom.ZPP_Geom=gs,e.geom.ZPP_GeomVert=ge,ge._createVec2Fn=function(){return new v.geom.Vec2},e.geom.ZPP_GeomPoly=yl,e.geom.ZPP_MarchSpan=Bn,e.geom.ZPP_MarchPair=jn,Js._init(e,v),e.geom.ZPP_MarchingSquares=Js,Us._nape=v,e.geom.ZPP_Mat23=Us,e.geom.ZPP_MatMN=Gi,e.geom.ZPP_Monotone=ml,e.geom.ZPP_PartitionVertex=Ge,e.geom.ZPP_PartitionedPoly=qi,e.geom.ZPP_Ray=bl,e.geom.ZPP_SimpleVert=Ee,e.geom.ZPP_SimpleSeg=Vt,e.geom.ZPP_SimpleEvent=Me,e.geom.ZPP_SimpleSweep=Ki,e.geom.ZPP_Simple=fl,e.geom.ZPP_SimplifyV=gn,e.geom.ZPP_SimplifyP=Le,e.geom.ZPP_Simplify=zl,e.geom.ZPP_ToiEvent=Ws,e.geom.ZPP_SweepDistance=Cn,e.geom.ZPP_PartitionPair=St,e.geom.ZPP_Triangular=Pl,e.geom.ZPP_Vec2=ae,ai._zpp=e,e.geom.ZPP_Vec3=ai,e.geom.ZPP_VecMath=wl,e.phys||(e.phys={}),e.phys.ZPP_Interactor=Wt,Wt._init(e,v),Mn._init(e,v),e.phys.ZPP_Body=Mn,Wn._nape=v,Wn._zpp=e,Wn._init(),e.phys.ZPP_Compound=Wn,Zn._nape=v,Zn._zpp=e,e.phys.ZPP_FluidProperties=Zn,Oe._nape=v,Oe._zpp=e,e.phys.ZPP_Material=Oe,e.shape||(e.shape={}),pi._nape=v,pi._zpp=e,pi._init(),e.shape.ZPP_Shape=pi,$n._nape=v,$n._zpp=e,$n._init(),e.shape.ZPP_Circle=$n,ot._nape=v,ot._zpp=e,e.shape.ZPP_Edge=ot,ei._nape=v,ei._zpp=e,ei._init(),e.shape.ZPP_Polygon=ei,ti._nape=v,ti._zpp=e,ti._init(),e.shape.ZPP_Capsule=ti,e.space||(e.space={}),Tn._zpp=e,Tn._nape=v,e.space.ZPP_Broadphase=Tn,e.space.ZPP_AABBNode=Ae,e.space.ZPP_AABBPair=st,e.space.ZPP_AABBTree=$e,Ms._zpp=e,Ms._nape=v,e.space.ZPP_DynAABBPhase=Ms,xt._zpp=e,e.space.ZPP_Island=xt,e.space.ZPP_Component=Ys,Kt._zpp=e,e.space.ZPP_CallbackSet=Kt,Hi._zpp=e,e.space.ZPP_CbSetManager=Hi,hi._zpp=e,hi._nape=v,e.space.ZPP_Space=hi,e.space.ZPP_SweepData=Dn,Zs._zpp=e,Zs._nape=v,e.space.ZPP_SweepPhase=Zs,ks._zpp=e,ks._nape=v,e.space.ZPP_SpatialHashPhase=ks,e.util.ZNPArray2_Float=ds,e.util.ZNPArray2_ZPP_GeomVert=_s,e.util.ZNPArray2_ZPP_MarchPair=ys,e.util.Hashable2_Boolfalse=Te,e.util.FastHash2_Hashable2_Boolfalse=Ti,e.util.ZPP_Math=al,e.util.ZPP_PubPool=ye,e.callbacks.ZPP_InteractionListener._initStatics(e),e.geom.ZPP_Collide._initStatics(e),e.space.ZPP_AABBTree._initStatics(),v.__zpp=e,v}var vl;function me(){return vl||(vl=Hl()),vl}var Ql=!1;function $l(){if(Ql)return;let v=vl;if(!v?.callbacks?.CbEvent||!v?.callbacks?.CbType||!v?.callbacks?.ListenerType||!v?.dynamics?.ArbiterType||!v?.phys?.BodyType||!v?.shape?.ShapeType)return;Ql=!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 eo=new WeakMap;function ke(v,e){if(!v)return null;let t=eo.get(v);return t||(t=e(v),eo.set(v,t)),t}var Be=class v{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;ae.zpp_pool==null?n=new ae:(n=ae.zpp_pool,ae.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(ye.poolVec2==null?s=new v:(s=ye.poolVec2,ye.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===ye.nextVec2&&(ye.nextVec2=null)),s.zpp_inner==null){let i;ae.zpp_pool==null?i=new ae:(i=ae.zpp_pool,ae.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 v?e:e?e instanceof ae?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?v._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 v._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 v._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 v._poolGet(s,i,n)}static fromAngle(e,t=!1){return v.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),o=v._poolGet(i,l,s);return v._disposeWeak(e),v._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&&v._disposeWeak(e),t!=null&&v._disposeWeak(t),o}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 v._disposeWeak(e),v._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,o=n-i,r=s-l,a=o*o+r*r;return v._disposeWeak(e),v._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,s=e.zpp_inner.y;t.zpp_inner.validate();let i=t.zpp_inner.x,l=t.zpp_inner.y,o=n-i,r=s-l,a=Math.sqrt(o*o+r*r);return v._disposeWeak(e),v._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,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),v._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 v._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=v._poolGet(n,s,!0);i.normalise();let l=e.sub(i.muleq(2*i.dot(e)),t);return v._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 v._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=v._poolGet(n,s,t);return v._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=v._poolGet(s,i,n);return v._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=v._poolGet(n,s,t);return v._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 v._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),v._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),v._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 v._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 v._disposeWeak(e),t}perp(e=!1){this._checkDisposed(),this._validate();let t=-this.zpp_inner.y,n=this.zpp_inner.x;return v._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,ye.nextVec2!=null?ye.nextVec2.zpp_pool=this:ye.poolVec2=this,ye.nextVec2=this,this.zpp_disp=!0,e.free(),e.next=ae.zpp_pool,ae.zpp_pool=e}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};ae._wrapFn=v=>ke(v,e=>{let t=Object.create(Be.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Uo=me();Uo.geom.Vec2=Be;var ui=class v{constructor(e=0,t=0,n=0){this.zpp_pool=null;this.zpp_disp=!1;let s=new ai;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 v?e:e?e instanceof ai?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?v._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=0){let s;return ye.poolVec3==null?s=new v:(s=ye.poolVec3,ye.poolVec3=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===ye.nextVec3&&(ye.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(),v.get(this.zpp_inner.x,this.zpp_inner.y,this.zpp_inner.z)}xy(e=!1){return this._checkDisposed(),this.zpp_inner.validate(),Be.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,ye.nextVec3!=null?ye.nextVec3.zpp_pool=this:ye.poolVec3=this,ye.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+" }"}};ai._wrapFn=v=>ke(v,e=>{let t=Object.create(ui.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Xs=class v{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 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<s&&(s=p),a>i&&(i=a),p>l&&(l=p)}return new v(n,s,i-n,l-s)}static _wrap(e){return e instanceof v?e:e?e instanceof be?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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 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(),l>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 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 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(),l<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 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 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==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(),o=e.zpp_inner.y==i}else o=!1;o||(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 o=i;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,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=v=>ke(v,e=>{let t=Object.create(Xs.prototype);return t.zpp_inner=e,e.outer=t,t});var gl=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 On=class v{get _inner(){return this}constructor(e=1,t=1){let n;if(Zn.zpp_pool==null?n=new Zn:(n=Zn.zpp_pool,Zn.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 v?e:e?e instanceof Zn?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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 o=s;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=l;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 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 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(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(),o!=o||a!=a)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==o){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==a}else c=!1;if(!c){s.zpp_inner.x=o,s.zpp_inner.y=a;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 m=e;m.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=m:n.util.ZPP_PubPool.poolVec2=m,n.util.ZPP_PubPool.nextVec2=m,m.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 v(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 o=i.zpp_inner;i.zpp_inner.outer=null,i.zpp_inner=null;let r=i;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(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 o=s.zpp_inner;o._validate!=null&&o._validate();let r=s.zpp_inner.x;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();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(),r!=r||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==r){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=r,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 m=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=m;y.outer!=null&&(y.outer.zpp_inner=null,y.outer=null),y._isimmutable=null,y._validate=null,y._invalidate=null,y.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=y}}return n}toString(){return"{ density: "+this.zpp_inner.density*1e3+" viscosity: "+this.zpp_inner.viscosity+" gravity: "+String(this.zpp_inner.wrap_gravity)+" }"}};Zn._wrapFn=v=>ke(v,e=>{let t=Object.create(On.prototype);return t.zpp_inner=e,e.outer=t,t});var Wo=me();Wo.phys.FluidProperties=On;var Hs,Cl,Ml;function to(v){Hs=v}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()&&Hs?Hs(e):e.isShape&&e.isShape()&&Cl?Cl(e):e.isCompound&&e.isCompound()&&Ml?Ml(e):ke(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 Hs?Hs(e):e}return null}get castShape(){if(this.zpp_inner_i.ishape!=null){let e=this.zpp_inner_i.ishape.outer;return Cl?Cl(e):e}return null}get castCompound(){if(this.zpp_inner_i.icompound!=null){let e=this.zpp_inner_i.icompound.outer;return Ml?Ml(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 Ci=Qs;var $s,el,tl;function no(v){$s=v}function io(v){el=v}function so(v){tl=v}var ni=class v extends Ci{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&&$s?$s(e):t===1&&el?el(e):t===2&&tl?tl(e):e.outer?e.outer:ke(e,n=>{let s=Object.create(v.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 pi.types[this.zpp_inner.type]}isCircle(){return this.zpp_inner.type===0}isPolygon(){return this.zpp_inner.type===1}isCapsule(){return this.zpp_inner.type===2}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 $s?$s(t):t}return null}get castPolygon(){let e=this.zpp_inner;if(e.type===1){let t=e.polygon.outer_zn;return el?el(t):t}return null}get castCapsule(){let e=this.zpp_inner;if(e.type===2){let t=e.capsule.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.type===1?e.polygon.setupLocalCOM():e.capsule.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.type===1?t.polygon.setupLocalCOM():t.capsule.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 On().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 On().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 On;t.setFluid(n.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new On().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.type===1?t.polygon:t.capsule).__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.type===1?n.polygon.__scale(e,t):n.capsule.__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.type===1?t.polygon.__rotate(i,s):t.capsule.__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.type===1?t.polygon.__transform(n):t.capsule.__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 s=Ce.shapeContains(t,n);return n.weak&&e.dispose(),s}copy(){let e=this.zpp_inner.copy();return e instanceof v?e:v._wrap(e)}toString(){let e=this.zpp_inner;return(e.type===0?"Circle":e.type===1?"Polygon":"Capsule")+"#"+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(ye.poolVec2==null?i=new e.geom.Vec2:(i=ye.poolVec2,ye.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i===ye.nextVec2&&(ye.nextVec2=null)),i.zpp_inner==null){let l;ae.zpp_pool==null?l=new ae:(l=ae.zpp_pool,ae.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 Dl=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 s=me(),i=s.__zpp;class l extends Dl{constructor(){super(),this.inner=new i.util[v]}static get(r,a=!1){let p=new s[e][t];return p.zpp_inner.inner=r,a&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}}return l.internal=!1,i.util[n]=l,l}var Fl=null,Ko=null,Rl=null;Fl=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");Rl=Sn("ZNPList_ZPP_Arbiter","dynamics","ArbiterList","ZPP_ArbiterList");function Kn(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 Yn(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 Fn(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 Es(v,e,t,n,s){if(Fn(t),t==null)throw new Error("Error: Body::"+v+" cannot be null");return e==null&&n!=null&&(n(),e=s()),e.set(t),e}function Zl(v,e,t){return Be.get(v,e,t)}function sn(v,e){return H[v]==null&&(H.internal=!0,H[v]=e(),H.internal=!1),H[v]}var We=class v extends Ci{constructor(t,n){super();this.debugDraw=!0;let s=new Mn;this.zpp_inner=s,s.outer=this,s.outer_i=this,this.zpp_inner_i=s,this._inner=this,n!=null?(Fn(n),s.posx=Kn(n),s.posy=Yn(n)):(s.posx=0,s.posy=0);let i=me(),l;if(t==null?l=sn("BodyType_DYNAMIC",()=>new i.phys.BodyType):l=t,s.immutable_midstep("Body::type"),s.world)throw new Error("Error: Space::world is immutable");if(Mn.types[s.type]!==l){if(l==null)throw new Error("Error: Cannot use null BodyType");let o=lo(l,i);o===1&&s.space!=null&&(s.velx=0,s.vely=0,s.angvel=0),s.invalidate_type(),s.space!=null?s.space.transmitType(s,o):s.type=o}n!=null&&An(n),s.insert_cbtype(pn.ANY_BODY.zpp_inner)}static _wrap(t){return t?t instanceof v?t:t instanceof Mn?ke(t,n=>{let s=Object.create(v.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?v._wrap(t.zpp_inner):ke(t,n=>{let s=Object.create(v.prototype);return s._inner=n,s}):null}get type(){return Mn.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(Mn.types[n.type]!==t){if(t==null)throw new Error("Error: Cannot use null BodyType");let s=me(),i=lo(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){Es("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){Es("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){Es("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){Es("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){Es("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 gl(this.zpp_inner.wrap_shapes,ni._wrap)}get space(){return this.zpp_inner.space==null?null:ii._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 Xs._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=Be.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=Be.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=sn("MassMode_DEFAULT",()=>new t.phys.MassMode),s=sn("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=sn("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=sn("InertiaMode_DEFAULT",()=>new t.phys.InertiaMode),s=sn("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=sn("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=sn("GravMassMode_DEFAULT",()=>new t.phys.GravMassMode),s=sn("GravMassMode_FIXED",()=>new t.phys.GravMassMode),i=sn("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=sn("GravMassMode_SCALED",()=>new n.phys.GravMassMode);if(t===s)this.zpp_inner.gravMassMode=2;else{let i=sn("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,o=1-.5*l,r=1-l*l/8,a=(o*n.axisx+i*n.axisy)*r;n.axisy=(o*n.axisy-i*n.axisx)*r,n.axisx=a}}return oo(n),n.zip_worldCOM=!0,n.zip_axis=!0,oo(n),n.zip_worldCOM=!0,n.sweepTime=0,this}localPointToWorld(t,n=!1){if(Fn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Kn(t),i=Yn(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,o=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return An(t),Zl(l+this.zpp_inner.posx,o+this.zpp_inner.posy,n)}worldPointToLocal(t,n=!1){if(Fn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Kn(t)-this.zpp_inner.posx,i=Yn(t)-this.zpp_inner.posy,l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,o=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return An(t),Zl(l,o,n)}localVectorToWorld(t,n=!1){if(Fn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Kn(t),i=Yn(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,o=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return An(t),Zl(l,o,n)}worldVectorToLocal(t,n=!1){if(Fn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Kn(t),i=Yn(t),l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,o=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return An(t),Zl(l,o,n)}applyImpulse(t,n,s=!1){if(Fn(t),n!=null&&Fn(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 An(t),n!=null&&An(n),this;this.zpp_inner.validate_mass();let i=this.zpp_inner.imass,l=Kn(t),o=Yn(t);if(this.zpp_inner.velx+=l*i,this.zpp_inner.vely+=o*i,n!=null){let r=Kn(n)-this.zpp_inner.posx,a=Yn(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(o*r-l*a)*this.zpp_inner.iinertia,An(n)}return s||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,s){if(Fn(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 o=(n-this.zpp_inner.rot)*i;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()"),Fn(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,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 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=Be.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-=Kn(n),this.zpp_inner.pre_posy-=Yn(n)),t.dispose(),n.dispose(),this}rotate(t,n){if(Fn(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);Es("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 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=s,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 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(Fn(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,An(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=Ie.COL|Ie.SENSOR|Ie.FLUID;else{let l=me(),o=sn("InteractionType_COLLISION",()=>new l.callbacks.InteractionType);if(t===o)i=Ie.COL;else{let r=sn("InteractionType_SENSOR",()=>new l.callbacks.InteractionType);i=t===r?Ie.SENSOR:Ie.FLUID}}return this.zpp_inner.interactingBodies(i,s)}normalImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.normalImpulse(this,n),t)}tangentImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.tangentImpulse(this,n),t)}totalContactsImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ie.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 o=l.zpp_inner.zpp_gl();if(l.zpp_critical=!0,l.zpp_i>=o){l.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1;let r=l.zpp_inner.at(l.zpp_i++),a=r.zpp_inner;a.type===Ie.COL&&(t!=null&&a.b2!==t.zpp_inner&&a.b1!==t.zpp_inner||(s+=r.collisionArbiter.rollingImpulse(this,n)))}return s}buoyancyImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.buoyancyImpulse(this),t)}dragImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.dragImpulse(this),t)}totalFluidImpulse(t=null){return this._arbiterImpulseQuery(Ie.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 o=i.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(),s+=r.z,o.dispose(),i=i.next}return ui.get(t,n,s)}totalImpulse(t=null,n=!1){let s=0,i=0,l=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 h=r.zpp_inner.at(r.zpp_i++).zpp_inner;if(h.type===Ie.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 a=this.zpp_inner.constraints.head;for(;a!=null;){let p=a.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()}a=a.next}return ui.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=Be.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),y=d.xy();n.addeq(y);let b=Kn(y),f=Yn(y);t+=Math.sqrt(b*b+f*f),y.dispose(),d.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 m=x.zpp_inner.user_length;if(r.zpp_critical=!0,r.zpp_i>=m){r.zpp_next=me().constraint.ConstraintIterator.zpp_pool,me().constraint.ConstraintIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let y=r.zpp_inner.at(r.zpp_i++).bodyImpulse(this),b=y.xy();n.addeq(b);let f=Kn(b),P=Yn(b);t+=Math.sqrt(f*f+P*P),b.dispose(),y.dispose()}let a=Kn(n),p=Yn(n),c=Math.sqrt(a*a+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=Rl.get(this.zpp_inner.arbiters,!0)),this.zpp_inner.wrap_arbiters}_getConstraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=Fl.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}_arbiterImpulseQuery(t,n,s){let i=0,l=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++),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(),o+=x.z,u.dispose()}return ui.get(i,l,o)}};function lo(v,e){let t=sn("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(v===t)return 2;let n=sn("BodyType_KINEMATIC",()=>new e.phys.BodyType);return v===n?3:1}function oo(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=We;to(v=>We._wrap(v));var Mi={SHAPES:1,JOINTS:2,CONTACTS:4,AABB:8,CENTER_OF_MASS:16,VELOCITIES:32,ALL:63};var ii=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 hi(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 hi?e.outer?e.outer:ke(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:ke(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_spatial_hash?(H.Broadphase_SPATIAL_HASH==null&&(H.internal=!0,H.Broadphase_SPATIAL_HASH=new(me()).space.Broadphase,H.internal=!1),H.Broadphase_SPATIAL_HASH):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 deterministic(){return this.zpp_inner.deterministic}set deterministic(e){this.zpp_inner.deterministic=e,e&&(this.zpp_inner.sortcontacts=!0)}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 Qn;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 o=s.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(s.zpp_critical=!0,s.zpp_i>=r){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 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.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 o=s.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(s.zpp_critical=!0,s.zpp_i>=r){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 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.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 o=s.zpp_inner.at(s.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,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 o=!1,r=i.constraints.head;for(;r!=null;){let u=r.elt;if(u.ignore&&u.pair_exists(i.id,l.id)){o=!0;break}r=r.next}let a;if(o)a=!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,m;if(x==null)m=!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 y=d==null?null:d.group;if(y==null)m=!1;else{let b=!1;for(;x!=null&&y!=null;){if(x==y){b=x.ignore;break}x.depth<y.depth?y=y.group:x=x.group}m=b}}a=!m}if(!a)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,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.shapesUnderPoint(i,l,o,n);return s.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 s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.bodiesUnderPoint(i,l,o,n);return s.weak&&e.dispose(),r}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 o=s==null?null:s.zpp_inner??s;return this.zpp_inner.shapesInAABB(e,n,t,o,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 o=s==null?null:s.zpp_inner??s;return this.zpp_inner.bodiesInAABB(e,n,t,o,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,o=this.zpp_inner.shapesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),o}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,o=this.zpp_inner.bodiesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),o}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 o=i.polygon.valid();if(H.ValidationResult_VALID==null&&(H.internal=!0,H.ValidationResult_VALID=new(me()).shape.ValidationResult,H.internal=!1),o!=H.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.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 o=i.polygon.valid();if(H.ValidationResult_VALID==null&&(H.internal=!0,H.ValidationResult_VALID=new(me()).shape.ValidationResult,H.internal=!1),o!=H.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.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 o=s.shape.ShapeIterator.get(l);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=s.shape.ShapeIterator.zpp_pool,s.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,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 o=s.shape.ShapeIterator.get(l);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=s.shape.ShapeIterator.zpp_pool,s.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,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=Mi.ALL){if(e==null)throw new Error("Error: drawer cannot be null for Space::debugDraw");let n=(t&Mi.SHAPES)!==0,s=(t&Mi.JOINTS)!==0,i=(t&Mi.CONTACTS)!==0,l=(t&Mi.AABB)!==0,o=(t&Mi.CENTER_OF_MASS)!==0,r=(t&Mi.VELOCITIES)!==0,a=4283417591,p=4287669422,c=4294948685,h=4289058471,u=4293874512,x=1157627903,m=4294961979,d=4291728344;if(this.visitBodies(y=>{let b=y.zpp_inner,f=b.type===2,k=b.type===1?p:f?a:c;if(n){let _=b.shapes.head;for(;_!=null;){let z=_.elt;if(z.type===0){let C=z.circle;z.zip_worldCOM&&z.validate_worldCOM();let w=z.worldCOMx,g=z.worldCOMy,O=C.radius,E=b.rot,M=w+Math.cos(E)*O,N=g+Math.sin(E)*O,Z={x:w,y:g},A={x:M,y:N};f?e.drawSolidCircle(Z,O,A,k):e.drawCircle(Z,O,k)}else if(z.type===1){let C=z.polygon;C.zip_gverts&&C.validate_gverts();let w=[],g=C.gverts.next;for(;g!=null;)w.push({x:g.x,y:g.y}),g=g.next;w.length>=3&&(f?e.drawSolidPolygon(w,k):e.drawPolygon(w,k))}else if(z.type===2){let C=z.capsule;z.zip_aabb&&z.validate_aabb();let w={x:C.spine1x,y:C.spine1y},g={x:C.spine2x,y:C.spine2y};f?e.drawSolidCapsule(w,g,C.radius,k):e.drawCapsule(w,g,C.radius,k)}_=_.next}}if(l&&!b.world){let _=b.aabb,z=_.minx,C=_.miny,w=_.maxx,g=_.maxy;e.drawSegment({x:z,y:C},{x:w,y:C},x),e.drawSegment({x:w,y:C},{x:w,y:g},x),e.drawSegment({x:w,y:g},{x:z,y:g},x),e.drawSegment({x:z,y:g},{x:z,y:C},x)}if(o&&!b.world&&(b.validate_worldCOM(),e.drawPoint({x:b.worldCOMx,y:b.worldCOMy},m)),r&&!b.world&&f){let _=b.posx,z=b.posy;e.drawSegment({x:_,y:z},{x:_+b.velx,y:z+b.vely},d)}}),s&&this.visitConstraints(y=>{if(!y.debugDraw)return;let b=y.zpp_inner,f=b.b1,P=b.b2,k=b.a1worldx??(f!=null?f.posx:0),_=b.a1worldy??(f!=null?f.posy:0),z=b.a2worldx??(P!=null?P.posx:0),C=b.a2worldy??(P!=null?P.posy:0);e.drawSegment({x:k,y:_},{x:z,y:C},h),e.drawPoint({x:k,y:_},h),e.drawPoint({x:z,y:C},h)}),i){let y=b=>{if(b==null)return;let f=b.head;for(;f!=null;){let P=f.elt;if(P!=null){let k=P.nx,_=P.ny,z=P.contacts?.next;for(;z!=null;){let C=z.px,w=z.py;e.drawPoint({x:C,y:w},u),e.drawSegment({x:C,y:w},{x:C+k*8,y:w+_*8},u),z=z.next}}f=f.next}};y(this.zpp_inner.c_arbiters_true),y(this.zpp_inner.c_arbiters_false)}}toString(){return`Space(bodies=${this.bodies.length})`}};var Rn=class v{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 v,H.internal=!1),H.BodyType_STATIC}static get DYNAMIC(){return H.BodyType_DYNAMIC==null&&(H.internal=!0,H.BodyType_DYNAMIC=new v,H.internal=!1),H.BodyType_DYNAMIC}static get KINEMATIC(){return H.BodyType_KINEMATIC==null&&(H.internal=!0,H.BodyType_KINEMATIC=new v,H.internal=!1),H.BodyType_KINEMATIC}toString(){return this===H.BodyType_STATIC?"STATIC":this===H.BodyType_DYNAMIC?"DYNAMIC":this===H.BodyType_KINEMATIC?"KINEMATIC":""}},Xo=me();Xo.phys.BodyType=Rn;$l();var Qi=class v{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 v,H.internal=!1),H.MassMode_DEFAULT}static get FIXED(){return H.MassMode_FIXED==null&&(H.internal=!0,H.MassMode_FIXED=new v,H.internal=!1),H.MassMode_FIXED}toString(){return this===H.MassMode_DEFAULT?"DEFAULT":this===H.MassMode_FIXED?"FIXED":""}},Ho=me();Ho.phys.MassMode=Qi;var $i=class v{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 v,H.internal=!1),H.InertiaMode_DEFAULT}static get FIXED(){return H.InertiaMode_FIXED==null&&(H.internal=!0,H.InertiaMode_FIXED=new v,H.internal=!1),H.InertiaMode_FIXED}toString(){return this===H.InertiaMode_DEFAULT?"DEFAULT":this===H.InertiaMode_FIXED?"FIXED":""}},Qo=me();Qo.phys.InertiaMode=$i;var xi=class v{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 v,H.internal=!1),H.GravMassMode_DEFAULT}static get FIXED(){return H.GravMassMode_FIXED==null&&(H.internal=!0,H.GravMassMode_FIXED=new v,H.internal=!1),H.GravMassMode_FIXED}static get SCALED(){return H.GravMassMode_SCALED==null&&(H.internal=!0,H.GravMassMode_SCALED=new v,H.internal=!1),H.GravMassMode_SCALED}toString(){return this===H.GravMassMode_DEFAULT?"DEFAULT":this===H.GravMassMode_FIXED?"FIXED":this===H.GravMassMode_SCALED?"SCALED":""}},$o=me();$o.phys.GravMassMode=xi;var Zi=class v extends ni{constructor(e=50,t,n,s){super();let i=me(),l=new $n;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>qn.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 o=t.zpp_inner;o._validate!=null&&o._validate(),l.localCOMx=o.x,o._validate!=null&&o._validate(),l.localCOMy=o.y,o.weak&&t.dispose()}else l.localCOMx=0,l.localCOMy=0;n==null?Oe.zpp_pool!=null?(l.material=Oe.zpp_pool,Oe.zpp_pool=l.material.next,l.material.next=null):l.material=new Oe:(l.immutable_midstep("Shape::material"),l.setMaterial(n.zpp_inner),l.material.wrapper()),s==null?it.zpp_pool!=null?(l.filter=it.zpp_pool,it.zpp_pool=l.filter.next,l.filter.next=null):l.filter=new it:(l.immutable_midstep("Shape::filter"),l.setFilter(s.zpp_inner),l.filter.wrapper()),l.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof v?e:e instanceof $n?ke(e,t=>{let n=Object.create(v.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?v._wrap(e.zpp_inner_zn):ke(e,t=>{let n=Object.create(v.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>qn.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}};no(v=>Zi._wrap(v));var er=me();er.shape.Circle=Zi;var ki=class v extends ni{constructor(e,t,n){super();let s=me();if(e==null)throw new Error("Error: localVerts cannot be null");let i=new ei;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 Be))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 o=l.zpp_inner;o._validate!=null&&o._validate();let r=o.x;o._validate!=null&&o._validate();let a=o.y,p=new Be(r,a);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,o=l.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=s.geom.Vec2Iterator.zpp_pool,s.geom.Vec2Iterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let h=o.zpp_inner.at(o.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 m=u.y,d=new Be(x,m);i.wrap_lverts.push(d)}l.zpp_inner._validate!=null&&l.zpp_inner._validate();let r=l.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 s.geom.GeomPoly){let l=e.zpp_inner.vertices;if(l!=null){let o=l;do{i.wrap_lverts==null&&i.getlverts();let r=new Be(o.x,o.y);i.wrap_lverts.push(r),o=o.next}while(o!==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?Oe.zpp_pool!=null?(i.material=Oe.zpp_pool,Oe.zpp_pool=i.material.next,i.material.next=null):i.material=new Oe:(i.immutable_midstep("Shape::material"),i.setMaterial(t.zpp_inner),i.material.wrapper()),n==null?it.zpp_pool!=null?(i.filter=it.zpp_pool,it.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new it:(i.immutable_midstep("Shape::filter"),i.setFilter(n.zpp_inner),i.filter.wrapper()),i.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof v?e:e instanceof ei?ke(e,t=>{let n=Object.create(v.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?v._wrap(e.zpp_inner_zn):ke(e,t=>{let n=Object.create(v.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 Be(e,t);l.zpp_inner.weak=i;let o=new Be(e+n,t);o.zpp_inner.weak=i;let r=new Be(e+n,t+s);r.zpp_inner.weak=i;let a=new Be(e,t+s);return a.zpp_inner.weak=i,[l,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 v.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=[],o=Math.PI*2/n;for(let r=0;r<n;r++){let a=r*o+s,p=Math.cos(a)*e,c=Math.sin(a)*t,h=new Be(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()}};io(v=>ki._wrap(v));var tr=me();tr.shape.Polygon=ki;var Ei=class v extends ni{constructor(e=100,t=40,n,s,i){super();let l=me();if(e!==e||t!==t)throw new Error("Error: Capsule dimensions cannot be NaN");if(t<=0)throw new Error("Error: Capsule height ("+t+") must be > 0");if(e<t)throw new Error("Error: Capsule width ("+e+") must be >= height ("+t+")");let o=t/2,r=(e-t)/2,a=new ti;if(this.zpp_inner_zn=a,this.zpp_inner=a,this.zpp_inner_i=a,a.outer=this,a.outer_zn=this,a.outer_i=this,this._inner=this,o<l.Config.epsilon)throw new Error("Error: Capsule radius ("+o+") must be > Config.epsilon");if(o>qn.FMAX)throw new Error("Error: Capsule radius ("+o+") must be < PR(Const).FMAX");if(a.radius=o,a.halfLength=r,a.invalidate_radius(),r>0&&a.invalidate_halfLength(),n!=null){if(n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=n.zpp_inner;p._validate!=null&&p._validate(),a.localCOMx=p.x,p._validate!=null&&p._validate(),a.localCOMy=p.y,p.weak&&n.dispose()}else a.localCOMx=0,a.localCOMy=0;s==null?Oe.zpp_pool!=null?(a.material=Oe.zpp_pool,Oe.zpp_pool=a.material.next,a.material.next=null):a.material=new Oe:(a.immutable_midstep("Shape::material"),a.setMaterial(s.zpp_inner),a.material.wrapper()),i==null?it.zpp_pool!=null?(a.filter=it.zpp_pool,it.zpp_pool=a.filter.next,a.filter.next=null):a.filter=new it:(a.immutable_midstep("Shape::filter"),a.setFilter(i.zpp_inner),a.filter.wrapper()),a.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof v?e:e instanceof ti?ke(e,t=>{let n=Object.create(v.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?v._wrap(e.zpp_inner_zn):ke(e,t=>{let n=Object.create(v.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("Capsule::radius"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modify radius of Capsule contained in static object once added to space");if(e!==t.radius){if(e!==e)throw new Error("Error: Capsule::radius cannot be NaN");if(e<n.Config.epsilon)throw new Error("Error: Capsule::radius ("+e+") must be > Config.epsilon");if(e>qn.FMAX)throw new Error("Error: Capsule::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}get halfLength(){return this.zpp_inner_zn.halfLength}set halfLength(e){let t=this.zpp_inner_zn;if(this.zpp_inner.immutable_midstep("Capsule::halfLength"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modify halfLength of Capsule contained in static object once added to space");if(e!==t.halfLength){if(e!==e)throw new Error("Error: Capsule::halfLength cannot be NaN");if(e<0)throw new Error("Error: Capsule::halfLength ("+e+") must be >= 0");t.halfLength=e,t.invalidate_halfLength()}}get width(){return 2*(this.zpp_inner_zn.halfLength+this.zpp_inner_zn.radius)}get height(){return 2*this.zpp_inner_zn.radius}};so(v=>Ei._wrap(v));var nr=me();nr.shape.Capsule=Ei;var es=class v{get _inner(){return this}constructor(e=0,t=1,n=2,s=1,i=.001){let l;if(Oe.zpp_pool==null?l=new Oe:(l=Oe.zpp_pool,Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.ANGDRAG|Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.ARBITERS)}}static _wrap(e){return e instanceof v?e:e?e instanceof Oe?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.ANGDRAG|Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.ARBITERS)}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}copy(){let e=new v(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 v(.4,.2,.38,.7,.005)}static steel(){return new v(.2,.57,.74,7.8,.001)}static ice(){return new v(.3,.03,.1,.9,1e-4)}static rubber(){return new v(.8,1,1.4,1.5,.01)}static glass(){return new v(.4,.4,.94,2.6,.002)}static sand(){return new v(-1,.45,.6,1.6,16)}};Oe._wrapFn=v=>ke(v,e=>{let t=Object.create(es.prototype);return t.zpp_inner=e,e.outer=t,t});var ts=class v{get _inner(){return this}constructor(e=1,t=-1,n=1,s=-1,i=1,l=-1){let o;it.zpp_pool==null?o=new it:(o=it.zpp_pool,it.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!=s&&(o.sensorMask=s,o.invalidate()),o.fluidGroup!=i&&(o.fluidGroup=i,o.invalidate()),o.fluidMask!=l&&(o.fluidMask=l,o.invalidate())}static _wrap(e){return e instanceof v?e:e?e instanceof it?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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 v(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)+" }"}};it._wrapFn=v=>ke(v,e=>{let t=Object.create(ts.prototype);return t.zpp_inner=e,e.outer=t,t});var Ni=class v{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 v,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 v,H.internal=!1),H.Broadphase_SWEEP_AND_PRUNE}static get SPATIAL_HASH(){return H.Broadphase_SPATIAL_HASH==null&&(H.internal=!0,H.Broadphase_SPATIAL_HASH=new v,H.internal=!1),H.Broadphase_SPATIAL_HASH}toString(){return this===H.Broadphase_DYNAMIC_AABB_TREE?"DYNAMIC_AABB_TREE":this===H.Broadphase_SWEEP_AND_PRUNE?"SWEEP_AND_PRUNE":this===H.Broadphase_SPATIAL_HASH?"SPATIAL_HASH":""}};var ns=class ns{constructor(){this.debugDraw=!0;this._inner=this}static _wrap(e){return e==null?null:e instanceof ns?e:e.zpp_inner?.outer instanceof ns?e.zpp_inner.outer:ke(e,t=>{let n=Object.create(ns.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 ns._wrap(this.zpp_inner.copy())}toString(){return"{Constraint}"}};ns.zpp_internalAlloc=!1;var ln=ns;function ro(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 ao(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 kl(v){v.zpp_inner.weak&&v.dispose()}var is=class v extends ln{constructor(e,t,n,s){super();let i=new fi;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=ro(n),i.a1localy=ao(n),kl(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=ro(s),i.a2localy=ao(s),kl(s)}static _wrap(e){return e==null?null:e instanceof v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof fi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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),kl(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),kl(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}};fi._wrapFn=v=>ke(v,e=>{let t=Object.create(is.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function po(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 co(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 El(v){v.zpp_inner.weak&&v.dispose()}var ss=class v extends ln{constructor(e,t,n,s,i,l){super();let o=new yi;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=po(n),a=co(n);if(o.a1localx=r,o.a1localy=a,El(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=po(s),c=co(s);if(o.a2localx=p,o.a2localy=c,El(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(o.jointMin!=i&&(o.jointMin=i,o.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");o.jointMax!=l&&(o.jointMax=l,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 yi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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),El(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),El(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}};yi._wrapFn=v=>ke(v,e=>{let t=Object.create(ss.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var ls=class v extends ln{constructor(e,t,n,s,i=1){super();let l=new qe;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 v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof qe?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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}};qe._wrapFn=v=>ke(v,e=>{let t=Object.create(ls.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var os=class v extends ln{constructor(e,t,n=0,s=1){super();let i=new bi;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 v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof bi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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}};bi._wrapFn=v=>ke(v,e=>{let t=Object.create(os.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Gl(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 Ns(v){v.zpp_inner.weak&&v.dispose()}var rs=class v extends ln{constructor(e,t,n,s,i,l,o){super();let r=new mi;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=Gl(n),r.a1localy=ql(n),Ns(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(r.a2localx=Gl(s),r.a2localy=ql(s),Ns(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(r.nlocalx=Gl(i),r.nlocaly=ql(i),r.zip_n=!0,Ns(i),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),l!==l)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(r.jointMin!=l&&(r.jointMin=l,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 mi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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),Ns(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),Ns(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),Ns(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}};mi._wrapFn=v=>ke(v,e=>{let t=Object.create(rs.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var nl=class v{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 v?e:e?e instanceof Gi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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 v(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 v(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 v(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 o=0;o<this.zpp_inner.n;o++)l+=this.zpp_inner.x[s*this.zpp_inner.n+o]*t.zpp_inner.x[o*t.zpp_inner.n+i];n.zpp_inner.x[s*n.zpp_inner.n+i]=l}return n}},ir=me();ir.geom.MatMN=nl;function il(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 sl(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 as=class v extends ln{constructor(e,t,n,s,i,l,o,r,a,p,c=1){super();let h=new zi;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(o,"anchor3",(u,x)=>{h.a3localx=u,h.a3localy=x}),this._setAnchorInit(r,"anchor4",(u,x)=>{h.a4localx=u,h.a4localy=x}),h.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(h.jointMin!=a&&(h.jointMin=a,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(il(e),sl(e)),ll(e)}static _wrap(e){return e==null?null:e instanceof v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof zi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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(),il(e),sl(e),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(),il(e),sl(e),this.zpp_inner.wrap_a2.set(e),ll(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(),il(e),sl(e),this.zpp_inner.wrap_a3.set(e),ll(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(),il(e),sl(e),this.zpp_inner.wrap_a4.set(e),ll(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 nl(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):ui.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}};zi._wrapFn=v=>ke(v,e=>{let t=Object.create(as.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function ho(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 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.y}function Nl(v){v.zpp_inner.weak&&v.dispose()}var ps=class v extends ln{constructor(e,t,n,s,i=0){super();let l=new Pi;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=ho(n),l.a1localy=uo(n),Nl(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=ho(s),l.a2localy=uo(s),Nl(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 v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof Pi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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),Nl(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),Nl(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}};Pi._wrapFn=v=>ke(v,e=>{let t=Object.create(ps.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var si=class v extends Ci{constructor(){super();let e=new Wn;this.zpp_inner=e,e.outer=this,e.outer_i=this,this.zpp_inner_i=e,this._inner=this,e.insert_cbtype(pn.ANY_COMPOUND.zpp_inner)}static _wrap(e){return e?e instanceof v?e:e instanceof Wn?ke(e,t=>{let n=Object.create(v.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?v._wrap(e.zpp_inner):ke(e,t=>{let n=Object.create(v.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:ii._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 Be(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 o=s.zpp_inner.cmass;t.addeq(l.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(s=>{s.rotate(e,t)}),e.zpp_inner.weak=n,e.zpp_inner.weak&&e.dispose(),this}toString(){return"Compound"+this.zpp_inner.id}};Wn._wrapFn=v=>ke(v,e=>{let t=Object.create(si.prototype);return t.zpp_inner=e,e.outer=t,e.outer_i=t,t.zpp_inner_i=e,t._inner=t,t});Object.defineProperty(si.prototype,"bodies",{get:function(){return this.zpp_inner.wrap_bodies},configurable:!0});Object.defineProperty(si.prototype,"constraints",{get:function(){return this.zpp_inner.wrap_constraints},configurable:!0});Object.defineProperty(si.prototype,"compounds",{get:function(){return this.zpp_inner.wrap_compounds},configurable:!0});function Oi(v){return Be.get(v.x,v.y)}function un(v){return Be.weak(v.x,v.y)}function sr(v){return new es(v.elasticity,v.dynamicFriction,v.staticFriction,v.density,v.rollingFriction)}function lr(v){let e=new ts;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 or(v){let e=new On(v.density,v.viscosity);return v.gravity!=null&&(e.gravity=Oi(v.gravity)),e}function rr(v){let e=sr(v.material),t=lr(v.filter),n;if(v.type==="circle"){let s=Oi(v.localCOM);n=new Zi(v.radius,s,e,t)}else if(v.type==="capsule"){let s=Oi(v.localCOM);n=new Ei(v.width,v.height,s,e,t)}else{let s=v.localVerts.map(i=>Oi(i));n=new ki(s,e,t)}return n.sensorEnabled=v.sensorEnabled,n.fluidEnabled=v.fluidEnabled,v.fluidEnabled&&v.fluidProperties!=null&&(n.fluidProperties=or(v.fluidProperties)),n}function ar(v){let e=v.type==="STATIC"?Rn.STATIC:v.type==="KINEMATIC"?Rn.KINEMATIC:Rn.DYNAMIC,t=new We(e,un(v.position));t.rotation=v.rotation,v.type!=="STATIC"&&(t.velocity=Oi(v.velocity),t.angularVel=v.angularVel),t.kinematicVel=Oi(v.kinematicVel),t.kinAngVel=v.kinAngVel,t.surfaceVel=Oi(v.surfaceVel),v.type==="DYNAMIC"&&(t.force=Oi(v.force),t.torque=v.torque),v.massMode==="FIXED"&&v.mass!=null?t.mass=v.mass:v.massMode==="DEFAULT"&&(t.massMode=Qi.DEFAULT),v.inertiaMode==="FIXED"&&v.inertia!=null?t.inertia=v.inertia:v.inertiaMode==="DEFAULT"&&(t.inertiaMode=$i.DEFAULT),v.gravMassMode==="SCALED"?(t.gravMassMode=xi.SCALED,t.gravMassScale=v.gravMassScale):v.gravMassMode==="FIXED"&&(t.gravMassMode=xi.FIXED),t.allowMovement=v.allowMovement,t.allowRotation=v.allowRotation,t.isBullet=v.bullet;for(let n of v.shapes)rr(n).body=t;return v.userData!=null&&Object.assign(t.userData,v.userData),t}function cs(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 pr(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 s=new is(t,n,un(v.anchor1),un(v.anchor2));return cs(s,v),s}case"DistanceJoint":{let s=new ss(t,n,un(v.anchor1),un(v.anchor2),v.jointMin,v.jointMax);return cs(s,v),s}case"AngleJoint":{let s=new ls(t,n,v.jointMin,v.jointMax,v.ratio);return cs(s,v),s}case"MotorJoint":{let s=new os(t,n,v.rate,v.ratio);return cs(s,v),s}case"LineJoint":{let s=new rs(t,n,un(v.anchor1),un(v.anchor2),un(v.direction),v.jointMin,v.jointMax);return cs(s,v),s}case"PulleyJoint":{let s=new as(t,n,null,null,un(v.anchor1),un(v.anchor2),un(v.anchor3),un(v.anchor4),v.jointMin,v.jointMax,v.ratio);return cs(s,v),s}case"WeldJoint":{let s=new ps(t,n,un(v.anchor1),un(v.anchor2),v.phase);return cs(s,v),s}}}function xo(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"?Ni.SWEEP_AND_PRUNE:Ni.DYNAMIC_AABB_TREE,t=new ii(un(v.gravity),e);t.worldLinearDrag=v.worldLinearDrag,t.worldAngularDrag=v.worldAngularDrag,t.sortContacts=v.sortContacts,t.deterministic=v.deterministic??!1;let n=v.bodies.map(ar),s=v.constraints.map(o=>pr(o,n)),i=new Set,l=new Set;for(let o of v.compounds){let r=new si;for(let a of o.bodyIds)n[a].compound=r,i.add(a);for(let a of o.constraintIndices)s[a].compound=r,l.add(a);r.space=t}for(let o=0;o<n.length;o++)i.has(o)||(n[o].space=t);for(let o=0;o<s.length;o++)l.has(o)||(s[o].space=t);return t}var Ol=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 cr=1312903237,Os=2,hr=0,ur=1,xr=2,dr=3,_r=4,yr=5,mr=6;function br(v,e){v.writeFloat64(e.elasticity),v.writeFloat64(e.dynamicFriction),v.writeFloat64(e.staticFriction),v.writeFloat64(e.density),v.writeFloat64(e.rollingFriction)}function fr(v,e){v.writeInt32(e.collisionGroup),v.writeInt32(e.collisionMask),v.writeInt32(e.sensorGroup),v.writeInt32(e.sensorMask),v.writeInt32(e.fluidGroup),v.writeInt32(e.fluidMask)}function zr(v,e){if(e==null)return;v.writeFloat64(e.density),v.writeFloat64(e.viscosity);let t=e.gravity;v.writeBool(t!=null),t!=null&&(v.writeFloat64(t.x),v.writeFloat64(t.y))}function Pr(v,e){if(e.isCircle()){v.writeUint8(0);let i=e;v.writeFloat64(i.radius);let l=e.localCOM;v.writeFloat64(l.x),v.writeFloat64(l.y)}else if(e.isCapsule()){v.writeUint8(2);let i=e;v.writeFloat64(i.width),v.writeFloat64(i.height);let l=e.localCOM;v.writeFloat64(l.x),v.writeFloat64(l.y)}else{v.writeUint8(1);let l=e.localVerts,o=l.length;v.writeUint16(o);for(let r=0;r<o;r++){let a=l.at(r);v.writeFloat64(a.x),v.writeFloat64(a.y)}}br(v,e.material),fr(v,e.filter);let t=e.fluidEnabled,n=t&&e.fluidProperties!=null,s=(e.sensorEnabled?1:0)|(t?2:0)|(n?4:0);v.writeUint8(s),n&&zr(v,e.fluidProperties)}function wr(v,e){let t=e.zpp_inner;v.writeUint8(t.type),v.writeFloat64(e.position.x),v.writeFloat64(e.position.y),v.writeFloat64(e.rotation),v.writeFloat64(e.velocity.x),v.writeFloat64(e.velocity.y),v.writeFloat64(e.angularVel),v.writeFloat64(e.kinematicVel.x),v.writeFloat64(e.kinematicVel.y),v.writeFloat64(e.kinAngVel),v.writeFloat64(e.surfaceVel.x),v.writeFloat64(e.surfaceVel.y),v.writeFloat64(e.force.x),v.writeFloat64(e.force.y),v.writeFloat64(t.type===2?e.torque:0),v.writeUint8(t.massMode),v.writeFloat64(t.massMode===1?t.cmass:0),v.writeUint8(t.inertiaMode),v.writeFloat64(t.inertiaMode===1?t.cinertia:0),v.writeUint8(t.gravMassMode),v.writeFloat64(t.gravMassScale);let n=(e.allowMovement?1:0)|(e.allowRotation?2:0)|(e.isBullet?4:0);v.writeUint8(n);let s=e.shapes,i=s.length;v.writeUint16(i);for(let l=0;l<i;l++)Pr(v,s.at(l))}var _o={PivotJoint:hr,DistanceJoint:ur,AngleJoint:xr,MotorJoint:dr,LineJoint:_r,PulleyJoint:yr,WeldJoint:mr};function hs(v,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;v.writeInt32(i),v.writeInt32(l);let o=e.zpp_inner,r=(o.active?1:0)|(o.ignore?2:0)|(o.stiff?4:0)|(o.breakUnderForce?8:0)|(o.breakUnderError?16:0)|(o.removeOnBreak?32:0);v.writeUint8(r),v.writeFloat64(o.frequency),v.writeFloat64(o.damping),v.writeFloat64(o.maxForce),v.writeFloat64(o.maxError)}function vr(v,e,t){let n=e.constructor?.name??"",s=_o[n];if(s===void 0)return!1;switch(v.writeUint8(s),n){case"PivotJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y);break}case"DistanceJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y),v.writeFloat64(i.jointMin),v.writeFloat64(i.jointMax);break}case"AngleJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.jointMin),v.writeFloat64(i.jointMax),v.writeFloat64(i.ratio);break}case"MotorJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.rate),v.writeFloat64(i.ratio);break}case"LineJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y),v.writeFloat64(i.direction.x),v.writeFloat64(i.direction.y),v.writeFloat64(i.jointMin),v.writeFloat64(i.jointMax);break}case"PulleyJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y),v.writeFloat64(i.anchor3.x),v.writeFloat64(i.anchor3.y),v.writeFloat64(i.anchor4.x),v.writeFloat64(i.anchor4.y),v.writeFloat64(i.jointMin),v.writeFloat64(i.jointMax),v.writeFloat64(i.ratio);break}case"WeldJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y),v.writeFloat64(i.phase);break}}return!0}function yo(v){let e=new Ol,t=[],n=new Map,s=new Map;function i(d){let y=d.zpp_inner.id;if(n.has(y))return;let b=t.length;s.set(d,b),n.set(y,b),t.push(d)}let l=v.bodies,o=l.length;for(let d=0;d<o;d++)i(l.at(d));let r=v.compounds,a=r.length;for(let d=0;d<a;d++){let b=r.at(d).bodies,f=b.length;for(let P=0;P<f;P++)i(b.at(P))}let p=[],c=new Map;function h(d){if(c.has(d))return;let y=d.constructor?.name??"";_o[y]!==void 0&&(c.set(d,p.length),p.push(d))}let u=v.constraints,x=u.length;for(let d=0;d<x;d++)h(u.at(d));for(let d=0;d<a;d++){let b=r.at(d).constraints,f=b.length;for(let P=0;P<f;P++)h(b.at(P))}e.writeUint32(cr),e.writeUint16(Os),e.writeUint32(t.length),e.writeUint32(p.length),e.writeUint32(a);let m=v.gravity;e.writeFloat64(m.x),e.writeFloat64(m.y),e.writeFloat64(v.worldLinearDrag),e.writeFloat64(v.worldAngularDrag),e.writeBool(v.sortContacts),e.writeBool(v.deterministic),e.writeUint8(v.zpp_inner.bphase.is_sweep?0:1);for(let d=0;d<t.length;d++)wr(e,t[d]);for(let d=0;d<p.length;d++)vr(e,p[d],n);for(let d=0;d<a;d++){let y=r.at(d),b=y.bodies,f=b.length;e.writeUint16(f);for(let z=0;z<f;z++){let C=b.at(z),w=s.get(C)??0;e.writeUint32(w)}let P=y.constraints,k=P.length,_=0;for(let z=0;z<k;z++){let C=P.at(z);c.has(C)&&_++}e.writeUint16(_);for(let z=0;z<k;z++){let C=P.at(z),w=c.get(C);w!=null&&e.writeUint32(w)}e.writeUint16(0)}return e.finish()}var Sl=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 mo=1312903237,gr=0,Cr=1,Mr=2,Zr=3,kr=4,Er=5,Nr=6,Or={1:Rn.STATIC,2:Rn.DYNAMIC,3:Rn.KINEMATIC};function Jl(v){let e=v.readFloat64(),t=v.readFloat64(),n=v.readFloat64(),s=v.readFloat64(),i=v.readFloat64();return new es(e,t,n,s,i)}function Ul(v){let e=new ts;return e.collisionGroup=v.readInt32(),e.collisionMask=v.readInt32(),e.sensorGroup=v.readInt32(),e.sensorMask=v.readInt32(),e.fluidGroup=v.readInt32(),e.fluidMask=v.readInt32(),e}function Sr(v){let e=v.readFloat64(),t=v.readFloat64(),n=new On(e,t);return v.readBool()&&(n.gravity=Be.get(v.readFloat64(),v.readFloat64())),n}function Ar(v){let e=v.readUint8(),t;if(e===0){let i=v.readFloat64(),l=v.readFloat64(),o=v.readFloat64(),r=Jl(v),a=Ul(v);t=new Zi(i,Be.weak(l,o),r,a)}else if(e===2){let i=v.readFloat64(),l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=Jl(v),p=Ul(v);t=new Ei(i,l,Be.weak(o,r),a,p)}else{let i=v.readUint16(),l=[];for(let a=0;a<i;a++)l.push(Be.get(v.readFloat64(),v.readFloat64()));let o=Jl(v),r=Ul(v);t=new ki(l,o,r)}let n=v.readUint8();return t.sensorEnabled=(n&1)!==0,t.fluidEnabled=(n&2)!==0,(n&4)!==0&&(t.fluidProperties=Sr(v)),t}function Vr(v){let e=v.readUint8(),t=Or[e]??Rn.DYNAMIC,n=v.readFloat64(),s=v.readFloat64(),i=v.readFloat64(),l=new We(t,Be.weak(n,s));l.rotation=i;let o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64();e!==1&&(l.velocity=Be.get(o,r),l.angularVel=a),l.kinematicVel=Be.get(v.readFloat64(),v.readFloat64()),l.kinAngVel=v.readFloat64(),l.surfaceVel=Be.get(v.readFloat64(),v.readFloat64());let p=v.readFloat64(),c=v.readFloat64(),h=v.readFloat64();e===2&&(l.force=Be.get(p,c),l.torque=h);let u=v.readUint8(),x=v.readFloat64();u===1&&x!==0?l.mass=x:u===0&&(l.massMode=Qi.DEFAULT);let m=v.readUint8(),d=v.readFloat64();m===1&&d!==0?l.inertia=d:m===0&&(l.inertiaMode=$i.DEFAULT);let y=v.readUint8(),b=v.readFloat64();y===2?(l.gravMassMode=xi.SCALED,l.gravMassScale=b):y===1&&(l.gravMassMode=xi.FIXED);let f=v.readUint8();l.allowMovement=(f&1)!==0,l.allowRotation=(f&2)!==0,l.isBullet=(f&4)!==0;let P=v.readUint16();for(let k=0;k<P;k++)Ar(v).body=l;return l}function Ir(v){let e=v.readInt32(),t=v.readInt32(),n=v.readUint8(),s=v.readFloat64(),i=v.readFloat64(),l=v.readFloat64(),o=v.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:o}}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}function Br(v,e){let t=v.readUint8(),n=Ir(v),s=n.body1Id>=0?e[n.body1Id]??null:null,i=n.body2Id>=0?e[n.body2Id]??null:null;switch(t){case gr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=new is(s,i,Be.weak(l,o),Be.weak(r,a));return us(p,n),p}case Cr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=v.readFloat64(),c=v.readFloat64(),h=new ss(s,i,Be.weak(l,o),Be.weak(r,a),p,c);return us(h,n),h}case Mr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=new ls(s,i,l,o,r);return us(a,n),a}case Zr:{let l=v.readFloat64(),o=v.readFloat64(),r=new os(s,i,l,o);return us(r,n),r}case kr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=v.readFloat64(),c=v.readFloat64(),h=v.readFloat64(),u=v.readFloat64(),x=new rs(s,i,Be.weak(l,o),Be.weak(r,a),Be.weak(p,c),h,u);return us(x,n),x}case Er:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=v.readFloat64(),c=v.readFloat64(),h=v.readFloat64(),u=v.readFloat64(),x=v.readFloat64(),m=v.readFloat64(),d=v.readFloat64(),y=new as(s,i,null,null,Be.weak(l,o),Be.weak(r,a),Be.weak(p,c),Be.weak(h,u),x,m,d);return us(y,n),y}case Nr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=v.readFloat64(),c=new ps(s,i,Be.weak(l,o),Be.weak(r,a),p);return us(c,n),c}default:throw new Error(`nape-js binary: unknown constraint type tag ${t}`)}}function bo(v){let e=new Sl(v),t=e.readUint32();if(t!==mo)throw new Error(`nape-js binary: invalid magic bytes 0x${t.toString(16)} (expected 0x${mo.toString(16)})`);let n=e.readUint16();if(n!==Os)throw new Error(`nape-js binary: unsupported version ${n} (expected ${Os})`);let s=e.readUint32(),i=e.readUint32(),l=e.readUint32(),o=e.readFloat64(),r=e.readFloat64(),a=e.readFloat64(),p=e.readFloat64(),c=e.readBool(),h=e.readBool(),x=e.readUint8()===0?Ni.SWEEP_AND_PRUNE:Ni.DYNAMIC_AABB_TREE,m=new ii(Be.weak(o,r),x);m.worldLinearDrag=a,m.worldAngularDrag=p,m.sortContacts=c,m.deterministic=h;let d=new Array(s);for(let P=0;P<s;P++)d[P]=Vr(e);let y=new Array(i);for(let P=0;P<i;P++)y[P]=Br(e,d);let b=new Set,f=new Set;for(let P=0;P<l;P++){let k=new si,_=e.readUint16();for(let w=0;w<_;w++){let g=e.readUint32();d[g].compound=k,b.add(g)}let z=e.readUint16();for(let w=0;w<z;w++){let g=e.readUint32();y[g].compound=k,f.add(g)}let C=e.readUint16();for(let w=0;w<C;w++)e.readUint32();k.space=m}for(let P=0;P<s;P++)b.has(P)||(d[P].space=m);for(let P=0;P<i;P++)f.has(P)||(y[P].space=m);return m}0&&(module.exports={BINARY_SNAPSHOT_VERSION,SNAPSHOT_VERSION,spaceFromBinary,spaceFromJSON,spaceToBinary,spaceToJSON});
|
|
1
|
+
"use strict";var Bl=Object.defineProperty;var fo=Object.getOwnPropertyDescriptor;var zo=Object.getOwnPropertyNames;var Po=Object.prototype.hasOwnProperty;var wo=(v,e)=>{for(var t in e)Bl(v,t,{get:e[t],enumerable:!0})},vo=(v,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of zo(e))!Po.call(v,s)&&s!==t&&Bl(v,s,{get:()=>e[s],enumerable:!(n=fo(e,s))||n.enumerable});return v};var go=v=>vo(Bl({},"__esModule",{value:!0}),v);var jr={};wo(jr,{BINARY_SNAPSHOT_VERSION:()=>Os,SNAPSHOT_VERSION:()=>Ss,spaceFromBinary:()=>bo,spaceFromJSON:()=>xo,spaceToBinary:()=>yo,spaceToJSON:()=>Yl});module.exports=go(jr);var Ss=1;function ht(v){return{x:v.x,y:v.y}}function Kl(v){if(v==null)return null;try{let e=JSON.stringify(v);return e==="{}"?null:JSON.parse(e)}catch{return null}}function Co(v){return{elasticity:v.elasticity,dynamicFriction:v.dynamicFriction,staticFriction:v.staticFriction,density:v.density,rollingFriction:v.rollingFriction}}function Mo(v){return{collisionGroup:v.collisionGroup,collisionMask:v.collisionMask,sensorGroup:v.sensorGroup,sensorMask:v.sensorMask,fluidGroup:v.fluidGroup,fluidMask:v.fluidMask}}function Zo(v){if(v==null)return null;let e=v.gravity;return{density:v.density,viscosity:v.viscosity,gravity:e!=null?ht(e):null}}function ko(v){let e=Co(v.material),t=Mo(v.filter),n=v.fluidEnabled,s=n?Zo(v.fluidProperties):null,i=v.sensorEnabled;if(v.isCircle()){let l=v,o=v.localCOM;return{type:"circle",radius:l.radius,localCOM:ht(o),material:e,filter:t,sensorEnabled:i,fluidEnabled:n,fluidProperties:s}}else if(v.isCapsule()){let l=v,o=v.localCOM;return{type:"capsule",width:l.width,height:l.height,localCOM:ht(o),material:e,filter:t,sensorEnabled:i,fluidEnabled:n,fluidProperties:s}}else{let o=v.localVerts,r=[],a=o.length;for(let p=0;p<a;p++)r.push(ht(o.at(p)));return{type:"polygon",localVerts:r,material:e,filter:t,sensorEnabled:i,fluidEnabled:n,fluidProperties:s}}}var Eo={1:"STATIC",2:"DYNAMIC",3:"KINEMATIC"},No={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},Oo={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},So={0:"DEFAULT",1:"FIXED",2:"SCALED"};function Ao(v,e){let t=v.zpp_inner,n=No[t.massMode]??"DEFAULT",s=Oo[t.inertiaMode]??"DEFAULT",i=So[t.gravMassMode]??"DEFAULT",l=[],o=v.shapes,r=o.length;for(let a=0;a<r;a++)l.push(ko(o.at(a)));return{id:e,type:Eo[t.type]??"DYNAMIC",position:ht(v.position),rotation:v.rotation,velocity:ht(v.velocity),angularVel:v.angularVel,kinematicVel:ht(v.kinematicVel),kinAngVel:v.kinAngVel,surfaceVel:ht(v.surfaceVel),force:ht(v.force),torque:t.type===2?v.torque:0,massMode:n,mass:n==="FIXED"?t.cmass:null,inertiaMode:s,inertia:s==="FIXED"?t.cinertia:null,gravMassMode:i,gravMassScale:t.gravMassScale,allowMovement:v.allowMovement,allowRotation:v.allowRotation,bullet:v.isBullet,shapes:l,userData:Kl(t.userData)}}function Ii(v,e,t,n){let s=v.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:Kl(s.userData)}}function Vo(v,e){switch(v.constructor?.name??""){case"PivotJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"PivotJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2)}}case"DistanceJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"DistanceJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2),jointMin:n.jointMin,jointMax:n.jointMax}}case"AngleJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"AngleJoint",jointMin:n.jointMin,jointMax:n.jointMax,ratio:n.ratio}}case"MotorJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"MotorJoint",rate:n.rate,ratio:n.ratio}}case"LineJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"LineJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2),direction:ht(n.direction),jointMin:n.jointMin,jointMax:n.jointMax}}case"PulleyJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"PulleyJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2),anchor3:ht(n.anchor3),anchor4:ht(n.anchor4),jointMin:n.jointMin,jointMax:n.jointMax,ratio:n.ratio}}case"WeldJoint":{let n=v;return{...Ii(v,e,n.body1,n.body2),type:"WeldJoint",anchor1:ht(n.anchor1),anchor2:ht(n.anchor2),phase:n.phase}}default:return null}}function Yl(v){let e=[],t=new Map,n=new Map;function s(f){let b=f.zpp_inner.id;if(n.has(b))return;let P=e.length;t.set(f,P),n.set(b,P),e.push(Ao(f,P))}let i=v.bodies,l=i.length;for(let f=0;f<l;f++)s(i.at(f));let o=v.compounds,r=o.length;for(let f=0;f<r;f++){let P=o.at(f).bodies,k=P.length;for(let _=0;_<k;_++)s(P.at(_))}let a=[],p=new Map;function c(f){if(p.has(f))return;let b=Vo(f,n);b!=null&&(p.set(f,a.length),a.push(b))}let h=v.constraints,u=h.length;for(let f=0;f<u;f++)c(h.at(f));for(let f=0;f<r;f++){let P=o.at(f).constraints,k=P.length;for(let _=0;_<k;_++)c(P.at(_))}let x=[];for(let f=0;f<r;f++){let b=o.at(f),P=[],k=b.bodies,_=k.length;for(let g=0;g<_;g++){let O=k.at(g),E=t.get(O);E!=null&&P.push(E)}let z=[],C=b.constraints,w=C.length;for(let g=0;g<w;g++){let O=C.at(g),E=p.get(O);E!=null&&z.push(E)}x.push({bodyIds:P,constraintIndices:z,childIndices:[]})}let d=v.zpp_inner.bphase.is_sweep?"SWEEP_AND_PRUNE":"DYNAMIC_AABB_TREE",y=v.gravity;return{version:1,gravity:ht(y),worldLinearDrag:v.worldLinearDrag,worldAngularDrag:v.worldAngularDrag,sortContacts:v.sortContacts,deterministic:v.deterministic,broadphase:d,bodies:e,constraints:a,compounds:x}}var qn=class{static POSINF(){return 1/0}static NEGINF(){return-1/0}};qn.FMAX=1e100;var gt=class gt{static Constraint(){return gt._Constraint++}static Interactor(){return gt._Interactor++}static CbType(){return gt._CbType++}static CbSet(){return gt._CbSet++}static Listener(){return gt._Listener++}static ZPP_SimpleVert(){return gt._ZPP_SimpleVert++}static ZPP_SimpleSeg(){return gt._ZPP_SimpleSeg++}static Space(){return gt._Space++}static InteractionGroup(){return gt._InteractionGroup++}};gt._Constraint=0,gt._Interactor=0,gt._CbType=0,gt._CbSet=0,gt._Listener=0,gt._ZPP_SimpleVert=0,gt._ZPP_SimpleSeg=0,gt._Space=0,gt._InteractionGroup=0;var yn=gt;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.ShapeType_CAPSULE=null,H.Broadphase_DYNAMIC_AABB_TREE=null,H.Broadphase_SWEEP_AND_PRUNE=null,H.Broadphase_SPATIAL_HASH=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_ShapeType_CAPSULE=2,H.id_Broadphase_DYNAMIC_AABB_TREE=0,H.id_Broadphase_SWEEP_AND_PRUNE=1,H.id_Broadphase_SPATIAL_HASH=2,H.id_ArbiterType_COLLISION=1,H.id_ArbiterType_SENSOR=2,H.id_ArbiterType_FLUID=4;var al=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 ye=class{};ye.poolGeomPoly=null,ye.nextGeomPoly=null,ye.poolVec2=null,ye.nextVec2=null,ye.poolVec3=null,ye.nextVec3=null;var As=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}},ds=class extends As{},_s=class extends As{},ys=class extends As{};var wn=class wn{constructor(){this.value=!1;this.next=null;this.hnext=null;this.id=0;this.di=0}static _alloc(){if(wn.zpp_pool==null)return new wn;let e=wn.zpp_pool;return wn.zpp_pool=e.next,e.next=null,e}static get(e,t,n){let s=wn._alloc();return s.id=e,s.di=t,s.value=n,s}static getpersist(e,t){let n=wn._alloc();return n.id=e,n.di=t,n}static ordered_get(e,t,n){if(e<=t){let s=wn._alloc();return s.id=e,s.di=t,s.value=n,s}else{let s=wn._alloc();return s.id=t,s.di=e,s.value=n,s}}static ordered_get_persist(e,t){if(e<=t){let n=wn._alloc();return n.id=e,n.di=t,n}else{let n=wn._alloc();return n.id=t,n.di=e,n}}free(){}alloc(){}};wn.zpp_pool=null;var Te=wn;var Io=1048576,Bi=1048575,ji=106039,Ti=class{constructor(){this.cnt=0;this.cnt=0,this.table=new Array(Io).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*ji+t&Bi];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*ji+t&Bi];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*ji+t&Bi];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*ji+e.di&Bi,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*ji+e.di&Bi,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*ji+e.di&Bi,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*ji+t&Bi}};var Vs=class{constructor(){this.elt=null;this.next=null}alloc(){}free(){this.elt=null}elem(){return this.elt}};Vs.zpp_pool=null;var dt=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}};dt.prototype.inlined_add=dt.prototype.add;dt.prototype.inlined_insert=dt.prototype.insert;dt.prototype.inlined_pop=dt.prototype.pop;dt.prototype.inlined_pop_unsafe=dt.prototype.pop_unsafe;dt.prototype.inlined_erase=dt.prototype.erase;dt.prototype.inlined_remove=dt.prototype.remove;dt.prototype.inlined_try_remove=dt.prototype.try_remove;dt.prototype.inlined_clear=dt.prototype.clear;dt.prototype.inlined_has=dt.prototype.has;var Is=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,o=i.next;s.colour=0,e.colour=t.colour=1,e.next=l,l!=null&&(l.parent=e);let r=t.data;t.data=i.data,i.data=r,this.swapped!=null&&this.swapped(t.data,i.data),i.prev=o,o!=null&&(o.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,o=i.prev;s.colour=0,e.colour=t.colour=1,e.prev=l,l!=null&&(l.parent=e);let r=t.data;t.data=i.data,i.data=r,this.swapped!=null&&this.swapped(t.data,i.data),i.next=o,o!=null&&(o.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,o,r,a,p;t==n.prev?(l=n,p=n.next,e==t.prev?(s=e,i=t,o=e.prev,r=e.next,a=t.next):(s=t,i=e,o=t.prev,r=e.prev,a=e.next)):(s=n,o=n.prev,e==t.prev?(i=e,l=t,r=e.prev,a=e.next,p=t.next):(i=t,l=e,r=t.prev,a=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=o,o!=null&&(o.parent=s),s.next=r,r!=null&&(r.parent=s),i.prev=s,s!=null&&(s.parent=i),i.next=l,l!=null&&(l.parent=i),l.prev=a,a!=null&&(a.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}};Is.zpp_pool=null;var _i=null,pl=null,ms=null,jl=null,Bo=null,Tl=null,bs=null,$t=null,fs=null,Xn=null,zs=null,Ps=null,Ll=null,jo=null,To=null,Lo=null,Do=null,Fo=null,Ro=null,Go=null,qo=null;function Je(v){let e=class extends Vs{};return e.zpp_pool=null,e}function Ue(v,e){let t=class extends dt{};return t._NodeClass=e,t}function di(v){let e=class extends Is{};return e.zpp_pool=null,e}function Xl(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;To=v.util.ZNPList_ZPP_InteractionListener=Ue("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),Lo=v.util.ZNPList_ZPP_BodyListener=Ue("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),Do=v.util.ZNPList_ZPP_ConstraintListener=Ue("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),Fo=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),Go=v.util.ZNPList_ZPP_CbSet=Ue("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),jo=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),qo=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),_i=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),pl=v.util.ZNPList_ZPP_PartitionedPoly,v.util.ZNPList_ZPP_GeomVert=Ue("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),ms=v.util.ZNPList_ZPP_GeomVert,v.util.ZNPList_ZPP_SimpleVert=Ue("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),Ll=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),bs=v.util.ZNPNode_RayResult,Tl=v.util.ZNPList_ZPP_SimpleVert,v.util.ZPP_Set_ZPP_Body=di("ZPP_Body"),v.util.ZPP_Set_ZPP_CbSetPair=di("ZPP_CbSetPair"),v.util.ZPP_Set_ZPP_PartitionVertex=di("ZPP_PartitionVertex"),zs=v.util.ZPP_Set_ZPP_PartitionVertex,v.util.ZPP_Set_ZPP_PartitionPair=di("ZPP_PartitionPair"),Ps=v.util.ZPP_Set_ZPP_PartitionPair,v.util.ZPP_Set_ZPP_SimpleVert=di("ZPP_SimpleVert"),$t=v.util.ZPP_Set_ZPP_SimpleVert,v.util.ZPP_Set_ZPP_SimpleSeg=di("ZPP_SimpleSeg"),fs=v.util.ZPP_Set_ZPP_SimpleSeg,v.util.ZPP_Set_ZPP_SimpleEvent=di("ZPP_SimpleEvent"),Xn=v.util.ZPP_Set_ZPP_SimpleEvent,v.util.ZPP_Set_ZPP_CbSet=di("ZPP_CbSet")}var zt=class zt{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&&(zt.internal=!0,this.outer_body=zt._createBodyCb(),zt.internal=!1,this.outer_body.zpp_inner=this),this.outer_body}wrapper_con(){return this.outer_con==null&&(zt.internal=!0,this.outer_con=zt._createConCb(),zt.internal=!1,this.outer_con.zpp_inner=this),this.outer_con}wrapper_int(){let e=zt._zpp;return this.outer_int==null&&(zt.internal=!0,this.outer_int=zt._createIntCb(),zt.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=zt._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}};zt._nape=null,zt._zpp=null,zt.internal=!1,zt.zpp_pool=null,zt._createBodyCb=null,zt._createConCb=null,zt._createIntCb=null,zt._createPreCb=null;var Tt=zt;var Jt=class Jt{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=Jt._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;Jt.zpp_pool==null?t=new Jt:(t=Jt.zpp_pool,Jt.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 o=e.options2,r=n.cbTypes;s=o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)}else s=!1;if(s)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=Jt._zpp,s=null,l=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;l!=null;){let o=l.elt;if(o.a==e&&o.b==t||o.a==t&&o.b==e){s=o;break}l=l.next}if(s==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,Jt.setlt(e,t)?(o.a=e,o.b=t):(o.a=t,o.b=e),s=o,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 Jt.findOrCreatePair(e,t).listeners.head==null}static single_intersection(e,t,n){let i=Jt.findOrCreatePair(e,t).listeners.head;return i!=null&&i.elt==n?i.next==null:!1}static find_all(e,t,n,s){let l=Jt.findOrCreatePair(e,t).listeners.head;for(;l!=null;){let o=l.elt;o.event==n&&s(o),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=Jt._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 o=l.elt;if(i!=null&&i.elt==o)l=l.next,s=i,i=i.next;else{let r;if(i!=null){let a=i.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;s==null?(c.next=a.head,a.head=c):(c.next=s.next,s.next=c),a.pushmod=a.modified=!0,a.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=Jt._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 o=l.elt;if(i!=null&&i.elt==o)l=l.next,s=i,i=i.next;else{let r;if(i!=null){let a=i.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 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=Jt._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 o=l.elt;if(i!=null&&i.elt==o)l=l.next,s=i,i=i.next;else{let r;if(i!=null){let a=i.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 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(){}};Jt._zpp=null,Jt.zpp_pool=null;var _t=Jt;var Jn=class Jn{constructor(){this.a=null;this.b=null;this.next=null;this.zip_listeners=!1;this.listeners=null;let e=Jn._zpp;this.listeners=new e.util.ZNPList_ZPP_InteractionListener}static get(e,t){let n=Jn._zpp,s;return Jn.zpp_pool==null?s=new Jn:(s=Jn.zpp_pool,Jn.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=Jn._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 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,s=t.elt;if(n==s){let i,l,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;l=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else l=!1;if(l)i=!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,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}}};Jn._zpp=null,Jn.zpp_pool=null;var Ne=Jn;var an=class an{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=an._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){an.ANY_SHAPE=new e.callbacks.CbType,an.ANY_BODY=new e.callbacks.CbType,an.ANY_COMPOUND=new e.callbacks.CbType,an.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=an._zpp,n=null,s=this.listeners.head;for(;s!=null;){let r=s.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.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 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=an._zpp,n=null,s=this.bodylisteners.head;for(;s!=null;){let r=s.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.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 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=an._zpp,n=null,s=this.conlisteners.head;for(;s!=null;){let r=s.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.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 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}};an._zpp=null,an.ANY_SHAPE=null,an.ANY_BODY=null,an.ANY_COMPOUND=null,an.ANY_CONSTRAINT=null;var pn=an;var oi=class oi{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=yn.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()),oi.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()),oi.events=[t.CbEvent_BEGIN,t.CbEvent_END,t.CbEvent_WAKE,t.CbEvent_SLEEP,t.CbEvent_BREAK,t.CbEvent_PRE,t.CbEvent_ONGOING]}};oi._nape=null,oi._zpp=null,oi.internal=!1,oi.types=[],oi.events=[];var Lt=oi;var cl=class extends Lt{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=Lt._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 o=s.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;i==null?(a.next=o.head,o.head=a):(a.next=i.next,i.next=a),o.pushmod=o.modified=!0,o.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 hl=class extends Lt{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=Lt._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 o=s.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;i==null?(a.next=o.head,o.head=a):(a.next=i.next,i.next=a),o.pushmod=o.modified=!0,o.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 Ct=class Ct extends Lt{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=Lt._zpp,l=Ct.UCbSet,o=Ct.VCbSet,r=Ct.WCbSet,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,h=p.elt;if(c==h){let u=this._allocCbSetNode(i);u.elt=c,u.next=r.head,r.head=u,r.modified=!0,r.length++,a=a.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++,a=a.next}else{let u=this._allocCbSetNode(i);u.elt=h,u.next=o.head,o.head=u,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbSetNode(i);c.elt=a.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,a=a.next}for(;p!=null;){let c=this._allocCbSetNode(i);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.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(;o.head!=null;){let c=o.pop_unsafe(),h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe();s(c,c);let h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}}CbTypeset(t,n,s){let i=Lt._zpp,l=Ct.UCbType,o=Ct.VCbType,r=Ct.WCbType,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,h=p.elt;if(c==h){let u=this._allocCbTypeNode(i);u.elt=c,u.next=r.head,r.head=u,r.modified=!0,r.length++,a=a.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++,a=a.next}else{let u=this._allocCbTypeNode(i);u.elt=h,u.next=o.head,o.head=u,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbTypeNode(i);c.elt=a.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,a=a.next}for(;p!=null;){let c=this._allocCbTypeNode(i);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.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(;o.head!=null;){let c=o.pop_unsafe(),h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe();s(c,c);let h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}}with_uniquesets(t){let n=Lt._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,o)=>{this.CbSetset(l.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),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 o=l.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=l.parent;a!=null&&(l==a.prev?a.prev=null:a.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=a}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=Lt._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 o=s.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;i==null?(a.next=o.head,o.head=a):(a.next=i.next,i.next=a),o.pushmod=o.modified=!0,o.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){Ct.UCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.VCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.WCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.UCbType=new t.util.ZNPList_ZPP_CbType,Ct.VCbType=new t.util.ZNPList_ZPP_CbType,Ct.WCbType=new t.util.ZNPList_ZPP_CbType}};Ct.UCbSet=null,Ct.VCbSet=null,Ct.WCbSet=null,Ct.UCbType=null,Ct.VCbType=null,Ct.WCbType=null;var ul=Ct;var Hn=class Hn{constructor(){this.outer=null;this.handler=null;this.includes=null;this.excludes=null;this.wrap_includes=null;this.wrap_excludes=null;let e=Hn._zpp;this.includes=new e.util.ZNPList_ZPP_CbType,this.excludes=new e.util.ZNPList_ZPP_CbType}static argument(e){let t=Hn._nape;return e==null?new t.callbacks.OptionType:e instanceof t.callbacks.OptionType?e:new t.callbacks.OptionType().including(e)}setup_includes(){let e=Hn._zpp;this.wrap_includes=e.util.ZPP_CbTypeList.get(this.includes,!0)}setup_excludes(){let e=Hn._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,o=s.elt;if(l===o){n=!0;break}else l.id<o.id?i=i.next:s=s.next}return n}insertOrdered(e,t){let n=Hn._zpp,s=null,i=e.head;for(;i!=null;){let o=i.elt;if(t.id<o.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=Hn._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 o=l.zpp_inner.user_length;i.zpp_critical=!0;let r;if(i.zpp_i<o?r=!0:(i.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,r=!1),!r)break;i.zpp_critical=!1;let a=i.zpp_inner.at(i.zpp_i++);this.append_type(e,a.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 o=l;this.append_type(e,o.zpp_inner)}}else throw new Error("Error: Cannot append non-CbType or CbType list value")}};Hn._nape=null,Hn._zpp=null;var ws=Hn;var vn=class vn{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=vn._zpp;this.id=yn.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=vn._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=vn._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 r=s.elt;if(e.id<r.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 o=l;n==null?(o.next=i.head,i.head=o):(o.next=n.next,n.next=o),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=vn._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=vn._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=vn._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=vn._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 m=i.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 d=m.zpp_inner.user_length;i.zpp_critical=!0;let y;if(i.zpp_i<d?y=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,y=!1),!y)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 b=e.zpp_inner.wrap_cbTypes;b.zpp_inner.reverse_flag?b.push(f):b.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 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 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=vn._findRoot(e),s=vn._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}};vn._nape=null,vn._zpp=null;var Ze=vn;var Un=class v{constructor(){this.id=0;this.bc=null;this.cb=null}static dict(e,t){let n=new v;return n.id=e,n.bc=t,n}static todo(e,t){let n=new v;return n.id=e,n.cb=t,n}};var Bs=class Bs extends Ze{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=Bs._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 o=t[l];if(++l,o.id==this.b1.id){i=o.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(Un.todo(this.b1.id,o=>{s.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let o=t[l];if(++l,o.id==this.b2.id){i=o.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(Un.todo(this.b2.id,o=>{s.zpp_inner.b2=o.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 o=1/(1+this.gamma),r=t*l*l*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-i*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,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 o=this.b1,r=-this.scale*l*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,h=1-.5*c,u=1-c*c/8,x=(h*o.axisx+r*o.axisy)*u;o.axisy=(h*o.axisy-r*o.axisx)*u,o.axisx=x}let a=this.b2,p=this.ratio*this.scale*l*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,h=1-.5*c,u=1-c*c/8,x=(h*a.axisx+p*a.axisy)*u;a.axisy=(h*a.axisy-p*a.axisx)*u,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 s=n*n,i=1-.5*s,l=1-s*s/8,o=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=o}}static _copyBody(t,n,s,i,l){if(t!=null&&s!=null){let o=null;for(let r=0;r<t.length;r++){let a=t[r];if(a.id==s.id){o=a.bc;break}}o!=null?i.zpp_inner_zn[l]=o.zpp_inner:n.push(Un.todo(s.id,function(r){i.zpp_inner_zn[l]=r.zpp_inner}))}}};Bs._wrapFn=null,Bs._createFn=null;var qe=Bs;var Nt=class Nt{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 Nt.zpp_pool==null?s=new Nt:(s=Nt.zpp_pool,Nt.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(Nt._wrapFn)this.outer=Nt._wrapFn(this);else{this.outer=new Nt._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=Nt.zpp_pool,Nt.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 Nt.zpp_pool==null?n=new Nt:(n=Nt.zpp_pool,Nt.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+" }"}};Nt.zpp_pool=null,Nt._nape=null,Nt._zpp=null,Nt._wrapFn=null;var ae=Nt;var Li=class Li extends Ze{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<Ze._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=Ze._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=Li._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=Li._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 o=Li._createFn(null,null,i,l.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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._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<Ze._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 o=1/(1+this.gamma),r=t*l*l*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-i*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,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,o,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s),p=r*r+a*a;if(p<Ze._nape.Config.epsilon)r=0,a=0,p=0,o=!0;else{p=Math.sqrt(p);let h=1/p;r*=h,a*=h,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<Ze._nape.Config.constraintLinearSlop*Ze._nape.Config.constraintLinearSlop)return!1;if(c*=.5,c*c>6){let m=this.b1.smass+this.b2.smass;if(m>Ze._nape.Config.epsilon){let d=.75/m;if(t=-c*d,this.equal||t<0){let y=t*this.b1.imass;this.b1.posx-=r*y,this.b1.posy-=a*y;let f=t*this.b2.imass;this.b2.posx+=r*f,this.b2.posy+=a*f,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s);let b=r*r+a*a;if(b<Ze._nape.Config.epsilon)r=0,a=0,b=0;else{b=Math.sqrt(b);let P=1/b;r*=P,a*=P,this.equal?b-=this.jointMax:b<this.jointMin?(b=this.jointMin-b,r=-r,a=-a):b>this.jointMax?b-=this.jointMax:(r=0,a=0,b=0)}c=b,c*=.5}}}let h=a*n-r*s,u=a*i-r*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 m=this.b1.imass*t;this.b1.posx-=r*m,this.b1.posy-=a*m;let d=this.b2.imass*t;this.b2.posx+=r*d,this.b2.posy+=a*d,qe._rotateBody(this.b1,-h*this.b1.iinertia*t),qe._rotateBody(this.b2,u*this.b2.iinertia*t)}}return!1}draw(t){}static _setupAnchorVec2(t,n,s,i){let l=Ze._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(ye.poolVec2==null?a=new l.geom.Vec2:(a=ye.poolVec2,ye.poolVec2=a.zpp_pool,a.zpp_pool=null,a.zpp_disp=!1,a==ye.nextVec2&&(ye.nextVec2=null)),a.zpp_inner==null){let p;ae.zpp_pool==null?p=new ae:(p=ae.zpp_pool,ae.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 h=a.zpp_inner;if(h._validate!=null&&h._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 u=a.zpp_inner;u._validate!=null&&u._validate(),c=a.zpp_inner.y==r}else c=!1;if(!c){a.zpp_inner.x=o,a.zpp_inner.y=r;let u=a.zpp_inner;u._invalidate!=null&&u._invalidate(u)}}return a.zpp_inner.weak=!1,a.zpp_inner._inuse=!0,a.zpp_inner._validate=s,a.zpp_inner._invalidate=i,a}};Li._wrapFn=null,Li._createFn=null;var yi=Li;var js=class js extends Ze{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=Ze._nape,o=Ze._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 l.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 h=r.zpp_inner;h._validate!=null&&h._validate(),c=r.zpp_inner.y==n}else c=!1;if(!c){r.zpp_inner.x=t,r.zpp_inner.y=n;let h=r.zpp_inner;h._invalidate!=null&&h._invalidate(h)}}return r.zpp_inner.weak=!1,r.zpp_inner._inuse=!0,r.zpp_inner._validate=s,r.zpp_inner._invalidate=i,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,s=1/Math.sqrt(t);this.nlocalx*=s,this.nlocaly*=s}}bodyImpulse(t){let n=Ze._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 o=l.zpp_inner_zn.wrap_a2,r=this.outer_zn;r.zpp_inner_zn.wrap_n==null&&r.zpp_inner_zn.setup_n();let a=js._createFn(null,null,i,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=Ze._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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._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,o=this.nrelx*s+this.nrely*i;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=s+this.a1relx,a=i+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 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+o*o>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),m=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=o;let y=-m;this.biasx*=y,this.biasy*=y;let f=this.maxError,b=this.biasx*this.biasx+this.biasy*this.biasy;if(b>f*f){let P=f*(1/Math.sqrt(b));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,o=this.biasy-i,r=this.kMassa*l+this.kMassb*o;o=this.kMassb*l+this.kMassc*o,l=r;let a=this.gamma;l-=this.jAccx*a,o-=this.jAccy*a;let p=this.jAccx,c=this.jAccy;if(this.jAccx+=l,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,b=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(b>f*f){let P=f*(1/Math.sqrt(b));this.jAccx*=P,this.jAccy*=P}}let h=this.jAccx-p,u=this.jAccy-c,x=this.scale*this.nrelx*u-this.nrely*h,m=this.nrelx*h+this.scale*this.nrely*u,d=this.b1.imass;this.b1.velx-=x*d,this.b1.vely-=m*d;let y=this.b2.imass;return this.b2.velx+=x*y,this.b2.vely+=m*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=Ze._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,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-i,p=this.b2.posy+r-this.b1.posy-l,c,h=p*n-a*s,u=n*a+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,m,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 A=.8/Z,S=A*(s*h-c*n*u),L=A*(n*h*c-s*h),T=this.b1.imass;this.b1.posx-=S*T,this.b1.posy-=L*T;let G=this.b2.imass;this.b2.posx+=S*G,this.b2.posy+=L*G,a=this.b2.posx+o-this.b1.posx-i,p=this.b2.posy+r-this.b1.posy-l,h=p*n-a*s,u=n*a+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 y=a+i,f=p+l,b=n*y+s*f,P=f*n-y*s,k=n*o+s*r,_=r*n-o*s,z=this.b1.smass+this.b2.smass+b*b*this.b1.sinertia+k*k*this.b2.sinertia,C=-c*(b*P*this.b1.sinertia+k*_*this.b2.sinertia),w=c*c*(this.b1.smass+this.b2.smass+P*P*this.b1.sinertia+_*_*this.b2.sinertia);x=-h,m=-u;let g=z*w-C*C;if(g!==g)m=0,x=m;else if(g==0)z!=0?x/=z:x=0,w!=0?m/=w:m=0;else{let Z=1/g,A=Z*(w*x-C*m);m=Z*(z*m-C*x),x=A}m>0&&(m=0);let O=c*n*m-s*x,E=n*x+c*s*m,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,qe._rotateBody(this.b1,(c*P*m-b*x)*this.b1.iinertia),qe._rotateBody(this.b2,(k*x-c*_*m)*this.b2.iinertia),!1}draw(t){}};js._wrapFn=null,js._createFn=null;var mi=js;var Ts=class Ts extends Ze{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=Ts._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 o=t[l];if(++l,o.id==this.b1.id){i=o.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(Un.todo(this.b1.id,o=>{s.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let o=t[l];if(++l,o.id==this.b2.id){i=o.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(Un.todo(this.b2.id,o=>{s.zpp_inner.b2=o.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}};Ts._wrapFn=null,Ts._createFn=null;var bi=Ts;var Ls=class Ls extends Ze{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=Ze._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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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 o=Ls._createFn(null,null,i,l.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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._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 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 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 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,l=r}else{let r=1/i,a=this.kMassc*r;this.kMassc=this.kMassa*r,this.kMassa=a,this.kMassb*=-r,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 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 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 m=u*(1/Math.sqrt(x));this.biasx*=m,this.biasy*=m}}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)),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 o=this.gamma;s-=this.jAccx*o,i-=this.jAccy*o;let r=this.jAccx,a=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 m=u*(1/Math.sqrt(x));this.jAccx*=m,this.jAccy*=m}}s=this.jAccx-r,i=this.jAccy-a;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=Ze._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,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s);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 z=this.b1.smass+this.b2.smass;if(z>t.Config.epsilon){let C=.75/z;p=-o*C,c=-r*C;let w=20,g=p*p+c*c;if(g>w*w){let N=w*(1/Math.sqrt(g));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,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s);let M=.5;o*=M,r*=M}}let h=this.b1.smass+this.b2.smass,u=h,x=0,m=h;if(this.b1.sinertia!=0){let z=n*this.b1.sinertia,C=s*this.b1.sinertia;u+=C*s,x+=-C*n,m+=z*n}if(this.b2.sinertia!=0){let z=i*this.b2.sinertia,C=l*this.b2.sinertia;u+=C*l,x+=-C*i,m+=z*i}p=-o,c=-r;let d=6,y=p*p+c*c;if(y>d*d){let z=d*(1/Math.sqrt(y));p*=z,c*=z}let f=u*m-x*x;if(f!=f)c=0,p=0;else if(f==0)u!=0?p/=u:p=0,m!=0?c/=m:c=0;else{let z=1/f,C=z*(m*p-x*c);c=z*(u*c-x*p),p=C}let b=this.b1.imass;this.b1.posx-=p*b,this.b1.posy-=c*b;let P=this.b2.imass;this.b2.posx+=p*P,this.b2.posy+=c*P;let k=-(c*n-p*s)*this.b1.iinertia;qe._rotateBody(this.b1,k);let _=(c*i-p*l)*this.b2.iinertia;return qe._rotateBody(this.b2,_),!1}draw(t){}};Ls._wrapFn=null,Ls._createFn=null;var fi=Ls;var Ds=class Ds extends Ze{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),o=Math.sqrt(n*n+s*s),r=Math.sqrt(i*i+l*l),a=o+this.ratio*r;return this.equal||a<this.jointMin||a>this.jointMax?t=!1:t=!0,t}bodyImpulse(t){let n=Ze._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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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 o=l.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=Ds._createFn(null,null,null,null,i,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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component),this.b3.type==2&&Ze._unionComponents(this.b3.component,this.component),this.b4.type==2&&Ze._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),o=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),r=Math.sqrt(s*s+i*i),a=Math.sqrt(l*l+o*o);if(r!=0){let h=1/r;this.n12x=s*h,this.n12y=i*h}if(a!=0){let h=1/a;this.n34x=l*h,this.n34y=o*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=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 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 m=1/(1+this.gamma),d=t*x*x*this.gamma;this.gamma*=m,this.kMass*=m,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 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=Ze._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,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,h,u=this.n12x,x=this.n12y,m=this.n34x,d=this.n34y,y=this.b2.posx+l-(this.b1.posx+s),f=this.b2.posy+o-(this.b1.posy+i),b=this.b4.posx+p-(this.b3.posx+r),P=this.b4.posy+c-(this.b3.posy+a),k=Math.sqrt(y*y+f*f),_=Math.sqrt(b*b+P*P);if(k!=0){let w=1/k;u=y*w,x=f*w}if(_!=0){let w=1/_;m=b*w,d=P*w;let g=this.ratio;m*=g,d*=g}else{let w=this.ratio/Math.sqrt(m*m+d*d);m*=w,d*=w}let z=k+this.ratio*_;this.equal?(z-=this.jointMax,h=!1):z<this.jointMin?(z=this.jointMin-z,u=-u,x=-x,m=-m,d=-d,h=!1):z>this.jointMax?(z-=this.jointMax,h=!1):(u=0,x=0,m=0,d=0,z=0,h=!0);let C=z;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 A=this.b1.smass+this.b2.smass;if(A>t.Config.epsilon){let S=.75/A;if(n=-C*S,this.equal||n<0){let L=n*this.b1.imass;this.b1.posx-=u*L,this.b1.posy-=x*L;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-=m*G,this.b3.posy-=d*G;let q=n*this.b4.imass;this.b4.posx+=m*q,this.b4.posy+=d*q;let R=this.b2.posx+l-(this.b1.posx+s),j=this.b2.posy+o-(this.b1.posy+i),V=this.b4.posx+p-(this.b3.posx+r),K=this.b4.posy+c-(this.b3.posy+a),$=Math.sqrt(R*R+j*j),Y=Math.sqrt(V*V+K*K);if($!=0){let ee=1/$;u=R*ee,x=j*ee}if(Y!=0){let ee=1/Y;m=V*ee,d=K*ee;let J=this.ratio;m*=J,d*=J}else{let ee=this.ratio/Math.sqrt(m*m+d*d);m*=ee,d*=ee}let X=$+this.ratio*Y;this.equal?X-=this.jointMax:X<this.jointMin?(X=this.jointMin-X,u=-u,x=-x,m=-m,d=-d):X>this.jointMax?X-=this.jointMax:(u=0,x=0,m=0,d=0,X=0),C=X,C*=.5}}}let w=x*s-u*i,g=x*l-u*o,O=d*r-m*a,E=d*p-m*c,M=this.ratio*this.ratio,N=this.b1.smass+this.b2.smass+M*(this.b3.smass+this.b4.smass)+this.b1.sinertia*w*w+this.b2.sinertia*g*g+this.b3.sinertia*O*O+this.b4.sinertia*E*E;this.b1==this.b4&&(N-=2*((u*m+x*d)*this.b1.smass+w*E*this.b1.sinertia)),this.b1==this.b3&&(N+=2*((u*m+x*d)*this.b1.smass+w*O*this.b1.sinertia)),this.b2==this.b3&&(N-=2*((u*m+x*d)*this.b2.smass+g*O*this.b2.sinertia)),this.b2==this.b4&&(N+=2*((u*m+x*d)*this.b2.smass+g*E*this.b2.sinertia));let Z=N;if(Z!=0&&(Z=1/Z),n=-C*Z,this.equal||n<0){let A=this.b1.imass*n;this.b1.posx-=u*A,this.b1.posy-=x*A;let S=this.b2.imass*n;this.b2.posx+=u*S,this.b2.posy+=x*S;let L=this.b3.imass*n;this.b3.posx-=m*L,this.b3.posy-=d*L;let T=this.b4.imass*n;this.b4.posx+=m*T,this.b4.posy+=d*T,qe._rotateBody(this.b1,-w*this.b1.iinertia*n),qe._rotateBody(this.b2,g*this.b2.iinertia*n),qe._rotateBody(this.b3,-O*this.b3.iinertia*n),qe._rotateBody(this.b4,E*this.b4.iinertia*n)}}return!1}draw(t){}};Ds._wrapFn=null,Ds._createFn=null;var zi=Ds;var vs=class{constructor(e,t){this.cnt=0;this.body=null;this.cnt=e,this.body=t}};var xl=class extends Ze{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=Ze._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 vs(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=Ze._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 o=i.parent;i.parent=l,l=i,i=o}for(;l!=null;){let o=l.parent;l.parent=i,l=o}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 o=i.parent;i.parent=l,l=i,i=o}for(;l!=null;){let o=l.parent;l.parent=i,l=o}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 o=this.bodies[l].body;for(let r=l+1;r<i;r++){let a=this.bodies[r].body;if(o.id===t&&a.id===n||o.id===n&&a.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 o=0;o<s-1;o++)i+=this.L[s*this.dim+o]*this.L[s*this.dim+o];let l=Math.sqrt(t[n++]-i);if(this.L[s*this.dim+s]=l,l!==0){l=1/l;for(let o=s+1;o<this.dim;o++){let r=0;for(let a=0;a<s-1;a++)r+=this.L[o*this.dim+a]*this.L[s*this.dim+a];this.L[o*this.dim+s]=l*(t[n++]-r)}}else{for(let o=s+1;o<this.dim;o++)this.L[o*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 o=0;o<s;o++)i-=t[s*this.dim+o]*this.y[o];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 o=this.y[i];for(let r=i+1;r<this.dim;r++)o-=t[r*this.dim+i]*n[r];n[i]=o/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 o=0;o<this.dim;o++)this.bias[o]*=-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,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(),i.velx=l+o.zpp_inner.x*s;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 h=c.zpp_inner;h._validate!=null&&h._validate(),a.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let d=m.zpp_inner;d._validate!=null&&d._validate(),u.angvel=x+m.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,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(),i.velx=l+o.zpp_inner.x*s;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 h=c.zpp_inner;h._validate!=null&&h._validate(),a.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let d=m.zpp_inner;d._validate!=null&&d._validate(),u.angvel=x+m.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<Ze._nape.Config.constraintLinearSlop*Ze._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,o=l.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(),l.posx=o+r.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 m=x.zpp_inner;m._validate!=null&&m._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 y=d*d,f=1-.5*y,b=1-y*y/8,P=(f*s.axisx+d*s.axisy)*b;s.axisy=(f*s.axisy-d*s.axisx)*b,s.axisx=P}}return!1}draw(t){this.outer_zn.__draw(t)}};var Fs=class Fs extends Ze{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=Ze._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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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=Ze._nape,n=Ze._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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 o=Fs._createFn(null,null,i,l.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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._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 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 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 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,l=o}else{let o=1/i,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),h=o*(this.kMassb*this.kMassc-this.kMassa*this.kMasse),u=o*(this.kMassa*this.kMassd-this.kMassb*this.kMassb);this.kMassa=r,this.kMassb=a,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 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 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,o=this.biasz-s,r=this.kMassa*i+this.kMassb*l+this.kMassc*o,a=this.kMassb*i+this.kMassd*l+this.kMasse*o;o=this.kMassc*i+this.kMasse*l+this.kMassf*o,i=r,l=a,i-=this.jAccx*this.gamma,l-=this.jAccy*this.gamma,o-=this.jAccz*this.gamma;let p=this.jAccx,c=this.jAccy,h=this.jAccz;if(this.jAccx+=i,this.jAccy+=l,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 m=this.jMax,d=this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz;if(d>m*m){let y=m*(1/Math.sqrt(d));this.jAccx*=y,this.jAccy*=y,this.jAccz*=y}}i=this.jAccx-p,l=this.jAccy-c,o=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+o)*this.b1.iinertia,this.b2.angvel+=(l*this.a2relx-i*this.a2rely+o)*this.b2.iinertia,!1}applyImpulsePos(){let t=Ze._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,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,p,c,h;if(this.breakUnderError&&o*o+r*r+a*a>this.maxError*this.maxError)return!0;let u=!0;o*o+r*r<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(u=!1,o=0,r=0);let x=t.Config.constraintAngularSlop;if(a*a<x*x)if(u)a=0;else return!1;if(o*=.5,r*=.5,a*=.5,o*o+r*r>6){let S=this.b1.smass+this.b2.smass;if(S>t.Config.epsilon){let L=.75/S;p=-o*L,c=-r*L;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,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,o*=.5,r*=.5,a*=.5}}let m=this.b1.smass+this.b2.smass,d=m,y=0,f=m,b=0,P=0,k=0;if(this.b1.sinertia!=0){let S=n*this.b1.sinertia,L=s*this.b1.sinertia;d+=L*s,y+=-L*n,f+=S*n,b+=-L,P+=S,k+=this.b1.sinertia}if(this.b2.sinertia!=0){let S=i*this.b2.sinertia,L=l*this.b2.sinertia;d+=L*l,y+=-L*i,f+=S*i,b+=-L,P+=S,k+=this.b2.sinertia}p=-o,c=-r,h=-a;let _=6,z=p*p+c*c;if(z>_*_){let S=_*(1/Math.sqrt(z));p*=S,c*=S}let w=h<-.25,g=d*(f*k-P*P)+y*(b*P-y*k)+b*(y*P-b*f);if(g!=g)h=0,c=h,p=c;else if(g==0)d!=0?p/=d:p=0,f!=0?c/=f:c=0,k!=0?h/=k:h=0;else{let S=1/g,L=P*b-y*k,T=y*P-b*f,G=y*b-d*P,q=S*(p*(f*k-P*P)+c*L+h*T),R=S*(p*L+c*(d*k-b*b)+h*G);h=S*(p*T+c*G+h*(d*f-y*y)),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;qe._rotateBody(M,N);let Z=this.b2,A=(c*i-p*l+h)*this.b2.iinertia;return qe._rotateBody(Z,A),!1}draw(t){}};Fs._wrapFn=null,Fs._createFn=null;var Pi=Fs;var nt=class nt{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()),nt.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID]}wrapper(){if(this.outer==null){let e=nt._nape;nt.internal=!0,this.type==nt.COL?(this.colarb.outer_zn=nt._createColArb(),this.outer=this.colarb.outer_zn):this.type==nt.FLUID?(this.fluidarb.outer_zn=nt._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,nt.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=nt._zpp;this.cleared=!0,(t==null||this.b2==t)&&nt._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&nt._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=nt._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=s,nt._addToArbiterList(this.b1.arbiters,this,i),nt._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=nt._zpp;this.cleared||(nt._removeFromArbiterList(this.b1.arbiters,this,e),nt._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,o;s==null?(l=e.head,o=l.next,e.head=o,e.head==null&&(e.pushmod=!0)):(l=s.next,o=l.next,s.next=o,o==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}}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++}};nt._nape=null,nt._zpp=null,nt.internal=!1,nt._createColArb=null,nt._createFluidArb=null,nt.COL=1,nt.FLUID=4,nt.SENSOR=2,nt.types=[];var Ie=nt;var Rs=class Rs extends Ie{constructor(){super(),this.next=null,this.type=Ie.SENSOR,this.sensorarb=this}alloc(){}free(){}assign(e,t,n,s){this.sup_assign(e,t,n,s)}retire(){this.sup_retire(),this.next=Rs.zpp_pool,Rs.zpp_pool=this}makemutable(){}makeimmutable(){}};Rs.zpp_pool=null;var Ot=Rs;var Gs=class Gs extends Ie{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=Ie.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=Ie._zpp,n=Ie._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 o=s.zpp_inner;if(o._validate!=null&&o._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 r=s.zpp_inner;r._validate!=null&&r._validate(),l=s.zpp_inner.y==0}else l=!1;if(!l){s.zpp_inner.x=0,s.zpp_inner.y=0;let r=s.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}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=Gs.zpp_pool,Gs.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=Ie._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,o;this.ws1.fluidEnabled&&this.ws1.fluidProperties.wrap_gravity!=null?(l=this.ws1.fluidProperties.gravityx,o=this.ws1.fluidProperties.gravityy):(l=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 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-=o*x}else if(h<u){let x=h+u;p+=r*x,c+=a*x}else{let x=l+r,m=o+a,d=.5;if(x*=d,m*=d,this.ws1.worldCOMx*x+this.ws1.worldCOMy*m>this.ws2.worldCOMx*x+this.ws2.worldCOMy*m){let y=h+u;p-=x*y,c-=m*y}else{let y=h+u;p+=x*y,c+=m*y}}}else if(this.ws1.fluidEnabled){let h=this.overlap*this.ws1.fluidProperties.density;p-=l*h,c-=o*h}else if(this.ws2.fluidEnabled){let h=this.overlap*this.ws2.fluidProperties.density;p+=r*h,c+=a*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 y=2*Math.PI*h;this.agamma=1/(n*y*(2+y*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,y=1/Math.sqrt(d);this.nx=u*y,this.ny=x*y}let m=0;if(this.ws1.fluidEnabled){let d=-this.ws1.fluidProperties.viscosity*this.overlap/this.ws2.area;if(this.ws2.type==0)m-=d*this.ws2.circle.radius*s.Config.fluidLinearDrag/(2*this.ws2.circle.radius*Math.PI);else{let y=this.ws2.polygon,f=0,b=0,P=y.edges.head;for(;P!=null;){let k=P.elt;f+=k.length;let _=d*k.length*(k.gnormx*this.nx+k.gnormy*this.ny);_>0&&(_*=-s.Config.fluidVacuumDrag),b-=_*.5*s.Config.fluidLinearDrag,P=P.next}m+=b/f}}if(this.ws2.fluidEnabled){let d=-this.ws2.fluidProperties.viscosity*this.overlap/this.ws1.area;if(this.ws1.type==0)m-=d*this.ws1.circle.radius*s.Config.fluidLinearDrag/(2*this.ws1.circle.radius*Math.PI);else{let y=this.ws1.polygon,f=0,b=0,P=y.edges.head;for(;P!=null;){let k=P.elt;f+=k.length;let _=d*k.length*(k.gnormx*this.nx+k.gnormy*this.ny);_>0&&(_*=-s.Config.fluidVacuumDrag),b-=_*.5*s.Config.fluidLinearDrag,P=P.next}m+=b/f}}if(m!=0){let d=this.b1.smass+this.b2.smass,y=d,f=0,b=d;if(this.b1.sinertia!=0){let z=this.r1x*this.b1.sinertia,C=this.r1y*this.b1.sinertia;y+=C*this.r1y,f+=-C*this.r1x,b+=z*this.r1x}if(this.b2.sinertia!=0){let z=this.r2x*this.b2.sinertia,C=this.r2y*this.b2.sinertia;y+=C*this.r2y,f+=-C*this.r2x,b+=z*this.r2x}let P=y*b-f*f;if(P!==P)b=0,f=b,y=f;else if(P==0)y!=0?y=1/y:y=0,b!=0?b=1/b:b=0,f=0;else{let z=1/P,C=b*z;b=y*z,y=C,f*=-z}this.vMassa=y,this.vMassb=f,this.vMassc=b;let k=2*Math.PI*m;this.lgamma=1/(n*k*(2+k*n));let _=1/(1+this.lgamma);this.lgamma*=_,this.vMassa*=_,this.vMassb*=_,this.vMassc*=_}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 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}}};Gs.zpp_pool=null;var Pt=Gs;var wi=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 mn=class mn{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 wi}wrapper(){return this.outer==null&&(mn._wrapFn?this.outer=mn._wrapFn(this):(mn.internal=!0,this.outer=new mn._nape.dynamics.Contact,mn.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=mn._zpp,t=mn._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 o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){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 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}};mn._nape=null,mn._zpp=null,mn.zpp_pool=null,mn.internal=!1,mn._wrapFn=null;var Pe=mn;var wt=class wt extends Ie{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=0;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 wi,this.type=Ie.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=Ie._zpp,n=Ie._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 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=s,o.y=i,l.zpp_inner=o,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 o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!==s||i!==i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._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(),r=l.zpp_inner.y==i}else r=!1;if(!r){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,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){Pe.zpp_pool==null?a=new Pe:(a=Pe.zpp_pool,Pe.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=s,this.ny=i,a.dist=l,a.stamp=this.stamp,a.posOnly=r,a}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=wt.zpp_pool,wt.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=Ie._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=Ie._nape,n=!0,s=null,i=null,l=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=wt._eraseFromList(this.contacts,s),l=wt._eraseFromList(this.innards,i),r.arbiter=null,r.next=Pe.zpp_pool,Pe.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),s=o,i=l,l=l.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=Ie._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,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,h=this.contacts.next;for(;h!=null;){let u=h;if(u.stamp+n.Config.arbiterExpirationDelay<this.stamp){h=wt._eraseFromList(this.contacts,a),c=wt._eraseFromList(this.innards,p),u.arbiter=null,u.next=Pe.zpp_pool,Pe.zpp_pool=u;continue}let x=u.inner,m=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,y=i+this.b2.sinertia*(d*d);d=x.r1x*this.nx+x.r1y*this.ny,y+=this.b1.sinertia*(d*d),x.tMass=y<n.Config.epsilon*n.Config.epsilon?0:1/y,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 b=this.b2.angvel+this.b2.kinangvel,P=this.b2.velx+this.b2.kinvelx-x.r2y*b,k=this.b2.vely+this.b2.kinvely+x.r2x*b;b=this.b1.angvel+this.b1.kinangvel,P-=this.b1.velx+this.b1.kinvelx-x.r1y*b,k-=this.b1.vely+this.b1.kinvely+x.r1x*b;let _=this.nx*P+this.ny*k;u.elasticity=this.restitution,x.bounce=_*u.elasticity,x.bounce>-n.Config.elasticThreshold&&(x.bounce=0);let z=k*this.nx-P*this.ny,C=n.Config.staticFrictionThreshold;z*z>C*C?x.friction=this.dyn_fric:x.friction=this.stat_fric,x.jnAcc*=s,x.jtAcc*=s}m!=u.active&&(this.contacts.modified=!0),a=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 m=1/x,d=this.kMassc*m;this.kMassc=this.kMassa*m,this.kMassa=d,this.kMassb*=-m}}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,o=l-s;o>i?o=i:o<-i&&(o=-i),s=o-l,this.c1.jtAcc=o;let r=-this.ny*s,a=this.nx*s;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*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,o=l-s,o>i?o=i:o<-i&&(o=-i),s=o-l,this.c2.jtAcc=o,r=-this.ny*s,a=this.nx*s,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*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),m=p*this.nx+c*this.ny+this.surfacey+this.c2.bounce-(this.Kb*h+this.Kc*u),d=-(this.kMassa*x+this.kMassb*m),y=-(this.kMassb*x+this.kMassc*m);d>=0&&y>=0?(x=d-h,m=y-u,this.c1.jnAcc=d,this.c2.jnAcc=y):(d=-this.c1.nMass*x,d>=0&&this.Kb*d+m>=0?(x=d-h,m=-u,this.c1.jnAcc=d,this.c2.jnAcc=0):(y=-this.c2.nMass*m,y>=0&&this.Kb*y+x>=0?(x=-h,m=y-u,this.c1.jnAcc=0,this.c2.jnAcc=y):x>=0&&m>=0?(x=-h,m=-u,this.c1.jnAcc=this.c2.jnAcc=0):(x=0,m=0))),s=x+m,r=this.nx*s,a=this.ny*s,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*m)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*x+this.rn2a*m)*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,o=l-s,o<0&&(o=0),s=o-l,this.c1.jnAcc=o,r=this.nx*s,a=this.ny*s,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*s*this.b2.iinertia,this.b1.angvel-=this.rn1a*s*this.b1.iinertia}applyImpulsePos(){let t=Ie._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,o=n.lr1x*this.b1.axisx+n.lr1y*this.b1.axisy;l+=this.b1.posx,o+=this.b1.posy;let r=s-l,a=i-o,p=Math.sqrt(r*r+a*a),c=this.radius-t.Config.collisionSlop,h=p-c;if(r*this.nx+a*this.ny<0&&(r=-r,a=-a,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;r*=u,a*=u;let x=.5*(l+s),m=.5*(o+i),d=p-c;l=x-this.b1.posx,o=m-this.b1.posy,s=x-this.b2.posx,i=m-this.b2.posy;let y=a*l-r*o,f=a*s-r*i,b=this.b2.smass+f*f*this.b2.sinertia+this.b1.smass+y*y*this.b1.sinertia;if(b!=0){let P=-this.biasCoef*d/b,k=r*P,_=a*P;this.b1.posx-=k*this.b1.imass,this.b1.posy-=_*this.b1.imass,wt._rotateBody(this.b1,-y*this.b1.iinertia*P),this.b2.posx+=k*this.b2.imass,this.b2.posy+=_*this.b2.imass,wt._rotateBody(this.b2,f*this.b2.iinertia*P)}}}_applyImpulsePosEdge(t){let n,s,i,l,o,r=0,a=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,o=this.c1.lr1x*this.b2.axisx+this.c1.lr1y*this.b2.axisy,l+=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,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,o=this.c1.lr1x*this.b1.axisx+this.c1.lr1y*this.b1.axisy,l+=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=l*n+o*s-i-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=r*n+a*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=o-this.b1.posy,x=l-this.b2.posx,m=o-this.b2.posy;if(this.hpc2){let d=r-this.b1.posx,y=a-this.b1.posy,f=r-this.b2.posx,b=a-this.b2.posy,P=s*h-n*u,k=s*x-n*m,_=s*d-n*y,z=s*f-n*b,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*_+this.b2.sinertia*k*z,this.kMassc=C+this.b1.sinertia*_*_+this.b2.sinertia*z*z;let w=this.kMassa,g=this.kMassb,O=this.kMassc,E=p*this.biasCoef,M=c*this.biasCoef;for(;;){let N=-E,Z=-M,A=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(A!==A)N=0,Z=0;else if(A==0)this.kMassa!=0?N/=this.kMassa:N=0,this.kMassc!=0?Z/=this.kMassc:Z=0;else{let S=1/A,L=S*(this.kMassc*N-this.kMassb*Z);Z=S*(this.kMassa*Z-this.kMassb*N),N=L}if(N>=0&&Z>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,N,Z,P,_,k,z);break}if(N=-E/w,Z=0,N>=0&&g*N+M>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,N,Z,P,_,k,z);break}if(N=0,Z=-M/O,Z>=0&&g*Z+E>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,N,Z,P,_,k,z);break}break}}else{let d=s*h-n*u,y=s*x-n*m,f=this.b2.smass+y*y*this.b2.sinertia+this.b1.smass+d*d*this.b1.sinertia;if(f!=0){let b=-this.biasCoef*p/f,P=n*b,k=s*b;this.b1.posx-=P*this.b1.imass,this.b1.posy-=k*this.b1.imass,wt._rotateBody(this.b1,-d*this.b1.iinertia*b),this.b2.posx+=P*this.b2.imass,this.b2.posy+=k*this.b2.imass,wt._rotateBody(this.b2,y*this.b2.iinertia*b)}}}}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,o=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=o}}static _applyPosImpulse2(t,n,s,i,l,o,r,a,p,c){let h=(l+o)*t.imass;t.posx-=s*h,t.posy-=i*h,wt._rotateBody(t,-t.iinertia*(r*l+a*o));let u=(l+o)*n.imass;n.posx+=s*u,n.posy+=i*u,wt._rotateBody(n,n.iinertia*(p*l+c*o))}};wt.FACE1=0,wt.FACE2=1,wt.CIRCLE=2,wt.zpp_pool=null;var ut=wt;var Ut=class Ut{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 Ut._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Ut._wrapFn)this.outer=Ut._wrapFn(this);else{this.outer=new Ut._nape.dynamics.InteractionFilter;let e=this.outer.zpp_inner;e.outer=null,e.next=Ut.zpp_pool,Ut.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Ut._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Ut.zpp_pool==null?e=new Ut:(e=Ut.zpp_pool,Ut.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}};Ut.zpp_pool=null,Ut._nape=null,Ut._zpp=null,Ut._wrapFn=null;var it=Ut;var Di=class Di{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=Di._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)}};Di.SHAPE=1,Di.BODY=2,Di._zpp=null,Di._wrapFn=null;var qs=Di;var Qn=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,o=this.space.f_arbiters.head;for(;o!=null;)o.elt.active&&++l,o=o.next;this.lengths[e++]=l,this._length+=l;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 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}};Qn._nape=null,Qn._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,s){let i;return Mt.zpp_pool==null?i=new Mt:(i=Mt.zpp_pool,Mt.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(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,s=Mt._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=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._nape=null,Mt._zpp=null,Mt._wrapFn=null;var be=Mt;var fe=class fe{static get debugCapsule(){return globalThis.__napeDebugCapsule===!0}static _initStatics(e){fe.flowpoly=new e.util.ZNPList_ZPP_Vec2,fe.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?fe.circleContains(e.circle,t):e.type==1?fe.polyContains(e.polygon,t):fe.capsuleContains(e.capsule,t)}static bodyContains(e,t){let n;n=!1;let s=e.shapes.head;for(;s!=null;){let i=s.elt;if(fe.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,o=t.circle.worldCOMy-e.circle.worldCOMy;return l*l+o*o<=i*i}else if(t.type==1){let i;i=!0;let l=t.polygon.gverts.next;for(;l!=null;){let o=l,r=e.circle.radius,a=o.x-e.circle.worldCOMx,p=o.y-e.circle.worldCOMy;if(a*a+p*p<=r*r){l=l.next;continue}else{i=!1;break}}return i}else{let i=t.capsule,l=e.circle.radius-i.radius;if(l<0)return!1;let o=l*l,r=i.spine1x-e.circle.worldCOMx,a=i.spine1y-e.circle.worldCOMy;if(r*r+a*a>o)return!1;let p=i.spine2x-e.circle.worldCOMx,c=i.spine2y-e.circle.worldCOMy;return p*p+c*c<=o}else if(e.type==2)if(t.type==0){let i=e.capsule,l=fe._closestT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,t.circle.worldCOMx,t.circle.worldCOMy),o=i.spine1x+l*(i.spine2x-i.spine1x),r=i.spine1y+l*(i.spine2y-i.spine1y),a=i.radius-t.circle.radius;if(a<0)return!1;let p=t.circle.worldCOMx-o,c=t.circle.worldCOMy-r;return p*p+c*c<=a*a}else return!1;else if(t.type==0){let i;i=!0;let l=e.polygon.edges.head;for(;l!=null;){let o=l.elt;if(o.gnormx*t.circle.worldCOMx+o.gnormy*t.circle.worldCOMy+t.circle.radius<=o.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 o=l.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){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==2)return fe._capsuleContactCollide(e,t,n,s,i);if(e.type==2)return fe._capsuleContactCollide(t,e,n,!s,i);if(t.type==1)if(e.type==1){let l=!0,o=-1e100,r=-1e100,a=-1,p=null,c=null,h=e.polygon.edges.head;for(;h!=null;){let u=h.elt,x=1e100,m=t.polygon.gverts.next;for(;m!=null;){let d=m,y=u.gnormx*d.x+u.gnormy*d.y;if(y<x&&(x=y),x-u.gprojection<=o)break;m=m.next}if(x-=u.gprojection,x>=0){l=!1;break}x>o&&(o=x,p=u,a=1),h=h.next}if(l){let u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,m=1e100,d=e.polygon.gverts.next;for(;d!=null;){let y=d,f=x.gnormx*y.x+x.gnormy*y.y;if(f<m&&(m=f),m-x.gprojection<=o)break;d=d.next}if(m-=x.gprojection,m>=0){l=!1;break}m>o&&(o=m,c=x,a=2),u=u.next}if(l){let x,m,d,y;a==1?(x=e.polygon,m=t.polygon,d=p,y=1):(x=t.polygon,m=e.polygon,d=c,y=-1);let f=null,b=1e100,P=m.edges.head;for(;P!=null;){let q=P.elt,R=d.gnormx*q.gnormx+d.gnormy*q.gnormy;R<b&&(b=R,f=q),P=P.next}let k=f.gp0.x,_=f.gp0.y,z=f.gp1.x,C=f.gp1.y,w=z-k,g=C-_,O=d.gnormy*k-d.gnormx*_,E=d.gnormy*z-d.gnormx*C,M=1/(E-O),N=(-d.tp1-O)*M;if(N>i.Config.epsilon){let q=N;k+=w*q,_+=g*q}let Z=(-d.tp0-E)*M;if(Z<-i.Config.epsilon){let q=Z;z+=w*q,C+=g*q}let A=y,S=d.gnormx*A,L=d.gnormy*A;n.lnormx=d.lnormx,n.lnormy=d.lnormy,n.lproj=d.lprojection,n.radius=0,n.rev=s!=(y==-1),n.ptype=n.rev?1:0;let T=k*d.gnormx+_*d.gnormy-d.gprojection,G=z*d.gnormx+C*d.gnormy-d.gprojection;if(T>0&&G>0)return!1;{s&&(S=-S,L=-L);let q=k-d.gnormx*T*.5,R=_-d.gnormy*T*.5,j=n.rev?1:0,V=T>0;V==null&&(V=!1);let K=null,$=n.contacts.next;for(;$!=null;){let W=$;if(j==W.hash){K=W;break}$=$.next}if(K==null){Pe.zpp_pool==null?K=new Pe:(K=Pe.zpp_pool,Pe.zpp_pool=K.next,K.next=null);let W=K.inner;W.jnAcc=W.jtAcc=0,K.hash=j,K.fresh=!0,K.arbiter=n,n.jrAcc=0;let ie=n.contacts;K._inuse=!0;let oe=K;oe.next=ie.next,ie.next=oe,ie.modified=!0,ie.length++,n.innards.add(W)}else K.fresh=!1;K.px=q,K.py=R,n.nx=S,n.ny=L,K.dist=T,K.stamp=n.stamp,K.posOnly=V;let Y=K,X=1;k-=m.body.posx*X,_-=m.body.posy*X,Y.inner.lr1x=k*m.body.axisy+_*m.body.axisx,Y.inner.lr1y=_*m.body.axisy-k*m.body.axisx;let ee=z-d.gnormx*G*.5,J=C-d.gnormy*G*.5,F=n.rev?0:1,D=G>0;D==null&&(D=!1);let I=null,U=n.contacts.next;for(;U!=null;){let W=U;if(F==W.hash){I=W;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 W=I.inner;W.jnAcc=W.jtAcc=0,I.hash=F,I.fresh=!0,I.arbiter=n,n.jrAcc=0;let ie=n.contacts;I._inuse=!0;let oe=I;oe.next=ie.next,ie.next=oe,ie.modified=!0,ie.length++,n.innards.add(W)}else I.fresh=!1;I.px=ee,I.py=J,n.nx=S,n.ny=L,I.dist=G,I.stamp=n.stamp,I.posOnly=D,Y=I;let Q=1;return z-=m.body.posx*Q,C-=m.body.posy*Q,Y.inner.lr1x=z*m.body.axisy+C*m.body.axisx,Y.inner.lr1y=C*m.body.axisy-z*m.body.axisx,a==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,o=-1e100,r=!0,a=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){r=!1;break}x>l&&(l=x,a=u,p=c),c=c.next,h=h.next}if(r){let u=p,x=p.next==null?t.polygon.gverts.next:p.next,m=e.circle.worldCOMy*a.gnormx-e.circle.worldCOMx*a.gnormy;if(m<=u.y*a.gnormx-u.x*a.gnormy){let d=e.circle.radius,y=u.x-e.circle.worldCOMx,f=u.y-e.circle.worldCOMy,b=y*y+f*f,P;if(b>d*d)P=null;else if(b<i.Config.epsilon*i.Config.epsilon){let k=e.circle.worldCOMx,_=e.circle.worldCOMy,z=null,C=n.contacts.next;for(;C!=null;){let w=C;if(w.hash==0){z=w;break}C=C.next}if(z==null){Pe.zpp_pool==null?z=new Pe:(z=Pe.zpp_pool,Pe.zpp_pool=z.next,z.next=null);let w=z.inner;w.jnAcc=w.jtAcc=0,z.hash=0,z.fresh=!0,z.arbiter=n,n.jrAcc=0;let g=n.contacts;z._inuse=!0;let O=z;O.next=g.next,g.next=O,g.modified=!0,g.length++,n.innards.add(w)}else z.fresh=!1;z.px=k,z.py=_,n.nx=1,n.ny=0,z.dist=-d,z.stamp=n.stamp,z.posOnly=!1,P=z}else{let k=1/Math.sqrt(b),_=k<i.Config.epsilon?1e100:1/k,z=.5+(e.circle.radius-.5*d)*k;if(s){let C=e.circle.worldCOMx+y*z,w=e.circle.worldCOMy+f*z,g=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){g=E;break}O=O.next}if(g==null){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let E=g.inner;E.jnAcc=E.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let N=g;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else g.fresh=!1;g.px=C,g.py=w,n.nx=-y*k,n.ny=-f*k,g.dist=_-d,g.stamp=n.stamp,g.posOnly=!1,P=g}else{let C=e.circle.worldCOMx+y*z,w=e.circle.worldCOMy+f*z,g=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){g=E;break}O=O.next}if(g==null){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let E=g.inner;E.jnAcc=E.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let N=g;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else g.fresh=!1;g.px=C,g.py=w,n.nx=y*k,n.ny=f*k,g.dist=_-d,g.stamp=n.stamp,g.posOnly=!1,P=g}}if(P!=null){let k=P.inner;n.ptype=2;let _=u.x-t.polygon.body.posx,z=u.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=-1,s?(k.lr1x=_*t.polygon.body.axisy+z*t.polygon.body.axisx,k.lr1y=z*t.polygon.body.axisy-_*t.polygon.body.axisx,k.lr2x=e.circle.localCOMx,k.lr2y=e.circle.localCOMy):(k.lr2x=_*t.polygon.body.axisy+z*t.polygon.body.axisx,k.lr2y=z*t.polygon.body.axisy-_*t.polygon.body.axisx,k.lr1x=e.circle.localCOMx,k.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return P!=null}else if(m>=x.y*a.gnormx-x.x*a.gnormy){let d=e.circle.radius,y=x.x-e.circle.worldCOMx,f=x.y-e.circle.worldCOMy,b=y*y+f*f,P;if(b>d*d)P=null;else if(b<i.Config.epsilon*i.Config.epsilon){let k=e.circle.worldCOMx,_=e.circle.worldCOMy,z=null,C=n.contacts.next;for(;C!=null;){let w=C;if(w.hash==0){z=w;break}C=C.next}if(z==null){Pe.zpp_pool==null?z=new Pe:(z=Pe.zpp_pool,Pe.zpp_pool=z.next,z.next=null);let w=z.inner;w.jnAcc=w.jtAcc=0,z.hash=0,z.fresh=!0,z.arbiter=n,n.jrAcc=0;let g=n.contacts;z._inuse=!0;let O=z;O.next=g.next,g.next=O,g.modified=!0,g.length++,n.innards.add(w)}else z.fresh=!1;z.px=k,z.py=_,n.nx=1,n.ny=0,z.dist=-d,z.stamp=n.stamp,z.posOnly=!1,P=z}else{let k=1/Math.sqrt(b),_=k<i.Config.epsilon?1e100:1/k,z=.5+(e.circle.radius-.5*d)*k;if(s){let C=e.circle.worldCOMx+y*z,w=e.circle.worldCOMy+f*z,g=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){g=E;break}O=O.next}if(g==null){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let E=g.inner;E.jnAcc=E.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let N=g;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else g.fresh=!1;g.px=C,g.py=w,n.nx=-y*k,n.ny=-f*k,g.dist=_-d,g.stamp=n.stamp,g.posOnly=!1,P=g}else{let C=e.circle.worldCOMx+y*z,w=e.circle.worldCOMy+f*z,g=null,O=n.contacts.next;for(;O!=null;){let E=O;if(E.hash==0){g=E;break}O=O.next}if(g==null){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let E=g.inner;E.jnAcc=E.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let N=g;N.next=M.next,M.next=N,M.modified=!0,M.length++,n.innards.add(E)}else g.fresh=!1;g.px=C,g.py=w,n.nx=y*k,n.ny=f*k,g.dist=_-d,g.stamp=n.stamp,g.posOnly=!1,P=g}}if(P!=null){let k=P.inner;n.ptype=2;let _=x.x-t.polygon.body.posx,z=x.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=1,s?(k.lr1x=_*t.polygon.body.axisy+z*t.polygon.body.axisx,k.lr1y=z*t.polygon.body.axisy-_*t.polygon.body.axisx,k.lr2x=e.circle.localCOMx,k.lr2y=e.circle.localCOMy):(k.lr2x=_*t.polygon.body.axisy+z*t.polygon.body.axisx,k.lr2y=z*t.polygon.body.axisy-_*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,y=a.gnormx*d,f=a.gnormy*d,b=e.circle.worldCOMx-y,P=e.circle.worldCOMy-f,k;if(s){let _=a.gnormx,z=a.gnormy,C=null,w=n.contacts.next;for(;w!=null;){let g=w;if(g.hash==0){C=g;break}w=w.next}if(C==null){Pe.zpp_pool==null?C=new Pe:(C=Pe.zpp_pool,Pe.zpp_pool=C.next,C.next=null);let g=C.inner;g.jnAcc=g.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(g)}else C.fresh=!1;C.px=b,C.py=P,n.nx=_,n.ny=z,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,k=C}else{let _=-a.gnormx,z=-a.gnormy,C=null,w=n.contacts.next;for(;w!=null;){let g=w;if(g.hash==0){C=g;break}w=w.next}if(C==null){Pe.zpp_pool==null?C=new Pe:(C=Pe.zpp_pool,Pe.zpp_pool=C.next,C.next=null);let g=C.inner;g.jnAcc=g.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(g)}else C.fresh=!1;C.px=b,C.py=P,n.nx=_,n.ny=z,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,k=C}return n.ptype=s?0:1,n.lnormx=a.lnormx,n.lnormy=a.lnormy,n.rev=!s,n.lproj=a.lprojection,n.radius=e.circle.radius,k.inner.lr1x=e.circle.localCOMx,k.inner.lr1y=e.circle.localCOMy,n.__ref_edge1=a,n.__ref_vertex=0,!0}}else return!1}else{let l=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>l*l)p=null;else if(a<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 m=x;if(m.hash==0){u=m;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 m=u.inner;m.jnAcc=m.jtAcc=0,u.hash=0,u.fresh=!0,u.arbiter=n,n.jrAcc=0;let d=n.contacts;u._inuse=!0;let y=u;y.next=d.next,d.next=y,d.modified=!0,d.length++,n.innards.add(m)}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(a),h=c<i.Config.epsilon?1e100:1/c,u=.5+(e.circle.radius-.5*l)*c;if(s){let x=e.circle.worldCOMx+o*u,m=e.circle.worldCOMy+r*u,d=null,y=n.contacts.next;for(;y!=null;){let f=y;if(f.hash==0){d=f;break}y=y.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 b=n.contacts;d._inuse=!0;let P=d;P.next=b.next,b.next=P,b.modified=!0,b.length++,n.innards.add(f)}else d.fresh=!1;d.px=x,d.py=m,n.nx=-o*c,n.ny=-r*c,d.dist=h-l,d.stamp=n.stamp,d.posOnly=!1,p=d}else{let x=e.circle.worldCOMx+o*u,m=e.circle.worldCOMy+r*u,d=null,y=n.contacts.next;for(;y!=null;){let f=y;if(f.hash==0){d=f;break}y=y.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 b=n.contacts;d._inuse=!0;let P=d;P.next=b.next,b.next=P,b.modified=!0,b.length++,n.innards.add(f)}else d.fresh=!1;d.px=x,d.py=m,n.nx=o*c,n.ny=r*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(e.type>t.type){let s=e;e=t,t=s}return fe.testCollide(e,t)}static testCollide(e,t){let n=me();if(t.type==2)return fe._capsuleTestCollide(e,t);if(t.type==1)if(e.type==1){let s=!0,i=e.polygon.edges.head;for(;i!=null;){let l=i.elt,o=1e100,r=t.polygon.gverts.next;for(;r!=null;){let a=r,p=l.gnormx*a.x+l.gnormy*a.y;p<o&&(o=p),r=r.next}if(o-=l.gprojection,o>0){s=!1;break}i=i.next}if(s){let l=t.polygon.edges.head;for(;l!=null;){let o=l.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){s=!1;break}l=l.next}return s}else return!1}else{let s=null,i=null,l=!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){l=!1;break}c>o&&(o=c,s=p,i=r),r=r.next,a=a.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,m=p.y-e.circle.worldCOMy;return x*x+m*m<=u*u}else if(h>=c.y*s.gnormx-c.x*s.gnormy){let u=e.circle.radius,x=c.x-e.circle.worldCOMx,m=c.y-e.circle.worldCOMy;return x*x+m*m<=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(e.type==2||t.type==2)return fe._capsuleFlowCollide(e,t,n,s);if(t.type==1)if(e.type==1){let i=[],l=[],o=!0,r=!0,a=e.polygon.edges.head;for(;a!=null;){let p=a.elt,c=1e100,h=0,u=t.polygon.gverts.next;for(;u!=null;){let x=u,m=p.gnormx*x.x+p.gnormy*x.y;m<c&&(c=m),m>=p.gprojection+s.Config.epsilon&&(l[h]=!0,r=!1),++h,u=u.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 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,m=x;x=x.next;let d=x;for(x=x.next;x!=null;){let _=x;u+=d.x*(_.y-m.y);let z=_.y*d.x-_.x*d.y;h.localCOMx+=(d.x+_.x)*z,h.localCOMy+=(d.y+_.y)*z,m=d,d=_,x=x.next}x=h.lverts.next;let y=x;u+=d.x*(y.y-m.y);let f=y.y*d.x-y.x*d.y;h.localCOMx+=(d.x+y.x)*f,h.localCOMy+=(d.y+y.y)*f,m=d,d=y,x=x.next;let b=x;u+=d.x*(b.y-m.y);let P=b.y*d.x-b.x*d.y;h.localCOMx+=(d.x+b.x)*P,h.localCOMy+=(d.y+b.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(o){r=!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 m=x,d=c.gnormx*m.x+c.gnormy*m.y;d<h&&(h=d),d>=c.gprojection+s.Config.epsilon&&(i[u]=!0,r=!1),++u,x=x.next}if(h-=c.gprojection,h>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 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 m=.5;u.localCOMx*=m,u.localCOMy*=m}else{u.localCOMx=0,u.localCOMy=0;let x=0,m=u.lverts.next,d=m;m=m.next;let y=m;for(m=m.next;m!=null;){let z=m;x+=y.x*(z.y-d.y);let C=z.y*y.x-z.x*y.y;u.localCOMx+=(y.x+z.x)*C,u.localCOMy+=(y.y+z.y)*C,d=y,y=z,m=m.next}m=u.lverts.next;let f=m;x+=y.x*(f.y-d.y);let b=f.y*y.x-f.x*y.y;u.localCOMx+=(y.x+f.x)*b,u.localCOMy+=(y.y+f.y)*b,d=y,y=f,m=m.next;let P=m;x+=y.x*(P.y-d.y);let k=P.y*y.x-P.x*y.y;u.localCOMx+=(y.x+P.x)*k,u.localCOMy+=(y.y+P.y)*k,x=1/(3*x);let _=x;u.localCOMx*=_,u.localCOMy*=_}}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(o){for(;fe.flowpoly.head!=null;){let P=fe.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=ae.zpp_pool,ae.zpp_pool=k}}let c=null,h=!1,u=e.polygon.gverts.next,x=0,m=t.polygon.gverts.next,d=0,y=0,f=t.polygon.edgeCnt;for(;y<f;){let P=y++;if(l[P])m=m.next;else{d=P;break}}if(m==null){m=t.polygon.gverts.next,h=!0;let P=0,k=e.polygon.edgeCnt;for(;P<k;){let _=P++;if(i[_])u=u.next;else{x=_;break}}u==null?u=e.polygon.gverts.next:(fe.flowpoly.add(u),c=fe.flowpoly.head.elt)}else fe.flowpoly.add(m),c=fe.flowpoly.head.elt;let b=1;if(fe.flowpoly.head==null){let P=!0,k=e.polygon.gverts.next,_=k,z=k.next;for(;z!=null;){let C=z,w=2,g=!0,O=t.polygon.gverts.next,E=O,M=O.next;for(;M!=null;){let N=M,Z=0,A=_.x-E.x,S=_.y-E.y,L=C.x-_.x,T=C.y-_.y,G=N.x-E.x,q=N.y-E.y,R=T*G-L*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let V=(q*A-G*S)*R;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let K=(T*A-L*S)*R;K>s.Config.epsilon&&K<1-s.Config.epsilon?(Z=V,j=!0):j=!1}else j=!1}else j=!1;j&&Z<w&&(w=Z,m=O),O=M,E=N,M=M.next}if(g)for(;;){M=t.polygon.gverts.next;let N=M,Z=0,A=_.x-E.x,S=_.y-E.y,L=C.x-_.x,T=C.y-_.y,G=N.x-E.x,q=N.y-E.y,R=T*G-L*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let V=(q*A-G*S)*R;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let K=(T*A-L*S)*R;K>s.Config.epsilon&&K<1-s.Config.epsilon?(Z=V,j=!0):j=!1}else j=!1}else j=!1;j&&Z<w&&(w=Z,m=O);break}if(w!=2){let N=w,Z=_.x+(C.x-_.x)*N,A=_.y+(C.y-_.y)*N;c=ae.get(Z,A),fe.flowpoly.add(c),h=!0,u=k,P=!1;break}k=z,_=C,z=z.next}if(P)for(;;){z=e.polygon.gverts.next;let C=z,w=2,g=!0,O=t.polygon.gverts.next,E=O,M=O.next;for(;M!=null;){let N=M,Z=0,A=_.x-E.x,S=_.y-E.y,L=C.x-_.x,T=C.y-_.y,G=N.x-E.x,q=N.y-E.y,R=T*G-L*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let V=(q*A-G*S)*R;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let K=(T*A-L*S)*R;K>s.Config.epsilon&&K<1-s.Config.epsilon?(Z=V,j=!0):j=!1}else j=!1}else j=!1;j&&Z<w&&(w=Z,m=O),O=M,E=N,M=M.next}if(g)for(;;){M=t.polygon.gverts.next;let N=M,Z=0,A=_.x-E.x,S=_.y-E.y,L=C.x-_.x,T=C.y-_.y,G=N.x-E.x,q=N.y-E.y,R=T*G-L*q,j;if(R*R>s.Config.epsilon*s.Config.epsilon){R=1/R;let V=(q*A-G*S)*R;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let K=(T*A-L*S)*R;K>s.Config.epsilon&&K<1-s.Config.epsilon?(Z=V,j=!0):j=!1}else j=!1}else j=!1;j&&Z<w&&(w=Z,m=O);break}if(w!=2){let N=w,Z=_.x+(C.x-_.x)*N,A=_.y+(C.y-_.y)*N;c=ae.get(Z,A),fe.flowpoly.add(c),h=!0,u=k;break}break}b=2}for(;;)if(h)if(u=u.next,++x,u==null&&(u=e.polygon.gverts.next,x=0),i[x]){let P=fe.flowpoly.head.elt,k=u,_=m,z=m.next;z==null&&(z=t.polygon.gverts.next);let C=-1,w=null,g=0,O=0,E=z,M=z;for(;;){let j=M,V=0,K=_.x-P.x,$=_.y-P.y,Y=j.x-_.x,X=j.y-_.y,ee=k.x-P.x,J=k.y-P.y,F=X*ee-Y*J,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let I=(J*K-ee*$)*F;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*K-Y*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=I,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(w=m,g=d,++O==b){C=V,M=E;break}else C=V;_=j,m=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,V=0,K=_.x-P.x,$=_.y-P.y,Y=j.x-_.x,X=j.y-_.y,ee=k.x-P.x,J=k.y-P.y,F=X*ee-Y*J,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let I=(J*K-ee*$)*F;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*K-Y*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=I,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(w=m,g=d,++O==b){C=V;break}else C=V;_=j,m=M,++d,d>=t.polygon.edgeCnt&&(d=0),M=M.next,M==null&&(M=t.polygon.gverts.next)}if(w==null)break;let N=w,Z=w.next;Z==null&&(Z=t.polygon.gverts.next);let A=Z,S=C,L=N.x+(A.x-N.x)*S,T=N.y+(A.y-N.y)*S,G;if(c!=null){let j=L-c.x,V=T-c.y;G=j*j+V*V<s.Config.epsilon}else G=!1;if(G)break;let q=fe.flowpoly,R=ae.get(L,T);q.add(R),c==null&&(c=fe.flowpoly.head.elt),m=w,d=g,h=!h,b=2}else{let P=u,k;if(c!=null){let _=P.x-c.x,z=P.y-c.y;k=_*_+z*z<s.Config.epsilon}else k=!1;if(k)break;fe.flowpoly.add(P),c==null&&(c=fe.flowpoly.head.elt),b=1}else if(m=m.next,++d,m==null&&(m=t.polygon.gverts.next,d=0),l[d]){let P=fe.flowpoly.head.elt,k=m,_=u,z=u.next;z==null&&(z=e.polygon.gverts.next);let C=-1,w=null,g=0,O=0,E=z,M=z;for(;;){let j=M,V=0,K=_.x-P.x,$=_.y-P.y,Y=j.x-_.x,X=j.y-_.y,ee=k.x-P.x,J=k.y-P.y,F=X*ee-Y*J,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let I=(J*K-ee*$)*F;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*K-Y*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=I,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(w=u,g=x,++O==b){C=V,M=E;break}else C=V;_=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,V=0,K=_.x-P.x,$=_.y-P.y,Y=j.x-_.x,X=j.y-_.y,ee=k.x-P.x,J=k.y-P.y,F=X*ee-Y*J,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let I=(J*K-ee*$)*F;if(I>s.Config.epsilon&&I<1-s.Config.epsilon){let U=(X*K-Y*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=I,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(w=u,g=x,++O==b){C=V;break}else C=V;_=j,u=M,++x,x>=e.polygon.edgeCnt&&(x=0),M=M.next,M==null&&(M=e.polygon.gverts.next)}if(w==null)break;let N=w,Z=w.next;Z==null&&(Z=e.polygon.gverts.next);let A=Z,S=C,L=N.x+(A.x-N.x)*S,T=N.y+(A.y-N.y)*S,G;if(c!=null){let j=L-c.x,V=T-c.y;G=j*j+V*V<s.Config.epsilon}else G=!1;if(G)break;let q=fe.flowpoly,R=ae.get(L,T);q.add(R),c==null&&(c=fe.flowpoly.head.elt),u=w,x=g,h=!h,b=2}else{let P=m,k;if(c!=null){let _=P.x-c.x,z=P.y-c.y;k=_*_+z*z<s.Config.epsilon}else k=!1;if(k)break;fe.flowpoly.add(P),c==null&&(c=fe.flowpoly.head.elt),b=1}if(fe.flowpoly.head!=null&&fe.flowpoly.head.next!=null&&fe.flowpoly.head.next.next!=null){let P=0,k=0,_=0,z=fe.flowpoly.head,C=z.elt;z=z.next;let w=z.elt;for(z=z.next;z!=null;){let A=z.elt;P+=w.x*(A.y-C.y);let S=A.y*w.x-A.x*w.y;k+=(w.x+A.x)*S,_+=(w.y+A.y)*S,C=w,w=A,z=z.next}z=fe.flowpoly.head;let g=z.elt;P+=w.x*(g.y-C.y);let O=g.y*w.x-g.x*w.y;k+=(w.x+g.x)*O,_+=(w.y+g.y)*O,C=w,w=g,z=z.next;let E=z.elt;P+=w.x*(E.y-C.y);let M=E.y*w.x-E.x*w.y;k+=(w.x+E.x)*M,_+=(w.y+E.y)*M,P*=.5;let Z=1/(6*P);return k*=Z,_*=Z,n.overlap=-P,n.centroidx=k,n.centroidy=_,!0}else return!1}else return!1}else return!1}else{let i=[],l=!0,o=null,r=null,a=-1e100,p=!0,c=t.polygon.gverts.next,h=0,u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,m=x.gnormx*e.circle.worldCOMx+x.gnormy*e.circle.worldCOMy;if(m>x.gprojection+e.circle.radius){p=!1;break}else m+e.circle.radius>x.gprojection+s.Config.epsilon&&(l=!1,i[h]=!0);m-=x.gprojection+e.circle.radius,m>a&&(a=m,o=x,r=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=r,m=r.next==null?t.polygon.gverts.next:r.next,d=e.circle.worldCOMy*o.gnormx-e.circle.worldCOMx*o.gnormy,y;if(d<=x.y*o.gnormx-x.x*o.gnormy){let f=e.circle.radius,b=x.x-e.circle.worldCOMx,P=x.y-e.circle.worldCOMy;y=b*b+P*P<=f*f}else if(d>=m.y*o.gnormx-m.x*o.gnormy){let f=e.circle.radius,b=m.x-e.circle.worldCOMx,P=m.y-e.circle.worldCOMy;y=b*b+P*P<=f*f}else y=!0;if(y){let f=[],b=0,P=!0,k=null,_=0,z=t.polygon.gverts.next;for(;z!=null;){let C=z,w=C.x-e.circle.worldCOMx,g=C.y-e.circle.worldCOMy,O=w*w+g*g;(f[b]=O<=e.circle.radius*e.circle.radius)?(_=b,k=z):P=!1,++b,z=z.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 g=C.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 O=1;g.localCOMx+=g.lverts.next.next.x*O,g.localCOMy+=g.lverts.next.next.y*O;let E=.5;g.localCOMx*=E,g.localCOMy*=E}else{g.localCOMx=0,g.localCOMy=0;let O=0,E=g.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;g.localCOMx+=(N.x+G.x)*q,g.localCOMy+=(N.y+G.y)*q,M=N,N=G,E=E.next}E=g.lverts.next;let Z=E;O+=N.x*(Z.y-M.y);let A=Z.y*N.x-Z.x*N.y;g.localCOMx+=(N.x+Z.x)*A,g.localCOMy+=(N.y+Z.y)*A,M=N,N=Z,E=E.next;let S=E;O+=N.x*(S.y-M.y);let L=S.y*N.x-S.x*N.y;g.localCOMx+=(N.x+S.x)*L,g.localCOMy+=(N.y+S.y)*L,O=1/(3*O);let T=O;g.localCOMx*=T,g.localCOMy*=T}}C.wrap_localCOM!=null&&(C.wrap_localCOM.zpp_inner.x=C.localCOMx,C.wrap_localCOM.zpp_inner.y=C.localCOMy)}let w=C.body;w.zip_axis&&(w.zip_axis=!1,w.axisx=Math.sin(w.rot),w.axisy=Math.cos(w.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(;fe.flowpoly.head!=null;){let g=fe.flowpoly.pop_unsafe();if(!g._inuse){let O=g;O.outer!=null&&(O.outer.zpp_inner=null,O.outer=null),O._isimmutable=null,O._validate=null,O._invalidate=null,O.next=ae.zpp_pool,ae.zpp_pool=O}}fe.flowsegs.clear();let C=null,w=1;for(k==null?(k=t.polygon.gverts.next,w=2):(C=k,fe.flowpoly.add(C));w!=0;)if(w==1)if(k=k.next,k==null&&(k=t.polygon.gverts.next),++_,_>=t.polygon.edgeCnt&&(_=0),f[_]){let g=C.x-k.x,O=C.y-k.y;if(g*g+O*O<s.Config.epsilon)break;fe.flowpoly.add(k)}else{let g=fe.flowpoly.head.elt,O=k,E=O.x-g.x,M=O.y-g.y,N=g.x-e.circle.worldCOMx,Z=g.y-e.circle.worldCOMy,A=E*E+M*M,S=2*(N*E+Z*M),L=N*N+Z*Z-e.circle.radius*e.circle.radius,T=Math.sqrt(S*S-4*A*L);A=1/(2*A);let G=(-S-T)*A,q=G<s.Config.epsilon?(-S+T)*A:G,R=0,j=0,V=q;R=g.x+(O.x-g.x)*V,j=g.y+(O.y-g.y)*V;let K=C.x-R,$=C.y-j;if(K*K+$*$<s.Config.epsilon)break;let Y=fe.flowpoly,X=ae.get(R,j);Y.add(X),w=2}else if(w==2){let g=k.next;g==null&&(g=t.polygon.gverts.next);let O=k;w=0;let E=g,M=g;for(;;){let N=M,Z=_+1;if(Z==t.polygon.edgeCnt&&(Z=0),i[_])if(f[Z]){let A=N.x-O.x,S=N.y-O.y,L=O.x-e.circle.worldCOMx,T=O.y-e.circle.worldCOMy,G=A*A+S*S,q=2*(L*A+T*S),R=L*L+T*T-e.circle.radius*e.circle.radius,j=Math.sqrt(q*q-4*G*R);G=1/(2*G);let V=(-q-j)*G,K=V<s.Config.epsilon?(-q+j)*G:V,$=0,Y=0,X=K;$=O.x+(N.x-O.x)*X,Y=O.y+(N.y-O.y)*X;let ee=C.x-$,J=C.y-Y;if(ee*ee+J*J<s.Config.epsilon){w=0,M=E;break}let D=ae.get($,Y);fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(D),fe.flowpoly.add(D),w=1,M=E;break}else{let A=0,S=0,L=N.x-O.x,T=N.y-O.y,G=O.x-e.circle.worldCOMx,q=O.y-e.circle.worldCOMy,R=L*L+T*T,j=2*(G*L+q*T),V=G*G+q*q-e.circle.radius*e.circle.radius,K=j*j-4*R*V,$;if(K*K<s.Config.epsilon?(K<0?A=10:(S=-j/(2*R),A=S),$=!1):(K=Math.sqrt(K),R=1/(2*R),A=(-j-K)*R,S=(-j+K)*R,$=!0),A<1-s.Config.epsilon&&S>s.Config.epsilon){let Y=0,X=0,ee=A;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){w=0,M=E;break}let D=ae.get(Y,X);if(fe.flowpoly.head!=null&&(fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(D)),fe.flowpoly.add(D),C==null&&(C=fe.flowpoly.head.elt),$){let I=0,U=0,Q=S;I=O.x+(N.x-O.x)*Q,U=O.y+(N.y-O.y)*Q;let W=fe.flowpoly,ie=ae.get(I,U);W.add(ie)}}}O=N,k=M,_=Z,M=M.next,M==null&&(M=t.polygon.gverts.next);break}for(;M!=E;){let N=M,Z=_+1;if(Z==t.polygon.edgeCnt&&(Z=0),i[_])if(f[Z]){let A=N.x-O.x,S=N.y-O.y,L=O.x-e.circle.worldCOMx,T=O.y-e.circle.worldCOMy,G=A*A+S*S,q=2*(L*A+T*S),R=L*L+T*T-e.circle.radius*e.circle.radius,j=Math.sqrt(q*q-4*G*R);G=1/(2*G);let V=(-q-j)*G,K=V<s.Config.epsilon?(-q+j)*G:V,$=0,Y=0,X=K;$=O.x+(N.x-O.x)*X,Y=O.y+(N.y-O.y)*X;let ee=C.x-$,J=C.y-Y;if(ee*ee+J*J<s.Config.epsilon){w=0,M=E;break}let D=ae.get($,Y);fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(D),fe.flowpoly.add(D),w=1,M=E;break}else{let A=0,S=0,L=N.x-O.x,T=N.y-O.y,G=O.x-e.circle.worldCOMx,q=O.y-e.circle.worldCOMy,R=L*L+T*T,j=2*(G*L+q*T),V=G*G+q*q-e.circle.radius*e.circle.radius,K=j*j-4*R*V,$;if(K*K<s.Config.epsilon?(K<0?A=10:(S=-j/(2*R),A=S),$=!1):(K=Math.sqrt(K),R=1/(2*R),A=(-j-K)*R,S=(-j+K)*R,$=!0),A<1-s.Config.epsilon&&S>s.Config.epsilon){let Y=0,X=0,ee=A;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){w=0,M=E;break}let D=ae.get(Y,X);if(fe.flowpoly.head!=null&&(fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(D)),fe.flowpoly.add(D),C==null&&(C=fe.flowpoly.head.elt),$){let I=0,U=0,Q=S;I=O.x+(N.x-O.x)*Q,U=O.y+(N.y-O.y)*Q;let W=fe.flowpoly,ie=ae.get(I,U);W.add(ie)}}}O=N,k=M,_=Z,M=M.next,M==null&&(M=t.polygon.gverts.next)}}if(fe.flowpoly.head==null)return!1;if(fe.flowpoly.head.next==null){let g=!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){g=!1;break}O=O.next}return g?(n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0):!1}else{let g=0,O=0,E=0;if(fe.flowpoly.head.next.next!=null){let N=0,Z=0,A=0;N=0;let S=fe.flowpoly.head,L=S.elt;S=S.next;let T=S.elt;for(S=S.next;S!=null;){let Y=S.elt;N+=T.x*(Y.y-L.y);let X=Y.y*T.x-Y.x*T.y;Z+=(T.x+Y.x)*X,A+=(T.y+Y.y)*X,L=T,T=Y,S=S.next}S=fe.flowpoly.head;let G=S.elt;N+=T.x*(G.y-L.y);let q=G.y*T.x-G.x*T.y;Z+=(T.x+G.x)*q,A+=(T.y+G.y)*q,L=T,T=G,S=S.next;let R=S.elt;N+=T.x*(R.y-L.y);let j=R.y*T.x-R.x*T.y;Z+=(T.x+R.x)*j,A+=(T.y+R.y)*j,N*=.5;let K=1/(6*N);Z*=K,A*=K;let $=-N;g+=Z*$,O+=A*$,E-=N}else fe.flowsegs.add(fe.flowpoly.head.elt),fe.flowsegs.add(fe.flowpoly.head.next.elt);for(;fe.flowsegs.head!=null;){let N=fe.flowsegs.pop_unsafe(),Z=fe.flowsegs.pop_unsafe(),A=Z.x-N.x,S=Z.y-N.y,L=A,T=S,G=L*L+T*T,R=1/Math.sqrt(G);L*=R,T*=R;let j=L;L=-T,T=j;let V=N.x+Z.x,K=N.y+Z.y,$=.5;V*=$,K*=$;let Y=1;V-=e.circle.worldCOMx*Y,K-=e.circle.worldCOMy*Y;let X=L*V+T*K,ee=0,J=0,F=X,D=F/e.circle.radius,I=Math.sqrt(1-D*D),U=Math.acos(D);ee=e.circle.radius*(e.circle.radius*U-F*I),J=.6666666666666666*e.circle.radius*I*I*I/(U-D*I),V=e.circle.worldCOMx,K=e.circle.worldCOMy;let Q=J;V+=L*Q,K+=T*Q;let W=ee;g+=V*W,O+=K*W,E+=ee}let M=1/E;return g*=M,O*=M,n.overlap=E,n.centroidx=g,n.centroidy=O,!0}}}else return!1}}else return!1}else{let i=e.circle,l=t.circle,o=l.worldCOMx-i.worldCOMx,r=l.worldCOMy-i.worldCOMy,a=i.radius+l.radius,p=o*o+r*r;if(p>a*a)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 m=0,d=0,y=0,f=0,b=u,P=b/i.radius,k=Math.sqrt(1-P*P),_=Math.acos(P);m=i.radius*(i.radius*_-b*k),d=.6666666666666666*i.radius*k*k*k/(_-P*k);let z=x,C=z/l.radius,w=Math.sqrt(1-C*C),g=Math.acos(C);y=l.radius*(l.radius*g-z*w),f=.6666666666666666*l.radius*w*w*w/(g-C*w);let O=m+y,E=(d*m+(c-f)*y)/O*h;n.overlap=O,n.centroidx=i.worldCOMx+o*E,n.centroidy=i.worldCOMy+r*E}}return!0}}}static capsuleContains(e,t){let n=fe._closestT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.x,t.y),s=e.spine1x+n*(e.spine2x-e.spine1x),i=e.spine1y+n*(e.spine2y-e.spine1y),l=t.x-s,o=t.y-i;return l*l+o*o<e.radius*e.radius}static _closestT(e,t,n,s,i,l){let o=n-e,r=s-t,a=o*o+r*r;if(a<1e-12)return 0;let p=((i-e)*o+(l-t)*r)/a;return p<0&&(p=0),p>1&&(p=1),p}static _closestTT(e,t,n,s,i,l,o,r){let a=n-e,p=s-t,c=o-i,h=r-l,u=e-i,x=t-l,m=a*a+p*p,d=c*c+h*h,y=c*u+h*x,f,b;if(m<1e-12&&d<1e-12)return[0,0];if(m<1e-12)return f=0,b=y/d,b<0&&(b=0),b>1&&(b=1),[f,b];let P=a*u+p*x;if(d<1e-12)return b=0,f=-P/m,f<0&&(f=0),f>1&&(f=1),[f,b];let k=a*c+p*h,_=m*d-k*k;if(_>1e-12)f=(k*y-P*d)/_,f<0&&(f=0),f>1&&(f=1),b=(k*f+y)/d,b<0?(b=0,f=-P/m,f<0&&(f=0),f>1&&(f=1)):b>1&&(b=1,f=(k-P)/m,f<0&&(f=0),f>1&&(f=1));else{let z=1/m,C=-(a*u+p*x)*z,w=C+k*z,g=Math.max(0,Math.min(C,w)),O=Math.min(1,Math.max(C,w));f=g<=O?(g+O)*.5:C<0?0:1,b=(k*f+y)/d,b<0&&(b=0),b>1&&(b=1)}return[f,b]}static _getOrCreateContact(e,t,n){let s=null,i=e.contacts.next;for(;i!=null;){if(t==i.hash){s=i;break}i=i.next}if(s==null){Pe.zpp_pool==null?s=new Pe:(s=Pe.zpp_pool,Pe.zpp_pool=s.next,s.next=null);let l=s.inner;l.jnAcc=l.jtAcc=0,s.hash=t,s.fresh=!0,s.arbiter=e,e.jrAcc=0;let o=e.contacts;s._inuse=!0;let r=s;r.next=o.next,o.next=r,o.modified=!0,o.length++,e.innards.add(l)}else s.fresh=!1;return s}static _capsuleContactCollide(e,t,n,s,i){let l=t.capsule;return e.type==0?fe._circleCapsuleContact(e.circle,l,n,s,i):e.type==1?fe._polyCapsuleContact(e.polygon,l,n,s,i):fe._capsuleCapsuleContact(e.capsule,l,n,s,i)}static _circleCapsuleContact(e,t,n,s,i){let l=fe._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,e.worldCOMx,e.worldCOMy),o=t.spine1x+l*(t.spine2x-t.spine1x),r=t.spine1y+l*(t.spine2y-t.spine1y),a=e.radius+t.radius,p=e.worldCOMx-o,c=e.worldCOMy-r,h=p*p+c*c;if(h>a*a)return!1;let u;if(h<i.Config.epsilon*i.Config.epsilon){let x=(e.worldCOMx+o)*.5,m=(e.worldCOMy+r)*.5;u=fe._getOrCreateContact(n,0,n.stamp),u.px=x,u.py=m,n.nx=1,n.ny=0,u.dist=-a,u.stamp=n.stamp,u.posOnly=!1}else{let x=1/Math.sqrt(h),m=x<i.Config.epsilon?1e100:1/x,d=.5+(e.radius-.5*a)*x,y=e.worldCOMx-p*d,f=e.worldCOMy-c*d;u=fe._getOrCreateContact(n,0,n.stamp),u.px=y,u.py=f,s?(n.nx=p*x,n.ny=c*x):(n.nx=-p*x,n.ny=-c*x),u.dist=m-a,u.stamp=n.stamp,u.posOnly=!1}if(u!=null){let x=u.inner,m=t.localCOMx+(2*l-1)*t.halfLength;return s?(x.lr1x=m,x.lr1y=t.localCOMy,x.lr2x=e.localCOMx,x.lr2y=e.localCOMy):(x.lr1x=e.localCOMx,x.lr1y=e.localCOMy,x.lr2x=m,x.lr2y=t.localCOMy),n.radius=a,n.ptype=2,!0}return!1}static _capsuleCapsuleContact(e,t,n,s,i){let l=e.radius+t.radius,o=i.Config.epsilon,r=(f,b,P)=>{let k=e.spine1x+b*(e.spine2x-e.spine1x),_=e.spine1y+b*(e.spine2y-e.spine1y),z=t.spine1x+P*(t.spine2x-t.spine1x),C=t.spine1y+P*(t.spine2y-t.spine1y),w=z-k,g=C-_,O=w*w+g*g;if(O>l*l)return!1;let E=fe._getOrCreateContact(n,f,n.stamp);if(O<o*o)E.px=(k+z)*.5,E.py=(_+C)*.5,f===0&&(n.nx=1,n.ny=0),E.dist=-l;else{let A=1/Math.sqrt(O),S=1/A,L=w*A,T=g*A,G=.5+(e.radius-.5*l)*A;E.px=k+w*G,E.py=_+g*G,f===0&&(n.nx=s?-L:L,n.ny=s?-T:T),E.dist=S-l}E.stamp=n.stamp,E.posOnly=!1;let M=E.inner,N=e.localCOMx+(2*b-1)*e.halfLength,Z=t.localCOMx+(2*P-1)*t.halfLength;return s?(M.lr1x=Z,M.lr1y=t.localCOMy,M.lr2x=N,M.lr2y=e.localCOMy):(M.lr1x=N,M.lr1y=e.localCOMy,M.lr2x=Z,M.lr2y=t.localCOMy),!0},[a,p]=fe._closestTT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine1x,t.spine1y,t.spine2x,t.spine2y);if(!r(0,a,p))return!1;if(n.radius=l,n.ptype=2,fe.debugCapsule){let f=e.spine1x+a*(e.spine2x-e.spine1x),b=e.spine1y+a*(e.spine2y-e.spine1y),P=t.spine1x+p*(t.spine2x-t.spine1x),k=t.spine1y+p*(t.spine2y-t.spine1y),_=P-f,z=k-b,C=Math.sqrt(_*_+z*z);console.log("[capCap] nx=",n.nx.toFixed(3),"ny=",n.ny.toFixed(3),"dist=",C.toFixed(3),"minDist=",l.toFixed(3),"pen=",(C-l).toFixed(3))}let c=e.spine2x-e.spine1x,h=e.spine2y-e.spine1y,u=t.spine2x-t.spine1x,x=t.spine2y-t.spine1y,m=c*c+h*h,d=u*u+x*x,y=c*x-h*u;if(y*y<.01*m*d&&m>1e-12&&d>1e-12){let f=[[0,fe._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,e.spine1x,e.spine1y)],[1,fe._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,e.spine2x,e.spine2y)],[fe._closestT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine1x,t.spine1y),0],[fe._closestT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine2x,t.spine2y),1]],b=0,P=null;for(let[k,_]of f){let z=k-a,C=z*z;if(C>b+1e-6){let w=e.spine1x+k*(e.spine2x-e.spine1x),g=e.spine1y+k*(e.spine2y-e.spine1y),O=t.spine1x+_*(t.spine2x-t.spine1x),E=t.spine1y+_*(t.spine2y-t.spine1y),M=O-w,N=E-g;M*M+N*N<=l*l&&(b=C,P=[k,_])}}P!=null&&r(1,P[0],P[1])}return!0}static _polyCapsuleContact(e,t,n,s,i){let l=-1e100,o=null,r=null,a=!0,p=e.gverts.next,c=e.edges.head;for(;c!=null;){let E=c.elt,M=E.gnormx*t.spine1x+E.gnormy*t.spine1y,N=E.gnormx*t.spine2x+E.gnormy*t.spine2y,A=(M<N?M:N)-E.gprojection-t.radius;if(A>0){a=!1;break}A>l&&(l=A,o=E,r=p),p=p.next,c=c.next}if(!a)return!1;let h=t.spine2x-t.spine1x,u=t.spine2y-t.spine1y,x=h*h+u*u;if(x>1e-12){let E=Math.sqrt(x),M=-u/E,N=h/E,Z=M*t.spine1x+N*t.spine1y,A=1e100,S=-1e100,L=e.gverts.next;for(;L!=null;){let G=M*L.x+N*L.y;G<A&&(A=G),G>S&&(S=G),L=L.next}if((A>Z+t.radius?A-(Z+t.radius):S<Z-t.radius?Z-t.radius-S:0)>0)return!1}let m=r,d=r.next==null?e.gverts.next:r.next,y=m.y*o.gnormx-m.x*o.gnormy,f=d.y*o.gnormx-d.x*o.gnormy,b=E=>t.localCOMx+(2*E-1)*t.halfLength,P=(E,M)=>{E.lr1x=M,E.lr1y=t.localCOMy,E.lr2x=0,E.lr2y=0},k=(E,M,N,Z)=>{let S=o.gnormx*N+o.gnormy*Z-o.gprojection-t.radius;if(S>0)return;let L=fe._getOrCreateContact(n,E,n.stamp);L.px=N-o.gnormx*(t.radius+S*.5),L.py=Z-o.gnormy*(t.radius+S*.5),L.dist=S,L.stamp=n.stamp,L.posOnly=!1,P(L.inner,b(M))},_=(E,M,N,Z,A)=>{let S=Z-M,L=A-N,T=S*S+L*L;if(T>t.radius*t.radius)return!1;let G=fe._getOrCreateContact(n,0,n.stamp);if(n.radius=t.radius,n.ptype=0,n.__ref_edge1=o,n.__ref_vertex=0,T<i.Config.epsilon*i.Config.epsilon)G.px=M,G.py=N,n.nx=s?-o.gnormx:o.gnormx,n.ny=s?-o.gnormy:o.gnormy,G.dist=-t.radius;else{let q=1/Math.sqrt(T),R=1/q,j=S*q,V=L*q;G.px=M+j*t.radius,G.py=N+V*t.radius,n.nx=s?-j:j,n.ny=s?-V:V,G.dist=R-t.radius}return G.stamp=n.stamp,G.posOnly=!1,P(G.inner,b(E)),!0},z=t.spine1y*o.gnormx-t.spine1x*o.gnormy,C=t.spine2y*o.gnormx-t.spine2x*o.gnormy,w=z>y&&z<f,g=C>y&&C<f;if(!w&&!g){let E=o.gnormx*t.spine1x+o.gnormy*t.spine1y,M=o.gnormx*t.spine2x+o.gnormy*t.spine2y;if(E<=M){if(z<=y){if(_(0,t.spine1x,t.spine1y,m.x,m.y))return!0}else if(_(0,t.spine1x,t.spine1y,d.x,d.y))return!0}else if(C<=y){if(_(1,t.spine2x,t.spine2y,m.x,m.y))return!0}else if(_(1,t.spine2x,t.spine2y,d.x,d.y))return!0;let N=fe._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,t.spine1x+o.gnormx*o.gprojection,t.spine1y+o.gnormy*o.gprojection),Z=(y+f)*.5,A=t.spine1y*o.gnormx-t.spine1x*o.gnormy,L=t.spine2y*o.gnormx-t.spine2x*o.gnormy-A,T=Math.abs(L)>1e-12?(Z-A)/L:.5;T<0&&(T=0),T>1&&(T=1);let G=t.spine1x+T*(t.spine2x-t.spine1x),q=t.spine1y+T*(t.spine2y-t.spine1y);return o.gnormx*G+o.gnormy*q-o.gprojection-t.radius>0?!1:(n.nx=s?-o.gnormx:o.gnormx,n.ny=s?-o.gnormy:o.gnormy,n.radius=t.radius,n.lproj=o.lprojection,n.lnormx=o.lnormx,n.lnormy=o.lnormy,n.ptype=s?1:0,n.rev=s,n.__ref_edge1=o,n.__ref_vertex=0,k(0,T,G,q),n.oc1!=null&&n.oc1.stamp==n.stamp)}n.nx=s?-o.gnormx:o.gnormx,n.ny=s?-o.gnormy:o.gnormy,n.radius=t.radius,n.lproj=o.lprojection,n.lnormx=o.lnormx,n.lnormy=o.lnormy,n.ptype=s?1:0,n.rev=s,n.__ref_edge1=o,n.__ref_vertex=0;let O=0;return w&&k(O++,0,t.spine1x,t.spine1y),g&&k(O,1,t.spine2x,t.spine2y),fe.debugCapsule&&O>0&&console.log("[polyCapsule face] nx=",n.nx.toFixed(3),"ny=",n.ny.toFixed(3),"dist=",n.oc1?.dist?.toFixed(3),"ptype=",n.ptype,"rev=",n.rev,"bestDist=",l.toFixed(3)),O>0||n.oc1!=null&&n.oc1.stamp==n.stamp}static _capsuleTestCollide(e,t){let n=t.capsule;if(e.type==0){let s=fe._closestT(n.spine1x,n.spine1y,n.spine2x,n.spine2y,e.circle.worldCOMx,e.circle.worldCOMy),i=n.spine1x+s*(n.spine2x-n.spine1x),l=n.spine1y+s*(n.spine2y-n.spine1y),o=e.circle.radius+n.radius,r=e.circle.worldCOMx-i,a=e.circle.worldCOMy-l;return r*r+a*a<=o*o}else if(e.type==1){let s=e.polygon.edges.head;for(;s!=null;){let r=s.elt,a=r.gnormx*n.spine1x+r.gnormy*n.spine1y,p=r.gnormx*n.spine2x+r.gnormy*n.spine2y;if((a<p?a:p)-r.gprojection-n.radius>0)return!1;s=s.next}let i=n.spine2x-n.spine1x,l=n.spine2y-n.spine1y,o=i*i+l*l;if(o>1e-12){let r=-l,a=i,p=Math.sqrt(o),c=r/p,h=a/p,u=c*n.spine1x+h*n.spine1y,x=1e100,m=-1e100,d=e.polygon.gverts.next;for(;d!=null;){let y=c*d.x+h*d.y;y<x&&(x=y),y>m&&(m=y),d=d.next}if(x>u+n.radius||m<u-n.radius)return!1}return!0}else{let s=e.capsule,[i,l]=fe._closestTT(s.spine1x,s.spine1y,s.spine2x,s.spine2y,n.spine1x,n.spine1y,n.spine2x,n.spine2y),o=s.spine1x+i*(s.spine2x-s.spine1x),r=s.spine1y+i*(s.spine2y-s.spine1y),a=n.spine1x+l*(n.spine2x-n.spine1x),p=n.spine1y+l*(n.spine2y-n.spine1y),c=s.radius+n.radius,h=a-o,u=p-r;return h*h+u*u<=c*c}}static _capsuleFlowCollide(e,t,n,s){let i=e.type==2?e.capsule:t.capsule,l=e.type==2?t:e,o=i.area||Math.PI*i.radius*i.radius+4*i.halfLength*i.radius;if(l.type==2){let u=l.capsule,[x,m]=fe._closestTT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,u.spine1x,u.spine1y,u.spine2x,u.spine2y),d=i.spine1x+x*(i.spine2x-i.spine1x),y=i.spine1y+x*(i.spine2y-i.spine1y),f=u.spine1x+m*(u.spine2x-u.spine1x),b=u.spine1y+m*(u.spine2y-u.spine1y),P=f-d,k=b-y,_=Math.sqrt(P*P+k*k),z=i.radius+u.radius;if(_>=z)return!1;let C=z-_;return n.overlap=C*Math.min(2*i.radius,2*u.radius)*.5,n.buoyx=(d+f)*.5,n.buoyy=(y+b)*.5,!0}if(l.type==0){let u=l.circle,x=fe._closestT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,u.worldCOMx,u.worldCOMy),m=i.spine1x+x*(i.spine2x-i.spine1x),d=i.spine1y+x*(i.spine2y-i.spine1y),y=u.worldCOMx-m,f=u.worldCOMy-d,b=Math.sqrt(y*y+f*f),P=i.radius+u.radius;if(b>=P)return!1;let k=P-b;return n.overlap=k*Math.min(2*i.radius,2*u.radius)*.5,n.buoyx=(m+u.worldCOMx)*.5,n.buoyy=(d+u.worldCOMy)*.5,!0}let r=l.polygon,a=1e100,p=0,c=0,h=r.edges.head;for(;h!=null;){let u=h.elt,x=u.gnormx*i.spine1x+u.gnormy*i.spine1y,m=u.gnormx*i.spine2x+u.gnormy*i.spine2y,d=x<m?x:m,y=u.gprojection+i.radius-d;if(y<0)return!1;y<a&&(a=y,p=u.gnormx,c=u.gnormy),h=h.next}return n.overlap=a*2*i.radius*.5,n.buoyx=i.worldCOMx,n.buoyy=i.worldCOMy,!0}};fe.flowpoly=null,fe.flowsegs=null;var Ce=fe;var dl=class v{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 o=l,r=o.prev,a=null,p=o.diagonals.head;for(;p!=null;){let c=p.elt,h=p.next==null?o.next:p.next.elt;if(!v.isinner(h,o,r)){a=p,r=c,p=p.next;continue}let u=!0,x=c,m=x.prev,d=null,y=x.diagonals.head;for(;y!=null;){let f=y.elt;if(f==o){let b=y.next==null?x.next:y.next.elt;u=v.isinner(b,x,m);break}m=f,d=y,y=y.next}if(u){p=o.diagonals.erase(a),x.diagonals.erase(d);continue}r=c,a=p,p=p.next}if(l=l.next,l==i)break}}}};var tt=class tt{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;tt.rayPool==null?(tt.internal=!0,i=tt._createRayResult(),i.zpp_inner=new tt,i.zpp_inner.ray=i,tt.internal=!1):(i=tt.rayPool.ray,tt.rayPool=tt.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;tt.convexPool==null?(tt.internal=!0,i=tt._createConvexResult(),i.zpp_inner=new tt,i.zpp_inner.convex=i,tt.internal=!1):(i=tt.convexPool.convex,tt.convexPool=tt.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(){tt._disposeVec2(this.normal),this.position!=null&&tt._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=tt.convexPool,tt.convexPool=this):(this.next=tt.rayPool,tt.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,ye.nextVec2!=null?ye.nextVec2.zpp_pool=e:ye.poolVec2=e,ye.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=ae.zpp_pool,ae.zpp_pool=n}};tt.rayPool=null,tt.convexPool=null,tt.internal=!1,tt._createRayResult=null,tt._createConvexResult=null;var bn=tt;var Fi=class Fi{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 Fi.zpp_pool==null?t=new Fi:(t=Fi.zpp_pool,Fi.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}};Fi.zpp_pool=null;var Qe=Fi;var Ri=class Ri{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,o=!1){let r;return Ri.zpp_pool==null?r=new Ri:(r=Ri.zpp_pool,Ri.zpp_pool=r.next,r.next=null),r.virtualint=l,r.end=t,r.start=n,r.path0=s,r.path1=i,r.time=e,r.vertex=o,r}alloc(){}free(){this.end=this.start=null,this.path0=this.path1=null}};Ri.zpp_pool=null;var lt=Ri;var ri=class ri{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 ri.zpp_pool==null?n=new ri:(n=ri.zpp_pool,ri.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,ye.nextVec2!=null?ye.nextVec2.zpp_pool=s:ye.poolVec2=s,ye.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=ae.zpp_pool,ae.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(ye.poolVec2==null?n=ri._createVec2Fn():(n=ye.poolVec2,ye.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n===ye.nextVec2&&(ye.nextVec2=null)),n.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.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 o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y===t}else i=!1;if(!i){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=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}};ri.zpp_pool=null,ri._createVec2Fn=null;var ge=ri;var et=class et{static run(e,t,n,s,i,l){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 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 m=n.zpp_inner;m._validate!=null&&m._validate();let d=n.zpp_inner.y-h,y=s?0:-1/0,f=i?1:1/0,b=-(h*x-p*d),P=null,k=!1,_=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=_,j.posx=_.x,j.posy=_.y,j.value=j.posy*x-j.posx*d+b,j.positive=j.value>0,j.value==0&&(k=!0);let V=j;if(P==null?V.prev=V.next=V:(V.prev=P,V.next=P.next,P.next.prev=V,P.next=V),P=V,_=_.next,_==e)break}if(k){let j=null,V=P,K=P;if(V!=null){let U=V;for(;;){let Q=U;if(Q.value!=0){j=Q;break}if(U=U.next,U==K)break}}let $,Y;$=x,Y=d;let X=$*$+Y*Y,J=1/Math.sqrt(X);$*=J,Y*=J;let F=$;$=-Y,Y=F;let D=null,I=j;for(;;){if(I.value!=0&&(D==null||I==D.next)){if(D=I,I=I.next,I==j)break;continue}let U=D.value*I.value;if(U==0){if(I=I.next,I==j)break;continue}let Q=D.next,W;if(U>0)W=D.positive;else{let se=Q.next,ne,re;ne=Q.posx+se.posx,re=Q.posy+se.posy;let le=.5;ne*=le,re*=le;let he=ne+$*1e-8,pe=re+Y*1e-8,ce=!1,te=e,ue=e;if(te!=null){let xe=te;for(;;){let _e=xe,ve=_e.prev;if((_e.y<pe&&ve.y>=pe||ve.y<pe&&_e.y>=pe)&&(_e.x<=he||ve.x<=he)&&_e.x+(pe-_e.y)/(ve.y-_e.y)*(ve.x-_e.x)<he&&(ce=!ce),xe=xe.next,xe==ue)break}}W=ce}let ie=Q,oe=I;if(ie!=null){let se=ie;for(;;){let ne=se;if(ne.positive=W,se=se.next,se==oe)break}}if(D=I,I=I.next,I==j)break}for(;!(I.value!=0&&(D==null||I==D.next));){let U=D.value*I.value;if(U==0)break;let Q=D.next,W;if(U>0)W=D.positive;else{let se=Q.next,ne,re;ne=Q.posx+se.posx,re=Q.posy+se.posy;let le=.5;ne*=le,re*=le;let he=ne+$*1e-8,pe=re+Y*1e-8,ce=!1,te=e,ue=e;if(te!=null){let xe=te;for(;;){let _e=xe,ve=_e.prev;if((_e.y<pe&&ve.y>=pe||ve.y<pe&&_e.y>=pe)&&(_e.x<=he||ve.x<=he)&&_e.x+(pe-_e.y)/(ve.y-_e.y)*(ve.x-_e.x)<he&&(ce=!ce),xe=xe.next,xe==ue)break}}W=ce}let ie=Q,oe=I;if(ie!=null){let se=ie;for(;;){let ne=se;if(ne.positive=W,se=se.next,se==oe)break}}break}}et.ints==null&&(et.ints=new r.util.ZNPList_ZPP_CutInt),et.paths==null&&(et.paths=new r.util.ZNPList_ZPP_CutVert);let z=null,C=P.posx,w=P.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=C,g.y=w;let O=g;O.prev=O.next=O,z=O;let E=z,M;Qe.zpp_pool==null?M=new Qe:(M=Qe.zpp_pool,Qe.zpp_pool=M.next,M.next=null),M.vert=z,M.parent=M,M.rank=0,M.used=!1;let N=M;et.paths.add(N);let Z=P;for(;;){let j=Z.next,V=j.posx,K=j.posy,$;ge.zpp_pool==null?$=new ge:($=ge.zpp_pool,ge.zpp_pool=$.next,$.next=null),$.forced=!1,$.x=V,$.y=K;let Y=$;if(Z.positive==j.positive){let X=Y;z==null?(X.prev=X.next=X,z=X):(X.next=z,X.prev=z.prev,z.prev.next=X,z.prev=X)}else{let X=j.posx-Z.posx,ee=j.posy-Z.posy,J=d*X-x*ee;J=1/J;let F=p-Z.posx,D=h-Z.posy,I=(ee*F-X*D)*J;if(I<y||I>f){let U=et.ints,Q=!0;Q==null&&(Q=!1);let W;lt.zpp_pool==null?W=new lt:(W=lt.zpp_pool,lt.zpp_pool=W.next,W.next=null),W.virtualint=Q,W.end=null,W.start=null,W.path0=null,W.path1=null,W.time=I,W.vertex=!1,U.add(W);let ie=Y;z==null?(ie.prev=ie.next=ie,z=ie):(ie.next=z,ie.prev=z.prev,z.prev.next=ie,z.prev=ie)}else if(Z.value==0){let U=z.prev;z=null;let Q=U.x,W=U.y,ie;ge.zpp_pool==null?ie=new ge:(ie=ge.zpp_pool,ge.zpp_pool=ie.next,ie.next=null),ie.forced=!1,ie.x=Q,ie.y=W;let oe=ie;oe.prev=oe.next=oe,z=oe;let se=Y;z==null?(se.prev=se.next=se,z=se):(se.next=z,se.prev=z.prev,z.prev.next=se,z.prev=se);let ne=et.paths.head.elt,re=et.paths,le;Qe.zpp_pool==null?le=new Qe:(le=Qe.zpp_pool,Qe.zpp_pool=le.next,le.next=null),le.vert=z,le.parent=le,le.rank=0,le.used=!1,re.add(le);let he=et.paths.head.elt,pe=et.ints,ce=!0;ce==null&&(ce=!1);let te;lt.zpp_pool==null?te=new lt:(te=lt.zpp_pool,lt.zpp_pool=te.next,te.next=null),te.virtualint=ce,te.end=U,te.start=z,te.path0=ne,te.path1=he,te.time=I,te.vertex=!1,pe.add(te)}else if(j.value==0){let U=Y;z==null?(U.prev=U.next=U,z=U):(U.next=z,U.prev=z.prev,z.prev.next=U,z.prev=U);let Q=z.prev;z=null;let W=j.posx,ie=j.posy,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=W,oe.y=ie;let se=oe;se.prev=se.next=se,z=se;let ne=et.paths.head.elt,re=et.paths,le;Qe.zpp_pool==null?le=new Qe:(le=Qe.zpp_pool,Qe.zpp_pool=le.next,le.next=null),le.vert=z,le.parent=le,le.rank=0,le.used=!1,re.add(le);let he=et.paths.head.elt,pe=et.ints,ce=!0;ce==null&&(ce=!1);let te;lt.zpp_pool==null?te=new lt:(te=lt.zpp_pool,lt.zpp_pool=te.next,te.next=null),te.virtualint=ce,te.end=Q,te.start=z,te.path0=ne,te.path1=he,te.time=I,te.vertex=!1,pe.add(te)}else{let U=(d*F-x*D)*J,Q,W;Q=Z.posx,W=Z.posy;let ie=U;Q+=X*ie,W+=ee*ie;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=Q,oe.y=W;let se=oe;z==null?(se.prev=se.next=se,z=se):(se.next=z,se.prev=z.prev,z.prev.next=se,z.prev=se);let ne=z.prev;z=null;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=Q,re.y=W;let le=re;le.prev=le.next=le,z=le;let he=Y;z==null?(he.prev=he.next=he,z=he):(he.next=z,he.prev=z.prev,z.prev.next=he,z.prev=he);let pe=et.paths.head.elt,ce=et.paths,te;Qe.zpp_pool==null?te=new Qe:(te=Qe.zpp_pool,Qe.zpp_pool=te.next,te.next=null),te.vert=z,te.parent=te,te.rank=0,te.used=!1,ce.add(te);let ue=et.paths.head.elt,xe=et.ints,_e=!1;_e==null&&(_e=!1);let ve;lt.zpp_pool==null?ve=new lt:(ve=lt.zpp_pool,lt.zpp_pool=ve.next,ve.next=null),ve.virtualint=_e,ve.end=ne,ve.start=z,ve.path0=pe,ve.path1=ue,ve.time=I,ve.vertex=!1,xe.add(ve)}}if(Z=Z.next,Z==P)break}let A=z.prev;A.next.prev=E.prev,E.prev.next=A.next,A.next=E,E.prev=A;let S=et.paths.head.elt,L;if(N==N.parent)L=N;else{let j=N,V=null;for(;j!=j.parent;){let K=j.parent;j.parent=V,V=j,j=K}for(;V!=null;){let K=V.parent;V.parent=j,V=K}L=j}let T;if(S==S.parent)T=S;else{let j=S,V=null;for(;j!=j.parent;){let K=j.parent;j.parent=V,V=j,j=K}for(;V!=null;){let K=V.parent;V.parent=j,V=K}T=j}L!=T&&(L.rank<T.rank?L.parent=T:L.rank>T.rank?T.parent=L:(T.parent=L,L.rank++));let G=et.ints;if(G.head!=null&&G.head.next!=null){let j=G.head,V,K,$,Y,X=1,ee,J,F;for(;;){for(ee=0,K=j,j=null,V=j;K!=null;){for(++ee,$=K,J=0,F=X;$!=null&&J<X;)++J,$=$.next;for(;J>0||F>0&&$!=null;)J==0?(Y=$,$=$.next,--F):F==0||$==null||K.elt.time<$.elt.time?(Y=K,K=K.next,--J):(Y=$,$=$.next,--F),V!=null?V.next=Y:j=Y,V=Y;K=$}if(V.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(),V=et.ints.pop_unsafe();if(!j.virtualint&&!V.virtualint){j.end.next.prev=V.start.prev,V.start.prev.next=j.end.next,j.end.next=V.start,V.start.prev=j.end,V.end.next.prev=j.start.prev,j.start.prev.next=V.end.next,V.end.next=j.start,j.start.prev=V.end;let Y;if(j.path0==j.path0.parent)Y=j.path0;else{let F=j.path0,D=null;for(;F!=F.parent;){let I=F.parent;F.parent=D,D=F,F=I}for(;D!=null;){let I=D.parent;D.parent=F,D=I}Y=F}let X;if(V.path1==V.path1.parent)X=V.path1;else{let F=V.path1,D=null;for(;F!=F.parent;){let I=F.parent;F.parent=D,D=F,F=I}for(;D!=null;){let I=D.parent;D.parent=F,D=I}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(j.path1==j.path1.parent)ee=j.path1;else{let F=j.path1,D=null;for(;F!=F.parent;){let I=F.parent;F.parent=D,D=F,F=I}for(;D!=null;){let I=D.parent;D.parent=F,D=I}ee=F}let J;if(V.path0==V.path0.parent)J=V.path0;else{let F=V.path0,D=null;for(;F!=F.parent;){let I=F.parent;F.parent=D,D=F,F=I}for(;D!=null;){let I=D.parent;D.parent=F,D=I}J=F}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&&!V.virtualint){let Y;if(V.end!=null&&V.end.prev==V.end){V.end.next=V.end.prev=null;let J=V.end;if(J.wrap!=null){J.wrap.zpp_inner._inuse=!1;let F=J.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=F.zpp_inner;if(D._immutable)throw new Error("Error: Vec2 is immutable");if(D._isimmutable!=null&&D._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let I=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let U=F;U.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=U:ye.poolVec2=U,ye.nextVec2=U,U.zpp_disp=!0;let Q=I;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=ae.zpp_pool,ae.zpp_pool=Q,J.wrap=null}J.prev=J.next=null,J.next=ge.zpp_pool,ge.zpp_pool=J,Y=null}else{let J=V.end.prev;V.end.prev.next=V.end.next,V.end.next.prev=V.end.prev,V.end.next=V.end.prev=null;let F=V.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,V.end=null,Y=J}if(V.end=Y,!V.vertex)if(V.end!=V.path0.vert){V.start.x=V.end.x,V.start.y=V.end.y;let J;if(V.end!=null&&V.end.prev==V.end){V.end.next=V.end.prev=null;let F=V.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,J=null}else{let F=V.end.prev;V.end.prev.next=V.end.next,V.end.next.prev=V.end.prev,V.end.next=V.end.prev=null;let D=V.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let I=D.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 Q=I.zpp_inner;I.zpp_inner.outer=null,I.zpp_inner=null;let W=I;W.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=W:ye.poolVec2=W,ye.nextVec2=W,W.zpp_disp=!0;let ie=Q;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=ae.zpp_pool,ae.zpp_pool=ie,D.wrap=null}D.prev=D.next=null,D.next=ge.zpp_pool,ge.zpp_pool=D,V.end=null,J=F}V.end=J}else{let J=V.start.next;if(V.start.x=J.x,V.start.y=J.y,J!=null&&J.prev==J){J.next=J.prev=null;let F=J;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}else{J.prev.next=J.next,J.next.prev=J.prev,J.next=J.prev=null;let F=J;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}}V.end.next.prev=V.start.prev,V.start.prev.next=V.end.next,V.end.next=V.start,V.start.prev=V.end;let X;if(V.path0==V.path0.parent)X=V.path0;else{let J=V.path0,F=null;for(;J!=J.parent;){let D=J.parent;J.parent=F,F=J,J=D}for(;F!=null;){let D=F.parent;F.parent=J,F=D}X=J}let ee;if(V.path1==V.path1.parent)ee=V.path1;else{let J=V.path1,F=null;for(;J!=J.parent;){let D=J.parent;J.parent=F,F=J,J=D}for(;F!=null;){let D=F.parent;F.parent=J,F=D}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(V.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 F=J.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=F.zpp_inner;if(D._immutable)throw new Error("Error: Vec2 is immutable");if(D._isimmutable!=null&&D._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let I=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let U=F;U.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=U:ye.poolVec2=U,ye.nextVec2=U,U.zpp_disp=!0;let Q=I;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=ae.zpp_pool,ae.zpp_pool=Q,J.wrap=null}J.prev=J.next=null,J.next=ge.zpp_pool,ge.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 F=j.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,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 F=j.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,J=null}else{let F=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 D=j.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let I=D.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 Q=I.zpp_inner;I.zpp_inner.outer=null,I.zpp_inner=null;let W=I;W.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=W:ye.poolVec2=W,ye.nextVec2=W,W.zpp_disp=!0;let ie=Q;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=ae.zpp_pool,ae.zpp_pool=ie,D.wrap=null}D.prev=D.next=null,D.next=ge.zpp_pool,ge.zpp_pool=D,j.end=null,J=F}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 F=J;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}else{J.prev.next=J.next,J.next.prev=J.prev,J.next=J.prev=null;let F=J;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let I=D.zpp_inner;if(I._immutable)throw new Error("Error: Vec2 is immutable");if(I._isimmutable!=null&&I._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=Q:ye.poolVec2=Q,ye.nextVec2=Q,Q.zpp_disp=!0;let W=U;W.outer!=null&&(W.outer.zpp_inner=null,W.outer=null),W._isimmutable=null,W._validate=null,W._invalidate=null,W.next=ae.zpp_pool,ae.zpp_pool=W,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}}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,F=null;for(;J!=J.parent;){let D=J.parent;J.parent=F,F=J,J=D}for(;F!=null;){let D=F.parent;F.parent=J,F=D}X=J}let ee;if(j.path1==j.path1.parent)ee=j.path1;else{let J=j.path1,F=null;for(;J!=J.parent;){let D=J.parent;J.parent=F,F=J,J=D}for(;F!=null;){let D=F.parent;F.parent=J,F=D}ee=J}X!=ee&&(X.rank<ee.rank?X.parent=ee:X.rank>ee.rank?ee.parent=X:(ee.parent=X,X.rank++))}let K=j;K.end=K.start=null,K.path0=K.path1=null,K.next=lt.zpp_pool,lt.zpp_pool=K;let $=V;$.end=$.start=null,$.path0=$.path1=null,$.next=lt.zpp_pool,lt.zpp_pool=$}let q=l??new o.geom.GeomPolyList,R=et.paths.head;for(;R!=null;){let j=R.elt,V;if(j==j.parent)V=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}V=Y}if(V.used){R=R.next;continue}V.used=!0;let K=V.vert,$=!0;for(;V.vert!=null&&($||K!=V.vert);)if($=!1,K.x==K.next.x&&K.y==K.next.y)if(K==V.vert&&(V.vert=K.next==K?null:K.next,$=!0),K!=null&&K.prev==K)K.next=K.prev=null,K=null;else{let Y=K.next;K.prev.next=K.next,K.next.prev=K.prev,K.next=K.prev=null,K=Y}else K=K.next;if(V.vert!=null){let Y=o.geom.GeomPoly.get();Y.zpp_inner.vertices=V.vert,q.zpp_inner.reverse_flag?q.push(Y):q.unshift(Y)}R=R.next}for(;et.paths.head!=null;){let V=et.paths.pop_unsafe();V.vert=null,V.parent=null,V.next=Qe.zpp_pool,Qe.zpp_pool=V}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 V=P;V.vert=null,V.parent=null,V.next=Qe.zpp_pool,Qe.zpp_pool=V,P=j}return q}};et.ints=null,et.paths=null;var _l=et;var gs=class v{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 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 a=i,p=s.elt;s=s.next,p.gp0=l,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,l=a,i=i.next}let o=t.gverts.next,r=s.elt;r.gp0=l,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;v._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 if(e.type==2)e.capsule.__validate_aabb();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,o=t.gverts.next;for(;o!=null;){let r=o,a=l;l=l.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 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&&v._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&&v._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 o=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*o,e.localCOMy+=(i.y+l.y)*o,s=i,i=l,n=n.next;let r=n;t+=i.x*(r.y-s.y);let a=r.y*i.x-r.x*i.y;e.localCOMx+=(i.x+r.x)*a,e.localCOMy+=(i.y+r.y)*a,t=1/(3*t);let p=t;e.localCOMx*=p,e.localCOMy*=p}}};var yl=class{constructor(e=null){this.outer=null;this.vertices=null;this.outer=e}};var Bn=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}};Bn.zpp_pool=null;var jn=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(){}};jn.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 s=t.zpp_inner;t.zpp_inner.outer=null,t.zpp_inner=null;let i=t;i.zpp_pool=null,ye.nextVec2!=null?ye.nextVec2.zpp_pool=i:ye.poolVec2=i,ye.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=ae.zpp_pool,ae.zpp_pool=l,e.wrap=null}e.prev=e.next=null,e.next=ge.zpp_pool,ge.zpp_pool=e}static _allocSpan(){let e;return Bn.zpp_pool==null?e=new Bn:(e=Bn.zpp_pool,Bn.zpp_pool=e.next,e.next=null),e.out=!1,e.rank=0,e}static _allocPair(){let e;return jn.zpp_pool==null?e=new jn:(e=jn.zpp_pool,jn.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=jn.zpp_pool,jn.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,o,r,a){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,r&&(ze.map==null?ze.map=new ys(h,x):ze.map.resize(h,x,null)),ze.isos==null?ze.isos=new ds(h+1,x+1):ze.isos.resize(h+1,x+1,0);for(let y=0;y<x+1;y++){let f;if(y==0)f=n;else if(y<=x){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(),f=n+l.zpp_inner.y*y}else f=i;for(let b=0;b<h+1;b++){let P;if(b==0)P=t;else if(b<=h){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(),P=t+l.zpp_inner.x*b}else P=s;let k=ze.isos,_=e(P,f);k.list[y*k.width+b]=_}}ze.ints==null?ze.ints=new _s(h+1,(x<<1)+1):ze.ints.resize(h+1,(x<<1)+1,null);let m=null;r&&(m=ze._allocSpan(),m.next=null);let d=n;for(let y=0;y<x;y++){let f=d,b;if(y==x-1)b=i;else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let _=l.zpp_inner;_._validate!=null&&_._validate(),b=n+l.zpp_inner.y*(y+1)}d=b;let P=t,k=null;for(let _=0;_<h;_++){let z=P,C;if(_==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*(_+1)}P=C;let w=_==0||!r,g=y==0||!r,O=_==h-1||!r,E=y==x-1||!r,M=ze.me.marchSquare(e,ze.isos,ze.ints,z,f,C,b,_,y,w,g,O,E,o);if(M==null){k=null;continue}if(r){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[y*Z.width+_]=M;let A;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,A=q>=2}else A=!1;A?(ze.me.combLR(k,M),M.span1=k.spanr):(M.span1=ze._allocSpan(),M.span1.next=m,m=M.span1),M.p2!=null?(M.span2=ze._allocSpan(),M.span2.next=m,m=M.span2,M.spanr=M.span2):M.spanr=M.span1;let S=(M.keyr&28)>>2,L=0;(S&1)!=0&&++L,(S&2)!=0&&++L,(S&4)!=0&&++L,L>=2?k=M:k=null}else ze.me.output(a,M.p1),M.p2!=null&&ze.me.output(a,M.p2),ze._freePair(M)}}if(r){for(let y=1;y<x;y++){let f=null;for(let b=0;b<h;b++){let P=ze.map,k=P.list[y*P.width+b];if(k==null){f=null;continue}let z=(k.p2!=null&&k.okey2==14?k.okey2:k.okey1)&7,C=0;if((z&1)!=0&&++C,(z&2)!=0&&++C,(z&4)!=0&&++C,C<2){f=null;continue}let w=ze.map,g=w.list[(y-1)*w.width+b];if(g==null){f=null;continue}let E=((g.p2!=null&&g.okey2==56?g.okey2:g.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=g.p2!=null&&g.okey2==56?g.span2:g.span1,Z=k.p2!=null&&k.okey2==14?k.span2:k.span1,A=ze._findRoot(N),S=ze._findRoot(Z);A==S?f!=Z&&ze.me.combUD_virtual(g,k):(ze._union(N,Z),ze.me.combUD(g,k)),f=((Z==k.span2?k.okey2:k.okey1)&4)!=0?Z:null}}for(let y=0;y<x;y++)for(let f=0;f<h;f++){let b=ze.map,P=b.list[y*b.width+f];if(P==null)continue;let k=ze._findRoot(P.span1);k.out||(k.out=!0,ze.me.output(a,P.p1)),P.p2!=null&&(k=ze._findRoot(P.span2),k.out||(k.out=!0,ze.me.output(a,P.p2))),ze._freePair(P),b.list[y*b.width+f]=null}for(;m!=null;){let y=m;m=y.next;let f=y;f.parent=f,f.next=Bn.zpp_pool,Bn.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 o=0,r=t,a=t;if(r!=null){let c=r;for(;;){let h=c;if(o+=h.x*(h.next.y-h.prev.y),c=c.next,c==a)break}}let p=o*.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 o=t.next;t.prev.next=t.next,t.next.prev=t.prev,t.next=t.prev=null,t=o}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,o=(t.okey1&1)==0?l.prev:l,r=i.next,a=o.prev;(e.keyr&4)!=0?(t.pr==t.p1&&(t.pr=i.prev),t.p1=i.prev,i.prev.next=o.next,o.next.prev=i.prev,ze._freeVert(i)):(i.next=o.next,o.next.prev=i),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,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,o,r,a,p,c,h,u,x,m,d,y,f,b){let P=null;for(let k=0;k<8;k++)if((e&1<<k)!=0){let _;if(k==0)_=ze._allocVert(s,i),(x||m)&&(_.forced=!0);else if(k==2)_=ze._allocVert(l,i),(d||m)&&(_.forced=!0);else if(k==4)_=ze._allocVert(l,o),(d||y)&&(_.forced=!0);else if(k==6)_=ze._allocVert(s,o),(x||y)&&(_.forced=!0);else if(k==1){if(_=n.list[(a<<1)*n.width+r],_==null){let z=this.xlerp(s,l,i,p,c,f,b);_=ze._allocVert(z,i),n.list[(a<<1)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);m&&(_.forced=!0),(_.x==s||_.x==l)&&(_.x==s&&(e&1)!=0||_.x==l&&(e&4)!=0)&&(e^=2)}else if(k==5){if(_=n.list[((a<<1)+2)*n.width+r],_==null){let z=this.xlerp(s,l,o,u,h,f,b);_=ze._allocVert(z,o),n.list[((a<<1)+2)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);y&&(_.forced=!0),(_.x==s||_.x==l)&&(_.x==s&&(e&64)!=0||_.x==l&&(e&16)!=0)&&(e^=32)}else if(k==3){if(_=n.list[((a<<1)+1)*n.width+(r+1)],_==null){let z=this.ylerp(i,o,l,c,h,f,b);_=ze._allocVert(l,z),n.list[((a<<1)+1)*n.width+(r+1)]=_}else _=ze._allocVert(_.x,_.y);d&&(_.forced=!0),(_.y==i||_.y==o)&&(_.y==i&&(e&4)!=0||_.y==o&&(e&16)!=0)&&(e^=8)}else{if(_=n.list[((a<<1)+1)*n.width+r],_==null){let z=this.ylerp(i,o,s,p,u,f,b);_=ze._allocVert(s,z),n.list[((a<<1)+1)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);x&&(_.forced=!0),(_.y==i||_.y==o)&&(_.y==i&&(e&1)!=0||_.y==o&&(e&64)!=0)&&(e^=128)}P=ze._pushVert(P,_)}return P!=null&&(P=P.next),{head:P,val:e}}marchSquare(e,t,n,s,i,l,o,r,a,p,c,h,u,x){let m=0,d=t.list[a*t.width+r];d<0&&(m|=8);let y=t.list[a*t.width+(r+1)];y<0&&(m|=4);let f=t.list[(a+1)*t.width+(r+1)];f<0&&(m|=2);let b=t.list[(a+1)*t.width+r];if(b<0&&(m|=1),m==0)return null;let P=ze._allocPair();if(m!=10&&m!=5){let k=ze.look_march[m];P.okey1=k;let _=this._buildPoly(k,t,n,s,i,l,o,r,a,d,y,f,b,p,c,h,u,e,x);P.p1=_.head,k=_.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+o))<0;if(m==10)if(k){let _=187;P.okey1=_;let z=this._buildPoly(_,t,n,s,i,l,o,r,a,d,y,f,b,p,c,h,u,e,x);P.p1=z.head,_=z.val,P.key1=_,ze._isDegenKey(_)&&(_=0,P.key1=0,P.p1=null),_==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let _=131;P.okey1=_;let z=this._buildPoly(_,t,n,s,i,l,o,r,a,d,y,f,b,p,c,h,u,e,x);if(P.p1=z.head,_=z.val,P.key1=_,ze._isDegenKey(_)&&(_=0,P.key1=0,P.p1=null),_!=0){let C=56;P.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,o,r,a,d,y,f,b,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 w=this._buildPoly(C,t,n,s,i,l,o,r,a,d,y,f,b,p,c,h,u,e,x);P.p1=w.head,C=w.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 _=238;P.okey1=_;let z=this._buildPoly(_,t,n,s,i,l,o,r,a,d,y,f,b,p,c,h,u,e,x);P.p1=z.head,_=z.val,P.key1=_,ze._isDegenKey(_)&&(_=0,P.key1=0,P.p1=null),_==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let _=224;P.okey1=_;let z=this._buildPoly(_,t,n,s,i,l,o,r,a,d,y,f,b,p,c,h,u,e,x);if(P.p1=z.head,_=z.val,P.key1=_,ze._isDegenKey(_)&&(_=0,P.key1=0,P.p1=null),_!=0){let C=14;P.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,o,r,a,d,y,f,b,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 w=this._buildPoly(C,t,n,s,i,l,o,r,a,d,y,f,b,p,c,h,u,e,x);P.p1=w.head,C=w.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,o,r,a,p,c,h,u,x,m,d,y,f,b,P){for(let k=0;k<8;k++)if((e&1<<k)!=0){let _;if(k==0)_=ze._allocVert(s,i),(x||m)&&(_.forced=!0);else if(k==2)_=ze._allocVert(l,i),(d||m)&&(_.forced=!0);else if(k==4)_=ze._allocVert(l,o),(d||y)&&(_.forced=!0);else if(k==6)_=ze._allocVert(s,o),(x||y)&&(_.forced=!0);else if(k==1){if(_=n.list[(a<<1)*n.width+r],_==null){let C=this.xlerp(s,l,i,p,c,f,b);_=ze._allocVert(C,i),n.list[(a<<1)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);m&&(_.forced=!0),(_.x==s||_.x==l)&&(_.x==s&&(e&1)!=0||_.x==l&&(e&4)!=0)&&(e^=2)}else if(k==5){if(_=n.list[((a<<1)+2)*n.width+r],_==null){let C=this.xlerp(s,l,o,u,h,f,b);_=ze._allocVert(C,o),n.list[((a<<1)+2)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);y&&(_.forced=!0),(_.x==s||_.x==l)&&(_.x==s&&(e&64)!=0||_.x==l&&(e&16)!=0)&&(e^=32)}else if(k==3){if(_=n.list[((a<<1)+1)*n.width+(r+1)],_==null){let C=this.ylerp(i,o,l,c,h,f,b);_=ze._allocVert(l,C),n.list[((a<<1)+1)*n.width+(r+1)]=_}else _=ze._allocVert(_.x,_.y);d&&(_.forced=!0),(_.y==i||_.y==o)&&(_.y==i&&(e&4)!=0||_.y==o&&(e&16)!=0)&&(e^=8)}else{if(_=n.list[((a<<1)+1)*n.width+r],_==null){let C=this.ylerp(i,o,s,p,u,f,b);_=ze._allocVert(s,C),n.list[((a<<1)+1)*n.width+r]=_}else _=ze._allocVert(_.x,_.y);x&&(_.forced=!0),(_.y==i||_.y==o)&&(_.y==i&&(e&1)!=0||_.y==o&&(e&64)!=0)&&(e^=128)}let z=_;P.p2==null?P.p2=z.prev=z.next=z:(z.prev=P.p2,z.next=P.p2.next,P.p2.next.prev=z,P.p2.next=z),P.p2=z}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,o=l*l<i.Config.epsilon*i.Config.epsilon?.5:n/l;return o<0?o=0:o>1&&(o=1),e+o*(t-e)}}xlerp(e,t,n,s,i,l,o){let r=ze._nape,a;if(s==0)a=e;else if(i==0)a=t;else{let p=s-i,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=l(a,n);if(p==0)break;if(s*p<0?(t=a,i=p):(e=a,s=p),s==0)a=e;else if(i==0)a=t;else{let c=s-i,h=c*c<r.Config.epsilon*r.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),a=e+h*(t-e)}}return a}ylerp(e,t,n,s,i,l,o){let r=ze._nape,a;if(s==0)a=e;else if(i==0)a=t;else{let p=s-i,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=l(n,a);if(p==0)break;if(s*p<0?(t=a,i=p):(e=a,s=p),s==0)a=e;else if(i==0)a=t;else{let c=s-i,h=c*c<r.Config.epsilon*r.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),a=e+h*(t-e)}}return a}};ze.isos=null,ze.ints=null,ze.map=null,ze._zpp=null,ze._nape=null;var Js=ze;var cn=class cn{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 cn.zpp_pool==null?e=new cn:(e=cn.zpp_pool,cn.zpp_pool=e.next,e.next=null),e}static identity(){let e=cn.get();return e.setas(1,0,0,1,0,0),e}wrapper(){if(this.outer==null)if(cn._wrapFn)this.outer=cn._wrapFn(this);else{this.outer=new cn._nape.geom.Mat23;let e=this.outer.zpp_inner;e.next=cn.zpp_pool,cn.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(){}};cn._nape=null,cn._wrapFn=null,cn.zpp_pool=null;var Us=cn;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,s=e*t;for(;n<s;)n++,this.x.push(0)}};var yt=class yt{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=yt.nextId++,this.diagonals=new _i}static get(e){let t;return yt.zpp_pool==null?t=new yt:(t=yt.zpp_pool,yt.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,o=t.y-e.y;return(n?-1:1)*(o*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 yt.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!yt.vert_lt(e,t);if(t==e.next)return yt.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 yt.rightdistance(t,e)>0?!0:yt.rightdistance(t,e.next)>0;else{let n=yt.rightdistance(e,t),s=yt.rightdistance(e,t.next);if(n==0&&s==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*s>=0)return n<0?!0:s<0;let i=yt.rightdistance(t,e),l=yt.rightdistance(t,e.next);return i*l>=0?i>0?!0:l>0:!1}}alloc(){}free(){this.helper=null}copy(){let e;return yt.zpp_pool==null?e=new yt:(e=yt.zpp_pool,yt.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,o=this.diagonals;if(o.head!=null&&o.head.next!=null){let r=o.head,a,p,c,h,u=1,x,m,d;for(;;){for(x=0,p=r,r=null,a=r;p!=null;){for(++x,c=p,m=0,d=u;c!=null&&m<u;)++m,c=c.next;for(;m>0||d>0&&c!=null;){if(m==0)h=c,c=c.next,--d;else if(d==0||c==null)h=p,p=p.next,--m;else{let y;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;y=(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,b=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(b*k==1||b*k==0&&(b==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 _=s*e-n*t;y=(_>0?-1:_==0?0:1)==1}else if(b==-1||k==-1)y=k==-1;else if(b==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 _=e*n+t*s;n=c.elt.x-this.x,s=c.elt.y-this.y;let z=e*n+t*s;y=_<0&&z>0?!0:!(z<0&&_>0)}else y=!0}y?(h=p,p=p.next,--m):(h=c,c=c.next,--d)}a!=null?a.next=h:r=h,a=h}p=c}if(a.next=null,u<<=1,!(x>1))break}o.head=r,o.modified=!0,o.pushmod=!0}}};yt.zpp_pool=null,yt.nextId=0;var Ge=yt;var hn=class hn{constructor(e){this.next=null;this.vertices=null;this.init(e)}static getSharedPP(){return hn.sharedPPList==null&&(hn.sharedPPList=new pl),hn.sharedPPList}static getShared(){return hn.sharedGVList==null&&(hn.sharedGVList=new ms),hn.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 o=n;for(;;){let r=o;if(t+=r.x*(r.next.y-r.prev.y),o=o.next,o==s)break}}let i=t*.5>0,l=e;for(;;){let o;if(i){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;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=l.x,r.y=l.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=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,o=e.next.x-e.x,a=(e.next.y-e.y)*i-o*l;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 pl),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 o=this.vertices;o.helper=null,o.next=Ge.zpp_pool,Ge.zpp_pool=o,l=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,l=o}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;hn.zpp_pool==null?n=new hn:(n=hn.zpp_pool,hn.zpp_pool=n.next,n.next=null);let s=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=s.x,r.y=s.y,r.forced=s.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=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,o=n.vertices;if(l!=null){let r=l;for(;;){let a=r;if(i+=a.x*(a.next.y-a.prev.y),r=r.next,r==o)break}}return i*.5!=0&&t.add(n),s}extract(e){if(e==null&&(e=new ms),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 a=s.x,p=s.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 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,o=n;if(l!=null){let a=l;for(;;){let p=a;if(i+=p.x*(p.next.y-p.prev.y),a=a.next,a==o)break}}let r=i*.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,h=a.y-a.next.y;if(c*c+h*h<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 u=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=u}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 h=a.prev,u=a.x-h.x,x=a.y-h.y,m=a.next.x-a.x,y=(a.next.y-a.y)*u-m*x;if(y*y>=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 s}};hn.zpp_pool=null,hn.sharedPPList=null,hn.sharedGVList=null;var qi=hn;var Fe=class Fe{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,o=n.y-e.y,r;ae.zpp_pool==null?r=new ae:(r=ae.zpp_pool,ae.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=-i-o,r.y=s+l;let a=r,p=a.x*a.x+a.y*a.y,h=1/Math.sqrt(p);return a.x*=h,a.y*=h,o*s-l*i<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=Fe.bisector(e),s=Fe.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 o=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=ae.zpp_pool,ae.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=ae.zpp_pool,ae.zpp_pool=s,o}}static above(e,t){return Fe.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 r=s;for(;;){let a=r;if(a.y<t.y&&(t=a),a.y>n.y&&(n=a),r=r.next,r==i)break}}let l=!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){l=!1;break}if(o=c,p=p.next,p==a)break}}}if(!l)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){l=!1;break}if(o=c,p=p.prev,p==a)break}}}return l}static getShared(){return Fe.sharedPPoly==null&&(Fe.sharedPPoly=new qi),Fe.sharedPPoly}static decompose(e,t){if(t==null?t=new qi(e):t.init(e),t.vertices==null)return t;Fe.queue==null&&(Fe.queue=new _i);let n=t.vertices,s=t.vertices;if(n!=null){let l=n;for(;;){let o=l;Fe.queue.add(o);let r=o.next.x-o.x,a=o.next.y-o.y,p=o.prev.x-o.x,h=(o.prev.y-o.y)*r-p*a>0;if(o.type=Fe.below(o.prev,o)?Fe.below(o.next,o)?h?0:3:4:Fe.below(o,o.next)?h?1:2:4,l=l.next,l==s)break}}let i=Fe.queue;if(i.head!=null&&i.head.next!=null){let l=i.head,o,r,a,p,c=1,h,u,x;for(;;){for(h=0,r=l,l=null,o=l;r!=null;){for(++h,a=r,u=0,x=c;a!=null&&u<c;)++u,a=a.next;for(;u>0||x>0&&a!=null;)u==0?(p=a,a=a.next,--x):x==0||a==null||Fe.above(r.elt,a.elt)?(p=r,r=r.next,--u):(p=a,a=a.next,--x),o!=null?o.next=p:l=p,o=p;r=a}if(o.next=null,c<<=1,!(h>1))break}i.head=l,i.modified=!0,i.pushmod=!0}for(Fe.edges==null&&(zs.zpp_pool==null?Fe.edges=new zs:(Fe.edges=zs.zpp_pool,zs.zpp_pool=Fe.edges.next,Fe.edges.next=null),Fe.edges.lt=Ge.edge_lt,Fe.edges.swapped=Ge.edge_swap);Fe.queue.head!=null;){let l=Fe.queue.pop_unsafe();switch(l.type){case 0:l.helper=l,l.node=Fe.edges.insert(l);break;case 1:{let o=l.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(l,o.helper),Fe.edges.remove_node(o.node),o.helper=null;break}case 2:{let o=l.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(l,o.helper),Fe.edges.remove_node(o.node),o.helper=null;let r=null;if(!Fe.edges.empty()){let p=Fe.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){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(l,a.helper),a.helper=l}break}case 3:{let o=null;if(!Fe.edges.empty()){let a=Fe.edges.parent;for(;a.prev!=null;)a=a.prev;for(;a!=null;){let p=a.data;if(!Ge.vert_lt(p,l)){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(l,r.helper),r.helper=l}l.node=Fe.edges.insert(l),l.helper=l;break}case 4:{let o=l.prev;if(Fe.left_vertex(l)){if(o.helper==null)throw new Error("Fatal error (5): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(l,o.helper),Fe.edges.remove_node(o.node),o.helper=null,l.node=Fe.edges.insert(l),l.helper=l}else{let r=null;if(!Fe.edges.empty()){let p=Fe.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){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(l,a.helper),a.helper=l}break}}}return t}};Fe.queue=null,Fe.edges=null,Fe.sharedPPoly=null;var ml=Fe;var Ji=class Ji{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 Ji.zpp_pool==null?n=new Ji:(n=Ji.zpp_pool,Ji.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(){}};Ji.zpp_pool=null;var St=Ji;var At=class At{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(ye.poolVec2==null?t=new e.geom.Vec2:(t=ye.poolVec2,ye.poolVec2=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t==ye.nextVec2&&(ye.nextVec2=null)),t.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.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 o=t.zpp_inner;o._validate!=null&&o._validate(),i=t.zpp_inner.y==0}else i=!1;if(!i){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=s=>this.origin_invalidate(s);let n;if(ye.poolVec2==null?n=new e.geom.Vec2:(n=ye.poolVec2,ye.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==ye.nextVec2&&(ye.nextVec2=null)),n.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.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 o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){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=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(ye.poolVec2==null?s=new n.geom.Vec2:(s=ye.poolVec2,ye.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==ye.nextVec2&&(ye.nextVec2=null)),s.zpp_inner==null){let i;ae.zpp_pool==null?i=new ae:(i=ae.zpp_pool,ae.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 o=i;for(i=i.next;i!=null;){let u=i;s+=o.x*(u.y-l.y);let x=u.y*o.x-u.x*o.y;n.localCOMx+=(o.x+u.x)*x,n.localCOMy+=(o.y+u.y)*x,l=o,o=u,i=i.next}i=n.lverts.next;let r=i;s+=o.x*(r.y-l.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,l=o,o=r,i=i.next;let p=i;s+=o.x*(p.y-l.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,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,o=1/Math.sqrt(l);return s*=o,i*=o,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 o=s.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=s,s=s.next}let i=e.zpp_inner.inner,l;bs.zpp_pool==null?l=new bs:(l=bs.zpp_pool,bs.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){At._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,o=2*(s*this.dirx+i*this.diry),r=s*s+i*i-e.radius*e.radius,a=o*o-4*l*r;if(a==0){let p=-o/2*l;if((!t||r>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),h=At._allocVec2(c.nx,c.ny);return bn.getRay(h,p,r<=0,e.outer)}else return null}else{a=Math.sqrt(a),l=1/(2*l);let p=(-o-a)*l,c=(-o+a)*l;if(p>0)if(p<n&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=At._allocVec2(h.nx,h.ny);return bn.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=At._allocVec2(h.nx,h.ny);return bn.getRay(u,c,!0,e.outer)}else return null;else return null}}circlesect2(e,t,n){At._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,o=2*(s*this.dirx+i*this.diry),r=s*s+i*i-e.radius*e.radius,a=o*o-4*l*r;if(a==0){let p=-o/2*l;if((!t||r>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),h=At._allocVec2(c.nx,c.ny),u=bn.getRay(h,p,r<=0,e.outer);At._insertSorted(n,u)}}else{a=Math.sqrt(a),l=1/(2*l);let p=(-o-a)*l,c=(-o+a)*l;if(p>0&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=At._allocVec2(h.nx,h.ny),x=bn.getRay(u,p,!1,e.outer);At._insertSorted(n,x)}if(c>0&&c<=this.maxdist&&t){let h=this._circleNormal(c,e,!0),u=At._allocVec2(h.nx,h.ny),x=bn.getRay(u,c,!0,e.outer);At._insertSorted(n,x)}}}polysect(e,t,n){let s=me(),i=n,l=null,o=e.edges.head,r=!0,a=e.gverts.next,p=a,c=a.next;for(;c!=null;){let h=c,u=o.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,m=h.y-p.y,d=p.x-this.originx,y=p.y-this.originy,f=m*this.dirx-x*this.diry;if(f*f>s.Config.epsilon){f=1/f;let b=(m*d-x*y)*f;if(b>0&&b<i&&b<=this.maxdist){let P=(this.diry*d-this.dirx*y)*f;P>-s.Config.epsilon&&P<1+s.Config.epsilon&&(i=b,l=o.elt)}}}o=o.next,p=h,c=c.next}if(r){c=e.gverts.next;let h=c,u=o.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,m=h.y-p.y,d=p.x-this.originx,y=p.y-this.originy,f=m*this.dirx-x*this.diry;if(f*f>s.Config.epsilon){f=1/f;let b=(m*d-x*y)*f;if(b>0&&b<i&&b<=this.maxdist){let P=(this.diry*d-this.dirx*y)*f;P>-s.Config.epsilon&&P<1+s.Config.epsilon&&(i=b,l=o.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 m=At._allocVec2(h,u);return bn.getRay(m,i,x,e.outer)}else return null}polysect2(e,t,n){let s=me(),i=1/0,l=-1,o=null,r=null,a=e.edges.head,p=!0,c=e.gverts.next,h=c,u=c.next;for(;u!=null;){let x=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let d=x.x-h.x,y=x.y-h.y,f=h.x-this.originx,b=h.y-this.originy,P=y*this.dirx-d*this.diry;if(P*P>s.Config.epsilon){P=1/P;let k=(y*f-d*b)*P;if(k>0&&k<=this.maxdist&&(k<i||k>l)){let _=(this.diry*f-this.dirx*b)*P;_>-s.Config.epsilon&&_<1+s.Config.epsilon&&(k<i&&(i=k,o=a.elt),k>l&&(l=k,r=a.elt))}}}a=a.next,h=x,u=u.next}if(p){u=e.gverts.next;let x=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let d=x.x-h.x,y=x.y-h.y,f=h.x-this.originx,b=h.y-this.originy,P=y*this.dirx-d*this.diry;if(P*P>s.Config.epsilon){P=1/P;let k=(y*f-d*b)*P;if(k>0&&k<=this.maxdist&&(k<i||k>l)){let _=(this.diry*f-this.dirx*b)*P;_>-s.Config.epsilon&&_<1+s.Config.epsilon&&(k<i&&(i=k,o=a.elt),k>l&&(l=k,r=a.elt))}}}}if(o!=null){let x=o.gnormx,m=o.gnormy,d=x*this.dirx+m*this.diry>0;d&&(x=-x,m=-m);let y=At._allocVec2(x,m),f=bn.getRay(y,i,d,e.outer);At._insertSorted(n,f)}if(r!=null&&o!=r){let x=r.gnormx,m=r.gnormy,d=x*this.dirx+m*this.diry>0;d&&(x=-x,m=-m);let y=At._allocVec2(x,m),f=bn.getRay(y,l,d,e.outer);At._insertSorted(n,f)}}};At.internal=!1;var bl=At;var vi=class vi{constructor(){this.forced=!1;this.x=0;this.y=0;this.links=null;this.id=0;this.next=null;this.node=null;this.id=yn.ZPP_SimpleVert(),$t.zpp_pool==null?this.links=new $t:(this.links=$t.zpp_pool,$t.zpp_pool=this.links.next,this.links.next=null),this.links.lt=vi.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 vi.zpp_pool==null?n=new vi:(n=vi.zpp_pool,vi.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(){}};vi.zpp_pool=null;var Ee=vi;var Ui=class Ui{constructor(){this.left=null;this.right=null;this.vertices=null;this.id=0;this.next=null;this.prev=null;this.node=null;this.id=yn.ZPP_SimpleSeg(),$t.zpp_pool==null?this.vertices=new $t:(this.vertices=$t.zpp_pool,$t.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 Ui.zpp_pool==null?n=new Ui:(n=Ui.zpp_pool,Ui.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}};Ui.zpp_pool=null;var Vt=Ui;var Wi=class Wi{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 Wi.zpp_pool==null?t=new Wi:(t=Wi.zpp_pool,Wi.zpp_pool=t.next,t.next=null),t.vertex=e,t}free(){this.vertex=null,this.segment=this.segment2=null,this.node=null}alloc(){}};Wi.zpp_pool=null;var Me=Wi;var Ki=class{constructor(){this.sweepx=0;this.tree=null;fs.zpp_pool==null?this.tree=new fs:(this.tree=fs.zpp_pool,fs.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,o,r,a,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,o=s.x-n.x,r=s.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.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,o=l.x-i.x,r=l.y-i.y,a=n.x-i.x,p=n.y-i.y,h=(c?r*a-o*p:p*o-a*r)<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,o=s.x-n.x,r=s.y-n.y,a=l.x-n.x,p=l.y-n.y,(c?r*a-o*p:p*o-a*r)<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,o=s.x-n.x,r=s.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?r*a-o*p:p*o-a*r)<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,o=l.x-i.x,r=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let h=c?r*a-o*p:p*o-a*r;c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let u=c?r*a-o*p:p*o-a*r;return h*u>=0?h>=0:this.sweepx>=n.x}else if(i.x==l.x){c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=c?r*a-o*p:p*o-a*r;c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=c?r*a-o*p:p*o-a*r;return h*u>=0?h<0:this.sweepx<i.x}else{c=s.x<n.x,o=s.x-n.x,r=s.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;c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=(c?r*a-o*p:p*o-a*r)<0;if(h==u)return h;{c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let x=(c?r*a-o*p:p*o-a*r)>=0;c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let m=(c?r*a-o*p:p*o-a*r)>=0;if(x==m)return x;let d=(this.sweepx-n.x)/(s.x-n.x)*(s.y-n.y)+n.y,y=(this.sweepx-i.x)/(l.x-i.x)*(l.y-i.y)+i.y;return d>y}}}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,o=(i.x-n.x)*(s.y-n.y)-(s.x-n.x)*(i.y-n.y),r=(l.x-n.x)*(s.y-n.y)-(s.x-n.x)*(l.y-n.y);if(o*r>0)return!1;{let a=(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!(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,s=e.right,i=t.left,l=t.right,o=s.x-n.x,r=s.y-n.y,a=l.x-i.x,p=l.y-i.y,c=p*o-a*r;if(c==0)return null;c=1/c;let h=i.x-n.x,u=i.y-n.y,x=(p*h-a*u)*c;if(x<0||x>1)return null;let m=(r*h-o*u)*c;if(m<0||m>1)return null;let d;if(m==0||m==1||x==0||x==1){let b=m==0;if(m==1&&b)throw new Error("corner case 1a");if(m==1&&(b=!0),x==0&&b)throw new Error("corner case 1b");if(x==0&&(b=!0),x==1&&b)throw new Error("corner case 1c");d=m==0?i:m==1?l:x==0?n:s}else{let b=.5*(n.x+o*x+i.x+a*m),P=.5*(n.y+r*x+i.y+p*m),k;Ee.zpp_pool==null?k=new Ee:(k=Ee.zpp_pool,Ee.zpp_pool=k.next,k.next=null),k.x=b,k.y=P,d=k}let y;Me.zpp_pool==null?y=new Me:(y=Me.zpp_pool,Me.zpp_pool=y.next,y.next=null),y.vertex=d;let f=y;return f.type=0,f.segment=e,f.segment2=t,f}}};var de=class de{static decompose(e,t){de.sweep==null&&(de.sweep=new Ki,de.inthash=new Ti),de.vertices==null&&($t.zpp_pool==null?de.vertices=new $t:(de.vertices=$t.zpp_pool,$t.zpp_pool=de.vertices.next,de.vertices.next=null),de.vertices.lt=Ee.less_xy,de.vertices.swapped=Ee.swap_nodes),de.queue==null&&(Xn.zpp_pool==null?de.queue=new Xn:(de.queue=Xn.zpp_pool,Xn.zpp_pool=de.queue.next,de.queue.next=null),de.queue.lt=Me.less_xy,de.queue.swapped=Me.swap_nodes);let n=null,s=null,i=e,l=e;if(i!=null){let x=i;for(;;){let m=x,d=m.x,y=m.y,f;Ee.zpp_pool==null?f=new Ee:(f=Ee.zpp_pool,Ee.zpp_pool=f.next,f.next=null),f.x=d,f.y=y;let b=f,P=de.vertices.parent;for(;P!=null;)if(de.vertices.lt(b,P.data))P=P.prev;else if(de.vertices.lt(P.data,b))P=P.next;else break;let k=P;if(k!=null){let _=b;_.links.clear(),_.node=null,_.forced=!1,_.next=Ee.zpp_pool,Ee.zpp_pool=_,b=k.data}else b.node=de.vertices.insert(b);if(s!=null){let _;Me.zpp_pool==null?_=new Me:(_=Me.zpp_pool,Me.zpp_pool=_.next,_.next=null),_.vertex=s;let z=_,C;Me.zpp_pool==null?C=new Me:(C=Me.zpp_pool,Me.zpp_pool=C.next,C.next=null),C.vertex=b;let w=C,g;Me.less_xy(z,w)?(z.type=1,w.type=2,g=Vt.get(s,b)):(z.type=2,w.type=1,g=Vt.get(b,s)),z.segment=w.segment=g,de.queue.insert(z),de.queue.insert(w),s.links.insert(b),b.links.insert(s)}if(s=b,n==null&&(n=b),x=x.next,x==l)break}}let o;Me.zpp_pool==null?o=new Me:(o=Me.zpp_pool,Me.zpp_pool=o.next,o.next=null),o.vertex=s;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=Vt.get(s,n)):(r.type=2,p.type=1,c=Vt.get(n,s)),r.segment=p.segment=c,de.queue.insert(r),de.queue.insert(p),s.links.insert(n),n.links.insert(s),de.ints==null&&(Xn.zpp_pool==null?de.ints=new Xn:(de.ints=Xn.zpp_pool,Xn.zpp_pool=de.ints.next,de.ints.next=null),de.ints.lt=Me.less_xy);!de.queue.empty();){let x=de.queue.pop_front();if(de.sweep.sweepx=x.vertex.x,x.type==1){let d=x.segment;if(de.sweep.add(d),d.next!=null&&d!=null&&!(d.next.id<d.id?de.inthash.has(d.next.id,d.id):de.inthash.has(d.id,d.next.id))){let y=de.sweep.intersection(d.next,d);if(y!=null)if(y.vertex.x>=de.sweep.sweepx){let f=de.queue.parent;for(;f!=null;)if(de.queue.lt(y,f.data))f=f.prev;else if(de.queue.lt(f.data,y))f=f.next;else break;let b=f;if(b==null){let P=de.ints.parent;for(;P!=null;)if(de.ints.lt(y,P.data))P=P.prev;else if(de.ints.lt(P.data,y))P=P.next;else break;let k=P;if(k!=null){let _=y.vertex;_.links.clear(),_.node=null,_.forced=!1,_.next=Ee.zpp_pool,Ee.zpp_pool=_,y.vertex=k.data.vertex,k.data=y,de.queue.insert(y)}else de.queue.insert(y),de.ints.insert(y);if(d.next.id<d.id){let _=de.inthash,z=d.next.id,C=d.id,w;Te.zpp_pool==null?w=new Te:(w=Te.zpp_pool,Te.zpp_pool=w.next,w.next=null),w.id=z,w.di=C;let g=w;g.value=!0,_.add(g)}else{let _=de.inthash,z=d.id,C=d.next.id,w;Te.zpp_pool==null?w=new Te:(w=Te.zpp_pool,Te.zpp_pool=w.next,w.next=null),w.id=z,w.di=C;let g=w;g.value=!0,_.add(g)}}else{let P=b.data;if(P.segment!=y.segment||y.segment2!=P.segment2)throw new Error("corner case 2, shiiiit.");let k=y.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=Ee.zpp_pool,Ee.zpp_pool=k;let _=y;_.vertex=null,_.segment=_.segment2=null,_.node=null,_.next=Me.zpp_pool,Me.zpp_pool=_}}else{let f=y.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=Ee.zpp_pool,Ee.zpp_pool=f;let b=y;b.vertex=null,b.segment=b.segment2=null,b.node=null,b.next=Me.zpp_pool,Me.zpp_pool=b}}if(d!=null&&d.prev!=null&&!(d.id<d.prev.id?de.inthash.has(d.id,d.prev.id):de.inthash.has(d.prev.id,d.id))){let y=de.sweep.intersection(d,d.prev);if(y!=null)if(y.vertex.x>=de.sweep.sweepx){let f=de.queue.parent;for(;f!=null;)if(de.queue.lt(y,f.data))f=f.prev;else if(de.queue.lt(f.data,y))f=f.next;else break;let b=f;if(b==null){let P=de.ints.parent;for(;P!=null;)if(de.ints.lt(y,P.data))P=P.prev;else if(de.ints.lt(P.data,y))P=P.next;else break;let k=P;if(k!=null){let _=y.vertex;_.links.clear(),_.node=null,_.forced=!1,_.next=Ee.zpp_pool,Ee.zpp_pool=_,y.vertex=k.data.vertex,k.data=y,de.queue.insert(y)}else de.queue.insert(y),de.ints.insert(y);if(d.id<d.prev.id){let _=de.inthash,z=d.id,C=d.prev.id,w;Te.zpp_pool==null?w=new Te:(w=Te.zpp_pool,Te.zpp_pool=w.next,w.next=null),w.id=z,w.di=C;let g=w;g.value=!0,_.add(g)}else{let _=de.inthash,z=d.prev.id,C=d.id,w;Te.zpp_pool==null?w=new Te:(w=Te.zpp_pool,Te.zpp_pool=w.next,w.next=null),w.id=z,w.di=C;let g=w;g.value=!0,_.add(g)}}else{let P=b.data;if(P.segment!=y.segment||y.segment2!=P.segment2)throw new Error("corner case 2, shiiiit.");let k=y.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=Ee.zpp_pool,Ee.zpp_pool=k;let _=y;_.vertex=null,_.segment=_.segment2=null,_.node=null,_.next=Me.zpp_pool,Me.zpp_pool=_}}else{let f=y.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=Ee.zpp_pool,Ee.zpp_pool=f;let b=y;b.vertex=null,b.segment=b.segment2=null,b.node=null,b.next=Me.zpp_pool,Me.zpp_pool=b}}}else if(x.type==2){let d=x.segment;if(d.node!=null){let y=d.next,f=d.prev;de.sweep.remove(d);let b=d;if(b.left=b.right=null,b.prev=null,b.node=null,b.vertices.clear(),b.next=Vt.zpp_pool,Vt.zpp_pool=b,y!=null&&f!=null&&!(y.id<f.id?de.inthash.has(y.id,f.id):de.inthash.has(f.id,y.id))){let P=de.sweep.intersection(y,f);if(P!=null)if(P.vertex.x>=de.sweep.sweepx){let k=de.queue.parent;for(;k!=null;)if(de.queue.lt(P,k.data))k=k.prev;else if(de.queue.lt(k.data,P))k=k.next;else break;let _=k;if(_==null){let z=de.ints.parent;for(;z!=null;)if(de.ints.lt(P,z.data))z=z.prev;else if(de.ints.lt(z.data,P))z=z.next;else break;let C=z;if(C!=null){let w=P.vertex;w.links.clear(),w.node=null,w.forced=!1,w.next=Ee.zpp_pool,Ee.zpp_pool=w,P.vertex=C.data.vertex,C.data=P,de.queue.insert(P)}else de.queue.insert(P),de.ints.insert(P);if(y.id<f.id){let w=de.inthash,g=y.id,O=f.id,E;Te.zpp_pool==null?E=new Te:(E=Te.zpp_pool,Te.zpp_pool=E.next,E.next=null),E.id=g,E.di=O;let M=E;M.value=!0,w.add(M)}else{let w=de.inthash,g=f.id,O=y.id,E;Te.zpp_pool==null?E=new Te:(E=Te.zpp_pool,Te.zpp_pool=E.next,E.next=null),E.id=g,E.di=O;let M=E;M.value=!0,w.add(M)}}else{let z=_.data;if(z.segment!=P.segment||P.segment2!=z.segment2)throw new Error("corner case 2, shiiiit.");let C=P.vertex;C.links.clear(),C.node=null,C.forced=!1,C.next=Ee.zpp_pool,Ee.zpp_pool=C;let w=P;w.vertex=null,w.segment=w.segment2=null,w.node=null,w.next=Me.zpp_pool,Me.zpp_pool=w}}else{let k=P.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=Ee.zpp_pool,Ee.zpp_pool=k;let _=P;_.vertex=null,_.segment=_.segment2=null,_.node=null,_.next=Me.zpp_pool,Me.zpp_pool=_}}}}else{let d=x.vertex,y=d.node==null,f=x.segment,b=x.segment2;if(b.next!=f){let C=f;f=b,b=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,_=b.vertices.parent;for(;_!=null;)if(b.vertices.lt(d,_.data))_=_.prev;else if(b.vertices.lt(_.data,d))_=_.next;else break;let z=_==null;if(k){let C=f.vertices.insert(d),w=d==f.left?d:f.vertices.predecessor_node(C).data,g=d==f.right?d:f.vertices.successor_node(C).data;w.links.remove(g),d!=w&&w.links.insert(d),g.links.remove(w),d!=g&&g.links.insert(d),d!=w&&d.links.insert(w),d!=g&&d.links.insert(g)}if(z){let C=b.vertices.insert(d),w=d==b.left?d:b.vertices.predecessor_node(C).data,g=d==b.right?d:b.vertices.successor_node(C).data;w.links.remove(g),d!=w&&w.links.insert(d),g.links.remove(w),d!=g&&g.links.insert(d),d!=w&&d.links.insert(w),d!=g&&d.links.insert(g)}if(y&&(d.node=de.vertices.insert(d)),d.forced=!0,y){let C=f.node,w=b.node;C.data=b,w.data=f,f.node=w,b.node=C,b.next=f.next,f.next=b,f.prev=b.prev,b.prev=f,f.prev!=null&&(f.prev.next=f),b.next!=null&&(b.next.prev=b)}if(b.next!=null&&b!=null&&!(b.next.id<b.id?de.inthash.has(b.next.id,b.id):de.inthash.has(b.id,b.next.id))){let C=de.sweep.intersection(b.next,b);if(C!=null)if(C.vertex.x>=de.sweep.sweepx){let w=de.queue.parent;for(;w!=null;)if(de.queue.lt(C,w.data))w=w.prev;else if(de.queue.lt(w.data,C))w=w.next;else break;let g=w;if(g==null){let O=de.ints.parent;for(;O!=null;)if(de.ints.lt(C,O.data))O=O.prev;else if(de.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=Ee.zpp_pool,Ee.zpp_pool=M,C.vertex=E.data.vertex,E.data=C,de.queue.insert(C)}else de.queue.insert(C),de.ints.insert(C);if(b.next.id<b.id){let M=de.inthash,N=b.next.id,Z=b.id,A;Te.zpp_pool==null?A=new Te:(A=Te.zpp_pool,Te.zpp_pool=A.next,A.next=null),A.id=N,A.di=Z;let S=A;S.value=!0,M.add(S)}else{let M=de.inthash,N=b.id,Z=b.next.id,A;Te.zpp_pool==null?A=new Te:(A=Te.zpp_pool,Te.zpp_pool=A.next,A.next=null),A.id=N,A.di=Z;let S=A;S.value=!0,M.add(S)}}else{let O=g.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=Ee.zpp_pool,Ee.zpp_pool=E;let M=C;M.vertex=null,M.segment=M.segment2=null,M.node=null,M.next=Me.zpp_pool,Me.zpp_pool=M}}else{let w=C.vertex;w.links.clear(),w.node=null,w.forced=!1,w.next=Ee.zpp_pool,Ee.zpp_pool=w;let g=C;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?de.inthash.has(f.id,f.prev.id):de.inthash.has(f.prev.id,f.id))){let C=de.sweep.intersection(f,f.prev);if(C!=null)if(C.vertex.x>=de.sweep.sweepx){let w=de.queue.parent;for(;w!=null;)if(de.queue.lt(C,w.data))w=w.prev;else if(de.queue.lt(w.data,C))w=w.next;else break;let g=w;if(g==null){let O=de.ints.parent;for(;O!=null;)if(de.ints.lt(C,O.data))O=O.prev;else if(de.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=Ee.zpp_pool,Ee.zpp_pool=M,C.vertex=E.data.vertex,E.data=C,de.queue.insert(C)}else de.queue.insert(C),de.ints.insert(C);if(f.id<f.prev.id){let M=de.inthash,N=f.id,Z=f.prev.id,A;Te.zpp_pool==null?A=new Te:(A=Te.zpp_pool,Te.zpp_pool=A.next,A.next=null),A.id=N,A.di=Z;let S=A;S.value=!0,M.add(S)}else{let M=de.inthash,N=f.prev.id,Z=f.id,A;Te.zpp_pool==null?A=new Te:(A=Te.zpp_pool,Te.zpp_pool=A.next,A.next=null),A.id=N,A.di=Z;let S=A;S.value=!0,M.add(S)}}else{let O=g.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=Ee.zpp_pool,Ee.zpp_pool=E;let M=C;M.vertex=null,M.segment=M.segment2=null,M.node=null,M.next=Me.zpp_pool,Me.zpp_pool=M}}else{let w=C.vertex;w.links.clear(),w.node=null,w.forced=!1,w.next=Ee.zpp_pool,Ee.zpp_pool=w;let g=C;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Me.zpp_pool,Me.zpp_pool=g}}de.ints.remove(x)}let m=x;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Me.zpp_pool,Me.zpp_pool=m}let h=0,u=de.inthash.table.length;for(;h<u;){let x=h++,m=de.inthash.table[x];if(m!=null){for(;m!=null;){let d=m.hnext;m.hnext=null;let y=m;y.next=Te.zpp_pool,Te.zpp_pool=y,m=d}de.inthash.table[x]=null}}for(t==null&&(t=new ms);!de.vertices.empty();)de.clip_polygon(de.vertices,t);return t}static clip_polygon(e,t){let n=null,s=e.first(),i=s,l=s.links.parent,o=l.prev==null?l.next:l.prev,r=l.data,a=o.data,p=s.x-r.x,c=s.y-r.y,h=a.x-s.x;(a.y-s.y)*p-h*c<0&&(a=r);let x=s.x,m=s.y,d;ge.zpp_pool==null?d=new ge:(d=ge.zpp_pool,ge.zpp_pool=d.next,d.next=null),d.forced=!1,d.x=x,d.y=m;let y=d;if(n==null)y.prev=y.next=y;else{let b=n,P=b.next;y.prev=b,y.next=P,P.prev=y,b.next=y}for(n=y,n.forced=s.forced;;){if(s.links.remove(a),a.links.remove(s),a==i){if(s.links.empty()){e.remove(s);let z=s;z.links.clear(),z.node=null,z.forced=!1,z.next=Ee.zpp_pool,Ee.zpp_pool=z}break}let b=a.x,P=a.y,k;ge.zpp_pool==null?k=new ge:(k=ge.zpp_pool,ge.zpp_pool=k.next,k.next=null),k.forced=!1,k.x=b,k.y=P;let _=k;if(n==null)_.prev=_.next=_;else{let z=n,C=z.next;_.prev=z,_.next=C,C.prev=_,z.next=_}if(n=_,n.forced=a.forced,a.links.singular()){if(s.links.empty()){e.remove(s);let z=s;z.links.clear(),z.node=null,z.forced=!1,z.next=Ee.zpp_pool,Ee.zpp_pool=z}s=a,a=a.links.parent.data}else{let z=null,C=0;if(!a.links.empty()){let w=a.links.parent;for(;w.prev!=null;)w=w.prev;for(;w!=null;){let g=w.data;if(z==null){z=g;let O=a.x-s.x,E=a.y-s.y,M=g.x-a.x;C=(g.y-a.y)*O-M*E}else{let O=a.x-s.x,E=a.y-s.y,M=g.x-a.x,Z=(g.y-a.y)*O-M*E;if(Z>0&&C<=0)z=g,C=Z;else if(C*Z>=0){let A=a.x-g.x,S=a.y-g.y,L=z.x-a.x;(z.y-a.y)*A-L*S>0&&(z=g,C=Z)}}if(w.next!=null)for(w=w.next;w.prev!=null;)w=w.prev;else{for(;w.parent!=null&&w==w.parent.next;)w=w.parent;w=w.parent}}}if(s.links.empty()){e.remove(s);let w=s;w.links.clear(),w.node=null,w.forced=!1,w.next=Ee.zpp_pool,Ee.zpp_pool=w}s=a,a=z}}e.remove(i);let f=i;f.links.clear(),f.node=null,f.forced=!1,f.next=Ee.zpp_pool,Ee.zpp_pool=f,t.add(n)}static isSimple(e){de.sweep==null&&(de.sweep=new Ki,de.inthash=new Ti);let t=de.list_vertices;t==null&&(t=de.list_vertices=new Tl);let n=e,s=e;if(n!=null){let d=n;for(;;){let y=d,f=y.x,b=y.y,P;if(Ee.zpp_pool==null?P=new Ee:(P=Ee.zpp_pool,Ee.zpp_pool=P.next,P.next=null),P.x=f,P.y=b,t.add(P),d=d.next,d==s)break}}let i=de.list_queue;i==null&&(i=de.list_queue=new Ll);let l=t.head,o=l.elt;for(l=l.next;l!=null;){let d=l.elt,y;Me.zpp_pool==null?y=new Me:(y=Me.zpp_pool,Me.zpp_pool=y.next,y.next=null),y.vertex=o;let f=i.add(y),b;Me.zpp_pool==null?b=new Me:(b=Me.zpp_pool,Me.zpp_pool=b.next,b.next=null),b.vertex=d;let P=i.add(b),k;Me.less_xy(f,P)?(f.type=1,P.type=2,k=Vt.get(o,d)):(f.type=2,P.type=1,k=Vt.get(d,o)),f.segment=P.segment=k,o=d,l=l.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=i.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 h=i.add(c),u;Me.less_xy(p,h)?(p.type=1,h.type=2,u=Vt.get(o,r)):(p.type=2,h.type=1,u=Vt.get(r,o)),p.segment=h.segment=u;let x=i;if(x.head!=null&&x.head.next!=null){let d=x.head,y,f,b,P,k=1,_,z,C;for(;;){for(_=0,f=d,d=null,y=null;f!=null;){for(++_,b=f,z=0,C=k;b!=null&&z<k;)++z,b=b.next;for(;z>0||C>0&&b!=null;)z==0?(P=b,b=b.next,--C):C==0||b==null||Me.less_xy(f.elt,b.elt)?(P=f,f=f.next,--z):(P=b,b=b.next,--C),y!=null?y.next=P:d=P,y=P;f=b}if(y.next=null,k<<=1,!(_>1))break}x.head=d,x.modified=!0,x.pushmod=!0}let m=!0;for(;i.head!=null;){let d=i.pop_unsafe(),y=d.segment;if(d.type==1){if(de.sweep.add(y),de.sweep.intersect(y,y.next)||de.sweep.intersect(y,y.prev)){m=!1;break}}else if(d.type==2){if(de.sweep.intersect(y.prev,y.next)){m=!1;break}de.sweep.remove(y);let b=y;b.left=b.right=null,b.prev=null,b.node=null,b.vertices.clear(),b.next=Vt.zpp_pool,Vt.zpp_pool=b}let f=d;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Me.zpp_pool,Me.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=Vt.zpp_pool,Vt.zpp_pool=f}let y=d;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Me.zpp_pool,Me.zpp_pool=y}for(de.sweep.clear();t.head!=null;){let d=t.pop_unsafe();d.links.clear(),d.node=null,d.forced=!1,d.next=Ee.zpp_pool,Ee.zpp_pool=d}return m}};de.sweep=null,de.inthash=null,de.vertices=null,de.queue=null,de.ints=null,de.list_vertices=null,de.list_queue=null;var fl=de;var Yi=class Yi{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 Yi.zpp_pool==null?t=new Yi:(t=Yi.zpp_pool,Yi.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t.flag=!1,t}free(){}alloc(){}};Yi.zpp_pool=null;var gn=Yi;var Xi=class Xi{constructor(){this.next=null;this.min=null;this.max=null}static get(e,t){let n;return Xi.zpp_pool==null?n=new Xi:(n=Xi.zpp_pool,Xi.zpp_pool=n.next,n.next=null),n.min=e,n.max=t,n}free(){this.min=null,this.max=null}alloc(){}};Xi.zpp_pool=null;var Le=Xi;var It=class It{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,o=e.y-t.y;if(s*s+i*i==0)return l*l+o*o;{let a=(l*s+o*i)/(s*s+i*i);if(a<=0)return l*l+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 l-=s*p,o-=i*p,l*l+o*o}}}static simplify(e,t){let n=null,s=null,i=null;t*=t,It.stack==null&&(It.stack=new jl);let l=null,o=null,r=e;for(;;){let p;gn.zpp_pool==null?p=new gn:(p=gn.zpp_pool,gn.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,l!=null){let u=It.stack,x;Le.zpp_pool==null?x=new Le:(x=Le.zpp_pool,Le.zpp_pool=x.next,x.next=null),x.min=l,x.max=c,u.add(x)}else o=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)),r=r.next,r==e)break}if(It.stack.head==null)if(o==null){s.flag=i.flag=!0;let p=It.stack,c;Le.zpp_pool==null?c=new Le:(c=Le.zpp_pool,Le.zpp_pool=c.next,c.next=null),c.min=s,c.max=i,p.add(c);let h=It.stack,u;Le.zpp_pool==null?u=new Le:(u=Le.zpp_pool,Le.zpp_pool=u.next,u.next=null),u.min=i,u.max=s,h.add(u)}else{let p=s.x-o.x+(s.y-o.y);p<0&&(p=-p);let c=i.x-o.x+(i.y-o.y);if(c<0&&(c=-c),p>c){s.flag=o.flag=!0;let h=It.stack,u;Le.zpp_pool==null?u=new Le:(u=Le.zpp_pool,Le.zpp_pool=u.next,u.next=null),u.min=s,u.max=o,h.add(u);let x=It.stack,m;Le.zpp_pool==null?m=new Le:(m=Le.zpp_pool,Le.zpp_pool=m.next,m.next=null),m.min=o,m.max=s,x.add(m)}else{i.flag=o.flag=!0;let h=It.stack,u;Le.zpp_pool==null?u=new Le:(u=Le.zpp_pool,Le.zpp_pool=u.next,u.next=null),u.min=i,u.max=o,h.add(u);let x=It.stack,m;Le.zpp_pool==null?m=new Le:(m=Le.zpp_pool,Le.zpp_pool=m.next,m.next=null),m.min=o,m.max=i,x.add(m)}}else{let p=It.stack,c;Le.zpp_pool==null?c=new Le:(c=Le.zpp_pool,Le.zpp_pool=c.next,c.next=null),c.min=l,c.max=o,p.add(c)}for(;It.stack.head!=null;){let p=It.stack.pop_unsafe(),c=p.min,h=p.max,u=p;u.min=u.max=null,u.next=Le.zpp_pool,Le.zpp_pool=u;let x=t,m=null,d=c.next;for(;d!=h;){let y=It.distance(d,c,h);y>x&&(x=y,m=d),d=d.next}if(m!=null){m.flag=!0;let y=It.stack,f;Le.zpp_pool==null?f=new Le:(f=Le.zpp_pool,Le.zpp_pool=f.next,f.next=null),f.min=c,f.max=m,y.add(f);let b=It.stack,P;Le.zpp_pool==null?P=new Le:(P=Le.zpp_pool,Le.zpp_pool=P.next,P.next=null),P.min=m,P.max=h,b.add(P)}}let a=null;for(;n!=null;){if(n.flag){let p=n.x,c=n.y,h;ge.zpp_pool==null?h=new ge:(h=ge.zpp_pool,ge.zpp_pool=h.next,h.next=null),h.forced=!1,h.x=p,h.y=c;let u=h;a==null?u.prev=u.next=u:(u.prev=a,u.next=a.next,a.next.prev=u,a.next=u),a=u,a.forced=n.forced}if(n!=null&&n.prev==n)n.next=n.prev=null,n.next=gn.zpp_pool,gn.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=gn.zpp_pool,gn.zpp_pool=n,n=p}}return a}};It.stack=null;var zl=It;var Ws=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=ae.get(0,0),this.c2=ae.get(0,0),this.axis=ae.get(0,0)}alloc(){this.failed=!1,this.s1=this.s2=null,this.arbiter=null}free(){}};Ws.zpp_pool=null;function at(v){return v.type===0||v.type===2}function Dt(v){return v.type===0?v.circle.radius:v.capsule.halfLength+v.capsule.radius}var Cn=class{static dynamicSweep(e,t,n,s,i){let l=me();i==null&&(i=!1);let o=e.s1,r=e.s2,a=o.body,p=r.body,c=0,h=0;c=p.velx-a.velx,h=p.vely-a.vely;let u=a.angvel;u<0&&(u=-u);let x=p.angvel;x<0&&(x=-x);let m=o.sweepCoef*u+r.sweepCoef*x;if(!i&&!e.kinematic&&c*c+h*h<l.Config.dynamicSweepLinearThreshold*l.Config.dynamicSweepLinearThreshold&&m<l.Config.dynamicSweepAngularThreshold){e.toi=-1,e.failed=!0;return}let d=e.c1,y=e.c2,f=e.axis,b=n,P=0;for(;;){let Z=b*t,A=Z-a.sweepTime;if(A!=0){a.sweepTime=Z;let Y=A;if(a.posx+=a.velx*Y,a.posy+=a.vely*Y,a.angvel!=0){let X=a.sweep_angvel*A;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,J=1-.5*ee,F=1-ee*ee/8,D=(J*a.axisx+X*a.axisy)*F;a.axisy=(J*a.axisy-X*a.axisx)*F,a.axisx=D}}}if(o.type==0||o.type===2)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 Q=ee,W=X;X=X.next,Q.x=a.posx+(a.axisy*W.x-a.axisx*W.y),Q.y=a.posy+(W.x*a.axisx+W.y*a.axisy),ee=ee.next}let J=Y.edges.head,F=Y.gverts.next,D=F;for(F=F.next;F!=null;){let Q=F,W=J.elt;J=J.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=D.y*W.gnormx-D.x*W.gnormy,W.tp1=Q.y*W.gnormx-Q.x*W.gnormy,D=Q,F=F.next}let I=Y.gverts.next,U=J.elt;J=J.next,U.gnormx=a.axisy*U.lnormx-a.axisx*U.lnormy,U.gnormy=U.lnormx*a.axisx+U.lnormy*a.axisy,U.gprojection=a.posx*U.gnormx+a.posy*U.gnormy+U.lprojection,U.tp0=D.y*U.gnormx-D.x*U.gnormy,U.tp1=I.y*U.gnormx-I.x*U.gnormy}let S=b*t,L=S-p.sweepTime;if(L!=0){p.sweepTime=S;let Y=L;if(p.posx+=p.velx*Y,p.posy+=p.vely*Y,p.angvel!=0){let X=p.sweep_angvel*L;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,F=1-ee*ee/8,D=(J*p.axisx+X*p.axisy)*F;p.axisy=(J*p.axisy-X*p.axisx)*F,p.axisx=D}}}if(r.type==0||r.type===2)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 Q=ee,W=X;X=X.next,Q.x=p.posx+(p.axisy*W.x-p.axisx*W.y),Q.y=p.posy+(W.x*p.axisx+W.y*p.axisy),ee=ee.next}let J=Y.edges.head,F=Y.gverts.next,D=F;for(F=F.next;F!=null;){let Q=F,W=J.elt;J=J.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=D.y*W.gnormx-D.x*W.gnormy,W.tp1=Q.y*W.gnormx-Q.x*W.gnormy,D=Q,F=F.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=D.y*U.gnormx-D.x*U.gnormy,U.tp1=I.y*U.gnormx-I.x*U.gnormy}let T=o,G=r,q=d,R=y;var k;if(at(T)&&at(G)){let Y=T.circle||T.capsule,X=G.circle||G.capsule,ee=Dt(T),J=Dt(G);var _;let F=0,D=0;F=X.worldCOMx-Y.worldCOMx,D=X.worldCOMy-Y.worldCOMy;let I=Math.sqrt(F*F+D*D);if(_=I-(ee+J),_<1e100){if(I==0)F=1,D=0;else{let W=1/I;F*=W,D*=W}let U=ee;q.x=Y.worldCOMx+F*U,q.y=Y.worldCOMy+D*U;let Q=-J;R.x=X.worldCOMx+F*Q,R.y=X.worldCOMy+D*Q,f.x=F,f.y=D}k=_}else{let Y=!1;if(at(T)&&G.type==1){let X=T;T=G,G=X;let ee=q;q=R,R=ee,Y=!0}if(T.type==1&&at(G)){let X=T.polygon,ee=G.circle||G.capsule,J=Dt(G),F=-1e100,D=null,I=X.edges.head;for(;I!=null;){let U=I.elt,Q=U.gnormx*ee.worldCOMx+U.gnormy*ee.worldCOMy-U.gprojection-J;if(Q>1e100){F=Q;break}Q>0?Q>F&&(F=Q,D=U):F<0&&Q>F&&(F=Q,D=U),I=I.next}if(F<1e100){let U=D.gp0,Q=D.gp1,W=ee.worldCOMy*D.gnormx-ee.worldCOMx*D.gnormy;if(W<=U.y*D.gnormx-U.x*D.gnormy){let ie=0,oe=0;ie=ee.worldCOMx-U.x,oe=ee.worldCOMy-U.y;let se=Math.sqrt(ie*ie+oe*oe);if(F=se-J,F<1e100){if(se==0)ie=1,oe=0;else{let le=1/se;ie*=le,oe*=le}let ne=0;q.x=U.x+ie*ne,q.y=U.y+oe*ne;let re=-J;R.x=ee.worldCOMx+ie*re,R.y=ee.worldCOMy+oe*re,f.x=ie,f.y=oe}}else if(W>=Q.y*D.gnormx-Q.x*D.gnormy){let ie=0,oe=0;ie=ee.worldCOMx-Q.x,oe=ee.worldCOMy-Q.y;let se=Math.sqrt(ie*ie+oe*oe);if(F=se-J,F<1e100){if(se==0)ie=1,oe=0;else{let le=1/se;ie*=le,oe*=le}let ne=0;q.x=Q.x+ie*ne,q.y=Q.y+oe*ne;let re=-J;R.x=ee.worldCOMx+ie*re,R.y=ee.worldCOMy+oe*re,f.x=ie,f.y=oe}}else{let ie=-J;R.x=ee.worldCOMx+D.gnormx*ie,R.y=ee.worldCOMy+D.gnormy*ie;let oe=-F;q.x=R.x+D.gnormx*oe,q.y=R.y+D.gnormy*oe,f.x=D.gnormx,f.y=D.gnormy}}Y&&(f.x=-f.x,f.y=-f.y),k=F}else{let X=T.polygon,ee=G.polygon,J=-1e100,F=null,D=null,I=0,U=X.edges.head;for(;U!=null;){let Q=U.elt,W=1e100,ie=ee.gverts.next;for(;ie!=null;){let oe=ie,se=Q.gnormx*oe.x+Q.gnormy*oe.y;se<W&&(W=se),ie=ie.next}if(W-=Q.gprojection,W>1e100){J=W;break}W>0?W>J&&(J=W,F=Q,I=1):J<0&&W>J&&(J=W,F=Q,I=1),U=U.next}if(J<1e100){let Q=ee.edges.head;for(;Q!=null;){let W=Q.elt,ie=1e100,oe=X.gverts.next;for(;oe!=null;){let se=oe,ne=W.gnormx*se.x+W.gnormy*se.y;ne<ie&&(ie=ne),oe=oe.next}if(ie-=W.gprojection,ie>1e100){J=ie;break}ie>0?ie>J&&(J=ie,D=W,I=2):J<0&&ie>J&&(J=ie,D=W,I=2),Q=Q.next}if(J<1e100){var z,C,w;if(I==1)z=X,C=ee,w=F;else{z=ee,C=X,w=D;let se=q;q=R,R=se,Y=!Y}let W=null,ie=1e100,oe=C.edges.head;for(;oe!=null;){let se=oe.elt,ne=w.gnormx*se.gnormx+w.gnormy*se.gnormy;ne<ie&&(ie=ne,W=se),oe=oe.next}if(Y?(f.x=-w.gnormx,f.y=-w.gnormy):(f.x=w.gnormx,f.y=w.gnormy),J>=0){let se=w.gp0,ne=w.gp1,re=W.gp0,le=W.gp1,he=0,pe=0,ce=0,te=0;he=ne.x-se.x,pe=ne.y-se.y,ce=le.x-re.x,te=le.y-re.y;let ue=1/(he*he+pe*pe),xe=1/(ce*ce+te*te),_e=-(he*(se.x-re.x)+pe*(se.y-re.y))*ue,ve=-(he*(se.x-le.x)+pe*(se.y-le.y))*ue,Se=-(ce*(re.x-se.x)+te*(re.y-se.y))*xe,Ve=-(ce*(re.x-ne.x)+te*(re.y-ne.y))*xe;_e<0?_e=0:_e>1&&(_e=1),ve<0?ve=0:ve>1&&(ve=1),Se<0?Se=0:Se>1&&(Se=1),Ve<0?Ve=0:Ve>1&&(Ve=1);let Ke=0,Xe=0,He=_e;Ke=se.x+he*He,Xe=se.y+pe*He;let Re=0,bt=0,vt=ve;Re=se.x+he*vt,bt=se.y+pe*vt;let pt=0,ct=0,rt=Se;pt=re.x+ce*rt,ct=re.y+te*rt;let Ye=0,ft=0,jt=Ve;Ye=re.x+ce*jt,ft=re.y+te*jt;let Gt=0,kt=0;Gt=Ke-re.x,kt=Xe-re.y;let Et=Gt*Gt+kt*kt,zn=0,Yt=0;zn=Re-le.x,Yt=bt-le.y;let xn=zn*zn+Yt*Yt,on=0,dn=0;on=pt-se.x,dn=ct-se.y;let Xt=on*on+dn*dn,Pn=0,Ht=0;Pn=Ye-ne.x,Ht=ft-ne.y;let _n=Pn*Pn+Ht*Ht,qt=0,Qt=0,rn=null;Et<xn?(qt=Ke,Qt=Xe,rn=re):(qt=Re,Qt=bt,rn=le,Et=xn);let li=0,Gn=0,Vn=null;if(Xt<_n?(li=pt,Gn=ct,Vn=se):(li=Ye,Gn=ft,Vn=ne,Xt=_n),Et<Xt?(q.x=qt,q.y=Qt,R.x=rn.x,R.y=rn.y,J=Math.sqrt(Et)):(R.x=li,R.y=Gn,q.x=Vn.x,q.y=Vn.y,J=Math.sqrt(Xt)),J!=0){f.x=R.x-q.x,f.y=R.y-q.y;let In=1/J;f.x*=In,f.y*=In,Y&&(f.x=-f.x,f.y=-f.y)}k=J}else{let se=0,ne=0;se=W.gp0.x,ne=W.gp0.y;let re=0,le=0;re=W.gp1.x,le=W.gp1.y;let he=0,pe=0;he=re-se,pe=le-ne;let ce=w.gnormy*se-w.gnormx*ne,te=w.gnormy*re-w.gnormx*le,ue=1/(te-ce),xe=(-w.tp1-ce)*ue;if(xe>l.Config.epsilon){let Ve=xe;se+=he*Ve,ne+=pe*Ve}let _e=(-w.tp0-te)*ue;if(_e<-l.Config.epsilon){let Ve=_e;re+=he*Ve,le+=pe*Ve}let ve=se*w.gnormx+ne*w.gnormy-w.gprojection,Se=re*w.gnormx+le*w.gnormy-w.gprojection;if(ve<Se){R.x=se,R.y=ne;let Ve=-ve;q.x=R.x+w.gnormx*Ve,q.y=R.y+w.gnormy*Ve,k=ve}else{R.x=re,R.y=le;let Ve=-Se;q.x=R.x+w.gnormx*Ve,q.y=R.y+w.gnormy*Ve,k=Se}}}else k=1e100}else k=1e100}}let j=k+s,V=c*f.x+h*f.y;if(j<l.Config.distanceThresholdCCD){if(i)break;let Y=0,X=0;Y=d.x-a.posx,X=d.y-a.posy;let ee=0,J=0;ee=y.x-p.posx,J=y.y-p.posy;let F=V-a.sweep_angvel*(f.y*Y-f.x*X)+p.sweep_angvel*(f.y*ee-f.x*J);if(F>0&&(e.slipped=!0),F<=0||j<l.Config.distanceThresholdCCD*.5)break}let K=(m-V)*t;if(K<=0){b=-1;break}let $=j/K;if($<1e-6&&($=1e-6),b+=$,b>=1){b=1;let Y=b*t,X=Y-a.sweepTime;if(X!=0){a.sweepTime=Y;let ie=X;if(a.posx+=a.velx*ie,a.posy+=a.vely*ie,a.angvel!=0){let oe=a.sweep_angvel*X;if(a.rot+=oe,oe*oe>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let se=oe*oe,ne=1-.5*se,re=1-se*se/8,le=(ne*a.axisx+oe*a.axisy)*re;a.axisy=(ne*a.axisy-oe*a.axisx)*re,a.axisx=le}}}if(o.type==0||o.type===2)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 ie=o.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ce=se,te=oe;oe=oe.next,ce.x=a.posx+(a.axisy*te.x-a.axisx*te.y),ce.y=a.posy+(te.x*a.axisx+te.y*a.axisy),se=se.next}let ne=ie.edges.head,re=ie.gverts.next,le=re;for(re=re.next;re!=null;){let ce=re,te=ne.elt;ne=ne.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=le.y*te.gnormx-le.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,le=ce,re=re.next}let he=ie.gverts.next,pe=ne.elt;ne=ne.next,pe.gnormx=a.axisy*pe.lnormx-a.axisx*pe.lnormy,pe.gnormy=pe.lnormx*a.axisx+pe.lnormy*a.axisy,pe.gprojection=a.posx*pe.gnormx+a.posy*pe.gnormy+pe.lprojection,pe.tp0=le.y*pe.gnormx-le.x*pe.gnormy,pe.tp1=he.y*pe.gnormx-he.x*pe.gnormy}let ee=b*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 oe=p.sweep_angvel*J;if(p.rot+=oe,oe*oe>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let se=oe*oe,ne=1-.5*se,re=1-se*se/8,le=(ne*p.axisx+oe*p.axisy)*re;p.axisy=(ne*p.axisy-oe*p.axisx)*re,p.axisx=le}}}if(r.type==0||r.type===2)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 ie=r.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ce=se,te=oe;oe=oe.next,ce.x=p.posx+(p.axisy*te.x-p.axisx*te.y),ce.y=p.posy+(te.x*p.axisx+te.y*p.axisy),se=se.next}let ne=ie.edges.head,re=ie.gverts.next,le=re;for(re=re.next;re!=null;){let ce=re,te=ne.elt;ne=ne.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=le.y*te.gnormx-le.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,le=ce,re=re.next}let he=ie.gverts.next,pe=ne.elt;ne=ne.next,pe.gnormx=p.axisy*pe.lnormx-p.axisx*pe.lnormy,pe.gnormy=pe.lnormx*p.axisx+pe.lnormy*p.axisy,pe.gprojection=p.posx*pe.gnormx+p.posy*pe.gnormy+pe.lprojection,pe.tp0=le.y*pe.gnormx-le.x*pe.gnormy,pe.tp1=he.y*pe.gnormx-he.x*pe.gnormy}let F=o,D=r,I=d,U=y;var g;if(at(F)&&at(D)){let ie=F.circle||F.capsule,oe=D.circle||D.capsule,se=Dt(F),ne=Dt(D);var O;let re=0,le=0;re=oe.worldCOMx-ie.worldCOMx,le=oe.worldCOMy-ie.worldCOMy;let he=Math.sqrt(re*re+le*le);if(O=he-(se+ne),O<1e100){if(he==0)re=1,le=0;else{let te=1/he;re*=te,le*=te}let pe=se;I.x=ie.worldCOMx+re*pe,I.y=ie.worldCOMy+le*pe;let ce=-ne;U.x=oe.worldCOMx+re*ce,U.y=oe.worldCOMy+le*ce,f.x=re,f.y=le}g=O}else{let ie=!1;if(at(F)&&D.type==1){let oe=F;F=D,D=oe;let se=I;I=U,U=se,ie=!0}if(F.type==1&&at(D)){let oe=F.polygon,se=D.circle||D.capsule,ne=Dt(D),re=-1e100,le=null,he=oe.edges.head;for(;he!=null;){let pe=he.elt,ce=pe.gnormx*se.worldCOMx+pe.gnormy*se.worldCOMy-pe.gprojection-ne;if(ce>1e100){re=ce;break}ce>0?ce>re&&(re=ce,le=pe):re<0&&ce>re&&(re=ce,le=pe),he=he.next}if(re<1e100){let pe=le.gp0,ce=le.gp1,te=se.worldCOMy*le.gnormx-se.worldCOMx*le.gnormy;if(te<=pe.y*le.gnormx-pe.x*le.gnormy){let ue=0,xe=0;ue=se.worldCOMx-pe.x,xe=se.worldCOMy-pe.y;let _e=Math.sqrt(ue*ue+xe*xe);if(re=_e-ne,re<1e100){if(_e==0)ue=1,xe=0;else{let Ve=1/_e;ue*=Ve,xe*=Ve}let ve=0;I.x=pe.x+ue*ve,I.y=pe.y+xe*ve;let Se=-ne;U.x=se.worldCOMx+ue*Se,U.y=se.worldCOMy+xe*Se,f.x=ue,f.y=xe}}else if(te>=ce.y*le.gnormx-ce.x*le.gnormy){let ue=0,xe=0;ue=se.worldCOMx-ce.x,xe=se.worldCOMy-ce.y;let _e=Math.sqrt(ue*ue+xe*xe);if(re=_e-ne,re<1e100){if(_e==0)ue=1,xe=0;else{let Ve=1/_e;ue*=Ve,xe*=Ve}let ve=0;I.x=ce.x+ue*ve,I.y=ce.y+xe*ve;let Se=-ne;U.x=se.worldCOMx+ue*Se,U.y=se.worldCOMy+xe*Se,f.x=ue,f.y=xe}}else{let ue=-ne;U.x=se.worldCOMx+le.gnormx*ue,U.y=se.worldCOMy+le.gnormy*ue;let xe=-re;I.x=U.x+le.gnormx*xe,I.y=U.y+le.gnormy*xe,f.x=le.gnormx,f.y=le.gnormy}}ie&&(f.x=-f.x,f.y=-f.y),g=re}else{let oe=F.polygon,se=D.polygon,ne=-1e100,re=null,le=null,he=0,pe=oe.edges.head;for(;pe!=null;){let ce=pe.elt,te=1e100,ue=se.gverts.next;for(;ue!=null;){let xe=ue,_e=ce.gnormx*xe.x+ce.gnormy*xe.y;_e<te&&(te=_e),ue=ue.next}if(te-=ce.gprojection,te>1e100){ne=te;break}te>0?te>ne&&(ne=te,re=ce,he=1):ne<0&&te>ne&&(ne=te,re=ce,he=1),pe=pe.next}if(ne<1e100){let ce=se.edges.head;for(;ce!=null;){let te=ce.elt,ue=1e100,xe=oe.gverts.next;for(;xe!=null;){let _e=xe,ve=te.gnormx*_e.x+te.gnormy*_e.y;ve<ue&&(ue=ve),xe=xe.next}if(ue-=te.gprojection,ue>1e100){ne=ue;break}ue>0?ue>ne&&(ne=ue,le=te,he=2):ne<0&&ue>ne&&(ne=ue,le=te,he=2),ce=ce.next}if(ne<1e100){var E,M,N;if(he==1)E=oe,M=se,N=re;else{E=se,M=oe,N=le;let _e=I;I=U,U=_e,ie=!ie}let te=null,ue=1e100,xe=M.edges.head;for(;xe!=null;){let _e=xe.elt,ve=N.gnormx*_e.gnormx+N.gnormy*_e.gnormy;ve<ue&&(ue=ve,te=_e),xe=xe.next}if(ie?(f.x=-N.gnormx,f.y=-N.gnormy):(f.x=N.gnormx,f.y=N.gnormy),ne>=0){let _e=N.gp0,ve=N.gp1,Se=te.gp0,Ve=te.gp1,Ke=0,Xe=0,He=0,Re=0;Ke=ve.x-_e.x,Xe=ve.y-_e.y,He=Ve.x-Se.x,Re=Ve.y-Se.y;let bt=1/(Ke*Ke+Xe*Xe),vt=1/(He*He+Re*Re),pt=-(Ke*(_e.x-Se.x)+Xe*(_e.y-Se.y))*bt,ct=-(Ke*(_e.x-Ve.x)+Xe*(_e.y-Ve.y))*bt,rt=-(He*(Se.x-_e.x)+Re*(Se.y-_e.y))*vt,Ye=-(He*(Se.x-ve.x)+Re*(Se.y-ve.y))*vt;pt<0?pt=0:pt>1&&(pt=1),ct<0?ct=0:ct>1&&(ct=1),rt<0?rt=0:rt>1&&(rt=1),Ye<0?Ye=0:Ye>1&&(Ye=1);let ft=0,jt=0,Gt=pt;ft=_e.x+Ke*Gt,jt=_e.y+Xe*Gt;let kt=0,Et=0,zn=ct;kt=_e.x+Ke*zn,Et=_e.y+Xe*zn;let Yt=0,xn=0,on=rt;Yt=Se.x+He*on,xn=Se.y+Re*on;let dn=0,Xt=0,Pn=Ye;dn=Se.x+He*Pn,Xt=Se.y+Re*Pn;let Ht=0,_n=0;Ht=ft-Se.x,_n=jt-Se.y;let qt=Ht*Ht+_n*_n,Qt=0,rn=0;Qt=kt-Ve.x,rn=Et-Ve.y;let li=Qt*Qt+rn*rn,Gn=0,Vn=0;Gn=Yt-_e.x,Vn=xn-_e.y;let In=Gn*Gn+Vn*Vn,Si=0,Ai=0;Si=dn-ve.x,Ai=Xt-ve.y;let Vi=Si*Si+Ai*Ai,xs=0,Al=0,ol=null;qt<li?(xs=ft,Al=jt,ol=Se):(xs=kt,Al=Et,ol=Ve,qt=li);let Vl=0,Il=0,rl=null;if(In<Vi?(Vl=Yt,Il=xn,rl=_e):(Vl=dn,Il=Xt,rl=ve,In=Vi),qt<In?(I.x=xs,I.y=Al,U.x=ol.x,U.y=ol.y,ne=Math.sqrt(qt)):(U.x=Vl,U.y=Il,I.x=rl.x,I.y=rl.y,ne=Math.sqrt(In)),ne!=0){f.x=U.x-I.x,f.y=U.y-I.y;let Wl=1/ne;f.x*=Wl,f.y*=Wl,ie&&(f.x=-f.x,f.y=-f.y)}g=ne}else{let _e=0,ve=0;_e=te.gp0.x,ve=te.gp0.y;let Se=0,Ve=0;Se=te.gp1.x,Ve=te.gp1.y;let Ke=0,Xe=0;Ke=Se-_e,Xe=Ve-ve;let He=N.gnormy*_e-N.gnormx*ve,Re=N.gnormy*Se-N.gnormx*Ve,bt=1/(Re-He),vt=(-N.tp1-He)*bt;if(vt>l.Config.epsilon){let Ye=vt;_e+=Ke*Ye,ve+=Xe*Ye}let pt=(-N.tp0-Re)*bt;if(pt<-l.Config.epsilon){let Ye=pt;Se+=Ke*Ye,Ve+=Xe*Ye}let ct=_e*N.gnormx+ve*N.gnormy-N.gprojection,rt=Se*N.gnormx+Ve*N.gnormy-N.gprojection;if(ct<rt){U.x=_e,U.y=ve;let Ye=-ct;I.x=U.x+N.gnormx*Ye,I.y=U.y+N.gnormy*Ye,g=ct}else{U.x=Se,U.y=Ve;let Ye=-rt;I.x=U.x+N.gnormx*Ye,I.y=U.y+N.gnormy*Ye,g=rt}}}else g=1e100}else g=1e100}}let Q=g+s,W=c*f.x+h*f.y;if(Q<l.Config.distanceThresholdCCD){if(i)break;let ie=0,oe=0;ie=d.x-a.posx,oe=d.y-a.posy;let se=0,ne=0;se=y.x-p.posx,ne=y.y-p.posy;let re=W-a.sweep_angvel*(f.y*ie-f.x*oe)+p.sweep_angvel*(f.y*se-f.x*ne);if(re>0&&(e.slipped=!0),re<=0||Q<l.Config.distanceThresholdCCD*.5)break}b=-1;break}if(++P>=40){j>s&&(e.failed=!0);break}}e.toi=b}static staticSweep(e,t,n,s){let i=me(),l=e.s1,o=e.s2,r=l.body,a=o.body,p=0,c=0;p=-r.velx,c=-r.vely;let h=r.sweep_angvel;h<0&&(h=-h);let u=l.sweepCoef*h,x=e.c1,m=e.c2,d=e.axis,y=n,f=0;for(;;){let M=y*t,N=M-r.sweepTime;if(N!=0){r.sweepTime=M;let j=N;if(r.posx+=r.velx*j,r.posy+=r.vely*j,r.angvel!=0){let V=r.sweep_angvel*N;if(r.rot+=V,V*V>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let K=V*V,$=1-.5*K,Y=1-K*K/8,X=($*r.axisx+V*r.axisy)*Y;r.axisy=($*r.axisy-V*r.axisx)*Y,r.axisx=X}}}if(l.type==0||l.type===2)l.worldCOMx=r.posx+(r.axisy*l.localCOMx-r.axisx*l.localCOMy),l.worldCOMy=r.posy+(l.localCOMx*r.axisx+l.localCOMy*r.axisy);else{let j=l.polygon,V=j.lverts.next,K=j.gverts.next;for(;K!=null;){let F=K,D=V;V=V.next,F.x=r.posx+(r.axisy*D.x-r.axisx*D.y),F.y=r.posy+(D.x*r.axisx+D.y*r.axisy),K=K.next}let $=j.edges.head,Y=j.gverts.next,X=Y;for(Y=Y.next;Y!=null;){let F=Y,D=$.elt;$=$.next,D.gnormx=r.axisy*D.lnormx-r.axisx*D.lnormy,D.gnormy=D.lnormx*r.axisx+D.lnormy*r.axisy,D.gprojection=r.posx*D.gnormx+r.posy*D.gnormy+D.lprojection,D.tp0=X.y*D.gnormx-X.x*D.gnormy,D.tp1=F.y*D.gnormx-F.x*D.gnormy,X=F,Y=Y.next}let ee=j.gverts.next,J=$.elt;$=$.next,J.gnormx=r.axisy*J.lnormx-r.axisx*J.lnormy,J.gnormy=J.lnormx*r.axisx+J.lnormy*r.axisy,J.gprojection=r.posx*J.gnormx+r.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,A=o,S=x,L=m;var b;if(at(Z)&&at(A)){let j=Z.circle||Z.capsule,V=A.circle||A.capsule,K=Dt(Z),$=Dt(A);var P;let Y=0,X=0;Y=V.worldCOMx-j.worldCOMx,X=V.worldCOMy-j.worldCOMy;let ee=Math.sqrt(Y*Y+X*X);if(P=ee-(j.radius+V.radius),P<1e100){if(ee==0)Y=1,X=0;else{let D=1/ee;Y*=D,X*=D}let J=j.radius;S.x=j.worldCOMx+Y*J,S.y=j.worldCOMy+X*J;let F=-V.radius;L.x=V.worldCOMx+Y*F,L.y=V.worldCOMy+X*F,d.x=Y,d.y=X}b=P}else{let j=!1;if(at(Z)&&A.type==1){let V=Z;Z=A,A=V;let K=S;S=L,L=K,j=!0}if(Z.type==1&&at(A)){let V=Z.polygon,K=A.circle||A.capsule,$=Dt(A),Y=-1e100,X=null,ee=V.edges.head;for(;ee!=null;){let J=ee.elt,F=J.gnormx*K.worldCOMx+J.gnormy*K.worldCOMy-J.gprojection-$;if(F>1e100){Y=F;break}F>0?F>Y&&(Y=F,X=J):Y<0&&F>Y&&(Y=F,X=J),ee=ee.next}if(Y<1e100){let J=X.gp0,F=X.gp1,D=K.worldCOMy*X.gnormx-K.worldCOMx*X.gnormy;if(D<=J.y*X.gnormx-J.x*X.gnormy){let I=0,U=0;I=K.worldCOMx-J.x,U=K.worldCOMy-J.y;let Q=Math.sqrt(I*I+U*U);if(Y=Q-$,Y<1e100){if(Q==0)I=1,U=0;else{let oe=1/Q;I*=oe,U*=oe}let W=0;S.x=J.x+I*W,S.y=J.y+U*W;let ie=-$;L.x=K.worldCOMx+I*ie,L.y=K.worldCOMy+U*ie,d.x=I,d.y=U}}else if(D>=F.y*X.gnormx-F.x*X.gnormy){let I=0,U=0;I=K.worldCOMx-F.x,U=K.worldCOMy-F.y;let Q=Math.sqrt(I*I+U*U);if(Y=Q-$,Y<1e100){if(Q==0)I=1,U=0;else{let oe=1/Q;I*=oe,U*=oe}let W=0;S.x=F.x+I*W,S.y=F.y+U*W;let ie=-$;L.x=K.worldCOMx+I*ie,L.y=K.worldCOMy+U*ie,d.x=I,d.y=U}}else{let I=-$;L.x=K.worldCOMx+X.gnormx*I,L.y=K.worldCOMy+X.gnormy*I;let U=-Y;S.x=L.x+X.gnormx*U,S.y=L.y+X.gnormy*U,d.x=X.gnormx,d.y=X.gnormy}}j&&(d.x=-d.x,d.y=-d.y),b=Y}else{let V=Z.polygon,K=A.polygon,$=-1e100,Y=null,X=null,ee=0,J=V.edges.head;for(;J!=null;){let F=J.elt,D=1e100,I=K.gverts.next;for(;I!=null;){let U=I,Q=F.gnormx*U.x+F.gnormy*U.y;Q<D&&(D=Q),I=I.next}if(D-=F.gprojection,D>1e100){$=D;break}D>0?D>$&&($=D,Y=F,ee=1):$<0&&D>$&&($=D,Y=F,ee=1),J=J.next}if($<1e100){let F=K.edges.head;for(;F!=null;){let D=F.elt,I=1e100,U=V.gverts.next;for(;U!=null;){let Q=U,W=D.gnormx*Q.x+D.gnormy*Q.y;W<I&&(I=W),U=U.next}if(I-=D.gprojection,I>1e100){$=I;break}I>0?I>$&&($=I,X=D,ee=2):$<0&&I>$&&($=I,X=D,ee=2),F=F.next}if($<1e100){var k,_,z;if(ee==1)k=V,_=K,z=Y;else{k=K,_=V,z=X;let Q=S;S=L,L=Q,j=!j}let D=null,I=1e100,U=_.edges.head;for(;U!=null;){let Q=U.elt,W=z.gnormx*Q.gnormx+z.gnormy*Q.gnormy;W<I&&(I=W,D=Q),U=U.next}if(j?(d.x=-z.gnormx,d.y=-z.gnormy):(d.x=z.gnormx,d.y=z.gnormy),$>=0){let Q=z.gp0,W=z.gp1,ie=D.gp0,oe=D.gp1,se=0,ne=0,re=0,le=0;se=W.x-Q.x,ne=W.y-Q.y,re=oe.x-ie.x,le=oe.y-ie.y;let he=1/(se*se+ne*ne),pe=1/(re*re+le*le),ce=-(se*(Q.x-ie.x)+ne*(Q.y-ie.y))*he,te=-(se*(Q.x-oe.x)+ne*(Q.y-oe.y))*he,ue=-(re*(ie.x-Q.x)+le*(ie.y-Q.y))*pe,xe=-(re*(ie.x-W.x)+le*(ie.y-W.y))*pe;ce<0?ce=0:ce>1&&(ce=1),te<0?te=0:te>1&&(te=1),ue<0?ue=0:ue>1&&(ue=1),xe<0?xe=0:xe>1&&(xe=1);let _e=0,ve=0,Se=ce;_e=Q.x+se*Se,ve=Q.y+ne*Se;let Ve=0,Ke=0,Xe=te;Ve=Q.x+se*Xe,Ke=Q.y+ne*Xe;let He=0,Re=0,bt=ue;He=ie.x+re*bt,Re=ie.y+le*bt;let vt=0,pt=0,ct=xe;vt=ie.x+re*ct,pt=ie.y+le*ct;let rt=0,Ye=0;rt=_e-ie.x,Ye=ve-ie.y;let ft=rt*rt+Ye*Ye,jt=0,Gt=0;jt=Ve-oe.x,Gt=Ke-oe.y;let kt=jt*jt+Gt*Gt,Et=0,zn=0;Et=He-Q.x,zn=Re-Q.y;let Yt=Et*Et+zn*zn,xn=0,on=0;xn=vt-W.x,on=pt-W.y;let dn=xn*xn+on*on,Xt=0,Pn=0,Ht=null;ft<kt?(Xt=_e,Pn=ve,Ht=ie):(Xt=Ve,Pn=Ke,Ht=oe,ft=kt);let _n=0,qt=0,Qt=null;if(Yt<dn?(_n=He,qt=Re,Qt=Q):(_n=vt,qt=pt,Qt=W,Yt=dn),ft<Yt?(S.x=Xt,S.y=Pn,L.x=Ht.x,L.y=Ht.y,$=Math.sqrt(ft)):(L.x=_n,L.y=qt,S.x=Qt.x,S.y=Qt.y,$=Math.sqrt(Yt)),$!=0){d.x=L.x-S.x,d.y=L.y-S.y;let rn=1/$;d.x*=rn,d.y*=rn,j&&(d.x=-d.x,d.y=-d.y)}b=$}else{let Q=0,W=0;Q=D.gp0.x,W=D.gp0.y;let ie=0,oe=0;ie=D.gp1.x,oe=D.gp1.y;let se=0,ne=0;se=ie-Q,ne=oe-W;let re=z.gnormy*Q-z.gnormx*W,le=z.gnormy*ie-z.gnormx*oe,he=1/(le-re),pe=(-z.tp1-re)*he;if(pe>i.Config.epsilon){let xe=pe;Q+=se*xe,W+=ne*xe}let ce=(-z.tp0-le)*he;if(ce<-i.Config.epsilon){let xe=ce;ie+=se*xe,oe+=ne*xe}let te=Q*z.gnormx+W*z.gnormy-z.gprojection,ue=ie*z.gnormx+oe*z.gnormy-z.gprojection;if(te<ue){L.x=Q,L.y=W;let xe=-te;S.x=L.x+z.gnormx*xe,S.y=L.y+z.gnormy*xe,b=te}else{L.x=ie,L.y=oe;let xe=-ue;S.x=L.x+z.gnormx*xe,S.y=L.y+z.gnormy*xe,b=ue}}}else b=1e100}else b=1e100}}let T=b+s,G=p*d.x+c*d.y;if(T<i.Config.distanceThresholdCCD){let j=0,V=0;j=x.x-r.posx,V=x.y-r.posy;let K=G-r.sweep_angvel*(d.y*j-d.x*V);if(K>0&&(e.slipped=!0),K<=0||T<i.Config.distanceThresholdCCD*.5)break}let q=(u-G)*t;if(q<=0){y=-1;break}let R=T/q;if(R<1e-6&&(R=1e-6),y+=R,y>=1){y=1;let j=y*t,V=j-r.sweepTime;if(V!=0){r.sweepTime=j;let F=V;if(r.posx+=r.velx*F,r.posy+=r.vely*F,r.angvel!=0){let D=r.sweep_angvel*V;if(r.rot+=D,D*D>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let I=D*D,U=1-.5*I,Q=1-I*I/8,W=(U*r.axisx+D*r.axisy)*Q;r.axisy=(U*r.axisy-D*r.axisx)*Q,r.axisx=W}}}if(l.type==0||l.type===2)l.worldCOMx=r.posx+(r.axisy*l.localCOMx-r.axisx*l.localCOMy),l.worldCOMy=r.posy+(l.localCOMx*r.axisx+l.localCOMy*r.axisy);else{let F=l.polygon,D=F.lverts.next,I=F.gverts.next;for(;I!=null;){let se=I,ne=D;D=D.next,se.x=r.posx+(r.axisy*ne.x-r.axisx*ne.y),se.y=r.posy+(ne.x*r.axisx+ne.y*r.axisy),I=I.next}let U=F.edges.head,Q=F.gverts.next,W=Q;for(Q=Q.next;Q!=null;){let se=Q,ne=U.elt;U=U.next,ne.gnormx=r.axisy*ne.lnormx-r.axisx*ne.lnormy,ne.gnormy=ne.lnormx*r.axisx+ne.lnormy*r.axisy,ne.gprojection=r.posx*ne.gnormx+r.posy*ne.gnormy+ne.lprojection,ne.tp0=W.y*ne.gnormx-W.x*ne.gnormy,ne.tp1=se.y*ne.gnormx-se.x*ne.gnormy,W=se,Q=Q.next}let ie=F.gverts.next,oe=U.elt;U=U.next,oe.gnormx=r.axisy*oe.lnormx-r.axisx*oe.lnormy,oe.gnormy=oe.lnormx*r.axisx+oe.lnormy*r.axisy,oe.gprojection=r.posx*oe.gnormx+r.posy*oe.gnormy+oe.lprojection,oe.tp0=W.y*oe.gnormx-W.x*oe.gnormy,oe.tp1=ie.y*oe.gnormx-ie.x*oe.gnormy}let K=l,$=o,Y=x,X=m;var C;if(at(K)&&at($)){let F=K.circle||K.capsule,D=$.circle||$.capsule,I=Dt(K),U=Dt($);var w;let Q=0,W=0;Q=D.worldCOMx-F.worldCOMx,W=D.worldCOMy-F.worldCOMy;let ie=Math.sqrt(Q*Q+W*W);if(w=ie-(I+U),w<1e100){if(ie==0)Q=1,W=0;else{let ne=1/ie;Q*=ne,W*=ne}let oe=I;Y.x=F.worldCOMx+Q*oe,Y.y=F.worldCOMy+W*oe;let se=-U;X.x=D.worldCOMx+Q*se,X.y=D.worldCOMy+W*se,d.x=Q,d.y=W}C=w}else{let F=!1;if(at(K)&&$.type==1){let D=K;K=$,$=D;let I=Y;Y=X,X=I,F=!0}if(K.type==1&&at($)){let D=K.polygon,I=$.circle||$.capsule,U=Dt($),Q=-1e100,W=null,ie=D.edges.head;for(;ie!=null;){let oe=ie.elt,se=oe.gnormx*I.worldCOMx+oe.gnormy*I.worldCOMy-oe.gprojection-U;if(se>1e100){Q=se;break}se>0?se>Q&&(Q=se,W=oe):Q<0&&se>Q&&(Q=se,W=oe),ie=ie.next}if(Q<1e100){let oe=W.gp0,se=W.gp1,ne=I.worldCOMy*W.gnormx-I.worldCOMx*W.gnormy;if(ne<=oe.y*W.gnormx-oe.x*W.gnormy){let re=0,le=0;re=I.worldCOMx-oe.x,le=I.worldCOMy-oe.y;let he=Math.sqrt(re*re+le*le);if(Q=he-U,Q<1e100){if(he==0)re=1,le=0;else{let te=1/he;re*=te,le*=te}let pe=0;Y.x=oe.x+re*pe,Y.y=oe.y+le*pe;let ce=-U;X.x=I.worldCOMx+re*ce,X.y=I.worldCOMy+le*ce,d.x=re,d.y=le}}else if(ne>=se.y*W.gnormx-se.x*W.gnormy){let re=0,le=0;re=I.worldCOMx-se.x,le=I.worldCOMy-se.y;let he=Math.sqrt(re*re+le*le);if(Q=he-U,Q<1e100){if(he==0)re=1,le=0;else{let te=1/he;re*=te,le*=te}let pe=0;Y.x=se.x+re*pe,Y.y=se.y+le*pe;let ce=-U;X.x=I.worldCOMx+re*ce,X.y=I.worldCOMy+le*ce,d.x=re,d.y=le}}else{let re=-U;X.x=I.worldCOMx+W.gnormx*re,X.y=I.worldCOMy+W.gnormy*re;let le=-Q;Y.x=X.x+W.gnormx*le,Y.y=X.y+W.gnormy*le,d.x=W.gnormx,d.y=W.gnormy}}F&&(d.x=-d.x,d.y=-d.y),C=Q}else{let D=K.polygon,I=$.polygon,U=-1e100,Q=null,W=null,ie=0,oe=D.edges.head;for(;oe!=null;){let se=oe.elt,ne=1e100,re=I.gverts.next;for(;re!=null;){let le=re,he=se.gnormx*le.x+se.gnormy*le.y;he<ne&&(ne=he),re=re.next}if(ne-=se.gprojection,ne>1e100){U=ne;break}ne>0?ne>U&&(U=ne,Q=se,ie=1):U<0&&ne>U&&(U=ne,Q=se,ie=1),oe=oe.next}if(U<1e100){let se=I.edges.head;for(;se!=null;){let ne=se.elt,re=1e100,le=D.gverts.next;for(;le!=null;){let he=le,pe=ne.gnormx*he.x+ne.gnormy*he.y;pe<re&&(re=pe),le=le.next}if(re-=ne.gprojection,re>1e100){U=re;break}re>0?re>U&&(U=re,W=ne,ie=2):U<0&&re>U&&(U=re,W=ne,ie=2),se=se.next}if(U<1e100){var g,O,E;if(ie==1)g=D,O=I,E=Q;else{g=I,O=D,E=W;let he=Y;Y=X,X=he,F=!F}let ne=null,re=1e100,le=O.edges.head;for(;le!=null;){let he=le.elt,pe=E.gnormx*he.gnormx+E.gnormy*he.gnormy;pe<re&&(re=pe,ne=he),le=le.next}if(F?(d.x=-E.gnormx,d.y=-E.gnormy):(d.x=E.gnormx,d.y=E.gnormy),U>=0){let he=E.gp0,pe=E.gp1,ce=ne.gp0,te=ne.gp1,ue=0,xe=0,_e=0,ve=0;ue=pe.x-he.x,xe=pe.y-he.y,_e=te.x-ce.x,ve=te.y-ce.y;let Se=1/(ue*ue+xe*xe),Ve=1/(_e*_e+ve*ve),Ke=-(ue*(he.x-ce.x)+xe*(he.y-ce.y))*Se,Xe=-(ue*(he.x-te.x)+xe*(he.y-te.y))*Se,He=-(_e*(ce.x-he.x)+ve*(ce.y-he.y))*Ve,Re=-(_e*(ce.x-pe.x)+ve*(ce.y-pe.y))*Ve;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 bt=0,vt=0,pt=Ke;bt=he.x+ue*pt,vt=he.y+xe*pt;let ct=0,rt=0,Ye=Xe;ct=he.x+ue*Ye,rt=he.y+xe*Ye;let ft=0,jt=0,Gt=He;ft=ce.x+_e*Gt,jt=ce.y+ve*Gt;let kt=0,Et=0,zn=Re;kt=ce.x+_e*zn,Et=ce.y+ve*zn;let Yt=0,xn=0;Yt=bt-ce.x,xn=vt-ce.y;let on=Yt*Yt+xn*xn,dn=0,Xt=0;dn=ct-te.x,Xt=rt-te.y;let Pn=dn*dn+Xt*Xt,Ht=0,_n=0;Ht=ft-he.x,_n=jt-he.y;let qt=Ht*Ht+_n*_n,Qt=0,rn=0;Qt=kt-pe.x,rn=Et-pe.y;let li=Qt*Qt+rn*rn,Gn=0,Vn=0,In=null;on<Pn?(Gn=bt,Vn=vt,In=ce):(Gn=ct,Vn=rt,In=te,on=Pn);let Si=0,Ai=0,Vi=null;if(qt<li?(Si=ft,Ai=jt,Vi=he):(Si=kt,Ai=Et,Vi=pe,qt=li),on<qt?(Y.x=Gn,Y.y=Vn,X.x=In.x,X.y=In.y,U=Math.sqrt(on)):(X.x=Si,X.y=Ai,Y.x=Vi.x,Y.y=Vi.y,U=Math.sqrt(qt)),U!=0){d.x=X.x-Y.x,d.y=X.y-Y.y;let xs=1/U;d.x*=xs,d.y*=xs,F&&(d.x=-d.x,d.y=-d.y)}C=U}else{let he=0,pe=0;he=ne.gp0.x,pe=ne.gp0.y;let ce=0,te=0;ce=ne.gp1.x,te=ne.gp1.y;let ue=0,xe=0;ue=ce-he,xe=te-pe;let _e=E.gnormy*he-E.gnormx*pe,ve=E.gnormy*ce-E.gnormx*te,Se=1/(ve-_e),Ve=(-E.tp1-_e)*Se;if(Ve>i.Config.epsilon){let Re=Ve;he+=ue*Re,pe+=xe*Re}let Ke=(-E.tp0-ve)*Se;if(Ke<-i.Config.epsilon){let Re=Ke;ce+=ue*Re,te+=xe*Re}let Xe=he*E.gnormx+pe*E.gnormy-E.gprojection,He=ce*E.gnormx+te*E.gnormy-E.gprojection;if(Xe<He){X.x=he,X.y=pe;let Re=-Xe;Y.x=X.x+E.gnormx*Re,Y.y=X.y+E.gnormy*Re,C=Xe}else{X.x=ce,X.y=te;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 F=0,D=0;F=x.x-r.posx,D=x.y-r.posy;let I=J-r.sweep_angvel*(d.y*F-d.x*D);if(I>0&&(e.slipped=!0),I<=0||ee<i.Config.distanceThresholdCCD*.5)break}y=-1;break}if(++f>=40){T>s&&(e.failed=!0);break}}e.toi=y}static distanceBody(e,t,n,s){let i=me(),l=ae.get(0,0),o=ae.get(0,0),r=ae.get(0,0),a=1e100,p=e.shapes.head;for(;p!=null;){let b=p.elt,P=t.shapes.head;for(;P!=null;){let k=P.elt,_=b,z=k,C=l,w=o,g=a;g==null&&(g=1e100);var c;if(at(_)&&at(z)){let O=_.circle||_.capsule,E=z.circle||z.capsule,M=Dt(_),N=Dt(z);var h;let Z=0,A=0;Z=E.worldCOMx-O.worldCOMx,A=E.worldCOMy-O.worldCOMy;let S=Math.sqrt(Z*Z+A*A);if(h=S-(M+N),h<g){if(S==0)Z=1,A=0;else{let G=1/S;Z*=G,A*=G}let L=M;C.x=O.worldCOMx+Z*L,C.y=O.worldCOMy+A*L;let T=-N;w.x=E.worldCOMx+Z*T,w.y=E.worldCOMy+A*T,r.x=Z,r.y=A}c=h}else{let O=!1;if(at(_)&&z.type==1){let E=_;_=z,z=E;let M=C;C=w,w=M,O=!0}if(_.type==1&&at(z)){let E=_.polygon,M=z.circle||z.capsule,N=Dt(z),Z=-1e100,A=null,S=E.edges.head;for(;S!=null;){let L=S.elt,T=L.gnormx*M.worldCOMx+L.gnormy*M.worldCOMy-L.gprojection-N;if(T>g){Z=T;break}T>0?T>Z&&(Z=T,A=L):Z<0&&T>Z&&(Z=T,A=L),S=S.next}if(Z<g){let L=A.gp0,T=A.gp1,G=M.worldCOMy*A.gnormx-M.worldCOMx*A.gnormy;if(G<=L.y*A.gnormx-L.x*A.gnormy){let q=0,R=0;q=M.worldCOMx-L.x,R=M.worldCOMy-L.y;let j=Math.sqrt(q*q+R*R);if(Z=j-N,Z<g){if(j==0)q=1,R=0;else{let $=1/j;q*=$,R*=$}let V=0;C.x=L.x+q*V,C.y=L.y+R*V;let K=-N;w.x=M.worldCOMx+q*K,w.y=M.worldCOMy+R*K,r.x=q,r.y=R}}else if(G>=T.y*A.gnormx-T.x*A.gnormy){let q=0,R=0;q=M.worldCOMx-T.x,R=M.worldCOMy-T.y;let j=Math.sqrt(q*q+R*R);if(Z=j-N,Z<g){if(j==0)q=1,R=0;else{let $=1/j;q*=$,R*=$}let V=0;C.x=T.x+q*V,C.y=T.y+R*V;let K=-N;w.x=M.worldCOMx+q*K,w.y=M.worldCOMy+R*K,r.x=q,r.y=R}}else{let q=-N;w.x=M.worldCOMx+A.gnormx*q,w.y=M.worldCOMy+A.gnormy*q;let R=-Z;C.x=w.x+A.gnormx*R,C.y=w.y+A.gnormy*R,r.x=A.gnormx,r.y=A.gnormy}}O&&(r.x=-r.x,r.y=-r.y),c=Z}else{let E=_.polygon,M=z.polygon,N=-1e100,Z=null,A=null,S=0,L=E.edges.head;for(;L!=null;){let T=L.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>g){N=G;break}G>0?G>N&&(N=G,Z=T,S=1):N<0&&G>N&&(N=G,Z=T,S=1),L=L.next}if(N<g){let T=M.edges.head;for(;T!=null;){let G=T.elt,q=1e100,R=E.gverts.next;for(;R!=null;){let j=R,V=G.gnormx*j.x+G.gnormy*j.y;V<q&&(q=V),R=R.next}if(q-=G.gprojection,q>g){N=q;break}q>0?q>N&&(N=q,A=G,S=2):N<0&&q>N&&(N=q,A=G,S=2),T=T.next}if(N<g){var u,x,m;if(S==1)u=E,x=M,m=Z;else{u=M,x=E,m=A;let j=C;C=w,w=j,O=!O}let G=null,q=1e100,R=x.edges.head;for(;R!=null;){let j=R.elt,V=m.gnormx*j.gnormx+m.gnormy*j.gnormy;V<q&&(q=V,G=j),R=R.next}if(O?(r.x=-m.gnormx,r.y=-m.gnormy):(r.x=m.gnormx,r.y=m.gnormy),N>=0){let j=m.gp0,V=m.gp1,K=G.gp0,$=G.gp1,Y=0,X=0,ee=0,J=0;Y=V.x-j.x,X=V.y-j.y,ee=$.x-K.x,J=$.y-K.y;let F=1/(Y*Y+X*X),D=1/(ee*ee+J*J),I=-(Y*(j.x-K.x)+X*(j.y-K.y))*F,U=-(Y*(j.x-$.x)+X*(j.y-$.y))*F,Q=-(ee*(K.x-j.x)+J*(K.y-j.y))*D,W=-(ee*(K.x-V.x)+J*(K.y-V.y))*D;I<0?I=0:I>1&&(I=1),U<0?U=0:U>1&&(U=1),Q<0?Q=0:Q>1&&(Q=1),W<0?W=0:W>1&&(W=1);let ie=0,oe=0,se=I;ie=j.x+Y*se,oe=j.y+X*se;let ne=0,re=0,le=U;ne=j.x+Y*le,re=j.y+X*le;let he=0,pe=0,ce=Q;he=K.x+ee*ce,pe=K.y+J*ce;let te=0,ue=0,xe=W;te=K.x+ee*xe,ue=K.y+J*xe;let _e=0,ve=0;_e=ie-K.x,ve=oe-K.y;let Se=_e*_e+ve*ve,Ve=0,Ke=0;Ve=ne-$.x,Ke=re-$.y;let Xe=Ve*Ve+Ke*Ke,He=0,Re=0;He=he-j.x,Re=pe-j.y;let bt=He*He+Re*Re,vt=0,pt=0;vt=te-V.x,pt=ue-V.y;let ct=vt*vt+pt*pt,rt=0,Ye=0,ft=null;Se<Xe?(rt=ie,Ye=oe,ft=K):(rt=ne,Ye=re,ft=$,Se=Xe);let jt=0,Gt=0,kt=null;if(bt<ct?(jt=he,Gt=pe,kt=j):(jt=te,Gt=ue,kt=V,bt=ct),Se<bt?(C.x=rt,C.y=Ye,w.x=ft.x,w.y=ft.y,N=Math.sqrt(Se)):(w.x=jt,w.y=Gt,C.x=kt.x,C.y=kt.y,N=Math.sqrt(bt)),N!=0){r.x=w.x-C.x,r.y=w.y-C.y;let Et=1/N;r.x*=Et,r.y*=Et,O&&(r.x=-r.x,r.y=-r.y)}c=N}else{let j=0,V=0;j=G.gp0.x,V=G.gp0.y;let K=0,$=0;K=G.gp1.x,$=G.gp1.y;let Y=0,X=0;Y=K-j,X=$-V;let ee=m.gnormy*j-m.gnormx*V,J=m.gnormy*K-m.gnormx*$,F=1/(J-ee),D=(-m.tp1-ee)*F;if(D>i.Config.epsilon){let W=D;j+=Y*W,V+=X*W}let I=(-m.tp0-J)*F;if(I<-i.Config.epsilon){let W=I;K+=Y*W,$+=X*W}let U=j*m.gnormx+V*m.gnormy-m.gprojection,Q=K*m.gnormx+$*m.gnormy-m.gprojection;if(U<Q){w.x=j,w.y=V;let W=-U;C.x=w.x+m.gnormx*W,C.y=w.y+m.gnormy*W,c=U}else{w.x=K,w.y=$;let W=-Q;C.x=w.x+m.gnormx*W,C.y=w.y+m.gnormy*W,c=Q}}}else c=g}else c=g}}c<a&&(a=c,n.x=l.x,n.y=l.y,s.x=o.x,s.y=o.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=ae.zpp_pool,ae.zpp_pool=d;let y=o;y.outer!=null&&(y.outer.zpp_inner=null,y.outer=null),y._isimmutable=null,y._validate=null,y._invalidate=null,y.next=ae.zpp_pool,ae.zpp_pool=y;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=ae.zpp_pool,ae.zpp_pool=f,a}static distance(e,t,n,s,i,l){let o=me();if(l==null&&(l=1e100),at(e)&&at(t)){let r=e.circle||e.capsule,a=t.circle||t.capsule,p=Dt(e),c=Dt(t),h,u=0,x=0;u=a.worldCOMx-r.worldCOMx,x=a.worldCOMy-r.worldCOMy;let m=Math.sqrt(u*u+x*x);if(h=m-(p+c),h<l){if(m==0)u=1,x=0;else{let f=1/m;u*=f,x*=f}let d=p;n.x=r.worldCOMx+u*d,n.y=r.worldCOMy+x*d;let y=-c;s.x=a.worldCOMx+u*y,s.y=a.worldCOMy+x*y,i.x=u,i.y=x}return h}else{let r=!1;if(at(e)&&t.type==1){let a=e;e=t,t=a;let p=n;n=s,s=p,r=!0}if(e.type==1&&at(t)){let a=e.polygon,p=t.circle||t.capsule,c=Dt(t),h=-1e100,u=null,x=a.edges.head;for(;x!=null;){let m=x.elt,d=m.gnormx*p.worldCOMx+m.gnormy*p.worldCOMy-m.gprojection-c;if(d>l){h=d;break}d>0?d>h&&(h=d,u=m):h<0&&d>h&&(h=d,u=m),x=x.next}if(h<l){let m=u.gp0,d=u.gp1,y=p.worldCOMy*u.gnormx-p.worldCOMx*u.gnormy;if(y<=m.y*u.gnormx-m.x*u.gnormy){let f=0,b=0;f=p.worldCOMx-m.x,b=p.worldCOMy-m.y;let P=Math.sqrt(f*f+b*b);if(h=P-c,h<l){if(P==0)f=1,b=0;else{let z=1/P;f*=z,b*=z}let k=0;n.x=m.x+f*k,n.y=m.y+b*k;let _=-c;s.x=p.worldCOMx+f*_,s.y=p.worldCOMy+b*_,i.x=f,i.y=b}}else if(y>=d.y*u.gnormx-d.x*u.gnormy){let f=0,b=0;f=p.worldCOMx-d.x,b=p.worldCOMy-d.y;let P=Math.sqrt(f*f+b*b);if(h=P-c,h<l){if(P==0)f=1,b=0;else{let z=1/P;f*=z,b*=z}let k=0;n.x=d.x+f*k,n.y=d.y+b*k;let _=-c;s.x=p.worldCOMx+f*_,s.y=p.worldCOMy+b*_,i.x=f,i.y=b}}else{let f=-c;s.x=p.worldCOMx+u.gnormx*f,s.y=p.worldCOMy+u.gnormy*f;let b=-h;n.x=s.x+u.gnormx*b,n.y=s.y+u.gnormy*b,i.x=u.gnormx,i.y=u.gnormy}}return r&&(i.x=-i.x,i.y=-i.y),h}else{let a=e.polygon,p=t.polygon,c=-1e100,h=null,u=null,x=0,m=a.edges.head;for(;m!=null;){let d=m.elt,y=1e100,f=p.gverts.next;for(;f!=null;){let b=f,P=d.gnormx*b.x+d.gnormy*b.y;P<y&&(y=P),f=f.next}if(y-=d.gprojection,y>l){c=y;break}y>0?y>c&&(c=y,h=d,x=1):c<0&&y>c&&(c=y,h=d,x=1),m=m.next}if(c<l){let d=p.edges.head;for(;d!=null;){let y=d.elt,f=1e100,b=a.gverts.next;for(;b!=null;){let P=b,k=y.gnormx*P.x+y.gnormy*P.y;k<f&&(f=k),b=b.next}if(f-=y.gprojection,f>l){c=f;break}f>0?f>c&&(c=f,u=y,x=2):c<0&&f>c&&(c=f,u=y,x=2),d=d.next}if(c<l){let y,f,b;if(x==1)y=a,f=p,b=h;else{y=p,f=a,b=u;let z=n;n=s,s=z,r=!r}let P=null,k=1e100,_=f.edges.head;for(;_!=null;){let z=_.elt,C=b.gnormx*z.gnormx+b.gnormy*z.gnormy;C<k&&(k=C,P=z),_=_.next}if(r?(i.x=-b.gnormx,i.y=-b.gnormy):(i.x=b.gnormx,i.y=b.gnormy),c>=0){let z=b.gp0,C=b.gp1,w=P.gp0,g=P.gp1,O=0,E=0,M=0,N=0;O=C.x-z.x,E=C.y-z.y,M=g.x-w.x,N=g.y-w.y;let Z=1/(O*O+E*E),A=1/(M*M+N*N),S=-(O*(z.x-w.x)+E*(z.y-w.y))*Z,L=-(O*(z.x-g.x)+E*(z.y-g.y))*Z,T=-(M*(w.x-z.x)+N*(w.y-z.y))*A,G=-(M*(w.x-C.x)+N*(w.y-C.y))*A;S<0?S=0:S>1&&(S=1),L<0?L=0:L>1&&(L=1),T<0?T=0:T>1&&(T=1),G<0?G=0:G>1&&(G=1);let q=0,R=0,j=S;q=z.x+O*j,R=z.y+E*j;let V=0,K=0,$=L;V=z.x+O*$,K=z.y+E*$;let Y=0,X=0,ee=T;Y=w.x+M*ee,X=w.y+N*ee;let J=0,F=0,D=G;J=w.x+M*D,F=w.y+N*D;let I=0,U=0;I=q-w.x,U=R-w.y;let Q=I*I+U*U,W=0,ie=0;W=V-g.x,ie=K-g.y;let oe=W*W+ie*ie,se=0,ne=0;se=Y-z.x,ne=X-z.y;let re=se*se+ne*ne,le=0,he=0;le=J-C.x,he=F-C.y;let pe=le*le+he*he,ce=0,te=0,ue=null;Q<oe?(ce=q,te=R,ue=w):(ce=V,te=K,ue=g,Q=oe);let xe=0,_e=0,ve=null;if(re<pe?(xe=Y,_e=X,ve=z):(xe=J,_e=F,ve=C,re=pe),Q<re?(n.x=ce,n.y=te,s.x=ue.x,s.y=ue.y,c=Math.sqrt(Q)):(s.x=xe,s.y=_e,n.x=ve.x,n.y=ve.y,c=Math.sqrt(re)),c!=0){i.x=s.x-n.x,i.y=s.y-n.y;let Se=1/c;i.x*=Se,i.y*=Se,r&&(i.x=-i.x,i.y=-i.y)}return c}else{let z=0,C=0;z=P.gp0.x,C=P.gp0.y;let w=0,g=0;w=P.gp1.x,g=P.gp1.y;let O=0,E=0;O=w-z,E=g-C;let M=b.gnormy*z-b.gnormx*C,N=b.gnormy*w-b.gnormx*g,Z=1/(N-M),A=(-b.tp1-M)*Z;if(A>o.Config.epsilon){let G=A;z+=O*G,C+=E*G}let S=(-b.tp0-N)*Z;if(S<-o.Config.epsilon){let G=S;w+=O*G,g+=E*G}let L=z*b.gnormx+C*b.gnormy-b.gprojection,T=w*b.gnormx+g*b.gnormy-b.gprojection;if(L<T){s.x=z,s.y=C;let G=-L;return n.x=s.x+b.gnormx*G,n.y=s.y+b.gnormy*G,L}else{s.x=w,s.y=g;let G=-T;return n.x=s.x+b.gnormx*G,n.y=s.y+b.gnormy*G,T}}}else return l}else return l}}}};var De=class De{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,o=t.x-e.x,r=t.y-e.y,a,p,c;return r*i-o*l>=0?c=!0:(i=s.x-n.x,l=s.y-n.y,o=n.x-t.x,r=n.y-t.y,c=r*i-o*l>=0),c?p=!0:(i=e.x-s.x,l=e.y-s.y,o=s.x-n.x,r=s.y-n.y,p=r*i-o*l>=0),p?a=!0:(i=t.x-e.x,l=t.y-e.y,o=e.x-s.x,r=e.y-s.y,a=r*i-o*l>=0),a?!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 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}}De.edgeSet==null&&(Ps.zpp_pool==null?De.edgeSet=new Ps:(De.edgeSet=Ps.zpp_pool,Ps.zpp_pool=De.edgeSet.next,De.edgeSet.next=null),De.edgeSet.lt=St.edge_lt,De.edgeSet.swapped=St.edge_swap);let s;St.zpp_pool==null?s=new St:(s=St.zpp_pool,St.zpp_pool=s.next,s.next=null);let i=e.vertices,l=e.vertices;if(i!=null){let r=i;for(;;){let a=r,p=a.next;a.diagonals.reverse();let c=a.diagonals.head;for(;c!=null;){let h=c.elt;if(h.id<a.id){p=h,c=c.next;continue}let u=c.next==null?a.prev:c.next.elt;if(!De.delaunay(a,p,h,u)){let x;St.zpp_pool==null?x=new St:(x=St.zpp_pool,St.zpp_pool=x.next,x.next=null),x.a=a,x.b=h,a.id<h.id?(x.id=a.id,x.di=h.id):(x.id=h.id,x.di=a.id);let m=x;s.add(m),m.node=De.edgeSet.insert(m)}p=h,c=c.next}if(r=r.next,r==l)break}}for(;s.next!=null;){let r=s.pop_unsafe(),a=r.a,p=r.b,c=a.next,h=null,u=a.diagonals.head;for(;u!=null;){let m=u.elt;if(m==p){u=u.next,h=u==null?a.prev:u.elt;break}c=m,u=u.next}if(a.diagonals.remove(p),p.diagonals.remove(a),p==c.next)c.diagonals.add(h);else{let m=c.diagonals.head;for(;m!=null;){if(m.elt==p){c.diagonals.insert(m,h);break}m=m.next}}if(a==h.next)h.diagonals.add(c);else{let m=h.diagonals.head;for(;m!=null;){if(m.elt==a){h.diagonals.insert(m,c);break}m=m.next}}De.edgeSet.remove_node(r.node);let x=r;x.a=x.b=null,x.node=null,x.next=St.zpp_pool,St.zpp_pool=x}let o=s;o.a=o.b=null,o.node=null,o.next=St.zpp_pool,St.zpp_pool=o}static triangulate(e){let t=e.vertices,n=e.vertices,s=e.vertices.next,i=e.vertices;if(s!=null){let a=s;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==i)break}}De.queue==null&&(De.queue=new _i);let l=n.prev,o=n.next;for(De.queue.add(n);l!=t||o!=t;)l==t||o!=t&&(l.y<o.y||l.y==o.y&&l.x<o.x)?(De.queue.add(o),o.rightchain=!1,o=o.next):(De.queue.add(l),l.rightchain=!0,l=l.prev);De.queue.add(t),De.stack==null&&(De.stack=new _i),De.stack.add(De.queue.pop_unsafe());let r=De.queue.pop_unsafe();for(De.stack.add(r);;){let a=De.queue.pop_unsafe();if(De.queue.head==null)break;if(a.rightchain!=De.stack.head.elt.rightchain){for(;;){let p=De.stack.pop_unsafe();if(De.stack.head==null)break;e.add_diagonal(p,a)}De.stack.add(r)}else{let p=De.stack.pop_unsafe();for(;De.stack.head!=null;){let c=De.stack.head.elt,h=a.x-p.x,u=a.y-p.y,x=p.x-c.x,d=(p.y-c.y)*h-x*u;if(a.rightchain&&d>=0||!a.rightchain&&d<=0)break;e.add_diagonal(c,a),p=c,De.stack.pop()}De.stack.add(p)}De.stack.add(a),r=a}if(De.stack.head!=null)for(De.stack.pop();De.stack.head!=null;){let a=De.stack.pop_unsafe();if(De.stack.head==null)break;e.add_diagonal(n,a)}return e}};De.queue=null,De.stack=null,De.edgeSet=null;var Pl=De;var Cs=class Cs{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&&Cs._wrapFn&&(this.outer=Cs._wrapFn(this)),this.outer}};Cs._zpp=null,Cs._wrapFn=null;var ai=Cs;var wl=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 fn=class fn{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;fn.initFields(this)}static initFields(e){let t=fn._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=yn.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,o=i.head;for(;o!=null;){let r=o.elt;if(r.id==n&&r.di==s){l=r;break}o=o.next}return l}static int_callback(e,t,n){let s=e.int1,i=e.int2,l,o=t.options1,r=s.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=t.options2,p=i.cbTypes;l=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.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=fn._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=fn._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 a=i.elt;if(e.id<a.id)break;s=i,i=i.next}let l=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;s==null?(r.next=l.head,l.head=r):(r.next=s.next,s.next=r),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=_t.zpp_pool,_t.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=fn._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 o=l.zpp_inner.user_length;i.zpp_critical=!0;let r;if(i.zpp_i<o?r=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,r=!1),!r)break;i.zpp_critical=!1;let a=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(a):p.unshift(a)}this.userData!=null&&(e.zpp_inner_i.userData=Object.assign({},this.userData))}static _init(e,t){fn._initialized||(fn._initialized=!0,fn._zpp=e,fn._nape=t)}};fn._nape=null,fn._zpp=null,fn._initialized=!1;var Wt=fn;var je=class je{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=je._zpp;Wt.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=je._nape,t=je._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(je.bodyset==null){let e=je._zpp;je.bodyset=new e.util.ZPP_Set_ZPP_Body,je.bodyset.lt=je.bodysetlt,je.bodystack=new e.util.ZNPList_ZPP_Body}}connectedBodies_cont(e){je.bodyset.try_insert_bool(e.zpp_inner)&&(je.bodystack.add(e.zpp_inner),e.zpp_inner.graph_depth=je.cur_graph_depth+1)}connectedBodies(e,t){let n=je._nape;je.bodyset==null&&this.init_bodysetlist();let s=t??new n.phys.BodyList;for(je.bodystack.add(this),je.bodyset.insert(this),this.graph_depth=0;je.bodystack.head!=null;){let l=je.bodystack.pop_unsafe();if(l.graph_depth===e)continue;je.cur_graph_depth=l.graph_depth;let o=l.constraints.head;for(;o!=null;)o.elt.outer.visitBodies(this.connectedBodies_cont.bind(this)),o=o.next}let i=je.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 o=l.data;if(o!==this){let p=o.outer;s.zpp_inner.reverse_flag?s.push(p):s.unshift(p)}let r=l.parent;r!=null&&(l===r.prev?r.prev=null:r.next=null,l.parent=null);let a=l;a.data=null,a.lt=null,a.next=je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool,je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool=a,l=r}i.parent=null}return s}interactingBodies(e,t){let n=je._nape,s=je._zpp;je.bodyset==null&&this.init_bodysetlist();let i=t??new n.phys.BodyList,l=this.arbiters.head;for(;l!=null;){let r=l.elt;if(!r.sleeping&&(e===4||r.type===e)){let a=r.b1===this?r.b2:r.b1;if(je.bodyset.try_insert_bool(a)){let p=a.outer;i.zpp_inner.reverse_flag?i.push(p):i.unshift(p)}}l=l.next}let o=je.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=s.util.ZPP_Set_ZPP_Body.zpp_pool,s.util.ZPP_Set_ZPP_Body.zpp_pool=p,r=a}o.parent=null}return i}atRest(e){let t=je._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 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)s=!1;else{let c=this.rot-this.pre_rot;s=!(c*c*a>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,o=(i*this.axisx+n*this.axisy)*l;this.axisy=(i*this.axisy-n*this.axisx)*l,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,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,o=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=o.y*c.gnormx-o.x*c.gnormy,c.tp1=p.y*c.gnormx-p.x*c.gnormy,o=p,l=l.next}let r=t.gverts.next,a=i.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,s){let i=je._nape;if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;if(ye.poolVec2==null?l=new i.geom.Vec2:(l=ye.poolVec2,ye.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===ye.nextVec2&&(ye.nextVec2=null)),l.zpp_inner==null){let o;ae.zpp_pool==null?o=new ae:(o=ae.zpp_pool,ae.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=e,o.y=t,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.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;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x===e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),r=l.zpp_inner.y===t):r=!1,r||(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,o=s;s=s.next,l.x=e.body.posx+(e.body.axisy*o.x-e.body.axisx*o.y),l.y=e.body.posy+(o.x*e.body.axisx+o.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 o=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*o,e.localCOMy+=(i.y+l.y)*o,s=i,i=l,n=n.next;let r=n;t+=i.x*(r.y-s.y);let a=r.y*i.x-r.x*i.y;e.localCOMx+=(i.x+r.x)*a,e.localCOMy+=(i.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,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=je._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=je._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 o=l;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}s=i,i=i.next}}copy(){let e=je._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(!je._initialized){je._initialized=!0,je._zpp=e,je._nape=t;for(let n of Object.getOwnPropertyNames(Wt.prototype))n!=="constructor"&&!(n in je.prototype)&&(je.prototype[n]=Wt.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()),je.types=[null,t.BodyType_STATIC,t.BodyType_DYNAMIC,t.BodyType_KINEMATIC]}};je._nape=null,je._zpp=null,je.types=[],je.bodystack=null,je.bodyset=null,je.cur_graph_depth=0,je._initialized=!1;var Mn=je;var en=class en{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=en._zpp;Wt.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=en._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=en._zppOf(e);t.compound=null,this.space!=null&&this.space.remBody(t)}bodies_modifiable(){this.immutable_midstep("Compound::bodies")}constraints_adder(e){let t=en._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=en._zppOf(e);t.compound=null,this.space!=null&&this.space.remConstraint(t)}constraints_modifiable(){this.immutable_midstep("Compound::constraints")}compounds_adder(e){let t=en._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=en._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=en._nape,s=en._zpp,i=e==null;e==null&&(e=[]),t==null&&(t=[]);let l=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)!==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)}o=o.next}let r=this.bodies.head;for(;r!=null;){let p=r.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)}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)!==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)}a=a.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(Wt.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(en.prototype,e)&&(en.prototype[e]=Wt.prototype[e])}};en._nape=null,en._zpp=null,en._wrapFn=null;var Wn=en;var Bt=class Bt{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 Bt._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Bt._wrapFn)this.outer=Bt._wrapFn(this);else{this.outer=new Bt._nape.phys.FluidProperties;let e=this.outer.zpp_inner;e.outer=null,e.next=Bt.zpp_pool,Bt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Bt._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Bt.zpp_pool==null?e=new Bt:(e=Bt.zpp_pool,Bt.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=Bt._zpp,t=Bt._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 o=!1;l._validate!=null&&l._validate(),(l.x!==n||l.y!==s)&&(o=!0),o&&(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}};Bt.zpp_pool=null,Bt._nape=null,Bt._zpp=null,Bt._wrapFn=null;var Zn=Bt;var Ft=class Ft{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 Ft._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Ft._wrapFn)this.outer=Ft._wrapFn(this);else{this.outer=new Ft._nape.phys.Material;let e=this.outer.zpp_inner;e.outer=null,e.next=Ft.zpp_pool,Ft.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Ft._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e=new Ft;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}};Ft.zpp_pool=null,Ft.WAKE=1,Ft.PROPS=2,Ft.ANGDRAG=4,Ft.ARBITERS=8,Ft._nape=null,Ft._zpp=null,Ft._wrapFn=null;var Oe=Ft;var kn=class kn{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.capsule=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()),t.ShapeType_CAPSULE==null&&(t.ShapeType_CAPSULE=n()),kn.types=[t.ShapeType_CIRCLE,t.ShapeType_POLYGON,t.ShapeType_CAPSULE]}_initShape(e){let t=kn._zpp;Wt.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 Oe,this.sweepRadius=this.sweepCoef=0}static _init(){if(!kn._initialized){kn._initialized=!0;for(let e of Object.getOwnPropertyNames(Wt.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(kn.prototype,e)&&(kn.prototype[e]=Wt.prototype[e])}}isCircle(){return this.type===0}isPolygon(){return this.type===1}isCapsule(){return this.type===2}invalidate_sweepRadius(){this.zip_sweepRadius=!0}validate_sweepRadius(){this.zip_sweepRadius&&(this.zip_sweepRadius=!1,this.type===0?this.circle.__validate_sweepRadius():this.type===1?this.polygon.__validate_sweepRadius():this.capsule.__validate_sweepRadius())}clear(){this.type===0?this.circle.__clear():this.type===1?this.polygon.__clear():this.capsule.__clear()}validate_aabb(){this.zip_aabb&&this.body!=null&&(this.zip_aabb=!1,this.type===0?this.circle.__validate_aabb():this.type===1?this.polygon.__validate_aabb():this.capsule.__validate_aabb())}force_validate_aabb(){this.type===0?this.circle._force_validate_aabb():this.type===1?this.polygon._force_validate_aabb():this.capsule._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.type===1?this.polygon.__validate_area_inertia():this.capsule.__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.type===1?this.polygon.__validate_angDrag():this.capsule.__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.type===2)&&(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&Oe.WAKE)!==0&&this.wake(),(e&Oe.ARBITERS)!==0&&this.body!=null&&this.body.refreshArbiters(),(e&Oe.PROPS)!==0&&this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia()),(e&Oe.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=kn._zpp,t=this.type===0?this.circle.__copy():this.type===1?this.polygon.__copy():this.capsule.__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=Oe.zpp_pool,Oe.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}};kn._nape=null,kn._zpp=null,kn.types=[],kn._initialized=!1;var pi=kn;var En=class En{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(En._initialized)return;En._initialized=!0;let t=En._zpp.shape.ZPP_Shape.prototype,n=En.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=En._zpp,t=En._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=En._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=En._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}};En._nape=null,En._zpp=null,En._initialized=!1;var $n=En;var tn=class tn{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&&(tn._wrapFn?this.outer=tn._wrapFn(this):(tn.internal=!0,this.outer=new tn._nape.shape.Edge,tn.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=tn._zpp,t=tn._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=tn._zpp,t=tn._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)}};tn.zpp_pool=null,tn.internal=!1,tn._nape=null,tn._zpp=null,tn._wrapFn=null;var ot=tn;var mt=class mt{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=mt._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(mt._initialized)return;mt._initialized=!0;let t=mt._zpp.shape.ZPP_Shape.prototype,n=mt.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=mt._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 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(s,o),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=mt._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=mt._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=mt._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,m=s.y-h.y,d=Math.sqrt(x*x+m*m);u.length=d;let y=1/d;x*=y,m*=y;let f=x;x=-m,m=f,u.lprojection=x*s.x+m*s.y,u.lnormx=x,u.lnormy=m,u.wrap_lnorm!=null&&(u.wrap_lnorm.zpp_inner.x=x,u.wrap_lnorm.zpp_inner.y=m),s=h,n=n.next}let i=this.lverts.next,l=t.elt;l.lp0=s,l.lp1=i;let o=s.x-i.x,r=s.y-i.y,a=Math.sqrt(o*o+r*r);l.length=a;let p=1/a;o*=p,r*=p;let c=o;o=-r,r=c,l.lprojection=o*s.x+r*s.y,l.lnormx=o,l.lnormy=r,l.wrap_lnorm!=null&&(l.wrap_lnorm.zpp_inner.x=o,l.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,s=n;for(n=n.next;n!=null;){let o=n,r=t.elt;t=t.next,r.gp0=s,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,s=o,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=mt._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 o=l;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=s==null?this.edges.head.elt:s.next.elt;this.edges.erase(s),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=mt._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,o=n.y-i.y;l*l+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 s;for(;;){s=!1;let i=this.lverts.next;for(;i!=null;){let l=i.next==null?this.lverts.next:i.next,o=l.next==null?this.lverts.next:l.next,r=l.x-i.x,a=l.y-i.y,p=o.x-l.x,h=(o.y-l.y)*r-p*a;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=mt._nape,t=mt._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,o=l;l=l.next;let r=l;for(l=l.next;l!=null;){let a=l,p=a.x-r.x,c=a.y-r.y,h=r.x-o.x,x=(r.y-o.y)*p-h*c;if(x>e.Config.epsilon?s=!0:x<-e.Config.epsilon&&(n=!0),s&&n){i=!1;break}o=r,r=a,l=l.next}if(i){l=this.lverts.next;let a=l,p=a.x-r.x,c=a.y-r.y,h=r.x-o.x,x=(r.y-o.y)*p-h*c;if(x>e.Config.epsilon?s=!0:x<-e.Config.epsilon&&(n=!0),!(s&&n)){o=r,r=a,l=l.next;let m=l,d=m.x-r.x,y=m.y-r.y,f=r.x-o.x,P=(r.y-o.y)*d-f*y;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 a=!0,p=this.lverts.next,c=p;for(p=p.next;p!=null&&a;){let h=p,u=this.lverts.next,x=u.next;for(;x!=null&&a;){let m=x;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,x=x.next}if(a){let m=this.lverts.next;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e))}c=h,p=p.next}if(a){let h=this.lverts.next,u=this.lverts.next,x=u.next;for(;x!=null&&a;){let m=x;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,x=x.next}if(a){let m=this.lverts.next;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,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,s,i){let l=e.x-n.x,o=e.y-n.y,r=t.x-e.x,a=t.y-e.y,p=s.x-n.x,c=s.y-n.y,h=a*p-r*c;if(h*h>i.Config.epsilon){h=1/h;let u=(c*l-p*o)*h;if(u>i.Config.epsilon&&u<1-i.Config.epsilon){let x=(a*l-r*o)*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,o=t;t=t.next,l.x=e.posx+(e.axisy*o.x-e.axisx*o.y),l.y=e.posy+(o.x*e.axisx+o.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,o=i.y*s.x-i.x*s.y,r=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+=o*r,t+=o,this.area+=i.x*(l.y-s.y),s=i,i=l,n=n.next;let a=n;o=i.y*s.x-i.x*s.y,r=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+=o*r,t+=o,this.area+=i.x*(a.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=mt._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,o=i.next;for(;o!=null;){let r=o,a=n.elt;n=n.next,s+=a.length;let p=r.x-l.x,c=r.y-l.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let h=-(l.y*a.lnormx-l.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(h>0){let u=h>1?1:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let d=a.lnormy*l.x-a.lnormx*l.y,y=a.lnormy*x-a.lnormx*m,f=(y*y*y-d*d*d)/(3*(y-d));t+=f*u*a.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let d=a.lnormy*x-a.lnormx*m,y=a.lnormy*r.x-a.lnormx*r.y,f=(y*y*y-d*d*d)/(3*(y-d));t+=f*e.Config.fluidVacuumDrag*(1-u)*a.length*e.Config.fluidAngularDrag}l=r,o=o.next}{let r=this.lverts.next,a=n.elt;s+=a.length;let p=r.x-l.x,c=r.y-l.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let h=-(l.y*a.lnormx-l.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(h>0){let u=h>1?1:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let d=a.lnormy*l.x-a.lnormx*l.y,y=a.lnormy*x-a.lnormx*m,f=(y*y*y-d*d*d)/(3*(y-d));t+=f*u*a.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let d=a.lnormy*x-a.lnormx*m,y=a.lnormy*r.x-a.lnormx*r.y,f=(y*y*y-d*d*d)/(3*(y-d));t+=f*e.Config.fluidVacuumDrag*(1-u)*a.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 r=t;e+=s.x*(r.y-n.y);let a=r.y*s.x-r.x*s.y;this.localCOMx+=(s.x+r.x)*a,this.localCOMy+=(s.y+r.y)*a,n=s,s=r,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 o=t;e+=s.x*(o.y-n.y),l=o.y*s.x-o.x*s.y,this.localCOMx+=(s.x+o.x)*l,this.localCOMy+=(s.y+o.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=mt._zpp,t=mt._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=mt._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}};mt._nape=null,mt._zpp=null,mt._initialized=!1;var ei=mt;var Nn=class Nn{constructor(){this.radius=0;this.halfLength=0;this.outer_zn=null;this.spine1x=0;this.spine1y=0;this.spine2x=0;this.spine2y=0;this.radius=0,this.halfLength=0,this.outer_zn=null,this._initShape(2),this.capsule=this,this.zip_localCOM=!1}static _init(){if(Nn._initialized)return;Nn._initialized=!0;let t=Nn._zpp.shape.ZPP_Shape.prototype,n=Nn.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.wake())}invalidate_halfLength(){this.invalidate_area_inertia(),this.invalidate_angDrag(),this.zip_aabb=!0,this.zip_sweepRadius=!0,this.body!=null&&(this.body.zip_aabb=!0,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 Capsule added to a static Body whilst within a Space")}setupLocalCOM(){let e=Nn._zpp,t=Nn._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.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy));let c=this.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),this.worldCOMx=c.posx+(c.axisy*this.localCOMx-c.axisx*this.localCOMy),this.worldCOMy=c.posy+(this.localCOMx*c.axisx+this.localCOMy*c.axisy)}let e=this.body;if(e!=null){e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let c=e.axisy*this.halfLength,h=e.axisx*this.halfLength;this.spine1x=this.worldCOMx-c,this.spine1y=this.worldCOMy-h,this.spine2x=this.worldCOMx+c,this.spine2y=this.worldCOMy+h}let t=this.radius,n=this.spine1x-t,s=this.spine2x-t,i=this.spine1y-t,l=this.spine2y-t,o=this.spine1x+t,r=this.spine2x+t,a=this.spine1y+t,p=this.spine2y+t;this.aabb.minx=n<s?n:s,this.aabb.miny=i<l?i:l,this.aabb.maxx=o>r?o:r,this.aabb.maxy=a>p?a:p}_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);let t=e.axisy*this.halfLength,n=e.axisx*this.halfLength;this.spine1x=this.worldCOMx-t,this.spine1y=this.worldCOMy-n,this.spine2x=this.worldCOMx+t,this.spine2y=this.worldCOMy+n;let s=this.radius,i=this.spine1x-s,l=this.spine2x-s,o=this.spine1y-s,r=this.spine2y-s,a=this.spine1x+s,p=this.spine2x+s,c=this.spine1y+s,h=this.spine2y+s;this.aabb.minx=i<l?i:l,this.aabb.miny=o<r?o:r,this.aabb.maxx=a>p?a:p,this.aabb.maxy=c>h?c:h}__validate_sweepRadius(){let e=Math.sqrt(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy);this.sweepCoef=e+this.halfLength,this.sweepRadius=this.sweepCoef+this.radius}__validate_area_inertia(){let e=this.radius,t=this.halfLength,n=e*e;this.area=Math.PI*n+4*t*e;let s=2*t*(2*e)*(2*e*(2*e)+2*t*(2*t))/12,i=Math.PI*n*(n*.5+t*t);this.inertia=(s+i)/this.area+(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy)}__validate_angDrag(){let e=Nn._nape,t=this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy,n=this.radius*this.radius,s=this.halfLength*this.halfLength,i=this.material.dynamicFriction*e.Config.fluidAngularDragFriction;this.angDrag=(t+2*n+s)*i+.5*e.Config.fluidAngularDrag*(1+e.Config.fluidVacuumDrag)*t,this.angDrag/=2*(t+.5*n+s/3)}__scale(e,t){let n=((e<0?-e:e)+(t<0?-t:t))/2,s=n<0?-n:n;this.radius*=s,this.halfLength*=s,this.invalidate_radius(),this.invalidate_halfLength(),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);let n=Math.sqrt(t);this.radius*=n,this.halfLength*=n;let s=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=s,this.invalidate_radius(),this.invalidate_halfLength(),this.invalidate_localCOM()}__copy(){let e=Nn._nape,t=2*(this.halfLength+this.radius),n=2*this.radius,s=new e.shape.Capsule(t,n).zpp_inner_zn;return s.localCOMx=this.localCOMx,s.localCOMy=this.localCOMy,s.zip_localCOM=!1,s}};Nn._nape=null,Nn._zpp=null,Nn._initialized=!1;var ti=Nn;var gi=class gi{constructor(){this.space=null;this.is_sweep=!1;this.is_spatial_hash=!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.is_spatial_hash=!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 o=1;l.localCOMx+=l.lverts.next.next.x*o,l.localCOMy+=l.lverts.next.next.y*o;let r=.5;l.localCOMx*=r,l.localCOMy*=r}else{l.localCOMx=0,l.localCOMy=0;let o=0,r=l.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let d=r;o+=p.x*(d.y-a.y);let y=d.y*p.x-d.x*p.y;l.localCOMx+=(p.x+d.x)*y,l.localCOMy+=(p.y+d.y)*y,a=p,p=d,r=r.next}r=l.lverts.next;let c=r;o+=p.x*(c.y-a.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,a=p,p=c,r=r.next;let u=r;o+=p.x*(u.y-a.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,o=1/(3*o);let m=o;l.localCOMx*=m,l.localCOMy*=m}}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 if(e.type==2)e.capsule.__validate_aabb();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,o=t.gverts.next;for(;o!=null;){let r=o,a=l;l=l.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 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 a=i.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,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let b=c;p+=u.x*(b.y-h.y);let P=b.y*u.x-b.x*u.y;a.localCOMx+=(u.x+b.x)*P,a.localCOMy+=(u.y+b.y)*P,h=u,u=b,c=c.next}c=a.lverts.next;let x=c;p+=u.x*(x.y-h.y);let m=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*m,a.localCOMy+=(u.y+x.y)*m,h=u,u=x,c=c.next;let d=c;p+=u.x*(d.y-h.y);let y=d.y*u.x-d.x*u.y;a.localCOMx+=(u.x+d.x)*y,a.localCOMy+=(u.y+d.y)*y,p=1/(3*p);let f=p;a.localCOMx*=f,a.localCOMy*=f}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.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,o=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-o,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+o}else if(e.type==2)e.capsule.__validate_aabb();else{let i=e.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let a=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=a;a=a.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 o=i.gverts.next.next;for(;o!=null;){let r=o;r.x<i.aabb.minx&&(i.aabb.minx=r.x),r.x>i.aabb.maxx&&(i.aabb.maxx=r.x),r.y<i.aabb.miny&&(i.aabb.miny=r.y),r.y>i.aabb.maxy&&(i.aabb.maxy=r.y),o=o.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=gi._zpp,n=gi._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 l=this.aabbShape.zpp_inner.aabb,o=(e.maxx-e.minx)/(l.maxx-l.minx),r=(e.maxy-e.miny)/(l.maxy-l.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,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 m=c.zpp_inner;m._invalidate!=null&&m._invalidate();let d=this.matrix;if(r!==r)throw new Error("Error: Mat23::d cannot be NaN");d.zpp_inner.d=r;let y=d.zpp_inner;y._invalidate!=null&&y._invalidate();let f=this.matrix,b=e.minx-o*l.minx;if(b!==b)throw new Error("Error: Mat23::tx cannot be NaN");f.zpp_inner.tx=b;let P=f.zpp_inner;P._invalidate!=null&&P._invalidate();let k=this.matrix,_=e.miny-r*l.miny;if(_!==_)throw new Error("Error: Mat23::ty cannot be NaN");k.zpp_inner.ty=_;let z=k.zpp_inner;z._invalidate!=null&&z._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 m=h;c+=x.x*(m.y-u.y);let d=m.y*x.x-m.x*x.y;p.localCOMx+=(x.x+m.x)*d,p.localCOMy+=(x.y+m.y)*d,u=x,x=m,h=h.next;let y=h;c+=x.x*(y.y-u.y);let f=y.y*x.x-y.x*x.y;p.localCOMx+=(x.x+y.x)*f,p.localCOMy+=(x.y+y.y)*f,c=1/(3*c);let b=c;p.localCOMx*=b,p.localCOMy*=b}}l.wrap_localCOM!=null&&(l.wrap_localCOM.zpp_inner.x=l.localCOMx,l.wrap_localCOM.zpp_inner.y=l.localCOMy)}let a=l.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.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 o=l.radius,r=l.radius;l.aabb.minx=l.worldCOMx-o,l.aabb.miny=l.worldCOMy-r,l.aabb.maxx=l.worldCOMx+o,l.aabb.maxy=l.worldCOMy+r}else{let l=s.polygon;if(l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let a=l.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.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 o=l.gverts.next;l.aabb.minx=o.x,l.aabb.miny=o.y,l.aabb.maxx=o.x,l.aabb.maxy=o.y;let r=l.gverts.next.next;for(;r!=null;){let a=r;a.x<l.aabb.minx&&(l.aabb.minx=a.x),a.x>l.aabb.maxx&&(l.aabb.maxx=a.x),a.y<l.aabb.miny&&(l.aabb.miny=a.y),a.y>l.aabb.maxy&&(l.aabb.maxy=a.y),r=r.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 m=x,d=u;u=u.next,m.x=i.body.posx+(i.body.axisy*d.x-i.body.axisx*d.y),m.y=i.body.posy+(d.x*i.body.axisx+d.y*i.body.axisy),x=x.next}}let o=i.edges.head,r=i.gverts.next,a=r;for(r=r.next;r!=null;){let h=r,u=o.elt;o=o.next,u.gp0=a,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,a=h,r=r.next}let p=i.gverts.next,c=o.elt;o=o.next,c.gp0=a,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=gi._zpp,i=gi._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 r=new i.phys.Body(s.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(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=a,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(),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 m=c.zpp_inner;if(m._validate!=null&&m._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 d=c.zpp_inner;d._validate!=null&&d._validate(),x=c.zpp_inner.y==p}else x=!1;if(!x){c.zpp_inner.x=a,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);r.zpp_inner.reverse_flag?r.push(h):r.unshift(h)}else{let o=this.circShape.zpp_inner.circle,r=n/o.radius;this.matrix==null&&(this.matrix=new i.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 h=p.zpp_inner.d;if(h!==h)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=h;let u=a.zpp_inner;u._invalidate!=null&&u._invalidate();let x=this.matrix,m=this.matrix;m.zpp_inner.c=0;let d=m.zpp_inner;d._invalidate!=null&&d._invalidate();let y=m.zpp_inner.c;if(y!==y)throw new Error("Error: Mat23::b cannot be NaN");x.zpp_inner.b=y;let f=x.zpp_inner;f._invalidate!=null&&f._invalidate();let b=this.matrix,P=e-r*o.localCOMx;if(P!==P)throw new Error("Error: Mat23::tx cannot be NaN");b.zpp_inner.tx=P;let k=b.zpp_inner;k._invalidate!=null&&k._invalidate();let _=this.matrix,z=t-r*o.localCOMy;if(z!==z)throw new Error("Error: Mat23::ty cannot be NaN");_.zpp_inner.ty=z;let C=_.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 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 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 m=u;for(u=u.next;u!=null;){let k=u;h+=m.x*(k.y-x.y);let _=k.y*m.x-k.x*m.y;c.localCOMx+=(m.x+k.x)*_,c.localCOMy+=(m.y+k.y)*_,x=m,m=k,u=u.next}u=c.lverts.next;let d=u;h+=m.x*(d.y-x.y);let y=d.y*m.x-d.x*m.y;c.localCOMx+=(m.x+d.x)*y,c.localCOMy+=(m.y+d.y)*y,x=m,m=d,u=u.next;let f=u;h+=m.x*(f.y-x.y);let b=f.y*m.x-f.x*m.y;c.localCOMx+=(m.x+f.x)*b,c.localCOMy+=(m.y+f.y)*b,h=1/(3*h);let P=h;c.localCOMx*=P,c.localCOMy*=P}}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,h=o.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),u.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),h=h.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,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 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 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 a=i,p=s.elt;s=s.next,p.gp0=l,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,l=a,i=i.next}let o=t.gverts.next,r=s.elt;s=s.next,r.gp0=l,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 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 o=1;l.localCOMx+=l.lverts.next.next.x*o,l.localCOMy+=l.lverts.next.next.y*o;let r=.5;l.localCOMx*=r,l.localCOMy*=r}else{l.localCOMx=0,l.localCOMy=0;let o=0,r=l.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let d=r;o+=p.x*(d.y-a.y);let y=d.y*p.x-d.x*p.y;l.localCOMx+=(p.x+d.x)*y,l.localCOMy+=(p.y+d.y)*y,a=p,p=d,r=r.next}r=l.lverts.next;let c=r;o+=p.x*(c.y-a.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,a=p,p=c,r=r.next;let u=r;o+=p.x*(u.y-a.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,o=1/(3*o);let m=o;l.localCOMx*=m,l.localCOMy*=m}}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,o=t.gverts.next;for(;o!=null;){let r=o,a=l;l=l.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 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 o=i;for(i=i.next;i!=null;){let u=i;s+=o.x*(u.y-l.y);let x=u.y*o.x-u.x*o.y;n.localCOMx+=(o.x+u.x)*x,n.localCOMy+=(o.y+u.y)*x,l=o,o=u,i=i.next}i=n.lverts.next;let r=i;s+=o.x*(r.y-l.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,l=o,o=r,i=i.next;let p=i;s+=o.x*(p.y-l.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,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}};gi._zpp=null,gi._nape=null;var Tn=gi;var Ae=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}};Ae.zpp_pool=null;var st=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;this.gprev=null}alloc(){}free(){this.n1=this.n2=null,this.sleeping=!1,this.gprev=null}};st.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 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=Ae.zpp_pool,Ae.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 a=n.child1,p=n.child2,c=n.aabb,h=(c.maxx-c.minx+(c.maxy-c.miny))*2,u=Zt.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 m=Zt.tmpaabb,d=(m.maxx-m.minx+(m.maxy-m.miny))*2,y=2*d,f=2*(d-h),b=Zt.tmpaabb,P=a.aabb;b.minx=t.minx<P.minx?t.minx:P.minx,b.miny=t.miny<P.miny?t.miny:P.miny,b.maxx=t.maxx>P.maxx?t.maxx:P.maxx,b.maxy=t.maxy>P.maxy?t.maxy:P.maxy;let k;if(a.child1==null){let w=Zt.tmpaabb;k=(w.maxx-w.minx+(w.maxy-w.miny))*2+f}else{let w=a.aabb,g=(w.maxx-w.minx+(w.maxy-w.miny))*2,O=Zt.tmpaabb;k=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+f}let _=Zt.tmpaabb,z=p.aabb;_.minx=t.minx<z.minx?t.minx:z.minx,_.miny=t.miny<z.miny?t.miny:z.miny,_.maxx=t.maxx>z.maxx?t.maxx:z.maxx,_.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let C;if(p.child1==null){let w=Zt.tmpaabb;C=(w.maxx-w.minx+(w.maxy-w.miny))*2+f}else{let w=p.aabb,g=(w.maxx-w.minx+(w.maxy-w.miny))*2,O=Zt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+f}if(y<k&&y<C)break;n=k<C?a:p}let s=n,i=s.parent,l;Ae.zpp_pool==null?l=new Ae:(l=Ae.zpp_pool,Ae.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 o=l.aabb,r=s.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,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,y=n.child2,f=y.height-d.height;if(f>1){let b=y.child1,P=y.child2;if(y.child1=n,y.parent=n.parent,n.parent=y,y.parent!=null?y.parent.child1==n?y.parent.child1=y:y.parent.child2=y:this.root=y,b.height>P.height){y.child2=b,n.child2=P,P.parent=n;let k=n.aabb,_=d.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=n.aabb,g=b.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=b.height;y.height=1+(M>N?M:N)}else{y.child2=P,n.child2=b,b.parent=n;let k=n.aabb,_=d.aabb,z=b.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=n.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=b.height;n.height=1+(O>E?O:E);let M=n.height,N=P.height;y.height=1+(M>N?M:N)}n=y}else if(f<-1){let b=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,b.height>P.height){d.child2=b,n.child1=P,P.parent=n;let k=n.aabb,_=y.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=n.aabb,g=b.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=b.height;d.height=1+(M>N?M:N)}else{d.child2=P,n.child1=b,b.parent=n;let k=n.aabb,_=y.aabb,z=b.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=n.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=b.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 a=n.child1,p=n.child2,c=a.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=a.aabb,m=p.aabb;u.minx=x.minx<m.minx?x.minx:m.minx,u.miny=x.miny<m.miny?x.miny:m.miny,u.maxx=x.maxx>m.maxx?x.maxx:m.maxx,u.maxy=x.maxy>m.maxy?x.maxy:m.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,h=(c.maxx-c.minx+(c.maxy-c.miny))*2,u=Zt.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 m=Zt.tmpaabb,d=(m.maxx-m.minx+(m.maxy-m.miny))*2,y=2*d,f=2*(d-h),b=Zt.tmpaabb,P=a.aabb;b.minx=t.minx<P.minx?t.minx:P.minx,b.miny=t.miny<P.miny?t.miny:P.miny,b.maxx=t.maxx>P.maxx?t.maxx:P.maxx,b.maxy=t.maxy>P.maxy?t.maxy:P.maxy;let k;if(a.child1==null){let w=Zt.tmpaabb;k=(w.maxx-w.minx+(w.maxy-w.miny))*2+f}else{let w=a.aabb,g=(w.maxx-w.minx+(w.maxy-w.miny))*2,O=Zt.tmpaabb;k=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+f}let _=Zt.tmpaabb,z=p.aabb;_.minx=t.minx<z.minx?t.minx:z.minx,_.miny=t.miny<z.miny?t.miny:z.miny,_.maxx=t.maxx>z.maxx?t.maxx:z.maxx,_.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let C;if(p.child1==null){let w=Zt.tmpaabb;C=(w.maxx-w.minx+(w.maxy-w.miny))*2+f}else{let w=p.aabb,g=(w.maxx-w.minx+(w.maxy-w.miny))*2,O=Zt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+f}if(y<k&&y<C)break;n=k<C?a:p}let s=n,i=s.parent,l;Ae.zpp_pool==null?l=new Ae:(l=Ae.zpp_pool,Ae.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 o=l.aabb,r=s.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,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,y=n.child2,f=y.height-d.height;if(f>1){let b=y.child1,P=y.child2;if(y.child1=n,y.parent=n.parent,n.parent=y,y.parent!=null?y.parent.child1==n?y.parent.child1=y:y.parent.child2=y:this.root=y,b.height>P.height){y.child2=b,n.child2=P,P.parent=n;let k=n.aabb,_=d.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=n.aabb,g=b.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=b.height;y.height=1+(M>N?M:N)}else{y.child2=P,n.child2=b,b.parent=n;let k=n.aabb,_=d.aabb,z=b.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=n.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=b.height;n.height=1+(O>E?O:E);let M=n.height,N=P.height;y.height=1+(M>N?M:N)}n=y}else if(f<-1){let b=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,b.height>P.height){d.child2=b,n.child1=P,P.parent=n;let k=n.aabb,_=y.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=n.aabb,g=b.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=P.height;n.height=1+(O>E?O:E);let M=n.height,N=b.height;d.height=1+(M>N?M:N)}else{d.child2=P,n.child1=b,b.parent=n;let k=n.aabb,_=y.aabb,z=b.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=n.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=b.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 a=n.child1,p=n.child2,c=a.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=a.aabb,m=p.aabb;u.minx=x.minx<m.minx?x.minx:m.minx,u.miny=x.miny<m.miny?x.miny:m.miny,u.maxx=x.maxx>m.maxx?x.maxx:m.maxx,u.maxy=x.maxy>m.maxy?x.maxy:m.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=Ae.zpp_pool,Ae.zpp_pool=i;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let d=o.child1,y=o.child2,f=y.height-d.height;if(f>1){let b=y.child1,P=y.child2;if(y.child1=o,y.parent=o.parent,o.parent=y,y.parent!=null?y.parent.child1==o?y.parent.child1=y:y.parent.child2=y:this.root=y,b.height>P.height){y.child2=b,o.child2=P,P.parent=o;let k=o.aabb,_=d.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=o.aabb,g=b.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=P.height;o.height=1+(O>E?O:E);let M=o.height,N=b.height;y.height=1+(M>N?M:N)}else{y.child2=P,o.child2=b,b.parent=o;let k=o.aabb,_=d.aabb,z=b.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=o.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=b.height;o.height=1+(O>E?O:E);let M=o.height,N=P.height;y.height=1+(M>N?M:N)}o=y}else if(f<-1){let b=d.child1,P=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,b.height>P.height){d.child2=b,o.child1=P,P.parent=o;let k=o.aabb,_=y.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=o.aabb,g=b.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=P.height;o.height=1+(O>E?O:E);let M=o.height,N=b.height;d.height=1+(M>N?M:N)}else{d.child2=P,o.child1=b,b.parent=o;let k=o.aabb,_=y.aabb,z=b.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=o.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=b.height;o.height=1+(O>E?O:E);let M=o.height,N=P.height;d.height=1+(M>N?M:N)}o=d}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,h=a.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=a.height,m=p.height;r.height=1+(x>m?x:m),o=r.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=Ae.zpp_pool,Ae.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=Ae.zpp_pool,Ae.zpp_pool=i;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let d=o.child1,y=o.child2,f=y.height-d.height;if(f>1){let b=y.child1,P=y.child2;if(y.child1=o,y.parent=o.parent,o.parent=y,y.parent!=null?y.parent.child1==o?y.parent.child1=y:y.parent.child2=y:this.root=y,b.height>P.height){y.child2=b,o.child2=P,P.parent=o;let k=o.aabb,_=d.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=o.aabb,g=b.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=P.height;o.height=1+(O>E?O:E);let M=o.height,N=b.height;y.height=1+(M>N?M:N)}else{y.child2=P,o.child2=b,b.parent=o;let k=o.aabb,_=d.aabb,z=b.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=y.aabb,w=o.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=d.height,E=b.height;o.height=1+(O>E?O:E);let M=o.height,N=P.height;y.height=1+(M>N?M:N)}o=y}else if(f<-1){let b=d.child1,P=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,b.height>P.height){d.child2=b,o.child1=P,P.parent=o;let k=o.aabb,_=y.aabb,z=P.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=o.aabb,g=b.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=P.height;o.height=1+(O>E?O:E);let M=o.height,N=b.height;d.height=1+(M>N?M:N)}else{d.child2=P,o.child1=b,b.parent=o;let k=o.aabb,_=y.aabb,z=b.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy;let C=d.aabb,w=o.aabb,g=P.aabb;C.minx=w.minx<g.minx?w.minx:g.minx,C.miny=w.miny<g.miny?w.miny:g.miny,C.maxx=w.maxx>g.maxx?w.maxx:g.maxx,C.maxy=w.maxy>g.maxy?w.maxy:g.maxy;let O=y.height,E=b.height;o.height=1+(O>E?O:E);let M=o.height,N=P.height;d.height=1+(M>N?M:N)}o=d}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,h=a.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=a.height,m=p.height;r.height=1+(x>m?x:m),o=r.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=Ae.zpp_pool,Ae.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 o=e.aabb,r=t.aabb,a=l.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,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 m=e.height,d=i.height;n.height=1+(m>d?m:d)}else{n.child2=l,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,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 m=e.height,d=l.height;n.height=1+(m>d?m: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 o=e.aabb,r=n.aabb,a=l.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,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 m=e.height,d=i.height;t.height=1+(m>d?m:d)}else{t.child2=l,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,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 m=e.height,d=l.height;t.height=1+(m>d?m:d)}return t}else return e}}};Zt.tmpaabb=null;var $e=Zt;var we=class we extends Tn{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}_linkPair(t){t.gprev=null,t.next=this.pairs,this.pairs!=null&&(this.pairs.gprev=t),this.pairs=t}_unlinkPair(t){t.gprev!=null?t.gprev.next=t.next:this.pairs=t.next,t.next!=null&&(t.next.gprev=t.gprev),t.gprev=null,t.next=null}dyn(t){return t.body.type==1?!1:!t.body.component.sleeping}__insert(t){let n;Ae.zpp_pool==null?n=new Ae:(n=Ae.zpp_pool,Ae.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 l=null,o=this.syncs;for(;o!=null&&o!=n;)l=o,o=o.snext;l==null?this.syncs=o.snext:l.snext=o.snext,o.snext=null,n.synced=!1}if(n.moved){let l=null,o=this.moves;for(;o!=null&&o!=n;)l=o,o=o.mnext;l==null?this.moves=o.mnext:l.mnext=o.mnext,o.mnext=null,n.moved=!1}for(;t.pairs.head!=null;){let l=t.pairs.pop_unsafe();l.sleeping||this._unlinkPair(l),l.n1==n?l.n2.shape.pairs.remove(l):l.n1.shape.pairs.remove(l),l.arb!=null&&(l.arb.pair=null),l.arb=null,l.n1=l.n2=null,l.sleeping=!1,l.gprev=null,l.next=st.zpp_pool,st.zpp_pool=l}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=Ae.zpp_pool,Ae.zpp_pool=s}__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 a=i.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,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let b=c;p+=u.x*(b.y-h.y);let P=b.y*u.x-b.x*u.y;a.localCOMx+=(u.x+b.x)*P,a.localCOMy+=(u.y+b.y)*P,h=u,u=b,c=c.next}c=a.lverts.next;let x=c;p+=u.x*(x.y-h.y);let m=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*m,a.localCOMy+=(u.y+x.y)*m,h=u,u=x,c=c.next;let d=c;p+=u.x*(d.y-h.y);let y=d.y*u.x-d.x*u.y;a.localCOMx+=(u.x+d.x)*y,a.localCOMy+=(u.y+d.y)*y,p=1/(3*p);let f=p;a.localCOMx*=f,a.localCOMy*=f}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.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,o=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-o,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+o}else{let i=t.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let a=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=a;a=a.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 o=i.gverts.next.next;for(;o!=null;){let r=o;r.x<i.aabb.minx&&(i.aabb.minx=r.x),r.x>i.aabb.maxx&&(i.aabb.maxx=r.x),r.y<i.aabb.miny&&(i.aabb.miny=r.y),r.y>i.aabb.maxy&&(i.aabb.maxy=r.y),o=o.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 r=t.dyn?this.dtree:this.stree;if(t==r.root)r.root=null;else{let a=t.parent,p=a.parent,c=a.child1==t?a.child2:a.child1;if(p!=null){p.child1==a?p.child1=c:p.child2=c,c.parent=p;let h=a;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=Ae.zpp_pool,Ae.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else{let _=x.child1,z=x.child2,C=z.height-_.height;if(C>1){let w=z.child1,g=z.child2;if(z.child1=x,z.parent=x.parent,x.parent=z,z.parent!=null?z.parent.child1==x?z.parent.child1=z:z.parent.child2=z:r.root=z,w.height>g.height){z.child2=w,x.child2=g,g.parent=x;let O=x.aabb,E=_.aabb,M=g.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=z.aabb,Z=x.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=g.height;x.height=1+(S>L?S:L);let T=x.height,G=w.height;z.height=1+(T>G?T:G)}else{z.child2=g,x.child2=w,w.parent=x;let O=x.aabb,E=_.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=z.aabb,Z=x.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=w.height;x.height=1+(S>L?S:L);let T=x.height,G=g.height;z.height=1+(T>G?T:G)}x=z}else if(C<-1){let w=_.child1,g=_.child2;if(_.child1=x,_.parent=x.parent,x.parent=_,_.parent!=null?_.parent.child1==x?_.parent.child1=_:_.parent.child2=_:r.root=_,w.height>g.height){_.child2=w,x.child1=g,g.parent=x;let O=x.aabb,E=z.aabb,M=g.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=_.aabb,Z=x.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=g.height;x.height=1+(S>L?S:L);let T=x.height,G=w.height;_.height=1+(T>G?T:G)}else{_.child2=g,x.child1=w,w.parent=x;let O=x.aabb,E=z.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=_.aabb,Z=x.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=w.height;x.height=1+(S>L?S:L);let T=x.height,G=g.height;_.height=1+(T>G?T:G)}x=_}else x=x}let m=x.child1,d=x.child2,y=x.aabb,f=m.aabb,b=d.aabb;y.minx=f.minx<b.minx?f.minx:b.minx,y.miny=f.miny<b.miny?f.miny:b.miny,y.maxx=f.maxx>b.maxx?f.maxx:b.maxx,y.maxy=f.maxy>b.maxy?f.maxy:b.maxy;let P=m.height,k=d.height;x.height=1+(P>k?P:k),x=x.parent}}else{r.root=c,c.parent=null;let h=a;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=Ae.zpp_pool,Ae.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 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 h=r.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,m=x;x=x.next;let d=x;for(x=x.next;x!=null;){let _=x;u+=d.x*(_.y-m.y);let z=_.y*d.x-_.x*d.y;h.localCOMx+=(d.x+_.x)*z,h.localCOMy+=(d.y+_.y)*z,m=d,d=_,x=x.next}x=h.lverts.next;let y=x;u+=d.x*(y.y-m.y);let f=y.y*d.x-y.x*d.y;h.localCOMx+=(d.x+y.x)*f,h.localCOMy+=(d.y+y.y)*f,m=d,d=y,x=x.next;let b=x;u+=d.x*(b.y-m.y);let P=b.y*d.x-b.x*d.y;h.localCOMx+=(d.x+b.x)*P,h.localCOMy+=(d.y+b.y)*P,u=1/(3*u);let k=u;h.localCOMx*=k,h.localCOMy*=k}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.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,p=r.radius;r.aabb.minx=r.worldCOMx-a,r.aabb.miny=r.worldCOMy-p,r.aabb.maxx=r.worldCOMx+a,r.aabb.maxy=r.worldCOMy+p}else{let r=s.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=r.lverts.next,u=r.gverts.next;for(;u!=null;){let x=u,m=h;h=h.next,x.x=r.body.posx+(r.body.axisy*m.x-r.body.axisx*m.y),x.y=r.body.posy+(m.x*r.body.axisx+m.y*r.body.axisy),u=u.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 p=r.gverts.next.next;for(;p!=null;){let c=p;c.x<r.aabb.minx&&(r.aabb.minx=c.x),c.x>r.aabb.maxx&&(r.aabb.maxx=c.x),c.y<r.aabb.miny&&(r.aabb.miny=c.y),c.y>r.aabb.maxy&&(r.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 o=(t.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(o.root==null)o.root=t,o.root.parent=null;else{let r=t.aabb,a=o.root;for(;a.child1!=null;){let m=a.child1,d=a.child2,y=a.aabb,f=(y.maxx-y.minx+(y.maxy-y.miny))*2,b=$e.tmpaabb,P=a.aabb;b.minx=P.minx<r.minx?P.minx:r.minx,b.miny=P.miny<r.miny?P.miny:r.miny,b.maxx=P.maxx>r.maxx?P.maxx:r.maxx,b.maxy=P.maxy>r.maxy?P.maxy:r.maxy;let k=$e.tmpaabb,_=(k.maxx-k.minx+(k.maxy-k.miny))*2,z=2*_,C=2*(_-f),w=$e.tmpaabb,g=m.aabb;w.minx=r.minx<g.minx?r.minx:g.minx,w.miny=r.miny<g.miny?r.miny:g.miny,w.maxx=r.maxx>g.maxx?r.maxx:g.maxx,w.maxy=r.maxy>g.maxy?r.maxy:g.maxy;let O;if(m.child1==null){let Z=$e.tmpaabb;O=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=m.aabb,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=$e.tmpaabb;O=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}let E=$e.tmpaabb,M=d.aabb;E.minx=r.minx<M.minx?r.minx:M.minx,E.miny=r.miny<M.miny?r.miny:M.miny,E.maxx=r.maxx>M.maxx?r.maxx:M.maxx,E.maxy=r.maxy>M.maxy?r.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,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=$e.tmpaabb;N=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}if(z<O&&z<N)break;a=O<N?m:d}let p=a,c=p.parent,h;Ae.zpp_pool==null?h=new Ae:(h=Ae.zpp_pool,Ae.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=r.minx<x.minx?r.minx:x.minx,u.miny=r.miny<x.miny?r.miny:x.miny,u.maxx=r.maxx>x.maxx?r.maxx:x.maxx,u.maxy=r.maxy>x.maxy?r.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,o.root=h),a=t.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else{let _=a.child1,z=a.child2,C=z.height-_.height;if(C>1){let w=z.child1,g=z.child2;if(z.child1=a,z.parent=a.parent,a.parent=z,z.parent!=null?z.parent.child1==a?z.parent.child1=z:z.parent.child2=z:o.root=z,w.height>g.height){z.child2=w,a.child2=g,g.parent=a;let O=a.aabb,E=_.aabb,M=g.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=z.aabb,Z=a.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=g.height;a.height=1+(S>L?S:L);let T=a.height,G=w.height;z.height=1+(T>G?T:G)}else{z.child2=g,a.child2=w,w.parent=a;let O=a.aabb,E=_.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=z.aabb,Z=a.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=w.height;a.height=1+(S>L?S:L);let T=a.height,G=g.height;z.height=1+(T>G?T:G)}a=z}else if(C<-1){let w=_.child1,g=_.child2;if(_.child1=a,_.parent=a.parent,a.parent=_,_.parent!=null?_.parent.child1==a?_.parent.child1=_:_.parent.child2=_:o.root=_,w.height>g.height){_.child2=w,a.child1=g,g.parent=a;let O=a.aabb,E=z.aabb,M=g.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=_.aabb,Z=a.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=g.height;a.height=1+(S>L?S:L);let T=a.height,G=w.height;_.height=1+(T>G?T:G)}else{_.child2=g,a.child1=w,w.parent=a;let O=a.aabb,E=z.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=_.aabb,Z=a.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=w.height;a.height=1+(S>L?S:L);let T=a.height,G=g.height;_.height=1+(T>G?T:G)}a=_}else a=a}let m=a.child1,d=a.child2,y=m.height,f=d.height;a.height=1+(y>f?y:f);let b=a.aabb,P=m.aabb,k=d.aabb;b.minx=P.minx<k.minx?P.minx:k.minx,b.miny=P.miny<k.miny?P.miny:k.miny,b.maxx=P.maxx>k.maxx?P.maxx:k.maxx,b.maxy=P.maxy>k.maxy?P.maxy:k.maxy,a=a.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 r=n.dyn?this.dtree:this.stree;if(n==r.root)r.root=null;else{let a=n.parent,p=a.parent,c=a.child1==n?a.child2:a.child1;if(p!=null){p.child1==a?p.child1=c:p.child2=c,c.parent=p;let h=a;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=Ae.zpp_pool,Ae.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else{let _=x.child1,z=x.child2,C=z.height-_.height;if(C>1){let w=z.child1,g=z.child2;if(z.child1=x,z.parent=x.parent,x.parent=z,z.parent!=null?z.parent.child1==x?z.parent.child1=z:z.parent.child2=z:r.root=z,w.height>g.height){z.child2=w,x.child2=g,g.parent=x;let O=x.aabb,E=_.aabb,M=g.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=z.aabb,Z=x.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=g.height;x.height=1+(S>L?S:L);let T=x.height,G=w.height;z.height=1+(T>G?T:G)}else{z.child2=g,x.child2=w,w.parent=x;let O=x.aabb,E=_.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=z.aabb,Z=x.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=w.height;x.height=1+(S>L?S:L);let T=x.height,G=g.height;z.height=1+(T>G?T:G)}x=z}else if(C<-1){let w=_.child1,g=_.child2;if(_.child1=x,_.parent=x.parent,x.parent=_,_.parent!=null?_.parent.child1==x?_.parent.child1=_:_.parent.child2=_:r.root=_,w.height>g.height){_.child2=w,x.child1=g,g.parent=x;let O=x.aabb,E=z.aabb,M=g.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=_.aabb,Z=x.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=g.height;x.height=1+(S>L?S:L);let T=x.height,G=w.height;_.height=1+(T>G?T:G)}else{_.child2=g,x.child1=w,w.parent=x;let O=x.aabb,E=z.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=_.aabb,Z=x.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=w.height;x.height=1+(S>L?S:L);let T=x.height,G=g.height;_.height=1+(T>G?T:G)}x=_}else x=x}let m=x.child1,d=x.child2,y=x.aabb,f=m.aabb,b=d.aabb;y.minx=f.minx<b.minx?f.minx:b.minx,y.miny=f.miny<b.miny?f.miny:b.miny,y.maxx=f.maxx>b.maxx?f.maxx:b.maxx,y.maxy=f.maxy>b.maxy?f.maxy:b.maxy;let P=m.height,k=d.height;x.height=1+(P>k?P:k),x=x.parent}}else{r.root=c,c.parent=null;let h=a;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=Ae.zpp_pool,Ae.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 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 h=r.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,m=x;x=x.next;let d=x;for(x=x.next;x!=null;){let _=x;u+=d.x*(_.y-m.y);let z=_.y*d.x-_.x*d.y;h.localCOMx+=(d.x+_.x)*z,h.localCOMy+=(d.y+_.y)*z,m=d,d=_,x=x.next}x=h.lverts.next;let y=x;u+=d.x*(y.y-m.y);let f=y.y*d.x-y.x*d.y;h.localCOMx+=(d.x+y.x)*f,h.localCOMy+=(d.y+y.y)*f,m=d,d=y,x=x.next;let b=x;u+=d.x*(b.y-m.y);let P=b.y*d.x-b.x*d.y;h.localCOMx+=(d.x+b.x)*P,h.localCOMy+=(d.y+b.y)*P,u=1/(3*u);let k=u;h.localCOMx*=k,h.localCOMy*=k}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.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,p=r.radius;r.aabb.minx=r.worldCOMx-a,r.aabb.miny=r.worldCOMy-p,r.aabb.maxx=r.worldCOMx+a,r.aabb.maxy=r.worldCOMy+p}else{let r=s.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=r.lverts.next,u=r.gverts.next;for(;u!=null;){let x=u,m=h;h=h.next,x.x=r.body.posx+(r.body.axisy*m.x-r.body.axisx*m.y),x.y=r.body.posy+(m.x*r.body.axisx+m.y*r.body.axisy),u=u.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 p=r.gverts.next.next;for(;p!=null;){let c=p;c.x<r.aabb.minx&&(r.aabb.minx=c.x),c.x>r.aabb.maxx&&(r.aabb.maxx=c.x),c.y<r.aabb.miny&&(r.aabb.miny=c.y),c.y>r.aabb.maxy&&(r.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 o=(n.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(o.root==null)o.root=n,o.root.parent=null;else{let r=n.aabb,a=o.root;for(;a.child1!=null;){let m=a.child1,d=a.child2,y=a.aabb,f=(y.maxx-y.minx+(y.maxy-y.miny))*2,b=$e.tmpaabb,P=a.aabb;b.minx=P.minx<r.minx?P.minx:r.minx,b.miny=P.miny<r.miny?P.miny:r.miny,b.maxx=P.maxx>r.maxx?P.maxx:r.maxx,b.maxy=P.maxy>r.maxy?P.maxy:r.maxy;let k=$e.tmpaabb,_=(k.maxx-k.minx+(k.maxy-k.miny))*2,z=2*_,C=2*(_-f),w=$e.tmpaabb,g=m.aabb;w.minx=r.minx<g.minx?r.minx:g.minx,w.miny=r.miny<g.miny?r.miny:g.miny,w.maxx=r.maxx>g.maxx?r.maxx:g.maxx,w.maxy=r.maxy>g.maxy?r.maxy:g.maxy;let O;if(m.child1==null){let Z=$e.tmpaabb;O=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=m.aabb,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=$e.tmpaabb;O=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}let E=$e.tmpaabb,M=d.aabb;E.minx=r.minx<M.minx?r.minx:M.minx,E.miny=r.miny<M.miny?r.miny:M.miny,E.maxx=r.maxx>M.maxx?r.maxx:M.maxx,E.maxy=r.maxy>M.maxy?r.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,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=$e.tmpaabb;N=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}if(z<O&&z<N)break;a=O<N?m:d}let p=a,c=p.parent,h;Ae.zpp_pool==null?h=new Ae:(h=Ae.zpp_pool,Ae.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=r.minx<x.minx?r.minx:x.minx,u.miny=r.miny<x.miny?r.miny:x.miny,u.maxx=r.maxx>x.maxx?r.maxx:x.maxx,u.maxy=r.maxy>x.maxy?r.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,o.root=h),a=n.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else{let _=a.child1,z=a.child2,C=z.height-_.height;if(C>1){let w=z.child1,g=z.child2;if(z.child1=a,z.parent=a.parent,a.parent=z,z.parent!=null?z.parent.child1==a?z.parent.child1=z:z.parent.child2=z:o.root=z,w.height>g.height){z.child2=w,a.child2=g,g.parent=a;let O=a.aabb,E=_.aabb,M=g.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=z.aabb,Z=a.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=g.height;a.height=1+(S>L?S:L);let T=a.height,G=w.height;z.height=1+(T>G?T:G)}else{z.child2=g,a.child2=w,w.parent=a;let O=a.aabb,E=_.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=z.aabb,Z=a.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=_.height,L=w.height;a.height=1+(S>L?S:L);let T=a.height,G=g.height;z.height=1+(T>G?T:G)}a=z}else if(C<-1){let w=_.child1,g=_.child2;if(_.child1=a,_.parent=a.parent,a.parent=_,_.parent!=null?_.parent.child1==a?_.parent.child1=_:_.parent.child2=_:o.root=_,w.height>g.height){_.child2=w,a.child1=g,g.parent=a;let O=a.aabb,E=z.aabb,M=g.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=_.aabb,Z=a.aabb,A=w.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=g.height;a.height=1+(S>L?S:L);let T=a.height,G=w.height;_.height=1+(T>G?T:G)}else{_.child2=g,a.child1=w,w.parent=a;let O=a.aabb,E=z.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=_.aabb,Z=a.aabb,A=g.aabb;N.minx=Z.minx<A.minx?Z.minx:A.minx,N.miny=Z.miny<A.miny?Z.miny:A.miny,N.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,N.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=z.height,L=w.height;a.height=1+(S>L?S:L);let T=a.height,G=g.height;_.height=1+(T>G?T:G)}a=_}else a=a}let m=a.child1,d=a.child2,y=m.height,f=d.height;a.height=1+(y>f?y:f);let b=a.aabb,P=m.aabb,k=d.aabb;b.minx=P.minx<k.minx?P.minx:k.minx,b.miny=P.miny<k.miny?P.miny:k.miny,b.maxx=P.maxx>k.maxx?P.maxx:k.maxx,b.maxy=P.maxy>k.maxy?P.maxy:k.maxy,a=a.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 l=s.shape;if(s.first_sync)s.first_sync=!1;else{let p=s.dyn?this.dtree:this.stree;if(s==p.root)p.root=null;else{let c=s.parent,h=c.parent,u=c.child1==s?c.child2:c.child1;if(h!=null){h.child1==c?h.child1=u:h.child2=u,u.parent=h;let x=c;x.height=-1;let m=x.aabb;m.outer!=null&&(m.outer.zpp_inner=null,m.outer=null),m.wrap_min=m.wrap_max=null,m._invalidate=null,m._validate=null,m.next=be.zpp_pool,be.zpp_pool=m,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ae.zpp_pool,Ae.zpp_pool=x;let d=h;for(;d!=null;){if(d.child1==null||d.height<2)d=d;else{let C=d.child1,w=d.child2,g=w.height-C.height;if(g>1){let O=w.child1,E=w.child2;if(w.child1=d,w.parent=d.parent,d.parent=w,w.parent!=null?w.parent.child1==d?w.parent.child1=w:w.parent.child2=w:p.root=w,O.height>E.height){w.child2=O,d.child2=E,E.parent=d;let M=d.aabb,N=C.aabb,Z=E.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=w.aabb,S=d.aabb,L=O.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=C.height,G=E.height;d.height=1+(T>G?T:G);let q=d.height,R=O.height;w.height=1+(q>R?q:R)}else{w.child2=E,d.child2=O,O.parent=d;let M=d.aabb,N=C.aabb,Z=O.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=w.aabb,S=d.aabb,L=E.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=C.height,G=O.height;d.height=1+(T>G?T:G);let q=d.height,R=E.height;w.height=1+(q>R?q:R)}d=w}else if(g<-1){let O=C.child1,E=C.child2;if(C.child1=d,C.parent=d.parent,d.parent=C,C.parent!=null?C.parent.child1==d?C.parent.child1=C:C.parent.child2=C:p.root=C,O.height>E.height){C.child2=O,d.child1=E,E.parent=d;let M=d.aabb,N=w.aabb,Z=E.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=C.aabb,S=d.aabb,L=O.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=w.height,G=E.height;d.height=1+(T>G?T:G);let q=d.height,R=O.height;C.height=1+(q>R?q:R)}else{C.child2=E,d.child1=O,O.parent=d;let M=d.aabb,N=w.aabb,Z=O.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=C.aabb,S=d.aabb,L=E.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=w.height,G=O.height;d.height=1+(T>G?T:G);let q=d.height,R=E.height;C.height=1+(q>R?q:R)}d=C}else d=d}let y=d.child1,f=d.child2,b=d.aabb,P=y.aabb,k=f.aabb;b.minx=P.minx<k.minx?P.minx:k.minx,b.miny=P.miny<k.miny?P.miny:k.miny,b.maxx=P.maxx>k.maxx?P.maxx:k.maxx,b.maxy=P.maxy>k.maxy?P.maxy:k.maxy;let _=y.height,z=f.height;d.height=1+(_>z?_:z),d=d.parent}}else{p.root=u,u.parent=null;let x=c;x.height=-1;let m=x.aabb;m.outer!=null&&(m.outer.zpp_inner=null,m.outer=null),m.wrap_min=m.wrap_max=null,m._invalidate=null,m._validate=null,m.next=be.zpp_pool,be.zpp_pool=m,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ae.zpp_pool,Ae.zpp_pool=x}}}let o=s.aabb;if(!t.continuous&&l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let p=l.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 m=1;x.localCOMx+=x.lverts.next.next.x*m,x.localCOMy+=x.lverts.next.next.y*m;let d=.5;x.localCOMx*=d,x.localCOMy*=d}else{x.localCOMx=0,x.localCOMy=0;let m=0,d=x.lverts.next,y=d;d=d.next;let f=d;for(d=d.next;d!=null;){let C=d;m+=f.x*(C.y-y.y);let w=C.y*f.x-C.x*f.y;x.localCOMx+=(f.x+C.x)*w,x.localCOMy+=(f.y+C.y)*w,y=f,f=C,d=d.next}d=x.lverts.next;let b=d;m+=f.x*(b.y-y.y);let P=b.y*f.x-b.x*f.y;x.localCOMx+=(f.x+b.x)*P,x.localCOMy+=(f.y+b.y)*P,y=f,f=b,d=d.next;let k=d;m+=f.x*(k.y-y.y);let _=k.y*f.x-k.x*f.y;x.localCOMx+=(f.x+k.x)*_,x.localCOMy+=(f.y+k.y)*_,m=1/(3*m);let z=m;x.localCOMx*=z,x.localCOMy*=z}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let u=p.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.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,h=p.radius;p.aabb.minx=p.worldCOMx-c,p.aabb.miny=p.worldCOMy-h,p.aabb.maxx=p.worldCOMx+c,p.aabb.maxy=p.worldCOMy+h}else{let p=l.polygon;if(p.zip_gverts&&p.body!=null){p.zip_gverts=!1,p.validate_lverts();let u=p.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let x=p.lverts.next,m=p.gverts.next;for(;m!=null;){let d=m,y=x;x=x.next,d.x=p.body.posx+(p.body.axisy*y.x-p.body.axisx*y.y),d.y=p.body.posy+(y.x*p.body.axisx+y.y*p.body.axisy),m=m.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 h=p.gverts.next.next;for(;h!=null;){let u=h;u.x<p.aabb.minx&&(p.aabb.minx=u.x),u.x>p.aabb.maxx&&(p.aabb.maxx=u.x),u.y<p.aabb.miny&&(p.aabb.miny=u.y),u.y>p.aabb.maxy&&(p.aabb.maxy=u.y),h=h.next}}let r=l.aabb;o.minx=r.minx-3,o.miny=r.miny-3,o.maxx=r.maxx+3,o.maxy=r.maxy+3;let a=(s.dyn=l.body.type==1?!1:!l.body.component.sleeping)?this.dtree:this.stree;if(a.root==null)a.root=s,a.root.parent=null;else{let p=s.aabb,c=a.root;for(;c.child1!=null;){let y=c.child1,f=c.child2,b=c.aabb,P=(b.maxx-b.minx+(b.maxy-b.miny))*2,k=$e.tmpaabb,_=c.aabb;k.minx=_.minx<p.minx?_.minx:p.minx,k.miny=_.miny<p.miny?_.miny:p.miny,k.maxx=_.maxx>p.maxx?_.maxx:p.maxx,k.maxy=_.maxy>p.maxy?_.maxy:p.maxy;let z=$e.tmpaabb,C=(z.maxx-z.minx+(z.maxy-z.miny))*2,w=2*C,g=2*(C-P),O=$e.tmpaabb,E=y.aabb;O.minx=p.minx<E.minx?p.minx:E.minx,O.miny=p.miny<E.miny?p.miny:E.miny,O.maxx=p.maxx>E.maxx?p.maxx:E.maxx,O.maxy=p.maxy>E.maxy?p.maxy:E.maxy;let M;if(y.child1==null){let S=$e.tmpaabb;M=(S.maxx-S.minx+(S.maxy-S.miny))*2+g}else{let S=y.aabb,L=(S.maxx-S.minx+(S.maxy-S.miny))*2,T=$e.tmpaabb;M=(T.maxx-T.minx+(T.maxy-T.miny))*2-L+g}let N=$e.tmpaabb,Z=f.aabb;N.minx=p.minx<Z.minx?p.minx:Z.minx,N.miny=p.miny<Z.miny?p.miny:Z.miny,N.maxx=p.maxx>Z.maxx?p.maxx:Z.maxx,N.maxy=p.maxy>Z.maxy?p.maxy:Z.maxy;let A;if(f.child1==null){let S=$e.tmpaabb;A=(S.maxx-S.minx+(S.maxy-S.miny))*2+g}else{let S=f.aabb,L=(S.maxx-S.minx+(S.maxy-S.miny))*2,T=$e.tmpaabb;A=(T.maxx-T.minx+(T.maxy-T.miny))*2-L+g}if(w<M&&w<A)break;c=M<A?y:f}let h=c,u=h.parent,x;Ae.zpp_pool==null?x=new Ae:(x=Ae.zpp_pool,Ae.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=u;let m=x.aabb,d=h.aabb;for(m.minx=p.minx<d.minx?p.minx:d.minx,m.miny=p.miny<d.miny?p.miny:d.miny,m.maxx=p.maxx>d.maxx?p.maxx:d.maxx,m.maxy=p.maxy>d.maxy?p.maxy:d.maxy,x.height=h.height+1,u!=null?(u.child1==h?u.child1=x:u.child2=x,x.child1=h,x.child2=s,h.parent=x,s.parent=x):(x.child1=h,x.child2=s,h.parent=x,s.parent=x,a.root=x),c=s.parent;c!=null;){if(c.child1==null||c.height<2)c=c;else{let C=c.child1,w=c.child2,g=w.height-C.height;if(g>1){let O=w.child1,E=w.child2;if(w.child1=c,w.parent=c.parent,c.parent=w,w.parent!=null?w.parent.child1==c?w.parent.child1=w:w.parent.child2=w:a.root=w,O.height>E.height){w.child2=O,c.child2=E,E.parent=c;let M=c.aabb,N=C.aabb,Z=E.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=w.aabb,S=c.aabb,L=O.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=C.height,G=E.height;c.height=1+(T>G?T:G);let q=c.height,R=O.height;w.height=1+(q>R?q:R)}else{w.child2=E,c.child2=O,O.parent=c;let M=c.aabb,N=C.aabb,Z=O.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=w.aabb,S=c.aabb,L=E.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=C.height,G=O.height;c.height=1+(T>G?T:G);let q=c.height,R=E.height;w.height=1+(q>R?q:R)}c=w}else if(g<-1){let O=C.child1,E=C.child2;if(C.child1=c,C.parent=c.parent,c.parent=C,C.parent!=null?C.parent.child1==c?C.parent.child1=C:C.parent.child2=C:a.root=C,O.height>E.height){C.child2=O,c.child1=E,E.parent=c;let M=c.aabb,N=w.aabb,Z=E.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=C.aabb,S=c.aabb,L=O.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=w.height,G=E.height;c.height=1+(T>G?T:G);let q=c.height,R=O.height;C.height=1+(q>R?q:R)}else{C.child2=E,c.child1=O,O.parent=c;let M=c.aabb,N=w.aabb,Z=O.aabb;M.minx=N.minx<Z.minx?N.minx:Z.minx,M.miny=N.miny<Z.miny?N.miny:Z.miny,M.maxx=N.maxx>Z.maxx?N.maxx:Z.maxx,M.maxy=N.maxy>Z.maxy?N.maxy:Z.maxy;let A=C.aabb,S=c.aabb,L=E.aabb;A.minx=S.minx<L.minx?S.minx:L.minx,A.miny=S.miny<L.miny?S.miny:L.miny,A.maxx=S.maxx>L.maxx?S.maxx:L.maxx,A.maxy=S.maxy>L.maxy?S.maxy:L.maxy;let T=w.height,G=O.height;c.height=1+(T>G?T:G);let q=c.height,R=E.height;C.height=1+(q>R?q:R)}c=C}else c=c}let y=c.child1,f=c.child2,b=y.height,P=f.height;c.height=1+(b>P?b:P);let k=c.aabb,_=y.aabb,z=f.aabb;k.minx=_.minx<z.minx?_.minx:z.minx,k.miny=_.miny<z.miny?_.miny:z.miny,k.maxx=_.maxx>z.maxx?_.maxx:z.maxx,k.maxy=_.maxy>z.maxy?_.maxy:z.maxy,c=c.parent}}s.synced=!1,s=s.snext}for(;this.syncs!=null;){let l=this.syncs;this.syncs=l.snext,l.snext=null;let o=l;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 h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let d,y;r.id<x.id?(d=r.id,y=x.id):(d=x.id,y=r.id);let f=r.pairs.length<x.pairs.length?r:x,b=null,P=f.pairs.head;for(;P!=null;){let O=P.elt;if(O.id==d&&O.di==y){b=O;break}P=P.next}if(b!=null){b.sleeping&&(b.sleeping=!1,this._linkPair(b),b.first=!0);continue}st.zpp_pool==null?b=new st:(b=st.zpp_pool,st.zpp_pool=b.next,b.next=null),b.n1=o,b.n2=u,b.id=d,b.di=y,this._linkPair(b),b.first=!0;let k=r.pairs,_;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?_=new we._zpp.util.ZNPNode_ZPP_AABBPair:(_=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_.next,_.next=null),_.elt=b;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++;let C=x.pairs,w;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new we._zpp.util.ZNPNode_ZPP_AABBPair:(w=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=b;let g=w;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let d,y;r.id<x.id?(d=r.id,y=x.id):(d=x.id,y=r.id);let f=r.pairs.length<x.pairs.length?r:x,b=null,P=f.pairs.head;for(;P!=null;){let O=P.elt;if(O.id==d&&O.di==y){b=O;break}P=P.next}if(b!=null){b.sleeping&&(b.sleeping=!1,this._linkPair(b),b.first=!0);continue}st.zpp_pool==null?b=new st:(b=st.zpp_pool,st.zpp_pool=b.next,b.next=null),b.n1=o,b.n2=u,b.id=d,b.di=y,this._linkPair(b),b.first=!0;let k=r.pairs,_;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?_=new we._zpp.util.ZNPNode_ZPP_AABBPair:(_=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_.next,_.next=null),_.elt=b;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++;let C=x.pairs,w;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new we._zpp.util.ZNPNode_ZPP_AABBPair:(w=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=b;let g=w;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2))}}}for(;this.moves!=null;){let l=this.moves;this.moves=l.mnext,l.mnext=null;let o=l;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 h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let d,y;r.id<x.id?(d=r.id,y=x.id):(d=x.id,y=r.id);let f=r.pairs.length<x.pairs.length?r:x,b=null,P=f.pairs.head;for(;P!=null;){let O=P.elt;if(O.id==d&&O.di==y){b=O;break}P=P.next}if(b!=null){b.sleeping&&(b.sleeping=!1,this._linkPair(b),b.first=!0);continue}st.zpp_pool==null?b=new st:(b=st.zpp_pool,st.zpp_pool=b.next,b.next=null),b.n1=o,b.n2=u,b.id=d,b.di=y,this._linkPair(b),b.first=!0;let k=r.pairs,_;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?_=new we._zpp.util.ZNPNode_ZPP_AABBPair:(_=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_.next,_.next=null),_.elt=b;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++;let C=x.pairs,w;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new we._zpp.util.ZNPNode_ZPP_AABBPair:(w=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=b;let g=w;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let d,y;r.id<x.id?(d=r.id,y=x.id):(d=x.id,y=r.id);let f=r.pairs.length<x.pairs.length?r:x,b=null,P=f.pairs.head;for(;P!=null;){let O=P.elt;if(O.id==d&&O.di==y){b=O;break}P=P.next}if(b!=null){b.sleeping&&(b.sleeping=!1,this._linkPair(b),b.first=!0);continue}st.zpp_pool==null?b=new st:(b=st.zpp_pool,st.zpp_pool=b.next,b.next=null),b.n1=o,b.n2=u,b.id=d,b.di=y,this._linkPair(b),b.first=!0;let k=r.pairs,_;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?_=new we._zpp.util.ZNPNode_ZPP_AABBPair:(_=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_.next,_.next=null),_.elt=b;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++;let C=x.pairs,w;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new we._zpp.util.ZNPNode_ZPP_AABBPair:(w=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=b;let g=w;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2))}}}let i=this.pairs;for(;i!=null;){let l;if(i.first)l=!1;else{let u=i.n1.aabb,x=i.n2.aabb;l=!(x.miny<=u.maxy&&u.miny<=x.maxy&&x.minx<=u.maxx&&u.minx<=x.maxx)}if(l){let u=i.next;this._unlinkPair(i),i.n1.shape.pairs.remove(i),i.n2.shape.pairs.remove(i),i.arb!=null&&(i.arb.pair=null),i.arb=null,i.n1=i.n2=null,i.sleeping=!1,i.gprev=null,i.next=st.zpp_pool,st.zpp_pool=i,i=u;continue}let o=i.n1.shape,r=o.body,a=i.n2.shape,p=a.body;if(!i.first&&(r.component.sleeping||r.type==1)&&(p.component.sleeping||p.type==1)){i.sleeping=!0;let u=i.next;this._unlinkPair(i),i=u;continue}i.first=!1;let c=o.aabb,h=a.aabb;if(h.miny<=c.maxy&&c.miny<=h.maxy&&h.minx<=c.maxx&&c.minx<=h.maxx){let u=i.arb;n?i.arb=t.narrowPhase(o,a,r.type!=2||p.type!=2,i.arb,!1):i.arb=t.continuousEvent(o,a,r.type!=2||p.type!=2,i.arb,!1),i.arb==null?u!=null&&(u.pair=null):i.arb.pair=i}i=i.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,n=this.pairs;n.arb!=null&&(n.arb.pair=null),n.arb=null,n.n1.shape.pairs.remove(n),n.n2.shape.pairs.remove(n),n.n1=n.n2=null,n.sleeping=!1,n.gprev=null,n.next=st.zpp_pool,st.zpp_pool=n,this.pairs=t}this.dtree.clear(),this.stree.clear()}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l;ae.zpp_pool==null?l=new ae:(l=ae.zpp_pool,ae.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,r=i??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.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?Ce.circleContains(p.shape.circle,o)&&r.push(p.shape.outer):Ce.polyContains(p.shape.polygon,o)&&r.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 we._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(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.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?Ce.circleContains(p.shape.circle,o)&&r.push(p.shape.outer):Ce.polyContains(p.shape.polygon,o)&&r.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let a=o;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,r}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l;ae.zpp_pool==null?l=new ae:(l=ae.zpp_pool,ae.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,r=i??new we._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!r.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?Ce.circleContains(p.shape.circle,o)&&r.push(h):Ce.polyContains(p.shape.polygon,o)&&r.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 we._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(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!r.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?Ce.circleContains(p.shape.circle,o)&&r.push(h):Ce.polyContains(p.shape.polygon,o)&&r.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let a=o;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,r}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&r.push(a.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);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&&r.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h;if(i!=null){let u=a.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n)if(s)Ce.containTest(this.aabbShape.zpp_inner,a.shape)&&r.push(a.shape.outer);else{let u=a.shape.aabb;(u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy||Ce.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&r.push(a.shape.outer)}else{let u;if(s){let x=a.shape.aabb;u=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy}else u=!0;u&&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 we._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(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&r.push(a.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);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&&r.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h;if(i!=null){let u=a.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n)if(s)Ce.containTest(this.aabbShape.zpp_inner,a.shape)&&r.push(a.shape.outer);else{let u=a.shape.aabb;(u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy||Ce.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&r.push(a.shape.outer)}else{let u;if(s){let x=a.shape.aabb;u=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy}else u=!0;u&&r.push(a.shape.outer)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}return r}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new we._nape.phys.BodyList;if(this.failed==null&&(this.failed=new we._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=a.shape.body.outer;r.has(h)||r.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);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;r.has(u)||r.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let x=a.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=Ce.containTest(this.aabbShape.zpp_inner,a.shape);!r.has(h)&&x?r.push(h):x||(r.remove(h),this.failed.push(h))}}else!r.has(h)&&Ce.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&r.push(h);else if(s){if(!this.failed.has(h)){let x=a.shape.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(h)&&m?r.push(h):m||(r.remove(h),this.failed.push(h))}}else{let x;if(r.has(h))x=!1;else{let m=a.shape.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(h)}}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 we._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(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=a.shape.body.outer;r.has(h)||r.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);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;r.has(u)||r.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let x=a.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=Ce.containTest(this.aabbShape.zpp_inner,a.shape);!r.has(h)&&x?r.push(h):x||(r.remove(h),this.failed.push(h))}}else!r.has(h)&&Ce.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&r.push(h);else if(s){if(!this.failed.has(h)){let x=a.shape.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(h)&&m?r.push(h):m||(r.remove(h),this.failed.push(h))}}else{let x;if(r.has(h))x=!1;else{let m=a.shape.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(h)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}return this.failed.clear(),r}shapesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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?Ce.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):Ce.testCollide_safe(p.shape,this.circShape.zpp_inner)&&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 we._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.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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?Ce.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):Ce.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return a}bodiesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new we._nape.phys.BodyList;if(this.failed==null&&(this.failed=new we._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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=Ce.containTest(this.circShape.zpp_inner,p.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ce.testCollide_safe(p.shape,this.circShape.zpp_inner)&&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 we._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.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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=Ce.containTest(this.circShape.zpp_inner,p.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ce.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(h)}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p;if(s!=null){let c=r.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ce.containTest(t,r.shape)&&o.push(r.shape.outer):Ce.testCollide_safe(r.shape,t)&&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 we._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(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p;if(s!=null){let c=r.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ce.containTest(t,r.shape)&&o.push(r.shape.outer):Ce.testCollide_safe(r.shape,t)&&o.push(r.shape.outer))}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}return o}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new we._nape.phys.BodyList;if(this.failed==null&&(this.failed=new we._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._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(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p=r.shape.body.outer,c;if(s!=null){let h=r.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=Ce.containTest(t,r.shape);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ce.testCollide_safe(r.shape,t)&&o.push(p)}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 we._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(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p=r.shape.body.outer,c;if(s!=null){let h=r.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=Ce.containTest(t,r.shape);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ce.testCollide_safe(r.shape,t)&&o.push(p)}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}return this.failed.clear(),o}rayCast(t,n,s){this.openlist==null&&(this.openlist=new we._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 o=t.aabbsect(this.dtree.root.aabb);if(o>=0&&o<i){this.dtree.root.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(this.dtree.root.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=this.dtree.root,h;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new we._zpp.util.ZNPNode_ZPP_AABBNode:(h=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;r==null?(u.next=p.head,p.head=u):(u.next=r.next,r.next=u),p.pushmod=p.modified=!0,p.length++}}if(this.stree.root!=null&&t.aabbtest(this.stree.root.aabb)){let o=t.aabbsect(this.stree.root.aabb);if(o>=0&&o<i){this.stree.root.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(this.stree.root.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=this.stree.root,h;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new we._zpp.util.ZNPNode_ZPP_AABBNode:(h=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;r==null?(u.next=p.head,p.head=u):(u.next=r.next,r.next=u),p.pushmod=p.modified=!0,p.length++}}let l=null;for(;this.openlist.head!=null;){let o=this.openlist.pop_unsafe();if(o.rayt>=i)break;if(o.child1==null){let r=o.shape,a;if(s!=null){let p=r.filter;a=(p.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&p.collisionGroup)!=0}else a=!0;if(a){let p=r.type==0?t.circlesect(r.circle,n,i):t.aabbtest(r.aabb)?t.polysect(r.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(o.child1!=null&&t.aabbtest(o.child1.aabb)){let r=t.aabbsect(o.child1.aabb);if(r>=0&&r<i){o.child1.rayt=r;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(o.child1.rayt<m.rayt)break;a=p,p=p.next}let c=this.openlist,h=o.child1,u;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new we._zpp.util.ZNPNode_ZPP_AABBNode:(u=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;a==null?(x.next=c.head,c.head=x):(x.next=a.next,a.next=x),c.pushmod=c.modified=!0,c.length++}}if(o.child2!=null&&t.aabbtest(o.child2.aabb)){let r=t.aabbsect(o.child2.aabb);if(r>=0&&r<i){o.child2.rayt=r;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(o.child2.rayt<m.rayt)break;a=p,p=p.next}let c=this.openlist,h=o.child2,u;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new we._zpp.util.ZNPNode_ZPP_AABBNode:(u=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;a==null?(x.next=c.head,c.head=x):(x.next=a.next,a.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 we._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let l=t.maxdist>=1/0,o=i??new we._nape.geom.RayResultList;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb))if(l)this.openlist.add(this.dtree.root);else{let r=t.aabbsect(this.dtree.root.aabb);r>=0&&r<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 r=t.aabbsect(this.stree.root.aabb);r>=0&&r<t.maxdist&&this.openlist.add(this.stree.root)}for(;this.openlist.head!=null;){let r=this.openlist.pop_unsafe();if(r.child1==null){let a=r.shape,p;if(s!=null){let c=a.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(a.type==0?t.circlesect2(a.circle,n,o):t.aabbtest(a.aabb)&&t.polysect2(a.polygon,n,o))}else{if(r.child1!=null&&t.aabbtest(r.child1.aabb))if(l)this.openlist.add(r.child1);else{let a=t.aabbsect(r.child1.aabb);a>=0&&a<t.maxdist&&this.openlist.add(r.child1)}if(r.child2!=null&&t.aabbtest(r.child2.aabb))if(l)this.openlist.add(r.child2);else{let a=t.aabbsect(r.child2.aabb);a>=0&&a<t.maxdist&&this.openlist.add(r.child2)}}}return this.openlist.clear(),o}};we._zpp=null,we._nape=null,we.FATTEN=3,we.VEL_STEPS=2;var Ms=we;var Ks=class Ks{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 Ks._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}};Ks.zpp_pool=null,Ks._zpp=null;var xt=Ks;var Ys=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}};Ys.zpp_pool=null;var Ln=class Ln{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 Ln._zpp.util.ZNPList_ZPP_Arbiter}static get(e,t){let n;return Ln.zpp_pool==null?n=new Ln:(n=Ln.zpp_pool,Ln.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=Ln._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 o=i;return o.next=s.head,s.head=o,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,o;n==null?(l=t.head,o=l.next,t.head=o,t.head==null&&(t.pushmod=!0)):(l=n.next,o=l.next,n.next=o,o==null&&(t.pushmod=!0));let r=l;r.elt=null;let a=Ln._zpp.util.ZNPNode_ZPP_Arbiter;r.next=a.zpp_pool,a.zpp_pool=r,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 o=i;o.elt=null;let r=Ln._zpp.util.ZNPNode_ZPP_Arbiter;o.next=r.zpp_pool,r.zpp_pool=o,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}};Ln.zpp_pool=null,Ln._zpp=null;var Kt=Ln;var ci=class ci{constructor(e){this.cbsets=null;this.space=null;let t=ci._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=ci._zpp.callbacks.ZPP_CbSet.setlt,this.space=e}get(e){if(e.head==null)return null;let t=ci._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 r=t.get(e);this.cbsets.insert(r),r.manager=this,l=r}n.cbTypes=s;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,l}remove(e){let t=ci._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=ci._zpp.callbacks.ZPP_CbSet,s=ci._zpp.callbacks.ZPP_CbSetPair,i=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){i=r;break}o=o.next}if(i==null){let r;s.zpp_pool==null?r=new s:(r=s.zpp_pool,s.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),i=r,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}};ci._zpp=null;var Hi=ci;var B=class B{constructor(e,t){this.outer=null;this.userData=null;this.gravityx=0;this.gravityy=0;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=0;this.global_ang_drag=0;this.stamp=0;this.midstep=!1;this.time=0;this.sortcontacts=!1;this.deterministic=!1;this.subSteps=1;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=0;this.toiEvents=null;this.continuous=!1;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.deterministic=!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,Tt.internal=!0,this.precb=Tt._createPreCb(),this.precb.zpp_inner=new Tt,Tt.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_SPATIAL_HASH==null&&(H.internal=!0,H.Broadphase_SPATIAL_HASH=new B._nape.space.Broadphase,H.internal=!1),t==H.Broadphase_SPATIAL_HASH?this.bphase=new B._zpp.space.ZPP_SpatialHashPhase(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 xt,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=Mn.__static(),this.__static.zpp_inner.space=this,this.callbacks=new Tt,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 Kt,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 Hi(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;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.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 o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y==t}else i=!1;if(!i){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=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 a=l.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)),l=l.next}let o=i.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=Kt.zpp_pool,Kt.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,o=!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,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,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 s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;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=ut.zpp_pool,ut.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,o=!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,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,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 s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;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=ut.zpp_pool,ut.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,o=!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,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,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=Ot.zpp_pool,Ot.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,o=!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,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,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=Pt.zpp_pool,Pt.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=xt.zpp_pool,xt.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=xt.zpp_pool,xt.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 o=l.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=xt.zpp_pool,xt.zpp_pool=r}}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 o=l.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=xt.zpp_pool,xt.zpp_pool=r}}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 o=l;o.next=i.head,i.head=o,i.modified=!0,i.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,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,o=null,r=l.head,a=!1;for(;r!=null;){if(r.elt==e){let p,c;o==null?(p=l.head,c=p.next,l.head=c,l.head==null&&(l.pushmod=!0)):(p=o.next,c=p.next,o.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,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 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 r=this.mrca1.head;for(;r!=null;){let a=r.elt,p=this.mrca2.head;for(;p!=null;){let c=p.elt,h=a.cbSet,u=c.cbSet;h.validate(),u.validate();let x=h.manager,m=null,y=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;y!=null;){let C=y.elt;if(C.a==h&&C.b==u||C.a==u&&C.b==h){m=C;break}y=y.next}if(m==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,_t.setlt(h,u)?(C.a=h,C.b=u):(C.a=u,C.b=h),m=C,h.cbpairs.add(m),u!=h&&u.cbpairs.add(m)}if(m.zip_listeners&&(m.zip_listeners=!1,m.__validate()),m.listeners.head==null){p=p.next;continue}let f=B._zpp.phys.ZPP_Interactor.get(a,c);f.remove_arb(l),l.present--;let b=h.manager,P=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){P=C;break}_=_.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,_t.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 z=P.listeners.head;for(;z!=null;){let C=z.elt;if(C.event==1&&(C.itype&l.type)!=0&&f.empty_arb(C.itype)){let w=this.push_callback(C);w.event=1;let g=f.int1,O=f.int2,E,M=C.options1,N=g.cbTypes;if(M.nonemptyintersection(N,M.includes)&&!M.nonemptyintersection(N,M.excludes)){let Z=C.options2,A=O.cbTypes;E=Z.nonemptyintersection(A,Z.includes)&&!Z.nonemptyintersection(A,Z.excludes)}else E=!1;E?(w.int1=g,w.int2=O):(w.int1=O,w.int2=g),w.set=f}z=z.next}f.arbiters.head==null&&this.remove_callbackset(f),p=p.next}r=r.next}}if(l.b1!=n&&l.b1.type==2){let r=l.b1;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))}if(l.b2!=n&&l.b2.type==2){let r=l.b2;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))}if(l.cleared=!0,n==null||l.b2==n){let r=l.b1.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}}if(n==null||l.b1==n){let r=l.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.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,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=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 o=i.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(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 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(),l.shapesInCircle(r,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 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(),l.bodiesInCircle(r,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 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 T=S.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 V=q;G+=j.x*(V.y-R.y);let K=V.y*j.x-V.x*j.y;T.localCOMx+=(j.x+V.x)*K,T.localCOMy+=(j.y+V.y)*K,R=j,j=V,q=q.next;let $=q;G+=j.x*($.y-R.y);let Y=$.y*j.x-$.x*j.y;T.localCOMx+=(j.x+$.x)*Y,T.localCOMy+=(j.y+$.y)*Y,G=1/(3*G);let X=G;T.localCOMx*=X,T.localCOMy*=X}}S.wrap_localCOM!=null&&(S.wrap_localCOM.zpp_inner.x=S.localCOMx,S.wrap_localCOM.zpp_inner.y=S.localCOMy)}let L=S.body;L.zip_axis&&(L.zip_axis=!1,L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.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)}}else if(e.type===2){let S=e.capsule;if(S.zip_worldCOM&&S.body!=null){S.zip_worldCOM=!1,S.zip_localCOM&&(S.zip_localCOM=!1,S.wrap_localCOM!=null&&(S.wrap_localCOM.zpp_inner.x=S.localCOMx,S.wrap_localCOM.zpp_inner.y=S.localCOMy));let L=S.body;L.zip_axis&&(L.zip_axis=!1,L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.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)}}else{let S=e.polygon;if(S.zip_gaxi&&S.body!=null){S.zip_gaxi=!1,S.validate_laxi();let L=S.body;if(L.zip_axis&&(L.zip_axis=!1,L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.rot)),S.zip_gverts&&S.body!=null){S.zip_gverts=!1,S.validate_lverts();let V=S.body;V.zip_axis&&(V.zip_axis=!1,V.axisx=Math.sin(V.rot),V.axisy=Math.cos(V.rot));let K=S.lverts.next,$=S.gverts.next;for(;$!=null;){let Y=$,X=K;K=K.next,Y.x=S.body.posx+(S.body.axisy*X.x-S.body.axisx*X.y),Y.y=S.body.posy+(X.x*S.body.axisx+X.y*S.body.axisy),$=$.next}}let T=S.edges.head,G=S.gverts.next,q=G;for(G=G.next;G!=null;){let V=G,K=T.elt;T=T.next,K.gp0=q,K.gp1=V,K.gnormx=S.body.axisy*K.lnormx-S.body.axisx*K.lnormy,K.gnormy=K.lnormx*S.body.axisx+K.lnormy*S.body.axisy,K.gprojection=S.body.posx*K.gnormx+S.body.posy*K.gnormy+K.lprojection,K.wrap_gnorm!=null&&(K.wrap_gnorm.zpp_inner.x=K.gnormx,K.wrap_gnorm.zpp_inner.y=K.gnormy),K.tp0=K.gp0.y*K.gnormx-K.gp0.x*K.gnormy,K.tp1=K.gp1.y*K.gnormx-K.gp1.x*K.gnormy,q=V,G=G.next}let R=S.gverts.next,j=T.elt;T=T.next,j.gp0=q,j.gp1=R,j.gnormx=S.body.axisy*j.lnormx-S.body.axisx*j.lnormy,j.gnormy=j.lnormx*S.body.axisx+j.lnormy*S.body.axisy,j.gprojection=S.body.posx*j.gnormx+S.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,o=l.posx,r=l.posy;l.sweepTime=0,l.sweep_angvel=l.angvel;let a=t-l.sweepTime;if(a!=0){l.sweepTime=t;let S=a;if(l.posx+=l.velx*S,l.posy+=l.vely*S,l.angvel!=0){let L=l.sweep_angvel*a;if(l.rot+=L,L*L>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let T=L*L,G=1-.5*T,q=1-T*T/8,R=(G*l.axisx+L*l.axisy)*q;l.axisy=(G*l.axisy-L*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=o,m=p;u.minx=(x<m?x:m)-h;let d=o,y=p;u.maxx=(d>y?d:y)+h;let f=r,b=c;u.miny=(f<b?f:b)-h;let P=r,k=c;u.maxy=(P>k?P:k)+h;let _=this.convexShapeList=this.bphase.shapesInAABB(u,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),z=u;z.outer!=null&&(z.outer.zpp_inner=null,z.outer=null),z.wrap_min=z.wrap_max=null,z._invalidate=null,z._validate=null,z.next=be.zpp_pool,be.zpp_pool=z;let C=0,w=0;C=0,w=0;let g=0,O=0;g=0,O=0;let E=null,M=t+1;_.zpp_inner.valmod();let N=B._nape.shape.ShapeIterator.get(_);for(;;){N.zpp_inner.zpp_inner.valmod();let S=N.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 L=S.zpp_inner.user_length;N.zpp_critical=!0;let T;if(N.zpp_i<L?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,Cn.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 K=R;if(q.posx+=q.velx*K,q.posy+=q.vely*K,q.angvel!=0){let $=q.sweep_angvel*R;if(q.rot+=$,$*$>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else{let Y=$*$,X=1-.5*Y,ee=1-Y*Y/8,J=(X*q.axisx+$*q.axisy)*ee;q.axisy=(X*q.axisy-$*q.axisx)*ee,q.axisx=J}}}let j=(G.zpp_inner.body!=null?G.zpp_inner.body.outer:null).zpp_inner,V=G.zpp_inner;if(V.type==0||V.type===2)V.worldCOMx=j.posx+(j.axisy*V.localCOMx-j.axisx*V.localCOMy),V.worldCOMy=j.posy+(V.localCOMx*j.axisx+V.localCOMy*j.axisy);else{let K=V.polygon,$=K.lverts.next,Y=K.gverts.next;for(;Y!=null;){let I=Y,U=$;$=$.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=K.edges.head,ee=K.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 F=K.gverts.next,D=X.elt;X=X.next,D.gnormx=j.axisy*D.lnormx-j.axisx*D.lnormy,D.gnormy=D.lnormx*j.axisx+D.lnormy*j.axisy,D.gprojection=j.posx*D.gnormx+j.posy*D.gnormy+D.lprojection,D.tp0=J.y*D.gnormx-J.x*D.gnormy,D.tp1=F.y*D.gnormx-F.x*D.gnormy}}else Cn.staticSweep(i,t,0,0);i.toi*=t,i.toi>0&&i.toi<M&&(M=i.toi,C=i.axis.x,w=i.axis.y,g=i.c2.x,O=i.c2.y,E=G)}}_.clear();let Z=i;Z.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=Z;let A=0-l.sweepTime;if(A!=0){l.sweepTime=0;let S=A;if(l.posx+=l.velx*S,l.posy+=l.vely*S,l.angvel!=0){let L=l.sweep_angvel*A;if(l.rot+=L,L*L>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let T=L*L,G=1-.5*T,q=1-T*T/8,R=(G*l.axisx+L*l.axisy)*q;l.axisy=(G*l.axisy-L*l.axisx)*q,l.axisx=R}}}if(e.type==0||e.type===2)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 S=e.polygon,L=S.lverts.next,T=S.gverts.next;for(;T!=null;){let K=T,$=L;L=L.next,K.x=l.posx+(l.axisy*$.x-l.axisx*$.y),K.y=l.posy+($.x*l.axisx+$.y*l.axisy),T=T.next}let G=S.edges.head,q=S.gverts.next,R=q;for(q=q.next;q!=null;){let K=q,$=G.elt;G=G.next,$.gnormx=l.axisy*$.lnormx-l.axisx*$.lnormy,$.gnormy=$.lnormx*l.axisx+$.lnormy*l.axisy,$.gprojection=l.posx*$.gnormx+l.posy*$.gnormy+$.lprojection,$.tp0=R.y*$.gnormx-R.x*$.gnormy,$.tp1=K.y*$.gnormx-K.x*$.gnormy,R=K,q=q.next}let j=S.gverts.next,V=G.elt;G=G.next,V.gnormx=l.axisy*V.lnormx-l.axisx*V.lnormy,V.gnormy=V.lnormx*l.axisx+V.lnormy*l.axisy,V.gprojection=l.posx*V.gnormx+l.posy*V.gnormy+V.lprojection,V.tp0=R.y*V.gnormx-R.x*V.gnormy,V.tp1=j.y*V.gnormx-j.x*V.gnormy}if(M<=t){let S=-C,L=-w;if(L==null&&(L=0),S==null&&(S=0),S!=S||L!=L)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;ae.zpp_pool==null?j=new ae:(j=ae.zpp_pool,ae.zpp_pool=j.next,j.next=null),j.weak=!1,j._immutable=!1,j.x=S,j.y=L,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(),S!=S||L!=L)throw new Error("Error: Vec2 components cannot be NaN");let V;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let K=T.zpp_inner;if(K._validate!=null&&K._validate(),T.zpp_inner.x==S){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let $=T.zpp_inner;$._validate!=null&&$._validate(),V=T.zpp_inner.y==L}else V=!1;if(!V){T.zpp_inner.x=S,T.zpp_inner.y=L;let $=T.zpp_inner;$._invalidate!=null&&$._invalidate($)}}T.zpp_inner.weak=!1;let G=g,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;ae.zpp_pool==null?j=new ae:(j=ae.zpp_pool,ae.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 V;if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let K=R.zpp_inner;if(K._validate!=null&&K._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 $=R.zpp_inner;$._validate!=null&&$._validate(),V=R.zpp_inner.y==q}else V=!1;if(!V){R.zpp_inner.x=G,R.zpp_inner.y=q;let $=R.zpp_inner;$._invalidate!=null&&$._invalidate($)}}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,o=l;l=l.next;let r=l;for(l=l.next;l!=null;){let x=l;i+=r.x*(x.y-o.y);let m=x.y*r.x-x.x*r.y;s.localCOMx+=(r.x+x.x)*m,s.localCOMy+=(r.y+x.y)*m,o=r,r=x,l=l.next}l=s.lverts.next;let a=l;i+=r.x*(a.y-o.y);let p=a.y*r.x-a.x*r.y;s.localCOMx+=(r.x+a.x)*p,s.localCOMy+=(r.y+a.y)*p,o=r,r=a,l=l.next;let c=l;i+=r.x*(c.y-o.y);let h=c.y*r.x-c.x*r.y;s.localCOMx+=(r.x+c.x)*h,s.localCOMy+=(r.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 if(e.type===2){let t=e.capsule;if(t.zip_worldCOM&&t.body!=null){t.zip_worldCOM=!1,t.zip_localCOM&&(t.zip_localCOM=!1,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 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 a=i,p=s.elt;s=s.next,p.gp0=l,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,l=a,i=i.next}let o=t.gverts.next,r=s.elt;s=s.next,r.gp0=l,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,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 A=1;Z.localCOMx+=Z.lverts.next.next.x*A,Z.localCOMy+=Z.lverts.next.next.y*A;let S=.5;Z.localCOMx*=S,Z.localCOMy*=S}else{Z.localCOMx=0,Z.localCOMy=0;let A=0,S=Z.lverts.next,L=S;S=S.next;let T=S;for(S=S.next;S!=null;){let K=S;A+=T.x*(K.y-L.y);let $=K.y*T.x-K.x*T.y;Z.localCOMx+=(T.x+K.x)*$,Z.localCOMy+=(T.y+K.y)*$,L=T,T=K,S=S.next}S=Z.lverts.next;let G=S;A+=T.x*(G.y-L.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,L=T,T=G,S=S.next;let R=S;A+=T.x*(R.y-L.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,A=1/(3*A);let V=A;Z.localCOMx*=V,Z.localCOMy*=V}}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 if(e.type===2){let M=e.capsule;if(M.zip_worldCOM&&M.body!=null){M.zip_worldCOM=!1,M.zip_localCOM&&(M.zip_localCOM=!1,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,V=q;q=q.next,j.x=M.body.posx+(M.body.axisy*V.x-M.body.axisx*V.y),j.y=M.body.posy+(V.x*M.body.axisx+V.y*M.body.axisy),R=R.next}}let Z=M.edges.head,A=M.gverts.next,S=A;for(A=A.next;A!=null;){let G=A,q=Z.elt;Z=Z.next,q.gp0=S,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,S=G,A=A.next}let L=M.gverts.next,T=Z.elt;Z=Z.next,T.gp0=S,T.gp1=L,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 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 M=p;if(o.posx+=o.velx*M,o.posy+=o.vely*M,o.angvel!=0){let N=o.sweep_angvel*p;if(o.rot+=N,N*N>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let Z=N*N,A=1-.5*Z,S=1-Z*Z/8,L=(A*o.axisx+N*o.axisy)*S;o.axisy=(A*o.axisy-N*o.axisx)*S,o.axisx=L}}}let c=o.posx,h=o.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 m=r,d=c;x.minx=(m<d?m:d)-u;let y=r,f=c;x.maxx=(y>f?y:f)+u;let b=a,P=h;x.miny=(b<P?b:P)-u;let k=a,_=h;x.maxy=(k>_?k:_)+u;let z=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 w=i??new B._nape.geom.ConvexResultList;z.zpp_inner.valmod();let g=B._nape.shape.ShapeIterator.get(z);for(;;){g.zpp_inner.zpp_inner.valmod();let M=g.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;g.zpp_critical=!0;let Z;if(g.zpp_i<N?Z=!0:(g.zpp_next=B._nape.shape.ShapeIterator.zpp_pool,B._nape.shape.ShapeIterator.zpp_pool=g,g.zpp_inner=null,Z=!1),!Z)break;g.zpp_critical=!1;let A=g.zpp_inner.at(g.zpp_i++);if(A!=e.outer&&(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null)!=o.outer){if(l.s1=e,l.s2=A.zpp_inner,s){A.zpp_inner.validate_sweepRadius(),(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner.angvel,(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,Cn.dynamicSweep(l,t,0,0,!0);let S=(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner,L=0-S.sweepTime;if(L!=0){S.sweepTime=0;let q=L;if(S.posx+=S.velx*q,S.posy+=S.vely*q,S.angvel!=0){let R=S.sweep_angvel*L;if(S.rot+=R,R*R>1e-4)S.axisx=Math.sin(S.rot),S.axisy=Math.cos(S.rot);else{let j=R*R,V=1-.5*j,K=1-j*j/8,$=(V*S.axisx+R*S.axisy)*K;S.axisy=(V*S.axisy-R*S.axisx)*K,S.axisx=$}}}let T=(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner,G=A.zpp_inner;if(G.type==0||G.type===2)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 V=q.edges.head,K=q.gverts.next,$=K;for(K=K.next;K!=null;){let ee=K,J=V.elt;V=V.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=$.y*J.gnormx-$.x*J.gnormy,J.tp1=ee.y*J.gnormx-ee.x*J.gnormy,$=ee,K=K.next}let Y=q.gverts.next,X=V.elt;V=V.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=$.y*X.gnormx-$.x*X.gnormy,X.tp1=Y.y*X.gnormx-Y.x*X.gnormy}}else Cn.staticSweep(l,t,0,0);if(l.toi*=t,l.toi>0){let S=-l.axis.x,L=-l.axis.y;if(L==null&&(L=0),S==null&&(S=0),S!=S||L!=L)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;ae.zpp_pool==null?ee=new ae:(ee=ae.zpp_pool,ae.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=S,ee.y=L,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(),S!=S||L!=L)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 F=T.zpp_inner;if(F._validate!=null&&F._validate(),T.zpp_inner.x==S){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=T.zpp_inner;D._validate!=null&&D._validate(),J=T.zpp_inner.y==L}else J=!1;if(!J){T.zpp_inner.x=S,T.zpp_inner.y=L;let D=T.zpp_inner;D._invalidate!=null&&D._invalidate(D)}}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;ae.zpp_pool==null?ee=new ae:(ee=ae.zpp_pool,ae.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 F=R.zpp_inner;if(F._validate!=null&&F._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 D=R.zpp_inner;D._validate!=null&&D._validate(),J=R.zpp_inner.y==q}else J=!1;if(!J){R.zpp_inner.x=G,R.zpp_inner.y=q;let D=R.zpp_inner;D._invalidate!=null&&D._invalidate(D)}}R.zpp_inner.weak=!1;let j=B._zpp.geom.ZPP_ConvexRayResult.getConvex(T,R,l.toi,A),V=null,K=w.zpp_inner.inner.head;for(;K!=null;){let ee=K.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;V=K,K=K.next}let $=w.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;V==null?(X.next=$.head,$.head=X):(X.next=V.next,V.next=X),$.pushmod=$.modified=!0,$.length++}}}z.clear();let O=l;O.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=O;let E=0-o.sweepTime;if(E!=0){o.sweepTime=0;let M=E;if(o.posx+=o.velx*M,o.posy+=o.vely*M,o.angvel!=0){let N=o.sweep_angvel*E;if(o.rot+=N,N*N>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let Z=N*N,A=1-.5*Z,S=1-Z*Z/8,L=(A*o.axisx+N*o.axisy)*S;o.axisy=(A*o.axisy-N*o.axisx)*S,o.axisx=L}}}if(e.type==0||e.type===2)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 M=e.polygon,N=M.lverts.next,Z=M.gverts.next;for(;Z!=null;){let q=Z,R=N;N=N.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),Z=Z.next}let A=M.edges.head,S=M.gverts.next,L=S;for(S=S.next;S!=null;){let q=S,R=A.elt;A=A.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=L.y*R.gnormx-L.x*R.gnormy,R.tp1=q.y*R.gnormx-q.x*R.gnormy,L=q,S=S.next}let T=M.gverts.next,G=A.elt;A=A.next,G.gnormx=o.axisy*G.lnormx-o.axisx*G.lnormy,G.gnormy=G.lnormx*o.axisx+G.lnormy*o.axisy,G.gprojection=o.posx*G.gnormx+o.posy*G.gnormy+G.lprojection,G.tp0=L.y*G.gnormx-L.x*G.gnormy,G.tp1=T.y*G.gnormx-T.x*G.gnormy}return w}push_callback(e){let t;return Tt.zpp_pool==null?t=new Tt:(t=Tt.zpp_pool,Tt.zpp_pool=t.next,t.next=null),this.callbacks.push(t),t.listener=e,t}_invalidateBodyList(e){let t=e.head;for(;t!=null;){let n=t.elt,s=!(n.posx==n.pre_posx&&n.posy==n.pre_posy),i=n.pre_rot!=n.rot;if(s||i){i&&(n.zip_axis=!0);let l=n.shapes.head;for(;l!=null;){let o=l.elt;o.type==1&&(o.polygon.invalidate_gverts(),o.polygon.invalidate_gaxi()),o.invalidate_worldCOM(),l=l.next}n.zip_worldCOM=!0}t=t.next}}_sortLinkedList(e,t){if(e.head==null||e.head.next==null)return;let n=e.head,s=1;for(;;){let i=0,l=n;n=null;let o=null;for(;l!=null;){i++;let r=l,a=0,p=s;for(;r!=null&&a<s;)a++,r=r.next;for(;a>0||p>0&&r!=null;){let c;a==0?(c=r,r=r.next,p--):p==0||r==null||t(l.elt)<=t(r.elt)?(c=l,l=l.next,a--):(c=r,r=r.next,p--),o!=null?o.next=c:n=c,o=c}l=r}if(o.next=null,s<<=1,i<=1)break}e.head=n,e.modified=!0,e.pushmod=!0}_arbiterSortKey(e){let t=e.s1!=null?e.s1.id:0,n=e.s2!=null?e.s2.id:0,s=t<n?t:n,i=t<n?n:t;return s*1e6+i}_ensureDeterministicOrder(){this.deterministic&&(this._sortLinkedList(this.live,e=>e.id),this._sortLinkedList(this.live_constraints,e=>e.id),this._sortLinkedList(this.c_arbiters_false,e=>this._arbiterSortKey(e)),this._sortLinkedList(this.c_arbiters_true,e=>this._arbiterSortKey(e)),this._sortLinkedList(this.f_arbiters,e=>this._arbiterSortKey(e)))}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!!");this.time+=e,this.midstep=!0,this.stamp++;let s=this.subSteps,i=e/s;try{for(let r=0;r<s;r++){if(this.pre_dt=i,this.validation(),this.bphase.broadphase(this,!0),this._ensureDeterministicOrder(),this.prestep(i),this.sortcontacts){let u=this.c_arbiters_false;if(u.head!=null&&u.head.next!=null){let x=u.head,m=null,d=null,y=null,f=null,b=1,P,k,_;for(;;){for(P=0,d=x,x=null,m=x;d!=null;){for(++P,y=d,k=0,_=b;y!=null&&k<b;)++k,y=y.next;for(;k>0||_>0&&y!=null;)k==0?(f=y,y=y.next,--_):_==0||y==null||(d.elt.active&&y.elt.active?d.elt.oc1.dist<y.elt.oc1.dist:!this.deterministic||this._arbiterSortKey(d.elt)<=this._arbiterSortKey(y.elt))?(f=d,d=d.next,--k):(f=y,y=y.next,--_),m!=null?m.next=f:x=f,m=f;d=y}if(m.next=null,b<<=1,!(P>1))break}u.head=x,u.modified=!0,u.pushmod=!0}}this.updateVel(i),this.warmStart(),this.iterateVel(t);let a=this.kinematics.head;for(;a!=null;){let u=a.elt;u.pre_posx=u.posx,u.pre_posy=u.posy,u.pre_rot=u.rot,a=a.next}let p=this.live.head;for(;p!=null;){let u=p.elt;u.pre_posx=u.posx,u.pre_posy=u.posy,u.pre_rot=u.rot,p=p.next}this.updatePos(i),this.continuous=!0,this.continuousCollisions(i),this.continuous=!1,this.iteratePos(n),this._invalidateBodyList(this.kinematics),this._invalidateBodyList(this.live);let c=null,h=this.staticsleep.head;for(;h!=null;){let u=h.elt;if(u.type!=3||u.velx==0&&u.vely==0&&u.angvel==0){if(u.kinematicDelaySleep){u.kinematicDelaySleep=!1,h=h.next;continue}u.component.sleeping=!0;let x=this.staticsleep,m,d;c==null?(m=x.head,d=m.next,x.head=d,x.head==null&&(x.pushmod=!0)):(m=c.next,d=m.next,c.next=d,d==null&&(x.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Body.zpp_pool,B._zpp.util.ZNPNode_ZPP_Body.zpp_pool=y,x.modified=!0,x.length--,x.pushmod=!0,h=d;continue}c=h,h=h.next}this.doForests(i),this.sleepArbiters()}}finally{this.midstep=!1}let l=null,o=this.callbackset_list.next;for(;o!=null;){let r=o;if(r.arbiters.head==null){let b=this.callbackset_list,P,k;l==null?(P=b.next,k=P.next,b.next=k,b.next==null&&(b.pushmod=!0)):(P=l.next,k=P.next,l.next=k,k==null&&(b.pushmod=!0)),P._inuse=!1,b.modified=!0,b.length--,b.pushmod=!0,o=k;let _=r;_.int1=_.int2=null,_.id=_.di=-1,_.freed=!0,_.next=Kt.zpp_pool,Kt.zpp_pool=_;continue}let a;a=!0;let p=r.arbiters.head;for(;p!=null;)if(p.elt.sleeping){p=p.next;continue}else{a=!1;break}let c=a,h=r.int1.cbSet,u=r.int2.cbSet,x=h.manager,m=null,y=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;y!=null;){let b=y.elt;if(b.a==h&&b.b==u||b.a==u&&b.b==h){m=b;break}y=y.next}if(m==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,_t.setlt(h,u)?(b.a=h,b.b=u):(b.a=u,b.b=h),m=b,h.cbpairs.add(m),u!=h&&u.cbpairs.add(m)}m.zip_listeners&&(m.zip_listeners=!1,m.__validate());let f=m.listeners.head;for(;f!=null;){let b=f.elt;if(b.event==6&&(!c||b.allowSleepingCallbacks)&&!r.empty_arb(b.itype)){let P=this.push_callback(b);P.event=6;let k=r.int1,_=r.int2,z,C=b.options1,w=k.cbTypes;if(C.nonemptyintersection(w,C.includes)&&!C.nonemptyintersection(w,C.excludes)){let g=b.options2,O=_.cbTypes;z=g.nonemptyintersection(O,g.includes)&&!g.nonemptyintersection(O,g.excludes)}else z=!1;z?(P.int1=k,P.int2=_):(P.int1=_,P.int2=k),P.set=r}f=f.next}l=o,o=o.next}for(;!this.callbacks.empty();){let r=this.callbacks.pop();r.listener.type==0?r.listener.body.handler(r.wrapper_body()):r.listener.type==1?r.listener.constraint.handler(r.wrapper_con()):r.listener.type==2&&r.listener.interaction.handleri(r.wrapper_int());let a=r;a.int1=a.int2=null,a.body=null,a.constraint=null,a.listener=null,a.wrap_arbiters!=null&&(a.wrap_arbiters.zpp_inner.inner=null),a.set=null,a.next=Tt.zpp_pool,Tt.zpp_pool=a}}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,o=2,r=!1,a=null,p=null,c=this.toiEvents.head;for(;c!=null;){let y=c.elt,f=y.s1.body,b=y.s2.body;if(f.sweepFrozen&&b.sweepFrozen)if(y.toi!=0&&Ce.testCollide_safe(y.s1,y.s2))y.toi=0;else{c=this.toiEvents.erase(p);let P=y;P.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}if(y.frozen1!=f.sweepFrozen||y.frozen2!=b.sweepFrozen)if(y.kinematic){c=this.toiEvents.erase(p);let P=y;P.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}else{if(y.frozen1=f.sweepFrozen,y.frozen2=b.sweepFrozen,y.frozen1){let P=y.s1;y.s1=y.s2,y.s2=P,y.frozen1=!1,y.frozen2=!0}if(Cn.staticSweep(y,e,0,B._nape.Config.collisionSlopCCD),y.toi<0){c=this.toiEvents.erase(p);let P=y;P.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}}y.toi>=0&&(y.toi<o||!r&&y.kinematic)&&(l=y,o=y.toi,r=y.kinematic,a=p),p=c,c=c.next}if(l==null)break;this.toiEvents.erase(a),n=l.toi;let h=l.s1.body,u=l.s2.body;if(!h.sweepFrozen){let y=n*e,f=y-h.sweepTime;if(f!=0){h.sweepTime=y;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 _=k*k,z=1-.5*_,C=1-_*_/8,w=(z*h.axisx+k*h.axisy)*C;h.axisy=(z*h.axisy-k*h.axisx)*C,h.axisx=w}}}let b=l.s1;if(b.type==0||b.type===2)b.worldCOMx=h.posx+(h.axisy*b.localCOMx-h.axisx*b.localCOMy),b.worldCOMy=h.posy+(b.localCOMx*h.axisx+b.localCOMy*h.axisy);else{let P=b.polygon,k=P.lverts.next,_=P.gverts.next;for(;_!=null;){let E=_,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),_=_.next}let z=P.edges.head,C=P.gverts.next,w=C;for(C=C.next;C!=null;){let E=C,M=z.elt;z=z.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=w.y*M.gnormx-w.x*M.gnormy,M.tp1=E.y*M.gnormx-E.x*M.gnormy,w=E,C=C.next}let g=P.gverts.next,O=z.elt;z=z.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=w.y*O.gnormx-w.x*O.gnormy,O.tp1=g.y*O.gnormx-g.x*O.gnormy}}if(!u.sweepFrozen){let y=n*e,f=y-u.sweepTime;if(f!=0){u.sweepTime=y;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 _=k*k,z=1-.5*_,C=1-_*_/8,w=(z*u.axisx+k*u.axisy)*C;u.axisy=(z*u.axisy-k*u.axisx)*C,u.axisx=w}}}let b=l.s2;if(b.type==0||b.type===2)b.worldCOMx=u.posx+(u.axisy*b.localCOMx-u.axisx*b.localCOMy),b.worldCOMy=u.posy+(b.localCOMx*u.axisx+b.localCOMy*u.axisy);else{let P=b.polygon,k=P.lverts.next,_=P.gverts.next;for(;_!=null;){let E=_,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),_=_.next}let z=P.edges.head,C=P.gverts.next,w=C;for(C=C.next;C!=null;){let E=C,M=z.elt;z=z.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=w.y*M.gnormx-w.x*M.gnormy,M.tp1=E.y*M.gnormx-E.x*M.gnormy,w=E,C=C.next}let g=P.gverts.next,O=z.elt;z=z.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=w.y*O.gnormx-w.x*O.gnormy,O.tp1=g.y*O.gnormx-g.x*O.gnormy}}let x=l.arbiter==null,m=this.narrowPhase(l.s1,l.s2,!0,l.arbiter,!0);if(m==null)l.arbiter!=null&&l.arbiter.pair!=null&&(l.arbiter.pair.arb=null,l.arbiter.pair=null);else if(!this.presteparb(m,e,!0)&&m.type==Ie.COL&&m.active&&(m.immState&1)!=0){let y=m.colarb,f=y.nx*y.c1.jnAcc-y.ny*y.c1.jtAcc,b=y.ny*y.c1.jnAcc+y.nx*y.c1.jtAcc,P=y.b1.imass;y.b1.velx-=f*P,y.b1.vely-=b*P,y.b1.angvel-=y.b1.iinertia*(b*y.c1.r1x-f*y.c1.r1y);let k=y.b2.imass;if(y.b2.velx+=f*k,y.b2.vely+=b*k,y.b2.angvel+=y.b2.iinertia*(b*y.c1.r2x-f*y.c1.r2y),y.hc2){let le=y.nx*y.c2.jnAcc-y.ny*y.c2.jtAcc,he=y.ny*y.c2.jnAcc+y.nx*y.c2.jtAcc,pe=y.b1.imass;y.b1.velx-=le*pe,y.b1.vely-=he*pe,y.b1.angvel-=y.b1.iinertia*(he*y.c2.r1x-le*y.c2.r1y);let ce=y.b2.imass;y.b2.velx+=le*ce,y.b2.vely+=he*ce,y.b2.angvel+=y.b2.iinertia*(he*y.c2.r2x-le*y.c2.r2y)}y.b2.angvel+=y.jrAcc*y.b2.iinertia,y.b1.angvel-=y.jrAcc*y.b1.iinertia;let _=m.colarb,z=_.k1x+_.b2.velx-_.c1.r2y*_.b2.angvel-(_.b1.velx-_.c1.r1y*_.b1.angvel),C=_.k1y+_.b2.vely+_.c1.r2x*_.b2.angvel-(_.b1.vely+_.c1.r1x*_.b1.angvel),w=(C*_.nx-z*_.ny+_.surfacex)*_.c1.tMass,g=_.c1.friction*_.c1.jnAcc,O=_.c1.jtAcc,E=O-w;E>g?E=g:E<-g&&(E=-g),w=E-O,_.c1.jtAcc=E;let M=-_.ny*w,N=_.nx*w;if(_.b2.velx+=M*_.b2.imass,_.b2.vely+=N*_.b2.imass,_.b1.velx-=M*_.b1.imass,_.b1.vely-=N*_.b1.imass,_.b2.angvel+=_.rt1b*w*_.b2.iinertia,_.b1.angvel-=_.rt1a*w*_.b1.iinertia,_.hc2){let le=_.k2x+_.b2.velx-_.c2.r2y*_.b2.angvel-(_.b1.velx-_.c2.r1y*_.b1.angvel),he=_.k2y+_.b2.vely+_.c2.r2x*_.b2.angvel-(_.b1.vely+_.c2.r1x*_.b1.angvel);w=(he*_.nx-le*_.ny+_.surfacex)*_.c2.tMass,g=_.c2.friction*_.c2.jnAcc,O=_.c2.jtAcc,E=O-w,E>g?E=g:E<-g&&(E=-g),w=E-O,_.c2.jtAcc=E,M=-_.ny*w,N=_.nx*w,_.b2.velx+=M*_.b2.imass,_.b2.vely+=N*_.b2.imass,_.b1.velx-=M*_.b1.imass,_.b1.vely-=N*_.b1.imass,_.b2.angvel+=_.rt2b*w*_.b2.iinertia,_.b1.angvel-=_.rt2a*w*_.b1.iinertia,z=_.k1x+_.b2.velx-_.c1.r2y*_.b2.angvel-(_.b1.velx-_.c1.r1y*_.b1.angvel),C=_.k1y+_.b2.vely+_.c1.r2x*_.b2.angvel-(_.b1.vely+_.c1.r1x*_.b1.angvel),le=_.k2x+_.b2.velx-_.c2.r2y*_.b2.angvel-(_.b1.velx-_.c2.r1y*_.b1.angvel),he=_.k2y+_.b2.vely+_.c2.r2x*_.b2.angvel-(_.b1.vely+_.c2.r1x*_.b1.angvel);let pe=_.c1.jnAcc,ce=_.c2.jnAcc,te=z*_.nx+C*_.ny+_.surfacey+_.c1.bounce-(_.Ka*pe+_.Kb*ce),ue=le*_.nx+he*_.ny+_.surfacey+_.c2.bounce-(_.Kb*pe+_.Kc*ce),xe=-(_.kMassa*te+_.kMassb*ue),_e=-(_.kMassb*te+_.kMassc*ue);xe>=0&&_e>=0?(te=xe-pe,ue=_e-ce,_.c1.jnAcc=xe,_.c2.jnAcc=_e):(xe=-_.c1.nMass*te,xe>=0&&_.Kb*xe+ue>=0?(te=xe-pe,ue=-ce,_.c1.jnAcc=xe,_.c2.jnAcc=0):(_e=-_.c2.nMass*ue,_e>=0&&_.Kb*_e+te>=0?(te=-pe,ue=_e-ce,_.c1.jnAcc=0,_.c2.jnAcc=_e):te>=0&&ue>=0?(te=-pe,ue=-ce,_.c1.jnAcc=_.c2.jnAcc=0):(te=0,ue=0))),w=te+ue,M=_.nx*w,N=_.ny*w,_.b2.velx+=M*_.b2.imass,_.b2.vely+=N*_.b2.imass,_.b1.velx-=M*_.b1.imass,_.b1.vely-=N*_.b1.imass,_.b2.angvel+=(_.rn1b*te+_.rn2b*ue)*_.b2.iinertia,_.b1.angvel-=(_.rn1a*te+_.rn2a*ue)*_.b1.iinertia}else _.radius!=0&&(w=(_.b2.angvel-_.b1.angvel)*_.rMass,g=_.rfric*_.c1.jnAcc,O=_.jrAcc,_.jrAcc-=w,_.jrAcc>g?_.jrAcc=g:_.jrAcc<-g&&(_.jrAcc=-g),w=_.jrAcc-O,_.b2.angvel+=w*_.b2.iinertia,_.b1.angvel-=w*_.b1.iinertia),z=_.k1x+_.b2.velx-_.c1.r2y*_.b2.angvel-(_.b1.velx-_.c1.r1y*_.b1.angvel),C=_.k1y+_.b2.vely+_.c1.r2x*_.b2.angvel-(_.b1.vely+_.c1.r1x*_.b1.angvel),w=(_.c1.bounce+(_.nx*z+_.ny*C)+_.surfacey)*_.c1.nMass,O=_.c1.jnAcc,E=O-w,E<0&&(E=0),w=E-O,_.c1.jnAcc=E,M=_.nx*w,N=_.ny*w,_.b2.velx+=M*_.b2.imass,_.b2.vely+=N*_.b2.imass,_.b1.velx-=M*_.b1.imass,_.b1.vely-=N*_.b1.imass,_.b2.angvel+=_.rn1b*w*_.b2.iinertia,_.b1.angvel-=_.rn1a*w*_.b1.iinertia;let Z=m.colarb,A=Z.k1x+Z.b2.velx-Z.c1.r2y*Z.b2.angvel-(Z.b1.velx-Z.c1.r1y*Z.b1.angvel),S=Z.k1y+Z.b2.vely+Z.c1.r2x*Z.b2.angvel-(Z.b1.vely+Z.c1.r1x*Z.b1.angvel),L=(S*Z.nx-A*Z.ny+Z.surfacex)*Z.c1.tMass,T=Z.c1.friction*Z.c1.jnAcc,G=Z.c1.jtAcc,q=G-L;q>T?q=T:q<-T&&(q=-T),L=q-G,Z.c1.jtAcc=q;let R=-Z.ny*L,j=Z.nx*L;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*L*Z.b2.iinertia,Z.b1.angvel-=Z.rt1a*L*Z.b1.iinertia,Z.hc2){let le=Z.k2x+Z.b2.velx-Z.c2.r2y*Z.b2.angvel-(Z.b1.velx-Z.c2.r1y*Z.b1.angvel),he=Z.k2y+Z.b2.vely+Z.c2.r2x*Z.b2.angvel-(Z.b1.vely+Z.c2.r1x*Z.b1.angvel);L=(he*Z.nx-le*Z.ny+Z.surfacex)*Z.c2.tMass,T=Z.c2.friction*Z.c2.jnAcc,G=Z.c2.jtAcc,q=G-L,q>T?q=T:q<-T&&(q=-T),L=q-G,Z.c2.jtAcc=q,R=-Z.ny*L,j=Z.nx*L,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*L*Z.b2.iinertia,Z.b1.angvel-=Z.rt2a*L*Z.b1.iinertia,A=Z.k1x+Z.b2.velx-Z.c1.r2y*Z.b2.angvel-(Z.b1.velx-Z.c1.r1y*Z.b1.angvel),S=Z.k1y+Z.b2.vely+Z.c1.r2x*Z.b2.angvel-(Z.b1.vely+Z.c1.r1x*Z.b1.angvel),le=Z.k2x+Z.b2.velx-Z.c2.r2y*Z.b2.angvel-(Z.b1.velx-Z.c2.r1y*Z.b1.angvel),he=Z.k2y+Z.b2.vely+Z.c2.r2x*Z.b2.angvel-(Z.b1.vely+Z.c2.r1x*Z.b1.angvel);let pe=Z.c1.jnAcc,ce=Z.c2.jnAcc,te=A*Z.nx+S*Z.ny+Z.surfacey+Z.c1.bounce-(Z.Ka*pe+Z.Kb*ce),ue=le*Z.nx+he*Z.ny+Z.surfacey+Z.c2.bounce-(Z.Kb*pe+Z.Kc*ce),xe=-(Z.kMassa*te+Z.kMassb*ue),_e=-(Z.kMassb*te+Z.kMassc*ue);xe>=0&&_e>=0?(te=xe-pe,ue=_e-ce,Z.c1.jnAcc=xe,Z.c2.jnAcc=_e):(xe=-Z.c1.nMass*te,xe>=0&&Z.Kb*xe+ue>=0?(te=xe-pe,ue=-ce,Z.c1.jnAcc=xe,Z.c2.jnAcc=0):(_e=-Z.c2.nMass*ue,_e>=0&&Z.Kb*_e+te>=0?(te=-pe,ue=_e-ce,Z.c1.jnAcc=0,Z.c2.jnAcc=_e):te>=0&&ue>=0?(te=-pe,ue=-ce,Z.c1.jnAcc=Z.c2.jnAcc=0):(te=0,ue=0))),L=te+ue,R=Z.nx*L,j=Z.ny*L,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*te+Z.rn2b*ue)*Z.b2.iinertia,Z.b1.angvel-=(Z.rn1a*te+Z.rn2a*ue)*Z.b1.iinertia}else Z.radius!=0&&(L=(Z.b2.angvel-Z.b1.angvel)*Z.rMass,T=Z.rfric*Z.c1.jnAcc,G=Z.jrAcc,Z.jrAcc-=L,Z.jrAcc>T?Z.jrAcc=T:Z.jrAcc<-T&&(Z.jrAcc=-T),L=Z.jrAcc-G,Z.b2.angvel+=L*Z.b2.iinertia,Z.b1.angvel-=L*Z.b1.iinertia),A=Z.k1x+Z.b2.velx-Z.c1.r2y*Z.b2.angvel-(Z.b1.velx-Z.c1.r1y*Z.b1.angvel),S=Z.k1y+Z.b2.vely+Z.c1.r2x*Z.b2.angvel-(Z.b1.vely+Z.c1.r1x*Z.b1.angvel),L=(Z.c1.bounce+(Z.nx*A+Z.ny*S)+Z.surfacey)*Z.c1.nMass,G=Z.c1.jnAcc,q=G-L,q<0&&(q=0),L=q-G,Z.c1.jnAcc=q,R=Z.nx*L,j=Z.ny*L,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*L*Z.b2.iinertia,Z.b1.angvel-=Z.rn1a*L*Z.b1.iinertia;let V=m.colarb,K=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),$=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),Y=($*V.nx-K*V.ny+V.surfacex)*V.c1.tMass,X=V.c1.friction*V.c1.jnAcc,ee=V.c1.jtAcc,J=ee-Y;J>X?J=X:J<-X&&(J=-X),Y=J-ee,V.c1.jtAcc=J;let F=-V.ny*Y,D=V.nx*Y;if(V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=V.rt1b*Y*V.b2.iinertia,V.b1.angvel-=V.rt1a*Y*V.b1.iinertia,V.hc2){let le=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),he=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);Y=(he*V.nx-le*V.ny+V.surfacex)*V.c2.tMass,X=V.c2.friction*V.c2.jnAcc,ee=V.c2.jtAcc,J=ee-Y,J>X?J=X:J<-X&&(J=-X),Y=J-ee,V.c2.jtAcc=J,F=-V.ny*Y,D=V.nx*Y,V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=V.rt2b*Y*V.b2.iinertia,V.b1.angvel-=V.rt2a*Y*V.b1.iinertia,K=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),$=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),le=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),he=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);let pe=V.c1.jnAcc,ce=V.c2.jnAcc,te=K*V.nx+$*V.ny+V.surfacey+V.c1.bounce-(V.Ka*pe+V.Kb*ce),ue=le*V.nx+he*V.ny+V.surfacey+V.c2.bounce-(V.Kb*pe+V.Kc*ce),xe=-(V.kMassa*te+V.kMassb*ue),_e=-(V.kMassb*te+V.kMassc*ue);xe>=0&&_e>=0?(te=xe-pe,ue=_e-ce,V.c1.jnAcc=xe,V.c2.jnAcc=_e):(xe=-V.c1.nMass*te,xe>=0&&V.Kb*xe+ue>=0?(te=xe-pe,ue=-ce,V.c1.jnAcc=xe,V.c2.jnAcc=0):(_e=-V.c2.nMass*ue,_e>=0&&V.Kb*_e+te>=0?(te=-pe,ue=_e-ce,V.c1.jnAcc=0,V.c2.jnAcc=_e):te>=0&&ue>=0?(te=-pe,ue=-ce,V.c1.jnAcc=V.c2.jnAcc=0):(te=0,ue=0))),Y=te+ue,F=V.nx*Y,D=V.ny*Y,V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=(V.rn1b*te+V.rn2b*ue)*V.b2.iinertia,V.b1.angvel-=(V.rn1a*te+V.rn2a*ue)*V.b1.iinertia}else V.radius!=0&&(Y=(V.b2.angvel-V.b1.angvel)*V.rMass,X=V.rfric*V.c1.jnAcc,ee=V.jrAcc,V.jrAcc-=Y,V.jrAcc>X?V.jrAcc=X:V.jrAcc<-X&&(V.jrAcc=-X),Y=V.jrAcc-ee,V.b2.angvel+=Y*V.b2.iinertia,V.b1.angvel-=Y*V.b1.iinertia),K=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),$=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),Y=(V.c1.bounce+(V.nx*K+V.ny*$)+V.surfacey)*V.c1.nMass,ee=V.c1.jnAcc,J=ee-Y,J<0&&(J=0),Y=J-ee,V.c1.jnAcc=J,F=V.nx*Y,D=V.ny*Y,V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=V.rn1b*Y*V.b2.iinertia,V.b1.angvel-=V.rn1a*Y*V.b1.iinertia;let I=m.colarb,U=I.k1x+I.b2.velx-I.c1.r2y*I.b2.angvel-(I.b1.velx-I.c1.r1y*I.b1.angvel),Q=I.k1y+I.b2.vely+I.c1.r2x*I.b2.angvel-(I.b1.vely+I.c1.r1x*I.b1.angvel),W=(Q*I.nx-U*I.ny+I.surfacex)*I.c1.tMass,ie=I.c1.friction*I.c1.jnAcc,oe=I.c1.jtAcc,se=oe-W;se>ie?se=ie:se<-ie&&(se=-ie),W=se-oe,I.c1.jtAcc=se;let ne=-I.ny*W,re=I.nx*W;if(I.b2.velx+=ne*I.b2.imass,I.b2.vely+=re*I.b2.imass,I.b1.velx-=ne*I.b1.imass,I.b1.vely-=re*I.b1.imass,I.b2.angvel+=I.rt1b*W*I.b2.iinertia,I.b1.angvel-=I.rt1a*W*I.b1.iinertia,I.hc2){let le=I.k2x+I.b2.velx-I.c2.r2y*I.b2.angvel-(I.b1.velx-I.c2.r1y*I.b1.angvel),he=I.k2y+I.b2.vely+I.c2.r2x*I.b2.angvel-(I.b1.vely+I.c2.r1x*I.b1.angvel);W=(he*I.nx-le*I.ny+I.surfacex)*I.c2.tMass,ie=I.c2.friction*I.c2.jnAcc,oe=I.c2.jtAcc,se=oe-W,se>ie?se=ie:se<-ie&&(se=-ie),W=se-oe,I.c2.jtAcc=se,ne=-I.ny*W,re=I.nx*W,I.b2.velx+=ne*I.b2.imass,I.b2.vely+=re*I.b2.imass,I.b1.velx-=ne*I.b1.imass,I.b1.vely-=re*I.b1.imass,I.b2.angvel+=I.rt2b*W*I.b2.iinertia,I.b1.angvel-=I.rt2a*W*I.b1.iinertia,U=I.k1x+I.b2.velx-I.c1.r2y*I.b2.angvel-(I.b1.velx-I.c1.r1y*I.b1.angvel),Q=I.k1y+I.b2.vely+I.c1.r2x*I.b2.angvel-(I.b1.vely+I.c1.r1x*I.b1.angvel),le=I.k2x+I.b2.velx-I.c2.r2y*I.b2.angvel-(I.b1.velx-I.c2.r1y*I.b1.angvel),he=I.k2y+I.b2.vely+I.c2.r2x*I.b2.angvel-(I.b1.vely+I.c2.r1x*I.b1.angvel);let pe=I.c1.jnAcc,ce=I.c2.jnAcc,te=U*I.nx+Q*I.ny+I.surfacey+I.c1.bounce-(I.Ka*pe+I.Kb*ce),ue=le*I.nx+he*I.ny+I.surfacey+I.c2.bounce-(I.Kb*pe+I.Kc*ce),xe=-(I.kMassa*te+I.kMassb*ue),_e=-(I.kMassb*te+I.kMassc*ue);xe>=0&&_e>=0?(te=xe-pe,ue=_e-ce,I.c1.jnAcc=xe,I.c2.jnAcc=_e):(xe=-I.c1.nMass*te,xe>=0&&I.Kb*xe+ue>=0?(te=xe-pe,ue=-ce,I.c1.jnAcc=xe,I.c2.jnAcc=0):(_e=-I.c2.nMass*ue,_e>=0&&I.Kb*_e+te>=0?(te=-pe,ue=_e-ce,I.c1.jnAcc=0,I.c2.jnAcc=_e):te>=0&&ue>=0?(te=-pe,ue=-ce,I.c1.jnAcc=I.c2.jnAcc=0):(te=0,ue=0))),W=te+ue,ne=I.nx*W,re=I.ny*W,I.b2.velx+=ne*I.b2.imass,I.b2.vely+=re*I.b2.imass,I.b1.velx-=ne*I.b1.imass,I.b1.vely-=re*I.b1.imass,I.b2.angvel+=(I.rn1b*te+I.rn2b*ue)*I.b2.iinertia,I.b1.angvel-=(I.rn1a*te+I.rn2a*ue)*I.b1.iinertia}else I.radius!=0&&(W=(I.b2.angvel-I.b1.angvel)*I.rMass,ie=I.rfric*I.c1.jnAcc,oe=I.jrAcc,I.jrAcc-=W,I.jrAcc>ie?I.jrAcc=ie:I.jrAcc<-ie&&(I.jrAcc=-ie),W=I.jrAcc-oe,I.b2.angvel+=W*I.b2.iinertia,I.b1.angvel-=W*I.b1.iinertia),U=I.k1x+I.b2.velx-I.c1.r2y*I.b2.angvel-(I.b1.velx-I.c1.r1y*I.b1.angvel),Q=I.k1y+I.b2.vely+I.c1.r2x*I.b2.angvel-(I.b1.vely+I.c1.r1x*I.b1.angvel),W=(I.c1.bounce+(I.nx*U+I.ny*Q)+I.surfacey)*I.c1.nMass,oe=I.c1.jnAcc,se=oe-W,se<0&&(se=0),W=se-oe,I.c1.jnAcc=se,ne=I.nx*W,re=I.ny*W,I.b2.velx+=ne*I.b2.imass,I.b2.vely+=re*I.b2.imass,I.b1.velx-=ne*I.b1.imass,I.b1.vely-=re*I.b1.imass,I.b2.angvel+=I.rn1b*W*I.b2.iinertia,I.b1.angvel-=I.rn1a*W*I.b1.iinertia;h.sweep_angvel=h.angvel%t,u.sweep_angvel=u.angvel%t}if(m!=null&&m.active&&(m.immState&1)!=0&&m.type==Ie.COL){if(!h.sweepFrozen&&h.type!=3)if(h.sweepFrozen=!0,l.failed)h.angvel=h.sweep_angvel=0;else if(l.slipped){let y=h;y.sweep_angvel*=B._nape.Config.angularCCDSlipScale,h.angvel=y.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 y=u;y.sweep_angvel*=B._nape.Config.angularCCDSlipScale,u.angvel=y.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 o=this.toiEvents.pop_unsafe();o.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=o}let s=this.kinematics.head;for(;s!=null;){let l=s.elt,o=e-l.sweepTime;if(o!=0){l.sweepTime=e;let r=o;if(l.posx+=l.velx*r,l.posy+=l.vely*r,l.angvel!=0){let a=l.sweep_angvel*o;if(l.rot+=a,a*a>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=a*a,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+a*l.axisy)*h;l.axisy=(c*l.axisy-a*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 o=e-l.sweepTime;if(o!=0){l.sweepTime=e;let r=o;if(l.posx+=l.velx*r,l.posy+=l.vely*r,l.angvel!=0){let a=l.sweep_angvel*o;if(l.rot+=a,a*a>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=a*a,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+a*l.axisy)*h;l.axisy=(c*l.axisy-a*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 a=e.body,p=t.body,c;c=!1;let h=a.constraints.head;for(;h!=null;){let m=h.elt;if(m.ignore&&m.pair_exists(a.id,p.id)){c=!0;break}h=h.next}let u,x;if(c)x=!1;else{let m=e;for(;m!=null&&m.group==null;)m.ishape!=null?m=m.ishape.body:m.icompound!=null?m=m.icompound.compound:m=m.ibody.compound;let d=m==null?null:m.group,y;if(d==null)y=!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 b=f==null?null:f.group;if(b==null)y=!1;else{let P=!1;for(;d!=null&&b!=null;){if(d==b){P=d.ignore;break}d.depth<b.depth?b=b.group:d=d.group}y=P}}x=!y}if(x){let m;if(e.sensorEnabled||t.sensorEnabled){let d=e.filter,y=t.filter;m=(d.sensorMask&y.sensorGroup)!=0&&(y.sensorMask&d.sensorGroup)!=0}else m=!1;if(m)u=2;else{let d;if(e.fluidEnabled||t.fluidEnabled){let y=e.filter,f=t.filter;d=(y.fluidMask&f.fluidGroup)!=0&&(f.fluidMask&y.fluidGroup)!=0}else d=!1;if(d&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0))u=0;else{let y=e.filter,f=t.filter;u=(y.collisionMask&f.collisionGroup)!=0&&(f.collisionMask&y.collisionGroup)!=0&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0)?1:-1}}}else u=-1;l=u<=0}if(l)return s;let o=e.body,r=t.body;if(n||o.bullet||r.bullet){let a;B._zpp.geom.ZPP_ToiEvent.zpp_pool==null?a=new B._zpp.geom.ZPP_ToiEvent:(a=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._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,Cn.staticSweep(a,this.pre_dt,0,B._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}Cn.staticSweep(a,this.pre_dt,0,B._nape.Config.collisionSlopCCD)}else Cn.dynamicSweep(a,this.pre_dt,0,B._nape.Config.collisionSlopCCD,!1);if(n&&a.toi<0||a.failed){let c=a;c.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._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=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,o=l.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=l.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,o=i.ishape!=null?i.ishape:null,r=l.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 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 m=x.arbiters.pop_unsafe();m.present--}this.remove_callbackset(x)}h=h.next}p=p.next}r=r.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 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=B._zpp.phys.ZPP_Interactor.get(r,p);c!=null&&(l.present--,c.remove_arb(l),c.arbiters.head==null&&this.remove_callbackset(c)),a=a.next}o=o.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,o=l.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=l.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,o=i.ishape!=null?i.ishape:null,r=l.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 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=Kt.get(c,u),this.add_callbackset(x));let m,d;d=!1;let y=x.arbiters.head;for(;y!=null;){if(y.elt==a){d=!0;break}y=y.next}if(d)m=!1;else{let f=x.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=a;let P=b;P.next=f.head,f.head=P,f.modified=!0,f.length++,m=!0}m&&a.present++,h=h.next}p=p.next}r=r.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 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,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 y=d.elt;if(y.a==c&&y.b==h||y.a==h&&y.b==c){x=y;break}d=d.next}if(x==null){let y;Ne.zpp_pool==null?y=new Ne:(y=Ne.zpp_pool,Ne.zpp_pool=y.next,y.next=null),y.zip_listeners=!0,_t.setlt(c,h)?(y.a=c,y.b=h):(y.a=h,y.b=c),x=y,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 y=B._zpp.phys.ZPP_Interactor.get(r,p);y==null&&(y=Kt.get(r,p),this.add_callbackset(y));let f,b;b=!1;let P=y.arbiters.head;for(;P!=null;){if(P.elt==l){b=!0;break}P=P.next}if(b)f=!1;else{let k=y.arbiters,_;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_Arbiter:(_=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_.next,_.next=null),_.elt=l;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++,f=!0}f&&l.present++}a=a.next}o=o.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==Ie.COL){let o=l.colarb;if(o.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=o;let p=a;p.next=r.head,r.head=p,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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}}else if(l.type==Ie.FLUID){let o=this.f_arbiters,r=l.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 p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}else{let o=this.s_arbiters,r=l.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 p=a;p.next=o.head,o.head=p,o.modified=!0,o.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 o=l.elt;o.node!=null&&this.bphase.sync(o),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 o=l;o.next=i.head,i.head=o,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=xt.zpp_pool,xt.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 o=l;o.next=i.head,i.head=o,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 o=l;o.next=i.head,i.head=o,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==Ie.COL){let l=i.colarb;if(l.stat){let o=this.c_arbiters_true,r;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(r=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=l;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}else{let o=this.c_arbiters_false,r;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(r=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=l;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}}else if(i.type==Ie.FLUID){let l=this.f_arbiters,o=i.fluidarb,r;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(r=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=l.head,l.head=a,l.modified=!0,l.length++}else{let l=this.s_arbiters,o=i.sensorarb,r;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(r=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=l.head,l.head=a,l.modified=!0,l.length++}if(i.type!=Ie.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 r=i.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}l=r}let o;if(i.b2.component==i.b2.component.parent)o=i.b2.component;else{let r=i.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}l!=o&&(l.rank<o.rank?l.parent=o:l.rank>o.rank?o.parent=l:(o.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 r=i.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}l=r}let o;if(i.b2.component==i.b2.component.parent)o=i.b2.component;else{let r=i.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}l!=o&&(l.rank<o.rank?l.parent=o:l.rank>o.rank?o.parent=l:(o.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 o=l,r=o.component,a;if(r==r.parent)a=r;else{let x=r,m=null;for(;x!=x.parent;){let d=x.parent;x.parent=m,m=x,x=d}for(;m!=null;){let d=m.parent;m.parent=x,m=d}a=x}if(a.island==null){xt.zpp_pool==null?a.island=new xt:(a.island=xt.zpp_pool,xt.zpp_pool=a.island.next,a.island.next=null),a.island.waket=0;let x=this.islands,m=a.island;m._inuse=!0;let d=m;d.next=x.next,x.next=d,x.modified=!0,x.length++,a.island.sleep=!0}r.island=a.island;let p=r.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=r;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++;let u=o.atRest(e);r.island.sleep=r.island.sleep&&u,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.live_constraints.head!=null;){let i=this.live_constraints,l=i.head.elt;i.pop();let r=l.component,a;if(r==r.parent)a=r;else{let u=r,x=null;for(;u!=u.parent;){let m=u.parent;u.parent=x,x=u,u=m}for(;x!=null;){let m=x.parent;x.parent=u,x=m}a=u}r.island=a.island;let p=r.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=r;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.islands.next!=null;){let i=this.islands,l=i.next;i.pop();let o=l;if(this.deterministic&&this._sortLinkedList(o.comps,r=>r.isBody?r.body.id:r.constraint.id+1e9),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 h=c.elt;this.bphase.sync(h),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 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 m=x;m.next=h.head,h.head=m,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 m=x;m.next=h.head,h.head=m,h.modified=!0,h.length++}c.sleeping=!1,c.island=null,c.parent=c,c.rank=0}let r=o;r.next=xt.zpp_pool,xt.zpp_pool=r}}}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,m;e==null?(x=t.head,m=x.next,t.head=m,t.head==null&&(t.pushmod=!0)):(x=e.next,m=x.next,e.next=m,m==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=m,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,o=l.head,r=!1;for(r&&o==null&&(r=!1,l=null,i=null);o!=null;){let u=o.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=!0;let x,m;i==null?(x=l.head,m=x.next,l.head=m,l.head==null&&(l.pushmod=!0)):(x=i.next,m=x.next,i.next=m,m==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,o=m,r&&o==null&&(r=!1,l=null,i=null);continue}i=o,o=o.next,r&&o==null&&(r=!1,l=null,i=null)}let a=null,p=this.s_arbiters,c=p.head,h=!1;for(h&&c==null&&(h=!1,p=null,a=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,m;a==null?(x=p.head,m=x.next,p.head=m,p.head==null&&(p.pushmod=!0)):(x=a.next,m=x.next,a.next=m,m==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=m,h&&c==null&&(h=!1,p=null,a=null);continue}a=c,c=c.next,h&&c==null&&(h=!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 s=n.elt;if(s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let o=s.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 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 m=u;for(u=u.next;u!=null;){let k=u;h+=m.x*(k.y-x.y);let _=k.y*m.x-k.x*m.y;c.localCOMx+=(m.x+k.x)*_,c.localCOMy+=(m.y+k.y)*_,x=m,m=k,u=u.next}u=c.lverts.next;let d=u;h+=m.x*(d.y-x.y);let y=d.y*m.x-d.x*m.y;c.localCOMx+=(m.x+d.x)*y,c.localCOMy+=(m.y+d.y)*y,x=m,m=d,u=u.next;let f=u;h+=m.x*(f.y-x.y);let b=f.y*m.x-f.x*m.y;c.localCOMx+=(m.x+f.x)*b,c.localCOMy+=(m.y+f.y)*b,h=1/(3*h);let P=h;c.localCOMx*=P,c.localCOMy*=P}}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 if(s.type===2)s.capsule.__validate_aabb();else{let o=s.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,h=o.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),u.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),h=h.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 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 o=l.body;if(o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.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,m=l.gverts.next;for(;m!=null;){let d=m,y=x;x=x.next,d.x=l.body.posx+(l.body.axisy*y.x-l.body.axisx*y.y),d.y=l.body.posy+(y.x*l.body.axisx+y.y*l.body.axisy),m=m.next}}let r=l.edges.head,a=l.gverts.next,p=a;for(a=a.next;a!=null;){let u=a,x=r.elt;r=r.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,a=a.next}let c=l.gverts.next,h=r.elt;r=r.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 r=l.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(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 : "+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 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 b=c.lverts.next,P=c.gverts.next;for(;P!=null;){let k=P,_=b;b=b.next,k.x=c.body.posx+(c.body.axisy*_.x-c.body.axisx*_.y),k.y=c.body.posy+(_.x*c.body.axisx+_.y*c.body.axisy),P=P.next}}let u=c.edges.head,x=c.gverts.next,m=x;for(x=x.next;x!=null;){let f=x,b=u.elt;u=u.next,b.gp0=m,b.gp1=f,b.gnormx=c.body.axisy*b.lnormx-c.body.axisx*b.lnormy,b.gnormy=b.lnormx*c.body.axisx+b.lnormy*c.body.axisy,b.gprojection=c.body.posx*b.gnormx+c.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,m=f,x=x.next}let d=c.gverts.next,y=u.elt;u=u.next,y.gp0=m,y.gp1=d,y.gnormx=c.body.axisy*y.lnormx-c.body.axisx*y.lnormy,y.gnormy=y.lnormx*c.body.axisx+y.lnormy*c.body.axisy,y.gprojection=c.body.posx*y.gnormx+c.body.posy*y.gnormy+y.lprojection,y.wrap_gnorm!=null&&(y.wrap_gnorm.zpp_inner.x=y.gnormx,y.wrap_gnorm.zpp_inner.y=y.gnormy),y.tp0=y.gp0.y*y.gnormx-y.gp0.x*y.gnormy,y.tp1=y.gp1.y*y.gnormx-y.gp1.x*y.gnormy}}r.validate_sweepRadius(),r.sweepRadius>i.sweepRadius&&(i.sweepRadius=r.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 r=i.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 h=a.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 y=1;d.localCOMx+=d.lverts.next.next.x*y,d.localCOMy+=d.lverts.next.next.y*y;let f=.5;d.localCOMx*=f,d.localCOMy*=f}else{d.localCOMx=0,d.localCOMy=0;let y=0,f=d.lverts.next,b=f;f=f.next;let P=f;for(f=f.next;f!=null;){let g=f;y+=P.x*(g.y-b.y);let O=g.y*P.x-g.x*P.y;d.localCOMx+=(P.x+g.x)*O,d.localCOMy+=(P.y+g.y)*O,b=P,P=g,f=f.next}f=d.lverts.next;let k=f;y+=P.x*(k.y-b.y);let _=k.y*P.x-k.x*P.y;d.localCOMx+=(P.x+k.x)*_,d.localCOMy+=(P.y+k.y)*_,b=P,P=k,f=f.next;let z=f;y+=P.x*(z.y-b.y);let C=z.y*P.x-z.x*P.y;d.localCOMx+=(P.x+z.x)*C,d.localCOMy+=(P.y+z.y)*C,y=1/(3*y);let w=y;d.localCOMx*=w,d.localCOMy*=w}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy)}let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.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 if(a.type===2)a.capsule.__validate_aabb();else{let h=a.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot));let d=h.lverts.next,y=h.gverts.next;for(;y!=null;){let f=y,b=d;d=d.next,f.x=h.body.posx+(h.body.axisy*b.x-h.body.axisx*b.y),f.y=h.body.posy+(b.x*h.body.axisx+b.y*h.body.axisy),y=y.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 m=x;m.x<h.aabb.minx&&(h.aabb.minx=m.x),m.x>h.aabb.maxx&&(h.aabb.maxx=m.x),m.y<h.aabb.miny&&(h.aabb.miny=m.y),m.y>h.aabb.maxy&&(h.aabb.maxy=m.y),x=x.next}}let p=i.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}}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 r=i.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=i,r=r.next}}i.component.woken=!1;let o=i.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 i=n.elt;i.sweepRadius=0;let l=i.shapes.head;for(;l!=null;){let r=l.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(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 : "+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 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 b=c.lverts.next,P=c.gverts.next;for(;P!=null;){let k=P,_=b;b=b.next,k.x=c.body.posx+(c.body.axisy*_.x-c.body.axisx*_.y),k.y=c.body.posy+(_.x*c.body.axisx+_.y*c.body.axisy),P=P.next}}let u=c.edges.head,x=c.gverts.next,m=x;for(x=x.next;x!=null;){let f=x,b=u.elt;u=u.next,b.gp0=m,b.gp1=f,b.gnormx=c.body.axisy*b.lnormx-c.body.axisx*b.lnormy,b.gnormy=b.lnormx*c.body.axisx+b.lnormy*c.body.axisy,b.gprojection=c.body.posx*b.gnormx+c.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,m=f,x=x.next}let d=c.gverts.next,y=u.elt;u=u.next,y.gp0=m,y.gp1=d,y.gnormx=c.body.axisy*y.lnormx-c.body.axisx*y.lnormy,y.gnormy=y.lnormx*c.body.axisx+y.lnormy*c.body.axisy,y.gprojection=c.body.posx*y.gnormx+c.body.posy*y.gnormy+y.lprojection,y.wrap_gnorm!=null&&(y.wrap_gnorm.zpp_inner.x=y.gnormx,y.wrap_gnorm.zpp_inner.y=y.gnormy),y.tp0=y.gp0.y*y.gnormx-y.gp0.x*y.gnormy,y.tp1=y.gp1.y*y.gnormx-y.gp1.x*y.gnormy}}r.validate_sweepRadius(),r.sweepRadius>i.sweepRadius&&(i.sweepRadius=r.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 r=i.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 h=a.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 y=1;d.localCOMx+=d.lverts.next.next.x*y,d.localCOMy+=d.lverts.next.next.y*y;let f=.5;d.localCOMx*=f,d.localCOMy*=f}else{d.localCOMx=0,d.localCOMy=0;let y=0,f=d.lverts.next,b=f;f=f.next;let P=f;for(f=f.next;f!=null;){let g=f;y+=P.x*(g.y-b.y);let O=g.y*P.x-g.x*P.y;d.localCOMx+=(P.x+g.x)*O,d.localCOMy+=(P.y+g.y)*O,b=P,P=g,f=f.next}f=d.lverts.next;let k=f;y+=P.x*(k.y-b.y);let _=k.y*P.x-k.x*P.y;d.localCOMx+=(P.x+k.x)*_,d.localCOMy+=(P.y+k.y)*_,b=P,P=k,f=f.next;let z=f;y+=P.x*(z.y-b.y);let C=z.y*P.x-z.x*P.y;d.localCOMx+=(P.x+z.x)*C,d.localCOMy+=(P.y+z.y)*C,y=1/(3*y);let w=y;d.localCOMx*=w,d.localCOMy*=w}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy)}let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.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 if(a.type===2)a.capsule.__validate_aabb();else{let h=a.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot));let d=h.lverts.next,y=h.gverts.next;for(;y!=null;){let f=y,b=d;d=d.next,f.x=h.body.posx+(h.body.axisy*b.x-h.body.axisx*b.y),f.y=h.body.posy+(b.x*h.body.axisx+b.y*h.body.axisy),y=y.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 m=x;m.x<h.aabb.minx&&(h.aabb.minx=m.x),m.x>h.aabb.maxx&&(h.aabb.maxx=m.x),m.y<h.aabb.miny&&(h.aabb.miny=m.y),m.y>h.aabb.maxy&&(h.aabb.maxy=m.y),x=x.next}}let p=i.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}}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 o=i.shapes.head;for(;o!=null;){let r=o.elt;this.bphase.sync(r),o=o.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 o=l.elt;if(o.event!=2){l=l.next;continue}let r=this.push_callback(o);r.event=2,r.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 o=e*l.imass;l.velx=n*l.velx+(l.forcex+this.gravityx*l.gravMass)*o,l.vely=n*l.vely+(l.forcey+this.gravityy*l.gravMass)*o}if(l.sinertia!=0){let o=0,r=0;o=l.worldCOMx-l.posx,r=l.worldCOMy-l.posy;let a=l.torque+(this.gravityy*o-this.gravityx*r)*l.gravMass;l.angvel=s*l.angvel+a*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 o=l;if(i.posx+=i.velx*o,i.posy+=i.vely*o,i.angvel!=0){let r=i.sweep_angvel*l;if(i.rot+=r,r*r>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+r*i.axisy)*c;i.axisy=(p*i.axisy-r*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let o=B._nape.Config.staticCCDLinearThreshold*i.sweepRadius,r=B._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>o*o||i.angvel*i.angvel*e*e>r*r||i.type==3){let a=i.sweep_angvel;a<0&&(a=-a);let p=1/a,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,m=u.miny,d=u.maxx,y=u.maxy,f=a*e*h.sweepCoef*.008333333333333333|0;f>8&&(f=8);let b=a*e/f,P=e-i.sweepTime;if(P!=0){i.sweepTime=e;let z=P;if(i.posx+=i.velx*z,i.posy+=i.vely*z,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 w=C*C,g=1-.5*w,O=1-w*w/8,E=(g*i.axisx+C*i.axisy)*O;i.axisy=(g*i.axisy-C*i.axisx)*O,i.axisx=E}}}if(h.type==0){let z=h.circle;z.worldCOMx=z.body.posx+(z.body.axisy*z.localCOMx-z.body.axisx*z.localCOMy),z.worldCOMy=z.body.posy+(z.localCOMx*z.body.axisx+z.localCOMy*z.body.axisy),z.aabb.minx=z.worldCOMx-z.radius,z.aabb.miny=z.worldCOMy-z.radius,z.aabb.maxx=z.worldCOMx+z.radius,z.aabb.maxy=z.worldCOMy+z.radius}else if(h.type===2)h.capsule.__validate_aabb();else{let z=h.polygon,C=z.lverts.next,w=z.gverts.next,g=C;C=C.next,w.x=z.body.posx+(z.body.axisy*g.x-z.body.axisx*g.y),w.y=z.body.posy+(g.x*z.body.axisx+g.y*z.body.axisy),z.aabb.minx=w.x,z.aabb.miny=w.y,z.aabb.maxx=w.x,z.aabb.maxy=w.y;let O=z.gverts.next.next;for(;O!=null;){let E=O,M=C;C=C.next,E.x=z.body.posx+(z.body.axisy*M.x-z.body.axisx*M.y),E.y=z.body.posy+(M.x*z.body.axisx+M.y*z.body.axisy),E.x<z.aabb.minx&&(z.aabb.minx=E.x),E.x>z.aabb.maxx&&(z.aabb.maxx=E.x),E.y<z.aabb.miny&&(z.aabb.miny=E.y),E.y>z.aabb.maxy&&(z.aabb.maxy=E.y),O=O.next}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;let k=1,_=f;for(;k<_;){let z=k++,C=b*z*p,w=C-i.sweepTime;if(w!=0){i.sweepTime=C;let g=w;if(i.posx+=i.velx*g,i.posy+=i.vely*g,i.angvel!=0){let O=i.sweep_angvel*w;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 g=h.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 if(h.type===2)h.capsule.__validate_aabb();else{let g=h.polygon,O=g.lverts.next,E=g.gverts.next,M=O;O=O.next,E.x=g.body.posx+(g.body.axisy*M.x-g.body.axisx*M.y),E.y=g.body.posy+(M.x*g.body.axisx+M.y*g.body.axisy),g.aabb.minx=E.x,g.aabb.miny=E.y,g.aabb.maxx=E.x,g.aabb.maxy=E.y;let N=g.gverts.next.next;for(;N!=null;){let Z=N,A=O;O=O.next,Z.x=g.body.posx+(g.body.axisy*A.x-g.body.axisx*A.y),Z.y=g.body.posy+(A.x*g.body.axisx+A.y*g.body.axisy),Z.x<g.aabb.minx&&(g.aabb.minx=Z.x),Z.x>g.aabb.maxx&&(g.aabb.maxx=Z.x),Z.y<g.aabb.miny&&(g.aabb.miny=Z.y),Z.y>g.aabb.maxy&&(g.aabb.maxy=Z.y),N=N.next}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,y>u.maxy?u.maxy=y:y=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 o=l;if(i.posx+=i.velx*o,i.posy+=i.vely*o,i.angvel!=0){let r=i.sweep_angvel*l;if(i.rot+=r,r*r>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+r*i.axisy)*c;i.axisy=(p*i.axisy-r*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let o=B._nape.Config.staticCCDLinearThreshold*i.sweepRadius,r=B._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>o*o||i.angvel*i.angvel*e*e>r*r||i.type==3){let a=i.sweep_angvel;a<0&&(a=-a);let p=1/a,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,m=u.miny,d=u.maxx,y=u.maxy,f=a*e*h.sweepCoef*.008333333333333333|0;f>8&&(f=8);let b=a*e/f,P=e-i.sweepTime;if(P!=0){i.sweepTime=e;let z=P;if(i.posx+=i.velx*z,i.posy+=i.vely*z,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 w=C*C,g=1-.5*w,O=1-w*w/8,E=(g*i.axisx+C*i.axisy)*O;i.axisy=(g*i.axisy-C*i.axisx)*O,i.axisx=E}}}if(h.type==0){let z=h.circle;z.worldCOMx=z.body.posx+(z.body.axisy*z.localCOMx-z.body.axisx*z.localCOMy),z.worldCOMy=z.body.posy+(z.localCOMx*z.body.axisx+z.localCOMy*z.body.axisy),z.aabb.minx=z.worldCOMx-z.radius,z.aabb.miny=z.worldCOMy-z.radius,z.aabb.maxx=z.worldCOMx+z.radius,z.aabb.maxy=z.worldCOMy+z.radius}else if(h.type===2)h.capsule.__validate_aabb();else{let z=h.polygon,C=z.lverts.next,w=z.gverts.next,g=C;C=C.next,w.x=z.body.posx+(z.body.axisy*g.x-z.body.axisx*g.y),w.y=z.body.posy+(g.x*z.body.axisx+g.y*z.body.axisy),z.aabb.minx=w.x,z.aabb.miny=w.y,z.aabb.maxx=w.x,z.aabb.maxy=w.y;let O=z.gverts.next.next;for(;O!=null;){let E=O,M=C;C=C.next,E.x=z.body.posx+(z.body.axisy*M.x-z.body.axisx*M.y),E.y=z.body.posy+(M.x*z.body.axisx+M.y*z.body.axisy),E.x<z.aabb.minx&&(z.aabb.minx=E.x),E.x>z.aabb.maxx&&(z.aabb.maxx=E.x),E.y<z.aabb.miny&&(z.aabb.miny=E.y),E.y>z.aabb.maxy&&(z.aabb.maxy=E.y),O=O.next}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;let k=1,_=f;for(;k<_;){let z=k++,C=b*z*p,w=C-i.sweepTime;if(w!=0){i.sweepTime=C;let g=w;if(i.posx+=i.velx*g,i.posy+=i.vely*g,i.angvel!=0){let O=i.sweep_angvel*w;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 g=h.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=h.polygon,O=g.lverts.next,E=g.gverts.next,M=O;O=O.next,E.x=g.body.posx+(g.body.axisy*M.x-g.body.axisx*M.y),E.y=g.body.posy+(M.x*g.body.axisx+M.y*g.body.axisy),g.aabb.minx=E.x,g.aabb.miny=E.y,g.aabb.maxx=E.x,g.aabb.maxy=E.y;let N=g.gverts.next.next;for(;N!=null;){let Z=N,A=O;O=O.next,Z.x=g.body.posx+(g.body.axisy*A.x-g.body.axisx*A.y),Z.y=g.body.posy+(A.x*g.body.axisx+A.y*g.body.axisy),Z.x<g.aabb.minx&&(g.aabb.minx=Z.x),Z.x>g.aabb.maxx&&(g.aabb.maxx=Z.x),Z.y<g.aabb.miny&&(g.aabb.miny=Z.y),Z.y>g.aabb.maxy&&(g.aabb.maxy=Z.y),N=N.next}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,d>u.maxx?u.maxx=d:d=u.maxx,y>u.maxy?u.maxy=y:y=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 o=e.ws1,r=e.ws2,a=this.mrca1;for(;a.head!=null;){let x=a.head;a.head=x.next;let m=x;m.elt=null,m.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m,a.head==null&&(a.pushmod=!0),a.modified=!0,a.length--}a.pushmod=!0;let p=this.mrca2;for(;p.head!=null;){let x=p.head;p.head=x.next;let m=x;m.elt=null,m.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m,p.head==null&&(p.pushmod=!0),p.modified=!0,p.length--}if(p.pushmod=!0,o.cbSet!=null){let x=this.mrca1,m;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?m=new B._zpp.util.ZNPNode_ZPP_Interactor:(m=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m.next,m.next=null),m.elt=o;let d=m;d.next=x.head,x.head=d,x.modified=!0,x.length++}if(o.body.cbSet!=null){let x=this.mrca1,m=o.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=m;let y=d;y.next=x.head,x.head=y,x.modified=!0,x.length++}if(r.cbSet!=null){let x=this.mrca2,m;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?m=new B._zpp.util.ZNPNode_ZPP_Interactor:(m=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m.next,m.next=null),m.elt=r;let d=m;d.next=x.head,x.head=d,x.modified=!0,x.length++}if(r.body.cbSet!=null){let x=this.mrca2,m=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=m;let y=d;y.next=x.head,x.head=y,x.modified=!0,x.length++}let c=o.body.compound,h=r.body.compound;for(;c!=h;){let x=c==null?0:c.depth,m=h==null?0:h.depth;if(x<m){if(h.cbSet!=null){let d=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=h;let f=y;f.next=d.head,d.head=f,d.modified=!0,d.length++}h=h.compound}else{if(c.cbSet!=null){let d=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=c;let f=y;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,m=this.mrca2.head;for(;m!=null;){let d=m.elt,y=x.cbSet,f=d.cbSet,b=y.manager,P=null,_=(y.cbpairs.length<f.cbpairs.length?y.cbpairs:f.cbpairs).head;for(;_!=null;){let C=_.elt;if(C.a==y&&C.b==f||C.a==f&&C.b==y){P=C;break}_=_.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,_t.setlt(y,f)?(C.a=y,C.b=f):(C.a=f,C.b=y),P=C,y.cbpairs.add(P),f!=y&&f.cbpairs.add(P)}if(P.zip_listeners&&(P.zip_listeners=!1,P.__validate()),P.listeners.head==null){m=m.next;continue}let z=B._zpp.phys.ZPP_Interactor.get(x,d);if(l||e.intchange){z==null&&(z=Kt.get(x,d),this.add_callbackset(z));let C=y.manager,w=null,O=(y.cbpairs.length<f.cbpairs.length?y.cbpairs:f.cbpairs).head;for(;O!=null;){let A=O.elt;if(A.a==y&&A.b==f||A.a==f&&A.b==y){w=A;break}O=O.next}if(w==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,_t.setlt(y,f)?(A.a=y,A.b=f):(A.a=f,A.b=y),w=A,y.cbpairs.add(w),f!=y&&f.cbpairs.add(w)}w.zip_listeners&&(w.zip_listeners=!1,w.__validate());let E=w.listeners.head;for(;E!=null;){let A=E.elt;if(A.event==0&&(A.itype&e.type)!=0&&z.empty_arb(A.itype)){let S=this.push_callback(A);S.event=0;let L=z.int1,T=z.int2,G,q=A.options1,R=L.cbTypes;if(q.nonemptyintersection(R,q.includes)&&!q.nonemptyintersection(R,q.excludes)){let j=A.options2,V=T.cbTypes;G=j.nonemptyintersection(V,j.includes)&&!j.nonemptyintersection(V,j.excludes)}else G=!1;G?(S.int1=L,S.int2=T):(S.int1=T,S.int2=L),S.set=z}E=E.next}let M,N;N=!1;let Z=z.arbiters.head;for(;Z!=null;){if(Z.elt==e){N=!0;break}Z=Z.next}if(N)M=!1;else{let A=z.arbiters,S;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?S=new B._zpp.util.ZNPNode_ZPP_Arbiter:(S=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=S.next,S.next=null),S.elt=e;let L=S;L.next=A.head,A.head=L,A.modified=!0,A.length++,M=!0}M&&e.present++}else{e.present--,z.remove_arb(e);let C=y.manager,w=null,O=(y.cbpairs.length<f.cbpairs.length?y.cbpairs:f.cbpairs).head;for(;O!=null;){let M=O.elt;if(M.a==y&&M.b==f||M.a==f&&M.b==y){w=M;break}O=O.next}if(w==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,_t.setlt(y,f)?(M.a=y,M.b=f):(M.a=f,M.b=y),w=M,y.cbpairs.add(w),f!=y&&f.cbpairs.add(w)}w.zip_listeners&&(w.zip_listeners=!1,w.__validate());let E=w.listeners.head;for(;E!=null;){let M=E.elt;if(M.event==1&&(M.itype&e.type)!=0&&z.empty_arb(M.itype)){let N=this.push_callback(M);N.event=1;let Z=z.int1,A=z.int2,S,L=M.options1,T=Z.cbTypes;if(L.nonemptyintersection(T,L.includes)&&!L.nonemptyintersection(T,L.excludes)){let G=M.options2,q=A.cbTypes;S=G.nonemptyintersection(q,G.includes)&&!G.nonemptyintersection(q,G.excludes)}else S=!1;S?(N.int1=Z,N.int2=A):(N.int1=A,N.int2=Z),N.set=z}E=E.next}z.arbiters.head==null&&this.remove_callbackset(z)}m=m.next}u=u.next}}e.fresh=!1,e.intchange=!1}if(e.cleared||e.up_stamp+(e.type==Ie.COL?B._nape.Config.arbiterExpirationDelay:0)<this.stamp){if(e.type==Ie.SENSOR){let i=e.sensorarb;if(!i.cleared){let o=i.b1.arbiters,r=null,a=o.head,p=!1;for(;a!=null;){if(a.elt==i){let m,d;r==null?(m=o.head,d=m.next,o.head=d,o.head==null&&(o.pushmod=!0)):(m=r.next,d=m.next,r.next=d,d==null&&(o.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}r=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let m,d;h==null?(m=c.head,d=m.next,c.head=d,c.head==null&&(c.pushmod=!0)):(m=h.next,d=m.next,h.next=d,d==null&&(c.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,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=Ot.zpp_pool,Ot.zpp_pool=l}else if(e.type==Ie.FLUID){let i=e.fluidarb;if(!i.cleared){let o=i.b1.arbiters,r=null,a=o.head,p=!1;for(;a!=null;){if(a.elt==i){let m,d;r==null?(m=o.head,d=m.next,o.head=d,o.head==null&&(o.pushmod=!0)):(m=r.next,d=m.next,r.next=d,d==null&&(o.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}r=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let m,d;h==null?(m=c.head,d=m.next,c.head=d,c.head==null&&(c.pushmod=!0)):(m=h.next,d=m.next,h.next=d,d==null&&(c.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,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=Pt.zpp_pool,Pt.zpp_pool=l,i.pre_dt=-1}else{let i=e.colarb;if(!i.cleared){let o=i.b1.arbiters,r=null,a=o.head,p=!1;for(;a!=null;){if(a.elt==i){let m,d;r==null?(m=o.head,d=m.next,o.head=d,o.head==null&&(o.pushmod=!0)):(m=r.next,d=m.next,r.next=d,d==null&&(o.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}r=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let m,d;h==null?(m=c.head,d=m.next,c.head=d,c.head==null&&(c.pushmod=!0)):(m=h.next,d=m.next,h.next=d,d==null&&(c.pushmod=!0));let y=m;y.elt=null,y.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,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 o=i.contacts,r=o.next;o.pop();let a=r;a.arbiter=null,a.next=Pe.zpp_pool,Pe.zpp_pool=a;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=ut.zpp_pool,ut.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!=Ie.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 o=i.b1.smass+i.b2.smass;i.hc2=!1;let r=!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 b=i.contacts,P,k;c==null?(P=b.next,k=P.next,b.next=k,b.next==null&&(b.pushmod=!0)):(P=c.next,k=P.next,c.next=k,k==null&&(b.pushmod=!0)),P._inuse=!1,b.modified=!0,b.length--,b.pushmod=!0,x=k;let _=i.innards,z,C;h==null?(z=_.next,C=z.next,_.next=C,_.next==null&&(_.pushmod=!0)):(z=h.next,C=z.next,h.next=C,C==null&&(_.pushmod=!0)),z._inuse=!1,_.modified=!0,_.length--,_.pushmod=!0,u=C;let w=d;w.arbiter=null,w.next=Pe.zpp_pool,Pe.zpp_pool=w;continue}let y=d.inner,f=d.active;if(d.active=d.stamp==i.stamp,d.active){r?(r=!1,i.c1=y,i.oc1=d):(i.hc2=!0,i.c2=y,i.oc2=d),y.r2x=d.px-i.b2.posx,y.r2y=d.py-i.b2.posy,y.r1x=d.px-i.b1.posx,y.r1y=d.py-i.b1.posy;let b=y.r2x*i.nx+y.r2y*i.ny,P=o+i.b2.sinertia*(b*b),k=y.r1x*i.nx+y.r1y*i.ny;P+=i.b1.sinertia*(k*k),y.tMass=P<B._nape.Config.epsilon*B._nape.Config.epsilon?0:1/P;let _=i.ny*y.r2x-i.nx*y.r2y,z=o+i.b2.sinertia*(_*_),C=i.ny*y.r1x-i.nx*y.r1y;z+=i.b1.sinertia*(C*C),y.nMass=z<B._nape.Config.epsilon*B._nape.Config.epsilon?0:1/z;let w=0,g=0,O=i.b2.angvel+i.b2.kinangvel;w=i.b2.velx+i.b2.kinvelx-y.r2y*O,g=i.b2.vely+i.b2.kinvely+y.r2x*O,O=i.b1.angvel+i.b1.kinangvel,w-=i.b1.velx+i.b1.kinvelx-y.r1y*O,g-=i.b1.vely+i.b1.kinvely+y.r1x*O;let E=i.nx*w+i.ny*g;d.elasticity=i.restitution,y.bounce=E*d.elasticity,y.bounce>-B._nape.Config.elasticThreshold&&(y.bounce=0),E=g*i.nx-w*i.ny;let M=B._nape.Config.staticFrictionThreshold;E*E>M*M?y.friction=i.dyn_fric:y.friction=i.stat_fric,y.jnAcc*=l,y.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 y=i.oc1;i.oc1=i.oc2,i.oc2=y,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(r=!0)}else i.hpc2=!1;if(i.jrAcc*=l,r||(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=o+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=o+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=o+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 y=i.kMassa*i.kMassc-i.kMassb*i.kMassb;if(y!=y)i.kMassa=i.kMassb=i.kMassc=0;else if(y==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{y=1/y;let f=i.kMassc*y;i.kMassc=i.kMassa*y,i.kMassa=f,i.kMassb*=-y}}else{if(i.hc2=!1,i.oc2.dist<i.oc1.dist){let y=i.c1;i.c1=i.c2,i.c2=y}i.oc2.active=!1,i.contacts.modified=!0}i.surfacex=i.b2.svelx,i.surfacey=i.b2.svely;let m=1;i.surfacex+=i.b1.svelx*m,i.surfacey+=i.b1.svely*m,i.surfacex=-i.surfacex,i.surfacey=-i.surfacey,i.rMass=i.b1.sinertia+i.b2.sinertia,i.rMass!=0&&(i.rMass=1/i.rMass),r&&(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 o=0,r=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(o=i.ws1.fluidProperties.gravityx,r=i.ws1.fluidProperties.gravityy):(o=this.gravityx,r=this.gravityy);let a=0,p=0;i.ws2.fluidEnabled&&i.ws2.fluidProperties.wrap_gravity!=null?(a=i.ws2.fluidProperties.gravityx,p=i.ws2.fluidProperties.gravityy):(a=this.gravityx,p=this.gravityy);let c=0,h=0;if(i.ws1.fluidEnabled&&i.ws2.fluidEnabled){let m=i.overlap*i.ws1.fluidProperties.density,d=i.overlap*i.ws2.fluidProperties.density;if(m>d){let y=m+d;c-=o*y,h-=r*y}else if(m<d){let y=m+d;c+=a*y,h+=p*y}else{let y=0,f=0;y=o+a,f=r+p;let b=.5;if(y*=b,f*=b,i.ws1.worldCOMx*y+i.ws1.worldCOMy*f>i.ws2.worldCOMx*y+i.ws2.worldCOMy*f){let P=m+d;c-=y*P,h-=f*P}else{let P=m+d;c+=y*P,h+=f*P}}}else if(i.ws1.fluidEnabled){let d=i.overlap*i.ws1.fluidProperties.density;c-=o*d,h-=r*d}else if(i.ws2.fluidEnabled){let d=i.overlap*i.ws2.fluidProperties.density;c+=a*d,h+=p*d}let u=t;if(c*=u,h*=u,i.buoyx=c,i.buoyy=h,i.b1.type==2){let m=i.b1.imass;i.b1.velx-=c*m,i.b1.vely-=h*m,i.b1.angvel-=(h*i.r1x-c*i.r1y)*i.b1.iinertia}if(i.b2.type==2){let m=i.b2.imass;i.b2.velx+=c*m,i.b2.vely+=h*m,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 m=0;if(i.ws1.fluidEnabled&&(i.ws2.validate_angDrag(),m+=i.ws1.fluidProperties.viscosity*i.ws2.angDrag*i.overlap/i.ws2.area),i.ws2.fluidEnabled&&(i.ws1.validate_angDrag(),m+=i.ws2.fluidProperties.viscosity*i.ws1.angDrag*i.overlap/i.ws1.area),m!=0){let b=i.b1.sinertia+i.b2.sinertia;b!=0?i.wMass=1/b:i.wMass=0,m*=4e-4;let P=2*Math.PI*m;i.agamma=1/(t*P*(2+P*t));let k=1/(1+i.agamma),_=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)),y=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+y*y<B._nape.Config.epsilon*B._nape.Config.epsilon)){let b=d*d+y*y,k=1/Math.sqrt(b);d*=k,y*=k,i.nx=d,i.ny=y}let f=0;if(i.ws1.fluidEnabled){let b=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)f-=b*i.ws2.circle.radius*B._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else if(i.ws2.type===2){let P=i.ws2.capsule.radius;f-=b*P*B._nape.Config.fluidLinearDrag/(2*P*Math.PI)}else{let P=i.ws2.polygon,k=0,_=0,z=P.edges.head;for(;z!=null;){let C=z.elt;k+=C.length;let w=b*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);w>0&&(w*=-B._nape.Config.fluidVacuumDrag,w=w),_-=w*.5*B._nape.Config.fluidLinearDrag,z=z.next}f+=_/k}}if(i.ws2.fluidEnabled){let b=-i.ws2.fluidProperties.viscosity*i.overlap/i.ws1.area;if(i.ws1.type==0)f-=b*i.ws1.circle.radius*B._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else if(i.ws1.type===2){let P=i.ws1.capsule.radius;f-=b*P*B._nape.Config.fluidLinearDrag/(2*P*Math.PI)}else{let P=i.ws1.polygon,k=0,_=0,z=P.edges.head;for(;z!=null;){let C=z.elt;k+=C.length;let w=b*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);w>0&&(w*=-B._nape.Config.fluidVacuumDrag,w=w),_-=w*.5*B._nape.Config.fluidLinearDrag,z=z.next}f+=_/k}}if(f!=0){let b=i.b1.smass+i.b2.smass,P=0,k=0,_=0;if(P=b,k=0,_=b,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,_+=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,_+=E*i.r2x}let z=P*_-k*k;if(z!=z)_=0,k=_,P=k;else if(z==0){let E=0;P!=0?P=1/P:(P=0,E|=1),_!=0?_=1/_:(_=0,E|=2),k=0}else{z=1/z;let E=_*z;_=P*z,P=E,k*=-z}i.vMassa=P,i.vMassb=k,i.vMassc=_;let C,w=2*Math.PI*f;i.lgamma=1/(t*w*(2+w*t));let g=1/(1+i.lgamma);C=t*w*w*i.lgamma,i.lgamma*=g;let O=g;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,o=null,r=null,a=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,m,d;o==null?(m=x.next,d=m.next,x.next=d,x.next==null&&(x.pushmod=!0)):(m=o.next,d=m.next,o.next=d,d==null&&(x.pushmod=!0)),m._inuse=!1,x.modified=!0,x.length--,x.pushmod=!0,p=d;let y=i.innards,f,b;r==null?(f=y.next,b=f.next,y.next=b,y.next==null&&(y.pushmod=!0)):(f=r.next,b=f.next,r.next=b,b==null&&(y.pushmod=!0)),f._inuse=!1,y.modified=!0,y.length--,y.pushmod=!0,a=b;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),o=p,r=a,a=a.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}_prestepArbiterList(e,t,n){let s=null,i=e.head;for(;i!=null;){let l=i.elt;if(this.presteparb(l,n)){let o,r;s==null?(o=e.head,r=o.next,e.head=r,e.head==null&&(e.pushmod=!0)):(o=s.next,r=o.next,s.next=r,r==null&&(e.pushmod=!0)),o.elt=null,o.next=t.zpp_pool,t.zpp_pool=o,e.modified=!0,e.length--,e.pushmod=!0,i=r;continue}s=i,i=i.next}}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let r=n.elt;if(r.preStep(e)){n=this.live_constraints.erase(t),r.broken(),this.constraintCbBreak(r),r.removeOnBreak?(r.component.sleeping=!0,this.midstep=!1,r.compound!=null?r.compound.wrap_constraints.remove(r.outer):this.wrap_constraints.remove(r.outer),this.midstep=!0):r.active=!1,r.clearcache();continue}t=n,n=n.next}let s=null,i=this.c_arbiters_true,l=i.head,o=this.c_arbiters_false!=null;for(o&&l==null&&(o=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);l!=null;){let r=l.elt;if(this.presteparb(r,e)){let a,p;s==null?(a=i.head,p=a.next,i.head=p,i.head==null&&(i.pushmod=!0)):(a=s.next,p=a.next,s.next=p,p==null&&(i.pushmod=!0));let c=a;c.elt=null,c.next=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=c,i.modified=!0,i.length--,i.pushmod=!0,l=p,o&&l==null&&(o=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);continue}s=l,l=l.next,o&&l==null&&(o=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null)}this._prestepArbiterList(this.f_arbiters,B._zpp.util.ZNPNode_ZPP_FluidArbiter,e),this._prestepArbiterList(this.s_arbiters,B._zpp.util.ZNPNode_ZPP_SensorArbiter,e)}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 o=i.b2.imass;i.b2.velx+=i.dampx*o,i.b2.vely+=i.dampy*o,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,o=i.ny*i.c1.jnAcc+i.nx*i.c1.jtAcc,r=i.b1.imass;i.b1.velx-=l*r,i.b1.vely-=o*r,i.b1.angvel-=i.b1.iinertia*(o*i.c1.r1x-l*i.c1.r1y);let a=i.b2.imass;if(i.b2.velx+=l*a,i.b2.vely+=o*a,i.b2.angvel+=i.b2.iinertia*(o*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),m=p.vMassa*u+p.vMassb*x;x=p.vMassb*u+p.vMassc*x,u=m;let d=p.lgamma;u-=p.dampx*d,x-=p.dampy*d;let y=1;p.dampx+=u*y,p.dampy+=x*y;let f=p.b1.imass;p.b1.velx-=u*f,p.b1.vely-=x*f;let b=p.b2.imass;p.b2.velx+=u*b,p.b2.vely+=x*b,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,o=this.live_constraints.head;for(;o!=null;){let p=o.elt;if(p.applyImpulseVel()){o=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=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),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,m=p.c1.jtAcc,d=m-u;d>x?d=x:d<-x&&(d=-x),u=d-m,p.c1.jtAcc=d;let y=-p.ny*u,f=p.nx*u;if(p.b2.velx+=y*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=y*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 b=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-b*p.ny+p.surfacex)*p.c2.tMass,x=p.c2.friction*p.c2.jnAcc,m=p.c2.jtAcc,d=m-u,d>x?d=x:d<-x&&(d=-x),u=d-m,p.c2.jtAcc=d,y=-p.ny*u,f=p.nx*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=y*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),b=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,_=p.c2.jnAcc,z=c*p.nx+h*p.ny+p.surfacey+p.c1.bounce-(p.Ka*k+p.Kb*_),C=b*p.nx+P*p.ny+p.surfacey+p.c2.bounce-(p.Kb*k+p.Kc*_),w=-(p.kMassa*z+p.kMassb*C),g=-(p.kMassb*z+p.kMassc*C);w>=0&&g>=0?(z=w-k,C=g-_,p.c1.jnAcc=w,p.c2.jnAcc=g):(w=-p.c1.nMass*z,w>=0&&p.Kb*w+C>=0?(z=w-k,C=-_,p.c1.jnAcc=w,p.c2.jnAcc=0):(g=-p.c2.nMass*C,g>=0&&p.Kb*g+z>=0?(z=-k,C=g-_,p.c1.jnAcc=0,p.c2.jnAcc=g):z>=0&&C>=0?(z=-k,C=-_,p.c1.jnAcc=p.c2.jnAcc=0):(z=0,C=0))),u=z+C,y=p.nx*u,f=p.ny*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=(p.rn1b*z+p.rn2b*C)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*z+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,m=p.jrAcc,p.jrAcc-=u,p.jrAcc>x?p.jrAcc=x:p.jrAcc<-x&&(p.jrAcc=-x),u=p.jrAcc-m,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,m=p.c1.jnAcc,d=m-u,d<0&&(d=0),u=d-m,p.c1.jnAcc=d,y=p.nx*u,f=p.ny*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=y*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}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 s=t++,i=null,l=this.live_constraints.head;for(;l!=null;){let a=l.elt;if(!a.__velocity&&a.stiff&&a.applyImpulsePos()){l=this.live_constraints.erase(i),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}i=l,l=l.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,h=0;c=a.b2.axisy*p.lr2x-a.b2.axisx*p.lr2y,h=p.lr2x*a.b2.axisx+p.lr2y*a.b2.axisy;let u=1;c+=a.b2.posx*u,h+=a.b2.posy*u;let x=0,m=0;x=a.b1.axisy*p.lr1x-a.b1.axisx*p.lr1y,m=p.lr1x*a.b1.axisx+p.lr1y*a.b1.axisy;let d=1;x+=a.b1.posx*d,m+=a.b1.posy*d;let y=0,f=0;y=c-x,f=h-m;let b=Math.sqrt(y*y+f*f),P=a.radius-B._nape.Config.collisionSlop,k=b-P;if(y*a.nx+f*a.ny<0&&(y=-y,f=-f,k-=a.radius),k<0)if(b<B._nape.Config.epsilon)a.b1.smass!=0?a.b1.posx+=B._nape.Config.epsilon*10:a.b2.posx+=B._nape.Config.epsilon*10;else{let _=1/b;y*=_,f*=_;let z=.5*(x+c),C=.5*(m+h),w=b-P;x=z-a.b1.posx,m=C-a.b1.posy,c=z-a.b2.posx,h=C-a.b2.posy;let g=f*x-y*m,O=f*c-y*h,E=a.b2.smass+O*O*a.b2.sinertia+a.b1.smass+g*g*a.b1.sinertia;if(E!=0){let M=-a.biasCoef*w/E,N=0,Z=0,A=M;N=y*A,Z=f*A;let S=a.b1.imass;a.b1.posx-=N*S,a.b1.posy-=Z*S;let L=a.b1,T=-g*a.b1.iinertia*M;if(L.rot+=T,T*T>1e-4)L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.rot);else{let j=T*T,V=1-.5*j,K=1-j*j/8,$=(V*L.axisx+T*L.axisy)*K;L.axisy=(V*L.axisy-T*L.axisx)*K,L.axisx=$}let G=a.b2.imass;a.b2.posx+=N*G,a.b2.posy+=Z*G;let q=a.b2,R=O*a.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,V=1-.5*j,K=1-j*j/8,$=(V*q.axisx+R*q.axisy)*K;q.axisy=(V*q.axisy-R*q.axisx)*K,q.axisx=$}}}}else{let p=0,c=0,h,u=0,x=0,m=0,d=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,h=a.lproj+(p*a.b1.posx+c*a.b1.posy),u=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 b=1;if(u+=a.b2.posx*b,x+=a.b2.posy*b,a.hpc2){m=a.b2.axisy*a.c2.lr1x-a.b2.axisx*a.c2.lr1y,d=a.c2.lr1x*a.b2.axisx+a.c2.lr1y*a.b2.axisy;let P=1;m+=a.b2.posx*P,d+=a.b2.posy*P}}else{p=a.b2.axisy*a.lnormx-a.b2.axisx*a.lnormy,c=a.lnormx*a.b2.axisx+a.lnormy*a.b2.axisy,h=a.lproj+(p*a.b2.posx+c*a.b2.posy),u=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 b=1;if(u+=a.b1.posx*b,x+=a.b1.posy*b,a.hpc2){m=a.b1.axisy*a.c2.lr1x-a.b1.axisx*a.c2.lr1y,d=a.c2.lr1x*a.b1.axisx+a.c2.lr1y*a.b1.axisy;let P=1;m+=a.b1.posx*P,d+=a.b1.posy*P}}let y=u*p+x*c-h-a.radius;y+=B._nape.Config.collisionSlop;let f=0;if(a.hpc2&&(f=m*p+d*c-h-a.radius,f+=B._nape.Config.collisionSlop),y<0||f<0){a.rev&&(p=-p,c=-c);let b=0,P=0;b=u-a.b1.posx,P=x-a.b1.posy;let k=0,_=0;k=u-a.b2.posx,_=x-a.b2.posy;let z=0,C=0,w=0,g=0;if(a.hpc2){z=m-a.b1.posx,C=d-a.b1.posy,w=m-a.b2.posx,g=d-a.b2.posy;let O=c*b-p*P,E=c*k-p*_,M=c*z-p*C,N=c*w-p*g,Z=a.b1.smass+a.b2.smass;a.kMassa=Z+a.b1.sinertia*O*O+a.b2.sinertia*E*E,a.kMassb=Z+a.b1.sinertia*O*M+a.b2.sinertia*E*N,a.kMassc=Z+a.b1.sinertia*M*M+a.b2.sinertia*N*N;let A=0,S=0,L=0;A=a.kMassa,S=a.kMassb,L=a.kMassc;let T=y*a.biasCoef,G=f*a.biasCoef;for(;;){let q=0,R=0;q=T,R=G,q=-q,R=-R;let j=a.kMassa*a.kMassc-a.kMassb*a.kMassb;if(j!=j)R=0,q=R;else if(j==0)a.kMassa!=0?q/=a.kMassa:q=0,a.kMassc!=0?R/=a.kMassc:R=0;else{j=1/j;let $=j*(a.kMassc*q-a.kMassb*R);R=j*(a.kMassa*R-a.kMassb*q),q=$}if(q>=0&&R>=0){let $=(q+R)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let Y=a.b1,X=-a.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 D=X*X,I=1-.5*D,U=1-D*D/8,Q=(I*Y.axisx+X*Y.axisy)*U;Y.axisy=(I*Y.axisy-X*Y.axisx)*U,Y.axisx=Q}let ee=(q+R)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let J=a.b2,F=a.b2.iinertia*(E*q+N*R);if(J.rot+=F,F*F>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let D=F*F,I=1-.5*D,U=1-D*D/8,Q=(I*J.axisx+F*J.axisy)*U;J.axisy=(I*J.axisy-F*J.axisx)*U,J.axisx=Q}break}q=-T/A,R=0;let V=S*q+G;if(q>=0&&V>=0){let $=(q+R)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let Y=a.b1,X=-a.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 D=X*X,I=1-.5*D,U=1-D*D/8,Q=(I*Y.axisx+X*Y.axisy)*U;Y.axisy=(I*Y.axisy-X*Y.axisx)*U,Y.axisx=Q}let ee=(q+R)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let J=a.b2,F=a.b2.iinertia*(E*q+N*R);if(J.rot+=F,F*F>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let D=F*F,I=1-.5*D,U=1-D*D/8,Q=(I*J.axisx+F*J.axisy)*U;J.axisy=(I*J.axisy-F*J.axisx)*U,J.axisx=Q}break}q=0,R=-G/L;let K=S*R+T;if(R>=0&&K>=0){let $=(q+R)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let Y=a.b1,X=-a.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 D=X*X,I=1-.5*D,U=1-D*D/8,Q=(I*Y.axisx+X*Y.axisy)*U;Y.axisy=(I*Y.axisy-X*Y.axisx)*U,Y.axisx=Q}let ee=(q+R)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let J=a.b2,F=a.b2.iinertia*(E*q+N*R);if(J.rot+=F,F*F>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let D=F*F,I=1-.5*D,U=1-D*D/8,Q=(I*J.axisx+F*J.axisy)*U;J.axisy=(I*J.axisy-F*J.axisx)*U,J.axisx=Q}break}break}}else{let O=c*b-p*P,E=c*k-p*_,M=a.b2.smass+E*E*a.b2.sinertia+a.b1.smass+O*O*a.b1.sinertia;if(M!=0){let N=-a.biasCoef*y/M,Z=0,A=0,S=N;Z=p*S,A=c*S;let L=a.b1.imass;a.b1.posx-=Z*L,a.b1.posy-=A*L;let T=a.b1,G=-O*a.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 V=G*G,K=1-.5*V,$=1-V*V/8,Y=(K*T.axisx+G*T.axisy)*$;T.axisy=(K*T.axisy-G*T.axisx)*$,T.axisx=Y}let q=a.b2.imass;a.b2.posx+=Z*q,a.b2.posy+=A*q;let R=a.b2,j=E*a.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 V=j*j,K=1-.5*V,$=1-V*V/8,Y=(K*R.axisx+j*R.axisy)*$;R.axisy=(K*R.axisy-j*R.axisx)*$,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 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 o=!1;for(;s!=null&&l!=null;){if(s==l){o=s.ignore;break}s.depth<l.depth?l=l.group:s=s.group}return o}}}interactionType(e,t,n,s){let i;i=!1;let l=n.constraints.head;for(;l!=null;){let r=l.elt;if(r.ignore&&r.pair_exists(n.id,s.id)){i=!0;break}l=l.next}let o;if(i)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 h=c==null?null:c.group;if(h==null)p=!1;else{let u=!1;for(;a!=null&&h!=null;){if(a==h){u=a.ignore;break}a.depth<h.depth?h=h.group:a=a.group}p=u}}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&&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,o=e.body,r=t.body,a;a=!1;let p=o.constraints.head;for(;p!=null;){let u=p.elt;if(u.ignore&&u.pair_exists(o.id,r.id)){a=!0;break}p=p.next}let c,h;if(a)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,m;if(x==null)m=!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 y=d==null?null:d.group;if(y==null)m=!1;else{let f=!1;for(;x!=null&&y!=null;){if(x==y){f=x.ignore;break}x.depth<y.depth?y=y.group:x=x.group}m=f}}h=!m}if(h){let u;if(e.sensorEnabled||t.sensorEnabled){let x=e.filter,m=t.filter;u=(x.sensorMask&m.sensorGroup)!=0&&(m.sensorMask&x.sensorGroup)!=0}else u=!1;if(u)c=2;else{let x;if(e.fluidEnabled||t.fluidEnabled){let m=e.filter,d=t.filter;x=(m.fluidMask&d.fluidGroup)!=0&&(d.fluidMask&m.fluidGroup)!=0}else x=!1;if(x&&!(o.imass==0&&r.imass==0&&o.iinertia==0&&r.iinertia==0))c=0;else{let m=e.filter,d=t.filter;c=(m.collisionMask&d.collisionGroup)!=0&&(d.collisionMask&m.collisionGroup)!=0&&!(o.imass==0&&r.imass==0&&o.iinertia==0&&r.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 m=u==t;if(c==0){let d;if(s==null){let k=null,z=(o.arbiters.length<r.arbiters.length?o:r).arbiters.head;for(;z!=null;){let C=z.elt;if(C.id==u.id&&C.di==x.id){k=C;break}z=z.next}d=k}else d=s;let y=d==null,f,b=!1;if(y)Pt.zpp_pool==null?f=new Pt:(f=Pt.zpp_pool,Pt.zpp_pool=f.next,f.next=null);else if(d.fluidarb==null){d.cleared=!0;{let _=d.b1.arbiters,z=null,C=_.head,w=!1;for(;C!=null;){if(C.elt==d){let g,O;z==null?(g=_.head,O=g.next,_.head=O,_.head==null&&(_.pushmod=!0)):(g=z.next,O=g.next,z.next=O,O==null&&(_.pushmod=!0));let E=g;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,_.modified=!0,_.length--,_.pushmod=!0,w=!0;break}z=C,C=C.next}}{let _=d.b2.arbiters,z=null,C=_.head,w=!1;for(;C!=null;){if(C.elt==d){let g,O;z==null?(g=_.head,O=g.next,_.head=O,_.head==null&&(_.pushmod=!0)):(g=z.next,O=g.next,z.next=O,O==null&&(_.pushmod=!0));let E=g;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,_.modified=!0,_.length--,_.pushmod=!0,w=!0;break}z=C,C=C.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Pt.zpp_pool==null?f=new Pt:(f=Pt.zpp_pool,Pt.zpp_pool=f.next,f.next=null),f.intchange=!0,y=!0,b=!0}else f=d.fluidarb;let P=4;if(y||f.stamp!=this.stamp||i)if(f.stamp=this.stamp,Ce.flowCollide(u,x,f)){if(y){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 _=f.b1.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=f;let C=z;C.next=_.head,_.head=C,_.modified=!0,_.length++;let w=f.b2.arbiters,g;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?g=new B._zpp.util.ZNPNode_ZPP_Arbiter:(g=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=g.next,g.next=null),g.elt=f;let O=g;O.next=w.head,w.head=O,w.modified=!0,w.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=!b}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,_=f.ws1.id>f.ws2.id?f.ws2:f.ws1,z=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 w=this.mrca2;for(;w.head!=null;){let M=w.head;w.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,w.head==null&&(w.pushmod=!0),w.modified=!0,w.length--}if(w.pushmod=!0,_.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=_;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(_.body.cbSet!=null){let M=this.mrca1,N=_.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 A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}if(z.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=z;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(z.body.cbSet!=null){let M=this.mrca2,N=z.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 A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}let g=_.body.compound,O=z.body.compound;for(;g!=O;){let M=g==null?0:g.depth,N=O==null?0:O.depth;if(M<N){if(O.cbSet!=null){let Z=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=O;let S=A;S.next=Z.head,Z.head=S,Z.modified=!0,Z.length++}O=O.compound}else{if(g.cbSet!=null){let Z=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=g;let S=A;S.next=Z.head,Z.head=S,Z.modified=!0,Z.length++}g=g.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,N=this.mrca2.head;for(;N!=null;){let Z=N.elt,A=M.cbSet,S=Z.cbSet,L=A.manager,T=null,q=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;q!=null;){let F=q.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){T=F;break}q=q.next}if(T==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,_t.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),T=F,A.cbpairs.add(T),S!=A&&S.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,V=this.prelisteners;for(;V.head!=null;){let F=V.head;V.head=F.next;let D=F;D.elt=null,D.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=D,V.head==null&&(V.pushmod=!0),V.modified=!0,V.length--}V.pushmod=!0;let K=null,$=A.manager,Y=null,ee=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;ee!=null;){let F=ee.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){Y=F;break}ee=ee.next}if(Y==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,_t.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),Y=F,A.cbpairs.add(Y),S!=A&&S.cbpairs.add(Y)}Y.zip_listeners&&(Y.zip_listeners=!1,Y.__validate());let J=Y.listeners.head;for(;J!=null;){let F=J.elt;if(F.event==5&&(F.itype&P)!=0){let D=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=F;let U=I;K==null?(U.next=D.head,D.head=U):(U.next=K.next,K.next=U),D.pushmod=D.modified=!0,D.length++,K=U,k=k||!F.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=Kt.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 F=f.active;f.active=!0;let D=!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 Q=this.precb.zpp_inner,W=R.int1,ie=R.int2,oe,se=U.options1,ne=W.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=U.options2,he=ie.cbTypes;oe=le.nonemptyintersection(he,le.includes)&&!le.nonemptyintersection(he,le.excludes)}else oe=!1;oe?(Q.int1=W,Q.int2=ie):(Q.int1=ie,Q.int2=W),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let re=U.handlerp(this.precb);if(re!=null){let le;H.PreFlag_ACCEPT==null&&(H.internal=!0,H.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,H.internal=!1),re==H.PreFlag_ACCEPT?le=5:(H.PreFlag_ACCEPT_ONCE==null&&(H.internal=!0,H.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,H.internal=!1),re==H.PreFlag_ACCEPT_ONCE?le=1:(H.PreFlag_IGNORE==null&&(H.internal=!0,H.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,H.internal=!1),le=re==H.PreFlag_IGNORE?6:2)),f.immState=le}I=I.next}if(f.mutable=!1,f.wrap_position!=null&&(f.wrap_position.zpp_inner._immutable=!0),f.active=F,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,_;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(_=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=_.next,_.next=null),_.elt=f;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++}l=f}else if(y){let k=f;k.next=Pt.zpp_pool,Pt.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,y;if(s==null){let _=null,C=(o.arbiters.length<r.arbiters.length?o:r).arbiters.head;for(;C!=null;){let w=C.elt;if(w.id==u.id&&w.di==x.id){_=w;break}C=C.next}y=_}else y=s;let f=y==null,b,P=!1;if(f)ut.zpp_pool==null?b=new ut:(b=ut.zpp_pool,ut.zpp_pool=b.next,b.next=null),b.stat=n;else if(y.colarb==null){y.cleared=!0;{let z=y.b1.arbiters,C=null,w=z.head,g=!1;for(;w!=null;){if(w.elt==y){let O,E;C==null?(O=z.head,E=O.next,z.head=E,z.head==null&&(z.pushmod=!0)):(O=C.next,E=O.next,C.next=E,E==null&&(z.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,z.modified=!0,z.length--,z.pushmod=!0,g=!0;break}C=w,w=w.next}}{let z=y.b2.arbiters,C=null,w=z.head,g=!1;for(;w!=null;){if(w.elt==y){let O,E;C==null?(O=z.head,E=O.next,z.head=E,z.head==null&&(z.pushmod=!0)):(O=C.next,E=O.next,C.next=E,E==null&&(z.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,z.modified=!0,z.length--,z.pushmod=!0,g=!0;break}C=w,w=w.next}}y.pair!=null&&(y.pair.arb=null,y.pair=null),y.active=!1,this.f_arbiters.modified=!0,ut.zpp_pool==null?b=new ut:(b=ut.zpp_pool,ut.zpp_pool=b.next,b.next=null),b.intchange=!0,b.stat=n,f=!0,P=!0}else b=y.colarb,m=u!=b.s1,b.stat!=n&&(b.stat=n,b.sleeping||((n?this.c_arbiters_false:this.c_arbiters_true).remove(b),d.add(b)));let k=1;if(f||b.stamp!=this.stamp||i)if(b.stamp=this.stamp,Ce.contactCollide(u,x,b,m)){if(f){let _=x.id;b.b1=e.body,b.ws1=e,b.b2=t.body,b.ws2=t,b.id=u.id,b.di=_;let z=b.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=b;let w=C;w.next=z.head,z.head=w,z.modified=!0,z.length++;let g=b.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=b;let E=O;E.next=g.head,g.head=E,g.modified=!0,g.length++,b.active=!0,b.present=0,b.cleared=!1,b.sleeping=!1,b.fresh=!1,b.presentable=!1,b.s1=e,b.s2=t,b.userdef_restitution||(b.s1.material.elasticity<=-1/0||b.s2.material.elasticity<=-1/0?b.restitution=0:b.s1.material.elasticity>=1/0||b.s2.material.elasticity>=1/0?b.restitution=1:b.restitution=(b.s1.material.elasticity+b.s2.material.elasticity)/2,b.restitution<0&&(b.restitution=0),b.restitution>1&&(b.restitution=1)),b.userdef_dyn_fric||(b.dyn_fric=Math.sqrt(b.s1.material.dynamicFriction*b.s2.material.dynamicFriction)),b.userdef_stat_fric||(b.stat_fric=Math.sqrt(b.s1.material.staticFriction*b.s2.material.staticFriction)),b.userdef_rfric||(b.rfric=Math.sqrt(b.s1.material.rollingFriction*b.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=b;let N=M;N.next=d.head,d.head=N,d.modified=!0,d.length++,b.fresh=!P}else b.fresh=b.up_stamp<this.stamp-1||b.endGenerated==this.stamp&&i;if(b.up_stamp=b.stamp,b.fresh||(b.immState&4)==0){b.immState=1;let _=!1,z=b.ws1.id>b.ws2.id?b.ws2:b.ws1,C=b.ws1.id>b.ws2.id?b.ws1:b.ws2,w=this.mrca1;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--}w.pushmod=!0;let g=this.mrca2;for(;g.head!=null;){let N=g.head;g.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,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}if(g.pushmod=!0,z.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=z;let A=Z;A.next=N.head,N.head=A,N.modified=!0,N.length++}if(z.body.cbSet!=null){let N=this.mrca1,Z=z.body,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=Z;let S=A;S.next=N.head,N.head=S,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 A=Z;A.next=N.head,N.head=A,N.modified=!0,N.length++}if(C.body.cbSet!=null){let N=this.mrca2,Z=C.body,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=Z;let S=A;S.next=N.head,N.head=S,N.modified=!0,N.length++}let O=z.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 A=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=E;let L=S;L.next=A.head,A.head=L,A.modified=!0,A.length++}E=E.compound}else{if(O.cbSet!=null){let A=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=O;let L=S;L.next=A.head,A.head=L,A.modified=!0,A.length++}O=O.compound}}let M=this.mrca1.head;for(;M!=null;){let N=M.elt,Z=this.mrca2.head;for(;Z!=null;){let A=Z.elt,S=N.cbSet,L=A.cbSet,T=S.manager,G=null,R=(S.cbpairs.length<L.cbpairs.length?S.cbpairs:L.cbpairs).head;for(;R!=null;){let D=R.elt;if(D.a==S&&D.b==L||D.a==L&&D.b==S){G=D;break}R=R.next}if(G==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,_t.setlt(S,L)?(D.a=S,D.b=L):(D.a=L,D.b=S),G=D,S.cbpairs.add(G),L!=S&&L.cbpairs.add(G)}if(G.zip_listeners&&(G.zip_listeners=!1,G.__validate()),G.listeners.head==null){Z=Z.next;continue}let j=null,V=null,K=this.prelisteners;for(;K.head!=null;){let D=K.head;K.head=D.next;let I=D;I.elt=null,I.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=I,K.head==null&&(K.pushmod=!0),K.modified=!0,K.length--}K.pushmod=!0;let $=null,Y=S.manager,X=null,J=(S.cbpairs.length<L.cbpairs.length?S.cbpairs:L.cbpairs).head;for(;J!=null;){let D=J.elt;if(D.a==S&&D.b==L||D.a==L&&D.b==S){X=D;break}J=J.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,_t.setlt(S,L)?(D.a=S,D.b=L):(D.a=L,D.b=S),X=D,S.cbpairs.add(X),L!=S&&L.cbpairs.add(X)}X.zip_listeners&&(X.zip_listeners=!1,X.__validate());let F=X.listeners.head;for(;F!=null;){let D=F.elt;if(D.event==5&&(D.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=D;let Q=U;$==null?(Q.next=I.head,I.head=Q):(Q.next=$.next,$.next=Q),I.pushmod=I.modified=!0,I.length++,$=Q,_=_||!D.pure}F=F.next}if(this.prelisteners.head==null){Z=Z.next;continue}if(j=B._zpp.phys.ZPP_Interactor.get(N,A),j==null&&(V=Kt.get(N,A),this.add_callbackset(V)),j==null||(j.COLLISIONstamp!=this.stamp||i)&&(j.COLLISIONstate&4)==0){if(V!=null&&(j=V),j!=null){let ne=this.prelisteners.head;for(;ne!=null;)ne.elt.itype==7?(j.COLLISIONstamp=this.stamp,j.SENSORstamp=this.stamp,j.FLUIDstamp=this.stamp):j.COLLISIONstamp=this.stamp,ne=ne.next}b.mutable=!0,b.wrap_normal!=null&&(b.wrap_normal.zpp_inner._immutable=!1),b.wrap_contacts!=null&&(b.wrap_contacts.zpp_inner.immutable=!1);let D=b.active;b.active=!0;let I=!1,U=!0,Q=null,W=null,ie=b.innards.next;b.hc2=!1;let oe=b.contacts.next;for(;oe!=null;){let ne=oe;if(ne.stamp+B._nape.Config.arbiterExpirationDelay<b.stamp){let he=b.contacts,pe,ce;Q==null?(pe=he.next,ce=pe.next,he.next=ce,he.next==null&&(he.pushmod=!0)):(pe=Q.next,ce=pe.next,Q.next=ce,ce==null&&(he.pushmod=!0)),pe._inuse=!1,he.modified=!0,he.length--,he.pushmod=!0,oe=ce;let te=b.innards,ue,xe;W==null?(ue=te.next,xe=ue.next,te.next=xe,te.next==null&&(te.pushmod=!0)):(ue=W.next,xe=ue.next,W.next=xe,xe==null&&(te.pushmod=!0)),ue._inuse=!1,te.modified=!0,te.length--,te.pushmod=!0,ie=xe;let _e=ne;_e.arbiter=null,_e.next=Pe.zpp_pool,Pe.zpp_pool=_e;continue}let re=ne.inner,le=ne.active;ne.active=ne.stamp==b.stamp,ne.active&&(U?(U=!1,b.c1=re,b.oc1=ne):(b.hc2=!0,b.c2=re,b.oc2=ne)),le!=ne.active&&(b.contacts.modified=!0),Q=oe,W=ie,ie=ie.next,oe=oe.next}if(b.hc2){if(b.hpc2=!0,b.oc1.posOnly){let ne=b.c1;b.c1=b.c2,b.c2=ne;let re=b.oc1;b.oc1=b.oc2,b.oc2=re,b.hc2=!1}else b.oc2.posOnly&&(b.hc2=!1);b.oc1.posOnly&&(U=!0)}else b.hpc2=!1;this.precb.zpp_inner.pre_arbiter=b,this.precb.zpp_inner.set=j;let se=this.prelisteners.head;for(;se!=null;){let ne=se.elt;this.precb.zpp_inner.listener=ne;let re=this.precb.zpp_inner,le=j.int1,he=j.int2,pe,ce=ne.options1,te=le.cbTypes;if(ce.nonemptyintersection(te,ce.includes)&&!ce.nonemptyintersection(te,ce.excludes)){let xe=ne.options2,_e=he.cbTypes;pe=xe.nonemptyintersection(_e,xe.includes)&&!xe.nonemptyintersection(_e,xe.excludes)}else pe=!1;pe?(re.int1=le,re.int2=he):(re.int1=he,re.int2=le),this.precb.zpp_inner.pre_swapped=N!=this.precb.zpp_inner.int1;let ue=ne.handlerp(this.precb);if(ue!=null){let xe;H.PreFlag_ACCEPT==null&&(H.internal=!0,H.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,H.internal=!1),ue==H.PreFlag_ACCEPT?xe=5:(H.PreFlag_ACCEPT_ONCE==null&&(H.internal=!0,H.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,H.internal=!1),ue==H.PreFlag_ACCEPT_ONCE?xe=1:(H.PreFlag_IGNORE==null&&(H.internal=!0,H.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,H.internal=!1),xe=ue==H.PreFlag_IGNORE?6:2)),b.immState=xe}se=se.next}if(b.mutable=!1,b.wrap_normal!=null&&(b.wrap_normal.zpp_inner._immutable=!0),b.wrap_contacts!=null&&(b.wrap_contacts.zpp_inner.immutable=!0),b.active=D,j!=null){let ne=this.prelisteners.head;for(;ne!=null;)ne.elt.itype==7?(j.COLLISIONstate=b.immState,j.SENSORstate=b.immState,j.FLUIDstate=b.immState):j.COLLISIONstate=b.immState,ne=ne.next}}else j==null?(b.immState&4)==0&&(b.immState=1):b.immState=j.COLLISIONstate;Z=Z.next}M=M.next}if(_&&(b.immState&4)==0){if(b.b1.type==2){let N=b.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(b.b1.type==2){let N=b.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((b.immState&1)!=0){if(b.b1.type==2&&b.b1.component.sleeping){let _=b.b1;_.world||(_.component.waket=this.stamp+(this.midstep?0:1),_.type==3&&(_.kinematicDelaySleep=!0),_.component.sleeping&&this.really_wake(_,!1))}if(b.b2.type==2&&b.b2.component.sleeping){let _=b.b2;_.world||(_.component.waket=this.stamp+(this.midstep?0:1),_.type==3&&(_.kinematicDelaySleep=!0),_.component.sleeping&&this.really_wake(_,!1))}}if(b.sleeping){b.sleeping=!1;let _;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(_=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=_.next,_.next=null),_.elt=b;let z=_;z.next=d.head,d.head=z,d.modified=!0,d.length++}l=b}else if(f){let _=b;_.userdef_dyn_fric=!1,_.userdef_stat_fric=!1,_.userdef_restitution=!1,_.userdef_rfric=!1,_.__ref_edge1=_.__ref_edge2=null,_.next=ut.zpp_pool,ut.zpp_pool=_,l=null}else l=b;else l=b}else{let d;if(s==null){let k=null,z=(o.arbiters.length<r.arbiters.length?o:r).arbiters.head;for(;z!=null;){let C=z.elt;if(C.id==u.id&&C.di==x.id){k=C;break}z=z.next}d=k}else d=s;let y=d==null,f,b=!1;if(y)Ot.zpp_pool==null?f=new Ot:(f=Ot.zpp_pool,Ot.zpp_pool=f.next,f.next=null);else if(d.sensorarb==null){d.cleared=!0;{let _=d.b1.arbiters,z=null,C=_.head,w=!1;for(;C!=null;){if(C.elt==d){let g,O;z==null?(g=_.head,O=g.next,_.head=O,_.head==null&&(_.pushmod=!0)):(g=z.next,O=g.next,z.next=O,O==null&&(_.pushmod=!0));let E=g;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,_.modified=!0,_.length--,_.pushmod=!0,w=!0;break}z=C,C=C.next}}{let _=d.b2.arbiters,z=null,C=_.head,w=!1;for(;C!=null;){if(C.elt==d){let g,O;z==null?(g=_.head,O=g.next,_.head=O,_.head==null&&(_.pushmod=!0)):(g=z.next,O=g.next,z.next=O,O==null&&(_.pushmod=!0));let E=g;E.elt=null,E.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,_.modified=!0,_.length--,_.pushmod=!0,w=!0;break}z=C,C=C.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Ot.zpp_pool==null?f=new Ot:(f=Ot.zpp_pool,Ot.zpp_pool=f.next,f.next=null),f.intchange=!0,y=!0,b=!0}else f=d.sensorarb;let P=2;if(y||f.stamp!=this.stamp||i)if(f.stamp=this.stamp,Ce.testCollide(u,x)){if(y){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 _=f.b1.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=f;let C=z;C.next=_.head,_.head=C,_.modified=!0,_.length++;let w=f.b2.arbiters,g;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?g=new B._zpp.util.ZNPNode_ZPP_Arbiter:(g=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=g.next,g.next=null),g.elt=f;let O=g;O.next=w.head,w.head=O,w.modified=!0,w.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=!b}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,_=f.ws1.id>f.ws2.id?f.ws2:f.ws1,z=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 w=this.mrca2;for(;w.head!=null;){let M=w.head;w.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,w.head==null&&(w.pushmod=!0),w.modified=!0,w.length--}if(w.pushmod=!0,_.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=_;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(_.body.cbSet!=null){let M=this.mrca1,N=_.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 A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}if(z.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=z;let Z=N;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(z.body.cbSet!=null){let M=this.mrca2,N=z.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 A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}let g=_.body.compound,O=z.body.compound;for(;g!=O;){let M=g==null?0:g.depth,N=O==null?0:O.depth;if(M<N){if(O.cbSet!=null){let Z=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=O;let S=A;S.next=Z.head,Z.head=S,Z.modified=!0,Z.length++}O=O.compound}else{if(g.cbSet!=null){let Z=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=g;let S=A;S.next=Z.head,Z.head=S,Z.modified=!0,Z.length++}g=g.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,N=this.mrca2.head;for(;N!=null;){let Z=N.elt,A=M.cbSet,S=Z.cbSet,L=A.manager,T=null,q=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;q!=null;){let F=q.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){T=F;break}q=q.next}if(T==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,_t.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),T=F,A.cbpairs.add(T),S!=A&&S.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,V=this.prelisteners;for(;V.head!=null;){let F=V.head;V.head=F.next;let D=F;D.elt=null,D.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=D,V.head==null&&(V.pushmod=!0),V.modified=!0,V.length--}V.pushmod=!0;let K=null,$=A.manager,Y=null,ee=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;ee!=null;){let F=ee.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){Y=F;break}ee=ee.next}if(Y==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,_t.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),Y=F,A.cbpairs.add(Y),S!=A&&S.cbpairs.add(Y)}Y.zip_listeners&&(Y.zip_listeners=!1,Y.__validate());let J=Y.listeners.head;for(;J!=null;){let F=J.elt;if(F.event==5&&(F.itype&P)!=0){let D=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=F;let U=I;K==null?(U.next=D.head,D.head=U):(U.next=K.next,K.next=U),D.pushmod=D.modified=!0,D.length++,K=U,k=k||!F.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=Kt.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 F=f.active;f.active=!0;let D=!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 Q=this.precb.zpp_inner,W=R.int1,ie=R.int2,oe,se=U.options1,ne=W.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=U.options2,he=ie.cbTypes;oe=le.nonemptyintersection(he,le.includes)&&!le.nonemptyintersection(he,le.excludes)}else oe=!1;oe?(Q.int1=W,Q.int2=ie):(Q.int1=ie,Q.int2=W),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let re=U.handlerp(this.precb);if(re!=null){let le;H.PreFlag_ACCEPT==null&&(H.internal=!0,H.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,H.internal=!1),re==H.PreFlag_ACCEPT?le=5:(H.PreFlag_ACCEPT_ONCE==null&&(H.internal=!0,H.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,H.internal=!1),re==H.PreFlag_ACCEPT_ONCE?le=1:(H.PreFlag_IGNORE==null&&(H.internal=!0,H.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,H.internal=!1),le=re==H.PreFlag_IGNORE?6:2)),f.immState=le}I=I.next}if(f.active=F,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,_;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(_=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=_.next,_.next=null),_.elt=f;let z=_;z.next=k.head,k.head=z,k.modified=!0,k.length++}l=f}else if(y){let k=f;k.next=Ot.zpp_pool,Ot.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 o=n.head;n.head=o.next;let r=o;r.elt=null,r.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let o=s.head;s.head=o.next;let r=o;r.elt=null,r.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_Interactor:(r=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._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;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=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;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_Interactor:(r=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._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;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let o=i==null?0:i.depth,r=l==null?0:l.depth;if(o<r){if(l.cbSet!=null){let a=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=a.head,a.head=c,a.modified=!0,a.length++}l=l.compound}else{if(i.cbSet!=null){let a=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=a.head,a.head=c,a.modified=!0,a.length++}i=i.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=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let o=s.head;s.head=o.next;let r=o;r.elt=null,r.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_Interactor:(r=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._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;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=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;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new B._zpp.util.ZNPNode_ZPP_Interactor:(r=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._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;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let o=i==null?0:i.depth,r=l==null?0:l.depth;if(o<r){if(l.cbSet!=null){let a=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=a.head,a.head=c,a.modified=!0,a.length++}l=l.compound}else{if(i.cbSet!=null){let a=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=a.head,a.head=c,a.modified=!0,a.length++}i=i.compound}}}};B._zpp=null,B._nape=null;var hi=B;var Dn=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}};Dn.zpp_pool=null;var nn=class nn extends Tn{constructor(t){super();this.failed=null;this.list=null;this.space=t,this.is_sweep=!0,this.sweep=this}__insert(t){let n;Dn.zpp_pool==null?n=new Dn:(n=Dn.zpp_pool,Dn.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=Dn.zpp_pool,Dn.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 o=n.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 r=1;o.localCOMx+=o.lverts.next.next.x*r,o.localCOMy+=o.lverts.next.next.y*r;let a=.5;o.localCOMx*=a,o.localCOMy*=a}else{o.localCOMx=0,o.localCOMy=0;let r=0,a=o.lverts.next,p=a;a=a.next;let c=a;for(a=a.next;a!=null;){let y=a;r+=c.x*(y.y-p.y);let f=y.y*c.x-y.x*c.y;o.localCOMx+=(c.x+y.x)*f,o.localCOMy+=(c.y+y.y)*f,p=c,c=y,a=a.next}a=o.lverts.next;let h=a;r+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;o.localCOMx+=(c.x+h.x)*u,o.localCOMy+=(c.y+h.y)*u,p=c,c=h,a=a.next;let x=a;r+=c.x*(x.y-p.y);let m=x.y*c.x-x.x*c.y;o.localCOMx+=(c.x+x.x)*m,o.localCOMy+=(c.y+x.y)*m,r=1/(3*r);let d=r;o.localCOMx*=d,o.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 o=n.lverts.next,r=n.gverts.next;for(;r!=null;){let a=r,p=o;o=o.next,a.x=n.body.posx+(n.body.axisy*p.x-n.body.axisx*p.y),a.y=n.body.posy+(p.x*n.body.axisx+p.y*n.body.axisy),r=r.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,o=s.prev;if(o!=null&&s.aabb.minx>o.aabb.minx){s=l;continue}for(;o.prev!=null&&o.prev.aabb.minx>s.aabb.minx;)o=o.prev;let r=s.prev;r.next=s.next,s.next!=null&&(s.next.prev=r),o.prev==null?(s.prev=null,this.list=s,s.next=o,o.prev=s):(s.prev=o.prev,o.prev=s,s.prev.next=s,s.next=o),s=l}let i=this.list;for(;i!=null;){let l=i.next,o=i.shape,r=o.body,a=i.aabb.maxx;for(;l!=null&&!(l.aabb.minx>a);){let p=l.shape,c=p.body;if(c==r){l=l.next;continue}if(r.type==1&&c.type==1){l=l.next;continue}if(r.component.sleeping&&c.component.sleeping){l=l.next;continue}let h=o.aabb,u=p.aabb;u.miny>h.maxy||h.miny>u.maxy||(n?t.narrowPhase(o,p,r.type!=2||c.type!=2,null,!1):t.continuousEvent(o,p,r.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=ae.get(t,n),o=i??new nn._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.minx>t;)r=r.next;for(;r!=null&&r.aabb.minx<=t;){if(r.aabb.maxx>=t&&r.aabb.miny<=n&&r.aabb.maxy>=n){let p=r.shape,c;if(s!=null){let h=p.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;c&&(p.type==0?Ce.circleContains(p.circle,l)&&o.push(p.outer):Ce.polyContains(p.polygon,l)&&o.push(p.outer))}r=r.next}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,o}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l=ae.get(t,n),o=i??new nn._nape.phys.BodyList,r=this.list;for(;r!=null&&r.aabb.minx>t;)r=r.next;for(;r!=null&&r.aabb.minx<=t;){if(r.aabb.maxx>=t&&r.aabb.miny<=n&&r.aabb.maxy>=n){let p=r.shape,c=p.body.outer;if(!o.has(c)){let h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.type==0?Ce.circleContains(p.circle,l)&&o.push(c):Ce.polyContains(p.polygon,l)&&o.push(c))}}r=r.next}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,o}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new nn._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.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)Ce.containTest(this.aabbShape.zpp_inner,p)&&r.push(p.outer);else{let h=a.aabb;if(h.minx>=o.minx&&h.miny>=o.miny&&h.maxx<=o.maxx&&h.maxy<=o.maxy)r.push(p.outer);else{let u=a.aabb;o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx&&Ce.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(p.outer)}}else{let h;if(s){let u=a.aabb;h=u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy}else{let u=a.aabb;h=o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx}h&&r.push(p.outer)}a=a.next}return r}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._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.shape,c=p.body.outer,h=a.aabb;if(o.miny<=h.maxy&&h.miny<=o.maxy&&o.minx<=h.maxx&&h.minx<=o.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=Ce.containTest(this.aabbShape.zpp_inner,p);!r.has(c)&&x?r.push(c):x||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ce.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(c);else if(s){if(!this.failed.has(c)){let x=p.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(c)&&m?r.push(c):m||(r.remove(c),this.failed.push(c))}}else{let x;if(r.has(c))x=!1;else{let m=p.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(c)}}a=a.next}return this.failed.clear(),r}shapesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new nn._nape.shape.ShapeList,p=this.list;for(;p!=null&&p.aabb.maxx<r.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=r.maxx;){let c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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?Ce.containTest(this.circShape.zpp_inner,h)&&a.push(h.outer):Ce.testCollide_safe(h,this.circShape.zpp_inner)&&a.push(h.outer))}p=p.next}return a}bodiesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._nape.phys.BodyList);let p=this.list;for(;p!=null&&p.aabb.maxx<r.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=r.maxx;){let c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx){let h=p.shape,u=h.body.outer,x;if(l!=null){let m=h.filter;x=(m.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&m.collisionGroup)!=0}else x=!0;if(x)if(i){if(!this.failed.has(u)){let m=Ce.containTest(this.circShape.zpp_inner,h);!a.has(u)&&m?a.push(u):m||(a.remove(u),this.failed.push(u))}}else!a.has(u)&&Ce.testCollide_safe(h,this.circShape.zpp_inner)&&a.push(u)}p=p.next}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new nn._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.maxx<l.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=l.maxx;){let a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=r.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?Ce.containTest(t,p)&&o.push(p.outer):Ce.testCollide_safe(p,t)&&o.push(p.outer))}r=r.next}return o}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._nape.phys.BodyList);let r=this.list;for(;r!=null&&r.aabb.maxx<l.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=l.maxx;){let a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=r.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=Ce.containTest(t,p);!o.has(c)&&u?o.push(c):u||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ce.testCollide_safe(t,p)&&o.push(c)}r=r.next}return this.failed.clear(),o}rayCast(t,n,s){this.sync_broadphase(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,o=null;if(t.dirx==0){let a=this.list;for(;a!=null&&a.aabb.minx<=i.minx;){let p,c=a.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=a.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(a.aabb);if(h>=0&&h<l){let u=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.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,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=u}}}a=a.next}}else if(t.dirx<0){let a=this.list,p=null;for(;a!=null&&a.aabb.minx<=i.maxx;)p=a,a=a.next;for(a=p;a!=null;){let c,h=a.aabb;if(i.miny<=h.maxy&&h.miny<=i.maxy&&i.minx<=h.maxx&&h.minx<=i.maxx)if(s!=null){let u=a.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(a.aabb);if(u>=0&&u<l){let x=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.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,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=x}}}a=a.prev}}else{let a=this.list;for(;a!=null&&a.aabb.minx<=i.maxx&&a.aabb.minx<t.originx+t.dirx*l;){let p,c=a.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=a.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(a.aabb);if(h>=0&&h<l){let u=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.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,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=u}}}a=a.next}}let r=i;return 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,o}rayMultiCast(t,n,s,i){this.sync_broadphase(),t.validate_dir();let l=t.rayAABB(),o=i??new nn._nape.geom.RayResultList;if(t.dirx==0){let a=this.list;for(;a!=null&&a.aabb.minx<=l.minx;){let p,c=a.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,o):t.polysect2(a.shape.polygon,n,o)),a=a.next}}else if(t.dirx<0){let a=this.list,p=null;for(;a!=null&&a.aabb.minx<=l.maxx;)p=a,a=a.next;for(a=p;a!=null;){let c,h=a.aabb;if(l.miny<=h.maxy&&h.miny<=l.maxy&&l.minx<=h.maxx&&h.minx<=l.maxx)if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;else c=!1;c&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,o):t.polysect2(a.shape.polygon,n,o)),a=a.prev}}else{let a=this.list;for(;a!=null&&a.aabb.minx<=l.maxx;){let p,c=a.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,o):t.polysect2(a.shape.polygon,n,o)),a=a.next}}let r=l;return 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,o}};nn._zpp=null,nn._nape=null;var Zs=nn;function Jo(v){v.length=0,this.push(v)}var Rt=class Rt extends Tn{constructor(t,n){super();this.failed=null;this.shapes=[];this.grid=new Map;this.cellPool=[];this.testedPairs=new Set;this.frameCount=0;this.space=t,this.is_sweep=!0,this.is_spatial_hash=!0,this.sweep=this,n!=null&&n>0?(this.cellSize=n,this.fixedCellSize=!0):(this.cellSize=64,this.fixedCellSize=!1),this.invCellSize=1/this.cellSize}cellKey(t,n){return t*73856093^n*19349663}__insert(t){this.shapes.push(t),t.__shIdx=this.shapes.length-1}__remove(t){let n=t.__shIdx,s=this.shapes.length-1;if(n!==s){let i=this.shapes[s];this.shapes[n]=i,i.__shIdx=n}this.shapes.pop(),t.__shIdx=void 0}__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 o=n.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 r=1;o.localCOMx+=o.lverts.next.next.x*r,o.localCOMy+=o.lverts.next.next.y*r;let a=.5;o.localCOMx*=a,o.localCOMy*=a}else{o.localCOMx=0,o.localCOMy=0;let r=0,a=o.lverts.next,p=a;a=a.next;let c=a;for(a=a.next;a!=null;){let y=a;r+=c.x*(y.y-p.y);let f=y.y*c.x-y.x*c.y;o.localCOMx+=(c.x+y.x)*f,o.localCOMy+=(c.y+y.y)*f,p=c,c=y,a=a.next}a=o.lverts.next;let h=a;r+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;o.localCOMx+=(c.x+h.x)*u,o.localCOMy+=(c.y+h.y)*u,p=c,c=h,a=a.next;let x=a;r+=c.x*(x.y-p.y);let m=x.y*c.x-x.x*c.y;o.localCOMx+=(c.x+x.x)*m,o.localCOMy+=(c.y+x.y)*m,r=1/(3*r);let d=r;o.localCOMx*=d,o.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 if(t.type==2)t.capsule.__validate_aabb();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 o=n.lverts.next,r=n.gverts.next;for(;r!=null;){let a=r,p=o;o=o.next,a.x=n.body.posx+(n.body.axisy*p.x-n.body.axisx*p.y),a.y=n.body.posy+(p.x*n.body.axisx+p.y*n.body.axisy),r=r.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}}}autoTuneCellSize(){if(this.fixedCellSize||this.shapes.length===0)return;let t=0,n=0,s=0;for(let o=0;o<this.shapes.length;o++){let r=this.shapes[o].aabb;r!=null&&(t+=r.maxx-r.minx,n+=r.maxy-r.miny,s++)}if(s===0)return;let i=(t+n)/(2*s),l=Math.max(i*2,8);this.cellSize=l,this.invCellSize=1/l}broadphase(t,n){let s=this.shapes.length;if(s===0)return;this.frameCount++,(this.frameCount===1||!this.fixedCellSize&&this.frameCount%Rt.TUNE_INTERVAL===0)&&this.autoTuneCellSize();let i=this.invCellSize,l=this.grid,o=this.cellPool;l.forEach(Jo,o),l.clear();let r=this.testedPairs;r.clear();for(let a=0;a<s;a++){let p=this.shapes[a],c=p.aabb,h=p.__shIdx,u=c.minx*i|0,x=c.miny*i|0,m=c.maxx*i|0,d=c.maxy*i|0;if(u===m&&x===d){let f=u*73856093^x*19349663,b=l.get(f);b===void 0&&(b=o.length>0?o.pop():[],l.set(f,b));let P=b.length,k=p.body,_=k.type,z=k.component.sleeping;for(let C=0;C<P;C++){let w=b[C],g=w.body;if(g===k||_===1&&g.type===1||z&&g.component.sleeping)continue;let O=w.aabb;O.miny>c.maxy||c.miny>O.maxy||O.minx>c.maxx||c.minx>O.maxx||(n?t.narrowPhase(p,w,_!==2||g.type!==2,null,!1):t.continuousEvent(p,w,_!==2||g.type!==2,null,!1))}b.push(p)}else for(let f=u;f<=m;f++)for(let b=x;b<=d;b++){let P=f*73856093^b*19349663,k=l.get(P);k===void 0&&(k=o.length>0?o.pop():[],l.set(P,k));let _=k.length,z=p.body,C=z.type,w=z.component.sleeping;for(let g=0;g<_;g++){let O=k[g],E=O.body;if(E===z||C===1&&E.type===1||w&&E.component.sleeping)continue;let M=O.__shIdx,N=h<M?h:M,Z=h<M?M:h,A=Z*Z+N;if(r.has(A))continue;r.add(A);let S=O.aabb;S.miny>c.maxy||c.miny>S.maxy||S.minx>c.maxx||c.minx>S.maxx||(n?t.narrowPhase(p,O,C!==2||E.type!==2,null,!1):t.continuousEvent(p,O,C!==2||E.type!==2,null,!1))}k.push(p)}}}clear(){for(;this.shapes.length>0;){let t=this.shapes[this.shapes.length-1];t.removedFromSpace(),this.__remove(t)}this.grid.clear(),this.cellPool.length=0,this.testedPairs.clear()}shapesUnderPoint(t,n,s,i){this.space.validation();let l=ae.get(t,n),o=i??new Rt._nape.shape.ShapeList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb;if(c.minx<=t&&c.maxx>=t&&c.miny<=n&&c.maxy>=n){let h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.type==0?Ce.circleContains(p.circle,l)&&o.push(p.outer):Ce.polyContains(p.polygon,l)&&o.push(p.outer))}}let r=l;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=ae.zpp_pool,ae.zpp_pool=r,o}bodiesUnderPoint(t,n,s,i){this.space.validation();let l=ae.get(t,n),o=i??new Rt._nape.phys.BodyList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb;if(c.minx<=t&&c.maxx>=t&&c.miny<=n&&c.maxy>=n){let h=p.body.outer;if(!o.has(h)){let u;if(s!=null){let x=p.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(p.type==0?Ce.circleContains(p.circle,l)&&o.push(h):Ce.polyContains(p.polygon,l)&&o.push(h))}}}let r=l;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=ae.zpp_pool,ae.zpp_pool=r,o}shapesInAABB(t,n,s,i,l){this.space.validation(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new Rt._nape.shape.ShapeList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],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)Ce.containTest(this.aabbShape.zpp_inner,p)&&r.push(p.outer);else{let h=p.aabb;if(h.minx>=o.minx&&h.miny>=o.miny&&h.maxx<=o.maxx&&h.maxy<=o.maxy)r.push(p.outer);else{let u=p.aabb;o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx&&Ce.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(p.outer)}}else{let h;if(s){let u=p.aabb;h=u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy}else{let u=p.aabb;h=o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx}h&&r.push(p.outer)}}return r}bodiesInAABB(t,n,s,i,l){this.space.validation(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new Rt._nape.phys.BodyList;this.failed==null&&(this.failed=new Rt._nape.phys.BodyList);for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.body.outer,h=p.aabb;if(o.miny<=h.maxy&&h.miny<=o.maxy&&o.minx<=h.maxx&&h.minx<=o.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=Ce.containTest(this.aabbShape.zpp_inner,p);!r.has(c)&&x?r.push(c):x||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ce.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(c);else if(s){if(!this.failed.has(c)){let x=p.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(c)&&m?r.push(c):m||(r.remove(c),this.failed.push(c))}}else{let x;if(r.has(c))x=!1;else{let m=p.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(c)}}}return this.failed.clear(),r}shapesInCircle(t,n,s,i,l,o){this.space.validation(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new Rt._nape.shape.ShapeList;for(let p=0;p<this.shapes.length;p++){let c=this.shapes[p],h=c.aabb;if(r.miny<=h.maxy&&h.miny<=r.maxy&&r.minx<=h.maxx&&h.minx<=r.maxx){let u;if(l!=null){let x=c.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(i?Ce.containTest(this.circShape.zpp_inner,c)&&a.push(c.outer):Ce.testCollide_safe(c,this.circShape.zpp_inner)&&a.push(c.outer))}}return a}bodiesInCircle(t,n,s,i,l,o){this.space.validation(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new Rt._nape.phys.BodyList;this.failed==null&&(this.failed=new Rt._nape.phys.BodyList);for(let p=0;p<this.shapes.length;p++){let c=this.shapes[p],h=c.aabb;if(r.miny<=h.maxy&&h.miny<=r.maxy&&r.minx<=h.maxx&&h.minx<=r.maxx){let u=c.body.outer,x;if(l!=null){let m=c.filter;x=(m.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&m.collisionGroup)!=0}else x=!0;if(x)if(i){if(!this.failed.has(u)){let m=Ce.containTest(this.circShape.zpp_inner,c);!a.has(u)&&m?a.push(u):m||(a.remove(u),this.failed.push(u))}}else!a.has(u)&&Ce.testCollide_safe(c,this.circShape.zpp_inner)&&a.push(u)}}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.space.validation(),this.validateShape(t);let l=t.aabb,o=i??new Rt._nape.shape.ShapeList;for(let r=0;r<this.shapes.length;r++){let a=this.shapes[r],p=a.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx){let c;if(s!=null){let h=a.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;c&&(n?Ce.containTest(t,a)&&o.push(a.outer):Ce.testCollide_safe(a,t)&&o.push(a.outer))}}return o}bodiesInShape(t,n,s,i){this.space.validation(),this.validateShape(t);let l=t.aabb,o=i??new Rt._nape.phys.BodyList;this.failed==null&&(this.failed=new Rt._nape.phys.BodyList);for(let r=0;r<this.shapes.length;r++){let a=this.shapes[r],p=a.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx){let c=a.body.outer,h;if(s!=null){let u=a.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=Ce.containTest(t,a);!o.has(c)&&u?o.push(c):u||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ce.testCollide_safe(t,a)&&o.push(c)}}return this.failed.clear(),o}rayCast(t,n,s){this.space.validation(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,o=null;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb,h;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;else h=!1;if(h){let u=t.aabbsect(c);if(u>=0&&u<l){let x=p.type==0?t.circlesect(p.circle,n,l):t.polysect(p.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,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=x}}}}let r=i;return 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,o}rayMultiCast(t,n,s,i){this.space.validation(),t.validate_dir();let l=t.rayAABB(),o=i??new Rt._nape.geom.RayResultList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb,h;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;else h=!1;h&&t.aabbsect(c)>=0&&(p.type==0?t.circlesect2(p.circle,n,o):t.polysect2(p.polygon,n,o))}let r=l;return 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,o}};Rt._zpp=null,Rt._nape=null,Rt.TUNE_INTERVAL=120;var ks=Rt;function Hl(){let v={},e={};return v.callbacks={},v.constraint={},v.dynamics={},v.geom={},v.phys={},v.shape={},v.space={},v.util={},e.ZPP_Const=qn,e.ZPP_ID=yn,e.callbacks||(e.callbacks={}),Tt._nape=v,Tt._zpp=e,e.callbacks.ZPP_Callback=Tt,_t._zpp=e,e.callbacks.ZPP_CbSet=_t,Ne._zpp=e,e.callbacks.ZPP_CbSetPair=Ne,e.util||(e.util={}),Xl(e),pn._zpp=e,e.callbacks.ZPP_CbType=pn,e.util.ZPP_Flags=H,Lt._nape=v,Lt._zpp=e,e.callbacks.ZPP_Listener=Lt,e.callbacks.ZPP_BodyListener=cl,e.callbacks.ZPP_ConstraintListener=hl,e.callbacks.ZPP_InteractionListener=ul,ws._nape=v,ws._zpp=e,e.callbacks.ZPP_OptionType=ws,e.constraint||(e.constraint={}),Ze._nape=v,Ze._zpp=e,e.constraint.ZPP_Constraint=Ze,e.constraint.ZPP_AngleJoint=qe,e.constraint.ZPP_CopyHelper=Un,e.constraint.ZPP_DistanceJoint=yi,e.constraint.ZPP_LineJoint=mi,e.constraint.ZPP_MotorJoint=bi,e.constraint.ZPP_PivotJoint=fi,e.constraint.ZPP_PulleyJoint=zi,e.constraint.ZPP_UserConstraint=xl,e.constraint.ZPP_UserBody=vs,e.constraint.ZPP_WeldJoint=Pi,e.dynamics||(e.dynamics={}),Ie._nape=v,Ie._zpp=e,e.dynamics.ZPP_Arbiter=Ie,e.dynamics.ZPP_SensorArbiter=Ot,Pt._nape=v,Pt._zpp=e,e.dynamics.ZPP_FluidArbiter=Pt,ut._nape=v,ut._zpp=e,e.dynamics.ZPP_ColArbiter=ut,e.dynamics.ZPP_IContact=wi,Pe._nape=v,Pe._zpp=e,e.dynamics.ZPP_Contact=Pe,it._nape=v,it._zpp=e,e.dynamics.ZPP_InteractionFilter=it,qs._zpp=e,e.dynamics.ZPP_InteractionGroup=qs,Qn._nape=v,Qn._zpp=e,e.dynamics.ZPP_SpaceArbiterList=Qn,e.geom||(e.geom={}),be._nape=v,be._zpp=e,e.geom.ZPP_AABB=be,e.geom.ZPP_Collide=Ce,e.geom.ZPP_Convex=dl,e.geom.ZPP_ConvexRayResult=bn,e.geom.ZPP_CutVert=Qe,e.geom.ZPP_CutInt=lt,e.geom.ZPP_Cutter=_l,e.geom.ZPP_Geom=gs,e.geom.ZPP_GeomVert=ge,ge._createVec2Fn=function(){return new v.geom.Vec2},e.geom.ZPP_GeomPoly=yl,e.geom.ZPP_MarchSpan=Bn,e.geom.ZPP_MarchPair=jn,Js._init(e,v),e.geom.ZPP_MarchingSquares=Js,Us._nape=v,e.geom.ZPP_Mat23=Us,e.geom.ZPP_MatMN=Gi,e.geom.ZPP_Monotone=ml,e.geom.ZPP_PartitionVertex=Ge,e.geom.ZPP_PartitionedPoly=qi,e.geom.ZPP_Ray=bl,e.geom.ZPP_SimpleVert=Ee,e.geom.ZPP_SimpleSeg=Vt,e.geom.ZPP_SimpleEvent=Me,e.geom.ZPP_SimpleSweep=Ki,e.geom.ZPP_Simple=fl,e.geom.ZPP_SimplifyV=gn,e.geom.ZPP_SimplifyP=Le,e.geom.ZPP_Simplify=zl,e.geom.ZPP_ToiEvent=Ws,e.geom.ZPP_SweepDistance=Cn,e.geom.ZPP_PartitionPair=St,e.geom.ZPP_Triangular=Pl,e.geom.ZPP_Vec2=ae,ai._zpp=e,e.geom.ZPP_Vec3=ai,e.geom.ZPP_VecMath=wl,e.phys||(e.phys={}),e.phys.ZPP_Interactor=Wt,Wt._init(e,v),Mn._init(e,v),e.phys.ZPP_Body=Mn,Wn._nape=v,Wn._zpp=e,Wn._init(),e.phys.ZPP_Compound=Wn,Zn._nape=v,Zn._zpp=e,e.phys.ZPP_FluidProperties=Zn,Oe._nape=v,Oe._zpp=e,e.phys.ZPP_Material=Oe,e.shape||(e.shape={}),pi._nape=v,pi._zpp=e,pi._init(),e.shape.ZPP_Shape=pi,$n._nape=v,$n._zpp=e,$n._init(),e.shape.ZPP_Circle=$n,ot._nape=v,ot._zpp=e,e.shape.ZPP_Edge=ot,ei._nape=v,ei._zpp=e,ei._init(),e.shape.ZPP_Polygon=ei,ti._nape=v,ti._zpp=e,ti._init(),e.shape.ZPP_Capsule=ti,e.space||(e.space={}),Tn._zpp=e,Tn._nape=v,e.space.ZPP_Broadphase=Tn,e.space.ZPP_AABBNode=Ae,e.space.ZPP_AABBPair=st,e.space.ZPP_AABBTree=$e,Ms._zpp=e,Ms._nape=v,e.space.ZPP_DynAABBPhase=Ms,xt._zpp=e,e.space.ZPP_Island=xt,e.space.ZPP_Component=Ys,Kt._zpp=e,e.space.ZPP_CallbackSet=Kt,Hi._zpp=e,e.space.ZPP_CbSetManager=Hi,hi._zpp=e,hi._nape=v,e.space.ZPP_Space=hi,e.space.ZPP_SweepData=Dn,Zs._zpp=e,Zs._nape=v,e.space.ZPP_SweepPhase=Zs,ks._zpp=e,ks._nape=v,e.space.ZPP_SpatialHashPhase=ks,e.util.ZNPArray2_Float=ds,e.util.ZNPArray2_ZPP_GeomVert=_s,e.util.ZNPArray2_ZPP_MarchPair=ys,e.util.Hashable2_Boolfalse=Te,e.util.FastHash2_Hashable2_Boolfalse=Ti,e.util.ZPP_Math=al,e.util.ZPP_PubPool=ye,e.callbacks.ZPP_InteractionListener._initStatics(e),e.geom.ZPP_Collide._initStatics(e),e.space.ZPP_AABBTree._initStatics(),v.__zpp=e,v}var vl;function me(){return vl||(vl=Hl()),vl}var Ql=!1;function $l(){if(Ql)return;let v=vl;if(!v?.callbacks?.CbEvent||!v?.callbacks?.CbType||!v?.callbacks?.ListenerType||!v?.dynamics?.ArbiterType||!v?.phys?.BodyType||!v?.shape?.ShapeType)return;Ql=!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 eo=new WeakMap;function ke(v,e){if(!v)return null;let t=eo.get(v);return t||(t=e(v),eo.set(v,t)),t}var Be=class v{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;ae.zpp_pool==null?n=new ae:(n=ae.zpp_pool,ae.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(ye.poolVec2==null?s=new v:(s=ye.poolVec2,ye.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===ye.nextVec2&&(ye.nextVec2=null)),s.zpp_inner==null){let i;ae.zpp_pool==null?i=new ae:(i=ae.zpp_pool,ae.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 v?e:e?e instanceof ae?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?v._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 v._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 v._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 v._poolGet(s,i,n)}static fromAngle(e,t=!1){return v.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),o=v._poolGet(i,l,s);return v._disposeWeak(e),v._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&&v._disposeWeak(e),t!=null&&v._disposeWeak(t),o}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 v._disposeWeak(e),v._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,o=n-i,r=s-l,a=o*o+r*r;return v._disposeWeak(e),v._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,s=e.zpp_inner.y;t.zpp_inner.validate();let i=t.zpp_inner.x,l=t.zpp_inner.y,o=n-i,r=s-l,a=Math.sqrt(o*o+r*r);return v._disposeWeak(e),v._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,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),v._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 v._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=v._poolGet(n,s,!0);i.normalise();let l=e.sub(i.muleq(2*i.dot(e)),t);return v._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 v._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=v._poolGet(n,s,t);return v._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=v._poolGet(s,i,n);return v._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=v._poolGet(n,s,t);return v._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 v._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),v._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),v._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 v._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 v._disposeWeak(e),t}perp(e=!1){this._checkDisposed(),this._validate();let t=-this.zpp_inner.y,n=this.zpp_inner.x;return v._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,ye.nextVec2!=null?ye.nextVec2.zpp_pool=this:ye.poolVec2=this,ye.nextVec2=this,this.zpp_disp=!0,e.free(),e.next=ae.zpp_pool,ae.zpp_pool=e}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};ae._wrapFn=v=>ke(v,e=>{let t=Object.create(Be.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Uo=me();Uo.geom.Vec2=Be;var ui=class v{constructor(e=0,t=0,n=0){this.zpp_pool=null;this.zpp_disp=!1;let s=new ai;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 v?e:e?e instanceof ai?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?v._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=0){let s;return ye.poolVec3==null?s=new v:(s=ye.poolVec3,ye.poolVec3=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===ye.nextVec3&&(ye.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(),v.get(this.zpp_inner.x,this.zpp_inner.y,this.zpp_inner.z)}xy(e=!1){return this._checkDisposed(),this.zpp_inner.validate(),Be.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,ye.nextVec3!=null?ye.nextVec3.zpp_pool=this:ye.poolVec3=this,ye.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+" }"}};ai._wrapFn=v=>ke(v,e=>{let t=Object.create(ui.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Xs=class v{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 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<s&&(s=p),a>i&&(i=a),p>l&&(l=p)}return new v(n,s,i-n,l-s)}static _wrap(e){return e instanceof v?e:e?e instanceof be?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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 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(),l>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 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 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(),l<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 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 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==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(),o=e.zpp_inner.y==i}else o=!1;o||(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 o=i;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,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=v=>ke(v,e=>{let t=Object.create(Xs.prototype);return t.zpp_inner=e,e.outer=t,t});var gl=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 On=class v{get _inner(){return this}constructor(e=1,t=1){let n;if(Zn.zpp_pool==null?n=new Zn:(n=Zn.zpp_pool,Zn.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 v?e:e?e instanceof Zn?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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 o=s;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=l;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 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 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(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(),o!=o||a!=a)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==o){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==a}else c=!1;if(!c){s.zpp_inner.x=o,s.zpp_inner.y=a;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 m=e;m.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=m:n.util.ZPP_PubPool.poolVec2=m,n.util.ZPP_PubPool.nextVec2=m,m.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 v(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 o=i.zpp_inner;i.zpp_inner.outer=null,i.zpp_inner=null;let r=i;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(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 o=s.zpp_inner;o._validate!=null&&o._validate();let r=s.zpp_inner.x;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();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(),r!=r||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==r){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=r,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 m=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=m;y.outer!=null&&(y.outer.zpp_inner=null,y.outer=null),y._isimmutable=null,y._validate=null,y._invalidate=null,y.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=y}}return n}toString(){return"{ density: "+this.zpp_inner.density*1e3+" viscosity: "+this.zpp_inner.viscosity+" gravity: "+String(this.zpp_inner.wrap_gravity)+" }"}};Zn._wrapFn=v=>ke(v,e=>{let t=Object.create(On.prototype);return t.zpp_inner=e,e.outer=t,t});var Wo=me();Wo.phys.FluidProperties=On;var Hs,Cl,Ml;function to(v){Hs=v}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()&&Hs?Hs(e):e.isShape&&e.isShape()&&Cl?Cl(e):e.isCompound&&e.isCompound()&&Ml?Ml(e):ke(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 Hs?Hs(e):e}return null}get castShape(){if(this.zpp_inner_i.ishape!=null){let e=this.zpp_inner_i.ishape.outer;return Cl?Cl(e):e}return null}get castCompound(){if(this.zpp_inner_i.icompound!=null){let e=this.zpp_inner_i.icompound.outer;return Ml?Ml(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 Ci=Qs;var $s,el,tl;function no(v){$s=v}function io(v){el=v}function so(v){tl=v}var ni=class v extends Ci{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&&$s?$s(e):t===1&&el?el(e):t===2&&tl?tl(e):e.outer?e.outer:ke(e,n=>{let s=Object.create(v.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 pi.types[this.zpp_inner.type]}isCircle(){return this.zpp_inner.type===0}isPolygon(){return this.zpp_inner.type===1}isCapsule(){return this.zpp_inner.type===2}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 $s?$s(t):t}return null}get castPolygon(){let e=this.zpp_inner;if(e.type===1){let t=e.polygon.outer_zn;return el?el(t):t}return null}get castCapsule(){let e=this.zpp_inner;if(e.type===2){let t=e.capsule.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.type===1?e.polygon.setupLocalCOM():e.capsule.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.type===1?t.polygon.setupLocalCOM():t.capsule.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 On().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 On().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 On;t.setFluid(n.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new On().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.type===1?t.polygon:t.capsule).__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.type===1?n.polygon.__scale(e,t):n.capsule.__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.type===1?t.polygon.__rotate(i,s):t.capsule.__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.type===1?t.polygon.__transform(n):t.capsule.__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 s=Ce.shapeContains(t,n);return n.weak&&e.dispose(),s}copy(){let e=this.zpp_inner.copy();return e instanceof v?e:v._wrap(e)}toString(){let e=this.zpp_inner;return(e.type===0?"Circle":e.type===1?"Polygon":"Capsule")+"#"+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(ye.poolVec2==null?i=new e.geom.Vec2:(i=ye.poolVec2,ye.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i===ye.nextVec2&&(ye.nextVec2=null)),i.zpp_inner==null){let l;ae.zpp_pool==null?l=new ae:(l=ae.zpp_pool,ae.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 Dl=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 s=me(),i=s.__zpp;class l extends Dl{constructor(){super(),this.inner=new i.util[v]}static get(r,a=!1){let p=new s[e][t];return p.zpp_inner.inner=r,a&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}}return l.internal=!1,i.util[n]=l,l}var Fl=null,Ko=null,Rl=null;Fl=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");Rl=Sn("ZNPList_ZPP_Arbiter","dynamics","ArbiterList","ZPP_ArbiterList");function Kn(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 Yn(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 Fn(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 Es(v,e,t,n,s){if(Fn(t),t==null)throw new Error("Error: Body::"+v+" cannot be null");return e==null&&n!=null&&(n(),e=s()),e.set(t),e}function Zl(v,e,t){return Be.get(v,e,t)}function sn(v,e){return H[v]==null&&(H.internal=!0,H[v]=e(),H.internal=!1),H[v]}var We=class v extends Ci{constructor(t,n){super();this.debugDraw=!0;let s=new Mn;this.zpp_inner=s,s.outer=this,s.outer_i=this,this.zpp_inner_i=s,this._inner=this,n!=null?(Fn(n),s.posx=Kn(n),s.posy=Yn(n)):(s.posx=0,s.posy=0);let i=me(),l;if(t==null?l=sn("BodyType_DYNAMIC",()=>new i.phys.BodyType):l=t,s.immutable_midstep("Body::type"),s.world)throw new Error("Error: Space::world is immutable");if(Mn.types[s.type]!==l){if(l==null)throw new Error("Error: Cannot use null BodyType");let o=lo(l,i);o===1&&s.space!=null&&(s.velx=0,s.vely=0,s.angvel=0),s.invalidate_type(),s.space!=null?s.space.transmitType(s,o):s.type=o}n!=null&&An(n),s.insert_cbtype(pn.ANY_BODY.zpp_inner)}static _wrap(t){return t?t instanceof v?t:t instanceof Mn?ke(t,n=>{let s=Object.create(v.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?v._wrap(t.zpp_inner):ke(t,n=>{let s=Object.create(v.prototype);return s._inner=n,s}):null}get type(){return Mn.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(Mn.types[n.type]!==t){if(t==null)throw new Error("Error: Cannot use null BodyType");let s=me(),i=lo(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){Es("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){Es("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){Es("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){Es("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){Es("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 gl(this.zpp_inner.wrap_shapes,ni._wrap)}get space(){return this.zpp_inner.space==null?null:ii._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 Xs._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=Be.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=Be.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=sn("MassMode_DEFAULT",()=>new t.phys.MassMode),s=sn("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=sn("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=sn("InertiaMode_DEFAULT",()=>new t.phys.InertiaMode),s=sn("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=sn("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=sn("GravMassMode_DEFAULT",()=>new t.phys.GravMassMode),s=sn("GravMassMode_FIXED",()=>new t.phys.GravMassMode),i=sn("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=sn("GravMassMode_SCALED",()=>new n.phys.GravMassMode);if(t===s)this.zpp_inner.gravMassMode=2;else{let i=sn("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,o=1-.5*l,r=1-l*l/8,a=(o*n.axisx+i*n.axisy)*r;n.axisy=(o*n.axisy-i*n.axisx)*r,n.axisx=a}}return oo(n),n.zip_worldCOM=!0,n.zip_axis=!0,oo(n),n.zip_worldCOM=!0,n.sweepTime=0,this}localPointToWorld(t,n=!1){if(Fn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Kn(t),i=Yn(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,o=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return An(t),Zl(l+this.zpp_inner.posx,o+this.zpp_inner.posy,n)}worldPointToLocal(t,n=!1){if(Fn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Kn(t)-this.zpp_inner.posx,i=Yn(t)-this.zpp_inner.posy,l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,o=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return An(t),Zl(l,o,n)}localVectorToWorld(t,n=!1){if(Fn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Kn(t),i=Yn(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,o=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return An(t),Zl(l,o,n)}worldVectorToLocal(t,n=!1){if(Fn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Kn(t),i=Yn(t),l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,o=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return An(t),Zl(l,o,n)}applyImpulse(t,n,s=!1){if(Fn(t),n!=null&&Fn(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 An(t),n!=null&&An(n),this;this.zpp_inner.validate_mass();let i=this.zpp_inner.imass,l=Kn(t),o=Yn(t);if(this.zpp_inner.velx+=l*i,this.zpp_inner.vely+=o*i,n!=null){let r=Kn(n)-this.zpp_inner.posx,a=Yn(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(o*r-l*a)*this.zpp_inner.iinertia,An(n)}return s||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,s){if(Fn(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 o=(n-this.zpp_inner.rot)*i;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()"),Fn(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,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 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=Be.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-=Kn(n),this.zpp_inner.pre_posy-=Yn(n)),t.dispose(),n.dispose(),this}rotate(t,n){if(Fn(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);Es("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 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=s,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 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(Fn(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,An(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=Ie.COL|Ie.SENSOR|Ie.FLUID;else{let l=me(),o=sn("InteractionType_COLLISION",()=>new l.callbacks.InteractionType);if(t===o)i=Ie.COL;else{let r=sn("InteractionType_SENSOR",()=>new l.callbacks.InteractionType);i=t===r?Ie.SENSOR:Ie.FLUID}}return this.zpp_inner.interactingBodies(i,s)}normalImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.normalImpulse(this,n),t)}tangentImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.tangentImpulse(this,n),t)}totalContactsImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ie.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 o=l.zpp_inner.zpp_gl();if(l.zpp_critical=!0,l.zpp_i>=o){l.zpp_next=me().dynamics.ArbiterIterator.zpp_pool,me().dynamics.ArbiterIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1;let r=l.zpp_inner.at(l.zpp_i++),a=r.zpp_inner;a.type===Ie.COL&&(t!=null&&a.b2!==t.zpp_inner&&a.b1!==t.zpp_inner||(s+=r.collisionArbiter.rollingImpulse(this,n)))}return s}buoyancyImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.buoyancyImpulse(this),t)}dragImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.dragImpulse(this),t)}totalFluidImpulse(t=null){return this._arbiterImpulseQuery(Ie.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 o=i.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(),s+=r.z,o.dispose(),i=i.next}return ui.get(t,n,s)}totalImpulse(t=null,n=!1){let s=0,i=0,l=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 h=r.zpp_inner.at(r.zpp_i++).zpp_inner;if(h.type===Ie.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 a=this.zpp_inner.constraints.head;for(;a!=null;){let p=a.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()}a=a.next}return ui.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=Be.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),y=d.xy();n.addeq(y);let f=Kn(y),b=Yn(y);t+=Math.sqrt(f*f+b*b),y.dispose(),d.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 m=x.zpp_inner.user_length;if(r.zpp_critical=!0,r.zpp_i>=m){r.zpp_next=me().constraint.ConstraintIterator.zpp_pool,me().constraint.ConstraintIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let y=r.zpp_inner.at(r.zpp_i++).bodyImpulse(this),f=y.xy();n.addeq(f);let b=Kn(f),P=Yn(f);t+=Math.sqrt(b*b+P*P),f.dispose(),y.dispose()}let a=Kn(n),p=Yn(n),c=Math.sqrt(a*a+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=Rl.get(this.zpp_inner.arbiters,!0)),this.zpp_inner.wrap_arbiters}_getConstraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=Fl.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}_arbiterImpulseQuery(t,n,s){let i=0,l=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++),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(),o+=x.z,u.dispose()}return ui.get(i,l,o)}};function lo(v,e){let t=sn("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(v===t)return 2;let n=sn("BodyType_KINEMATIC",()=>new e.phys.BodyType);return v===n?3:1}function oo(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=We;to(v=>We._wrap(v));var Mi={SHAPES:1,JOINTS:2,CONTACTS:4,AABB:8,CENTER_OF_MASS:16,VELOCITIES:32,ALL:63};var ii=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 hi(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 hi?e.outer?e.outer:ke(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:ke(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_spatial_hash?(H.Broadphase_SPATIAL_HASH==null&&(H.internal=!0,H.Broadphase_SPATIAL_HASH=new(me()).space.Broadphase,H.internal=!1),H.Broadphase_SPATIAL_HASH):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 deterministic(){return this.zpp_inner.deterministic}set deterministic(e){this.zpp_inner.deterministic=e,e&&(this.zpp_inner.sortcontacts=!0)}get subSteps(){return this.zpp_inner.subSteps}set subSteps(e){if(e!==e)throw new Error("Error: Space::subSteps cannot be NaN");if(e<1)throw new Error("Error: Space::subSteps must be at least 1");this.zpp_inner.subSteps=Math.floor(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 Qn;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 o=s.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(s.zpp_critical=!0,s.zpp_i>=r){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 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.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 o=s.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(s.zpp_critical=!0,s.zpp_i>=r){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 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.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 o=s.zpp_inner.at(s.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,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 o=!1,r=i.constraints.head;for(;r!=null;){let u=r.elt;if(u.ignore&&u.pair_exists(i.id,l.id)){o=!0;break}r=r.next}let a;if(o)a=!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,m;if(x==null)m=!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 y=d==null?null:d.group;if(y==null)m=!1;else{let f=!1;for(;x!=null&&y!=null;){if(x==y){f=x.ignore;break}x.depth<y.depth?y=y.group:x=x.group}m=f}}a=!m}if(!a)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,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.shapesUnderPoint(i,l,o,n);return s.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 s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.bodiesUnderPoint(i,l,o,n);return s.weak&&e.dispose(),r}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 o=s==null?null:s.zpp_inner??s;return this.zpp_inner.shapesInAABB(e,n,t,o,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 o=s==null?null:s.zpp_inner??s;return this.zpp_inner.bodiesInAABB(e,n,t,o,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,o=this.zpp_inner.shapesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),o}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,o=this.zpp_inner.bodiesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),o}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 o=i.polygon.valid();if(H.ValidationResult_VALID==null&&(H.internal=!0,H.ValidationResult_VALID=new(me()).shape.ValidationResult,H.internal=!1),o!=H.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.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 o=i.polygon.valid();if(H.ValidationResult_VALID==null&&(H.internal=!0,H.ValidationResult_VALID=new(me()).shape.ValidationResult,H.internal=!1),o!=H.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.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 o=s.shape.ShapeIterator.get(l);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=s.shape.ShapeIterator.zpp_pool,s.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,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 o=s.shape.ShapeIterator.get(l);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=s.shape.ShapeIterator.zpp_pool,s.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,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=Mi.ALL){if(e==null)throw new Error("Error: drawer cannot be null for Space::debugDraw");let n=(t&Mi.SHAPES)!==0,s=(t&Mi.JOINTS)!==0,i=(t&Mi.CONTACTS)!==0,l=(t&Mi.AABB)!==0,o=(t&Mi.CENTER_OF_MASS)!==0,r=(t&Mi.VELOCITIES)!==0,a=4283417591,p=4287669422,c=4294948685,h=4289058471,u=4293874512,x=1157627903,m=4294961979,d=4291728344;if(this.visitBodies(y=>{let f=y.zpp_inner,b=f.type===2,k=f.type===1?p:b?a:c;if(n){let _=f.shapes.head;for(;_!=null;){let z=_.elt;if(z.type===0){let C=z.circle;z.zip_worldCOM&&z.validate_worldCOM();let w=z.worldCOMx,g=z.worldCOMy,O=C.radius,E=f.rot,M=w+Math.cos(E)*O,N=g+Math.sin(E)*O,Z={x:w,y:g},A={x:M,y:N};b?e.drawSolidCircle(Z,O,A,k):e.drawCircle(Z,O,k)}else if(z.type===1){let C=z.polygon;C.zip_gverts&&C.validate_gverts();let w=[],g=C.gverts.next;for(;g!=null;)w.push({x:g.x,y:g.y}),g=g.next;w.length>=3&&(b?e.drawSolidPolygon(w,k):e.drawPolygon(w,k))}else if(z.type===2){let C=z.capsule;z.zip_aabb&&z.validate_aabb();let w={x:C.spine1x,y:C.spine1y},g={x:C.spine2x,y:C.spine2y};b?e.drawSolidCapsule(w,g,C.radius,k):e.drawCapsule(w,g,C.radius,k)}_=_.next}}if(l&&!f.world){let _=f.aabb,z=_.minx,C=_.miny,w=_.maxx,g=_.maxy;e.drawSegment({x:z,y:C},{x:w,y:C},x),e.drawSegment({x:w,y:C},{x:w,y:g},x),e.drawSegment({x:w,y:g},{x:z,y:g},x),e.drawSegment({x:z,y:g},{x:z,y:C},x)}if(o&&!f.world&&(f.validate_worldCOM(),e.drawPoint({x:f.worldCOMx,y:f.worldCOMy},m)),r&&!f.world&&b){let _=f.posx,z=f.posy;e.drawSegment({x:_,y:z},{x:_+f.velx,y:z+f.vely},d)}}),s&&this.visitConstraints(y=>{if(!y.debugDraw)return;let f=y.zpp_inner,b=f.b1,P=f.b2,k=f.a1worldx??(b!=null?b.posx:0),_=f.a1worldy??(b!=null?b.posy:0),z=f.a2worldx??(P!=null?P.posx:0),C=f.a2worldy??(P!=null?P.posy:0);e.drawSegment({x:k,y:_},{x:z,y:C},h),e.drawPoint({x:k,y:_},h),e.drawPoint({x:z,y:C},h)}),i){let y=f=>{if(f==null)return;let b=f.head;for(;b!=null;){let P=b.elt;if(P!=null){let k=P.nx,_=P.ny,z=P.contacts?.next;for(;z!=null;){let C=z.px,w=z.py;e.drawPoint({x:C,y:w},u),e.drawSegment({x:C,y:w},{x:C+k*8,y:w+_*8},u),z=z.next}}b=b.next}};y(this.zpp_inner.c_arbiters_true),y(this.zpp_inner.c_arbiters_false)}}toString(){return`Space(bodies=${this.bodies.length})`}};var Rn=class v{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 v,H.internal=!1),H.BodyType_STATIC}static get DYNAMIC(){return H.BodyType_DYNAMIC==null&&(H.internal=!0,H.BodyType_DYNAMIC=new v,H.internal=!1),H.BodyType_DYNAMIC}static get KINEMATIC(){return H.BodyType_KINEMATIC==null&&(H.internal=!0,H.BodyType_KINEMATIC=new v,H.internal=!1),H.BodyType_KINEMATIC}toString(){return this===H.BodyType_STATIC?"STATIC":this===H.BodyType_DYNAMIC?"DYNAMIC":this===H.BodyType_KINEMATIC?"KINEMATIC":""}},Xo=me();Xo.phys.BodyType=Rn;$l();var Qi=class v{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 v,H.internal=!1),H.MassMode_DEFAULT}static get FIXED(){return H.MassMode_FIXED==null&&(H.internal=!0,H.MassMode_FIXED=new v,H.internal=!1),H.MassMode_FIXED}toString(){return this===H.MassMode_DEFAULT?"DEFAULT":this===H.MassMode_FIXED?"FIXED":""}},Ho=me();Ho.phys.MassMode=Qi;var $i=class v{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 v,H.internal=!1),H.InertiaMode_DEFAULT}static get FIXED(){return H.InertiaMode_FIXED==null&&(H.internal=!0,H.InertiaMode_FIXED=new v,H.internal=!1),H.InertiaMode_FIXED}toString(){return this===H.InertiaMode_DEFAULT?"DEFAULT":this===H.InertiaMode_FIXED?"FIXED":""}},Qo=me();Qo.phys.InertiaMode=$i;var xi=class v{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 v,H.internal=!1),H.GravMassMode_DEFAULT}static get FIXED(){return H.GravMassMode_FIXED==null&&(H.internal=!0,H.GravMassMode_FIXED=new v,H.internal=!1),H.GravMassMode_FIXED}static get SCALED(){return H.GravMassMode_SCALED==null&&(H.internal=!0,H.GravMassMode_SCALED=new v,H.internal=!1),H.GravMassMode_SCALED}toString(){return this===H.GravMassMode_DEFAULT?"DEFAULT":this===H.GravMassMode_FIXED?"FIXED":this===H.GravMassMode_SCALED?"SCALED":""}},$o=me();$o.phys.GravMassMode=xi;var Zi=class v extends ni{constructor(e=50,t,n,s){super();let i=me(),l=new $n;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>qn.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 o=t.zpp_inner;o._validate!=null&&o._validate(),l.localCOMx=o.x,o._validate!=null&&o._validate(),l.localCOMy=o.y,o.weak&&t.dispose()}else l.localCOMx=0,l.localCOMy=0;n==null?Oe.zpp_pool!=null?(l.material=Oe.zpp_pool,Oe.zpp_pool=l.material.next,l.material.next=null):l.material=new Oe:(l.immutable_midstep("Shape::material"),l.setMaterial(n.zpp_inner),l.material.wrapper()),s==null?it.zpp_pool!=null?(l.filter=it.zpp_pool,it.zpp_pool=l.filter.next,l.filter.next=null):l.filter=new it:(l.immutable_midstep("Shape::filter"),l.setFilter(s.zpp_inner),l.filter.wrapper()),l.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof v?e:e instanceof $n?ke(e,t=>{let n=Object.create(v.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?v._wrap(e.zpp_inner_zn):ke(e,t=>{let n=Object.create(v.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>qn.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}};no(v=>Zi._wrap(v));var er=me();er.shape.Circle=Zi;var ki=class v extends ni{constructor(e,t,n){super();let s=me();if(e==null)throw new Error("Error: localVerts cannot be null");let i=new ei;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 Be))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 o=l.zpp_inner;o._validate!=null&&o._validate();let r=o.x;o._validate!=null&&o._validate();let a=o.y,p=new Be(r,a);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,o=l.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=s.geom.Vec2Iterator.zpp_pool,s.geom.Vec2Iterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let h=o.zpp_inner.at(o.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 m=u.y,d=new Be(x,m);i.wrap_lverts.push(d)}l.zpp_inner._validate!=null&&l.zpp_inner._validate();let r=l.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 s.geom.GeomPoly){let l=e.zpp_inner.vertices;if(l!=null){let o=l;do{i.wrap_lverts==null&&i.getlverts();let r=new Be(o.x,o.y);i.wrap_lverts.push(r),o=o.next}while(o!==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?Oe.zpp_pool!=null?(i.material=Oe.zpp_pool,Oe.zpp_pool=i.material.next,i.material.next=null):i.material=new Oe:(i.immutable_midstep("Shape::material"),i.setMaterial(t.zpp_inner),i.material.wrapper()),n==null?it.zpp_pool!=null?(i.filter=it.zpp_pool,it.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new it:(i.immutable_midstep("Shape::filter"),i.setFilter(n.zpp_inner),i.filter.wrapper()),i.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof v?e:e instanceof ei?ke(e,t=>{let n=Object.create(v.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?v._wrap(e.zpp_inner_zn):ke(e,t=>{let n=Object.create(v.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 Be(e,t);l.zpp_inner.weak=i;let o=new Be(e+n,t);o.zpp_inner.weak=i;let r=new Be(e+n,t+s);r.zpp_inner.weak=i;let a=new Be(e,t+s);return a.zpp_inner.weak=i,[l,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 v.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=[],o=Math.PI*2/n;for(let r=0;r<n;r++){let a=r*o+s,p=Math.cos(a)*e,c=Math.sin(a)*t,h=new Be(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()}};io(v=>ki._wrap(v));var tr=me();tr.shape.Polygon=ki;var Ei=class v extends ni{constructor(e=100,t=40,n,s,i){super();let l=me();if(e!==e||t!==t)throw new Error("Error: Capsule dimensions cannot be NaN");if(t<=0)throw new Error("Error: Capsule height ("+t+") must be > 0");if(e<t)throw new Error("Error: Capsule width ("+e+") must be >= height ("+t+")");let o=t/2,r=(e-t)/2,a=new ti;if(this.zpp_inner_zn=a,this.zpp_inner=a,this.zpp_inner_i=a,a.outer=this,a.outer_zn=this,a.outer_i=this,this._inner=this,o<l.Config.epsilon)throw new Error("Error: Capsule radius ("+o+") must be > Config.epsilon");if(o>qn.FMAX)throw new Error("Error: Capsule radius ("+o+") must be < PR(Const).FMAX");if(a.radius=o,a.halfLength=r,a.invalidate_radius(),r>0&&a.invalidate_halfLength(),n!=null){if(n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=n.zpp_inner;p._validate!=null&&p._validate(),a.localCOMx=p.x,p._validate!=null&&p._validate(),a.localCOMy=p.y,p.weak&&n.dispose()}else a.localCOMx=0,a.localCOMy=0;s==null?Oe.zpp_pool!=null?(a.material=Oe.zpp_pool,Oe.zpp_pool=a.material.next,a.material.next=null):a.material=new Oe:(a.immutable_midstep("Shape::material"),a.setMaterial(s.zpp_inner),a.material.wrapper()),i==null?it.zpp_pool!=null?(a.filter=it.zpp_pool,it.zpp_pool=a.filter.next,a.filter.next=null):a.filter=new it:(a.immutable_midstep("Shape::filter"),a.setFilter(i.zpp_inner),a.filter.wrapper()),a.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof v?e:e instanceof ti?ke(e,t=>{let n=Object.create(v.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?v._wrap(e.zpp_inner_zn):ke(e,t=>{let n=Object.create(v.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("Capsule::radius"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modify radius of Capsule contained in static object once added to space");if(e!==t.radius){if(e!==e)throw new Error("Error: Capsule::radius cannot be NaN");if(e<n.Config.epsilon)throw new Error("Error: Capsule::radius ("+e+") must be > Config.epsilon");if(e>qn.FMAX)throw new Error("Error: Capsule::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}get halfLength(){return this.zpp_inner_zn.halfLength}set halfLength(e){let t=this.zpp_inner_zn;if(this.zpp_inner.immutable_midstep("Capsule::halfLength"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modify halfLength of Capsule contained in static object once added to space");if(e!==t.halfLength){if(e!==e)throw new Error("Error: Capsule::halfLength cannot be NaN");if(e<0)throw new Error("Error: Capsule::halfLength ("+e+") must be >= 0");t.halfLength=e,t.invalidate_halfLength()}}get width(){return 2*(this.zpp_inner_zn.halfLength+this.zpp_inner_zn.radius)}get height(){return 2*this.zpp_inner_zn.radius}};so(v=>Ei._wrap(v));var nr=me();nr.shape.Capsule=Ei;var es=class v{get _inner(){return this}constructor(e=0,t=1,n=2,s=1,i=.001){let l;if(Oe.zpp_pool==null?l=new Oe:(l=Oe.zpp_pool,Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.ANGDRAG|Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.ARBITERS)}}static _wrap(e){return e instanceof v?e:e?e instanceof Oe?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.ANGDRAG|Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.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(Oe.WAKE|Oe.ARBITERS)}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}copy(){let e=new v(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 v(.4,.2,.38,.7,.005)}static steel(){return new v(.2,.57,.74,7.8,.001)}static ice(){return new v(.3,.03,.1,.9,1e-4)}static rubber(){return new v(.8,1,1.4,1.5,.01)}static glass(){return new v(.4,.4,.94,2.6,.002)}static sand(){return new v(-1,.45,.6,1.6,16)}};Oe._wrapFn=v=>ke(v,e=>{let t=Object.create(es.prototype);return t.zpp_inner=e,e.outer=t,t});var ts=class v{get _inner(){return this}constructor(e=1,t=-1,n=1,s=-1,i=1,l=-1){let o;it.zpp_pool==null?o=new it:(o=it.zpp_pool,it.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!=s&&(o.sensorMask=s,o.invalidate()),o.fluidGroup!=i&&(o.fluidGroup=i,o.invalidate()),o.fluidMask!=l&&(o.fluidMask=l,o.invalidate())}static _wrap(e){return e instanceof v?e:e?e instanceof it?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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 v(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)+" }"}};it._wrapFn=v=>ke(v,e=>{let t=Object.create(ts.prototype);return t.zpp_inner=e,e.outer=t,t});var Ni=class v{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 v,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 v,H.internal=!1),H.Broadphase_SWEEP_AND_PRUNE}static get SPATIAL_HASH(){return H.Broadphase_SPATIAL_HASH==null&&(H.internal=!0,H.Broadphase_SPATIAL_HASH=new v,H.internal=!1),H.Broadphase_SPATIAL_HASH}toString(){return this===H.Broadphase_DYNAMIC_AABB_TREE?"DYNAMIC_AABB_TREE":this===H.Broadphase_SWEEP_AND_PRUNE?"SWEEP_AND_PRUNE":this===H.Broadphase_SPATIAL_HASH?"SPATIAL_HASH":""}};var ns=class ns{constructor(){this.debugDraw=!0;this._inner=this}static _wrap(e){return e==null?null:e instanceof ns?e:e.zpp_inner?.outer instanceof ns?e.zpp_inner.outer:ke(e,t=>{let n=Object.create(ns.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 ns._wrap(this.zpp_inner.copy())}toString(){return"{Constraint}"}};ns.zpp_internalAlloc=!1;var ln=ns;function ro(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 ao(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 kl(v){v.zpp_inner.weak&&v.dispose()}var is=class v extends ln{constructor(e,t,n,s){super();let i=new fi;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=ro(n),i.a1localy=ao(n),kl(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=ro(s),i.a2localy=ao(s),kl(s)}static _wrap(e){return e==null?null:e instanceof v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof fi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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),kl(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),kl(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}};fi._wrapFn=v=>ke(v,e=>{let t=Object.create(is.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function po(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 co(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 El(v){v.zpp_inner.weak&&v.dispose()}var ss=class v extends ln{constructor(e,t,n,s,i,l){super();let o=new yi;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=po(n),a=co(n);if(o.a1localx=r,o.a1localy=a,El(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=po(s),c=co(s);if(o.a2localx=p,o.a2localy=c,El(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(o.jointMin!=i&&(o.jointMin=i,o.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");o.jointMax!=l&&(o.jointMax=l,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 yi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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),El(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),El(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}};yi._wrapFn=v=>ke(v,e=>{let t=Object.create(ss.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var ls=class v extends ln{constructor(e,t,n,s,i=1){super();let l=new qe;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 v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof qe?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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}};qe._wrapFn=v=>ke(v,e=>{let t=Object.create(ls.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var os=class v extends ln{constructor(e,t,n=0,s=1){super();let i=new bi;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 v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof bi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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}};bi._wrapFn=v=>ke(v,e=>{let t=Object.create(os.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Gl(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 Ns(v){v.zpp_inner.weak&&v.dispose()}var rs=class v extends ln{constructor(e,t,n,s,i,l,o){super();let r=new mi;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=Gl(n),r.a1localy=ql(n),Ns(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(r.a2localx=Gl(s),r.a2localy=ql(s),Ns(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(r.nlocalx=Gl(i),r.nlocaly=ql(i),r.zip_n=!0,Ns(i),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),l!==l)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(r.jointMin!=l&&(r.jointMin=l,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 mi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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),Ns(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),Ns(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),Ns(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}};mi._wrapFn=v=>ke(v,e=>{let t=Object.create(rs.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var nl=class v{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 v?e:e?e instanceof Gi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?v._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 v(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 v(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 v(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 o=0;o<this.zpp_inner.n;o++)l+=this.zpp_inner.x[s*this.zpp_inner.n+o]*t.zpp_inner.x[o*t.zpp_inner.n+i];n.zpp_inner.x[s*n.zpp_inner.n+i]=l}return n}},ir=me();ir.geom.MatMN=nl;function il(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 sl(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 as=class v extends ln{constructor(e,t,n,s,i,l,o,r,a,p,c=1){super();let h=new zi;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(o,"anchor3",(u,x)=>{h.a3localx=u,h.a3localy=x}),this._setAnchorInit(r,"anchor4",(u,x)=>{h.a4localx=u,h.a4localy=x}),h.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(h.jointMin!=a&&(h.jointMin=a,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(il(e),sl(e)),ll(e)}static _wrap(e){return e==null?null:e instanceof v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof zi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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(),il(e),sl(e),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(),il(e),sl(e),this.zpp_inner.wrap_a2.set(e),ll(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(),il(e),sl(e),this.zpp_inner.wrap_a3.set(e),ll(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(),il(e),sl(e),this.zpp_inner.wrap_a4.set(e),ll(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 nl(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):ui.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}};zi._wrapFn=v=>ke(v,e=>{let t=Object.create(as.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function ho(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 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.y}function Nl(v){v.zpp_inner.weak&&v.dispose()}var ps=class v extends ln{constructor(e,t,n,s,i=0){super();let l=new Pi;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=ho(n),l.a1localy=uo(n),Nl(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=ho(s),l.a2localy=uo(s),Nl(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 v?e:e.zpp_inner?.outer instanceof v?e.zpp_inner.outer:e instanceof Pi?ke(e,t=>{let n=Object.create(v.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ke(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: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),Nl(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),Nl(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}};Pi._wrapFn=v=>ke(v,e=>{let t=Object.create(ps.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var si=class v extends Ci{constructor(){super();let e=new Wn;this.zpp_inner=e,e.outer=this,e.outer_i=this,this.zpp_inner_i=e,this._inner=this,e.insert_cbtype(pn.ANY_COMPOUND.zpp_inner)}static _wrap(e){return e?e instanceof v?e:e instanceof Wn?ke(e,t=>{let n=Object.create(v.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?v._wrap(e.zpp_inner):ke(e,t=>{let n=Object.create(v.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:ii._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 Be(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 o=s.zpp_inner.cmass;t.addeq(l.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(s=>{s.rotate(e,t)}),e.zpp_inner.weak=n,e.zpp_inner.weak&&e.dispose(),this}toString(){return"Compound"+this.zpp_inner.id}};Wn._wrapFn=v=>ke(v,e=>{let t=Object.create(si.prototype);return t.zpp_inner=e,e.outer=t,e.outer_i=t,t.zpp_inner_i=e,t._inner=t,t});Object.defineProperty(si.prototype,"bodies",{get:function(){return this.zpp_inner.wrap_bodies},configurable:!0});Object.defineProperty(si.prototype,"constraints",{get:function(){return this.zpp_inner.wrap_constraints},configurable:!0});Object.defineProperty(si.prototype,"compounds",{get:function(){return this.zpp_inner.wrap_compounds},configurable:!0});function Oi(v){return Be.get(v.x,v.y)}function un(v){return Be.weak(v.x,v.y)}function sr(v){return new es(v.elasticity,v.dynamicFriction,v.staticFriction,v.density,v.rollingFriction)}function lr(v){let e=new ts;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 or(v){let e=new On(v.density,v.viscosity);return v.gravity!=null&&(e.gravity=Oi(v.gravity)),e}function rr(v){let e=sr(v.material),t=lr(v.filter),n;if(v.type==="circle"){let s=Oi(v.localCOM);n=new Zi(v.radius,s,e,t)}else if(v.type==="capsule"){let s=Oi(v.localCOM);n=new Ei(v.width,v.height,s,e,t)}else{let s=v.localVerts.map(i=>Oi(i));n=new ki(s,e,t)}return n.sensorEnabled=v.sensorEnabled,n.fluidEnabled=v.fluidEnabled,v.fluidEnabled&&v.fluidProperties!=null&&(n.fluidProperties=or(v.fluidProperties)),n}function ar(v){let e=v.type==="STATIC"?Rn.STATIC:v.type==="KINEMATIC"?Rn.KINEMATIC:Rn.DYNAMIC,t=new We(e,un(v.position));t.rotation=v.rotation,v.type!=="STATIC"&&(t.velocity=Oi(v.velocity),t.angularVel=v.angularVel),t.kinematicVel=Oi(v.kinematicVel),t.kinAngVel=v.kinAngVel,t.surfaceVel=Oi(v.surfaceVel),v.type==="DYNAMIC"&&(t.force=Oi(v.force),t.torque=v.torque),v.massMode==="FIXED"&&v.mass!=null?t.mass=v.mass:v.massMode==="DEFAULT"&&(t.massMode=Qi.DEFAULT),v.inertiaMode==="FIXED"&&v.inertia!=null?t.inertia=v.inertia:v.inertiaMode==="DEFAULT"&&(t.inertiaMode=$i.DEFAULT),v.gravMassMode==="SCALED"?(t.gravMassMode=xi.SCALED,t.gravMassScale=v.gravMassScale):v.gravMassMode==="FIXED"&&(t.gravMassMode=xi.FIXED),t.allowMovement=v.allowMovement,t.allowRotation=v.allowRotation,t.isBullet=v.bullet;for(let n of v.shapes)rr(n).body=t;return v.userData!=null&&Object.assign(t.userData,v.userData),t}function cs(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 pr(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 s=new is(t,n,un(v.anchor1),un(v.anchor2));return cs(s,v),s}case"DistanceJoint":{let s=new ss(t,n,un(v.anchor1),un(v.anchor2),v.jointMin,v.jointMax);return cs(s,v),s}case"AngleJoint":{let s=new ls(t,n,v.jointMin,v.jointMax,v.ratio);return cs(s,v),s}case"MotorJoint":{let s=new os(t,n,v.rate,v.ratio);return cs(s,v),s}case"LineJoint":{let s=new rs(t,n,un(v.anchor1),un(v.anchor2),un(v.direction),v.jointMin,v.jointMax);return cs(s,v),s}case"PulleyJoint":{let s=new as(t,n,null,null,un(v.anchor1),un(v.anchor2),un(v.anchor3),un(v.anchor4),v.jointMin,v.jointMax,v.ratio);return cs(s,v),s}case"WeldJoint":{let s=new ps(t,n,un(v.anchor1),un(v.anchor2),v.phase);return cs(s,v),s}}}function xo(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"?Ni.SWEEP_AND_PRUNE:Ni.DYNAMIC_AABB_TREE,t=new ii(un(v.gravity),e);t.worldLinearDrag=v.worldLinearDrag,t.worldAngularDrag=v.worldAngularDrag,t.sortContacts=v.sortContacts,t.deterministic=v.deterministic??!1;let n=v.bodies.map(ar),s=v.constraints.map(o=>pr(o,n)),i=new Set,l=new Set;for(let o of v.compounds){let r=new si;for(let a of o.bodyIds)n[a].compound=r,i.add(a);for(let a of o.constraintIndices)s[a].compound=r,l.add(a);r.space=t}for(let o=0;o<n.length;o++)i.has(o)||(n[o].space=t);for(let o=0;o<s.length;o++)l.has(o)||(s[o].space=t);return t}var Ol=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 cr=1312903237,Os=2,hr=0,ur=1,xr=2,dr=3,_r=4,yr=5,mr=6;function br(v,e){v.writeFloat64(e.elasticity),v.writeFloat64(e.dynamicFriction),v.writeFloat64(e.staticFriction),v.writeFloat64(e.density),v.writeFloat64(e.rollingFriction)}function fr(v,e){v.writeInt32(e.collisionGroup),v.writeInt32(e.collisionMask),v.writeInt32(e.sensorGroup),v.writeInt32(e.sensorMask),v.writeInt32(e.fluidGroup),v.writeInt32(e.fluidMask)}function zr(v,e){if(e==null)return;v.writeFloat64(e.density),v.writeFloat64(e.viscosity);let t=e.gravity;v.writeBool(t!=null),t!=null&&(v.writeFloat64(t.x),v.writeFloat64(t.y))}function Pr(v,e){if(e.isCircle()){v.writeUint8(0);let i=e;v.writeFloat64(i.radius);let l=e.localCOM;v.writeFloat64(l.x),v.writeFloat64(l.y)}else if(e.isCapsule()){v.writeUint8(2);let i=e;v.writeFloat64(i.width),v.writeFloat64(i.height);let l=e.localCOM;v.writeFloat64(l.x),v.writeFloat64(l.y)}else{v.writeUint8(1);let l=e.localVerts,o=l.length;v.writeUint16(o);for(let r=0;r<o;r++){let a=l.at(r);v.writeFloat64(a.x),v.writeFloat64(a.y)}}br(v,e.material),fr(v,e.filter);let t=e.fluidEnabled,n=t&&e.fluidProperties!=null,s=(e.sensorEnabled?1:0)|(t?2:0)|(n?4:0);v.writeUint8(s),n&&zr(v,e.fluidProperties)}function wr(v,e){let t=e.zpp_inner;v.writeUint8(t.type),v.writeFloat64(e.position.x),v.writeFloat64(e.position.y),v.writeFloat64(e.rotation),v.writeFloat64(e.velocity.x),v.writeFloat64(e.velocity.y),v.writeFloat64(e.angularVel),v.writeFloat64(e.kinematicVel.x),v.writeFloat64(e.kinematicVel.y),v.writeFloat64(e.kinAngVel),v.writeFloat64(e.surfaceVel.x),v.writeFloat64(e.surfaceVel.y),v.writeFloat64(e.force.x),v.writeFloat64(e.force.y),v.writeFloat64(t.type===2?e.torque:0),v.writeUint8(t.massMode),v.writeFloat64(t.massMode===1?t.cmass:0),v.writeUint8(t.inertiaMode),v.writeFloat64(t.inertiaMode===1?t.cinertia:0),v.writeUint8(t.gravMassMode),v.writeFloat64(t.gravMassScale);let n=(e.allowMovement?1:0)|(e.allowRotation?2:0)|(e.isBullet?4:0);v.writeUint8(n);let s=e.shapes,i=s.length;v.writeUint16(i);for(let l=0;l<i;l++)Pr(v,s.at(l))}var _o={PivotJoint:hr,DistanceJoint:ur,AngleJoint:xr,MotorJoint:dr,LineJoint:_r,PulleyJoint:yr,WeldJoint:mr};function hs(v,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;v.writeInt32(i),v.writeInt32(l);let o=e.zpp_inner,r=(o.active?1:0)|(o.ignore?2:0)|(o.stiff?4:0)|(o.breakUnderForce?8:0)|(o.breakUnderError?16:0)|(o.removeOnBreak?32:0);v.writeUint8(r),v.writeFloat64(o.frequency),v.writeFloat64(o.damping),v.writeFloat64(o.maxForce),v.writeFloat64(o.maxError)}function vr(v,e,t){let n=e.constructor?.name??"",s=_o[n];if(s===void 0)return!1;switch(v.writeUint8(s),n){case"PivotJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y);break}case"DistanceJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y),v.writeFloat64(i.jointMin),v.writeFloat64(i.jointMax);break}case"AngleJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.jointMin),v.writeFloat64(i.jointMax),v.writeFloat64(i.ratio);break}case"MotorJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.rate),v.writeFloat64(i.ratio);break}case"LineJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y),v.writeFloat64(i.direction.x),v.writeFloat64(i.direction.y),v.writeFloat64(i.jointMin),v.writeFloat64(i.jointMax);break}case"PulleyJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y),v.writeFloat64(i.anchor3.x),v.writeFloat64(i.anchor3.y),v.writeFloat64(i.anchor4.x),v.writeFloat64(i.anchor4.y),v.writeFloat64(i.jointMin),v.writeFloat64(i.jointMax),v.writeFloat64(i.ratio);break}case"WeldJoint":{let i=e;hs(v,e,t,i.body1,i.body2),v.writeFloat64(i.anchor1.x),v.writeFloat64(i.anchor1.y),v.writeFloat64(i.anchor2.x),v.writeFloat64(i.anchor2.y),v.writeFloat64(i.phase);break}}return!0}function yo(v){let e=new Ol,t=[],n=new Map,s=new Map;function i(d){let y=d.zpp_inner.id;if(n.has(y))return;let f=t.length;s.set(d,f),n.set(y,f),t.push(d)}let l=v.bodies,o=l.length;for(let d=0;d<o;d++)i(l.at(d));let r=v.compounds,a=r.length;for(let d=0;d<a;d++){let f=r.at(d).bodies,b=f.length;for(let P=0;P<b;P++)i(f.at(P))}let p=[],c=new Map;function h(d){if(c.has(d))return;let y=d.constructor?.name??"";_o[y]!==void 0&&(c.set(d,p.length),p.push(d))}let u=v.constraints,x=u.length;for(let d=0;d<x;d++)h(u.at(d));for(let d=0;d<a;d++){let f=r.at(d).constraints,b=f.length;for(let P=0;P<b;P++)h(f.at(P))}e.writeUint32(cr),e.writeUint16(Os),e.writeUint32(t.length),e.writeUint32(p.length),e.writeUint32(a);let m=v.gravity;e.writeFloat64(m.x),e.writeFloat64(m.y),e.writeFloat64(v.worldLinearDrag),e.writeFloat64(v.worldAngularDrag),e.writeBool(v.sortContacts),e.writeBool(v.deterministic),e.writeUint8(v.zpp_inner.bphase.is_sweep?0:1);for(let d=0;d<t.length;d++)wr(e,t[d]);for(let d=0;d<p.length;d++)vr(e,p[d],n);for(let d=0;d<a;d++){let y=r.at(d),f=y.bodies,b=f.length;e.writeUint16(b);for(let z=0;z<b;z++){let C=f.at(z),w=s.get(C)??0;e.writeUint32(w)}let P=y.constraints,k=P.length,_=0;for(let z=0;z<k;z++){let C=P.at(z);c.has(C)&&_++}e.writeUint16(_);for(let z=0;z<k;z++){let C=P.at(z),w=c.get(C);w!=null&&e.writeUint32(w)}e.writeUint16(0)}return e.finish()}var Sl=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 mo=1312903237,gr=0,Cr=1,Mr=2,Zr=3,kr=4,Er=5,Nr=6,Or={1:Rn.STATIC,2:Rn.DYNAMIC,3:Rn.KINEMATIC};function Jl(v){let e=v.readFloat64(),t=v.readFloat64(),n=v.readFloat64(),s=v.readFloat64(),i=v.readFloat64();return new es(e,t,n,s,i)}function Ul(v){let e=new ts;return e.collisionGroup=v.readInt32(),e.collisionMask=v.readInt32(),e.sensorGroup=v.readInt32(),e.sensorMask=v.readInt32(),e.fluidGroup=v.readInt32(),e.fluidMask=v.readInt32(),e}function Sr(v){let e=v.readFloat64(),t=v.readFloat64(),n=new On(e,t);return v.readBool()&&(n.gravity=Be.get(v.readFloat64(),v.readFloat64())),n}function Ar(v){let e=v.readUint8(),t;if(e===0){let i=v.readFloat64(),l=v.readFloat64(),o=v.readFloat64(),r=Jl(v),a=Ul(v);t=new Zi(i,Be.weak(l,o),r,a)}else if(e===2){let i=v.readFloat64(),l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=Jl(v),p=Ul(v);t=new Ei(i,l,Be.weak(o,r),a,p)}else{let i=v.readUint16(),l=[];for(let a=0;a<i;a++)l.push(Be.get(v.readFloat64(),v.readFloat64()));let o=Jl(v),r=Ul(v);t=new ki(l,o,r)}let n=v.readUint8();return t.sensorEnabled=(n&1)!==0,t.fluidEnabled=(n&2)!==0,(n&4)!==0&&(t.fluidProperties=Sr(v)),t}function Vr(v){let e=v.readUint8(),t=Or[e]??Rn.DYNAMIC,n=v.readFloat64(),s=v.readFloat64(),i=v.readFloat64(),l=new We(t,Be.weak(n,s));l.rotation=i;let o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64();e!==1&&(l.velocity=Be.get(o,r),l.angularVel=a),l.kinematicVel=Be.get(v.readFloat64(),v.readFloat64()),l.kinAngVel=v.readFloat64(),l.surfaceVel=Be.get(v.readFloat64(),v.readFloat64());let p=v.readFloat64(),c=v.readFloat64(),h=v.readFloat64();e===2&&(l.force=Be.get(p,c),l.torque=h);let u=v.readUint8(),x=v.readFloat64();u===1&&x!==0?l.mass=x:u===0&&(l.massMode=Qi.DEFAULT);let m=v.readUint8(),d=v.readFloat64();m===1&&d!==0?l.inertia=d:m===0&&(l.inertiaMode=$i.DEFAULT);let y=v.readUint8(),f=v.readFloat64();y===2?(l.gravMassMode=xi.SCALED,l.gravMassScale=f):y===1&&(l.gravMassMode=xi.FIXED);let b=v.readUint8();l.allowMovement=(b&1)!==0,l.allowRotation=(b&2)!==0,l.isBullet=(b&4)!==0;let P=v.readUint16();for(let k=0;k<P;k++)Ar(v).body=l;return l}function Ir(v){let e=v.readInt32(),t=v.readInt32(),n=v.readUint8(),s=v.readFloat64(),i=v.readFloat64(),l=v.readFloat64(),o=v.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:o}}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}function Br(v,e){let t=v.readUint8(),n=Ir(v),s=n.body1Id>=0?e[n.body1Id]??null:null,i=n.body2Id>=0?e[n.body2Id]??null:null;switch(t){case gr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=new is(s,i,Be.weak(l,o),Be.weak(r,a));return us(p,n),p}case Cr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=v.readFloat64(),c=v.readFloat64(),h=new ss(s,i,Be.weak(l,o),Be.weak(r,a),p,c);return us(h,n),h}case Mr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=new ls(s,i,l,o,r);return us(a,n),a}case Zr:{let l=v.readFloat64(),o=v.readFloat64(),r=new os(s,i,l,o);return us(r,n),r}case kr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=v.readFloat64(),c=v.readFloat64(),h=v.readFloat64(),u=v.readFloat64(),x=new rs(s,i,Be.weak(l,o),Be.weak(r,a),Be.weak(p,c),h,u);return us(x,n),x}case Er:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=v.readFloat64(),c=v.readFloat64(),h=v.readFloat64(),u=v.readFloat64(),x=v.readFloat64(),m=v.readFloat64(),d=v.readFloat64(),y=new as(s,i,null,null,Be.weak(l,o),Be.weak(r,a),Be.weak(p,c),Be.weak(h,u),x,m,d);return us(y,n),y}case Nr:{let l=v.readFloat64(),o=v.readFloat64(),r=v.readFloat64(),a=v.readFloat64(),p=v.readFloat64(),c=new ps(s,i,Be.weak(l,o),Be.weak(r,a),p);return us(c,n),c}default:throw new Error(`nape-js binary: unknown constraint type tag ${t}`)}}function bo(v){let e=new Sl(v),t=e.readUint32();if(t!==mo)throw new Error(`nape-js binary: invalid magic bytes 0x${t.toString(16)} (expected 0x${mo.toString(16)})`);let n=e.readUint16();if(n!==Os)throw new Error(`nape-js binary: unsupported version ${n} (expected ${Os})`);let s=e.readUint32(),i=e.readUint32(),l=e.readUint32(),o=e.readFloat64(),r=e.readFloat64(),a=e.readFloat64(),p=e.readFloat64(),c=e.readBool(),h=e.readBool(),x=e.readUint8()===0?Ni.SWEEP_AND_PRUNE:Ni.DYNAMIC_AABB_TREE,m=new ii(Be.weak(o,r),x);m.worldLinearDrag=a,m.worldAngularDrag=p,m.sortContacts=c,m.deterministic=h;let d=new Array(s);for(let P=0;P<s;P++)d[P]=Vr(e);let y=new Array(i);for(let P=0;P<i;P++)y[P]=Br(e,d);let f=new Set,b=new Set;for(let P=0;P<l;P++){let k=new si,_=e.readUint16();for(let w=0;w<_;w++){let g=e.readUint32();d[g].compound=k,f.add(g)}let z=e.readUint16();for(let w=0;w<z;w++){let g=e.readUint32();y[g].compound=k,b.add(g)}let C=e.readUint16();for(let w=0;w<C;w++)e.readUint32();k.space=m}for(let P=0;P<s;P++)f.has(P)||(d[P].space=m);for(let P=0;P<i;P++)b.has(P)||(y[P].space=m);return m}0&&(module.exports={BINARY_SNAPSHOT_VERSION,SNAPSHOT_VERSION,spaceFromBinary,spaceFromJSON,spaceToBinary,spaceToJSON});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|