@newkrok/nape-js 3.19.0 → 3.21.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/chunk-KHH45HMB.cjs +2 -0
- package/dist/chunk-SNMC46IS.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/serialization/index.cjs +1 -1
- package/dist/serialization/index.js +1 -1
- package/dist/worker/index.cjs +4 -3
- package/dist/worker/index.js +3 -2
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Tr=Object.defineProperty;var xo=Object.getOwnPropertyDescriptor;var yo=Object.getOwnPropertyNames;var mo=Object.prototype.hasOwnProperty;var fo=(w,e)=>{for(var t in e)Tr(w,t,{get:e[t],enumerable:!0})},bo=(w,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of yo(e))!mo.call(w,s)&&s!==t&&Tr(w,s,{get:()=>e[s],enumerable:!(n=xo(e,s))||n.enumerable});return w};var zo=w=>bo(Tr({},"__esModule",{value:!0}),w);var ra={};fo(ra,{AABB:()=>Kn,AngleJoint:()=>Xs,Arbiter:()=>wi,ArbiterType:()=>qs,Body:()=>Ke,BodyCallback:()=>Il,BodyListener:()=>jl,BodyType:()=>bi,Broadphase:()=>Sl,Callback:()=>Tn,Capsule:()=>os,CbEvent:()=>_t,CbType:()=>Js,CharacterController:()=>Sr,Circle:()=>rs,CollisionArbiter:()=>Al,Compound:()=>zi,Constraint:()=>kt,ConstraintCallback:()=>Tl,ConstraintListener:()=>Dl,Contact:()=>Ws,ConvexResult:()=>Ss,DebugDraw:()=>Or,DebugDrawFlags:()=>Bi,DistanceJoint:()=>Qs,Edge:()=>Fs,FluidArbiter:()=>Vl,FluidProperties:()=>Yn,Geom:()=>El,GeomPoly:()=>Ii,GravMassMode:()=>Ls,InertiaMode:()=>js,InteractionCallback:()=>Bl,InteractionFilter:()=>Hi,InteractionGroup:()=>Gs,InteractionListener:()=>Fl,InteractionType:()=>hn,Interactor:()=>oi,LineJoint:()=>$s,Listener:()=>In,ListenerType:()=>Ks,MarchingSquares:()=>kl,MassMode:()=>Ds,Mat23:()=>Ns,MatMN:()=>yi,Material:()=>Bs,MotorJoint:()=>el,NapeList:()=>Nl,OptionType:()=>Us,PivotJoint:()=>tl,Polygon:()=>Pi,PreCallback:()=>Ll,PreFlag:()=>ci,PreListener:()=>as,PulleyJoint:()=>nl,Ray:()=>Ai,RayResult:()=>As,Shape:()=>Mn,ShapeType:()=>Yi,Space:()=>ai,UserConstraint:()=>Gl,VERSION:()=>la,ValidationResult:()=>Rs,Vec2:()=>Se,Vec3:()=>Xe,WeldJoint:()=>il,Winding:()=>Os,createConcaveBody:()=>_o});module.exports=zo(ra);var Xi=class{static POSINF(){return 1/0}static NEGINF(){return-1/0}};Xi.FMAX=1e100;var Tt=class Tt{static Constraint(){return Tt._Constraint++}static Interactor(){return Tt._Interactor++}static CbType(){return Tt._CbType++}static CbSet(){return Tt._CbSet++}static Listener(){return Tt._Listener++}static ZPP_SimpleVert(){return Tt._ZPP_SimpleVert++}static ZPP_SimpleSeg(){return Tt._ZPP_SimpleSeg++}static Space(){return Tt._Space++}static InteractionGroup(){return Tt._InteractionGroup++}};Tt._Constraint=0,Tt._Interactor=0,Tt._CbType=0,Tt._CbSet=0,Tt._Listener=0,Tt._ZPP_SimpleVert=0,Tt._ZPP_SimpleSeg=0,Tt._Space=0,Tt._InteractionGroup=0;var On=Tt;var I=class{};I.GravMassMode_DEFAULT=null,I.GravMassMode_FIXED=null,I.GravMassMode_SCALED=null,I.InertiaMode_DEFAULT=null,I.InertiaMode_FIXED=null,I.MassMode_DEFAULT=null,I.MassMode_FIXED=null,I.BodyType_STATIC=null,I.BodyType_DYNAMIC=null,I.BodyType_KINEMATIC=null,I.ListenerType_BODY=null,I.ListenerType_CONSTRAINT=null,I.ListenerType_INTERACTION=null,I.ListenerType_PRE=null,I.PreFlag_ACCEPT=null,I.PreFlag_IGNORE=null,I.PreFlag_ACCEPT_ONCE=null,I.PreFlag_IGNORE_ONCE=null,I.CbEvent_BEGIN=null,I.CbEvent_ONGOING=null,I.CbEvent_END=null,I.CbEvent_WAKE=null,I.CbEvent_SLEEP=null,I.CbEvent_BREAK=null,I.CbEvent_PRE=null,I.InteractionType_COLLISION=null,I.InteractionType_SENSOR=null,I.InteractionType_FLUID=null,I.InteractionType_ANY=null,I.Winding_UNDEFINED=null,I.Winding_CLOCKWISE=null,I.Winding_ANTICLOCKWISE=null,I.ValidationResult_VALID=null,I.ValidationResult_DEGENERATE=null,I.ValidationResult_CONCAVE=null,I.ValidationResult_SELF_INTERSECTING=null,I.ShapeType_CIRCLE=null,I.ShapeType_POLYGON=null,I.ShapeType_CAPSULE=null,I.Broadphase_DYNAMIC_AABB_TREE=null,I.Broadphase_SWEEP_AND_PRUNE=null,I.Broadphase_SPATIAL_HASH=null,I.ArbiterType_COLLISION=null,I.ArbiterType_SENSOR=null,I.ArbiterType_FLUID=null,I.internal=!1,I.id_ImmState_ACCEPT=1,I.id_ImmState_IGNORE=2,I.id_ImmState_ALWAYS=4,I.id_GravMassMode_DEFAULT=0,I.id_GravMassMode_FIXED=1,I.id_GravMassMode_SCALED=2,I.id_InertiaMode_DEFAULT=0,I.id_InertiaMode_FIXED=1,I.id_MassMode_DEFAULT=0,I.id_MassMode_FIXED=1,I.id_BodyType_STATIC=1,I.id_BodyType_DYNAMIC=2,I.id_BodyType_KINEMATIC=3,I.id_ListenerType_BODY=0,I.id_ListenerType_CONSTRAINT=1,I.id_ListenerType_INTERACTION=2,I.id_ListenerType_PRE=3,I.id_PreFlag_ACCEPT=1,I.id_PreFlag_IGNORE=2,I.id_PreFlag_ACCEPT_ONCE=3,I.id_PreFlag_IGNORE_ONCE=4,I.id_CbEvent_BEGIN=0,I.id_CbEvent_END=1,I.id_CbEvent_WAKE=2,I.id_CbEvent_SLEEP=3,I.id_CbEvent_BREAK=4,I.id_CbEvent_PRE=5,I.id_CbEvent_ONGOING=6,I.id_InteractionType_COLLISION=1,I.id_InteractionType_SENSOR=2,I.id_InteractionType_FLUID=4,I.id_InteractionType_ANY=7,I.id_Winding_UNDEFINED=0,I.id_Winding_CLOCKWISE=1,I.id_Winding_ANTICLOCKWISE=2,I.id_ValidationResult_VALID=0,I.id_ValidationResult_DEGENERATE=1,I.id_ValidationResult_CONCAVE=2,I.id_ValidationResult_SELF_INTERSECTING=3,I.id_ShapeType_CIRCLE=0,I.id_ShapeType_POLYGON=1,I.id_ShapeType_CAPSULE=2,I.id_Broadphase_DYNAMIC_AABB_TREE=0,I.id_Broadphase_SWEEP_AND_PRUNE=1,I.id_Broadphase_SPATIAL_HASH=2,I.id_ArbiterType_COLLISION=1,I.id_ArbiterType_SENSOR=2,I.id_ArbiterType_FLUID=4;var fr=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 ue=class{};ue.poolGeomPoly=null,ue.nextGeomPoly=null,ue.poolVec2=null,ue.nextVec2=null,ue.poolVec3=null,ue.nextVec3=null;var ql=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}},rl=class extends ql{},ol=class extends ql{},al=class extends ql{};var Dn=class Dn{constructor(){this.value=!1;this.next=null;this.hnext=null;this.id=0;this.di=0}static _alloc(){if(Dn.zpp_pool==null)return new Dn;let e=Dn.zpp_pool;return Dn.zpp_pool=e.next,e.next=null,e}static get(e,t,n){let s=Dn._alloc();return s.id=e,s.di=t,s.value=n,s}static getpersist(e,t){let n=Dn._alloc();return n.id=e,n.di=t,n}static ordered_get(e,t,n){if(e<=t){let s=Dn._alloc();return s.id=e,s.di=t,s.value=n,s}else{let s=Dn._alloc();return s.id=t,s.di=e,s.value=n,s}}static ordered_get_persist(e,t){if(e<=t){let n=Dn._alloc();return n.id=e,n.di=t,n}else{let n=Dn._alloc();return n.id=t,n.di=e,n}}free(){}alloc(){}};Dn.zpp_pool=null;var De=Dn;var Po=1048576,_s=1048575,xs=106039,ds=class{constructor(){this.cnt=0;this.cnt=0,this.table=new Array(Po).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*xs+t&_s];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*xs+t&_s];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*xs+t&_s];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*xs+e.di&_s,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*xs+e.di&_s,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*xs+e.di&_s,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*xs+t&_s}};var Wl=class{constructor(){this.elt=null;this.next=null}alloc(){}free(){this.elt=null}elem(){return this.elt}};Wl.zpp_pool=null;var vt=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}};vt.prototype.inlined_add=vt.prototype.add;vt.prototype.inlined_insert=vt.prototype.insert;vt.prototype.inlined_pop=vt.prototype.pop;vt.prototype.inlined_pop_unsafe=vt.prototype.pop_unsafe;vt.prototype.inlined_erase=vt.prototype.erase;vt.prototype.inlined_remove=vt.prototype.remove;vt.prototype.inlined_try_remove=vt.prototype.try_remove;vt.prototype.inlined_clear=vt.prototype.clear;vt.prototype.inlined_has=vt.prototype.has;var Jl=class{constructor(){this.colour=0;this.parent=null;this.next=null;this.prev=null;this.data=null;this.swapped=null;this.lt=null}_allocNode(){let e=this.constructor,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor;e.data=null,e.lt=null,e.swapped=null,e.next=t.zpp_pool,t.zpp_pool=e}free(){this.data=null,this.lt=null,this.swapped=null}alloc(){}verify(){if(!this.empty()){let e=this.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;){let t=e.data,n=!0;if(!this.empty()){let s=this.parent;for(;s.prev!=null;)s=s.prev;for(;s!=null;){let i=s.data;if(n){if(t==i)n=!1;else if(!this.lt(i,t)&&this.lt(t,i))return!1}else if(!this.lt(t,i)&&this.lt(i,t))return!1;if(s.next!=null)for(s=s.next;s.prev!=null;)s=s.prev;else{for(;s.parent!=null&&s==s.parent.next;)s=s.parent;s=s.parent}}}if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent}}}return!0}empty(){return this.parent==null}singular(){return this.parent!=null&&this.parent.prev==null?this.parent.next==null:!1}size(){let e=0;if(!this.empty()){let t=this.parent;for(;t.prev!=null;)t=t.prev;for(;t!=null;)if(++e,t.next!=null)for(t=t.next;t.prev!=null;)t=t.prev;else{for(;t.parent!=null&&t==t.parent.next;)t=t.parent;t=t.parent}}return e}has(e){return this.find(e)!=null}find(e){let t=this.parent;for(;t!=null&&t.data!=e;)this.lt(e,t.data)?t=t.prev:t=t.next;return t}has_weak(e){return this.find_weak(e)!=null}find_weak(e){let t=this.parent;for(;t!=null;)if(this.lt(e,t.data))t=t.prev;else if(this.lt(t.data,e))t=t.next;else break;return t}lower_bound(e){let t=null;if(!this.empty()){let n=this.parent;for(;n.prev!=null;)n=n.prev;for(;n!=null;){if(!this.lt(n.data,e)){t=n.data;break}if(n.next!=null)for(n=n.next;n.prev!=null;)n=n.prev;else{for(;n.parent!=null&&n==n.parent.next;)n=n.parent;n=n.parent}}}return t}first(){let e=this.parent;for(;e.prev!=null;)e=e.prev;return e.data}pop_front(){let e=this.parent;for(;e.prev!=null;)e=e.prev;let t=e.data;return this.remove_node(e),t}remove(e){this.remove_node(this.find(e))}successor_node(e){if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{let t=e;for(e=e.parent;e!=null&&e.prev!=t;)t=e,e=e.parent}return e}predecessor_node(e){if(e.prev!=null)for(e=e.prev;e.next!=null;)e=e.next;else{let t=e;for(e=e.parent;e!=null&&e.next!=t;)t=e,e=e.parent}return e}successor(e){let t=this.successor_node(this.find(e));return t==null?null:t.data}predecessor(e){let t=this.predecessor_node(this.find(e));return t==null?null:t.data}remove_node(e){if(e.next!=null&&e.prev!=null){let s=e.next;for(;s.prev!=null;)s=s.prev;let i=e.data;e.data=s.data,s.data=i,this.swapped!=null&&this.swapped(e.data,s.data),e=s}let t=e.prev==null?e.next:e.prev;if(e.colour==1){if(e.prev!=null||e.next!=null)t.colour=1;else if(e.parent!=null){let s=e.parent;for(;;){s.colour++,s.prev.colour--,s.next.colour--;let i=s.prev;if(i.colour==-1){this.__fix_neg_red(i);break}else if(i.colour==0){if(i.prev!=null&&i.prev.colour==0){this.__fix_dbl_red(i.prev);break}if(i.next!=null&&i.next.colour==0){this.__fix_dbl_red(i.next);break}}let l=s.next;if(l.colour==-1){this.__fix_neg_red(l);break}else if(l.colour==0){if(l.prev!=null&&l.prev.colour==0){this.__fix_dbl_red(l.prev);break}if(l.next!=null&&l.next.colour==0){this.__fix_dbl_red(l.next);break}}if(s.colour==2)if(s.parent==null)s.colour=1;else{s=s.parent;continue}break}}}let n=e.parent;n==null?this.parent=t:n.prev==e?n.prev=t:n.next=t,t!=null&&(t.parent=n),e.parent=e.prev=e.next=null,this._freeNode(e)}clear(){if(this.parent!=null){let e=this.parent;for(;e!=null;)if(e.prev!=null)e=e.prev;else if(e.next!=null)e=e.next;else{let t=e.parent;t!=null&&(e==t.prev?t.prev=null:t.next=null,e.parent=null),this._freeNode(e),e=t}this.parent=null}}clear_with(e){if(this.parent==null)return;let t=this.parent;for(;t!=null;)if(t.prev!=null)t=t.prev;else if(t.next!=null)t=t.next;else{e(t.data);let n=t.parent;n!=null&&(t==n.prev?n.prev=null:n.next=null,t.parent=null),this._freeNode(t),t=n}this.parent=null}clear_node(e,t){t(e.data);let n=e.parent;return n!=null&&(e==n.prev?n.prev=null:n.next=null,e.parent=null),this._freeNode(e),n}__fix_neg_red(e){let t=e.parent,n;if(t.prev==e){let s=e.prev,i=e.next,l=i.prev,r=i.next;s.colour=0,e.colour=t.colour=1,e.next=l,l!=null&&(l.parent=e);let o=t.data;t.data=i.data,i.data=o,this.swapped!=null&&this.swapped(t.data,i.data),i.prev=r,r!=null&&(r.parent=i),i.next=t.next,t.next!=null&&(t.next.parent=i),t.next=i,i!=null&&(i.parent=t),n=s}else{let s=e.next,i=e.prev,l=i.next,r=i.prev;s.colour=0,e.colour=t.colour=1,e.prev=l,l!=null&&(l.parent=e);let o=t.data;t.data=i.data,i.data=o,this.swapped!=null&&this.swapped(t.data,i.data),i.next=r,r!=null&&(r.parent=i),i.prev=t.prev,t.prev!=null&&(t.prev.parent=i),t.prev=i,i!=null&&(i.parent=t),n=s}n.prev!=null&&n.prev.colour==0?this.__fix_dbl_red(n.prev):n.next!=null&&n.next.colour==0&&this.__fix_dbl_red(n.next)}__fix_dbl_red(e){for(;;){let t=e.parent,n=t.parent;if(n==null){t.colour=1;break}let s,i,l,r,o,a,p;t==n.prev?(l=n,p=n.next,e==t.prev?(s=e,i=t,r=e.prev,o=e.next,a=t.next):(s=t,i=e,r=t.prev,o=e.prev,a=e.next)):(s=n,r=n.prev,e==t.prev?(i=e,l=t,o=e.prev,a=e.next,p=t.next):(i=t,l=e,o=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=r,r!=null&&(r.parent=s),s.next=o,o!=null&&(o.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}};Jl.zpp_pool=null;var $i=null,ys=null,ui=null,Br=null,Lr=null,jr=null,pl=null,yn=null,cl=null,vi=null,hl=null,ul=null,Dr=null,wo=null,vo=null,go=null,Co=null,Zo=null,Mo=null,Eo=null,ko=null;function Ye(w){let e=class extends Wl{};return e.zpp_pool=null,e}function He(w,e){let t=class extends vt{};return t._NodeClass=e,t}function Qi(w){let e=class extends Jl{};return e.zpp_pool=null,e}function Kr(w){w.util||(w.util={}),w.util.ZNPNode_ZPP_CbType=Ye("ZPP_CbType"),w.util.ZNPNode_ZPP_CallbackSet=Ye("ZPP_CallbackSet"),w.util.ZNPNode_ZPP_Shape=Ye("ZPP_Shape"),w.util.ZNPNode_ZPP_Body=Ye("ZPP_Body"),w.util.ZNPNode_ZPP_Constraint=Ye("ZPP_Constraint"),w.util.ZNPNode_ZPP_Compound=Ye("ZPP_Compound"),w.util.ZNPNode_ZPP_Arbiter=Ye("ZPP_Arbiter"),w.util.ZNPNode_ZPP_InteractionListener=Ye("ZPP_InteractionListener"),w.util.ZNPNode_ZPP_CbSet=Ye("ZPP_CbSet"),w.util.ZNPNode_ZPP_Interactor=Ye("ZPP_Interactor"),w.util.ZNPNode_ZPP_BodyListener=Ye("ZPP_BodyListener"),w.util.ZNPNode_ZPP_CbSetPair=Ye("ZPP_CbSetPair"),w.util.ZNPNode_ZPP_ConstraintListener=Ye("ZPP_ConstraintListener"),w.util.ZNPNode_ZPP_CutInt=Ye("ZPP_CutInt"),w.util.ZNPNode_ZPP_CutVert=Ye("ZPP_CutVert"),w.util.ZNPNode_ZPP_PartitionVertex=Ye("ZPP_PartitionVertex"),w.util.ZNPNode_ZPP_SimplifyP=Ye("ZPP_SimplifyP"),w.util.ZNPNode_ZPP_PartitionedPoly=Ye("ZPP_PartitionedPoly"),w.util.ZNPNode_ZPP_GeomVert=Ye("ZPP_GeomVert"),w.util.ZNPNode_ZPP_SimpleVert=Ye("ZPP_SimpleVert"),w.util.ZNPNode_ZPP_SimpleEvent=Ye("ZPP_SimpleEvent"),w.util.ZNPNode_ZPP_Vec2=Ye("ZPP_Vec2"),w.util.ZNPNode_ZPP_AABBPair=Ye("ZPP_AABBPair"),w.util.ZNPNode_ZPP_Edge=Ye("ZPP_Edge"),w.util.ZNPNode_ZPP_AABBNode=Ye("ZPP_AABBNode"),w.util.ZNPNode_ZPP_Component=Ye("ZPP_Component"),w.util.ZNPNode_ZPP_FluidArbiter=Ye("ZPP_FluidArbiter"),w.util.ZNPNode_ZPP_SensorArbiter=Ye("ZPP_SensorArbiter"),w.util.ZNPNode_ZPP_Listener=Ye("ZPP_Listener"),w.util.ZNPNode_ZPP_ColArbiter=Ye("ZPP_ColArbiter"),w.util.ZNPNode_ZPP_InteractionGroup=Ye("ZPP_InteractionGroup"),w.util.ZNPNode_ZPP_ToiEvent=Ye("ZPP_ToiEvent"),w.util.ZNPNode_ConvexResult=Ye("ConvexResult"),w.util.ZNPNode_ZPP_GeomPoly=Ye("ZPP_GeomPoly"),w.util.ZNPNode_RayResult=Ye("RayResult");let e=w.util;vo=w.util.ZNPList_ZPP_InteractionListener=He("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),go=w.util.ZNPList_ZPP_BodyListener=He("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),Co=w.util.ZNPList_ZPP_ConstraintListener=He("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),Zo=w.util.ZNPList_ZPP_Constraint=He("ZPP_Constraint",e.ZNPNode_ZPP_Constraint),Mo=w.util.ZNPList_ZPP_Interactor=He("ZPP_Interactor",e.ZNPNode_ZPP_Interactor),Eo=w.util.ZNPList_ZPP_CbSet=He("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),wo=w.util.ZNPList_ZPP_CbType=He("ZPP_CbType",e.ZNPNode_ZPP_CbType),w.util.ZNPList_ZPP_Vec2=He("ZPP_Vec2",e.ZNPNode_ZPP_Vec2),Lr=w.util.ZNPList_ZPP_Vec2,w.util.ZNPList_ZPP_CallbackSet=He("ZPP_CallbackSet",e.ZNPNode_ZPP_CallbackSet),w.util.ZNPList_ZPP_Shape=He("ZPP_Shape",e.ZNPNode_ZPP_Shape),w.util.ZNPList_ZPP_Body=He("ZPP_Body",e.ZNPNode_ZPP_Body),w.util.ZNPList_ZPP_Compound=He("ZPP_Compound",e.ZNPNode_ZPP_Compound),w.util.ZNPList_ZPP_Arbiter=He("ZPP_Arbiter",e.ZNPNode_ZPP_Arbiter),ko=w.util.ZNPList_ZPP_CbSetPair=He("ZPP_CbSetPair",e.ZNPNode_ZPP_CbSetPair),w.util.ZNPList_ZPP_CutInt=He("ZPP_CutInt",e.ZNPNode_ZPP_CutInt),w.util.ZNPList_ZPP_CutVert=He("ZPP_CutVert",e.ZNPNode_ZPP_CutVert),w.util.ZNPList_ZPP_PartitionVertex=He("ZPP_PartitionVertex",e.ZNPNode_ZPP_PartitionVertex),$i=w.util.ZNPList_ZPP_PartitionVertex,w.util.ZNPList_ZPP_SimplifyP=He("ZPP_SimplifyP",e.ZNPNode_ZPP_SimplifyP),Br=w.util.ZNPList_ZPP_SimplifyP,w.util.ZNPList_ZPP_PartitionedPoly=He("ZPP_PartitionedPoly",e.ZNPNode_ZPP_PartitionedPoly),ys=w.util.ZNPList_ZPP_PartitionedPoly,w.util.ZNPList_ZPP_GeomVert=He("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),ui=w.util.ZNPList_ZPP_GeomVert,w.util.ZNPList_ZPP_SimpleVert=He("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),Dr=w.util.ZNPList_ZPP_SimpleEvent=He("ZPP_SimpleEvent",e.ZNPNode_ZPP_SimpleEvent),w.util.ZNPList_ZPP_AABBPair=He("ZPP_AABBPair",e.ZNPNode_ZPP_AABBPair),w.util.ZNPList_ZPP_Edge=He("ZPP_Edge",e.ZNPNode_ZPP_Edge),w.util.ZNPList_ZPP_AABBNode=He("ZPP_AABBNode",e.ZNPNode_ZPP_AABBNode),w.util.ZNPList_ZPP_Component=He("ZPP_Component",e.ZNPNode_ZPP_Component),w.util.ZNPList_ZPP_FluidArbiter=He("ZPP_FluidArbiter",e.ZNPNode_ZPP_FluidArbiter),w.util.ZNPList_ZPP_SensorArbiter=He("ZPP_SensorArbiter",e.ZNPNode_ZPP_SensorArbiter),w.util.ZNPList_ZPP_Listener=He("ZPP_Listener",e.ZNPNode_ZPP_Listener),w.util.ZNPList_ZPP_ColArbiter=He("ZPP_ColArbiter",e.ZNPNode_ZPP_ColArbiter),w.util.ZNPList_ZPP_InteractionGroup=He("ZPP_InteractionGroup",e.ZNPNode_ZPP_InteractionGroup),w.util.ZNPList_ZPP_ToiEvent=He("ZPP_ToiEvent",e.ZNPNode_ZPP_ToiEvent),w.util.ZNPList_ConvexResult=He("ConvexResult",e.ZNPNode_ConvexResult),w.util.ZNPList_ZPP_GeomPoly=He("ZPP_GeomPoly",e.ZNPNode_ZPP_GeomPoly),w.util.ZNPList_RayResult=He("RayResult",e.ZNPNode_RayResult),pl=w.util.ZNPNode_RayResult,jr=w.util.ZNPList_ZPP_SimpleVert,w.util.ZPP_Set_ZPP_Body=Qi("ZPP_Body"),w.util.ZPP_Set_ZPP_CbSetPair=Qi("ZPP_CbSetPair"),w.util.ZPP_Set_ZPP_PartitionVertex=Qi("ZPP_PartitionVertex"),hl=w.util.ZPP_Set_ZPP_PartitionVertex,w.util.ZPP_Set_ZPP_PartitionPair=Qi("ZPP_PartitionPair"),ul=w.util.ZPP_Set_ZPP_PartitionPair,w.util.ZPP_Set_ZPP_SimpleVert=Qi("ZPP_SimpleVert"),yn=w.util.ZPP_Set_ZPP_SimpleVert,w.util.ZPP_Set_ZPP_SimpleSeg=Qi("ZPP_SimpleSeg"),cl=w.util.ZPP_Set_ZPP_SimpleSeg,w.util.ZPP_Set_ZPP_SimpleEvent=Qi("ZPP_SimpleEvent"),vi=w.util.ZPP_Set_ZPP_SimpleEvent,w.util.ZPP_Set_ZPP_CbSet=Qi("ZPP_CbSet")}var St=class St{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&&(St.internal=!0,this.outer_body=St._createBodyCb(),St.internal=!1,this.outer_body.zpp_inner=this),this.outer_body}wrapper_con(){return this.outer_con==null&&(St.internal=!0,this.outer_con=St._createConCb(),St.internal=!1,this.outer_con.zpp_inner=this),this.outer_con}wrapper_int(){let e=St._zpp;return this.outer_int==null&&(St.internal=!0,this.outer_int=St._createIntCb(),St.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=St._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}};St._nape=null,St._zpp=null,St.internal=!1,St.zpp_pool=null,St._createBodyCb=null,St._createConCb=null,St._createIntCb=null,St._createPreCb=null;var xt=St;var rn=class rn{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=rn._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;rn.zpp_pool==null?t=new rn:(t=rn.zpp_pool,rn.zpp_pool=t.next,t.next=null);let n=null,s=e.head;for(;s!=null;){let i=s.elt;n=t.cbTypes.insert(n,i),i.cbsets.add(t),s=s.next}return t}static compatible(e,t,n){let s,i=e.options1,l=t.cbTypes;if(i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)){let r=e.options2,o=n.cbTypes;s=r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.excludes)}else s=!1;if(s)return!0;{let r=e.options2,o=t.cbTypes;if(r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.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=rn._zpp,s=null,l=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;l!=null;){let r=l.elt;if(r.a==e&&r.b==t||r.a==t&&r.b==e){s=r;break}l=l.next}if(s==null){let r;n.callbacks.ZPP_CbSetPair.zpp_pool==null?r=new n.callbacks.ZPP_CbSetPair:(r=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=r.next,r.next=null),r.zip_listeners=!0,rn.setlt(e,t)?(r.a=e,r.b=t):(r.a=t,r.b=e),s=r,e.cbpairs.add(s),t!=e&&t.cbpairs.add(s)}return s.zip_listeners&&(s.zip_listeners=!1,s.__validate()),s}static empty_intersection(e,t){return rn.findOrCreatePair(e,t).listeners.head==null}static single_intersection(e,t,n){let i=rn.findOrCreatePair(e,t).listeners.head;return i!=null&&i.elt==n?i.next==null:!1}static find_all(e,t,n,s){let l=rn.findOrCreatePair(e,t).listeners.head;for(;l!=null;){let r=l.elt;r.event==n&&s(r),l=l.next}}increment(){this.count++}decrement(){return--this.count==0}invalidate_pairs(){let e=this.cbpairs.head;for(;e!=null;){let t=e.elt;t.zip_listeners=!0,e=e.next}}invalidate_listeners(){this.zip_listeners=!0,this.invalidate_pairs()}validate_listeners(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners())}realvalidate_listeners(){let e=rn._zpp;this.listeners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.listeners.head,l=n.listeners.head;for(;l!=null;){let r=l.elt;if(i!=null&&i.elt==r)l=l.next,s=i,i=i.next;else{let o;if(i!=null){let a=i.elt;o=r.precedence>a.precedence||r.precedence==a.precedence&&r.id>a.id}else o=!0;if(o){if(r.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=r;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=rn._zpp;this.bodylisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.bodylisteners.head,l=n.bodylisteners.head;for(;l!=null;){let r=l.elt;if(i!=null&&i.elt==r)l=l.next,s=i,i=i.next;else{let o;if(i!=null){let a=i.elt;o=r.precedence>a.precedence||r.precedence==a.precedence&&r.id>a.id}else o=!0;if(o){let a=r.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&r.space==this.manager.space){let p=this.bodylisteners,c;e.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_BodyListener:(c=e.util.ZNPNode_ZPP_BodyListener.zpp_pool,e.util.ZNPNode_ZPP_BodyListener.zpp_pool=c.next,c.next=null),c.elt=r;let h=c;s==null?(h.next=p.head,p.head=h):(h.next=s.next,s.next=h),p.pushmod=p.modified=!0,p.length++,s=h}l=l.next}else s=i,i=i.next}}t=t.next}}invalidate_conlisteners(){this.zip_conlisteners=!0}validate_conlisteners(){this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}realvalidate_conlisteners(){let e=rn._zpp;this.conlisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.conlisteners.head,l=n.conlisteners.head;for(;l!=null;){let r=l.elt;if(i!=null&&i.elt==r)l=l.next,s=i,i=i.next;else{let o;if(i!=null){let a=i.elt;o=r.precedence>a.precedence||r.precedence==a.precedence&&r.id>a.id}else o=!0;if(o){let a=r.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&r.space==this.manager.space){let p=this.conlisteners,c;e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_ConstraintListener:(c=e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=c.next,c.next=null),c.elt=r;let h=c;s==null?(h.next=p.head,p.head=h):(h.next=s.next,s.next=h),p.pushmod=p.modified=!0,p.length++,s=h}l=l.next}else s=i,i=i.next}}t=t.next}}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners()),this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners()),this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}addConstraint(e){this.constraints.add(e)}addInteractor(e){this.interactors.add(e)}remConstraint(e){this.constraints.remove(e)}remInteractor(e){this.interactors.remove(e)}free(){for(this.listeners.clear(),this.zip_listeners=!0,this.bodylisteners.clear(),this.zip_bodylisteners=!0,this.conlisteners.clear(),this.zip_conlisteners=!0;this.cbTypes.head!=null;)this.cbTypes.pop_unsafe().cbsets.remove(this)}alloc(){}};rn._zpp=null,rn.zpp_pool=null;var gt=rn;var _i=class _i{constructor(){this.a=null;this.b=null;this.next=null;this.zip_listeners=!1;this.listeners=null;let e=_i._zpp;this.listeners=new e.util.ZNPList_ZPP_InteractionListener}static get(e,t){let n=_i._zpp,s;return _i.zpp_pool==null?s=new _i:(s=_i.zpp_pool,_i.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=_i._zpp;return n.callbacks.ZPP_CbSet.setlt(e.a,t.a)?!0:e.a==t.a?n.callbacks.ZPP_CbSet.setlt(e.b,t.b):!1}free(){this.a=this.b=null,this.listeners.clear()}alloc(){this.zip_listeners=!0}compatible(e){let t,n=e.options1,s=this.a.cbTypes;if(n.nonemptyintersection(s,n.includes)&&!n.nonemptyintersection(s,n.excludes)){let i=e.options2,l=this.b.cbTypes;t=i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)}else t=!1;if(t)return!0;{let i=e.options2,l=this.a.cbTypes;if(i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)){let r=e.options1,o=this.b.cbTypes;return r.nonemptyintersection(o,r.includes)?!r.nonemptyintersection(o,r.excludes):!1}else return!1}}invalidate(){this.zip_listeners=!0}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.__validate())}__validate(){this.listeners.clear();let e=this.a.listeners.head,t=this.b.listeners.head;for(;e!=null&&t!=null;){let n=e.elt,s=t.elt;if(n==s){let i,l,r=n.options1,o=this.a.cbTypes;if(r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.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}}};_i._zpp=null,_i.zpp_pool=null;var Ve=_i;var gn=class gn{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=gn._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){gn.ANY_SHAPE=new e.callbacks.CbType,gn.ANY_BODY=new e.callbacks.CbType,gn.ANY_COMPOUND=new e.callbacks.CbType,gn.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=gn._zpp,n=null,s=this.listeners.head;for(;s!=null;){let o=s.elt;if(e.precedence>o.precedence||e.precedence===o.precedence&&e.id>o.id)break;n=s,s=s.next}let i=this.listeners,l;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_InteractionListener:(l=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++;let r=this.cbsets.head;for(;r!=null;)r.elt.zip_listeners=!0,r.elt.invalidate_pairs(),r=r.next}removeint(e){this.listeners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_listeners=!0,t.elt.invalidate_pairs(),t=t.next}invalidateint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_listeners=!0,e.elt.invalidate_pairs(),e=e.next}addbody(e){let t=gn._zpp,n=null,s=this.bodylisteners.head;for(;s!=null;){let o=s.elt;if(e.precedence>o.precedence||e.precedence===o.precedence&&e.id>o.id)break;n=s,s=s.next}let i=this.bodylisteners,l;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_BodyListener:(l=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++;let r=this.cbsets.head;for(;r!=null;)r.elt.zip_bodylisteners=!0,r=r.next}removebody(e){this.bodylisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_bodylisteners=!0,t=t.next}invalidatebody(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_bodylisteners=!0,e=e.next}addconstraint(e){let t=gn._zpp,n=null,s=this.conlisteners.head;for(;s!=null;){let o=s.elt;if(e.precedence>o.precedence||e.precedence===o.precedence&&e.id>o.id)break;n=s,s=s.next}let i=this.conlisteners,l;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_ConstraintListener:(l=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++;let r=this.cbsets.head;for(;r!=null;)r.elt.zip_conlisteners=!0,r=r.next}removeconstraint(e){this.conlisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_conlisteners=!0,t=t.next}invalidateconstraint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_conlisteners=!0,e=e.next}};gn._zpp=null,gn.ANY_SHAPE=null,gn.ANY_BODY=null,gn.ANY_COMPOUND=null,gn.ANY_CONSTRAINT=null;var ut=gn;var Di=class Di{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=On.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()),Di.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()),Di.events=[t.CbEvent_BEGIN,t.CbEvent_END,t.CbEvent_WAKE,t.CbEvent_SLEEP,t.CbEvent_BREAK,t.CbEvent_PRE,t.CbEvent_ONGOING]}};Di._nape=null,Di._zpp=null,Di.internal=!1,Di.types=[],Di.events=[];var Ue=Di;var _l=class extends Ue{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=Ue._zpp;this.options.handler=(s,i,l)=>this.cbtype_change(s,i,l);let n=this.options.includes.head;for(;n!=null;){let s=n.elt,i=null,l=s.bodylisteners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next}let r=s.bodylisteners,o;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?o=new t.util.ZNPNode_ZPP_BodyListener:(o=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=o.next,o.next=null),o.elt=this;let a=o;i==null?(a.next=r.head,r.head=a):(a.next=i.next,i.next=a),r.pushmod=r.modified=!0,r.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_bodylisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.bodylisteners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_bodylisteners=!0,s=s.next}t=t.next}this.options.handler=null}cbtype_change(t,n,s){this.removedFromSpace();let i=this.options;n?s?i.effect_change(t,!0,!0):i.includes.remove(t):s?i.effect_change(t,!1,!0):i.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3)throw new Error("Error: BodyListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};var xl=class extends Ue{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=Ue._zpp;this.options.handler=(s,i,l)=>this.cbtype_change(s,i,l);let n=this.options.includes.head;for(;n!=null;){let s=n.elt,i=null,l=s.conlisteners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next}let r=s.conlisteners,o;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?o=new t.util.ZNPNode_ZPP_ConstraintListener:(o=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=o.next,o.next=null),o.elt=this;let a=o;i==null?(a.next=r.head,r.head=a):(a.next=i.next,i.next=a),r.pushmod=r.modified=!0,r.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_conlisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.conlisteners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_conlisteners=!0,s=s.next}t=t.next}this.options.handler=null}cbtype_change(t,n,s){this.removedFromSpace();let i=this.options;n?s?i.effect_change(t,!0,!0):i.includes.remove(t):s?i.effect_change(t,!1,!0):i.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3&&t!=4)throw new Error("Error: ConstraintListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};var Bt=class Bt extends Ue{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=Ue._zpp,l=Bt.UCbSet,r=Bt.VCbSet,o=Bt.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=o.head,o.head=u,o.modified=!0,o.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=r.head,r.head=u,r.modified=!0,r.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=r.head,r.head=c,r.modified=!0,r.length++,p=p.next}for(;l.head!=null;){let c=l.pop_unsafe(),h=n.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe(),h=o.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;o.head!=null;){let c=o.pop_unsafe();s(c,c);let h=o.head;for(;h!=null;)s(c,h.elt),h=h.next}}CbTypeset(t,n,s){let i=Ue._zpp,l=Bt.UCbType,r=Bt.VCbType,o=Bt.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=o.head,o.head=u,o.modified=!0,o.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=r.head,r.head=u,r.modified=!0,r.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=r.head,r.head=c,r.modified=!0,r.length++,p=p.next}for(;l.head!=null;){let c=l.pop_unsafe(),h=n.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe(),h=o.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;o.head!=null;){let c=o.pop_unsafe();s(c,c);let h=o.head;for(;h!=null;)s(c,h.elt),h=h.next}}with_uniquesets(t){let n=Ue._zpp,s;if(n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool==null?s=new n.util.ZPP_Set_ZPP_CbSetPair:(s=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=s.next,s.next=null),s.lt=n.callbacks.ZPP_CbSetPair.setlt,this.CbTypeset(this.options1.includes,this.options2.includes,(l,r)=>{this.CbSetset(l.cbsets,r.cbsets,(o,a)=>{if(o.validate(),a.validate(),n.callbacks.ZPP_CbSet.single_intersection(o,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(o,a)?(p.a=o,p.b=a):(p.a=a,p.b=o),s.try_insert(p)}})}),s.parent!=null){let l=s.parent;for(;l!=null;)if(l.prev!=null)l=l.prev;else if(l.next!=null)l=l.next;else{let r=l.data;t?this.space.freshListenerType(r.a,r.b):this.space.nullListenerType(r.a,r.b);let o=r;o.a=o.b=null,o.listeners.clear(),o.next=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=o;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=Ue._zpp,n=this.type==3;this.with_union(s=>{let i=null,l=s.listeners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next}let r=s.listeners,o;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?o=new t.util.ZNPNode_ZPP_InteractionListener:(o=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=o.next,o.next=null),o.elt=this;let a=o;i==null?(a.next=r.head,r.head=a):(a.next=i.next,i.next=a),r.pushmod=r.modified=!0,r.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_listeners=!0,c.invalidate_pairs(),p=p.next}if(n){let c=s.interactors.head;for(;c!=null;)c.elt.wake(),c=c.next}}),this.options1.handler=(s,i,l)=>this.cbtype_change1(s,i,l),this.options2.handler=(s,i,l)=>this.cbtype_change2(s,i,l),this.with_uniquesets(!0)}removedFromSpace(){this.with_uniquesets(!1);let t=this.type==3;this.with_union(n=>{n.listeners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_listeners=!0,i.invalidate_pairs(),s=s.next}if(t){let i=n.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next}}),this.options1.handler=null,this.options2.handler=null}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}cbtype_change1(t,n,s){this.cbtype_change(this.options1,t,n,s)}cbtype_change2(t,n,s){this.cbtype_change(this.options2,t,n,s)}cbtype_change(t,n,s,i){this.removedFromSpace(),s?i?t.effect_change(n,!0,!0):t.includes.remove(n):i?t.effect_change(n,!1,!0):t.excludes.remove(n),this.addedToSpace()}swapEvent(t){if(this.type==3)throw new Error("Error: PreListener event can only be PRE");if(t!=0&&t!=1&&t!=6)throw new Error("Error: InteractionListener event must be either BEGIN, END, ONGOING");this.removedFromSpace(),this.event=t,this.addedToSpace()}_allocCbSetNode(t){let n;return t.util.ZNPNode_ZPP_CbSet.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbSet:(n=t.util.ZNPNode_ZPP_CbSet.zpp_pool,t.util.ZNPNode_ZPP_CbSet.zpp_pool=n.next,n.next=null),n}_allocCbTypeNode(t){let n;return t.util.ZNPNode_ZPP_CbType.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbType:(n=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=n.next,n.next=null),n}static _initStatics(t){Bt.UCbSet=new t.util.ZNPList_ZPP_CbSet,Bt.VCbSet=new t.util.ZNPList_ZPP_CbSet,Bt.WCbSet=new t.util.ZNPList_ZPP_CbSet,Bt.UCbType=new t.util.ZNPList_ZPP_CbType,Bt.VCbType=new t.util.ZNPList_ZPP_CbType,Bt.WCbType=new t.util.ZNPList_ZPP_CbType}};Bt.UCbSet=null,Bt.VCbSet=null,Bt.WCbSet=null,Bt.UCbType=null,Bt.VCbType=null,Bt.WCbType=null;var es=Bt;var gi=class gi{constructor(){this.outer=null;this.handler=null;this.includes=null;this.excludes=null;this.wrap_includes=null;this.wrap_excludes=null;let e=gi._zpp;this.includes=new e.util.ZNPList_ZPP_CbType,this.excludes=new e.util.ZNPList_ZPP_CbType}static argument(e){let t=gi._nape;return e==null?new t.callbacks.OptionType:e instanceof t.callbacks.OptionType?e:new t.callbacks.OptionType().including(e)}setup_includes(){let e=gi._zpp;this.wrap_includes=e.util.ZPP_CbTypeList.get(this.includes,!0)}setup_excludes(){let e=gi._zpp;this.wrap_excludes=e.util.ZPP_CbTypeList.get(this.excludes,!0)}excluded(e){return this.nonemptyintersection(e,this.excludes)}included(e){return this.nonemptyintersection(e,this.includes)}compatible(e){return this.nonemptyintersection(e,this.includes)?!this.nonemptyintersection(e,this.excludes):!1}nonemptyintersection(e,t){let n=!1,s=e.head,i=t.head;for(;i!=null&&s!=null;){let l=i.elt,r=s.elt;if(l===r){n=!0;break}else l.id<r.id?i=i.next:s=s.next}return n}insertOrdered(e,t){let n=gi._zpp,s=null,i=e.head;for(;i!=null;){let r=i.elt;if(t.id<r.id)break;s=i,i=i.next}let l;n.util.ZNPNode_ZPP_CbType.zpp_pool==null?l=new n.util.ZNPNode_ZPP_CbType:(l=n.util.ZNPNode_ZPP_CbType.zpp_pool,n.util.ZNPNode_ZPP_CbType.zpp_pool=l.next,l.next=null),l.elt=t,s==null?(l.next=e.head,e.head=l):(l.next=s.next,s.next=l),e.pushmod=e.modified=!0,e.length++}effect_change(e,t,n){t?n?this.insertOrdered(this.includes,e):this.includes.remove(e):n?this.insertOrdered(this.excludes,e):this.excludes.remove(e)}append_type(e,t){e===this.includes?this.includes.has(t)||(this.excludes.has(t)?this.handler!=null?this.handler(t,!1,!1):this.excludes.remove(t):this.handler!=null?this.handler(t,!0,!0):this.insertOrdered(this.includes,t)):this.excludes.has(t)||(this.includes.has(t)?this.handler!=null?this.handler(t,!0,!1):this.includes.remove(t):this.handler!=null?this.handler(t,!1,!0):this.insertOrdered(this.excludes,t))}set(e){if(e!==this){for(;this.includes.head!=null;)this.append_type(this.excludes,this.includes.head.elt);for(;this.excludes.head!=null;)this.append_type(this.includes,this.excludes.head.elt);let t=e.excludes.head;for(;t!=null;){let s=t.elt;this.append_type(this.excludes,s),t=t.next}let n=e.includes.head;for(;n!=null;){let s=n.elt;this.append_type(this.includes,s),n=n.next}}return this}append(e,t){let n=gi._nape;if(t==null)throw new Error("Error: Cannot append null, only CbType and CbType list values");if(t instanceof n.callbacks.CbType){let s=t;this.append_type(e,s.zpp_inner)}else if(t instanceof n.callbacks.CbTypeList){let s=t;s.zpp_inner.valmod();let i=n.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let l=i.zpp_inner;l.zpp_inner.valmod(),l.zpp_inner.zip_length&&(l.zpp_inner.zip_length=!1,l.zpp_inner.user_length=l.zpp_inner.inner.length);let r=l.zpp_inner.user_length;i.zpp_critical=!0;let o;if(i.zpp_i<r?o=!0:(i.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,o=!1),!o)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 r=l;this.append_type(e,r.zpp_inner)}}else throw new Error("Error: Cannot append non-CbType or CbType list value")}};gi._nape=null,gi._zpp=null;var Gt=gi;var Fn=class Fn{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=Fn._zpp;this.id=On.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=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("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=Fn._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 o=s.elt;if(e.id<o.id)break;n=s,s=s.next}let i=this.cbTypes,l;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?l=new t.util.ZNPNode_ZPP_CbType:(l=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;n==null?(r.next=i.head,i.head=r):(r.next=n.next,n.next=r),i.pushmod=i.modified=!0,i.length++,this.space!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){(this.cbSet=this.space.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.constraints.add(this))}dealloc_cbSet(){let e=Fn._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=Fn._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=Fn._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=Fn._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 x=m.zpp_inner.user_length;i.zpp_critical=!0;let y;if(i.zpp_i<x?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 z=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(z):f.unshift(z)}e.zpp_inner.removeOnBreak=n.zpp_inner.removeOnBreak;let l=n.zpp_inner.breakUnderError;e.zpp_inner.breakUnderError!=l&&(e.zpp_inner.breakUnderError=l,e.zpp_inner.wake());let r=n.zpp_inner.breakUnderForce;e.zpp_inner.breakUnderForce!=r&&(e.zpp_inner.breakUnderForce=r,e.zpp_inner.wake());let o=n.zpp_inner.maxError;if(o!==o)throw new Error("Error: Constraint::maxError cannot be NaN");if(o<0)throw new Error("Error: Constraint::maxError must be >=0");e.zpp_inner.maxError!=o&&(e.zpp_inner.maxError=o,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 _=n.zpp_inner.active;e.zpp_inner.active!=_&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.woken=!1),e.zpp_inner.clearcache(),_?(e.zpp_inner.active=_,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=_,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=Fn._findRoot(e),s=Fn._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}};Fn._nape=null,Fn._zpp=null;var ke=Fn;var xi=class w{constructor(){this.id=0;this.bc=null;this.cb=null}static dict(e,t){let n=new w;return n.id=e,n.bc=t,n}static todo(e,t){let n=new w;return n.id=e,n.cb=t,n}};var Ul=class Ul extends ke{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=re();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=Ul._createFn(null,null,this.jointMin,this.jointMax,this.ratio);if(this.copyto(s),t!=null&&this.b1!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b1.id){i=r.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(xi.todo(this.b1.id,r=>{s.zpp_inner.b1=r.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b2.id){i=r.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(xi.todo(this.b2.id,r=>{s.zpp_inner.b2=r.zpp_inner}))}return s}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: AngleJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: AngleJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let s=this.b1.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let s=this.b2.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1,this.slack=!1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax;let s=this.ratio*this.b2.rot-this.b1.rot;this.equal?(s-=this.jointMax,this.slack=!1,this.scale=1):s<this.jointMin?(s=this.jointMin-s,this.scale=-1,this.slack=!1):s>this.jointMax?(s-=this.jointMax,this.scale=1,this.slack=!1):(this.scale=0,s=0,this.slack=!0);let i=s;if(!this.slack){if(this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&i*i>this.maxError*this.maxError)return!0;let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let r=1/(1+this.gamma),o=t*l*l*this.gamma;this.gamma*=r,this.kMass*=r,this.bias=-i*o,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){this.slack||(this.b1.angvel-=this.scale*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*this.jAcc)}applyImpulseVel(){if(this.slack)return!1;let t=this.scale*(this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel),n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;return this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&(this.jAcc>this.jMax||this.jAcc<-this.jMax)?!0:(this.stiff||(this.jAcc>this.jMax?this.jAcc=this.jMax:this.jAcc<-this.jMax&&(this.jAcc=-this.jMax)),n=this.jAcc-s,this.b1.angvel-=this.scale*this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*n,!1)}applyImpulsePos(){let t=this.ratio*this.b2.rot-this.b1.rot,n;this.equal?(t-=this.jointMax,n=!1,this.scale=1):t<this.jointMin?(t=this.jointMin-t,this.scale=-1,n=!1):t>this.jointMax?(t-=this.jointMax,this.scale=1,n=!1):(this.scale=0,t=0,n=!0);let s=t;if(!n){if(this.breakUnderError&&s*s>this.maxError*this.maxError)return!0;let l=-(s*.5)*this.kMass;if(this.equal||l<0){let r=this.b1,o=-this.scale*l*this.b1.iinertia;if(r.rot+=o,o*o>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let c=o*o,h=1-.5*c,u=1-c*c/8,_=(h*r.axisx+o*r.axisy)*u;r.axisy=(h*r.axisy-o*r.axisx)*u,r.axisx=_}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,_=(h*a.axisx+p*a.axisy)*u;a.axisy=(h*a.axisy-p*a.axisx)*u,a.axisx=_}}}return!1}draw(t){}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let s=n*n,i=1-.5*s,l=1-s*s/8,r=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=r}}static _copyBody(t,n,s,i,l){if(t!=null&&s!=null){let r=null;for(let o=0;o<t.length;o++){let a=t[o];if(a.id==s.id){r=a.bc;break}}r!=null?i.zpp_inner_zn[l]=r.zpp_inner:n.push(xi.todo(s.id,function(o){i.zpp_inner_zn[l]=o.zpp_inner}))}}};Ul._wrapFn=null,Ul._createFn=null;var We=Ul;var qt=class qt{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 qt.zpp_pool==null?s=new qt:(s=qt.zpp_pool,qt.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(qt._wrapFn)this.outer=qt._wrapFn(this);else{this.outer=new qt._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=qt.zpp_pool,qt.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 qt.zpp_pool==null?n=new qt:(n=qt.zpp_pool,qt.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+" }"}};qt.zpp_pool=null,qt._nape=null,qt._zpp=null,qt._wrapFn=null;var pe=qt;var ms=class ms extends ke{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<ke._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=ke._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=ms._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=ms._setupAnchorVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=ms._createFn(null,null,i,l.zpp_inner_zn.wrap_a2,this.jointMin,this.jointMax);return this.copyto(r),We._copyBody(t,n,this.b1,r,"b1"),We._copyBody(t,n,this.b2,r,"b2"),r}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: DistanceJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&ke._unionComponents(this.b1.component,this.component),this.b2.type==2&&ke._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<ke._nape.Config.epsilon)this.nx=0,this.ny=0,s=0,this.slack=!0;else{s=Math.sqrt(s);let l=1/s;this.nx*=l,this.ny*=l,this.equal?(s-=this.jointMax,this.slack=!1):s<this.jointMin?(s=this.jointMin-s,this.nx=-this.nx,this.ny=-this.ny,this.slack=!1):s>this.jointMax?(s-=this.jointMax,this.slack=!1):(this.nx=0,this.ny=0,s=0,this.slack=!0)}let i=s;if(!this.slack){if(this.cx1=this.ny*this.a1relx-this.nx*this.a1rely,this.cx2=this.ny*this.a2relx-this.nx*this.a2rely,this.kMass=this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&i*i>this.maxError*this.maxError)return!0;let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let r=1/(1+this.gamma),o=t*l*l*this.gamma;this.gamma*=r,this.kMass*=r,this.bias=-i*o,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.nx*t,this.b1.vely-=this.ny*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.nx*n,this.b2.vely+=this.ny*n,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.nx*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.ny*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-s;let i=this.b1.imass*n;this.b1.velx-=this.nx*i,this.b1.vely-=this.ny*i;let l=this.b2.imass*n;return this.b2.velx+=this.nx*l,this.b2.vely+=this.ny*l,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,!1}applyImpulsePos(){let t,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r,o=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s),p=o*o+a*a;if(p<ke._nape.Config.epsilon)o=0,a=0,p=0,r=!0;else{p=Math.sqrt(p);let h=1/p;o*=h,a*=h,this.equal?(p-=this.jointMax,r=!1):p<this.jointMin?(p=this.jointMin-p,o=-o,a=-a,r=!1):p>this.jointMax?(p-=this.jointMax,r=!1):(o=0,a=0,p=0,r=!0)}let c=p;if(!r){if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;if(c*c<ke._nape.Config.constraintLinearSlop*ke._nape.Config.constraintLinearSlop)return!1;if(c*=.5,c*c>6){let m=this.b1.smass+this.b2.smass;if(m>ke._nape.Config.epsilon){let x=.75/m;if(t=-c*x,this.equal||t<0){let y=t*this.b1.imass;this.b1.posx-=o*y,this.b1.posy-=a*y;let z=t*this.b2.imass;this.b2.posx+=o*z,this.b2.posy+=a*z,o=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s);let f=o*o+a*a;if(f<ke._nape.Config.epsilon)o=0,a=0,f=0;else{f=Math.sqrt(f);let v=1/f;o*=v,a*=v,this.equal?f-=this.jointMax:f<this.jointMin?(f=this.jointMin-f,o=-o,a=-a):f>this.jointMax?f-=this.jointMax:(o=0,a=0,f=0)}c=f,c*=.5}}}let h=a*n-o*s,u=a*i-o*l,_=this.b1.smass+this.b2.smass+h*h*this.b1.sinertia+u*u*this.b2.sinertia;if(_!=0&&(_=1/_),t=-c*_,this.equal||t<0){let m=this.b1.imass*t;this.b1.posx-=o*m,this.b1.posy-=a*m;let x=this.b2.imass*t;this.b2.posx+=o*x,this.b2.posy+=a*x,We._rotateBody(this.b1,-h*this.b1.iinertia*t),We._rotateBody(this.b2,u*this.b2.iinertia*t)}}return!1}draw(t){}static _setupAnchorVec2(t,n,s,i){let l=ke._nape,r=t,o=n;if(o==null&&(o=0),r==null&&(r=0),r!=r||o!=o)throw new Error("Error: Vec2 components cannot be NaN");let a;if(ue.poolVec2==null?a=new l.geom.Vec2:(a=ue.poolVec2,ue.poolVec2=a.zpp_pool,a.zpp_pool=null,a.zpp_disp=!1,a==ue.nextVec2&&(ue.nextVec2=null)),a.zpp_inner==null){let p;pe.zpp_pool==null?p=new pe:(p=pe.zpp_pool,pe.zpp_pool=p.next,p.next=null),p.weak=!1,p._immutable=!1,p.x=r,p.y=o,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(),r!=r||o!=o)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==r){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==o}else c=!1;if(!c){a.zpp_inner.x=r,a.zpp_inner.y=o;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}};ms._wrapFn=null,ms._createFn=null;var Ci=ms;var Kl=class Kl extends ke{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=ke._nape,r=ke._zpp;if(n==null&&(n=0),t==null&&(t=0),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");let o;if(r.util.ZPP_PubPool.poolVec2==null?o=new l.geom.Vec2:(o=r.util.ZPP_PubPool.poolVec2,r.util.ZPP_PubPool.poolVec2=o.zpp_pool,o.zpp_pool=null,o.zpp_disp=!1,o==r.util.ZPP_PubPool.nextVec2&&(r.util.ZPP_PubPool.nextVec2=null)),o.zpp_inner==null){let a;r.geom.ZPP_Vec2.zpp_pool==null?a=new r.geom.ZPP_Vec2:(a=r.geom.ZPP_Vec2.zpp_pool,r.geom.ZPP_Vec2.zpp_pool=a.next,a.next=null),a.weak=!1,a._immutable=!1,a.x=t,a.y=n,o.zpp_inner=a,o.zpp_inner.outer=o}else{if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=o.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(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=o.zpp_inner;p._validate!=null&&p._validate();let c;if(o.zpp_inner.x==t){if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=o.zpp_inner;h._validate!=null&&h._validate(),c=o.zpp_inner.y==n}else c=!1;if(!c){o.zpp_inner.x=t,o.zpp_inner.y=n;let h=o.zpp_inner;h._invalidate!=null&&h._invalidate(h)}}return o.zpp_inner.weak=!1,o.zpp_inner._inuse=!0,o.zpp_inner._validate=s,o.zpp_inner._invalidate=i,o}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=ke._nape;if(this.stepped){let s=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,i=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy;return t==this.b1?n.geom.Vec3.get(-s,-i,this.scale*this.cx1*i-this.dot1*s):n.geom.Vec3.get(s,i,this.scale*this.cx1*i-this.dot1*s)}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=l.zpp_inner_zn.wrap_a2,o=this.outer_zn;o.zpp_inner_zn.wrap_n==null&&o.zpp_inner_zn.setup_n();let a=Kl._createFn(null,null,i,r,o.zpp_inner_zn.wrap_n,this.jointMin,this.jointMax);return this.copyto(a),We._copyBody(t,n,this.b1,a,"b1"),We._copyBody(t,n,this.b2,a,"b2"),a}validate(){let t=ke._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&&ke._unionComponents(this.b1.component,this.component),this.b2.type==2&&ke._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.equal=this.jointMin==this.jointMax,this.stepped=!0,this.validate_norm(),this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.nrelx=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,this.nrely=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b2.posx+this.a2relx-this.b1.posx-this.a1relx,i=this.b2.posy+this.a2rely-this.b1.posy-this.a1rely,l=i*this.nrelx-s*this.nrely,r=this.nrelx*s+this.nrely*i;this.equal?(r-=this.jointMin,this.scale=1):r>this.jointMax?(r-=this.jointMax,this.scale=1):r<this.jointMin?(r=this.jointMin-r,this.scale=-1):(r=0,this.scale=0);let o=s+this.a1relx,a=i+this.a1rely;this.dot1=this.nrelx*o+this.nrely*a,this.cx1=a*this.nrelx-o*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,_=this.kMassc*u;this.kMassc=this.kMassa*u,this.kMassa=_,this.kMassb*=-u,c=0}if((c&1)!=0&&(this.jAccx=0),(c&2)!=0&&(this.jAccy=0),this.stiff)this.gamma=0,this.biasx=0,this.biasy=0;else{if(this.breakUnderError&&l*l+r*r>this.maxError*this.maxError)return!0;let u=2*Math.PI*this.frequency;this.gamma=1/(t*u*(2*this.damping+u*t));let _=1/(1+this.gamma),m=t*u*u*this.gamma;this.gamma*=_;let x=_;this.kMassa*=x,this.kMassb*=x,this.kMassc*=x,this.biasx=l,this.biasy=r;let y=-m;this.biasx*=y,this.biasy*=y;let z=this.maxError,f=this.biasx*this.biasx+this.biasy*this.biasy;if(f>z*z){let v=z*(1/Math.sqrt(f));this.biasx*=v,this.biasy*=v}}let h=n;return this.jAccx*=h,this.jAccy*=h,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,n=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy,s=this.b1.imass;this.b1.velx-=t*s,this.b1.vely-=n*s;let i=this.b2.imass;this.b2.velx+=t*i,this.b2.vely+=n*i,this.b1.angvel+=(this.scale*this.cx1*this.jAccy-this.dot1*this.jAccx)*this.b1.iinertia,this.b2.angvel+=(this.dot2*this.jAccx-this.scale*this.cx2*this.jAccy)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx-this.b1.velx,n=this.b2.vely-this.b1.vely;t+=this.b2.kinvelx-this.b1.kinvelx,n+=this.b2.kinvely-this.b1.kinvely;let s=n*this.nrelx-t*this.nrely+(this.b2.angvel+this.b2.kinangvel)*this.dot2-(this.b1.angvel+this.b1.kinangvel)*this.dot1,i=this.scale*(this.nrelx*t+this.nrely*n-(this.b2.angvel+this.b2.kinangvel)*this.cx2+(this.b1.angvel+this.b1.kinangvel)*this.cx1),l=this.biasx-s,r=this.biasy-i,o=this.kMassa*l+this.kMassb*r;r=this.kMassb*l+this.kMassc*r,l=o;let a=this.gamma;l-=this.jAccx*a,r-=this.jAccy*a;let p=this.jAccx,c=this.jAccy;if(this.jAccx+=l,this.jAccy+=r,this.jAccy>0&&(this.jAccy=0),this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let z=this.jMax,f=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(f>z*z){let v=z*(1/Math.sqrt(f));this.jAccx*=v,this.jAccy*=v}}let h=this.jAccx-p,u=this.jAccy-c,_=this.scale*this.nrelx*u-this.nrely*h,m=this.nrelx*h+this.scale*this.nrely*u,x=this.b1.imass;this.b1.velx-=_*x,this.b1.vely-=m*x;let y=this.b2.imass;return this.b2.velx+=_*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=ke._nape,n=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,s=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,i=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,r=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,o=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,a=this.b2.posx+r-this.b1.posx-i,p=this.b2.posy+o-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 _,m,x=.5;if(h*=x,u*=x,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),R=A*(n*h*c-s*h),j=this.b1.imass;this.b1.posx-=S*j,this.b1.posy-=R*j;let q=this.b2.imass;this.b2.posx+=S*q,this.b2.posy+=R*q,a=this.b2.posx+r-this.b1.posx-i,p=this.b2.posy+o-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 J=.5;h*=J,u*=J}}let y=a+i,z=p+l,f=n*y+s*z,v=z*n-y*s,E=n*r+s*o,d=o*n-r*s,b=this.b1.smass+this.b2.smass+f*f*this.b1.sinertia+E*E*this.b2.sinertia,C=-c*(f*v*this.b1.sinertia+E*d*this.b2.sinertia),P=c*c*(this.b1.smass+this.b2.smass+v*v*this.b1.sinertia+d*d*this.b2.sinertia);_=-h,m=-u;let g=b*P-C*C;if(g!==g)m=0,_=m;else if(g==0)b!=0?_/=b:_=0,P!=0?m/=P:m=0;else{let Z=1/g,A=Z*(P*_-C*m);m=Z*(b*m-C*_),_=A}m>0&&(m=0);let O=c*n*m-s*_,N=n*_+c*s*m,M=this.b1.imass;this.b1.posx-=O*M,this.b1.posy-=N*M;let k=this.b2.imass;return this.b2.posx+=O*k,this.b2.posy+=N*k,We._rotateBody(this.b1,(c*v*m-f*_)*this.b1.iinertia),We._rotateBody(this.b2,(E*_-c*d*m)*this.b2.iinertia),!1}draw(t){}};Kl._wrapFn=null,Kl._createFn=null;var Zi=Kl;var Yl=class Yl extends ke{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=re();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=Yl._createFn(null,null,this.rate,this.ratio);if(this.copyto(s),t!=null&&this.b1!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b1.id){i=r.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(xi.todo(this.b1.id,r=>{s.zpp_inner.b1=r.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b2.id){i=r.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(xi.todo(this.b2.id,r=>{s.zpp_inner.b2=r.zpp_inner}))}return s}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: MotorJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let s=this.b1.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let s=this.b2.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;return this.pre_dt=t,this.stepped=!0,this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass=1/this.kMass,this.jAcc*=n,this.jMax=this.maxForce*t,!1}warmStart(){this.b1.angvel-=this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.b2.iinertia*this.jAcc}applyImpulseVel(){let t=this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel-this.rate,n=-this.kMass*t,s=this.jAcc;if(this.jAcc+=n,this.breakUnderForce){if(this.jAcc>this.jMax||this.jAcc<-this.jMax)return!0}else this.jAcc<-this.jMax?this.jAcc=-this.jMax:this.jAcc>this.jMax&&(this.jAcc=this.jMax);return n=this.jAcc-s,this.b1.angvel-=this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.b2.iinertia*n,!1}applyImpulsePos(){return!1}};Yl._wrapFn=null,Yl._createFn=null;var Mi=Yl;var Hl=class Hl extends ke{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=ke._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=ke._nape,n=ke._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;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(),o=l.zpp_inner.y==i}else o=!1;if(!o){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=ke._nape,n=ke._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;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(),o=l.zpp_inner.y==i}else o=!1;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=Hl._createFn(null,null,i,l.zpp_inner_zn.wrap_a2);return this.copyto(r),We._copyBody(t,n,this.b1,r,"b1"),We._copyBody(t,n,this.b2,r,"b2"),r}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: PivotJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: PivotJoint cannot be simulated with body1 == body2 (body1=body2="+this.b1.outer.toString()+")");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&ke._unionComponents(this.b1.component,this.component),this.b2.type==2&&ke._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 o=this.a1relx*this.b1.sinertia,a=this.a1rely*this.b1.sinertia;this.kMassa+=a*this.a1rely,this.kMassb+=-a*this.a1relx,this.kMassc+=o*this.a1relx}if(this.b2.sinertia!=0){let o=this.a2relx*this.b2.sinertia,a=this.a2rely*this.b2.sinertia;this.kMassa+=a*this.a2rely,this.kMassb+=-a*this.a2relx,this.kMassc+=o*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 o=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,o|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,o|=2),this.kMassb=0,l=o}else{let o=1/i,a=this.kMassc*o;this.kMassc=this.kMassa*o,this.kMassa=a,this.kMassb*=-o,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 o=2*Math.PI*this.frequency;this.gamma=1/(t*o*(2*this.damping+o*t));let a=1/(1+this.gamma),p=t*o*o*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,_=this.biasx*this.biasx+this.biasy*this.biasy;if(_>u*u){let m=u*(1/Math.sqrt(_));this.biasx*=m,this.biasy*=m}}let r=n;return this.jAccx*=r,this.jAccy*=r,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),s=this.biasx-t,i=this.biasy-n,l=this.kMassa*s+this.kMassb*i;i=this.kMassb*s+this.kMassc*i,s=l;let r=this.gamma;s-=this.jAccx*r,i-=this.jAccy*r;let o=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,_=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(_>u*u){let m=u*(1/Math.sqrt(_));this.jAccx*=m,this.jAccy*=m}}s=this.jAccx-o,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=ke._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s);if(this.breakUnderError&&r*r+o*o>this.maxError*this.maxError)return!0;if(r*r+o*o<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let a=.5;r*=a,o*=a;let p,c;if(r*r+o*o>6){let b=this.b1.smass+this.b2.smass;if(b>t.Config.epsilon){let C=.75/b;p=-r*C,c=-o*C;let P=20,g=p*p+c*c;if(g>P*P){let k=P*(1/Math.sqrt(g));p*=k,c*=k}let O=this.b1.imass;this.b1.posx-=p*O,this.b1.posy-=c*O;let N=this.b2.imass;this.b2.posx+=p*N,this.b2.posy+=c*N,r=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s);let M=.5;r*=M,o*=M}}let h=this.b1.smass+this.b2.smass,u=h,_=0,m=h;if(this.b1.sinertia!=0){let b=n*this.b1.sinertia,C=s*this.b1.sinertia;u+=C*s,_+=-C*n,m+=b*n}if(this.b2.sinertia!=0){let b=i*this.b2.sinertia,C=l*this.b2.sinertia;u+=C*l,_+=-C*i,m+=b*i}p=-r,c=-o;let x=6,y=p*p+c*c;if(y>x*x){let b=x*(1/Math.sqrt(y));p*=b,c*=b}let z=u*m-_*_;if(z!=z)c=0,p=0;else if(z==0)u!=0?p/=u:p=0,m!=0?c/=m:c=0;else{let b=1/z,C=b*(m*p-_*c);c=b*(u*c-_*p),p=C}let f=this.b1.imass;this.b1.posx-=p*f,this.b1.posy-=c*f;let v=this.b2.imass;this.b2.posx+=p*v,this.b2.posy+=c*v;let E=-(c*n-p*s)*this.b1.iinertia;We._rotateBody(this.b1,E);let d=(c*i-p*l)*this.b2.iinertia;return We._rotateBody(this.b2,d),!1}draw(t){}};Hl._wrapFn=null,Hl._createFn=null;var Ei=Hl;var Xl=class Xl extends ke{constructor(){super();this.outer_zn=null;this.ratio=1;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.n12x=0;this.n12y=0;this.n34x=0;this.n34y=0;this.cx1=0;this.cx2=0;this.cx3=0;this.cx4=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.b3=null;this.a3localx=0;this.a3localy=0;this.a3relx=0;this.a3rely=0;this.wrap_a3=null;this.b4=null;this.a4localx=0;this.a4localy=0;this.a4relx=0;this.a4rely=0;this.wrap_a4=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.a3localx=0,this.a3localy=0,this.a3relx=0,this.a3rely=0,this.a4localx=0,this.a4localy=0,this.a4relx=0,this.a4rely=0,this.n12x=1,this.n12y=0,this.n34x=1,this.n34y=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=this.cx3=this.cx4=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),l=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),r=Math.sqrt(n*n+s*s),o=Math.sqrt(i*i+l*l),a=r+this.ratio*o;return this.equal||a<this.jointMin||a>this.jointMax?t=!1:t=!0,t}bodyImpulse(t){let n=ke._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=ke._nape,n=ke._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;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(),o=l.zpp_inner.y==i}else o=!1;if(!o){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=ke._nape,n=ke._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;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(),o=l.zpp_inner.y==i}else o=!1;if(!o){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=ke._nape,n=ke._zpp,s=this.a3localx,i=this.a3localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;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(),o=l.zpp_inner.y==i}else o=!1;if(!o){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=ke._nape,n=ke._zpp,s=this.a4localx,i=this.a4localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;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(),o=l.zpp_inner.y==i}else o=!1;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a4=l,this.wrap_a4.zpp_inner._inuse=!0,this.wrap_a4.zpp_inner._validate=this.validate_a4.bind(this),this.wrap_a4.zpp_inner._invalidate=this.invalidate_a4.bind(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=l.zpp_inner_zn.wrap_a2,o=this.outer_zn;o.zpp_inner_zn.wrap_a3==null&&o.zpp_inner_zn.setup_a3();let a=o.zpp_inner_zn.wrap_a3,p=this.outer_zn;p.zpp_inner_zn.wrap_a4==null&&p.zpp_inner_zn.setup_a4();let c=Xl._createFn(null,null,null,null,i,r,a,p.zpp_inner_zn.wrap_a4,this.jointMin,this.jointMax,this.ratio);return this.copyto(c),We._copyBody(t,n,this.b1,c,"b1"),We._copyBody(t,n,this.b2,c,"b2"),We._copyBody(t,n,this.b3,c,"b3"),We._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&&ke._unionComponents(this.b1.component,this.component),this.b2.type==2&&ke._unionComponents(this.b2.component,this.component),this.b3.type==2&&ke._unionComponents(this.b3.component,this.component),this.b4.type==2&&ke._unionComponents(this.b4.component,this.component)}pair_exists(t,n){return this.b1.id==t&&(this.b2.id==n||this.b3.id==n||this.b4.id==n)||this.b2.id==t&&(this.b3.id==n||this.b4.id==n||this.b1.id==n)||this.b3.id==t&&(this.b4.id==n||this.b1.id==n||this.b2.id==n)?!0:this.b4.id==t?this.b1.id==n||this.b2.id==n?!0:this.b3.id==n:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let s=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),i=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),l=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),r=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),o=Math.sqrt(s*s+i*i),a=Math.sqrt(l*l+r*r);if(o!=0){let h=1/o;this.n12x=s*h,this.n12y=i*h}if(a!=0){let h=1/a;this.n34x=l*h,this.n34y=r*h;let u=this.ratio;this.n34x*=u,this.n34y*=u}else{let h=this.ratio/Math.sqrt(this.n34x*this.n34x+this.n34y*this.n34y);this.n34x*=h,this.n34y*=h}let p=o+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 _=2*Math.PI*this.frequency;this.gamma=1/(t*_*(2*this.damping+_*t));let m=1/(1+this.gamma),x=t*_*_*this.gamma;this.gamma*=m,this.kMass*=m,this.bias=-c*x,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.n12x*t,this.b1.vely-=this.n12y*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.n12x*n,this.b2.vely+=this.n12y*n;let s=this.b3.imass*this.jAcc;this.b3.velx-=this.n34x*s,this.b3.vely-=this.n34y*s;let i=this.b4.imass*this.jAcc;this.b4.velx+=this.n34x*i,this.b4.vely+=this.n34y*i,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc,this.b3.angvel-=this.cx3*this.b3.iinertia*this.jAcc,this.b4.angvel+=this.cx4*this.b4.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.n12x*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.n12y*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+this.n34x*(this.b4.velx+this.b4.kinvelx-this.b3.velx-this.b3.kinvelx)+this.n34y*(this.b4.vely+this.b4.kinvely-this.b3.vely-this.b3.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1+(this.b4.angvel+this.b4.kinangvel)*this.cx4-(this.b3.angvel+this.b3.kinangvel)*this.cx3,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-s;let i=this.b1.imass*n;this.b1.velx-=this.n12x*i,this.b1.vely-=this.n12y*i;let l=this.b2.imass*n;this.b2.velx+=this.n12x*l,this.b2.vely+=this.n12y*l;let r=this.b3.imass*n;this.b3.velx-=this.n34x*r,this.b3.vely-=this.n34y*r;let o=this.b4.imass*n;return this.b4.velx+=this.n34x*o,this.b4.vely+=this.n34y*o,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=ke._nape,n,s=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,i=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,l=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,r=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o=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,_=this.n12y,m=this.n34x,x=this.n34y,y=this.b2.posx+l-(this.b1.posx+s),z=this.b2.posy+r-(this.b1.posy+i),f=this.b4.posx+p-(this.b3.posx+o),v=this.b4.posy+c-(this.b3.posy+a),E=Math.sqrt(y*y+z*z),d=Math.sqrt(f*f+v*v);if(E!=0){let P=1/E;u=y*P,_=z*P}if(d!=0){let P=1/d;m=f*P,x=v*P;let g=this.ratio;m*=g,x*=g}else{let P=this.ratio/Math.sqrt(m*m+x*x);m*=P,x*=P}let b=E+this.ratio*d;this.equal?(b-=this.jointMax,h=!1):b<this.jointMin?(b=this.jointMin-b,u=-u,_=-_,m=-m,x=-x,h=!1):b>this.jointMax?(b-=this.jointMax,h=!1):(u=0,_=0,m=0,x=0,b=0,h=!0);let C=b;if(!h){if(this.breakUnderError&&C*C>this.maxError*this.maxError)return!0;if(C*C<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;if(C*=.5,C*C>6){let 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 R=n*this.b1.imass;this.b1.posx-=u*R,this.b1.posy-=_*R;let j=n*this.b2.imass;this.b2.posx+=u*j,this.b2.posy+=_*j;let q=n*this.b3.imass;this.b3.posx-=m*q,this.b3.posy-=x*q;let J=n*this.b4.imass;this.b4.posx+=m*J,this.b4.posy+=x*J;let G=this.b2.posx+l-(this.b1.posx+s),L=this.b2.posy+r-(this.b1.posy+i),V=this.b4.posx+p-(this.b3.posx+o),Y=this.b4.posy+c-(this.b3.posy+a),$=Math.sqrt(G*G+L*L),H=Math.sqrt(V*V+Y*Y);if($!=0){let ee=1/$;u=G*ee,_=L*ee}if(H!=0){let ee=1/H;m=V*ee,x=Y*ee;let W=this.ratio;m*=W,x*=W}else{let ee=this.ratio/Math.sqrt(m*m+x*x);m*=ee,x*=ee}let X=$+this.ratio*H;this.equal?X-=this.jointMax:X<this.jointMin?(X=this.jointMin-X,u=-u,_=-_,m=-m,x=-x):X>this.jointMax?X-=this.jointMax:(u=0,_=0,m=0,x=0,X=0),C=X,C*=.5}}}let P=_*s-u*i,g=_*l-u*r,O=x*o-m*a,N=x*p-m*c,M=this.ratio*this.ratio,k=this.b1.smass+this.b2.smass+M*(this.b3.smass+this.b4.smass)+this.b1.sinertia*P*P+this.b2.sinertia*g*g+this.b3.sinertia*O*O+this.b4.sinertia*N*N;this.b1==this.b4&&(k-=2*((u*m+_*x)*this.b1.smass+P*N*this.b1.sinertia)),this.b1==this.b3&&(k+=2*((u*m+_*x)*this.b1.smass+P*O*this.b1.sinertia)),this.b2==this.b3&&(k-=2*((u*m+_*x)*this.b2.smass+g*O*this.b2.sinertia)),this.b2==this.b4&&(k+=2*((u*m+_*x)*this.b2.smass+g*N*this.b2.sinertia));let Z=k;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-=_*A;let S=this.b2.imass*n;this.b2.posx+=u*S,this.b2.posy+=_*S;let R=this.b3.imass*n;this.b3.posx-=m*R,this.b3.posy-=x*R;let j=this.b4.imass*n;this.b4.posx+=m*j,this.b4.posy+=x*j,We._rotateBody(this.b1,-P*this.b1.iinertia*n),We._rotateBody(this.b2,g*this.b2.iinertia*n),We._rotateBody(this.b3,-O*this.b3.iinertia*n),We._rotateBody(this.b4,N*this.b4.iinertia*n)}}return!1}draw(t){}};Xl._wrapFn=null,Xl._createFn=null;var ki=Xl;var dl=class{constructor(e,t){this.cnt=0;this.body=null;this.cnt=e,this.body=t}};var yl=class extends ke{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=ke._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 dl(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=ke._nape.geom.Vec3.get(0,0,0);return this.stepped&&this.outer_zn.__impulse(this.J,t.outer,n),n}activeBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.add(this)}inactiveBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.remove(this)}copy(t,n){let s=this.outer_zn.__copy();throw this.copyto(s),new Error("not done yet")}validate(){for(let t of this.bodies)if(t.body.space!==this.space)throw new Error("Error: Constraints must have each body within the same sapce to which the constraint has been assigned");this.outer_zn.__validate()}wake_connected(){for(let t of this.bodies)t.body.type===2&&t.body.wake()}forest(){for(let t of this.bodies)if(t.body.type===2){let n;if(t.body.component===t.body.component.parent)n=t.body.component;else{let i=t.body.component,l=null;for(;i!==i.parent;){let r=i.parent;i.parent=l,l=i,i=r}for(;l!=null;){let r=l.parent;l.parent=i,l=r}n=i}let s;if(this.component===this.component.parent)s=this.component;else{let i=this.component,l=null;for(;i!==i.parent;){let r=i.parent;i.parent=l,l=i,i=r}for(;l!=null;){let r=l.parent;l.parent=i,l=r}s=i}n!==s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}}pair_exists(t,n){let s=!1,i=this.bodies.length|0;for(let l=0;l<i;l++){let r=this.bodies[l].body;for(let o=l+1;o<i;o++){let a=this.bodies[o].body;if(r.id===t&&a.id===n||r.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 r=0;r<s-1;r++)i+=this.L[s*this.dim+r]*this.L[s*this.dim+r];let l=Math.sqrt(t[n++]-i);if(this.L[s*this.dim+s]=l,l!==0){l=1/l;for(let r=s+1;r<this.dim;r++){let o=0;for(let a=0;a<s-1;a++)o+=this.L[r*this.dim+a]*this.L[s*this.dim+a];this.L[r*this.dim+s]=l*(t[n++]-o)}}else{for(let r=s+1;r<this.dim;r++)this.L[r*this.dim+s]=0;n+=this.dim-s-1}}return this.L}transform(t,n){for(let s=0;s<this.dim;s++){let i=n[s],l=t[s*this.dim+s];if(l!==0){for(let r=0;r<s;r++)i-=t[s*this.dim+r]*this.y[r];this.y[s]=i/l}else this.y[s]=0}for(let s=0;s<this.dim;s++){let i=this.dim-1-s,l=t[i*this.dim+i];if(l!==0){let r=this.y[i];for(let o=i+1;o<this.dim;o++)r-=t[o*this.dim+i]*n[o];n[i]=r/l}else n[i]=0}}preStep(t){this.pre_dt===-1&&(this.pre_dt=t);let n=t/this.pre_dt;if(this.pre_dt=t,this.stepped=!0,this.outer_zn.__prepare(),this.outer_zn.__eff_mass(this.Keff),this.L=this.solve(this.Keff),!this.stiff&&!this.velonly){let s=2*Math.PI*this.frequency;this.gamma=1/(t*s*(2*this.damping+s*t));let i=1/(1+this.gamma),l=t*s*s*this.gamma;if(this.gamma*=i,this.soft=i,this.outer_zn.__position(this.bias),this.breakUnderError&&this.lsq(this.bias)>this.maxError*this.maxError)return!0;for(let r=0;r<this.dim;r++)this.bias[r]*=-l;this._clamp(this.bias,this.maxError)}else{for(let s=0;s<this.dim;s++)this.bias[s]=0;this.gamma=0,this.soft=1}for(let s=0;s<this.dim;s++)this.jAcc[s]*=n;return this.jMax=this.maxForce*t,!1}warmStart(){for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.jAcc,n.outer,this.vec3);let s=n.imass,i=n,l=i.velx,r=this.vec3;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let o=r.zpp_inner;o._validate!=null&&o._validate(),i.velx=l+r.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,_=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let x=m.zpp_inner;x._validate!=null&&x._validate(),u.angvel=_+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,r=this.vec3;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let o=r.zpp_inner;o._validate!=null&&o._validate(),i.velx=l+r.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,_=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let x=m.zpp_inner;x._validate!=null&&x._validate(),u.angvel=_+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<ke._nape.Config.constraintLinearSlop*ke._nape.Config.constraintLinearSlop)return!1;for(let n=0;n<this.dim;n++)this.J[n]*=-1;this.outer_zn.__eff_mass(this.Keff),this.transform(this.solve(this.Keff),this.J),this.outer_zn.__clamp(this.J);for(let n of this.bodies){let s=n.body;this.outer_zn.__impulse(this.J,s.outer,this.vec3);let i=s.imass,l=s,r=l.posx,o=this.vec3;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let a=o.zpp_inner;a._validate!=null&&a._validate(),l.posx=r+o.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 _=this.vec3;if(_!=null&&_.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let m=_.zpp_inner;m._validate!=null&&m._validate();let x=_.zpp_inner.z*s.iinertia;if(s.rot+=x,x*x>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let y=x*x,z=1-.5*y,f=1-y*y/8,v=(z*s.axisx+x*s.axisy)*f;s.axisy=(z*s.axisy-x*s.axisx)*f,s.axisx=v}}return!1}draw(t){this.outer_zn.__draw(t)}};var Ql=class Ql extends ke{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=ke._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=ke._nape,n=ke._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;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(),o=l.zpp_inner.y==i}else o=!1;if(!o){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=ke._nape,n=ke._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;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(),o=l.zpp_inner.y==i}else o=!1;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=Ql._createFn(null,null,i,l.zpp_inner_zn.wrap_a2);return this.copyto(r),We._copyBody(t,n,this.b1,r,"b1"),We._copyBody(t,n,this.b2,r,"b2"),r}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: WeldJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&ke._unionComponents(this.b1.component,this.component),this.b2.type==2&&ke._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.jAccz=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b1.smass+this.b2.smass;if(this.kMassa=s,this.kMassb=0,this.kMassd=s,this.kMassc=0,this.kMasse=0,this.kMassf=0,this.b1.sinertia!=0){let r=this.a1relx*this.b1.sinertia,o=this.a1rely*this.b1.sinertia;this.kMassa+=o*this.a1rely,this.kMassb+=-o*this.a1relx,this.kMassd+=r*this.a1relx,this.kMassc+=-o,this.kMasse+=r,this.kMassf+=this.b1.sinertia}if(this.b2.sinertia!=0){let r=this.a2relx*this.b2.sinertia,o=this.a2rely*this.b2.sinertia;this.kMassa+=o*this.a2rely,this.kMassb+=-o*this.a2relx,this.kMassd+=r*this.a2relx,this.kMassc+=-o,this.kMasse+=r,this.kMassf+=this.b2.sinertia}let i=this.kMassa*(this.kMassd*this.kMassf-this.kMasse*this.kMasse)+this.kMassb*(this.kMassc*this.kMasse-this.kMassb*this.kMassf)+this.kMassc*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),l;if(i!=i)this.kMassa=0,this.kMassb=0,this.kMassd=0,this.kMassc=0,this.kMasse=0,this.kMassf=0,l=7;else if(i==0){let r=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,r|=1),this.kMassd!=0?this.kMassd=1/this.kMassd:(this.kMassd=0,r|=2),this.kMassf!=0?this.kMassf=1/this.kMassf:(this.kMassf=0,r|=4),this.kMassb=this.kMassc=this.kMasse=0,l=r}else{let r=1/i,o=r*(this.kMassd*this.kMassf-this.kMasse*this.kMasse),a=r*(this.kMasse*this.kMassc-this.kMassb*this.kMassf),p=r*(this.kMassa*this.kMassf-this.kMassc*this.kMassc),c=r*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),h=r*(this.kMassb*this.kMassc-this.kMassa*this.kMasse),u=r*(this.kMassa*this.kMassd-this.kMassb*this.kMassb);this.kMassa=o,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 r=2*Math.PI*this.frequency;this.gamma=1/(t*r*(2*this.damping+r*t));let o=1/(1+this.gamma),a=t*r*r*this.gamma;this.gamma*=o;let p=o;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 _=h*(1/Math.sqrt(u));this.biasx*=_,this.biasy*=_,this.biasz*=_}}return this.jAccx*=n,this.jAccy*=n,this.jAccz*=n,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),s=this.b2.angvel+this.b2.kinangvel-this.b1.angvel-this.b1.kinangvel,i=this.biasx-t,l=this.biasy-n,r=this.biasz-s,o=this.kMassa*i+this.kMassb*l+this.kMassc*r,a=this.kMassb*i+this.kMassd*l+this.kMasse*r;r=this.kMassc*i+this.kMasse*l+this.kMassf*r,i=o,l=a,i-=this.jAccx*this.gamma,l-=this.jAccy*this.gamma,r-=this.jAccz*this.gamma;let p=this.jAccx,c=this.jAccy,h=this.jAccz;if(this.jAccx+=i,this.jAccy+=l,this.jAccz+=r,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz>this.jMax*this.jMax)return!0}else if(!this.stiff){let m=this.jMax,x=this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz;if(x>m*m){let y=m*(1/Math.sqrt(x));this.jAccx*=y,this.jAccy*=y,this.jAccz*=y}}i=this.jAccx-p,l=this.jAccy-c,r=this.jAccz-h;let u=this.b1.imass;this.b1.velx-=i*u,this.b1.vely-=l*u;let _=this.b2.imass;return this.b2.velx+=i*_,this.b2.vely+=l*_,this.b1.angvel-=(l*this.a1relx-i*this.a1rely+r)*this.b1.iinertia,this.b2.angvel+=(l*this.a2relx-i*this.a2rely+r)*this.b2.iinertia,!1}applyImpulsePos(){let t=ke._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,p,c,h;if(this.breakUnderError&&r*r+o*o+a*a>this.maxError*this.maxError)return!0;let u=!0;r*r+o*o<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(u=!1,r=0,o=0);let _=t.Config.constraintAngularSlop;if(a*a<_*_)if(u)a=0;else return!1;if(r*=.5,o*=.5,a*=.5,r*r+o*o>6){let S=this.b1.smass+this.b2.smass;if(S>t.Config.epsilon){let R=.75/S;p=-r*R,c=-o*R;let j=20,q=p*p+c*c;if(q>j*j){let L=j*(1/Math.sqrt(q));p*=L,c*=L}let J=this.b1.imass;this.b1.posx-=p*J,this.b1.posy-=c*J;let G=this.b2.imass;this.b2.posx+=p*G,this.b2.posy+=c*G,r=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,r*=.5,o*=.5,a*=.5}}let m=this.b1.smass+this.b2.smass,x=m,y=0,z=m,f=0,v=0,E=0;if(this.b1.sinertia!=0){let S=n*this.b1.sinertia,R=s*this.b1.sinertia;x+=R*s,y+=-R*n,z+=S*n,f+=-R,v+=S,E+=this.b1.sinertia}if(this.b2.sinertia!=0){let S=i*this.b2.sinertia,R=l*this.b2.sinertia;x+=R*l,y+=-R*i,z+=S*i,f+=-R,v+=S,E+=this.b2.sinertia}p=-r,c=-o,h=-a;let d=6,b=p*p+c*c;if(b>d*d){let S=d*(1/Math.sqrt(b));p*=S,c*=S}let P=h<-.25,g=x*(z*E-v*v)+y*(f*v-y*E)+f*(y*v-f*z);if(g!=g)h=0,c=h,p=c;else if(g==0)x!=0?p/=x:p=0,z!=0?c/=z:c=0,E!=0?h/=E:h=0;else{let S=1/g,R=v*f-y*E,j=y*v-f*z,q=y*f-x*v,J=S*(p*(z*E-v*v)+c*R+h*j),G=S*(p*R+c*(x*E-f*f)+h*q);h=S*(p*j+c*q+h*(x*z-y*y)),p=J,c=G}let O=this.b1.imass;this.b1.posx-=p*O,this.b1.posy-=c*O;let N=this.b2.imass;this.b2.posx+=p*N,this.b2.posy+=c*N;let M=this.b1,k=-(c*n-p*s+h)*this.b1.iinertia;We._rotateBody(M,k);let Z=this.b2,A=(c*i-p*l+h)*this.b2.iinertia;return We._rotateBody(Z,A),!1}draw(t){}};Ql._wrapFn=null,Ql._createFn=null;var Ni=Ql;var at=class at{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()),at.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID]}wrapper(){if(this.outer==null){let e=at._nape;at.internal=!0,this.type==at.COL?(this.colarb.outer_zn=at._createColArb(),this.outer=this.colarb.outer_zn):this.type==at.FLUID?(this.fluidarb.outer_zn=at._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,at.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=at._zpp;this.cleared=!0,(t==null||this.b2==t)&&at._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&at._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=at._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=s,at._addToArbiterList(this.b1.arbiters,this,i),at._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=at._zpp;this.cleared||(at._removeFromArbiterList(this.b1.arbiters,this,e),at._removeFromArbiterList(this.b2.arbiters,this,e),this.pair!=null&&(this.pair.arb=null,this.pair=null)),this.b1=this.b2=null,this.active=!1,this.intchange=!1}static _removeFromArbiterList(e,t,n){let s=null,i=e.head;for(;i!=null;){if(i.elt==t){let l,r;s==null?(l=e.head,r=l.next,e.head=r,e.head==null&&(e.pushmod=!0)):(l=s.next,r=l.next,s.next=r,r==null&&(e.pushmod=!0));let 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}}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++}};at._nape=null,at._zpp=null,at.internal=!1,at._createColArb=null,at._createFluidArb=null,at.COL=1,at.FLUID=4,at.SENSOR=2,at.types=[];var Ne=at;var $l=class $l extends Ne{constructor(){super(),this.next=null,this.type=Ne.SENSOR,this.sensorarb=this}alloc(){}free(){}assign(e,t,n,s){this.sup_assign(e,t,n,s)}retire(){this.sup_retire(),this.next=$l.zpp_pool,$l.zpp_pool=this}makemutable(){}makeimmutable(){}};$l.zpp_pool=null;var Wt=$l;var er=class er extends Ne{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=Ne.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=Ne._zpp,n=Ne._nape,s;if(t.util.ZPP_PubPool.poolVec2==null?s=new n.geom.Vec2:(s=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;t.geom.ZPP_Vec2.zpp_pool==null?i=new t.geom.ZPP_Vec2:(i=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=0,i.y=0,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");i._isimmutable!=null&&i._isimmutable();let l;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=s.zpp_inner;if(r._validate!=null&&r._validate(),s.zpp_inner.x==0){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=s.zpp_inner;o._validate!=null&&o._validate(),l=s.zpp_inner.y==0}else l=!1;if(!l){s.zpp_inner.x=0,s.zpp_inner.y=0;let o=s.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}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=er.zpp_pool,er.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=Ne._nape;this.pre_dt==-1&&(this.pre_dt=n);let i=n/this.pre_dt;this.pre_dt=n,this.r1x=this.centroidx-this.b1.posx,this.r1y=this.centroidy-this.b1.posy,this.r2x=this.centroidx-this.b2.posx,this.r2y=this.centroidy-this.b2.posy;let l,r;this.ws1.fluidEnabled&&this.ws1.fluidProperties.wrap_gravity!=null?(l=this.ws1.fluidProperties.gravityx,r=this.ws1.fluidProperties.gravityy):(l=t.gravityx,r=t.gravityy);let o,a;this.ws2.fluidEnabled&&this.ws2.fluidProperties.wrap_gravity!=null?(o=this.ws2.fluidProperties.gravityx,a=this.ws2.fluidProperties.gravityy):(o=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 _=h+u;p-=l*_,c-=r*_}else if(h<u){let _=h+u;p+=o*_,c+=a*_}else{let _=l+o,m=r+a,x=.5;if(_*=x,m*=x,this.ws1.worldCOMx*_+this.ws1.worldCOMy*m>this.ws2.worldCOMx*_+this.ws2.worldCOMy*m){let y=h+u;p-=_*y,c-=m*y}else{let y=h+u;p+=_*y,c+=m*y}}}else if(this.ws1.fluidEnabled){let h=this.overlap*this.ws1.fluidProperties.density;p-=l*h,c-=r*h}else if(this.ws2.fluidEnabled){let h=this.overlap*this.ws2.fluidProperties.density;p+=o*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 x=this.b1.sinertia+this.b2.sinertia;x!=0?this.wMass=1/x:this.wMass=0,h*=4e-4;let y=2*Math.PI*h;this.agamma=1/(n*y*(2+y*n));let z=1/(1+this.agamma);this.agamma*=z,this.wMass*=z}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)),_=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+_*_<s.Config.epsilon*s.Config.epsilon)){let x=u*u+_*_,y=1/Math.sqrt(x);this.nx=u*y,this.ny=_*y}let m=0;if(this.ws1.fluidEnabled){let x=-this.ws1.fluidProperties.viscosity*this.overlap/this.ws2.area;if(this.ws2.type==0)m-=x*this.ws2.circle.radius*s.Config.fluidLinearDrag/(2*this.ws2.circle.radius*Math.PI);else{let y=this.ws2.polygon,z=0,f=0,v=y.edges.head;for(;v!=null;){let E=v.elt;z+=E.length;let d=x*E.length*(E.gnormx*this.nx+E.gnormy*this.ny);d>0&&(d*=-s.Config.fluidVacuumDrag),f-=d*.5*s.Config.fluidLinearDrag,v=v.next}m+=f/z}}if(this.ws2.fluidEnabled){let x=-this.ws2.fluidProperties.viscosity*this.overlap/this.ws1.area;if(this.ws1.type==0)m-=x*this.ws1.circle.radius*s.Config.fluidLinearDrag/(2*this.ws1.circle.radius*Math.PI);else{let y=this.ws1.polygon,z=0,f=0,v=y.edges.head;for(;v!=null;){let E=v.elt;z+=E.length;let d=x*E.length*(E.gnormx*this.nx+E.gnormy*this.ny);d>0&&(d*=-s.Config.fluidVacuumDrag),f-=d*.5*s.Config.fluidLinearDrag,v=v.next}m+=f/z}}if(m!=0){let x=this.b1.smass+this.b2.smass,y=x,z=0,f=x;if(this.b1.sinertia!=0){let b=this.r1x*this.b1.sinertia,C=this.r1y*this.b1.sinertia;y+=C*this.r1y,z+=-C*this.r1x,f+=b*this.r1x}if(this.b2.sinertia!=0){let b=this.r2x*this.b2.sinertia,C=this.r2y*this.b2.sinertia;y+=C*this.r2y,z+=-C*this.r2x,f+=b*this.r2x}let v=y*f-z*z;if(v!==v)f=0,z=f,y=z;else if(v==0)y!=0?y=1/y:y=0,f!=0?f=1/f:f=0,z=0;else{let b=1/v,C=f*b;f=y*b,y=C,z*=-b}this.vMassa=y,this.vMassb=z,this.vMassc=f;let E=2*Math.PI*m;this.lgamma=1/(n*E*(2+E*n));let d=1/(1+this.lgamma);this.lgamma*=d,this.vMassa*=d,this.vMassb*=d,this.vMassc*=d}else this.vMassa=0,this.vMassb=0,this.vMassc=0,this.lgamma=0}this.dampx*=i,this.dampy*=i,this.adamp*=i}warmStart(){this.b1.velx-=this.dampx*this.b1.imass,this.b1.vely-=this.dampy*this.b1.imass,this.b2.velx+=this.dampx*this.b2.imass,this.b2.vely+=this.dampy*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(this.dampy*this.r1x-this.dampx*this.r1y),this.b2.angvel+=this.b2.iinertia*(this.dampy*this.r2x-this.dampx*this.r2y),this.b1.angvel-=this.adamp*this.b1.iinertia,this.b2.angvel+=this.adamp*this.b2.iinertia}applyImpulseVel(){if(!this.nodrag){let t=this.b1.angvel+this.b1.kinangvel,n=this.b2.angvel+this.b2.kinangvel,s=this.b1.velx+this.b1.kinvelx-this.r1y*t-(this.b2.velx+this.b2.kinvelx-this.r2y*n),i=this.b1.vely+this.b1.kinvely+this.r1x*t-(this.b2.vely+this.b2.kinvely+this.r2x*n),l=this.vMassa*s+this.vMassb*i;i=this.vMassb*s+this.vMassc*i,s=l,s-=this.dampx*this.lgamma,i-=this.dampy*this.lgamma,this.dampx+=s,this.dampy+=i,this.b1.velx-=s*this.b1.imass,this.b1.vely-=i*this.b1.imass,this.b2.velx+=s*this.b2.imass,this.b2.vely+=i*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(i*this.r1x-s*this.r1y),this.b2.angvel+=this.b2.iinertia*(i*this.r2x-s*this.r2y);let r=(t-n)*this.wMass-this.adamp*this.agamma;this.adamp+=r,this.b1.angvel-=r*this.b1.iinertia,this.b2.angvel+=r*this.b2.iinertia}}};er.zpp_pool=null;var At=er;var ts=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 Sn=class Sn{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 ts}wrapper(){return this.outer==null&&(Sn._wrapFn?this.outer=Sn._wrapFn(this):(Sn.internal=!0,this.outer=new Sn._nape.dynamics.Contact,Sn.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=Sn._zpp,t=Sn._nape,n;if(e.util.ZPP_PubPool.poolVec2==null?n=new t.geom.Vec2:(n=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let s;e.geom.ZPP_Vec2.zpp_pool==null?s=new e.geom.ZPP_Vec2:(s=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){n.zpp_inner.x=0,n.zpp_inner.y=0;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}n.zpp_inner.weak=!1,this.wrap_position=n,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!0,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this)}inactiveme(){return!(this.active&&this.arbiter!=null&&this.arbiter.active)}free(){this.arbiter=null}alloc(){}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};Sn._nape=null,Sn._zpp=null,Sn.zpp_pool=null,Sn.internal=!1,Sn._wrapFn=null;var we=Sn;var Vt=class Vt extends Ne{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 we,this.innards=new ts,this.type=Ne.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=Ne._zpp,n=Ne._nape,s=0,i=0,l;if(t.util.ZPP_PubPool.poolVec2==null?l=new n.geom.Vec2:(l=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;t.geom.ZPP_Vec2.zpp_pool==null?r=new t.geom.ZPP_Vec2:(r=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!==s||i!==i)throw new Error("Error: Vec2 components cannot be NaN");let o;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(),o=l.zpp_inner.y==i}else o=!1;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_normal=l,this.wrap_normal.zpp_inner._immutable=!0,this.wrap_normal.zpp_inner._inuse=!0,this.wrap_normal.zpp_inner._validate=this.normal_validate.bind(this)}injectContact(t,n,s,i,l,r,o=!1){let a=null,p=this.contacts.next;for(;p!=null;){if(r==p.hash){a=p;break}p=p.next}if(a==null){we.zpp_pool==null?a=new we:(a=we.zpp_pool,we.zpp_pool=a.next,a.next=null);let c=a.inner;c.jnAcc=c.jtAcc=0,a.hash=r,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=o,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=we.zpp_pool,we.zpp_pool=t;let n=this.innards.next;this.innards.next=n.next,n._inuse=!1,this.innards.next==null&&(this.innards.pushmod=!0),this.innards.modified=!0,this.innards.length--}this.free(),this.next=Vt.zpp_pool,Vt.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=we.zpp_pool,we.zpp_pool=l;break}n=l,s=i,i=i.next,l=l.next}}setupcontacts(){let t=Ne._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=Ne._nape,n=!0,s=null,i=null,l=this.innards.next;this.hc2=!1;let r=this.contacts.next;for(;r!=null;){let o=r;if(o.stamp+t.Config.arbiterExpirationDelay<this.stamp){r=Vt._eraseFromList(this.contacts,s),l=Vt._eraseFromList(this.innards,i),o.arbiter=null,o.next=we.zpp_pool,we.zpp_pool=o;continue}let a=o.inner,p=o.active;o.active=o.stamp==this.stamp,o.active&&(n?(n=!1,this.c1=a,this.oc1=o):(this.hc2=!0,this.c2=a,this.oc2=o)),p!=o.active&&(this.contacts.modified=!0),s=r,i=l,l=l.next,r=r.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let o=this.c1;this.c1=this.c2,this.c2=o,o=this.oc1,this.oc1=this.oc2,this.oc2=o,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=Ne._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,o=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=o,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=Vt._eraseFromList(this.contacts,a),c=Vt._eraseFromList(this.innards,p),u.arbiter=null,u.next=we.zpp_pool,we.zpp_pool=u;continue}let _=u.inner,m=u.active;if(u.active=u.stamp==this.stamp,u.active){l?(l=!1,this.c1=_,this.oc1=u):(this.hc2=!0,this.c2=_,this.oc2=u),_.r2x=u.px-this.b2.posx,_.r2y=u.py-this.b2.posy,_.r1x=u.px-this.b1.posx,_.r1y=u.py-this.b1.posy;let x=_.r2x*this.nx+_.r2y*this.ny,y=i+this.b2.sinertia*(x*x);x=_.r1x*this.nx+_.r1y*this.ny,y+=this.b1.sinertia*(x*x),_.tMass=y<n.Config.epsilon*n.Config.epsilon?0:1/y,x=this.ny*_.r2x-this.nx*_.r2y;let z=i+this.b2.sinertia*(x*x);x=this.ny*_.r1x-this.nx*_.r1y,z+=this.b1.sinertia*(x*x),_.nMass=z<n.Config.epsilon*n.Config.epsilon?0:1/z;let f=this.b2.angvel+this.b2.kinangvel,v=this.b2.velx+this.b2.kinvelx-_.r2y*f,E=this.b2.vely+this.b2.kinvely+_.r2x*f;f=this.b1.angvel+this.b1.kinangvel,v-=this.b1.velx+this.b1.kinvelx-_.r1y*f,E-=this.b1.vely+this.b1.kinvely+_.r1x*f;let d=this.nx*v+this.ny*E;u.elasticity=this.restitution,_.bounce=d*u.elasticity,_.bounce>-n.Config.elasticThreshold&&(_.bounce=0);let b=E*this.nx-v*this.ny,C=n.Config.staticFrictionThreshold;b*b>C*C?_.friction=this.dyn_fric:_.friction=this.stat_fric,_.jnAcc*=s,_.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 _=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(_!==_)this.kMassa=this.kMassb=this.kMassc=0;else if(_==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=this.kMassc*m;this.kMassc=this.kMassa*m,this.kMassa=x,this.kMassb*=-m}}else{if(this.hc2=!1,this.oc2.dist<this.oc1.dist){let _=this.c1;this.c1=this.c2,this.c2=_}this.oc2.active=!1,this.contacts.modified=!0}return this.surfacex=this.b2.svelx,this.surfacey=this.b2.svely,this.surfacex+=this.b1.svelx,this.surfacey+=this.b1.svely,this.surfacex=-this.surfacex,this.surfacey=-this.surfacey,this.rMass=this.b1.sinertia+this.b2.sinertia,this.rMass!=0&&(this.rMass=1/this.rMass),l}warmStart(){let t=this.nx*this.c1.jnAcc-this.ny*this.c1.jtAcc,n=this.ny*this.c1.jnAcc+this.nx*this.c1.jtAcc;this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c1.r1x-t*this.c1.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c1.r2x-t*this.c1.r2y),this.hc2&&(t=this.nx*this.c2.jnAcc-this.ny*this.c2.jtAcc,n=this.ny*this.c2.jnAcc+this.nx*this.c2.jtAcc,this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c2.r1x-t*this.c2.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c2.r2x-t*this.c2.r2y)),this.b2.angvel+=this.jrAcc*this.b2.iinertia,this.b1.angvel-=this.jrAcc*this.b1.iinertia}applyImpulseVel(){let t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),s=(n*this.nx-t*this.ny+this.surfacex)*this.c1.tMass,i=this.c1.friction*this.c1.jnAcc,l=this.c1.jtAcc,r=l-s;r>i?r=i:r<-i&&(r=-i),s=r-l,this.c1.jtAcc=r;let o=-this.ny*s,a=this.nx*s;if(this.b2.velx+=o*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=o*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,r=l-s,r>i?r=i:r<-i&&(r=-i),s=r-l,this.c2.jtAcc=r,o=-this.ny*s,a=this.nx*s,this.b2.velx+=o*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=o*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,_=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),x=-(this.kMassa*_+this.kMassb*m),y=-(this.kMassb*_+this.kMassc*m);x>=0&&y>=0?(_=x-h,m=y-u,this.c1.jnAcc=x,this.c2.jnAcc=y):(x=-this.c1.nMass*_,x>=0&&this.Kb*x+m>=0?(_=x-h,m=-u,this.c1.jnAcc=x,this.c2.jnAcc=0):(y=-this.c2.nMass*m,y>=0&&this.Kb*y+_>=0?(_=-h,m=y-u,this.c1.jnAcc=0,this.c2.jnAcc=y):_>=0&&m>=0?(_=-h,m=-u,this.c1.jnAcc=this.c2.jnAcc=0):(_=0,m=0))),s=_+m,o=this.nx*s,a=this.ny*s,this.b2.velx+=o*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=o*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=(this.rn1b*_+this.rn2b*m)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*_+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,r=l-s,r<0&&(r=0),s=r-l,this.c1.jnAcc=r,o=this.nx*s,a=this.ny*s,this.b2.velx+=o*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=o*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=Ne._nape;this.ptype==2?this._applyImpulsePosCircle(t):this._applyImpulsePosEdge(t)}_applyImpulsePosCircle(t){let n=this.c1,s=this.b2.axisy*n.lr2x-this.b2.axisx*n.lr2y,i=n.lr2x*this.b2.axisx+n.lr2y*this.b2.axisy;s+=this.b2.posx,i+=this.b2.posy;let l=this.b1.axisy*n.lr1x-this.b1.axisx*n.lr1y,r=n.lr1x*this.b1.axisx+n.lr1y*this.b1.axisy;l+=this.b1.posx,r+=this.b1.posy;let o=s-l,a=i-r,p=Math.sqrt(o*o+a*a),c=this.radius-t.Config.collisionSlop,h=p-c;if(o*this.nx+a*this.ny<0&&(o=-o,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;o*=u,a*=u;let _=.5*(l+s),m=.5*(r+i),x=p-c;l=_-this.b1.posx,r=m-this.b1.posy,s=_-this.b2.posx,i=m-this.b2.posy;let y=a*l-o*r,z=a*s-o*i,f=this.b2.smass+z*z*this.b2.sinertia+this.b1.smass+y*y*this.b1.sinertia;if(f!=0){let v=-this.biasCoef*x/f,E=o*v,d=a*v;this.b1.posx-=E*this.b1.imass,this.b1.posy-=d*this.b1.imass,Vt._rotateBody(this.b1,-y*this.b1.iinertia*v),this.b2.posx+=E*this.b2.imass,this.b2.posy+=d*this.b2.imass,Vt._rotateBody(this.b2,z*this.b2.iinertia*v)}}}_applyImpulsePosEdge(t){let n,s,i,l,r,o=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,r=this.c1.lr1x*this.b2.axisx+this.c1.lr1y*this.b2.axisy,l+=this.b2.posx,r+=this.b2.posy,this.hpc2&&(o=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,o+=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,r=this.c1.lr1x*this.b1.axisx+this.c1.lr1y*this.b1.axisy,l+=this.b1.posx,r+=this.b1.posy,this.hpc2&&(o=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,o+=this.b1.posx,a+=this.b1.posy));let p=l*n+r*s-i-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=o*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=r-this.b1.posy,_=l-this.b2.posx,m=r-this.b2.posy;if(this.hpc2){let x=o-this.b1.posx,y=a-this.b1.posy,z=o-this.b2.posx,f=a-this.b2.posy,v=s*h-n*u,E=s*_-n*m,d=s*x-n*y,b=s*z-n*f,C=this.b1.smass+this.b2.smass;this.kMassa=C+this.b1.sinertia*v*v+this.b2.sinertia*E*E,this.kMassb=C+this.b1.sinertia*v*d+this.b2.sinertia*E*b,this.kMassc=C+this.b1.sinertia*d*d+this.b2.sinertia*b*b;let P=this.kMassa,g=this.kMassb,O=this.kMassc,N=p*this.biasCoef,M=c*this.biasCoef;for(;;){let k=-N,Z=-M,A=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(A!==A)k=0,Z=0;else if(A==0)this.kMassa!=0?k/=this.kMassa:k=0,this.kMassc!=0?Z/=this.kMassc:Z=0;else{let S=1/A,R=S*(this.kMassc*k-this.kMassb*Z);Z=S*(this.kMassa*Z-this.kMassb*k),k=R}if(k>=0&&Z>=0){Vt._applyPosImpulse2(this.b1,this.b2,n,s,k,Z,v,d,E,b);break}if(k=-N/P,Z=0,k>=0&&g*k+M>=0){Vt._applyPosImpulse2(this.b1,this.b2,n,s,k,Z,v,d,E,b);break}if(k=0,Z=-M/O,Z>=0&&g*Z+N>=0){Vt._applyPosImpulse2(this.b1,this.b2,n,s,k,Z,v,d,E,b);break}break}}else{let x=s*h-n*u,y=s*_-n*m,z=this.b2.smass+y*y*this.b2.sinertia+this.b1.smass+x*x*this.b1.sinertia;if(z!=0){let f=-this.biasCoef*p/z,v=n*f,E=s*f;this.b1.posx-=v*this.b1.imass,this.b1.posy-=E*this.b1.imass,Vt._rotateBody(this.b1,-x*this.b1.iinertia*f),this.b2.posx+=v*this.b2.imass,this.b2.posy+=E*this.b2.imass,Vt._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,r=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=r}}static _applyPosImpulse2(t,n,s,i,l,r,o,a,p,c){let h=(l+r)*t.imass;t.posx-=s*h,t.posy-=i*h,Vt._rotateBody(t,-t.iinertia*(o*l+a*r));let u=(l+r)*n.imass;n.posx+=s*u,n.posy+=i*u,Vt._rotateBody(n,n.iinertia*(p*l+c*r))}};Vt.FACE1=0,Vt.FACE2=1,Vt.CIRCLE=2,Vt.zpp_pool=null;var Pt=Vt;var on=class on{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 on._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(on._wrapFn)this.outer=on._wrapFn(this);else{this.outer=new on._nape.dynamics.InteractionFilter;let e=this.outer.zpp_inner;e.outer=null,e.next=on.zpp_pool,on.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new on._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return on.zpp_pool==null?e=new on:(e=on.zpp_pool,on.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}};on.zpp_pool=null,on._nape=null,on._zpp=null,on._wrapFn=null;var pt=on;var fs=class fs{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=fs._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)}};fs.SHAPE=1,fs.BODY=2,fs._zpp=null,fs._wrapFn=null;var Fi=fs;var Oi=class{constructor(){this.zpp_inner=null;this.space=null;this._length=0;this.zip_length=!1;this.lengths=[];this.ite_0=null;this.ite_1=null;this.ite_2=null;this.ite_3=null;this.at_index_0=0;this.at_index_1=0;this.at_index_2=0;this.at_index_3=0;this.at_index_0=0,this.at_index_1=0,this.at_index_2=0,this.at_index_3=0,this.zip_length=!0,this._length=0,this.lengths=[],this.lengths.push(0),this.lengths.push(0),this.lengths.push(0),this.lengths.push(0)}zpp_gl(){if(this.zpp_vm(),this.zip_length){this._length=0;let e=0,t=0,n=this.space.c_arbiters_true.head;for(;n!=null;)n.elt.active&&++t,n=n.next;this.lengths[e++]=t,this._length+=t;let s=0,i=this.space.c_arbiters_false.head;for(;i!=null;)i.elt.active&&++s,i=i.next;this.lengths[e++]=s,this._length+=s;let l=0,r=this.space.f_arbiters.head;for(;r!=null;)r.elt.active&&++l,r=r.next;this.lengths[e++]=l,this._length+=l;let o=0,a=this.space.s_arbiters.head;for(;a!=null;)a.elt.active&&++o,a=a.next;this.lengths[e++]=o,this._length+=o,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}};Oi._nape=null,Oi._zpp=null;var Lt=class Lt{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 Lt.zpp_pool==null?i=new Lt:(i=Lt.zpp_pool,Lt.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(Lt._wrapFn)this.outer=Lt._wrapFn(this);else{this.outer=new Lt._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=Lt.zpp_pool,Lt.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 Lt.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=Lt._zpp,s=Lt._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=Lt._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=Lt._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)+" }"}};Lt.zpp_pool=null,Lt._nape=null,Lt._zpp=null,Lt._wrapFn=null;var fe=Lt;var Ee=class Ee{static _initStatics(e){Ee.flowpoly=new e.util.ZNPList_ZPP_Vec2,Ee.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?Ee.circleContains(e.circle,t):Ee.polyContains(e.polygon,t)}static bodyContains(e,t){let n;n=!1;let s=e.shapes.head;for(;s!=null;){let i=s.elt;if(Ee.shapeContains(i,t)){n=!0;break}s=s.next}return n}static containTest(e,t){let n=e.aabb,s=t.aabb;if(s.minx>=n.minx&&s.miny>=n.miny&&s.maxx<=n.maxx&&s.maxy<=n.maxy)if(e.type==0)if(t.type==0){let i=e.circle.radius+-t.circle.radius,l=t.circle.worldCOMx-e.circle.worldCOMx,r=t.circle.worldCOMy-e.circle.worldCOMy;return l*l+r*r<=i*i}else{let i;i=!0;let l=t.polygon.gverts.next;for(;l!=null;){let r=l,o=e.circle.radius,a=r.x-e.circle.worldCOMx,p=r.y-e.circle.worldCOMy;if(a*a+p*p<=o*o){l=l.next;continue}else{i=!1;break}}return i}else if(t.type==0){let i;i=!0;let l=e.polygon.edges.head;for(;l!=null;){let r=l.elt;if(r.gnormx*t.circle.worldCOMx+r.gnormy*t.circle.worldCOMy+t.circle.radius<=r.gprojection){l=l.next;continue}else{i=!1;break}}return i}else{let i;i=!0;let l=e.polygon.edges.head;for(;l!=null;){let r=l.elt,o=-1e100,a=t.polygon.gverts.next;for(;a!=null;){let p=a,c=r.gnormx*p.x+r.gnormy*p.y;c>o&&(o=c),a=a.next}if(o<=r.gprojection){l=l.next;continue}else{i=!1;break}}return i}else return!1}static contactCollide(e,t,n,s){let i=re();if(t.type==1)if(e.type==1){let l=!0,r=-1e100,o=-1e100,a=-1,p=null,c=null,h=e.polygon.edges.head;for(;h!=null;){let u=h.elt,_=1e100,m=t.polygon.gverts.next;for(;m!=null;){let x=m,y=u.gnormx*x.x+u.gnormy*x.y;if(y<_&&(_=y),_-u.gprojection<=r)break;m=m.next}if(_-=u.gprojection,_>=0){l=!1;break}_>r&&(r=_,p=u,a=1),h=h.next}if(l){let u=t.polygon.edges.head;for(;u!=null;){let _=u.elt,m=1e100,x=e.polygon.gverts.next;for(;x!=null;){let y=x,z=_.gnormx*y.x+_.gnormy*y.y;if(z<m&&(m=z),m-_.gprojection<=r)break;x=x.next}if(m-=_.gprojection,m>=0){l=!1;break}m>r&&(r=m,c=_,a=2),u=u.next}if(l){let _,m,x,y;a==1?(_=e.polygon,m=t.polygon,x=p,y=1):(_=t.polygon,m=e.polygon,x=c,y=-1);let z=null,f=1e100,v=m.edges.head;for(;v!=null;){let J=v.elt,G=x.gnormx*J.gnormx+x.gnormy*J.gnormy;G<f&&(f=G,z=J),v=v.next}let E=z.gp0.x,d=z.gp0.y,b=z.gp1.x,C=z.gp1.y,P=b-E,g=C-d,O=x.gnormy*E-x.gnormx*d,N=x.gnormy*b-x.gnormx*C,M=1/(N-O),k=(-x.tp1-O)*M;if(k>i.Config.epsilon){let J=k;E+=P*J,d+=g*J}let Z=(-x.tp0-N)*M;if(Z<-i.Config.epsilon){let J=Z;b+=P*J,C+=g*J}let A=y,S=x.gnormx*A,R=x.gnormy*A;n.lnormx=x.lnormx,n.lnormy=x.lnormy,n.lproj=x.lprojection,n.radius=0,n.rev=s!=(y==-1),n.ptype=n.rev?1:0;let j=E*x.gnormx+d*x.gnormy-x.gprojection,q=b*x.gnormx+C*x.gnormy-x.gprojection;if(j>0&&q>0)return!1;{s&&(S=-S,R=-R);let J=E-x.gnormx*j*.5,G=d-x.gnormy*j*.5,L=n.rev?1:0,V=j>0;V==null&&(V=!1);let Y=null,$=n.contacts.next;for(;$!=null;){let K=$;if(L==K.hash){Y=K;break}$=$.next}if(Y==null){we.zpp_pool==null?Y=new we:(Y=we.zpp_pool,we.zpp_pool=Y.next,Y.next=null);let K=Y.inner;K.jnAcc=K.jtAcc=0,Y.hash=L,Y.fresh=!0,Y.arbiter=n,n.jrAcc=0;let ie=n.contacts;Y._inuse=!0;let oe=Y;oe.next=ie.next,ie.next=oe,ie.modified=!0,ie.length++,n.innards.add(K)}else Y.fresh=!1;Y.px=J,Y.py=G,n.nx=S,n.ny=R,Y.dist=j,Y.stamp=n.stamp,Y.posOnly=V;let H=Y,X=1;E-=m.body.posx*X,d-=m.body.posy*X,H.inner.lr1x=E*m.body.axisy+d*m.body.axisx,H.inner.lr1y=d*m.body.axisy-E*m.body.axisx;let ee=b-x.gnormx*q*.5,W=C-x.gnormy*q*.5,F=n.rev?0:1,D=q>0;D==null&&(D=!1);let T=null,U=n.contacts.next;for(;U!=null;){let K=U;if(F==K.hash){T=K;break}U=U.next}if(T==null){we.zpp_pool==null?T=new we:(T=we.zpp_pool,we.zpp_pool=T.next,T.next=null);let K=T.inner;K.jnAcc=K.jtAcc=0,T.hash=F,T.fresh=!0,T.arbiter=n,n.jrAcc=0;let ie=n.contacts;T._inuse=!0;let oe=T;oe.next=ie.next,ie.next=oe,ie.modified=!0,ie.length++,n.innards.add(K)}else T.fresh=!1;T.px=ee,T.py=W,n.nx=S,n.ny=R,T.dist=q,T.stamp=n.stamp,T.posOnly=D,H=T;let Q=1;return b-=m.body.posx*Q,C-=m.body.posy*Q,H.inner.lr1x=b*m.body.axisy+C*m.body.axisx,H.inner.lr1y=C*m.body.axisy-b*m.body.axisx,a==1?(n.__ref_edge1=x,n.__ref_edge2=z):(n.__ref_edge2=x,n.__ref_edge1=z),!0}}else return!1}else return!1}else{let l=-1e100,r=-1e100,o=!0,a=null,p=null,c=t.polygon.gverts.next,h=t.polygon.edges.head;for(;h!=null;){let u=h.elt,_=u.gnormx*e.circle.worldCOMx+u.gnormy*e.circle.worldCOMy-u.gprojection-e.circle.radius;if(_>0){o=!1;break}_>l&&(l=_,a=u,p=c),c=c.next,h=h.next}if(o){let u=p,_=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 x=e.circle.radius,y=u.x-e.circle.worldCOMx,z=u.y-e.circle.worldCOMy,f=y*y+z*z,v;if(f>x*x)v=null;else if(f<i.Config.epsilon*i.Config.epsilon){let E=e.circle.worldCOMx,d=e.circle.worldCOMy,b=null,C=n.contacts.next;for(;C!=null;){let P=C;if(P.hash==0){b=P;break}C=C.next}if(b==null){we.zpp_pool==null?b=new we:(b=we.zpp_pool,we.zpp_pool=b.next,b.next=null);let P=b.inner;P.jnAcc=P.jtAcc=0,b.hash=0,b.fresh=!0,b.arbiter=n,n.jrAcc=0;let g=n.contacts;b._inuse=!0;let O=b;O.next=g.next,g.next=O,g.modified=!0,g.length++,n.innards.add(P)}else b.fresh=!1;b.px=E,b.py=d,n.nx=1,n.ny=0,b.dist=-x,b.stamp=n.stamp,b.posOnly=!1,v=b}else{let E=1/Math.sqrt(f),d=E<i.Config.epsilon?1e100:1/E,b=.5+(e.circle.radius-.5*x)*E;if(s){let C=e.circle.worldCOMx+y*b,P=e.circle.worldCOMy+z*b,g=null,O=n.contacts.next;for(;O!=null;){let N=O;if(N.hash==0){g=N;break}O=O.next}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let k=g;k.next=M.next,M.next=k,M.modified=!0,M.length++,n.innards.add(N)}else g.fresh=!1;g.px=C,g.py=P,n.nx=-y*E,n.ny=-z*E,g.dist=d-x,g.stamp=n.stamp,g.posOnly=!1,v=g}else{let C=e.circle.worldCOMx+y*b,P=e.circle.worldCOMy+z*b,g=null,O=n.contacts.next;for(;O!=null;){let N=O;if(N.hash==0){g=N;break}O=O.next}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let k=g;k.next=M.next,M.next=k,M.modified=!0,M.length++,n.innards.add(N)}else g.fresh=!1;g.px=C,g.py=P,n.nx=y*E,n.ny=z*E,g.dist=d-x,g.stamp=n.stamp,g.posOnly=!1,v=g}}if(v!=null){let E=v.inner;n.ptype=2;let d=u.x-t.polygon.body.posx,b=u.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=-1,s?(E.lr1x=d*t.polygon.body.axisy+b*t.polygon.body.axisx,E.lr1y=b*t.polygon.body.axisy-d*t.polygon.body.axisx,E.lr2x=e.circle.localCOMx,E.lr2y=e.circle.localCOMy):(E.lr2x=d*t.polygon.body.axisy+b*t.polygon.body.axisx,E.lr2y=b*t.polygon.body.axisy-d*t.polygon.body.axisx,E.lr1x=e.circle.localCOMx,E.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return v!=null}else if(m>=_.y*a.gnormx-_.x*a.gnormy){let x=e.circle.radius,y=_.x-e.circle.worldCOMx,z=_.y-e.circle.worldCOMy,f=y*y+z*z,v;if(f>x*x)v=null;else if(f<i.Config.epsilon*i.Config.epsilon){let E=e.circle.worldCOMx,d=e.circle.worldCOMy,b=null,C=n.contacts.next;for(;C!=null;){let P=C;if(P.hash==0){b=P;break}C=C.next}if(b==null){we.zpp_pool==null?b=new we:(b=we.zpp_pool,we.zpp_pool=b.next,b.next=null);let P=b.inner;P.jnAcc=P.jtAcc=0,b.hash=0,b.fresh=!0,b.arbiter=n,n.jrAcc=0;let g=n.contacts;b._inuse=!0;let O=b;O.next=g.next,g.next=O,g.modified=!0,g.length++,n.innards.add(P)}else b.fresh=!1;b.px=E,b.py=d,n.nx=1,n.ny=0,b.dist=-x,b.stamp=n.stamp,b.posOnly=!1,v=b}else{let E=1/Math.sqrt(f),d=E<i.Config.epsilon?1e100:1/E,b=.5+(e.circle.radius-.5*x)*E;if(s){let C=e.circle.worldCOMx+y*b,P=e.circle.worldCOMy+z*b,g=null,O=n.contacts.next;for(;O!=null;){let N=O;if(N.hash==0){g=N;break}O=O.next}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let k=g;k.next=M.next,M.next=k,M.modified=!0,M.length++,n.innards.add(N)}else g.fresh=!1;g.px=C,g.py=P,n.nx=-y*E,n.ny=-z*E,g.dist=d-x,g.stamp=n.stamp,g.posOnly=!1,v=g}else{let C=e.circle.worldCOMx+y*b,P=e.circle.worldCOMy+z*b,g=null,O=n.contacts.next;for(;O!=null;){let N=O;if(N.hash==0){g=N;break}O=O.next}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let M=n.contacts;g._inuse=!0;let k=g;k.next=M.next,M.next=k,M.modified=!0,M.length++,n.innards.add(N)}else g.fresh=!1;g.px=C,g.py=P,n.nx=y*E,n.ny=z*E,g.dist=d-x,g.stamp=n.stamp,g.posOnly=!1,v=g}}if(v!=null){let E=v.inner;n.ptype=2;let d=_.x-t.polygon.body.posx,b=_.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=1,s?(E.lr1x=d*t.polygon.body.axisy+b*t.polygon.body.axisx,E.lr1y=b*t.polygon.body.axisy-d*t.polygon.body.axisx,E.lr2x=e.circle.localCOMx,E.lr2y=e.circle.localCOMy):(E.lr2x=d*t.polygon.body.axisy+b*t.polygon.body.axisx,E.lr2y=b*t.polygon.body.axisy-d*t.polygon.body.axisx,E.lr1x=e.circle.localCOMx,E.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return v!=null}else{let x=e.circle.radius+l*.5,y=a.gnormx*x,z=a.gnormy*x,f=e.circle.worldCOMx-y,v=e.circle.worldCOMy-z,E;if(s){let d=a.gnormx,b=a.gnormy,C=null,P=n.contacts.next;for(;P!=null;){let g=P;if(g.hash==0){C=g;break}P=P.next}if(C==null){we.zpp_pool==null?C=new we:(C=we.zpp_pool,we.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 N=C;N.next=O.next,O.next=N,O.modified=!0,O.length++,n.innards.add(g)}else C.fresh=!1;C.px=f,C.py=v,n.nx=d,n.ny=b,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,E=C}else{let d=-a.gnormx,b=-a.gnormy,C=null,P=n.contacts.next;for(;P!=null;){let g=P;if(g.hash==0){C=g;break}P=P.next}if(C==null){we.zpp_pool==null?C=new we:(C=we.zpp_pool,we.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 N=C;N.next=O.next,O.next=N,O.modified=!0,O.length++,n.innards.add(g)}else C.fresh=!1;C.px=f,C.py=v,n.nx=d,n.ny=b,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,E=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,E.inner.lr1x=e.circle.localCOMx,E.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,r=t.circle.worldCOMx-e.circle.worldCOMx,o=t.circle.worldCOMy-e.circle.worldCOMy,a=r*r+o*o,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,_=n.contacts.next;for(;_!=null;){let m=_;if(m.hash==0){u=m;break}_=_.next}if(u==null){we.zpp_pool==null?u=new we:(u=we.zpp_pool,we.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 x=n.contacts;u._inuse=!0;let y=u;y.next=x.next,x.next=y,x.modified=!0,x.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 _=e.circle.worldCOMx+r*u,m=e.circle.worldCOMy+o*u,x=null,y=n.contacts.next;for(;y!=null;){let z=y;if(z.hash==0){x=z;break}y=y.next}if(x==null){we.zpp_pool==null?x=new we:(x=we.zpp_pool,we.zpp_pool=x.next,x.next=null);let z=x.inner;z.jnAcc=z.jtAcc=0,x.hash=0,x.fresh=!0,x.arbiter=n,n.jrAcc=0;let f=n.contacts;x._inuse=!0;let v=x;v.next=f.next,f.next=v,f.modified=!0,f.length++,n.innards.add(z)}else x.fresh=!1;x.px=_,x.py=m,n.nx=-r*c,n.ny=-o*c,x.dist=h-l,x.stamp=n.stamp,x.posOnly=!1,p=x}else{let _=e.circle.worldCOMx+r*u,m=e.circle.worldCOMy+o*u,x=null,y=n.contacts.next;for(;y!=null;){let z=y;if(z.hash==0){x=z;break}y=y.next}if(x==null){we.zpp_pool==null?x=new we:(x=we.zpp_pool,we.zpp_pool=x.next,x.next=null);let z=x.inner;z.jnAcc=z.jtAcc=0,x.hash=0,x.fresh=!0,x.arbiter=n,n.jrAcc=0;let f=n.contacts;x._inuse=!0;let v=x;v.next=f.next,f.next=v,f.modified=!0,f.length++,n.innards.add(z)}else x.fresh=!1;x.px=_,x.py=m,n.nx=r*c,n.ny=o*c,x.dist=h-l,x.stamp=n.stamp,x.posOnly=!1,p=x}}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=re();if(e.type>t.type){let s=e;e=t,t=s}return Ee.testCollide(e,t)}static testCollide(e,t){let n=re();if(t.type==1)if(e.type==1){let s=!0,i=e.polygon.edges.head;for(;i!=null;){let l=i.elt,r=1e100,o=t.polygon.gverts.next;for(;o!=null;){let a=o,p=l.gnormx*a.x+l.gnormy*a.y;p<r&&(r=p),o=o.next}if(r-=l.gprojection,r>0){s=!1;break}i=i.next}if(s){let l=t.polygon.edges.head;for(;l!=null;){let r=l.elt,o=1e100,a=e.polygon.gverts.next;for(;a!=null;){let p=a,c=r.gnormx*p.x+r.gnormy*p.y;c<o&&(o=c),a=a.next}if(o-=r.gprojection,o>0){s=!1;break}l=l.next}return s}else return!1}else{let s=null,i=null,l=!0,r=-1e100,o=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>r&&(r=c,s=p,i=o),o=o.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,_=p.x-e.circle.worldCOMx,m=p.y-e.circle.worldCOMy;return _*_+m*m<=u*u}else if(h>=c.y*s.gnormx-c.x*s.gnormy){let u=e.circle.radius,_=c.x-e.circle.worldCOMx,m=c.y-e.circle.worldCOMy;return _*_+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=re();if(t.type==1)if(e.type==1){let i=[],l=[],r=!0,o=!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 _=u,m=p.gnormx*_.x+p.gnormy*_.y;m<c&&(c=m),m>=p.gprojection+s.Config.epsilon&&(l[h]=!0,o=!1),++h,u=u.next}if(c-=p.gprojection,c>0){r=!1;break}a=a.next}if(o){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 _=.5;h.localCOMx*=_,h.localCOMy*=_}else{h.localCOMx=0,h.localCOMy=0;let u=0,_=h.lverts.next,m=_;_=_.next;let x=_;for(_=_.next;_!=null;){let d=_;u+=x.x*(d.y-m.y);let b=d.y*x.x-d.x*x.y;h.localCOMx+=(x.x+d.x)*b,h.localCOMy+=(x.y+d.y)*b,m=x,x=d,_=_.next}_=h.lverts.next;let y=_;u+=x.x*(y.y-m.y);let z=y.y*x.x-y.x*x.y;h.localCOMx+=(x.x+y.x)*z,h.localCOMy+=(x.y+y.y)*z,m=x,x=y,_=_.next;let f=_;u+=x.x*(f.y-m.y);let v=f.y*x.x-f.x*x.y;h.localCOMx+=(x.x+f.x)*v,h.localCOMy+=(x.y+f.y)*v,u=1/(3*u);let E=u;h.localCOMx*=E,h.localCOMy*=E}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let c=p.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else if(r){o=!0;let p=t.polygon.edges.head;for(;p!=null;){let c=p.elt,h=1e100,u=0,_=e.polygon.gverts.next;for(;_!=null;){let m=_,x=c.gnormx*m.x+c.gnormy*m.y;x<h&&(h=x),x>=c.gprojection+s.Config.epsilon&&(i[u]=!0,o=!1),++u,_=_.next}if(h-=c.gprojection,h>0){r=!1;break}p=p.next}if(o){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 _=1;u.localCOMx+=u.lverts.next.next.x*_,u.localCOMy+=u.lverts.next.next.y*_;let m=.5;u.localCOMx*=m,u.localCOMy*=m}else{u.localCOMx=0,u.localCOMy=0;let _=0,m=u.lverts.next,x=m;m=m.next;let y=m;for(m=m.next;m!=null;){let b=m;_+=y.x*(b.y-x.y);let C=b.y*y.x-b.x*y.y;u.localCOMx+=(y.x+b.x)*C,u.localCOMy+=(y.y+b.y)*C,x=y,y=b,m=m.next}m=u.lverts.next;let z=m;_+=y.x*(z.y-x.y);let f=z.y*y.x-z.x*y.y;u.localCOMx+=(y.x+z.x)*f,u.localCOMy+=(y.y+z.y)*f,x=y,y=z,m=m.next;let v=m;_+=y.x*(v.y-x.y);let E=v.y*y.x-v.x*y.y;u.localCOMx+=(y.x+v.x)*E,u.localCOMy+=(y.y+v.y)*E,_=1/(3*_);let d=_;u.localCOMx*=d,u.localCOMy*=d}}c.wrap_localCOM!=null&&(c.wrap_localCOM.zpp_inner.x=c.localCOMx,c.wrap_localCOM.zpp_inner.y=c.localCOMy)}let h=c.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.worldCOMx=c.body.posx+(c.body.axisy*c.localCOMx-c.body.axisx*c.localCOMy),c.worldCOMy=c.body.posy+(c.localCOMx*c.body.axisx+c.localCOMy*c.body.axisy)}return n.overlap=e.polygon.area,n.centroidx=e.polygon.worldCOMx,n.centroidy=e.polygon.worldCOMy,!0}else if(r){for(;Ee.flowpoly.head!=null;){let v=Ee.flowpoly.pop_unsafe();if(!v._inuse){let E=v;E.outer!=null&&(E.outer.zpp_inner=null,E.outer=null),E._isimmutable=null,E._validate=null,E._invalidate=null,E.next=pe.zpp_pool,pe.zpp_pool=E}}let c=null,h=!1,u=e.polygon.gverts.next,_=0,m=t.polygon.gverts.next,x=0,y=0,z=t.polygon.edgeCnt;for(;y<z;){let v=y++;if(l[v])m=m.next;else{x=v;break}}if(m==null){m=t.polygon.gverts.next,h=!0;let v=0,E=e.polygon.edgeCnt;for(;v<E;){let d=v++;if(i[d])u=u.next;else{_=d;break}}u==null?u=e.polygon.gverts.next:(Ee.flowpoly.add(u),c=Ee.flowpoly.head.elt)}else Ee.flowpoly.add(m),c=Ee.flowpoly.head.elt;let f=1;if(Ee.flowpoly.head==null){let v=!0,E=e.polygon.gverts.next,d=E,b=E.next;for(;b!=null;){let C=b,P=2,g=!0,O=t.polygon.gverts.next,N=O,M=O.next;for(;M!=null;){let k=M,Z=0,A=d.x-N.x,S=d.y-N.y,R=C.x-d.x,j=C.y-d.y,q=k.x-N.x,J=k.y-N.y,G=j*q-R*J,L;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(J*A-q*S)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(j*A-R*S)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(Z=V,L=!0):L=!1}else L=!1}else L=!1;L&&Z<P&&(P=Z,m=O),O=M,N=k,M=M.next}if(g)for(;;){M=t.polygon.gverts.next;let k=M,Z=0,A=d.x-N.x,S=d.y-N.y,R=C.x-d.x,j=C.y-d.y,q=k.x-N.x,J=k.y-N.y,G=j*q-R*J,L;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(J*A-q*S)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(j*A-R*S)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(Z=V,L=!0):L=!1}else L=!1}else L=!1;L&&Z<P&&(P=Z,m=O);break}if(P!=2){let k=P,Z=d.x+(C.x-d.x)*k,A=d.y+(C.y-d.y)*k;c=pe.get(Z,A),Ee.flowpoly.add(c),h=!0,u=E,v=!1;break}E=b,d=C,b=b.next}if(v)for(;;){b=e.polygon.gverts.next;let C=b,P=2,g=!0,O=t.polygon.gverts.next,N=O,M=O.next;for(;M!=null;){let k=M,Z=0,A=d.x-N.x,S=d.y-N.y,R=C.x-d.x,j=C.y-d.y,q=k.x-N.x,J=k.y-N.y,G=j*q-R*J,L;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(J*A-q*S)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(j*A-R*S)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(Z=V,L=!0):L=!1}else L=!1}else L=!1;L&&Z<P&&(P=Z,m=O),O=M,N=k,M=M.next}if(g)for(;;){M=t.polygon.gverts.next;let k=M,Z=0,A=d.x-N.x,S=d.y-N.y,R=C.x-d.x,j=C.y-d.y,q=k.x-N.x,J=k.y-N.y,G=j*q-R*J,L;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(J*A-q*S)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(j*A-R*S)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(Z=V,L=!0):L=!1}else L=!1}else L=!1;L&&Z<P&&(P=Z,m=O);break}if(P!=2){let k=P,Z=d.x+(C.x-d.x)*k,A=d.y+(C.y-d.y)*k;c=pe.get(Z,A),Ee.flowpoly.add(c),h=!0,u=E;break}break}f=2}for(;;)if(h)if(u=u.next,++_,u==null&&(u=e.polygon.gverts.next,_=0),i[_]){let v=Ee.flowpoly.head.elt,E=u,d=m,b=m.next;b==null&&(b=t.polygon.gverts.next);let C=-1,P=null,g=0,O=0,N=b,M=b;for(;;){let L=M,V=0,Y=d.x-v.x,$=d.y-v.y,H=L.x-d.x,X=L.y-d.y,ee=E.x-v.x,W=E.y-v.y,F=X*ee-H*W,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let T=(W*Y-ee*$)*F;if(T>s.Config.epsilon&&T<1-s.Config.epsilon){let U=(X*Y-H*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=T,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(P=m,g=x,++O==f){C=V,M=N;break}else C=V;d=L,m=M,++x,x>=t.polygon.edgeCnt&&(x=0),M=M.next,M==null&&(M=t.polygon.gverts.next);break}for(;M!=N;){let L=M,V=0,Y=d.x-v.x,$=d.y-v.y,H=L.x-d.x,X=L.y-d.y,ee=E.x-v.x,W=E.y-v.y,F=X*ee-H*W,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let T=(W*Y-ee*$)*F;if(T>s.Config.epsilon&&T<1-s.Config.epsilon){let U=(X*Y-H*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=T,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(P=m,g=x,++O==f){C=V;break}else C=V;d=L,m=M,++x,x>=t.polygon.edgeCnt&&(x=0),M=M.next,M==null&&(M=t.polygon.gverts.next)}if(P==null)break;let k=P,Z=P.next;Z==null&&(Z=t.polygon.gverts.next);let A=Z,S=C,R=k.x+(A.x-k.x)*S,j=k.y+(A.y-k.y)*S,q;if(c!=null){let L=R-c.x,V=j-c.y;q=L*L+V*V<s.Config.epsilon}else q=!1;if(q)break;let J=Ee.flowpoly,G=pe.get(R,j);J.add(G),c==null&&(c=Ee.flowpoly.head.elt),m=P,x=g,h=!h,f=2}else{let v=u,E;if(c!=null){let d=v.x-c.x,b=v.y-c.y;E=d*d+b*b<s.Config.epsilon}else E=!1;if(E)break;Ee.flowpoly.add(v),c==null&&(c=Ee.flowpoly.head.elt),f=1}else if(m=m.next,++x,m==null&&(m=t.polygon.gverts.next,x=0),l[x]){let v=Ee.flowpoly.head.elt,E=m,d=u,b=u.next;b==null&&(b=e.polygon.gverts.next);let C=-1,P=null,g=0,O=0,N=b,M=b;for(;;){let L=M,V=0,Y=d.x-v.x,$=d.y-v.y,H=L.x-d.x,X=L.y-d.y,ee=E.x-v.x,W=E.y-v.y,F=X*ee-H*W,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let T=(W*Y-ee*$)*F;if(T>s.Config.epsilon&&T<1-s.Config.epsilon){let U=(X*Y-H*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=T,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(P=u,g=_,++O==f){C=V,M=N;break}else C=V;d=L,u=M,++_,_>=e.polygon.edgeCnt&&(_=0),M=M.next,M==null&&(M=e.polygon.gverts.next);break}for(;M!=N;){let L=M,V=0,Y=d.x-v.x,$=d.y-v.y,H=L.x-d.x,X=L.y-d.y,ee=E.x-v.x,W=E.y-v.y,F=X*ee-H*W,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let T=(W*Y-ee*$)*F;if(T>s.Config.epsilon&&T<1-s.Config.epsilon){let U=(X*Y-H*$)*F;U>s.Config.epsilon&&U<1-s.Config.epsilon?(V=T,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=C)if(P=u,g=_,++O==f){C=V;break}else C=V;d=L,u=M,++_,_>=e.polygon.edgeCnt&&(_=0),M=M.next,M==null&&(M=e.polygon.gverts.next)}if(P==null)break;let k=P,Z=P.next;Z==null&&(Z=e.polygon.gverts.next);let A=Z,S=C,R=k.x+(A.x-k.x)*S,j=k.y+(A.y-k.y)*S,q;if(c!=null){let L=R-c.x,V=j-c.y;q=L*L+V*V<s.Config.epsilon}else q=!1;if(q)break;let J=Ee.flowpoly,G=pe.get(R,j);J.add(G),c==null&&(c=Ee.flowpoly.head.elt),u=P,_=g,h=!h,f=2}else{let v=m,E;if(c!=null){let d=v.x-c.x,b=v.y-c.y;E=d*d+b*b<s.Config.epsilon}else E=!1;if(E)break;Ee.flowpoly.add(v),c==null&&(c=Ee.flowpoly.head.elt),f=1}if(Ee.flowpoly.head!=null&&Ee.flowpoly.head.next!=null&&Ee.flowpoly.head.next.next!=null){let v=0,E=0,d=0,b=Ee.flowpoly.head,C=b.elt;b=b.next;let P=b.elt;for(b=b.next;b!=null;){let A=b.elt;v+=P.x*(A.y-C.y);let S=A.y*P.x-A.x*P.y;E+=(P.x+A.x)*S,d+=(P.y+A.y)*S,C=P,P=A,b=b.next}b=Ee.flowpoly.head;let g=b.elt;v+=P.x*(g.y-C.y);let O=g.y*P.x-g.x*P.y;E+=(P.x+g.x)*O,d+=(P.y+g.y)*O,C=P,P=g,b=b.next;let N=b.elt;v+=P.x*(N.y-C.y);let M=N.y*P.x-N.x*P.y;E+=(P.x+N.x)*M,d+=(P.y+N.y)*M,v*=.5;let Z=1/(6*v);return E*=Z,d*=Z,n.overlap=-v,n.centroidx=E,n.centroidy=d,!0}else return!1}else return!1}else return!1}else{let i=[],l=!0,r=null,o=null,a=-1e100,p=!0,c=t.polygon.gverts.next,h=0,u=t.polygon.edges.head;for(;u!=null;){let _=u.elt,m=_.gnormx*e.circle.worldCOMx+_.gnormy*e.circle.worldCOMy;if(m>_.gprojection+e.circle.radius){p=!1;break}else m+e.circle.radius>_.gprojection+s.Config.epsilon&&(l=!1,i[h]=!0);m-=_.gprojection+e.circle.radius,m>a&&(a=m,r=_,o=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 _=o,m=o.next==null?t.polygon.gverts.next:o.next,x=e.circle.worldCOMy*r.gnormx-e.circle.worldCOMx*r.gnormy,y;if(x<=_.y*r.gnormx-_.x*r.gnormy){let z=e.circle.radius,f=_.x-e.circle.worldCOMx,v=_.y-e.circle.worldCOMy;y=f*f+v*v<=z*z}else if(x>=m.y*r.gnormx-m.x*r.gnormy){let z=e.circle.radius,f=m.x-e.circle.worldCOMx,v=m.y-e.circle.worldCOMy;y=f*f+v*v<=z*z}else y=!0;if(y){let z=[],f=0,v=!0,E=null,d=0,b=t.polygon.gverts.next;for(;b!=null;){let C=b,P=C.x-e.circle.worldCOMx,g=C.y-e.circle.worldCOMy,O=P*P+g*g;(z[f]=O<=e.circle.radius*e.circle.radius)?(d=f,E=b):v=!1,++f,b=b.next}if(v){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 N=.5;g.localCOMx*=N,g.localCOMy*=N}else{g.localCOMx=0,g.localCOMy=0;let O=0,N=g.lverts.next,M=N;N=N.next;let k=N;for(N=N.next;N!=null;){let q=N;O+=k.x*(q.y-M.y);let J=q.y*k.x-q.x*k.y;g.localCOMx+=(k.x+q.x)*J,g.localCOMy+=(k.y+q.y)*J,M=k,k=q,N=N.next}N=g.lverts.next;let Z=N;O+=k.x*(Z.y-M.y);let A=Z.y*k.x-Z.x*k.y;g.localCOMx+=(k.x+Z.x)*A,g.localCOMy+=(k.y+Z.y)*A,M=k,k=Z,N=N.next;let S=N;O+=k.x*(S.y-M.y);let R=S.y*k.x-S.x*k.y;g.localCOMx+=(k.x+S.x)*R,g.localCOMy+=(k.y+S.y)*R,O=1/(3*O);let j=O;g.localCOMx*=j,g.localCOMy*=j}}C.wrap_localCOM!=null&&(C.wrap_localCOM.zpp_inner.x=C.localCOMx,C.wrap_localCOM.zpp_inner.y=C.localCOMy)}let P=C.body;P.zip_axis&&(P.zip_axis=!1,P.axisx=Math.sin(P.rot),P.axisy=Math.cos(P.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(;Ee.flowpoly.head!=null;){let g=Ee.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=pe.zpp_pool,pe.zpp_pool=O}}Ee.flowsegs.clear();let C=null,P=1;for(E==null?(E=t.polygon.gverts.next,P=2):(C=E,Ee.flowpoly.add(C));P!=0;)if(P==1)if(E=E.next,E==null&&(E=t.polygon.gverts.next),++d,d>=t.polygon.edgeCnt&&(d=0),z[d]){let g=C.x-E.x,O=C.y-E.y;if(g*g+O*O<s.Config.epsilon)break;Ee.flowpoly.add(E)}else{let g=Ee.flowpoly.head.elt,O=E,N=O.x-g.x,M=O.y-g.y,k=g.x-e.circle.worldCOMx,Z=g.y-e.circle.worldCOMy,A=N*N+M*M,S=2*(k*N+Z*M),R=k*k+Z*Z-e.circle.radius*e.circle.radius,j=Math.sqrt(S*S-4*A*R);A=1/(2*A);let q=(-S-j)*A,J=q<s.Config.epsilon?(-S+j)*A:q,G=0,L=0,V=J;G=g.x+(O.x-g.x)*V,L=g.y+(O.y-g.y)*V;let Y=C.x-G,$=C.y-L;if(Y*Y+$*$<s.Config.epsilon)break;let H=Ee.flowpoly,X=pe.get(G,L);H.add(X),P=2}else if(P==2){let g=E.next;g==null&&(g=t.polygon.gverts.next);let O=E;P=0;let N=g,M=g;for(;;){let k=M,Z=d+1;if(Z==t.polygon.edgeCnt&&(Z=0),i[d])if(z[Z]){let A=k.x-O.x,S=k.y-O.y,R=O.x-e.circle.worldCOMx,j=O.y-e.circle.worldCOMy,q=A*A+S*S,J=2*(R*A+j*S),G=R*R+j*j-e.circle.radius*e.circle.radius,L=Math.sqrt(J*J-4*q*G);q=1/(2*q);let V=(-J-L)*q,Y=V<s.Config.epsilon?(-J+L)*q:V,$=0,H=0,X=Y;$=O.x+(k.x-O.x)*X,H=O.y+(k.y-O.y)*X;let ee=C.x-$,W=C.y-H;if(ee*ee+W*W<s.Config.epsilon){P=0,M=N;break}let D=pe.get($,H);Ee.flowsegs.add(Ee.flowpoly.head.elt),Ee.flowsegs.add(D),Ee.flowpoly.add(D),P=1,M=N;break}else{let A=0,S=0,R=k.x-O.x,j=k.y-O.y,q=O.x-e.circle.worldCOMx,J=O.y-e.circle.worldCOMy,G=R*R+j*j,L=2*(q*R+J*j),V=q*q+J*J-e.circle.radius*e.circle.radius,Y=L*L-4*G*V,$;if(Y*Y<s.Config.epsilon?(Y<0?A=10:(S=-L/(2*G),A=S),$=!1):(Y=Math.sqrt(Y),G=1/(2*G),A=(-L-Y)*G,S=(-L+Y)*G,$=!0),A<1-s.Config.epsilon&&S>s.Config.epsilon){let H=0,X=0,ee=A;H=O.x+(k.x-O.x)*ee,X=O.y+(k.y-O.y)*ee;let W;if(C!=null){let T=C.x-H,U=C.y-X;W=T*T+U*U<s.Config.epsilon}else W=!1;if(W){P=0,M=N;break}let D=pe.get(H,X);if(Ee.flowpoly.head!=null&&(Ee.flowsegs.add(Ee.flowpoly.head.elt),Ee.flowsegs.add(D)),Ee.flowpoly.add(D),C==null&&(C=Ee.flowpoly.head.elt),$){let T=0,U=0,Q=S;T=O.x+(k.x-O.x)*Q,U=O.y+(k.y-O.y)*Q;let K=Ee.flowpoly,ie=pe.get(T,U);K.add(ie)}}}O=k,E=M,d=Z,M=M.next,M==null&&(M=t.polygon.gverts.next);break}for(;M!=N;){let k=M,Z=d+1;if(Z==t.polygon.edgeCnt&&(Z=0),i[d])if(z[Z]){let A=k.x-O.x,S=k.y-O.y,R=O.x-e.circle.worldCOMx,j=O.y-e.circle.worldCOMy,q=A*A+S*S,J=2*(R*A+j*S),G=R*R+j*j-e.circle.radius*e.circle.radius,L=Math.sqrt(J*J-4*q*G);q=1/(2*q);let V=(-J-L)*q,Y=V<s.Config.epsilon?(-J+L)*q:V,$=0,H=0,X=Y;$=O.x+(k.x-O.x)*X,H=O.y+(k.y-O.y)*X;let ee=C.x-$,W=C.y-H;if(ee*ee+W*W<s.Config.epsilon){P=0,M=N;break}let D=pe.get($,H);Ee.flowsegs.add(Ee.flowpoly.head.elt),Ee.flowsegs.add(D),Ee.flowpoly.add(D),P=1,M=N;break}else{let A=0,S=0,R=k.x-O.x,j=k.y-O.y,q=O.x-e.circle.worldCOMx,J=O.y-e.circle.worldCOMy,G=R*R+j*j,L=2*(q*R+J*j),V=q*q+J*J-e.circle.radius*e.circle.radius,Y=L*L-4*G*V,$;if(Y*Y<s.Config.epsilon?(Y<0?A=10:(S=-L/(2*G),A=S),$=!1):(Y=Math.sqrt(Y),G=1/(2*G),A=(-L-Y)*G,S=(-L+Y)*G,$=!0),A<1-s.Config.epsilon&&S>s.Config.epsilon){let H=0,X=0,ee=A;H=O.x+(k.x-O.x)*ee,X=O.y+(k.y-O.y)*ee;let W;if(C!=null){let T=C.x-H,U=C.y-X;W=T*T+U*U<s.Config.epsilon}else W=!1;if(W){P=0,M=N;break}let D=pe.get(H,X);if(Ee.flowpoly.head!=null&&(Ee.flowsegs.add(Ee.flowpoly.head.elt),Ee.flowsegs.add(D)),Ee.flowpoly.add(D),C==null&&(C=Ee.flowpoly.head.elt),$){let T=0,U=0,Q=S;T=O.x+(k.x-O.x)*Q,U=O.y+(k.y-O.y)*Q;let K=Ee.flowpoly,ie=pe.get(T,U);K.add(ie)}}}O=k,E=M,d=Z,M=M.next,M==null&&(M=t.polygon.gverts.next)}}if(Ee.flowpoly.head==null)return!1;if(Ee.flowpoly.head.next==null){let g=!0,O=t.polygon.edges.head;for(;O!=null;){let N=O.elt;if(N.gnormx*e.circle.worldCOMx+N.gnormy*e.circle.worldCOMy>N.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,N=0;if(Ee.flowpoly.head.next.next!=null){let k=0,Z=0,A=0;k=0;let S=Ee.flowpoly.head,R=S.elt;S=S.next;let j=S.elt;for(S=S.next;S!=null;){let H=S.elt;k+=j.x*(H.y-R.y);let X=H.y*j.x-H.x*j.y;Z+=(j.x+H.x)*X,A+=(j.y+H.y)*X,R=j,j=H,S=S.next}S=Ee.flowpoly.head;let q=S.elt;k+=j.x*(q.y-R.y);let J=q.y*j.x-q.x*j.y;Z+=(j.x+q.x)*J,A+=(j.y+q.y)*J,R=j,j=q,S=S.next;let G=S.elt;k+=j.x*(G.y-R.y);let L=G.y*j.x-G.x*j.y;Z+=(j.x+G.x)*L,A+=(j.y+G.y)*L,k*=.5;let Y=1/(6*k);Z*=Y,A*=Y;let $=-k;g+=Z*$,O+=A*$,N-=k}else Ee.flowsegs.add(Ee.flowpoly.head.elt),Ee.flowsegs.add(Ee.flowpoly.head.next.elt);for(;Ee.flowsegs.head!=null;){let k=Ee.flowsegs.pop_unsafe(),Z=Ee.flowsegs.pop_unsafe(),A=Z.x-k.x,S=Z.y-k.y,R=A,j=S,q=R*R+j*j,G=1/Math.sqrt(q);R*=G,j*=G;let L=R;R=-j,j=L;let V=k.x+Z.x,Y=k.y+Z.y,$=.5;V*=$,Y*=$;let H=1;V-=e.circle.worldCOMx*H,Y-=e.circle.worldCOMy*H;let X=R*V+j*Y,ee=0,W=0,F=X,D=F/e.circle.radius,T=Math.sqrt(1-D*D),U=Math.acos(D);ee=e.circle.radius*(e.circle.radius*U-F*T),W=.6666666666666666*e.circle.radius*T*T*T/(U-D*T),V=e.circle.worldCOMx,Y=e.circle.worldCOMy;let Q=W;V+=R*Q,Y+=j*Q;let K=ee;g+=V*K,O+=Y*K,N+=ee}let M=1/N;return g*=M,O*=M,n.overlap=N,n.centroidx=g,n.centroidy=O,!0}}}else return!1}}else return!1}else{let i=e.circle,l=t.circle,r=l.worldCOMx-i.worldCOMx,o=l.worldCOMy-i.worldCOMy,a=i.radius+l.radius,p=r*r+o*o;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 _=c-u;if(_<=-l.radius)n.overlap=l.area,n.centroidx=l.worldCOMx,n.centroidy=l.worldCOMy;else{let m=0,x=0,y=0,z=0,f=u,v=f/i.radius,E=Math.sqrt(1-v*v),d=Math.acos(v);m=i.radius*(i.radius*d-f*E),x=.6666666666666666*i.radius*E*E*E/(d-v*E);let b=_,C=b/l.radius,P=Math.sqrt(1-C*C),g=Math.acos(C);y=l.radius*(l.radius*g-b*P),z=.6666666666666666*l.radius*P*P*P/(g-C*P);let O=m+y,N=(x*m+(c-z)*y)/O*h;n.overlap=O,n.centroidx=i.worldCOMx+r*N,n.centroidy=i.worldCOMy+o*N}}return!0}}}};Ee.flowpoly=null,Ee.flowsegs=null;var Ze=Ee;var ml=class w{static isinner(e,t,n){let s=e.x-t.x,i=e.y-t.y,l=n.x-t.x;return(n.y-t.y)*s-l*i>=0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}let s=e.vertices,i=e.vertices;if(s!=null){let l=s;for(;;){let r=l,o=r.prev,a=null,p=r.diagonals.head;for(;p!=null;){let c=p.elt,h=p.next==null?r.next:p.next.elt;if(!w.isinner(h,r,o)){a=p,o=c,p=p.next;continue}let u=!0,_=c,m=_.prev,x=null,y=_.diagonals.head;for(;y!=null;){let z=y.elt;if(z==r){let f=y.next==null?_.next:y.next.elt;u=w.isinner(f,_,m);break}m=z,x=y,y=y.next}if(u){p=r.diagonals.erase(a),_.diagonals.erase(x);continue}o=c,a=p,p=p.next}if(l=l.next,l==i)break}}}};var ot=class ot{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;ot.rayPool==null?(ot.internal=!0,i=ot._createRayResult(),i.zpp_inner=new ot,i.zpp_inner.ray=i,ot.internal=!1):(i=ot.rayPool.ray,ot.rayPool=ot.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;ot.convexPool==null?(ot.internal=!0,i=ot._createConvexResult(),i.zpp_inner=new ot,i.zpp_inner.convex=i,ot.internal=!1):(i=ot.convexPool.convex,ot.convexPool=ot.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(){ot._disposeVec2(this.normal),this.position!=null&&ot._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=ot.convexPool,ot.convexPool=this):(this.next=ot.rayPool,ot.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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=e:ue.poolVec2=e,ue.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=pe.zpp_pool,pe.zpp_pool=n}};ot.rayPool=null,ot.convexPool=null,ot.internal=!1,ot._createRayResult=null,ot._createConvexResult=null;var jt=ot;var bs=class bs{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 bs.zpp_pool==null?t=new bs:(t=bs.zpp_pool,bs.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}};bs.zpp_pool=null;var st=bs;var zs=class zs{constructor(){this.next=null;this.time=0;this.virtualint=!1;this.vertex=!1;this.path0=null;this.end=null;this.start=null;this.path1=null}static get(e,t,n,s,i,l=!1,r=!1){let o;return zs.zpp_pool==null?o=new zs:(o=zs.zpp_pool,zs.zpp_pool=o.next,o.next=null),o.virtualint=l,o.end=t,o.start=n,o.path0=s,o.path1=i,o.time=e,o.vertex=r,o}alloc(){}free(){this.end=this.start=null,this.path0=this.path1=null}};zs.zpp_pool=null;var dt=zs;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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=s:ue.poolVec2=s,ue.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=pe.zpp_pool,pe.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(ue.poolVec2==null?n=Ri._createVec2Fn():(n=ue.poolVec2,ue.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n===ue.nextVec2&&(ue.nextVec2=null)),n.zpp_inner==null){let s;pe.zpp_pool==null?s=new pe:(s=pe.zpp_pool,pe.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x===e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y===t}else i=!1;if(!i){n.zpp_inner.x=e,n.zpp_inner.y=t;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}n.zpp_inner.weak=!1,this.wrap=n,this.wrap.zpp_inner._inuse=!0,this.wrap.zpp_inner._invalidate=s=>this.modwrap(s),this.wrap.zpp_inner._validate=()=>this.getwrap()}return this.wrap}modwrap(e){this.x=e.x,this.y=e.y}getwrap(){this.wrap.zpp_inner.x=this.x,this.wrap.zpp_inner.y=this.y}};Ri.zpp_pool=null,Ri._createVec2Fn=null;var ge=Ri;var rt=class rt{static run(e,t,n,s,i,l){let r=re(),o=r.__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 _=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 x=n.zpp_inner.y-h,y=s?0:-1/0,z=i?1:1/0,f=-(h*_-p*x),v=null,E=!1,d=e;for(;;){let L;st.zpp_pool==null?L=new st:(L=st.zpp_pool,st.zpp_pool=L.next,L.next=null),L.vert=d,L.posx=d.x,L.posy=d.y,L.value=L.posy*_-L.posx*x+f,L.positive=L.value>0,L.value==0&&(E=!0);let V=L;if(v==null?V.prev=V.next=V:(V.prev=v,V.next=v.next,v.next.prev=V,v.next=V),v=V,d=d.next,d==e)break}if(E){let L=null,V=v,Y=v;if(V!=null){let U=V;for(;;){let Q=U;if(Q.value!=0){L=Q;break}if(U=U.next,U==Y)break}}let $,H;$=_,H=x;let X=$*$+H*H,W=1/Math.sqrt(X);$*=W,H*=W;let F=$;$=-H,H=F;let D=null,T=L;for(;;){if(T.value!=0&&(D==null||T==D.next)){if(D=T,T=T.next,T==L)break;continue}let U=D.value*T.value;if(U==0){if(T=T.next,T==L)break;continue}let Q=D.next,K;if(U>0)K=D.positive;else{let se=Q.next,ne,ae;ne=Q.posx+se.posx,ae=Q.posy+se.posy;let le=.5;ne*=le,ae*=le;let _e=ne+$*1e-8,ce=ae+H*1e-8,he=!1,te=e,xe=e;if(te!=null){let de=te;for(;;){let me=de,Ce=me.prev;if((me.y<ce&&Ce.y>=ce||Ce.y<ce&&me.y>=ce)&&(me.x<=_e||Ce.x<=_e)&&me.x+(ce-me.y)/(Ce.y-me.y)*(Ce.x-me.x)<_e&&(he=!he),de=de.next,de==xe)break}}K=he}let ie=Q,oe=T;if(ie!=null){let se=ie;for(;;){let ne=se;if(ne.positive=K,se=se.next,se==oe)break}}if(D=T,T=T.next,T==L)break}for(;!(T.value!=0&&(D==null||T==D.next));){let U=D.value*T.value;if(U==0)break;let Q=D.next,K;if(U>0)K=D.positive;else{let se=Q.next,ne,ae;ne=Q.posx+se.posx,ae=Q.posy+se.posy;let le=.5;ne*=le,ae*=le;let _e=ne+$*1e-8,ce=ae+H*1e-8,he=!1,te=e,xe=e;if(te!=null){let de=te;for(;;){let me=de,Ce=me.prev;if((me.y<ce&&Ce.y>=ce||Ce.y<ce&&me.y>=ce)&&(me.x<=_e||Ce.x<=_e)&&me.x+(ce-me.y)/(Ce.y-me.y)*(Ce.x-me.x)<_e&&(he=!he),de=de.next,de==xe)break}}K=he}let ie=Q,oe=T;if(ie!=null){let se=ie;for(;;){let ne=se;if(ne.positive=K,se=se.next,se==oe)break}}break}}rt.ints==null&&(rt.ints=new o.util.ZNPList_ZPP_CutInt),rt.paths==null&&(rt.paths=new o.util.ZNPList_ZPP_CutVert);let b=null,C=v.posx,P=v.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=P;let O=g;O.prev=O.next=O,b=O;let N=b,M;st.zpp_pool==null?M=new st:(M=st.zpp_pool,st.zpp_pool=M.next,M.next=null),M.vert=b,M.parent=M,M.rank=0,M.used=!1;let k=M;rt.paths.add(k);let Z=v;for(;;){let L=Z.next,V=L.posx,Y=L.posy,$;ge.zpp_pool==null?$=new ge:($=ge.zpp_pool,ge.zpp_pool=$.next,$.next=null),$.forced=!1,$.x=V,$.y=Y;let H=$;if(Z.positive==L.positive){let X=H;b==null?(X.prev=X.next=X,b=X):(X.next=b,X.prev=b.prev,b.prev.next=X,b.prev=X)}else{let X=L.posx-Z.posx,ee=L.posy-Z.posy,W=x*X-_*ee;W=1/W;let F=p-Z.posx,D=h-Z.posy,T=(ee*F-X*D)*W;if(T<y||T>z){let U=rt.ints,Q=!0;Q==null&&(Q=!1);let K;dt.zpp_pool==null?K=new dt:(K=dt.zpp_pool,dt.zpp_pool=K.next,K.next=null),K.virtualint=Q,K.end=null,K.start=null,K.path0=null,K.path1=null,K.time=T,K.vertex=!1,U.add(K);let ie=H;b==null?(ie.prev=ie.next=ie,b=ie):(ie.next=b,ie.prev=b.prev,b.prev.next=ie,b.prev=ie)}else if(Z.value==0){let U=b.prev;b=null;let Q=U.x,K=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=K;let oe=ie;oe.prev=oe.next=oe,b=oe;let se=H;b==null?(se.prev=se.next=se,b=se):(se.next=b,se.prev=b.prev,b.prev.next=se,b.prev=se);let ne=rt.paths.head.elt,ae=rt.paths,le;st.zpp_pool==null?le=new st:(le=st.zpp_pool,st.zpp_pool=le.next,le.next=null),le.vert=b,le.parent=le,le.rank=0,le.used=!1,ae.add(le);let _e=rt.paths.head.elt,ce=rt.ints,he=!0;he==null&&(he=!1);let te;dt.zpp_pool==null?te=new dt:(te=dt.zpp_pool,dt.zpp_pool=te.next,te.next=null),te.virtualint=he,te.end=U,te.start=b,te.path0=ne,te.path1=_e,te.time=T,te.vertex=!1,ce.add(te)}else if(L.value==0){let U=H;b==null?(U.prev=U.next=U,b=U):(U.next=b,U.prev=b.prev,b.prev.next=U,b.prev=U);let Q=b.prev;b=null;let K=L.posx,ie=L.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=K,oe.y=ie;let se=oe;se.prev=se.next=se,b=se;let ne=rt.paths.head.elt,ae=rt.paths,le;st.zpp_pool==null?le=new st:(le=st.zpp_pool,st.zpp_pool=le.next,le.next=null),le.vert=b,le.parent=le,le.rank=0,le.used=!1,ae.add(le);let _e=rt.paths.head.elt,ce=rt.ints,he=!0;he==null&&(he=!1);let te;dt.zpp_pool==null?te=new dt:(te=dt.zpp_pool,dt.zpp_pool=te.next,te.next=null),te.virtualint=he,te.end=Q,te.start=b,te.path0=ne,te.path1=_e,te.time=T,te.vertex=!1,ce.add(te)}else{let U=(x*F-_*D)*W,Q,K;Q=Z.posx,K=Z.posy;let ie=U;Q+=X*ie,K+=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=K;let se=oe;b==null?(se.prev=se.next=se,b=se):(se.next=b,se.prev=b.prev,b.prev.next=se,b.prev=se);let ne=b.prev;b=null;let ae;ge.zpp_pool==null?ae=new ge:(ae=ge.zpp_pool,ge.zpp_pool=ae.next,ae.next=null),ae.forced=!1,ae.x=Q,ae.y=K;let le=ae;le.prev=le.next=le,b=le;let _e=H;b==null?(_e.prev=_e.next=_e,b=_e):(_e.next=b,_e.prev=b.prev,b.prev.next=_e,b.prev=_e);let ce=rt.paths.head.elt,he=rt.paths,te;st.zpp_pool==null?te=new st:(te=st.zpp_pool,st.zpp_pool=te.next,te.next=null),te.vert=b,te.parent=te,te.rank=0,te.used=!1,he.add(te);let xe=rt.paths.head.elt,de=rt.ints,me=!1;me==null&&(me=!1);let Ce;dt.zpp_pool==null?Ce=new dt:(Ce=dt.zpp_pool,dt.zpp_pool=Ce.next,Ce.next=null),Ce.virtualint=me,Ce.end=ne,Ce.start=b,Ce.path0=ce,Ce.path1=xe,Ce.time=T,Ce.vertex=!1,de.add(Ce)}}if(Z=Z.next,Z==v)break}let A=b.prev;A.next.prev=N.prev,N.prev.next=A.next,A.next=N,N.prev=A;let S=rt.paths.head.elt,R;if(k==k.parent)R=k;else{let L=k,V=null;for(;L!=L.parent;){let Y=L.parent;L.parent=V,V=L,L=Y}for(;V!=null;){let Y=V.parent;V.parent=L,V=Y}R=L}let j;if(S==S.parent)j=S;else{let L=S,V=null;for(;L!=L.parent;){let Y=L.parent;L.parent=V,V=L,L=Y}for(;V!=null;){let Y=V.parent;V.parent=L,V=Y}j=L}R!=j&&(R.rank<j.rank?R.parent=j:R.rank>j.rank?j.parent=R:(j.parent=R,R.rank++));let q=rt.ints;if(q.head!=null&&q.head.next!=null){let L=q.head,V,Y,$,H,X=1,ee,W,F;for(;;){for(ee=0,Y=L,L=null,V=L;Y!=null;){for(++ee,$=Y,W=0,F=X;$!=null&&W<X;)++W,$=$.next;for(;W>0||F>0&&$!=null;)W==0?(H=$,$=$.next,--F):F==0||$==null||Y.elt.time<$.elt.time?(H=Y,Y=Y.next,--W):(H=$,$=$.next,--F),V!=null?V.next=H:L=H,V=H;Y=$}if(V.next=null,X<<=1,!(ee>1))break}q.head=L,q.modified=!0,q.pushmod=!0}for(;rt.ints.head!=null;){let L=rt.ints.pop_unsafe(),V=rt.ints.pop_unsafe();if(!L.virtualint&&!V.virtualint){L.end.next.prev=V.start.prev,V.start.prev.next=L.end.next,L.end.next=V.start,V.start.prev=L.end,V.end.next.prev=L.start.prev,L.start.prev.next=V.end.next,V.end.next=L.start,L.start.prev=V.end;let H;if(L.path0==L.path0.parent)H=L.path0;else{let F=L.path0,D=null;for(;F!=F.parent;){let T=F.parent;F.parent=D,D=F,F=T}for(;D!=null;){let T=D.parent;D.parent=F,D=T}H=F}let X;if(V.path1==V.path1.parent)X=V.path1;else{let F=V.path1,D=null;for(;F!=F.parent;){let T=F.parent;F.parent=D,D=F,F=T}for(;D!=null;){let T=D.parent;D.parent=F,D=T}X=F}H!=X&&(H.rank<X.rank?H.parent=X:H.rank>X.rank?X.parent=H:(X.parent=H,H.rank++));let ee;if(L.path1==L.path1.parent)ee=L.path1;else{let F=L.path1,D=null;for(;F!=F.parent;){let T=F.parent;F.parent=D,D=F,F=T}for(;D!=null;){let T=D.parent;D.parent=F,D=T}ee=F}let W;if(V.path0==V.path0.parent)W=V.path0;else{let F=V.path0,D=null;for(;F!=F.parent;){let T=F.parent;F.parent=D,D=F,F=T}for(;D!=null;){let T=D.parent;D.parent=F,D=T}W=F}ee!=W&&(ee.rank<W.rank?ee.parent=W:ee.rank>W.rank?W.parent=ee:(W.parent=ee,ee.rank++))}else if(L.virtualint&&!V.virtualint){let H;if(V.end!=null&&V.end.prev==V.end){V.end.next=V.end.prev=null;let W=V.end;if(W.wrap!=null){W.wrap.zpp_inner._inuse=!1;let F=W.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 T=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let U=F;U.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=U:ue.poolVec2=U,ue.nextVec2=U,U.zpp_disp=!0;let Q=T;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=pe.zpp_pool,pe.zpp_pool=Q,W.wrap=null}W.prev=W.next=null,W.next=ge.zpp_pool,ge.zpp_pool=W,H=null}else{let W=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 T=D.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,V.end=null,H=W}if(V.end=H,!V.vertex)if(V.end!=V.path0.vert){V.start.x=V.end.x,V.start.y=V.end.y;let W;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 T=D.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,W=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 T=D.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let U=T.zpp_inner;if(U._immutable)throw new Error("Error: Vec2 is immutable");if(U._isimmutable!=null&&U._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let Q=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let K=T;K.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=K:ue.poolVec2=K,ue.nextVec2=K,K.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=pe.zpp_pool,pe.zpp_pool=ie,D.wrap=null}D.prev=D.next=null,D.next=ge.zpp_pool,ge.zpp_pool=D,V.end=null,W=F}V.end=W}else{let W=V.start.next;if(V.start.x=W.x,V.start.y=W.y,W!=null&&W.prev==W){W.next=W.prev=null;let F=W;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 T=D.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}else{W.prev.next=W.next,W.next.prev=W.prev,W.next=W.prev=null;let F=W;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 T=D.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,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 W=V.path0,F=null;for(;W!=W.parent;){let D=W.parent;W.parent=F,F=W,W=D}for(;F!=null;){let D=F.parent;F.parent=W,F=D}X=W}let ee;if(V.path1==V.path1.parent)ee=V.path1;else{let W=V.path1,F=null;for(;W!=W.parent;){let D=W.parent;W.parent=F,F=W,W=D}for(;F!=null;){let D=F.parent;F.parent=W,F=D}ee=W}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&&!L.virtualint){let H;if(L.end!=null&&L.end.prev==L.end){L.end.next=L.end.prev=null;let W=L.end;if(W.wrap!=null){W.wrap.zpp_inner._inuse=!1;let F=W.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 T=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let U=F;U.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=U:ue.poolVec2=U,ue.nextVec2=U,U.zpp_disp=!0;let Q=T;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=pe.zpp_pool,pe.zpp_pool=Q,W.wrap=null}W.prev=W.next=null,W.next=ge.zpp_pool,ge.zpp_pool=W,H=null}else{let W=L.end.prev;L.end.prev.next=L.end.next,L.end.next.prev=L.end.prev,L.end.next=L.end.prev=null;let F=L.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 T=D.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,L.end=null,H=W}if(L.end=H,!L.vertex)if(L.end!=L.path0.vert){L.start.x=L.end.x,L.start.y=L.end.y;let W;if(L.end!=null&&L.end.prev==L.end){L.end.next=L.end.prev=null;let F=L.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 T=D.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F,W=null}else{let F=L.end.prev;L.end.prev.next=L.end.next,L.end.next.prev=L.end.prev,L.end.next=L.end.prev=null;let D=L.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let T=D.wrap;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let U=T.zpp_inner;if(U._immutable)throw new Error("Error: Vec2 is immutable");if(U._isimmutable!=null&&U._isimmutable(),T.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let Q=T.zpp_inner;T.zpp_inner.outer=null,T.zpp_inner=null;let K=T;K.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=K:ue.poolVec2=K,ue.nextVec2=K,K.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=pe.zpp_pool,pe.zpp_pool=ie,D.wrap=null}D.prev=D.next=null,D.next=ge.zpp_pool,ge.zpp_pool=D,L.end=null,W=F}L.end=W}else{let W=L.start.next;if(L.start.x=W.x,L.start.y=W.y,W!=null&&W.prev==W){W.next=W.prev=null;let F=W;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 T=D.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}else{W.prev.next=W.next,W.next.prev=W.prev,W.next=W.prev=null;let F=W;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 T=D.zpp_inner;if(T._immutable)throw new Error("Error: Vec2 is immutable");if(T._isimmutable!=null&&T._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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ge.zpp_pool,ge.zpp_pool=F}}L.end.next.prev=L.start.prev,L.start.prev.next=L.end.next,L.end.next=L.start,L.start.prev=L.end;let X;if(L.path0==L.path0.parent)X=L.path0;else{let W=L.path0,F=null;for(;W!=W.parent;){let D=W.parent;W.parent=F,F=W,W=D}for(;F!=null;){let D=F.parent;F.parent=W,F=D}X=W}let ee;if(L.path1==L.path1.parent)ee=L.path1;else{let W=L.path1,F=null;for(;W!=W.parent;){let D=W.parent;W.parent=F,F=W,W=D}for(;F!=null;){let D=F.parent;F.parent=W,F=D}ee=W}X!=ee&&(X.rank<ee.rank?X.parent=ee:X.rank>ee.rank?ee.parent=X:(ee.parent=X,X.rank++))}let Y=L;Y.end=Y.start=null,Y.path0=Y.path1=null,Y.next=dt.zpp_pool,dt.zpp_pool=Y;let $=V;$.end=$.start=null,$.path0=$.path1=null,$.next=dt.zpp_pool,dt.zpp_pool=$}let J=l??new r.geom.GeomPolyList,G=rt.paths.head;for(;G!=null;){let L=G.elt,V;if(L==L.parent)V=L;else{let H=L,X=null;for(;H!=H.parent;){let ee=H.parent;H.parent=X,X=H,H=ee}for(;X!=null;){let ee=X.parent;X.parent=H,X=ee}V=H}if(V.used){G=G.next;continue}V.used=!0;let Y=V.vert,$=!0;for(;V.vert!=null&&($||Y!=V.vert);)if($=!1,Y.x==Y.next.x&&Y.y==Y.next.y)if(Y==V.vert&&(V.vert=Y.next==Y?null:Y.next,$=!0),Y!=null&&Y.prev==Y)Y.next=Y.prev=null,Y=null;else{let H=Y.next;Y.prev.next=Y.next,Y.next.prev=Y.prev,Y.next=Y.prev=null,Y=H}else Y=Y.next;if(V.vert!=null){let H=r.geom.GeomPoly.get();H.zpp_inner.vertices=V.vert,J.zpp_inner.reverse_flag?J.push(H):J.unshift(H)}G=G.next}for(;rt.paths.head!=null;){let V=rt.paths.pop_unsafe();V.vert=null,V.parent=null,V.next=st.zpp_pool,st.zpp_pool=V}for(;v!=null;)if(v!=null&&v.prev==v){v.next=v.prev=null;let L=v;L.vert=null,L.parent=null,L.next=st.zpp_pool,st.zpp_pool=L,v=null}else{let L=v.next;v.prev.next=v.next,v.next.prev=v.prev,v.next=v.prev=null;let V=v;V.vert=null,V.parent=null,V.next=st.zpp_pool,st.zpp_pool=V,v=L}return J}};rt.ints=null,rt.paths=null;var fl=rt;var an=class w{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 r=t.gverts.next,o=s.elt;o.gp0=l,o.gp1=r,o.gnormx=t.body.axisy*o.lnormx-t.body.axisx*o.lnormy,o.gnormy=o.lnormx*t.body.axisx+o.lnormy*t.body.axisy,o.gprojection=t.body.posx*o.gnormx+t.body.posy*o.gnormy+o.lprojection,o.wrap_gnorm!=null&&(o.wrap_gnorm.zpp_inner.x=o.gnormx,o.wrap_gnorm.zpp_inner.y=o.gnormy),o.tp0=o.gp0.y*o.gnormx-o.gp0.x*o.gnormy,o.tp1=o.gp1.y*o.gnormx-o.gp1.x*o.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;w._validateWorldCOM(t);let n=t.radius,s=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-s,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+s}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,r=t.gverts.next;for(;r!=null;){let o=r,a=l;l=l.next,o.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),o.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),r=r.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next}}if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type==1&&w._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&&w._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy));let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}static _computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null){e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;let t=1;e.localCOMx+=e.lverts.next.next.x*t,e.localCOMy+=e.lverts.next.next.y*t;let n=.5;e.localCOMx*=n,e.localCOMy*=n}else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let c=n;t+=i.x*(c.y-s.y);let h=c.y*i.x-c.x*i.y;e.localCOMx+=(i.x+c.x)*h,e.localCOMy+=(i.y+c.y)*h,s=i,i=c,n=n.next}n=e.lverts.next;let l=n;t+=i.x*(l.y-s.y);let r=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*r,e.localCOMy+=(i.y+l.y)*r,s=i,i=l,n=n.next;let o=n;t+=i.x*(o.y-s.y);let a=o.y*i.x-o.x*i.y;e.localCOMx+=(i.x+o.x)*a,e.localCOMy+=(i.y+o.y)*a,t=1/(3*t);let p=t;e.localCOMx*=p,e.localCOMy*=p}}};var bl=class{constructor(e=null){this.outer=null;this.vertices=null;this.outer=e}};var ei=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}};ei.zpp_pool=null;var ti=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(){}};ti.zpp_pool=null;var Pe=class Pe{static _init(e,t){Pe._zpp=e,Pe._nape=t,Pe.me=new Pe,Pe.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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=i:ue.poolVec2=i,ue.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=pe.zpp_pool,pe.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 ei.zpp_pool==null?e=new ei:(e=ei.zpp_pool,ei.zpp_pool=e.next,e.next=null),e.out=!1,e.rank=0,e}static _allocPair(){let e;return ti.zpp_pool==null?e=new ti:(e=ti.zpp_pool,ti.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=ti.zpp_pool,ti.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=Pe._findRoot(e),s=Pe._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}static _pushVert(e,t){return e==null?t.prev=t.next=t:(t.prev=e,t.next=e.next,e.next.prev=t,e.next=t),t}static _isDegenKey(e){return e==1||e==4||e==16||e==64||e==3||e==12||e==48||e==192||e==129||e==6||e==24||e==96||e==5||e==20||e==80||e==65||e==17||e==68}static ISO(e,t,n){return e(t,n)}static run(e,t,n,s,i,l,r,o,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,_=u|0;c!=h&&++h,u!=_&&++_,o&&(Pe.map==null?Pe.map=new al(h,_):Pe.map.resize(h,_,null)),Pe.isos==null?Pe.isos=new rl(h+1,_+1):Pe.isos.resize(h+1,_+1,0);for(let y=0;y<_+1;y++){let z;if(y==0)z=n;else if(y<=_){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(),z=n+l.zpp_inner.y*y}else z=i;for(let f=0;f<h+1;f++){let v;if(f==0)v=t;else if(f<=h){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let b=l.zpp_inner;b._validate!=null&&b._validate(),v=t+l.zpp_inner.x*f}else v=s;let E=Pe.isos,d=e(v,z);E.list[y*E.width+f]=d}}Pe.ints==null?Pe.ints=new ol(h+1,(_<<1)+1):Pe.ints.resize(h+1,(_<<1)+1,null);let m=null;o&&(m=Pe._allocSpan(),m.next=null);let x=n;for(let y=0;y<_;y++){let z=x,f;if(y==_-1)f=i;else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let d=l.zpp_inner;d._validate!=null&&d._validate(),f=n+l.zpp_inner.y*(y+1)}x=f;let v=t,E=null;for(let d=0;d<h;d++){let b=v,C;if(d==h-1)C=s;else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let k=l.zpp_inner;k._validate!=null&&k._validate(),C=t+l.zpp_inner.x*(d+1)}v=C;let P=d==0||!o,g=y==0||!o,O=d==h-1||!o,N=y==_-1||!o,M=Pe.me.marchSquare(e,Pe.isos,Pe.ints,b,z,C,f,d,y,P,g,O,N,r);if(M==null){E=null;continue}if(o){let k=M.p2!=null&&M.okey2!=14?M.p2:M.p1;M.pd=((k==M.p2?M.okey2:M.okey1)&128)==0?k.prev:k.prev.prev;let Z=Pe.map;Z.list[y*Z.width+d]=M;let A;if(E!=null){let j=M.key1,q=j&1|(j&192)>>5,J=0;(q&1)!=0&&++J,(q&2)!=0&&++J,(q&4)!=0&&++J,A=J>=2}else A=!1;A?(Pe.me.combLR(E,M),M.span1=E.spanr):(M.span1=Pe._allocSpan(),M.span1.next=m,m=M.span1),M.p2!=null?(M.span2=Pe._allocSpan(),M.span2.next=m,m=M.span2,M.spanr=M.span2):M.spanr=M.span1;let S=(M.keyr&28)>>2,R=0;(S&1)!=0&&++R,(S&2)!=0&&++R,(S&4)!=0&&++R,R>=2?E=M:E=null}else Pe.me.output(a,M.p1),M.p2!=null&&Pe.me.output(a,M.p2),Pe._freePair(M)}}if(o){for(let y=1;y<_;y++){let z=null;for(let f=0;f<h;f++){let v=Pe.map,E=v.list[y*v.width+f];if(E==null){z=null;continue}let b=(E.p2!=null&&E.okey2==14?E.okey2:E.okey1)&7,C=0;if((b&1)!=0&&++C,(b&2)!=0&&++C,(b&4)!=0&&++C,C<2){z=null;continue}let P=Pe.map,g=P.list[(y-1)*P.width+f];if(g==null){z=null;continue}let N=((g.p2!=null&&g.okey2==56?g.okey2:g.okey1)&112)>>4,M=0;if((N&1)!=0&&++M,(N&2)!=0&&++M,(N&4)!=0&&++M,M<2){z=null;continue}let k=g.p2!=null&&g.okey2==56?g.span2:g.span1,Z=E.p2!=null&&E.okey2==14?E.span2:E.span1,A=Pe._findRoot(k),S=Pe._findRoot(Z);A==S?z!=Z&&Pe.me.combUD_virtual(g,E):(Pe._union(k,Z),Pe.me.combUD(g,E)),z=((Z==E.span2?E.okey2:E.okey1)&4)!=0?Z:null}}for(let y=0;y<_;y++)for(let z=0;z<h;z++){let f=Pe.map,v=f.list[y*f.width+z];if(v==null)continue;let E=Pe._findRoot(v.span1);E.out||(E.out=!0,Pe.me.output(a,v.p1)),v.p2!=null&&(E=Pe._findRoot(v.span2),E.out||(E.out=!0,Pe.me.output(a,v.p2))),Pe._freePair(v),f.list[y*f.width+z]=null}for(;m!=null;){let y=m;m=y.next;let z=y;z.parent=z,z.next=ei.zpp_pool,ei.zpp_pool=z}}}output(e,t){let n=Pe._nape,s;if(t==null||t.next==t||t.next==t.prev)s=!0;else{let r=0,o=t,a=t;if(o!=null){let c=o;for(;;){let h=c;if(r+=h.x*(h.next.y-h.prev.y),c=c.next,c==a)break}}let p=r*.5;s=p*p<n.Config.epsilon*n.Config.epsilon}if(s){for(;t!=null;)if(t!=null&&t.prev==t)t.next=t.prev=null,t=null;else{let r=t.next;t.prev.next=t.next,t.next.prev=t.prev,t.next=t.prev=null,t=r}return}let i=n.geom.GeomPoly.get();i.zpp_inner.vertices=t;let l=e;l.zpp_inner.reverse_flag?l.push(i):l.unshift(i)}linkright(e,t){let n=t&7;return n==0?e:n==3?e.next.next:e.next}linkleft(e,t){return(t&1)==0?e.prev:e}linkdown(e,t){return(t&128)==0?e.prev:e.prev.prev}linkup(e,t){return e}combLR(e,t){let n=e.pr,s=e.okeyr&7,i=s==0?n:s==3?n.next.next:n.next,l=t.p1,r=(t.okey1&1)==0?l.prev:l,o=i.next,a=r.prev;(e.keyr&4)!=0?(t.pr==t.p1&&(t.pr=i.prev),t.p1=i.prev,i.prev.next=r.next,r.next.prev=i.prev,Pe._freeVert(i)):(i.next=r.next,r.next.prev=i),Pe._freeVert(r),(e.keyr&16)!=0?(t.pd=o.next,o.next.prev=a.prev,a.prev.next=o.next,Pe._freeVert(o)):(o.prev=a.prev,a.prev.next=o),Pe._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,Pe._freeVert(n),l.prev=i.prev,i.prev.next=l,i==e.p1&&(e.p1=l),Pe._freeVert(i)}combUD_virtual(e,t){let n=e.pd,s=t.p2!=null&&t.key2==14?t.p2:t.p1,i=n.prev,l=s.next;n.forced=s.forced=i.forced=l.forced=!0}combLeft(e){let t=e&1|(e&192)>>5,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combRight(e){let t=(e&28)>>2,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combUp(e){let t=e&7,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combDown(e){let t=(e&112)>>4,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}comb(e){let t=0;return(e&1)!=0&&++t,(e&2)!=0&&++t,(e&4)!=0&&++t,t>=2}_buildPoly(e,t,n,s,i,l,r,o,a,p,c,h,u,_,m,x,y,z,f){let v=null;for(let E=0;E<8;E++)if((e&1<<E)!=0){let d;if(E==0)d=Pe._allocVert(s,i),(_||m)&&(d.forced=!0);else if(E==2)d=Pe._allocVert(l,i),(x||m)&&(d.forced=!0);else if(E==4)d=Pe._allocVert(l,r),(x||y)&&(d.forced=!0);else if(E==6)d=Pe._allocVert(s,r),(_||y)&&(d.forced=!0);else if(E==1){if(d=n.list[(a<<1)*n.width+o],d==null){let b=this.xlerp(s,l,i,p,c,z,f);d=Pe._allocVert(b,i),n.list[(a<<1)*n.width+o]=d}else d=Pe._allocVert(d.x,d.y);m&&(d.forced=!0),(d.x==s||d.x==l)&&(d.x==s&&(e&1)!=0||d.x==l&&(e&4)!=0)&&(e^=2)}else if(E==5){if(d=n.list[((a<<1)+2)*n.width+o],d==null){let b=this.xlerp(s,l,r,u,h,z,f);d=Pe._allocVert(b,r),n.list[((a<<1)+2)*n.width+o]=d}else d=Pe._allocVert(d.x,d.y);y&&(d.forced=!0),(d.x==s||d.x==l)&&(d.x==s&&(e&64)!=0||d.x==l&&(e&16)!=0)&&(e^=32)}else if(E==3){if(d=n.list[((a<<1)+1)*n.width+(o+1)],d==null){let b=this.ylerp(i,r,l,c,h,z,f);d=Pe._allocVert(l,b),n.list[((a<<1)+1)*n.width+(o+1)]=d}else d=Pe._allocVert(d.x,d.y);x&&(d.forced=!0),(d.y==i||d.y==r)&&(d.y==i&&(e&4)!=0||d.y==r&&(e&16)!=0)&&(e^=8)}else{if(d=n.list[((a<<1)+1)*n.width+o],d==null){let b=this.ylerp(i,r,s,p,u,z,f);d=Pe._allocVert(s,b),n.list[((a<<1)+1)*n.width+o]=d}else d=Pe._allocVert(d.x,d.y);_&&(d.forced=!0),(d.y==i||d.y==r)&&(d.y==i&&(e&1)!=0||d.y==r&&(e&64)!=0)&&(e^=128)}v=Pe._pushVert(v,d)}return v!=null&&(v=v.next),{head:v,val:e}}marchSquare(e,t,n,s,i,l,r,o,a,p,c,h,u,_){let m=0,x=t.list[a*t.width+o];x<0&&(m|=8);let y=t.list[a*t.width+(o+1)];y<0&&(m|=4);let z=t.list[(a+1)*t.width+(o+1)];z<0&&(m|=2);let f=t.list[(a+1)*t.width+o];if(f<0&&(m|=1),m==0)return null;let v=Pe._allocPair();if(m!=10&&m!=5){let E=Pe.look_march[m];v.okey1=E;let d=this._buildPoly(E,t,n,s,i,l,r,o,a,x,y,z,f,p,c,h,u,e,_);v.p1=d.head,E=d.val,v.key1=E,Pe._isDegenKey(E)&&(E=0,v.key1=0,v.p1=null),E==0?v=null:(v.pr=v.p1,v.okeyr=v.okey1,v.keyr=v.key1)}else{let E=e(.5*(s+l),.5*(i+r))<0;if(m==10)if(E){let d=187;v.okey1=d;let b=this._buildPoly(d,t,n,s,i,l,r,o,a,x,y,z,f,p,c,h,u,e,_);v.p1=b.head,d=b.val,v.key1=d,Pe._isDegenKey(d)&&(d=0,v.key1=0,v.p1=null),d==0?v=null:(v.pr=v.p1,v.okeyr=v.okey1,v.keyr=v.key1)}else{let d=131;v.okey1=d;let b=this._buildPoly(d,t,n,s,i,l,r,o,a,x,y,z,f,p,c,h,u,e,_);if(v.p1=b.head,d=b.val,v.key1=d,Pe._isDegenKey(d)&&(d=0,v.key1=0,v.p1=null),d!=0){let C=56;v.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,r,o,a,x,y,z,f,p,c,h,u,e,_,v).val,v.key2=C,Pe._isDegenKey(C)&&(C=0,v.key2=0,v.p2=null),C==0?(v.pr=v.p1,v.okeyr=v.okey1,v.keyr=v.key1):(v.pr=v.p2,v.okeyr=v.okey2,v.keyr=v.key2)}else{let C=56;v.okey1=C;let P=this._buildPoly(C,t,n,s,i,l,r,o,a,x,y,z,f,p,c,h,u,e,_);v.p1=P.head,C=P.val,v.key1=C,Pe._isDegenKey(C)&&(C=0,v.key1=0,v.p1=null),C==0?v=null:(v.pr=v.p1,v.okeyr=v.okey1,v.keyr=v.key1)}}else if(E){let d=238;v.okey1=d;let b=this._buildPoly(d,t,n,s,i,l,r,o,a,x,y,z,f,p,c,h,u,e,_);v.p1=b.head,d=b.val,v.key1=d,Pe._isDegenKey(d)&&(d=0,v.key1=0,v.p1=null),d==0?v=null:(v.pr=v.p1,v.okeyr=v.okey1,v.keyr=v.key1)}else{let d=224;v.okey1=d;let b=this._buildPoly(d,t,n,s,i,l,r,o,a,x,y,z,f,p,c,h,u,e,_);if(v.p1=b.head,d=b.val,v.key1=d,Pe._isDegenKey(d)&&(d=0,v.key1=0,v.p1=null),d!=0){let C=14;v.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,r,o,a,x,y,z,f,p,c,h,u,e,_,v).val,v.key2=C,Pe._isDegenKey(C)&&(C=0,v.key2=0,v.p2=null),C==0?(v.pr=v.p1,v.okeyr=v.okey1,v.keyr=v.key1):(v.pr=v.p2,v.okeyr=v.okey2,v.keyr=v.key2)}else{let C=14;v.okey1=C;let P=this._buildPoly(C,t,n,s,i,l,r,o,a,x,y,z,f,p,c,h,u,e,_);v.p1=P.head,C=P.val,v.key1=C,Pe._isDegenKey(C)&&(C=0,v.key1=0,v.p1=null),C==0?v=null:(v.pr=v.p1,v.okeyr=v.okey1,v.keyr=v.key1)}}}return v}_buildPoly2(e,t,n,s,i,l,r,o,a,p,c,h,u,_,m,x,y,z,f,v){for(let E=0;E<8;E++)if((e&1<<E)!=0){let d;if(E==0)d=Pe._allocVert(s,i),(_||m)&&(d.forced=!0);else if(E==2)d=Pe._allocVert(l,i),(x||m)&&(d.forced=!0);else if(E==4)d=Pe._allocVert(l,r),(x||y)&&(d.forced=!0);else if(E==6)d=Pe._allocVert(s,r),(_||y)&&(d.forced=!0);else if(E==1){if(d=n.list[(a<<1)*n.width+o],d==null){let C=this.xlerp(s,l,i,p,c,z,f);d=Pe._allocVert(C,i),n.list[(a<<1)*n.width+o]=d}else d=Pe._allocVert(d.x,d.y);m&&(d.forced=!0),(d.x==s||d.x==l)&&(d.x==s&&(e&1)!=0||d.x==l&&(e&4)!=0)&&(e^=2)}else if(E==5){if(d=n.list[((a<<1)+2)*n.width+o],d==null){let C=this.xlerp(s,l,r,u,h,z,f);d=Pe._allocVert(C,r),n.list[((a<<1)+2)*n.width+o]=d}else d=Pe._allocVert(d.x,d.y);y&&(d.forced=!0),(d.x==s||d.x==l)&&(d.x==s&&(e&64)!=0||d.x==l&&(e&16)!=0)&&(e^=32)}else if(E==3){if(d=n.list[((a<<1)+1)*n.width+(o+1)],d==null){let C=this.ylerp(i,r,l,c,h,z,f);d=Pe._allocVert(l,C),n.list[((a<<1)+1)*n.width+(o+1)]=d}else d=Pe._allocVert(d.x,d.y);x&&(d.forced=!0),(d.y==i||d.y==r)&&(d.y==i&&(e&4)!=0||d.y==r&&(e&16)!=0)&&(e^=8)}else{if(d=n.list[((a<<1)+1)*n.width+o],d==null){let C=this.ylerp(i,r,s,p,u,z,f);d=Pe._allocVert(s,C),n.list[((a<<1)+1)*n.width+o]=d}else d=Pe._allocVert(d.x,d.y);_&&(d.forced=!0),(d.y==i||d.y==r)&&(d.y==i&&(e&1)!=0||d.y==r&&(e&64)!=0)&&(e^=128)}let b=d;v.p2==null?v.p2=b.prev=b.next=b:(b.prev=v.p2,b.next=v.p2.next,v.p2.next.prev=b,v.p2.next=b),v.p2=b}return v.p2!=null&&(v.p2=v.p2.next),{val:e}}lerp(e,t,n,s){let i=Pe._nape;if(n==0)return e;if(s==0)return t;{let l=n-s,r=l*l<i.Config.epsilon*i.Config.epsilon?.5:n/l;return r<0?r=0:r>1&&(r=1),e+r*(t-e)}}xlerp(e,t,n,s,i,l,r){let o=Pe._nape,a;if(s==0)a=e;else if(i==0)a=t;else{let p=s-i,c=p*p<o.Config.epsilon*o.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;r--!=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<o.Config.epsilon*o.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,r){let o=Pe._nape,a;if(s==0)a=e;else if(i==0)a=t;else{let p=s-i,c=p*p<o.Config.epsilon*o.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;r--!=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<o.Config.epsilon*o.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),a=e+h*(t-e)}}return a}};Pe.isos=null,Pe.ints=null,Pe.map=null,Pe._zpp=null,Pe._nape=null;var Ps=Pe;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 Gi=Cn;var ws=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 Ct=class Ct{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=Ct.nextId++,this.diagonals=new $i}static get(e){let t;return Ct.zpp_pool==null?t=new Ct:(t=Ct.zpp_pool,Ct.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t}static rightdistance(e,t){let n=e.next.y>e.y,s=e.next.x-e.x,i=e.next.y-e.y,l=t.x-e.x,r=t.y-e.y;return(n?-1:1)*(r*s-l*i)}static vert_lt(e,t){if(t==e||t==e.next)return!0;if(e.y==e.next.y){let n=e.x,s=e.next.x;return(n<s?n:s)<=t.x}else return Ct.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!Ct.vert_lt(e,t);if(t==e.next)return Ct.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 Ct.rightdistance(t,e)>0?!0:Ct.rightdistance(t,e.next)>0;else{let n=Ct.rightdistance(e,t),s=Ct.rightdistance(e,t.next);if(n==0&&s==0){let r=e.x,o=e.next.x,a=t.x,p=t.next.x;return(r>o?r:o)>(a>p?a:p)}if(n*s>=0)return n<0?!0:s<0;let i=Ct.rightdistance(t,e),l=Ct.rightdistance(t,e.next);return i*l>=0?i>0?!0:l>0:!1}}alloc(){}free(){this.helper=null}copy(){let e;return Ct.zpp_pool==null?e=new Ct:(e=Ct.zpp_pool,Ct.zpp_pool=e.next,e.next=null),e.x=this.x,e.y=this.y,e.forced=this.forced,e}sort(){let e=this.prev.x-this.x,t=this.prev.y-this.y,n=this.next.x-this.x,s=this.next.y-this.y,i=s*e-n*t,l=i>0?-1:i==0?0:1,r=this.diagonals;if(r.head!=null&&r.head.next!=null){let o=r.head,a,p,c,h,u=1,_,m,x;for(;;){for(_=0,p=o,o=null,a=o;p!=null;){for(++_,c=p,m=0,x=u;c!=null&&m<u;)++m,c=c.next;for(;m>0||x>0&&c!=null;){if(m==0)h=c,c=c.next,--x;else if(x==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 z=s*e-n*t;y=(z>0?-1:z==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 z=s*e-n*t,f=z>0?-1:z==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 v=s*e-n*t,E=v>0?-1:v==0?0:1;if(f*E==1||f*E==0&&(f==1||E==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 d=s*e-n*t;y=(d>0?-1:d==0?0:1)==1}else if(f==-1||E==-1)y=E==-1;else if(f==0&&E==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 d=e*n+t*s;n=c.elt.x-this.x,s=c.elt.y-this.y;let b=e*n+t*s;y=d<0&&b>0?!0:!(b<0&&d>0)}else y=!0}y?(h=p,p=p.next,--m):(h=c,c=c.next,--x)}a!=null?a.next=h:o=h,a=h}p=c}if(a.next=null,u<<=1,!(_>1))break}r.head=o,r.modified=!0,r.pushmod=!0}}};Ct.zpp_pool=null,Ct.nextId=0;var Je=Ct;var Zn=class Zn{constructor(e){this.next=null;this.vertices=null;this.init(e)}static getSharedPP(){return Zn.sharedPPList==null&&(Zn.sharedPPList=new ys),Zn.sharedPPList}static getShared(){return Zn.sharedGVList==null&&(Zn.sharedGVList=new ui),Zn.sharedGVList}eq(e,t){let n=e.x-t.x,s=e.y-t.y;return n*n+s*s<re().Config.epsilon*re().Config.epsilon}alloc(){}free(){}init(e){if(e==null)return;let t=0,n=e,s=e;if(n!=null){let r=n;for(;;){let o=r;if(t+=o.x*(o.next.y-o.prev.y),r=r.next,r==s)break}}let i=t*.5>0,l=e;for(;;){let r;if(i){let o;Je.zpp_pool==null?o=new Je:(o=Je.zpp_pool,Je.zpp_pool=o.next,o.next=null),o.x=l.x,o.y=l.y;let a=o;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),r=a}else{let o;Je.zpp_pool==null?o=new Je:(o=Je.zpp_pool,Je.zpp_pool=o.next,o.next=null),o.x=l.x,o.y=l.y;let a=o;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),r=a}if(this.vertices=r,this.vertices.forced=l.forced,l=l.next,l==e)break}this.remove_collinear_vertices()}remove_collinear_vertices(){let e=this.vertices,t=!0;for(;t||e!=this.vertices;)if(t=!1,this.eq(e,e.next)){if(e==this.vertices&&(this.vertices=e.next,t=!0),e.forced&&(e.next.forced=!0),e!=null&&e.prev==e){e.next=e.prev=null;let s=e;s.helper=null,s.next=Je.zpp_pool,Je.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=Je.zpp_pool,Je.zpp_pool=i,e=s}if(e==null){this.vertices=null;break}}else e=e.next;if(this.vertices==null)return!0;let n;for(;;){for(n=!1,e=this.vertices,t=!0;t||e!=this.vertices;){t=!1;let s=e.prev,i=e.x-s.x,l=e.y-s.y,r=e.next.x-e.x,a=(e.next.y-e.y)*i-r*l;if(a*a>=re().Config.epsilon*re().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=Je.zpp_pool,Je.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=Je.zpp_pool,Je.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 ys),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}for(this.pull_partitions(this.vertices,e);this.vertices!=null;){let l;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let r=this.vertices;r.helper=null,r.next=Je.zpp_pool,Je.zpp_pool=r,l=this.vertices=null}else{let r=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let o=this.vertices;o.helper=null,o.next=Je.zpp_pool,Je.zpp_pool=o,this.vertices=null,l=r}this.vertices=l}let s=null,i=e.head;for(;i!=null;){if(i.elt.remove_collinear_vertices()){e.erase(s);continue}s=i,i=i.next}}return e}pull_partitions(e,t){let n;Zn.zpp_pool==null?n=new Zn:(n=Zn.zpp_pool,Zn.zpp_pool=n.next,n.next=null);let s=e;for(;;){let o;Je.zpp_pool==null?o=new Je:(o=Je.zpp_pool,Je.zpp_pool=o.next,o.next=null),o.x=s.x,o.y=s.y,o.forced=s.forced;let a=o;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,r=n.vertices;if(l!=null){let o=l;for(;;){let a=o;if(i+=a.x*(a.next.y-a.prev.y),o=o.next,o==r)break}}return i*.5!=0&&t.add(n),s}extract(e){if(e==null&&(e=new ui),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=Je.zpp_pool,Je.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=Je.zpp_pool,Je.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,_=u.head.elt;if(u.pop(),_==e)break;s=this.pull(s,t)}else s=s.next;if(s==e)break}let i=0,l=n,r=n;if(l!=null){let a=l;for(;;){let p=a;if(i+=p.x*(p.next.y-p.prev.y),a=a.next,a==r)break}}let o=i*.5;if(o*o>=re().Config.epsilon*re().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<re().Config.epsilon*re().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,_=a.y-h.y,m=a.next.x-a.x,y=(a.next.y-a.y)*u-m*_;if(y*y>=re().Config.epsilon*re().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 z=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=z}if(c=!0,a==null){c=!1,n=null;break}}}if(!c)break}}n!=null&&t.add(n)}return s}};Zn.zpp_pool=null,Zn.sharedPPList=null,Zn.sharedGVList=null;var Qe=Zn;var Ge=class Ge{static bisector(e){let t=e.prev,n=e.next,s=e.x-t.x,i=e.y-t.y,l=n.x-e.x,r=n.y-e.y,o;pe.zpp_pool==null?o=new pe:(o=pe.zpp_pool,pe.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=-i-r,o.y=s+l;let a=o,p=a.x*a.x+a.y*a.y,h=1/Math.sqrt(p);return a.x*=h,a.y*=h,r*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=Ge.bisector(e),s=Ge.bisector(t),i=1;n.x+=e.x*i,n.y+=e.y*i;let l=1;s.x+=t.x*l,s.y+=t.y*l;let r=n.x<s.x||n.x==s.x&&n.y<s.y;return n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=pe.zpp_pool,pe.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=pe.zpp_pool,pe.zpp_pool=s,r}}static above(e,t){return Ge.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 o=s;for(;;){let a=o;if(a.y<t.y&&(t=a),a.y>n.y&&(n=a),o=o.next,o==i)break}}let l=!0,r=t;if(n!=t.next){let o=t.next,a=n;if(o!=null){let p=o;for(;;){let c=p;if(c.y<r.y){l=!1;break}if(r=c,p=p.next,p==a)break}}}if(!l)return!1;if(r=t,n!=t.prev){let o=t.prev,a=n;if(o!=null){let p=o;for(;;){let c=p;if(c.y<r.y){l=!1;break}if(r=c,p=p.prev,p==a)break}}}return l}static getShared(){return Ge.sharedPPoly==null&&(Ge.sharedPPoly=new Qe),Ge.sharedPPoly}static decompose(e,t){if(t==null?t=new Qe(e):t.init(e),t.vertices==null)return t;Ge.queue==null&&(Ge.queue=new $i);let n=t.vertices,s=t.vertices;if(n!=null){let l=n;for(;;){let r=l;Ge.queue.add(r);let o=r.next.x-r.x,a=r.next.y-r.y,p=r.prev.x-r.x,h=(r.prev.y-r.y)*o-p*a>0;if(r.type=Ge.below(r.prev,r)?Ge.below(r.next,r)?h?0:3:4:Ge.below(r,r.next)?h?1:2:4,l=l.next,l==s)break}}let i=Ge.queue;if(i.head!=null&&i.head.next!=null){let l=i.head,r,o,a,p,c=1,h,u,_;for(;;){for(h=0,o=l,l=null,r=l;o!=null;){for(++h,a=o,u=0,_=c;a!=null&&u<c;)++u,a=a.next;for(;u>0||_>0&&a!=null;)u==0?(p=a,a=a.next,--_):_==0||a==null||Ge.above(o.elt,a.elt)?(p=o,o=o.next,--u):(p=a,a=a.next,--_),r!=null?r.next=p:l=p,r=p;o=a}if(r.next=null,c<<=1,!(h>1))break}i.head=l,i.modified=!0,i.pushmod=!0}for(Ge.edges==null&&(hl.zpp_pool==null?Ge.edges=new hl:(Ge.edges=hl.zpp_pool,hl.zpp_pool=Ge.edges.next,Ge.edges.next=null),Ge.edges.lt=Je.edge_lt,Ge.edges.swapped=Je.edge_swap);Ge.queue.head!=null;){let l=Ge.queue.pop_unsafe();switch(l.type){case 0:l.helper=l,l.node=Ge.edges.insert(l);break;case 1:{let r=l.prev;if(r.helper==null)throw new Error("Fatal error (1): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),Ge.edges.remove_node(r.node),r.helper=null;break}case 2:{let r=l.prev;if(r.helper==null)throw new Error("Fatal error (3): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),Ge.edges.remove_node(r.node),r.helper=null;let o=null;if(!Ge.edges.empty()){let p=Ge.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Je.vert_lt(c,l)){o=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=o;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 r=null;if(!Ge.edges.empty()){let a=Ge.edges.parent;for(;a.prev!=null;)a=a.prev;for(;a!=null;){let p=a.data;if(!Je.vert_lt(p,l)){r=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 o=r;if(o!=null){if(o.helper==null)throw new Error("Fatal error (2): Polygon is not weakly-simple and clockwise");t.add_diagonal(l,o.helper),o.helper=l}l.node=Ge.edges.insert(l),l.helper=l;break}case 4:{let r=l.prev;if(Ge.left_vertex(l)){if(r.helper==null)throw new Error("Fatal error (5): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),Ge.edges.remove_node(r.node),r.helper=null,l.node=Ge.edges.insert(l),l.helper=l}else{let o=null;if(!Ge.edges.empty()){let p=Ge.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Je.vert_lt(c,l)){o=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=o;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}};Ge.queue=null,Ge.edges=null,Ge.sharedPPoly=null;var $t=Ge;var vs=class vs{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 vs.zpp_pool==null?n=new vs:(n=vs.zpp_pool,vs.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(){}};vs.zpp_pool=null;var Jt=vs;var Ut=class Ut{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=re(),t;if(ue.poolVec2==null?t=new e.geom.Vec2:(t=ue.poolVec2,ue.poolVec2=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t==ue.nextVec2&&(ue.nextVec2=null)),t.zpp_inner==null){let s;pe.zpp_pool==null?s=new pe:(s=pe.zpp_pool,pe.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,t.zpp_inner=s,t.zpp_inner.outer=t}else{if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=t.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=t.zpp_inner;if(l._validate!=null&&l._validate(),t.zpp_inner.x==0){if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=t.zpp_inner;r._validate!=null&&r._validate(),i=t.zpp_inner.y==0}else i=!1;if(!i){t.zpp_inner.x=0,t.zpp_inner.y=0;let r=t.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}t.zpp_inner.weak=!1,this.origin=t,this.origin.zpp_inner._invalidate=s=>this.origin_invalidate(s);let n;if(ue.poolVec2==null?n=new e.geom.Vec2:(n=ue.poolVec2,ue.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==ue.nextVec2&&(ue.nextVec2=null)),n.zpp_inner==null){let s;pe.zpp_pool==null?s=new pe:(s=pe.zpp_pool,pe.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){n.zpp_inner.x=0,n.zpp_inner.y=0;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}n.zpp_inner.weak=!1,this.direction=n,this.direction.zpp_inner._invalidate=s=>this.direction_invalidate(s),this.originx=0,this.originy=0,this.dirx=0,this.diry=0,this.zip_dir=!1}origin_invalidate(e){this.originx=e.x,this.originy=e.y}direction_invalidate(e){this.dirx=e.x,this.diry=e.y,this.zip_dir=!0}invalidate_dir(){this.zip_dir=!0}validate_dir(){if(this.zip_dir){this.zip_dir=!1;let e=re();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 fe.zpp_pool==null?i=new fe:(i=fe.zpp_pool,fe.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=re();if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(ue.poolVec2==null?s=new n.geom.Vec2:(s=ue.poolVec2,ue.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==ue.nextVec2&&(ue.nextVec2=null)),s.zpp_inner==null){let i;pe.zpp_pool==null?i=new pe:(i=pe.zpp_pool,pe.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=e,i.y=t,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;s.zpp_inner._validate!=null&&s.zpp_inner._validate(),s.zpp_inner.x==e?(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l=s.zpp_inner.y==t):l=!1,l||(s.zpp_inner.x=e,s.zpp_inner.y=t,s.zpp_inner._invalidate!=null&&s.zpp_inner._invalidate(s.zpp_inner))}return s.zpp_inner.weak=!1,s}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let s=1;n.localCOMx+=n.lverts.next.next.x*s,n.localCOMy+=n.lverts.next.next.y*s;let i=.5;n.localCOMx*=i,n.localCOMy*=i}else{n.localCOMx=0,n.localCOMy=0;let s=0,i=n.lverts.next,l=i;i=i.next;let r=i;for(i=i.next;i!=null;){let u=i;s+=r.x*(u.y-l.y);let _=u.y*r.x-u.x*r.y;n.localCOMx+=(r.x+u.x)*_,n.localCOMy+=(r.y+u.y)*_,l=r,r=u,i=i.next}i=n.lverts.next;let o=i;s+=r.x*(o.y-l.y);let a=o.y*r.x-o.x*r.y;n.localCOMx+=(r.x+o.x)*a,n.localCOMy+=(r.y+o.y)*a,l=r,r=o,i=i.next;let p=i;s+=r.x*(p.y-l.y);let c=p.y*r.x-p.x*r.y;n.localCOMx+=(r.x+p.x)*c,n.localCOMy+=(r.y+p.y)*c,s=1/(3*s);let h=s;n.localCOMx*=h,n.localCOMy*=h}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}_circleNormal(e,t,n){let s=this.originx+this.dirx*e,i=this.originy+this.diry*e;s-=t.worldCOMx,i-=t.worldCOMy;let l=s*s+i*i,r=1/Math.sqrt(l);return s*=r,i*=r,n&&(s=-s,i=-i),{nx:s,ny:i}}static _insertSorted(e,t){let n=null,s=e.zpp_inner.inner.head;for(;s!=null;){let r=s.elt;if(t.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(t.zpp_inner.toiDistance<r.zpp_inner.toiDistance)break;n=s,s=s.next}let i=e.zpp_inner.inner,l;pl.zpp_pool==null?l=new pl:(l=pl.zpp_pool,pl.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){Ut._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,r=2*(s*this.dirx+i*this.diry),o=s*s+i*i-e.radius*e.radius,a=r*r-4*l*o;if(a==0){let p=-r/2*l;if((!t||o>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,o<=0),h=Ut._allocVec2(c.nx,c.ny);return jt.getRay(h,p,o<=0,e.outer)}else return null}else{a=Math.sqrt(a),l=1/(2*l);let p=(-r-a)*l,c=(-r+a)*l;if(p>0)if(p<n&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=Ut._allocVec2(h.nx,h.ny);return jt.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=Ut._allocVec2(h.nx,h.ny);return jt.getRay(u,c,!0,e.outer)}else return null;else return null}}circlesect2(e,t,n){Ut._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,r=2*(s*this.dirx+i*this.diry),o=s*s+i*i-e.radius*e.radius,a=r*r-4*l*o;if(a==0){let p=-r/2*l;if((!t||o>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,o<=0),h=Ut._allocVec2(c.nx,c.ny),u=jt.getRay(h,p,o<=0,e.outer);Ut._insertSorted(n,u)}}else{a=Math.sqrt(a),l=1/(2*l);let p=(-r-a)*l,c=(-r+a)*l;if(p>0&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=Ut._allocVec2(h.nx,h.ny),_=jt.getRay(u,p,!1,e.outer);Ut._insertSorted(n,_)}if(c>0&&c<=this.maxdist&&t){let h=this._circleNormal(c,e,!0),u=Ut._allocVec2(h.nx,h.ny),_=jt.getRay(u,c,!0,e.outer);Ut._insertSorted(n,_)}}}polysect(e,t,n){let s=re(),i=n,l=null,r=e.edges.head,o=!0,a=e.gverts.next,p=a,c=a.next;for(;c!=null;){let h=c,u=r.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let _=h.x-p.x,m=h.y-p.y,x=p.x-this.originx,y=p.y-this.originy,z=m*this.dirx-_*this.diry;if(z*z>s.Config.epsilon){z=1/z;let f=(m*x-_*y)*z;if(f>0&&f<i&&f<=this.maxdist){let v=(this.diry*x-this.dirx*y)*z;v>-s.Config.epsilon&&v<1+s.Config.epsilon&&(i=f,l=r.elt)}}}r=r.next,p=h,c=c.next}if(o){c=e.gverts.next;let h=c,u=r.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let _=h.x-p.x,m=h.y-p.y,x=p.x-this.originx,y=p.y-this.originy,z=m*this.dirx-_*this.diry;if(z*z>s.Config.epsilon){z=1/z;let f=(m*x-_*y)*z;if(f>0&&f<i&&f<=this.maxdist){let v=(this.diry*x-this.dirx*y)*z;v>-s.Config.epsilon&&v<1+s.Config.epsilon&&(i=f,l=r.elt)}}}}if(l!=null){let h=l.gnormx,u=l.gnormy,_=h*this.dirx+u*this.diry>0;_&&(h=-h,u=-u);let m=Ut._allocVec2(h,u);return jt.getRay(m,i,_,e.outer)}else return null}polysect2(e,t,n){let s=re(),i=1/0,l=-1,r=null,o=null,a=e.edges.head,p=!0,c=e.gverts.next,h=c,u=c.next;for(;u!=null;){let _=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let x=_.x-h.x,y=_.y-h.y,z=h.x-this.originx,f=h.y-this.originy,v=y*this.dirx-x*this.diry;if(v*v>s.Config.epsilon){v=1/v;let E=(y*z-x*f)*v;if(E>0&&E<=this.maxdist&&(E<i||E>l)){let d=(this.diry*z-this.dirx*f)*v;d>-s.Config.epsilon&&d<1+s.Config.epsilon&&(E<i&&(i=E,r=a.elt),E>l&&(l=E,o=a.elt))}}}a=a.next,h=_,u=u.next}if(p){u=e.gverts.next;let _=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let x=_.x-h.x,y=_.y-h.y,z=h.x-this.originx,f=h.y-this.originy,v=y*this.dirx-x*this.diry;if(v*v>s.Config.epsilon){v=1/v;let E=(y*z-x*f)*v;if(E>0&&E<=this.maxdist&&(E<i||E>l)){let d=(this.diry*z-this.dirx*f)*v;d>-s.Config.epsilon&&d<1+s.Config.epsilon&&(E<i&&(i=E,r=a.elt),E>l&&(l=E,o=a.elt))}}}}if(r!=null){let _=r.gnormx,m=r.gnormy,x=_*this.dirx+m*this.diry>0;x&&(_=-_,m=-m);let y=Ut._allocVec2(_,m),z=jt.getRay(y,i,x,e.outer);Ut._insertSorted(n,z)}if(o!=null&&r!=o){let _=o.gnormx,m=o.gnormy,x=_*this.dirx+m*this.diry>0;x&&(_=-_,m=-m);let y=Ut._allocVec2(_,m),z=jt.getRay(y,l,x,e.outer);Ut._insertSorted(n,z)}}};Ut.internal=!1;var zl=Ut;var ns=class ns{constructor(){this.forced=!1;this.x=0;this.y=0;this.links=null;this.id=0;this.next=null;this.node=null;this.id=On.ZPP_SimpleVert(),yn.zpp_pool==null?this.links=new yn:(this.links=yn.zpp_pool,yn.zpp_pool=this.links.next,this.links.next=null),this.links.lt=ns.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 ns.zpp_pool==null?n=new ns:(n=ns.zpp_pool,ns.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(){}};ns.zpp_pool=null;var Oe=ns;var gs=class gs{constructor(){this.left=null;this.right=null;this.vertices=null;this.id=0;this.next=null;this.prev=null;this.node=null;this.id=On.ZPP_SimpleSeg(),yn.zpp_pool==null?this.vertices=new yn:(this.vertices=yn.zpp_pool,yn.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 gs.zpp_pool==null?n=new gs:(n=gs.zpp_pool,gs.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}};gs.zpp_pool=null;var Kt=gs;var Cs=class Cs{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 Cs.zpp_pool==null?t=new Cs:(t=Cs.zpp_pool,Cs.zpp_pool=t.next,t.next=null),t.vertex=e,t}free(){this.vertex=null,this.segment=this.segment2=null,this.node=null}alloc(){}};Cs.zpp_pool=null;var Me=Cs;var Zs=class{constructor(){this.sweepx=0;this.tree=null;cl.zpp_pool==null?this.tree=new cl:(this.tree=cl.zpp_pool,cl.zpp_pool=this.tree.next,this.tree.next=null),this.tree.lt=(e,t)=>this.edge_lt(e,t),this.tree.swapped=(e,t)=>this.swap_nodes(e,t)}swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}edge_lt(e,t){let n=e.left,s=e.right,i=t.left,l=t.right,r,o,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,r=s.x-n.x,o=s.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?o*a-r*p:p*r-a*o)<0);if(e.right==t.left){let h;return i.x==l.x?h=i.y<l.y?i.y>n.y:l.y>n.y:(c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=n.x-i.x,p=n.y-i.y,h=(c?o*a-r*p:p*r-a*o)<0),!h}else{if(e.left==t.left)return n.x==s.x?n.y<s.y?n.y>l.y:s.y>l.y:(c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=l.x-n.x,p=l.y-n.y,(c?o*a-r*p:p*r-a*o)<0);if(e.right==t.right)return n.x==s.x?n.y<s.y?n.y>i.y:s.y>i.y:(c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?o*a-r*p:p*r-a*o)<0)}if(n.x==s.x)if(i.x==l.x){let h=n.y<s.y?s:n,u=i.y<l.y?l:i;return h.y>u.y}else{c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let h=c?o*a-r*p:p*r-a*o;c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let u=c?o*a-r*p:p*r-a*o;return h*u>=0?h>=0:this.sweepx>=n.x}else if(i.x==l.x){c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=c?o*a-r*p:p*r-a*o;c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=c?o*a-r*p:p*r-a*o;return h*u>=0?h<0:this.sweepx<i.x}else{c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=(c?o*a-r*p:p*r-a*o)<0;c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=(c?o*a-r*p:p*r-a*o)<0;if(h==u)return h;{c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let _=(c?o*a-r*p:p*r-a*o)>=0;c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let m=(c?o*a-r*p:p*r-a*o)>=0;if(_==m)return _;let x=(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 x>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,r=(i.x-n.x)*(s.y-n.y)-(s.x-n.x)*(i.y-n.y),o=(l.x-n.x)*(s.y-n.y)-(s.x-n.x)*(l.y-n.y);if(r*o>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,r=s.x-n.x,o=s.y-n.y,a=l.x-i.x,p=l.y-i.y,c=p*r-a*o;if(c==0)return null;c=1/c;let h=i.x-n.x,u=i.y-n.y,_=(p*h-a*u)*c;if(_<0||_>1)return null;let m=(o*h-r*u)*c;if(m<0||m>1)return null;let x;if(m==0||m==1||_==0||_==1){let f=m==0;if(m==1&&f)throw new Error("corner case 1a");if(m==1&&(f=!0),_==0&&f)throw new Error("corner case 1b");if(_==0&&(f=!0),_==1&&f)throw new Error("corner case 1c");x=m==0?i:m==1?l:_==0?n:s}else{let f=.5*(n.x+r*_+i.x+a*m),v=.5*(n.y+o*_+i.y+p*m),E;Oe.zpp_pool==null?E=new Oe:(E=Oe.zpp_pool,Oe.zpp_pool=E.next,E.next=null),E.x=f,E.y=v,x=E}let y;Me.zpp_pool==null?y=new Me:(y=Me.zpp_pool,Me.zpp_pool=y.next,y.next=null),y.vertex=x;let z=y;return z.type=0,z.segment=e,z.segment2=t,z}}};var ye=class ye{static decompose(e,t){ye.sweep==null&&(ye.sweep=new Zs,ye.inthash=new ds),ye.vertices==null&&(yn.zpp_pool==null?ye.vertices=new yn:(ye.vertices=yn.zpp_pool,yn.zpp_pool=ye.vertices.next,ye.vertices.next=null),ye.vertices.lt=Oe.less_xy,ye.vertices.swapped=Oe.swap_nodes),ye.queue==null&&(vi.zpp_pool==null?ye.queue=new vi:(ye.queue=vi.zpp_pool,vi.zpp_pool=ye.queue.next,ye.queue.next=null),ye.queue.lt=Me.less_xy,ye.queue.swapped=Me.swap_nodes);let n=null,s=null,i=e,l=e;if(i!=null){let _=i;for(;;){let m=_,x=m.x,y=m.y,z;Oe.zpp_pool==null?z=new Oe:(z=Oe.zpp_pool,Oe.zpp_pool=z.next,z.next=null),z.x=x,z.y=y;let f=z,v=ye.vertices.parent;for(;v!=null;)if(ye.vertices.lt(f,v.data))v=v.prev;else if(ye.vertices.lt(v.data,f))v=v.next;else break;let E=v;if(E!=null){let d=f;d.links.clear(),d.node=null,d.forced=!1,d.next=Oe.zpp_pool,Oe.zpp_pool=d,f=E.data}else f.node=ye.vertices.insert(f);if(s!=null){let d;Me.zpp_pool==null?d=new Me:(d=Me.zpp_pool,Me.zpp_pool=d.next,d.next=null),d.vertex=s;let b=d,C;Me.zpp_pool==null?C=new Me:(C=Me.zpp_pool,Me.zpp_pool=C.next,C.next=null),C.vertex=f;let P=C,g;Me.less_xy(b,P)?(b.type=1,P.type=2,g=Kt.get(s,f)):(b.type=2,P.type=1,g=Kt.get(f,s)),b.segment=P.segment=g,ye.queue.insert(b),ye.queue.insert(P),s.links.insert(f),f.links.insert(s)}if(s=f,n==null&&(n=f),_=_.next,_==l)break}}let r;Me.zpp_pool==null?r=new Me:(r=Me.zpp_pool,Me.zpp_pool=r.next,r.next=null),r.vertex=s;let o=r,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(o,p)?(o.type=1,p.type=2,c=Kt.get(s,n)):(o.type=2,p.type=1,c=Kt.get(n,s)),o.segment=p.segment=c,ye.queue.insert(o),ye.queue.insert(p),s.links.insert(n),n.links.insert(s),ye.ints==null&&(vi.zpp_pool==null?ye.ints=new vi:(ye.ints=vi.zpp_pool,vi.zpp_pool=ye.ints.next,ye.ints.next=null),ye.ints.lt=Me.less_xy);!ye.queue.empty();){let _=ye.queue.pop_front();if(ye.sweep.sweepx=_.vertex.x,_.type==1){let x=_.segment;if(ye.sweep.add(x),x.next!=null&&x!=null&&!(x.next.id<x.id?ye.inthash.has(x.next.id,x.id):ye.inthash.has(x.id,x.next.id))){let y=ye.sweep.intersection(x.next,x);if(y!=null)if(y.vertex.x>=ye.sweep.sweepx){let z=ye.queue.parent;for(;z!=null;)if(ye.queue.lt(y,z.data))z=z.prev;else if(ye.queue.lt(z.data,y))z=z.next;else break;let f=z;if(f==null){let v=ye.ints.parent;for(;v!=null;)if(ye.ints.lt(y,v.data))v=v.prev;else if(ye.ints.lt(v.data,y))v=v.next;else break;let E=v;if(E!=null){let d=y.vertex;d.links.clear(),d.node=null,d.forced=!1,d.next=Oe.zpp_pool,Oe.zpp_pool=d,y.vertex=E.data.vertex,E.data=y,ye.queue.insert(y)}else ye.queue.insert(y),ye.ints.insert(y);if(x.next.id<x.id){let d=ye.inthash,b=x.next.id,C=x.id,P;De.zpp_pool==null?P=new De:(P=De.zpp_pool,De.zpp_pool=P.next,P.next=null),P.id=b,P.di=C;let g=P;g.value=!0,d.add(g)}else{let d=ye.inthash,b=x.id,C=x.next.id,P;De.zpp_pool==null?P=new De:(P=De.zpp_pool,De.zpp_pool=P.next,P.next=null),P.id=b,P.di=C;let g=P;g.value=!0,d.add(g)}}else{let v=f.data;if(v.segment!=y.segment||y.segment2!=v.segment2)throw new Error("corner case 2, shiiiit.");let E=y.vertex;E.links.clear(),E.node=null,E.forced=!1,E.next=Oe.zpp_pool,Oe.zpp_pool=E;let d=y;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Me.zpp_pool,Me.zpp_pool=d}}else{let z=y.vertex;z.links.clear(),z.node=null,z.forced=!1,z.next=Oe.zpp_pool,Oe.zpp_pool=z;let f=y;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Me.zpp_pool,Me.zpp_pool=f}}if(x!=null&&x.prev!=null&&!(x.id<x.prev.id?ye.inthash.has(x.id,x.prev.id):ye.inthash.has(x.prev.id,x.id))){let y=ye.sweep.intersection(x,x.prev);if(y!=null)if(y.vertex.x>=ye.sweep.sweepx){let z=ye.queue.parent;for(;z!=null;)if(ye.queue.lt(y,z.data))z=z.prev;else if(ye.queue.lt(z.data,y))z=z.next;else break;let f=z;if(f==null){let v=ye.ints.parent;for(;v!=null;)if(ye.ints.lt(y,v.data))v=v.prev;else if(ye.ints.lt(v.data,y))v=v.next;else break;let E=v;if(E!=null){let d=y.vertex;d.links.clear(),d.node=null,d.forced=!1,d.next=Oe.zpp_pool,Oe.zpp_pool=d,y.vertex=E.data.vertex,E.data=y,ye.queue.insert(y)}else ye.queue.insert(y),ye.ints.insert(y);if(x.id<x.prev.id){let d=ye.inthash,b=x.id,C=x.prev.id,P;De.zpp_pool==null?P=new De:(P=De.zpp_pool,De.zpp_pool=P.next,P.next=null),P.id=b,P.di=C;let g=P;g.value=!0,d.add(g)}else{let d=ye.inthash,b=x.prev.id,C=x.id,P;De.zpp_pool==null?P=new De:(P=De.zpp_pool,De.zpp_pool=P.next,P.next=null),P.id=b,P.di=C;let g=P;g.value=!0,d.add(g)}}else{let v=f.data;if(v.segment!=y.segment||y.segment2!=v.segment2)throw new Error("corner case 2, shiiiit.");let E=y.vertex;E.links.clear(),E.node=null,E.forced=!1,E.next=Oe.zpp_pool,Oe.zpp_pool=E;let d=y;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Me.zpp_pool,Me.zpp_pool=d}}else{let z=y.vertex;z.links.clear(),z.node=null,z.forced=!1,z.next=Oe.zpp_pool,Oe.zpp_pool=z;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(_.type==2){let x=_.segment;if(x.node!=null){let y=x.next,z=x.prev;ye.sweep.remove(x);let f=x;if(f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=Kt.zpp_pool,Kt.zpp_pool=f,y!=null&&z!=null&&!(y.id<z.id?ye.inthash.has(y.id,z.id):ye.inthash.has(z.id,y.id))){let v=ye.sweep.intersection(y,z);if(v!=null)if(v.vertex.x>=ye.sweep.sweepx){let E=ye.queue.parent;for(;E!=null;)if(ye.queue.lt(v,E.data))E=E.prev;else if(ye.queue.lt(E.data,v))E=E.next;else break;let d=E;if(d==null){let b=ye.ints.parent;for(;b!=null;)if(ye.ints.lt(v,b.data))b=b.prev;else if(ye.ints.lt(b.data,v))b=b.next;else break;let C=b;if(C!=null){let P=v.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=Oe.zpp_pool,Oe.zpp_pool=P,v.vertex=C.data.vertex,C.data=v,ye.queue.insert(v)}else ye.queue.insert(v),ye.ints.insert(v);if(y.id<z.id){let P=ye.inthash,g=y.id,O=z.id,N;De.zpp_pool==null?N=new De:(N=De.zpp_pool,De.zpp_pool=N.next,N.next=null),N.id=g,N.di=O;let M=N;M.value=!0,P.add(M)}else{let P=ye.inthash,g=z.id,O=y.id,N;De.zpp_pool==null?N=new De:(N=De.zpp_pool,De.zpp_pool=N.next,N.next=null),N.id=g,N.di=O;let M=N;M.value=!0,P.add(M)}}else{let b=d.data;if(b.segment!=v.segment||v.segment2!=b.segment2)throw new Error("corner case 2, shiiiit.");let C=v.vertex;C.links.clear(),C.node=null,C.forced=!1,C.next=Oe.zpp_pool,Oe.zpp_pool=C;let P=v;P.vertex=null,P.segment=P.segment2=null,P.node=null,P.next=Me.zpp_pool,Me.zpp_pool=P}}else{let E=v.vertex;E.links.clear(),E.node=null,E.forced=!1,E.next=Oe.zpp_pool,Oe.zpp_pool=E;let d=v;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Me.zpp_pool,Me.zpp_pool=d}}}}else{let x=_.vertex,y=x.node==null,z=_.segment,f=_.segment2;if(f.next!=z){let C=z;z=f,f=C}let v=z.vertices.parent;for(;v!=null;)if(z.vertices.lt(x,v.data))v=v.prev;else if(z.vertices.lt(v.data,x))v=v.next;else break;let E=v==null,d=f.vertices.parent;for(;d!=null;)if(f.vertices.lt(x,d.data))d=d.prev;else if(f.vertices.lt(d.data,x))d=d.next;else break;let b=d==null;if(E){let C=z.vertices.insert(x),P=x==z.left?x:z.vertices.predecessor_node(C).data,g=x==z.right?x:z.vertices.successor_node(C).data;P.links.remove(g),x!=P&&P.links.insert(x),g.links.remove(P),x!=g&&g.links.insert(x),x!=P&&x.links.insert(P),x!=g&&x.links.insert(g)}if(b){let C=f.vertices.insert(x),P=x==f.left?x:f.vertices.predecessor_node(C).data,g=x==f.right?x:f.vertices.successor_node(C).data;P.links.remove(g),x!=P&&P.links.insert(x),g.links.remove(P),x!=g&&g.links.insert(x),x!=P&&x.links.insert(P),x!=g&&x.links.insert(g)}if(y&&(x.node=ye.vertices.insert(x)),x.forced=!0,y){let C=z.node,P=f.node;C.data=f,P.data=z,z.node=P,f.node=C,f.next=z.next,z.next=f,z.prev=f.prev,f.prev=z,z.prev!=null&&(z.prev.next=z),f.next!=null&&(f.next.prev=f)}if(f.next!=null&&f!=null&&!(f.next.id<f.id?ye.inthash.has(f.next.id,f.id):ye.inthash.has(f.id,f.next.id))){let C=ye.sweep.intersection(f.next,f);if(C!=null)if(C.vertex.x>=ye.sweep.sweepx){let P=ye.queue.parent;for(;P!=null;)if(ye.queue.lt(C,P.data))P=P.prev;else if(ye.queue.lt(P.data,C))P=P.next;else break;let g=P;if(g==null){let O=ye.ints.parent;for(;O!=null;)if(ye.ints.lt(C,O.data))O=O.prev;else if(ye.ints.lt(O.data,C))O=O.next;else break;let N=O;if(N!=null){let M=C.vertex;M.links.clear(),M.node=null,M.forced=!1,M.next=Oe.zpp_pool,Oe.zpp_pool=M,C.vertex=N.data.vertex,N.data=C,ye.queue.insert(C)}else ye.queue.insert(C),ye.ints.insert(C);if(f.next.id<f.id){let M=ye.inthash,k=f.next.id,Z=f.id,A;De.zpp_pool==null?A=new De:(A=De.zpp_pool,De.zpp_pool=A.next,A.next=null),A.id=k,A.di=Z;let S=A;S.value=!0,M.add(S)}else{let M=ye.inthash,k=f.id,Z=f.next.id,A;De.zpp_pool==null?A=new De:(A=De.zpp_pool,De.zpp_pool=A.next,A.next=null),A.id=k,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 N=C.vertex;N.links.clear(),N.node=null,N.forced=!1,N.next=Oe.zpp_pool,Oe.zpp_pool=N;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 P=C.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=Oe.zpp_pool,Oe.zpp_pool=P;let g=C;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Me.zpp_pool,Me.zpp_pool=g}}if(z!=null&&z.prev!=null&&!(z.id<z.prev.id?ye.inthash.has(z.id,z.prev.id):ye.inthash.has(z.prev.id,z.id))){let C=ye.sweep.intersection(z,z.prev);if(C!=null)if(C.vertex.x>=ye.sweep.sweepx){let P=ye.queue.parent;for(;P!=null;)if(ye.queue.lt(C,P.data))P=P.prev;else if(ye.queue.lt(P.data,C))P=P.next;else break;let g=P;if(g==null){let O=ye.ints.parent;for(;O!=null;)if(ye.ints.lt(C,O.data))O=O.prev;else if(ye.ints.lt(O.data,C))O=O.next;else break;let N=O;if(N!=null){let M=C.vertex;M.links.clear(),M.node=null,M.forced=!1,M.next=Oe.zpp_pool,Oe.zpp_pool=M,C.vertex=N.data.vertex,N.data=C,ye.queue.insert(C)}else ye.queue.insert(C),ye.ints.insert(C);if(z.id<z.prev.id){let M=ye.inthash,k=z.id,Z=z.prev.id,A;De.zpp_pool==null?A=new De:(A=De.zpp_pool,De.zpp_pool=A.next,A.next=null),A.id=k,A.di=Z;let S=A;S.value=!0,M.add(S)}else{let M=ye.inthash,k=z.prev.id,Z=z.id,A;De.zpp_pool==null?A=new De:(A=De.zpp_pool,De.zpp_pool=A.next,A.next=null),A.id=k,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 N=C.vertex;N.links.clear(),N.node=null,N.forced=!1,N.next=Oe.zpp_pool,Oe.zpp_pool=N;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 P=C.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=Oe.zpp_pool,Oe.zpp_pool=P;let g=C;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Me.zpp_pool,Me.zpp_pool=g}}ye.ints.remove(_)}let m=_;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Me.zpp_pool,Me.zpp_pool=m}let h=0,u=ye.inthash.table.length;for(;h<u;){let _=h++,m=ye.inthash.table[_];if(m!=null){for(;m!=null;){let x=m.hnext;m.hnext=null;let y=m;y.next=De.zpp_pool,De.zpp_pool=y,m=x}ye.inthash.table[_]=null}}for(t==null&&(t=new ui);!ye.vertices.empty();)ye.clip_polygon(ye.vertices,t);return t}static clip_polygon(e,t){let n=null,s=e.first(),i=s,l=s.links.parent,r=l.prev==null?l.next:l.prev,o=l.data,a=r.data,p=s.x-o.x,c=s.y-o.y,h=a.x-s.x;(a.y-s.y)*p-h*c<0&&(a=o);let _=s.x,m=s.y,x;ge.zpp_pool==null?x=new ge:(x=ge.zpp_pool,ge.zpp_pool=x.next,x.next=null),x.forced=!1,x.x=_,x.y=m;let y=x;if(n==null)y.prev=y.next=y;else{let f=n,v=f.next;y.prev=f,y.next=v,v.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 b=s;b.links.clear(),b.node=null,b.forced=!1,b.next=Oe.zpp_pool,Oe.zpp_pool=b}break}let f=a.x,v=a.y,E;ge.zpp_pool==null?E=new ge:(E=ge.zpp_pool,ge.zpp_pool=E.next,E.next=null),E.forced=!1,E.x=f,E.y=v;let d=E;if(n==null)d.prev=d.next=d;else{let b=n,C=b.next;d.prev=b,d.next=C,C.prev=d,b.next=d}if(n=d,n.forced=a.forced,a.links.singular()){if(s.links.empty()){e.remove(s);let b=s;b.links.clear(),b.node=null,b.forced=!1,b.next=Oe.zpp_pool,Oe.zpp_pool=b}s=a,a=a.links.parent.data}else{let b=null,C=0;if(!a.links.empty()){let P=a.links.parent;for(;P.prev!=null;)P=P.prev;for(;P!=null;){let g=P.data;if(b==null){b=g;let O=a.x-s.x,N=a.y-s.y,M=g.x-a.x;C=(g.y-a.y)*O-M*N}else{let O=a.x-s.x,N=a.y-s.y,M=g.x-a.x,Z=(g.y-a.y)*O-M*N;if(Z>0&&C<=0)b=g,C=Z;else if(C*Z>=0){let A=a.x-g.x,S=a.y-g.y,R=b.x-a.x;(b.y-a.y)*A-R*S>0&&(b=g,C=Z)}}if(P.next!=null)for(P=P.next;P.prev!=null;)P=P.prev;else{for(;P.parent!=null&&P==P.parent.next;)P=P.parent;P=P.parent}}}if(s.links.empty()){e.remove(s);let P=s;P.links.clear(),P.node=null,P.forced=!1,P.next=Oe.zpp_pool,Oe.zpp_pool=P}s=a,a=b}}e.remove(i);let z=i;z.links.clear(),z.node=null,z.forced=!1,z.next=Oe.zpp_pool,Oe.zpp_pool=z,t.add(n)}static isSimple(e){ye.sweep==null&&(ye.sweep=new Zs,ye.inthash=new ds);let t=ye.list_vertices;t==null&&(t=ye.list_vertices=new jr);let n=e,s=e;if(n!=null){let x=n;for(;;){let y=x,z=y.x,f=y.y,v;if(Oe.zpp_pool==null?v=new Oe:(v=Oe.zpp_pool,Oe.zpp_pool=v.next,v.next=null),v.x=z,v.y=f,t.add(v),x=x.next,x==s)break}}let i=ye.list_queue;i==null&&(i=ye.list_queue=new Dr);let l=t.head,r=l.elt;for(l=l.next;l!=null;){let x=l.elt,y;Me.zpp_pool==null?y=new Me:(y=Me.zpp_pool,Me.zpp_pool=y.next,y.next=null),y.vertex=r;let z=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=x;let v=i.add(f),E;Me.less_xy(z,v)?(z.type=1,v.type=2,E=Kt.get(r,x)):(z.type=2,v.type=1,E=Kt.get(x,r)),z.segment=v.segment=E,r=x,l=l.next}let o=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=r;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=o;let h=i.add(c),u;Me.less_xy(p,h)?(p.type=1,h.type=2,u=Kt.get(r,o)):(p.type=2,h.type=1,u=Kt.get(o,r)),p.segment=h.segment=u;let _=i;if(_.head!=null&&_.head.next!=null){let x=_.head,y,z,f,v,E=1,d,b,C;for(;;){for(d=0,z=x,x=null,y=null;z!=null;){for(++d,f=z,b=0,C=E;f!=null&&b<E;)++b,f=f.next;for(;b>0||C>0&&f!=null;)b==0?(v=f,f=f.next,--C):C==0||f==null||Me.less_xy(z.elt,f.elt)?(v=z,z=z.next,--b):(v=f,f=f.next,--C),y!=null?y.next=v:x=v,y=v;z=f}if(y.next=null,E<<=1,!(d>1))break}_.head=x,_.modified=!0,_.pushmod=!0}let m=!0;for(;i.head!=null;){let x=i.pop_unsafe(),y=x.segment;if(x.type==1){if(ye.sweep.add(y),ye.sweep.intersect(y,y.next)||ye.sweep.intersect(y,y.prev)){m=!1;break}}else if(x.type==2){if(ye.sweep.intersect(y.prev,y.next)){m=!1;break}ye.sweep.remove(y);let f=y;f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=Kt.zpp_pool,Kt.zpp_pool=f}let z=x;z.vertex=null,z.segment=z.segment2=null,z.node=null,z.next=Me.zpp_pool,Me.zpp_pool=z}for(;i.head!=null;){let x=i.pop_unsafe();if(x.type==2){let z=x.segment;z.left=z.right=null,z.prev=null,z.node=null,z.vertices.clear(),z.next=Kt.zpp_pool,Kt.zpp_pool=z}let y=x;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Me.zpp_pool,Me.zpp_pool=y}for(ye.sweep.clear();t.head!=null;){let x=t.pop_unsafe();x.links.clear(),x.node=null,x.forced=!1,x.next=Oe.zpp_pool,Oe.zpp_pool=x}return m}};ye.sweep=null,ye.inthash=null,ye.vertices=null,ye.queue=null,ye.ints=null,ye.list_vertices=null,ye.list_queue=null;var is=ye;var Ms=class Ms{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 Ms.zpp_pool==null?t=new Ms:(t=Ms.zpp_pool,Ms.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t.flag=!1,t}free(){}alloc(){}};Ms.zpp_pool=null;var Rn=Ms;var Es=class Es{constructor(){this.next=null;this.min=null;this.max=null}static get(e,t){let n;return Es.zpp_pool==null?n=new Es:(n=Es.zpp_pool,Es.zpp_pool=n.next,n.next=null),n.min=e,n.max=t,n}free(){this.min=null,this.max=null}alloc(){}};Es.zpp_pool=null;var Fe=Es;var Yt=class Yt{static lessval(e,t){return e.x-t.x+(e.y-t.y)}static less(e,t){return e.x-t.x+(e.y-t.y)<0}static distance(e,t,n){let s=n.x-t.x,i=n.y-t.y,l=e.x-t.x,r=e.y-t.y;if(s*s+i*i==0)return l*l+r*r;{let a=(l*s+r*i)/(s*s+i*i);if(a<=0)return l*l+r*r;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,r-=i*p,l*l+r*r}}}static simplify(e,t){let n=null,s=null,i=null;t*=t,Yt.stack==null&&(Yt.stack=new Br);let l=null,r=null,o=e;for(;;){let p;Rn.zpp_pool==null?p=new Rn:(p=Rn.zpp_pool,Rn.zpp_pool=p.next,p.next=null),p.x=o.x,p.y=o.y,p.flag=!1;let c=p;if(c.forced=o.forced,c.forced){if(c.flag=!0,l!=null){let u=Yt.stack,_;Fe.zpp_pool==null?_=new Fe:(_=Fe.zpp_pool,Fe.zpp_pool=_.next,_.next=null),_.min=l,_.max=c,u.add(_)}else r=c;l=c}let h=c;if(n==null?h.prev=h.next=h:(h.prev=n,h.next=n.next,n.next.prev=h,n.next=h),n=h,s==null?(s=n,i=n):(n.x-s.x+(n.y-s.y)<0&&(s=n),i.x-n.x+(i.y-n.y)<0&&(i=n)),o=o.next,o==e)break}if(Yt.stack.head==null)if(r==null){s.flag=i.flag=!0;let p=Yt.stack,c;Fe.zpp_pool==null?c=new Fe:(c=Fe.zpp_pool,Fe.zpp_pool=c.next,c.next=null),c.min=s,c.max=i,p.add(c);let h=Yt.stack,u;Fe.zpp_pool==null?u=new Fe:(u=Fe.zpp_pool,Fe.zpp_pool=u.next,u.next=null),u.min=i,u.max=s,h.add(u)}else{let p=s.x-r.x+(s.y-r.y);p<0&&(p=-p);let c=i.x-r.x+(i.y-r.y);if(c<0&&(c=-c),p>c){s.flag=r.flag=!0;let h=Yt.stack,u;Fe.zpp_pool==null?u=new Fe:(u=Fe.zpp_pool,Fe.zpp_pool=u.next,u.next=null),u.min=s,u.max=r,h.add(u);let _=Yt.stack,m;Fe.zpp_pool==null?m=new Fe:(m=Fe.zpp_pool,Fe.zpp_pool=m.next,m.next=null),m.min=r,m.max=s,_.add(m)}else{i.flag=r.flag=!0;let h=Yt.stack,u;Fe.zpp_pool==null?u=new Fe:(u=Fe.zpp_pool,Fe.zpp_pool=u.next,u.next=null),u.min=i,u.max=r,h.add(u);let _=Yt.stack,m;Fe.zpp_pool==null?m=new Fe:(m=Fe.zpp_pool,Fe.zpp_pool=m.next,m.next=null),m.min=r,m.max=i,_.add(m)}}else{let p=Yt.stack,c;Fe.zpp_pool==null?c=new Fe:(c=Fe.zpp_pool,Fe.zpp_pool=c.next,c.next=null),c.min=l,c.max=r,p.add(c)}for(;Yt.stack.head!=null;){let p=Yt.stack.pop_unsafe(),c=p.min,h=p.max,u=p;u.min=u.max=null,u.next=Fe.zpp_pool,Fe.zpp_pool=u;let _=t,m=null,x=c.next;for(;x!=h;){let y=Yt.distance(x,c,h);y>_&&(_=y,m=x),x=x.next}if(m!=null){m.flag=!0;let y=Yt.stack,z;Fe.zpp_pool==null?z=new Fe:(z=Fe.zpp_pool,Fe.zpp_pool=z.next,z.next=null),z.min=c,z.max=m,y.add(z);let f=Yt.stack,v;Fe.zpp_pool==null?v=new Fe:(v=Fe.zpp_pool,Fe.zpp_pool=v.next,v.next=null),v.min=m,v.max=h,f.add(v)}}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=Rn.zpp_pool,Rn.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=Rn.zpp_pool,Rn.zpp_pool=n,n=p}}return a}};Yt.stack=null;var Pl=Yt;var tr=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=pe.get(0,0),this.c2=pe.get(0,0),this.axis=pe.get(0,0)}alloc(){this.failed=!1,this.s1=this.s2=null,this.arbiter=null}free(){}};tr.zpp_pool=null;function mt(w){return w.type===0}function en(w){return w.circle.radius}var mn=class{static dynamicSweep(e,t,n,s,i){let l=re();i==null&&(i=!1);let r=e.s1,o=e.s2,a=r.body,p=o.body,c=0,h=0;c=p.velx-a.velx,h=p.vely-a.vely;let u=a.angvel;u<0&&(u=-u);let _=p.angvel;_<0&&(_=-_);let m=r.sweepCoef*u+o.sweepCoef*_;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 x=e.c1,y=e.c2,z=e.axis,f=n,v=0;for(;;){let Z=f*t,A=Z-a.sweepTime;if(A!=0){a.sweepTime=Z;let H=A;if(a.posx+=a.velx*H,a.posy+=a.vely*H,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,W=1-.5*ee,F=1-ee*ee/8,D=(W*a.axisx+X*a.axisy)*F;a.axisy=(W*a.axisy-X*a.axisx)*F,a.axisx=D}}}if(r.type==0)r.worldCOMx=a.posx+(a.axisy*r.localCOMx-a.axisx*r.localCOMy),r.worldCOMy=a.posy+(r.localCOMx*a.axisx+r.localCOMy*a.axisy);else{let H=r.polygon,X=H.lverts.next,ee=H.gverts.next;for(;ee!=null;){let Q=ee,K=X;X=X.next,Q.x=a.posx+(a.axisy*K.x-a.axisx*K.y),Q.y=a.posy+(K.x*a.axisx+K.y*a.axisy),ee=ee.next}let W=H.edges.head,F=H.gverts.next,D=F;for(F=F.next;F!=null;){let Q=F,K=W.elt;W=W.next,K.gnormx=a.axisy*K.lnormx-a.axisx*K.lnormy,K.gnormy=K.lnormx*a.axisx+K.lnormy*a.axisy,K.gprojection=a.posx*K.gnormx+a.posy*K.gnormy+K.lprojection,K.tp0=D.y*K.gnormx-D.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,D=Q,F=F.next}let T=H.gverts.next,U=W.elt;W=W.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=T.y*U.gnormx-T.x*U.gnormy}let S=f*t,R=S-p.sweepTime;if(R!=0){p.sweepTime=S;let H=R;if(p.posx+=p.velx*H,p.posy+=p.vely*H,p.angvel!=0){let X=p.sweep_angvel*R;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,W=1-.5*ee,F=1-ee*ee/8,D=(W*p.axisx+X*p.axisy)*F;p.axisy=(W*p.axisy-X*p.axisx)*F,p.axisx=D}}}if(o.type==0)o.worldCOMx=p.posx+(p.axisy*o.localCOMx-p.axisx*o.localCOMy),o.worldCOMy=p.posy+(o.localCOMx*p.axisx+o.localCOMy*p.axisy);else{let H=o.polygon,X=H.lverts.next,ee=H.gverts.next;for(;ee!=null;){let Q=ee,K=X;X=X.next,Q.x=p.posx+(p.axisy*K.x-p.axisx*K.y),Q.y=p.posy+(K.x*p.axisx+K.y*p.axisy),ee=ee.next}let W=H.edges.head,F=H.gverts.next,D=F;for(F=F.next;F!=null;){let Q=F,K=W.elt;W=W.next,K.gnormx=p.axisy*K.lnormx-p.axisx*K.lnormy,K.gnormy=K.lnormx*p.axisx+K.lnormy*p.axisy,K.gprojection=p.posx*K.gnormx+p.posy*K.gnormy+K.lprojection,K.tp0=D.y*K.gnormx-D.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,D=Q,F=F.next}let T=H.gverts.next,U=W.elt;W=W.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=T.y*U.gnormx-T.x*U.gnormy}let j=r,q=o,J=x,G=y;var E;if(mt(j)&&mt(q)){let H=j.circle||j.capsule,X=q.circle||q.capsule,ee=en(j),W=en(q);var d;let F=0,D=0;F=X.worldCOMx-H.worldCOMx,D=X.worldCOMy-H.worldCOMy;let T=Math.sqrt(F*F+D*D);if(d=T-(ee+W),d<1e100){if(T==0)F=1,D=0;else{let K=1/T;F*=K,D*=K}let U=ee;J.x=H.worldCOMx+F*U,J.y=H.worldCOMy+D*U;let Q=-W;G.x=X.worldCOMx+F*Q,G.y=X.worldCOMy+D*Q,z.x=F,z.y=D}E=d}else{let H=!1;if(mt(j)&&q.type==1){let X=j;j=q,q=X;let ee=J;J=G,G=ee,H=!0}if(j.type==1&&mt(q)){let X=j.polygon,ee=q.circle||q.capsule,W=en(q),F=-1e100,D=null,T=X.edges.head;for(;T!=null;){let U=T.elt,Q=U.gnormx*ee.worldCOMx+U.gnormy*ee.worldCOMy-U.gprojection-W;if(Q>1e100){F=Q;break}Q>0?Q>F&&(F=Q,D=U):F<0&&Q>F&&(F=Q,D=U),T=T.next}if(F<1e100){let U=D.gp0,Q=D.gp1,K=ee.worldCOMy*D.gnormx-ee.worldCOMx*D.gnormy;if(K<=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-W,F<1e100){if(se==0)ie=1,oe=0;else{let le=1/se;ie*=le,oe*=le}let ne=0;J.x=U.x+ie*ne,J.y=U.y+oe*ne;let ae=-W;G.x=ee.worldCOMx+ie*ae,G.y=ee.worldCOMy+oe*ae,z.x=ie,z.y=oe}}else if(K>=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-W,F<1e100){if(se==0)ie=1,oe=0;else{let le=1/se;ie*=le,oe*=le}let ne=0;J.x=Q.x+ie*ne,J.y=Q.y+oe*ne;let ae=-W;G.x=ee.worldCOMx+ie*ae,G.y=ee.worldCOMy+oe*ae,z.x=ie,z.y=oe}}else{let ie=-W;G.x=ee.worldCOMx+D.gnormx*ie,G.y=ee.worldCOMy+D.gnormy*ie;let oe=-F;J.x=G.x+D.gnormx*oe,J.y=G.y+D.gnormy*oe,z.x=D.gnormx,z.y=D.gnormy}}H&&(z.x=-z.x,z.y=-z.y),E=F}else{let X=j.polygon,ee=q.polygon,W=-1e100,F=null,D=null,T=0,U=X.edges.head;for(;U!=null;){let Q=U.elt,K=1e100,ie=ee.gverts.next;for(;ie!=null;){let oe=ie,se=Q.gnormx*oe.x+Q.gnormy*oe.y;se<K&&(K=se),ie=ie.next}if(K-=Q.gprojection,K>1e100){W=K;break}K>0?K>W&&(W=K,F=Q,T=1):W<0&&K>W&&(W=K,F=Q,T=1),U=U.next}if(W<1e100){let Q=ee.edges.head;for(;Q!=null;){let K=Q.elt,ie=1e100,oe=X.gverts.next;for(;oe!=null;){let se=oe,ne=K.gnormx*se.x+K.gnormy*se.y;ne<ie&&(ie=ne),oe=oe.next}if(ie-=K.gprojection,ie>1e100){W=ie;break}ie>0?ie>W&&(W=ie,D=K,T=2):W<0&&ie>W&&(W=ie,D=K,T=2),Q=Q.next}if(W<1e100){var b,C,P;if(T==1)b=X,C=ee,P=F;else{b=ee,C=X,P=D;let se=J;J=G,G=se,H=!H}let K=null,ie=1e100,oe=C.edges.head;for(;oe!=null;){let se=oe.elt,ne=P.gnormx*se.gnormx+P.gnormy*se.gnormy;ne<ie&&(ie=ne,K=se),oe=oe.next}if(H?(z.x=-P.gnormx,z.y=-P.gnormy):(z.x=P.gnormx,z.y=P.gnormy),W>=0){let se=P.gp0,ne=P.gp1,ae=K.gp0,le=K.gp1,_e=0,ce=0,he=0,te=0;_e=ne.x-se.x,ce=ne.y-se.y,he=le.x-ae.x,te=le.y-ae.y;let xe=1/(_e*_e+ce*ce),de=1/(he*he+te*te),me=-(_e*(se.x-ae.x)+ce*(se.y-ae.y))*xe,Ce=-(_e*(se.x-le.x)+ce*(se.y-le.y))*xe,Te=-(he*(ae.x-se.x)+te*(ae.y-se.y))*de,Le=-(he*(ae.x-ne.x)+te*(ae.y-ne.y))*de;me<0?me=0:me>1&&(me=1),Ce<0?Ce=0:Ce>1&&(Ce=1),Te<0?Te=0:Te>1&&(Te=1),Le<0?Le=0:Le>1&&(Le=1);let et=0,nt=0,it=me;et=se.x+_e*it,nt=se.y+ce*it;let qe=0,Nt=0,It=Ce;qe=se.x+_e*It,Nt=se.y+ce*It;let bt=0,zt=0,yt=Te;bt=ae.x+he*yt,zt=ae.y+te*yt;let tt=0,Ot=0,Qt=Le;tt=ae.x+he*Qt,Ot=ae.y+te*Qt;let sn=0,Ft=0;sn=et-ae.x,Ft=nt-ae.y;let Rt=sn*sn+Ft*Ft,Ln=0,un=0;Ln=qe-le.x,un=Nt-le.y;let En=Ln*Ln+un*un,wn=0,kn=0;wn=bt-se.x,kn=zt-se.y;let _n=wn*wn+kn*kn,jn=0,xn=0;jn=tt-ne.x,xn=Ot-ne.y;let Nn=jn*jn+xn*xn,ln=0,dn=0,vn=null;Rt<En?(ln=et,dn=nt,vn=ae):(ln=qe,dn=Nt,vn=le,Rt=En);let ji=0,hi=0,Qn=null;if(_n<Nn?(ji=bt,hi=zt,Qn=se):(ji=tt,hi=Ot,Qn=ne,_n=Nn),Rt<_n?(J.x=ln,J.y=dn,G.x=vn.x,G.y=vn.y,W=Math.sqrt(Rt)):(G.x=ji,G.y=hi,J.x=Qn.x,J.y=Qn.y,W=Math.sqrt(_n)),W!=0){z.x=G.x-J.x,z.y=G.y-J.y;let $n=1/W;z.x*=$n,z.y*=$n,H&&(z.x=-z.x,z.y=-z.y)}E=W}else{let se=0,ne=0;se=K.gp0.x,ne=K.gp0.y;let ae=0,le=0;ae=K.gp1.x,le=K.gp1.y;let _e=0,ce=0;_e=ae-se,ce=le-ne;let he=P.gnormy*se-P.gnormx*ne,te=P.gnormy*ae-P.gnormx*le,xe=1/(te-he),de=(-P.tp1-he)*xe;if(de>l.Config.epsilon){let Le=de;se+=_e*Le,ne+=ce*Le}let me=(-P.tp0-te)*xe;if(me<-l.Config.epsilon){let Le=me;ae+=_e*Le,le+=ce*Le}let Ce=se*P.gnormx+ne*P.gnormy-P.gprojection,Te=ae*P.gnormx+le*P.gnormy-P.gprojection;if(Ce<Te){G.x=se,G.y=ne;let Le=-Ce;J.x=G.x+P.gnormx*Le,J.y=G.y+P.gnormy*Le,E=Ce}else{G.x=ae,G.y=le;let Le=-Te;J.x=G.x+P.gnormx*Le,J.y=G.y+P.gnormy*Le,E=Te}}}else E=1e100}else E=1e100}}let L=E+s,V=c*z.x+h*z.y;if(L<l.Config.distanceThresholdCCD){if(i)break;let H=0,X=0;H=x.x-a.posx,X=x.y-a.posy;let ee=0,W=0;ee=y.x-p.posx,W=y.y-p.posy;let F=V-a.sweep_angvel*(z.y*H-z.x*X)+p.sweep_angvel*(z.y*ee-z.x*W);if(F>0&&(e.slipped=!0),F<=0||L<l.Config.distanceThresholdCCD*.5)break}let Y=(m-V)*t;if(Y<=0){f=-1;break}let $=L/Y;if($<1e-6&&($=1e-6),f+=$,f>=1){f=1;let H=f*t,X=H-a.sweepTime;if(X!=0){a.sweepTime=H;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,ae=1-se*se/8,le=(ne*a.axisx+oe*a.axisy)*ae;a.axisy=(ne*a.axisy-oe*a.axisx)*ae,a.axisx=le}}}if(r.type==0)r.worldCOMx=a.posx+(a.axisy*r.localCOMx-a.axisx*r.localCOMy),r.worldCOMy=a.posy+(r.localCOMx*a.axisx+r.localCOMy*a.axisy);else{let ie=r.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let he=se,te=oe;oe=oe.next,he.x=a.posx+(a.axisy*te.x-a.axisx*te.y),he.y=a.posy+(te.x*a.axisx+te.y*a.axisy),se=se.next}let ne=ie.edges.head,ae=ie.gverts.next,le=ae;for(ae=ae.next;ae!=null;){let he=ae,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=he.y*te.gnormx-he.x*te.gnormy,le=he,ae=ae.next}let _e=ie.gverts.next,ce=ne.elt;ne=ne.next,ce.gnormx=a.axisy*ce.lnormx-a.axisx*ce.lnormy,ce.gnormy=ce.lnormx*a.axisx+ce.lnormy*a.axisy,ce.gprojection=a.posx*ce.gnormx+a.posy*ce.gnormy+ce.lprojection,ce.tp0=le.y*ce.gnormx-le.x*ce.gnormy,ce.tp1=_e.y*ce.gnormx-_e.x*ce.gnormy}let ee=f*t,W=ee-p.sweepTime;if(W!=0){p.sweepTime=ee;let ie=W;if(p.posx+=p.velx*ie,p.posy+=p.vely*ie,p.angvel!=0){let oe=p.sweep_angvel*W;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,ae=1-se*se/8,le=(ne*p.axisx+oe*p.axisy)*ae;p.axisy=(ne*p.axisy-oe*p.axisx)*ae,p.axisx=le}}}if(o.type==0)o.worldCOMx=p.posx+(p.axisy*o.localCOMx-p.axisx*o.localCOMy),o.worldCOMy=p.posy+(o.localCOMx*p.axisx+o.localCOMy*p.axisy);else{let ie=o.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let he=se,te=oe;oe=oe.next,he.x=p.posx+(p.axisy*te.x-p.axisx*te.y),he.y=p.posy+(te.x*p.axisx+te.y*p.axisy),se=se.next}let ne=ie.edges.head,ae=ie.gverts.next,le=ae;for(ae=ae.next;ae!=null;){let he=ae,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=he.y*te.gnormx-he.x*te.gnormy,le=he,ae=ae.next}let _e=ie.gverts.next,ce=ne.elt;ne=ne.next,ce.gnormx=p.axisy*ce.lnormx-p.axisx*ce.lnormy,ce.gnormy=ce.lnormx*p.axisx+ce.lnormy*p.axisy,ce.gprojection=p.posx*ce.gnormx+p.posy*ce.gnormy+ce.lprojection,ce.tp0=le.y*ce.gnormx-le.x*ce.gnormy,ce.tp1=_e.y*ce.gnormx-_e.x*ce.gnormy}let F=r,D=o,T=x,U=y;var g;if(mt(F)&&mt(D)){let ie=F.circle||F.capsule,oe=D.circle||D.capsule,se=en(F),ne=en(D);var O;let ae=0,le=0;ae=oe.worldCOMx-ie.worldCOMx,le=oe.worldCOMy-ie.worldCOMy;let _e=Math.sqrt(ae*ae+le*le);if(O=_e-(se+ne),O<1e100){if(_e==0)ae=1,le=0;else{let te=1/_e;ae*=te,le*=te}let ce=se;T.x=ie.worldCOMx+ae*ce,T.y=ie.worldCOMy+le*ce;let he=-ne;U.x=oe.worldCOMx+ae*he,U.y=oe.worldCOMy+le*he,z.x=ae,z.y=le}g=O}else{let ie=!1;if(mt(F)&&D.type==1){let oe=F;F=D,D=oe;let se=T;T=U,U=se,ie=!0}if(F.type==1&&mt(D)){let oe=F.polygon,se=D.circle||D.capsule,ne=en(D),ae=-1e100,le=null,_e=oe.edges.head;for(;_e!=null;){let ce=_e.elt,he=ce.gnormx*se.worldCOMx+ce.gnormy*se.worldCOMy-ce.gprojection-ne;if(he>1e100){ae=he;break}he>0?he>ae&&(ae=he,le=ce):ae<0&&he>ae&&(ae=he,le=ce),_e=_e.next}if(ae<1e100){let ce=le.gp0,he=le.gp1,te=se.worldCOMy*le.gnormx-se.worldCOMx*le.gnormy;if(te<=ce.y*le.gnormx-ce.x*le.gnormy){let xe=0,de=0;xe=se.worldCOMx-ce.x,de=se.worldCOMy-ce.y;let me=Math.sqrt(xe*xe+de*de);if(ae=me-ne,ae<1e100){if(me==0)xe=1,de=0;else{let Le=1/me;xe*=Le,de*=Le}let Ce=0;T.x=ce.x+xe*Ce,T.y=ce.y+de*Ce;let Te=-ne;U.x=se.worldCOMx+xe*Te,U.y=se.worldCOMy+de*Te,z.x=xe,z.y=de}}else if(te>=he.y*le.gnormx-he.x*le.gnormy){let xe=0,de=0;xe=se.worldCOMx-he.x,de=se.worldCOMy-he.y;let me=Math.sqrt(xe*xe+de*de);if(ae=me-ne,ae<1e100){if(me==0)xe=1,de=0;else{let Le=1/me;xe*=Le,de*=Le}let Ce=0;T.x=he.x+xe*Ce,T.y=he.y+de*Ce;let Te=-ne;U.x=se.worldCOMx+xe*Te,U.y=se.worldCOMy+de*Te,z.x=xe,z.y=de}}else{let xe=-ne;U.x=se.worldCOMx+le.gnormx*xe,U.y=se.worldCOMy+le.gnormy*xe;let de=-ae;T.x=U.x+le.gnormx*de,T.y=U.y+le.gnormy*de,z.x=le.gnormx,z.y=le.gnormy}}ie&&(z.x=-z.x,z.y=-z.y),g=ae}else{let oe=F.polygon,se=D.polygon,ne=-1e100,ae=null,le=null,_e=0,ce=oe.edges.head;for(;ce!=null;){let he=ce.elt,te=1e100,xe=se.gverts.next;for(;xe!=null;){let de=xe,me=he.gnormx*de.x+he.gnormy*de.y;me<te&&(te=me),xe=xe.next}if(te-=he.gprojection,te>1e100){ne=te;break}te>0?te>ne&&(ne=te,ae=he,_e=1):ne<0&&te>ne&&(ne=te,ae=he,_e=1),ce=ce.next}if(ne<1e100){let he=se.edges.head;for(;he!=null;){let te=he.elt,xe=1e100,de=oe.gverts.next;for(;de!=null;){let me=de,Ce=te.gnormx*me.x+te.gnormy*me.y;Ce<xe&&(xe=Ce),de=de.next}if(xe-=te.gprojection,xe>1e100){ne=xe;break}xe>0?xe>ne&&(ne=xe,le=te,_e=2):ne<0&&xe>ne&&(ne=xe,le=te,_e=2),he=he.next}if(ne<1e100){var N,M,k;if(_e==1)N=oe,M=se,k=ae;else{N=se,M=oe,k=le;let me=T;T=U,U=me,ie=!ie}let te=null,xe=1e100,de=M.edges.head;for(;de!=null;){let me=de.elt,Ce=k.gnormx*me.gnormx+k.gnormy*me.gnormy;Ce<xe&&(xe=Ce,te=me),de=de.next}if(ie?(z.x=-k.gnormx,z.y=-k.gnormy):(z.x=k.gnormx,z.y=k.gnormy),ne>=0){let me=k.gp0,Ce=k.gp1,Te=te.gp0,Le=te.gp1,et=0,nt=0,it=0,qe=0;et=Ce.x-me.x,nt=Ce.y-me.y,it=Le.x-Te.x,qe=Le.y-Te.y;let Nt=1/(et*et+nt*nt),It=1/(it*it+qe*qe),bt=-(et*(me.x-Te.x)+nt*(me.y-Te.y))*Nt,zt=-(et*(me.x-Le.x)+nt*(me.y-Le.y))*Nt,yt=-(it*(Te.x-me.x)+qe*(Te.y-me.y))*It,tt=-(it*(Te.x-Ce.x)+qe*(Te.y-Ce.y))*It;bt<0?bt=0:bt>1&&(bt=1),zt<0?zt=0:zt>1&&(zt=1),yt<0?yt=0:yt>1&&(yt=1),tt<0?tt=0:tt>1&&(tt=1);let Ot=0,Qt=0,sn=bt;Ot=me.x+et*sn,Qt=me.y+nt*sn;let Ft=0,Rt=0,Ln=zt;Ft=me.x+et*Ln,Rt=me.y+nt*Ln;let un=0,En=0,wn=yt;un=Te.x+it*wn,En=Te.y+qe*wn;let kn=0,_n=0,jn=tt;kn=Te.x+it*jn,_n=Te.y+qe*jn;let xn=0,Nn=0;xn=Ot-Te.x,Nn=Qt-Te.y;let ln=xn*xn+Nn*Nn,dn=0,vn=0;dn=Ft-Le.x,vn=Rt-Le.y;let ji=dn*dn+vn*vn,hi=0,Qn=0;hi=un-me.x,Qn=En-me.y;let $n=hi*hi+Qn*Qn,cs=0,hs=0;cs=kn-Ce.x,hs=_n-Ce.y;let us=cs*cs+hs*hs,ll=0,Ar=0,yr=null;ln<ji?(ll=Ot,Ar=Qt,yr=Te):(ll=Ft,Ar=Rt,yr=Le,ln=ji);let Vr=0,Ir=0,mr=null;if($n<us?(Vr=un,Ir=En,mr=me):(Vr=kn,Ir=_n,mr=Ce,$n=us),ln<$n?(T.x=ll,T.y=Ar,U.x=yr.x,U.y=yr.y,ne=Math.sqrt(ln)):(U.x=Vr,U.y=Ir,T.x=mr.x,T.y=mr.y,ne=Math.sqrt($n)),ne!=0){z.x=U.x-T.x,z.y=U.y-T.y;let Ur=1/ne;z.x*=Ur,z.y*=Ur,ie&&(z.x=-z.x,z.y=-z.y)}g=ne}else{let me=0,Ce=0;me=te.gp0.x,Ce=te.gp0.y;let Te=0,Le=0;Te=te.gp1.x,Le=te.gp1.y;let et=0,nt=0;et=Te-me,nt=Le-Ce;let it=k.gnormy*me-k.gnormx*Ce,qe=k.gnormy*Te-k.gnormx*Le,Nt=1/(qe-it),It=(-k.tp1-it)*Nt;if(It>l.Config.epsilon){let tt=It;me+=et*tt,Ce+=nt*tt}let bt=(-k.tp0-qe)*Nt;if(bt<-l.Config.epsilon){let tt=bt;Te+=et*tt,Le+=nt*tt}let zt=me*k.gnormx+Ce*k.gnormy-k.gprojection,yt=Te*k.gnormx+Le*k.gnormy-k.gprojection;if(zt<yt){U.x=me,U.y=Ce;let tt=-zt;T.x=U.x+k.gnormx*tt,T.y=U.y+k.gnormy*tt,g=zt}else{U.x=Te,U.y=Le;let tt=-yt;T.x=U.x+k.gnormx*tt,T.y=U.y+k.gnormy*tt,g=yt}}}else g=1e100}else g=1e100}}let Q=g+s,K=c*z.x+h*z.y;if(Q<l.Config.distanceThresholdCCD){if(i)break;let ie=0,oe=0;ie=x.x-a.posx,oe=x.y-a.posy;let se=0,ne=0;se=y.x-p.posx,ne=y.y-p.posy;let ae=K-a.sweep_angvel*(z.y*ie-z.x*oe)+p.sweep_angvel*(z.y*se-z.x*ne);if(ae>0&&(e.slipped=!0),ae<=0||Q<l.Config.distanceThresholdCCD*.5)break}f=-1;break}if(++v>=40){L>s&&(e.failed=!0);break}}e.toi=f}static staticSweep(e,t,n,s){let i=re(),l=e.s1,r=e.s2,o=l.body,a=r.body,p=0,c=0;p=-o.velx,c=-o.vely;let h=o.sweep_angvel;h<0&&(h=-h);let u=l.sweepCoef*h,_=e.c1,m=e.c2,x=e.axis,y=n,z=0;for(;;){let M=y*t,k=M-o.sweepTime;if(k!=0){o.sweepTime=M;let L=k;if(o.posx+=o.velx*L,o.posy+=o.vely*L,o.angvel!=0){let V=o.sweep_angvel*k;if(o.rot+=V,V*V>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let Y=V*V,$=1-.5*Y,H=1-Y*Y/8,X=($*o.axisx+V*o.axisy)*H;o.axisy=($*o.axisy-V*o.axisx)*H,o.axisx=X}}}if(l.type==0)l.worldCOMx=o.posx+(o.axisy*l.localCOMx-o.axisx*l.localCOMy),l.worldCOMy=o.posy+(l.localCOMx*o.axisx+l.localCOMy*o.axisy);else{let L=l.polygon,V=L.lverts.next,Y=L.gverts.next;for(;Y!=null;){let F=Y,D=V;V=V.next,F.x=o.posx+(o.axisy*D.x-o.axisx*D.y),F.y=o.posy+(D.x*o.axisx+D.y*o.axisy),Y=Y.next}let $=L.edges.head,H=L.gverts.next,X=H;for(H=H.next;H!=null;){let F=H,D=$.elt;$=$.next,D.gnormx=o.axisy*D.lnormx-o.axisx*D.lnormy,D.gnormy=D.lnormx*o.axisx+D.lnormy*o.axisy,D.gprojection=o.posx*D.gnormx+o.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,H=H.next}let ee=L.gverts.next,W=$.elt;$=$.next,W.gnormx=o.axisy*W.lnormx-o.axisx*W.lnormy,W.gnormy=W.lnormx*o.axisx+W.lnormy*o.axisy,W.gprojection=o.posx*W.gnormx+o.posy*W.gnormy+W.lprojection,W.tp0=X.y*W.gnormx-X.x*W.gnormy,W.tp1=ee.y*W.gnormx-ee.x*W.gnormy}let Z=l,A=r,S=_,R=m;var f;if(mt(Z)&&mt(A)){let L=Z.circle||Z.capsule,V=A.circle||A.capsule,Y=en(Z),$=en(A);var v;let H=0,X=0;H=V.worldCOMx-L.worldCOMx,X=V.worldCOMy-L.worldCOMy;let ee=Math.sqrt(H*H+X*X);if(v=ee-(L.radius+V.radius),v<1e100){if(ee==0)H=1,X=0;else{let D=1/ee;H*=D,X*=D}let W=L.radius;S.x=L.worldCOMx+H*W,S.y=L.worldCOMy+X*W;let F=-V.radius;R.x=V.worldCOMx+H*F,R.y=V.worldCOMy+X*F,x.x=H,x.y=X}f=v}else{let L=!1;if(mt(Z)&&A.type==1){let V=Z;Z=A,A=V;let Y=S;S=R,R=Y,L=!0}if(Z.type==1&&mt(A)){let V=Z.polygon,Y=A.circle||A.capsule,$=en(A),H=-1e100,X=null,ee=V.edges.head;for(;ee!=null;){let W=ee.elt,F=W.gnormx*Y.worldCOMx+W.gnormy*Y.worldCOMy-W.gprojection-$;if(F>1e100){H=F;break}F>0?F>H&&(H=F,X=W):H<0&&F>H&&(H=F,X=W),ee=ee.next}if(H<1e100){let W=X.gp0,F=X.gp1,D=Y.worldCOMy*X.gnormx-Y.worldCOMx*X.gnormy;if(D<=W.y*X.gnormx-W.x*X.gnormy){let T=0,U=0;T=Y.worldCOMx-W.x,U=Y.worldCOMy-W.y;let Q=Math.sqrt(T*T+U*U);if(H=Q-$,H<1e100){if(Q==0)T=1,U=0;else{let oe=1/Q;T*=oe,U*=oe}let K=0;S.x=W.x+T*K,S.y=W.y+U*K;let ie=-$;R.x=Y.worldCOMx+T*ie,R.y=Y.worldCOMy+U*ie,x.x=T,x.y=U}}else if(D>=F.y*X.gnormx-F.x*X.gnormy){let T=0,U=0;T=Y.worldCOMx-F.x,U=Y.worldCOMy-F.y;let Q=Math.sqrt(T*T+U*U);if(H=Q-$,H<1e100){if(Q==0)T=1,U=0;else{let oe=1/Q;T*=oe,U*=oe}let K=0;S.x=F.x+T*K,S.y=F.y+U*K;let ie=-$;R.x=Y.worldCOMx+T*ie,R.y=Y.worldCOMy+U*ie,x.x=T,x.y=U}}else{let T=-$;R.x=Y.worldCOMx+X.gnormx*T,R.y=Y.worldCOMy+X.gnormy*T;let U=-H;S.x=R.x+X.gnormx*U,S.y=R.y+X.gnormy*U,x.x=X.gnormx,x.y=X.gnormy}}L&&(x.x=-x.x,x.y=-x.y),f=H}else{let V=Z.polygon,Y=A.polygon,$=-1e100,H=null,X=null,ee=0,W=V.edges.head;for(;W!=null;){let F=W.elt,D=1e100,T=Y.gverts.next;for(;T!=null;){let U=T,Q=F.gnormx*U.x+F.gnormy*U.y;Q<D&&(D=Q),T=T.next}if(D-=F.gprojection,D>1e100){$=D;break}D>0?D>$&&($=D,H=F,ee=1):$<0&&D>$&&($=D,H=F,ee=1),W=W.next}if($<1e100){let F=Y.edges.head;for(;F!=null;){let D=F.elt,T=1e100,U=V.gverts.next;for(;U!=null;){let Q=U,K=D.gnormx*Q.x+D.gnormy*Q.y;K<T&&(T=K),U=U.next}if(T-=D.gprojection,T>1e100){$=T;break}T>0?T>$&&($=T,X=D,ee=2):$<0&&T>$&&($=T,X=D,ee=2),F=F.next}if($<1e100){var E,d,b;if(ee==1)E=V,d=Y,b=H;else{E=Y,d=V,b=X;let Q=S;S=R,R=Q,L=!L}let D=null,T=1e100,U=d.edges.head;for(;U!=null;){let Q=U.elt,K=b.gnormx*Q.gnormx+b.gnormy*Q.gnormy;K<T&&(T=K,D=Q),U=U.next}if(L?(x.x=-b.gnormx,x.y=-b.gnormy):(x.x=b.gnormx,x.y=b.gnormy),$>=0){let Q=b.gp0,K=b.gp1,ie=D.gp0,oe=D.gp1,se=0,ne=0,ae=0,le=0;se=K.x-Q.x,ne=K.y-Q.y,ae=oe.x-ie.x,le=oe.y-ie.y;let _e=1/(se*se+ne*ne),ce=1/(ae*ae+le*le),he=-(se*(Q.x-ie.x)+ne*(Q.y-ie.y))*_e,te=-(se*(Q.x-oe.x)+ne*(Q.y-oe.y))*_e,xe=-(ae*(ie.x-Q.x)+le*(ie.y-Q.y))*ce,de=-(ae*(ie.x-K.x)+le*(ie.y-K.y))*ce;he<0?he=0:he>1&&(he=1),te<0?te=0:te>1&&(te=1),xe<0?xe=0:xe>1&&(xe=1),de<0?de=0:de>1&&(de=1);let me=0,Ce=0,Te=he;me=Q.x+se*Te,Ce=Q.y+ne*Te;let Le=0,et=0,nt=te;Le=Q.x+se*nt,et=Q.y+ne*nt;let it=0,qe=0,Nt=xe;it=ie.x+ae*Nt,qe=ie.y+le*Nt;let It=0,bt=0,zt=de;It=ie.x+ae*zt,bt=ie.y+le*zt;let yt=0,tt=0;yt=me-ie.x,tt=Ce-ie.y;let Ot=yt*yt+tt*tt,Qt=0,sn=0;Qt=Le-oe.x,sn=et-oe.y;let Ft=Qt*Qt+sn*sn,Rt=0,Ln=0;Rt=it-Q.x,Ln=qe-Q.y;let un=Rt*Rt+Ln*Ln,En=0,wn=0;En=It-K.x,wn=bt-K.y;let kn=En*En+wn*wn,_n=0,jn=0,xn=null;Ot<Ft?(_n=me,jn=Ce,xn=ie):(_n=Le,jn=et,xn=oe,Ot=Ft);let Nn=0,ln=0,dn=null;if(un<kn?(Nn=it,ln=qe,dn=Q):(Nn=It,ln=bt,dn=K,un=kn),Ot<un?(S.x=_n,S.y=jn,R.x=xn.x,R.y=xn.y,$=Math.sqrt(Ot)):(R.x=Nn,R.y=ln,S.x=dn.x,S.y=dn.y,$=Math.sqrt(un)),$!=0){x.x=R.x-S.x,x.y=R.y-S.y;let vn=1/$;x.x*=vn,x.y*=vn,L&&(x.x=-x.x,x.y=-x.y)}f=$}else{let Q=0,K=0;Q=D.gp0.x,K=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-K;let ae=b.gnormy*Q-b.gnormx*K,le=b.gnormy*ie-b.gnormx*oe,_e=1/(le-ae),ce=(-b.tp1-ae)*_e;if(ce>i.Config.epsilon){let de=ce;Q+=se*de,K+=ne*de}let he=(-b.tp0-le)*_e;if(he<-i.Config.epsilon){let de=he;ie+=se*de,oe+=ne*de}let te=Q*b.gnormx+K*b.gnormy-b.gprojection,xe=ie*b.gnormx+oe*b.gnormy-b.gprojection;if(te<xe){R.x=Q,R.y=K;let de=-te;S.x=R.x+b.gnormx*de,S.y=R.y+b.gnormy*de,f=te}else{R.x=ie,R.y=oe;let de=-xe;S.x=R.x+b.gnormx*de,S.y=R.y+b.gnormy*de,f=xe}}}else f=1e100}else f=1e100}}let j=f+s,q=p*x.x+c*x.y;if(j<i.Config.distanceThresholdCCD){let L=0,V=0;L=_.x-o.posx,V=_.y-o.posy;let Y=q-o.sweep_angvel*(x.y*L-x.x*V);if(Y>0&&(e.slipped=!0),Y<=0||j<i.Config.distanceThresholdCCD*.5)break}let J=(u-q)*t;if(J<=0){y=-1;break}let G=j/J;if(G<1e-6&&(G=1e-6),y+=G,y>=1){y=1;let L=y*t,V=L-o.sweepTime;if(V!=0){o.sweepTime=L;let F=V;if(o.posx+=o.velx*F,o.posy+=o.vely*F,o.angvel!=0){let D=o.sweep_angvel*V;if(o.rot+=D,D*D>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let T=D*D,U=1-.5*T,Q=1-T*T/8,K=(U*o.axisx+D*o.axisy)*Q;o.axisy=(U*o.axisy-D*o.axisx)*Q,o.axisx=K}}}if(l.type==0)l.worldCOMx=o.posx+(o.axisy*l.localCOMx-o.axisx*l.localCOMy),l.worldCOMy=o.posy+(l.localCOMx*o.axisx+l.localCOMy*o.axisy);else{let F=l.polygon,D=F.lverts.next,T=F.gverts.next;for(;T!=null;){let se=T,ne=D;D=D.next,se.x=o.posx+(o.axisy*ne.x-o.axisx*ne.y),se.y=o.posy+(ne.x*o.axisx+ne.y*o.axisy),T=T.next}let U=F.edges.head,Q=F.gverts.next,K=Q;for(Q=Q.next;Q!=null;){let se=Q,ne=U.elt;U=U.next,ne.gnormx=o.axisy*ne.lnormx-o.axisx*ne.lnormy,ne.gnormy=ne.lnormx*o.axisx+ne.lnormy*o.axisy,ne.gprojection=o.posx*ne.gnormx+o.posy*ne.gnormy+ne.lprojection,ne.tp0=K.y*ne.gnormx-K.x*ne.gnormy,ne.tp1=se.y*ne.gnormx-se.x*ne.gnormy,K=se,Q=Q.next}let ie=F.gverts.next,oe=U.elt;U=U.next,oe.gnormx=o.axisy*oe.lnormx-o.axisx*oe.lnormy,oe.gnormy=oe.lnormx*o.axisx+oe.lnormy*o.axisy,oe.gprojection=o.posx*oe.gnormx+o.posy*oe.gnormy+oe.lprojection,oe.tp0=K.y*oe.gnormx-K.x*oe.gnormy,oe.tp1=ie.y*oe.gnormx-ie.x*oe.gnormy}let Y=l,$=r,H=_,X=m;var C;if(mt(Y)&&mt($)){let F=Y.circle||Y.capsule,D=$.circle||$.capsule,T=en(Y),U=en($);var P;let Q=0,K=0;Q=D.worldCOMx-F.worldCOMx,K=D.worldCOMy-F.worldCOMy;let ie=Math.sqrt(Q*Q+K*K);if(P=ie-(T+U),P<1e100){if(ie==0)Q=1,K=0;else{let ne=1/ie;Q*=ne,K*=ne}let oe=T;H.x=F.worldCOMx+Q*oe,H.y=F.worldCOMy+K*oe;let se=-U;X.x=D.worldCOMx+Q*se,X.y=D.worldCOMy+K*se,x.x=Q,x.y=K}C=P}else{let F=!1;if(mt(Y)&&$.type==1){let D=Y;Y=$,$=D;let T=H;H=X,X=T,F=!0}if(Y.type==1&&mt($)){let D=Y.polygon,T=$.circle||$.capsule,U=en($),Q=-1e100,K=null,ie=D.edges.head;for(;ie!=null;){let oe=ie.elt,se=oe.gnormx*T.worldCOMx+oe.gnormy*T.worldCOMy-oe.gprojection-U;if(se>1e100){Q=se;break}se>0?se>Q&&(Q=se,K=oe):Q<0&&se>Q&&(Q=se,K=oe),ie=ie.next}if(Q<1e100){let oe=K.gp0,se=K.gp1,ne=T.worldCOMy*K.gnormx-T.worldCOMx*K.gnormy;if(ne<=oe.y*K.gnormx-oe.x*K.gnormy){let ae=0,le=0;ae=T.worldCOMx-oe.x,le=T.worldCOMy-oe.y;let _e=Math.sqrt(ae*ae+le*le);if(Q=_e-U,Q<1e100){if(_e==0)ae=1,le=0;else{let te=1/_e;ae*=te,le*=te}let ce=0;H.x=oe.x+ae*ce,H.y=oe.y+le*ce;let he=-U;X.x=T.worldCOMx+ae*he,X.y=T.worldCOMy+le*he,x.x=ae,x.y=le}}else if(ne>=se.y*K.gnormx-se.x*K.gnormy){let ae=0,le=0;ae=T.worldCOMx-se.x,le=T.worldCOMy-se.y;let _e=Math.sqrt(ae*ae+le*le);if(Q=_e-U,Q<1e100){if(_e==0)ae=1,le=0;else{let te=1/_e;ae*=te,le*=te}let ce=0;H.x=se.x+ae*ce,H.y=se.y+le*ce;let he=-U;X.x=T.worldCOMx+ae*he,X.y=T.worldCOMy+le*he,x.x=ae,x.y=le}}else{let ae=-U;X.x=T.worldCOMx+K.gnormx*ae,X.y=T.worldCOMy+K.gnormy*ae;let le=-Q;H.x=X.x+K.gnormx*le,H.y=X.y+K.gnormy*le,x.x=K.gnormx,x.y=K.gnormy}}F&&(x.x=-x.x,x.y=-x.y),C=Q}else{let D=Y.polygon,T=$.polygon,U=-1e100,Q=null,K=null,ie=0,oe=D.edges.head;for(;oe!=null;){let se=oe.elt,ne=1e100,ae=T.gverts.next;for(;ae!=null;){let le=ae,_e=se.gnormx*le.x+se.gnormy*le.y;_e<ne&&(ne=_e),ae=ae.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=T.edges.head;for(;se!=null;){let ne=se.elt,ae=1e100,le=D.gverts.next;for(;le!=null;){let _e=le,ce=ne.gnormx*_e.x+ne.gnormy*_e.y;ce<ae&&(ae=ce),le=le.next}if(ae-=ne.gprojection,ae>1e100){U=ae;break}ae>0?ae>U&&(U=ae,K=ne,ie=2):U<0&&ae>U&&(U=ae,K=ne,ie=2),se=se.next}if(U<1e100){var g,O,N;if(ie==1)g=D,O=T,N=Q;else{g=T,O=D,N=K;let _e=H;H=X,X=_e,F=!F}let ne=null,ae=1e100,le=O.edges.head;for(;le!=null;){let _e=le.elt,ce=N.gnormx*_e.gnormx+N.gnormy*_e.gnormy;ce<ae&&(ae=ce,ne=_e),le=le.next}if(F?(x.x=-N.gnormx,x.y=-N.gnormy):(x.x=N.gnormx,x.y=N.gnormy),U>=0){let _e=N.gp0,ce=N.gp1,he=ne.gp0,te=ne.gp1,xe=0,de=0,me=0,Ce=0;xe=ce.x-_e.x,de=ce.y-_e.y,me=te.x-he.x,Ce=te.y-he.y;let Te=1/(xe*xe+de*de),Le=1/(me*me+Ce*Ce),et=-(xe*(_e.x-he.x)+de*(_e.y-he.y))*Te,nt=-(xe*(_e.x-te.x)+de*(_e.y-te.y))*Te,it=-(me*(he.x-_e.x)+Ce*(he.y-_e.y))*Le,qe=-(me*(he.x-ce.x)+Ce*(he.y-ce.y))*Le;et<0?et=0:et>1&&(et=1),nt<0?nt=0:nt>1&&(nt=1),it<0?it=0:it>1&&(it=1),qe<0?qe=0:qe>1&&(qe=1);let Nt=0,It=0,bt=et;Nt=_e.x+xe*bt,It=_e.y+de*bt;let zt=0,yt=0,tt=nt;zt=_e.x+xe*tt,yt=_e.y+de*tt;let Ot=0,Qt=0,sn=it;Ot=he.x+me*sn,Qt=he.y+Ce*sn;let Ft=0,Rt=0,Ln=qe;Ft=he.x+me*Ln,Rt=he.y+Ce*Ln;let un=0,En=0;un=Nt-he.x,En=It-he.y;let wn=un*un+En*En,kn=0,_n=0;kn=zt-te.x,_n=yt-te.y;let jn=kn*kn+_n*_n,xn=0,Nn=0;xn=Ot-_e.x,Nn=Qt-_e.y;let ln=xn*xn+Nn*Nn,dn=0,vn=0;dn=Ft-ce.x,vn=Rt-ce.y;let ji=dn*dn+vn*vn,hi=0,Qn=0,$n=null;wn<jn?(hi=Nt,Qn=It,$n=he):(hi=zt,Qn=yt,$n=te,wn=jn);let cs=0,hs=0,us=null;if(ln<ji?(cs=Ot,hs=Qt,us=_e):(cs=Ft,hs=Rt,us=ce,ln=ji),wn<ln?(H.x=hi,H.y=Qn,X.x=$n.x,X.y=$n.y,U=Math.sqrt(wn)):(X.x=cs,X.y=hs,H.x=us.x,H.y=us.y,U=Math.sqrt(ln)),U!=0){x.x=X.x-H.x,x.y=X.y-H.y;let ll=1/U;x.x*=ll,x.y*=ll,F&&(x.x=-x.x,x.y=-x.y)}C=U}else{let _e=0,ce=0;_e=ne.gp0.x,ce=ne.gp0.y;let he=0,te=0;he=ne.gp1.x,te=ne.gp1.y;let xe=0,de=0;xe=he-_e,de=te-ce;let me=N.gnormy*_e-N.gnormx*ce,Ce=N.gnormy*he-N.gnormx*te,Te=1/(Ce-me),Le=(-N.tp1-me)*Te;if(Le>i.Config.epsilon){let qe=Le;_e+=xe*qe,ce+=de*qe}let et=(-N.tp0-Ce)*Te;if(et<-i.Config.epsilon){let qe=et;he+=xe*qe,te+=de*qe}let nt=_e*N.gnormx+ce*N.gnormy-N.gprojection,it=he*N.gnormx+te*N.gnormy-N.gprojection;if(nt<it){X.x=_e,X.y=ce;let qe=-nt;H.x=X.x+N.gnormx*qe,H.y=X.y+N.gnormy*qe,C=nt}else{X.x=he,X.y=te;let qe=-it;H.x=X.x+N.gnormx*qe,H.y=X.y+N.gnormy*qe,C=it}}}else C=1e100}else C=1e100}}let ee=C+s,W=p*x.x+c*x.y;if(ee<i.Config.distanceThresholdCCD){let F=0,D=0;F=_.x-o.posx,D=_.y-o.posy;let T=W-o.sweep_angvel*(x.y*F-x.x*D);if(T>0&&(e.slipped=!0),T<=0||ee<i.Config.distanceThresholdCCD*.5)break}y=-1;break}if(++z>=40){j>s&&(e.failed=!0);break}}e.toi=y}static distanceBody(e,t,n,s){let i=re(),l=pe.get(0,0),r=pe.get(0,0),o=pe.get(0,0),a=1e100,p=e.shapes.head;for(;p!=null;){let f=p.elt,v=t.shapes.head;for(;v!=null;){let E=v.elt,d=f,b=E,C=l,P=r,g=a;g==null&&(g=1e100);var c;if(mt(d)&&mt(b)){let O=d.circle||d.capsule,N=b.circle||b.capsule,M=en(d),k=en(b);var h;let Z=0,A=0;Z=N.worldCOMx-O.worldCOMx,A=N.worldCOMy-O.worldCOMy;let S=Math.sqrt(Z*Z+A*A);if(h=S-(M+k),h<g){if(S==0)Z=1,A=0;else{let q=1/S;Z*=q,A*=q}let R=M;C.x=O.worldCOMx+Z*R,C.y=O.worldCOMy+A*R;let j=-k;P.x=N.worldCOMx+Z*j,P.y=N.worldCOMy+A*j,o.x=Z,o.y=A}c=h}else{let O=!1;if(mt(d)&&b.type==1){let N=d;d=b,b=N;let M=C;C=P,P=M,O=!0}if(d.type==1&&mt(b)){let N=d.polygon,M=b.circle||b.capsule,k=en(b),Z=-1e100,A=null,S=N.edges.head;for(;S!=null;){let R=S.elt,j=R.gnormx*M.worldCOMx+R.gnormy*M.worldCOMy-R.gprojection-k;if(j>g){Z=j;break}j>0?j>Z&&(Z=j,A=R):Z<0&&j>Z&&(Z=j,A=R),S=S.next}if(Z<g){let R=A.gp0,j=A.gp1,q=M.worldCOMy*A.gnormx-M.worldCOMx*A.gnormy;if(q<=R.y*A.gnormx-R.x*A.gnormy){let J=0,G=0;J=M.worldCOMx-R.x,G=M.worldCOMy-R.y;let L=Math.sqrt(J*J+G*G);if(Z=L-k,Z<g){if(L==0)J=1,G=0;else{let $=1/L;J*=$,G*=$}let V=0;C.x=R.x+J*V,C.y=R.y+G*V;let Y=-k;P.x=M.worldCOMx+J*Y,P.y=M.worldCOMy+G*Y,o.x=J,o.y=G}}else if(q>=j.y*A.gnormx-j.x*A.gnormy){let J=0,G=0;J=M.worldCOMx-j.x,G=M.worldCOMy-j.y;let L=Math.sqrt(J*J+G*G);if(Z=L-k,Z<g){if(L==0)J=1,G=0;else{let $=1/L;J*=$,G*=$}let V=0;C.x=j.x+J*V,C.y=j.y+G*V;let Y=-k;P.x=M.worldCOMx+J*Y,P.y=M.worldCOMy+G*Y,o.x=J,o.y=G}}else{let J=-k;P.x=M.worldCOMx+A.gnormx*J,P.y=M.worldCOMy+A.gnormy*J;let G=-Z;C.x=P.x+A.gnormx*G,C.y=P.y+A.gnormy*G,o.x=A.gnormx,o.y=A.gnormy}}O&&(o.x=-o.x,o.y=-o.y),c=Z}else{let N=d.polygon,M=b.polygon,k=-1e100,Z=null,A=null,S=0,R=N.edges.head;for(;R!=null;){let j=R.elt,q=1e100,J=M.gverts.next;for(;J!=null;){let G=J,L=j.gnormx*G.x+j.gnormy*G.y;L<q&&(q=L),J=J.next}if(q-=j.gprojection,q>g){k=q;break}q>0?q>k&&(k=q,Z=j,S=1):k<0&&q>k&&(k=q,Z=j,S=1),R=R.next}if(k<g){let j=M.edges.head;for(;j!=null;){let q=j.elt,J=1e100,G=N.gverts.next;for(;G!=null;){let L=G,V=q.gnormx*L.x+q.gnormy*L.y;V<J&&(J=V),G=G.next}if(J-=q.gprojection,J>g){k=J;break}J>0?J>k&&(k=J,A=q,S=2):k<0&&J>k&&(k=J,A=q,S=2),j=j.next}if(k<g){var u,_,m;if(S==1)u=N,_=M,m=Z;else{u=M,_=N,m=A;let L=C;C=P,P=L,O=!O}let q=null,J=1e100,G=_.edges.head;for(;G!=null;){let L=G.elt,V=m.gnormx*L.gnormx+m.gnormy*L.gnormy;V<J&&(J=V,q=L),G=G.next}if(O?(o.x=-m.gnormx,o.y=-m.gnormy):(o.x=m.gnormx,o.y=m.gnormy),k>=0){let L=m.gp0,V=m.gp1,Y=q.gp0,$=q.gp1,H=0,X=0,ee=0,W=0;H=V.x-L.x,X=V.y-L.y,ee=$.x-Y.x,W=$.y-Y.y;let F=1/(H*H+X*X),D=1/(ee*ee+W*W),T=-(H*(L.x-Y.x)+X*(L.y-Y.y))*F,U=-(H*(L.x-$.x)+X*(L.y-$.y))*F,Q=-(ee*(Y.x-L.x)+W*(Y.y-L.y))*D,K=-(ee*(Y.x-V.x)+W*(Y.y-V.y))*D;T<0?T=0:T>1&&(T=1),U<0?U=0:U>1&&(U=1),Q<0?Q=0:Q>1&&(Q=1),K<0?K=0:K>1&&(K=1);let ie=0,oe=0,se=T;ie=L.x+H*se,oe=L.y+X*se;let ne=0,ae=0,le=U;ne=L.x+H*le,ae=L.y+X*le;let _e=0,ce=0,he=Q;_e=Y.x+ee*he,ce=Y.y+W*he;let te=0,xe=0,de=K;te=Y.x+ee*de,xe=Y.y+W*de;let me=0,Ce=0;me=ie-Y.x,Ce=oe-Y.y;let Te=me*me+Ce*Ce,Le=0,et=0;Le=ne-$.x,et=ae-$.y;let nt=Le*Le+et*et,it=0,qe=0;it=_e-L.x,qe=ce-L.y;let Nt=it*it+qe*qe,It=0,bt=0;It=te-V.x,bt=xe-V.y;let zt=It*It+bt*bt,yt=0,tt=0,Ot=null;Te<nt?(yt=ie,tt=oe,Ot=Y):(yt=ne,tt=ae,Ot=$,Te=nt);let Qt=0,sn=0,Ft=null;if(Nt<zt?(Qt=_e,sn=ce,Ft=L):(Qt=te,sn=xe,Ft=V,Nt=zt),Te<Nt?(C.x=yt,C.y=tt,P.x=Ot.x,P.y=Ot.y,k=Math.sqrt(Te)):(P.x=Qt,P.y=sn,C.x=Ft.x,C.y=Ft.y,k=Math.sqrt(Nt)),k!=0){o.x=P.x-C.x,o.y=P.y-C.y;let Rt=1/k;o.x*=Rt,o.y*=Rt,O&&(o.x=-o.x,o.y=-o.y)}c=k}else{let L=0,V=0;L=q.gp0.x,V=q.gp0.y;let Y=0,$=0;Y=q.gp1.x,$=q.gp1.y;let H=0,X=0;H=Y-L,X=$-V;let ee=m.gnormy*L-m.gnormx*V,W=m.gnormy*Y-m.gnormx*$,F=1/(W-ee),D=(-m.tp1-ee)*F;if(D>i.Config.epsilon){let K=D;L+=H*K,V+=X*K}let T=(-m.tp0-W)*F;if(T<-i.Config.epsilon){let K=T;Y+=H*K,$+=X*K}let U=L*m.gnormx+V*m.gnormy-m.gprojection,Q=Y*m.gnormx+$*m.gnormy-m.gprojection;if(U<Q){P.x=L,P.y=V;let K=-U;C.x=P.x+m.gnormx*K,C.y=P.y+m.gnormy*K,c=U}else{P.x=Y,P.y=$;let K=-Q;C.x=P.x+m.gnormx*K,C.y=P.y+m.gnormy*K,c=Q}}}else c=g}else c=g}}c<a&&(a=c,n.x=l.x,n.y=l.y,s.x=r.x,s.y=r.y),v=v.next}p=p.next}let x=l;x.outer!=null&&(x.outer.zpp_inner=null,x.outer=null),x._isimmutable=null,x._validate=null,x._invalidate=null,x.next=pe.zpp_pool,pe.zpp_pool=x;let y=r;y.outer!=null&&(y.outer.zpp_inner=null,y.outer=null),y._isimmutable=null,y._validate=null,y._invalidate=null,y.next=pe.zpp_pool,pe.zpp_pool=y;let z=o;return z.outer!=null&&(z.outer.zpp_inner=null,z.outer=null),z._isimmutable=null,z._validate=null,z._invalidate=null,z.next=pe.zpp_pool,pe.zpp_pool=z,a}static distance(e,t,n,s,i,l){let r=re();if(l==null&&(l=1e100),mt(e)&&mt(t)){let o=e.circle||e.capsule,a=t.circle||t.capsule,p=en(e),c=en(t),h,u=0,_=0;u=a.worldCOMx-o.worldCOMx,_=a.worldCOMy-o.worldCOMy;let m=Math.sqrt(u*u+_*_);if(h=m-(p+c),h<l){if(m==0)u=1,_=0;else{let z=1/m;u*=z,_*=z}let x=p;n.x=o.worldCOMx+u*x,n.y=o.worldCOMy+_*x;let y=-c;s.x=a.worldCOMx+u*y,s.y=a.worldCOMy+_*y,i.x=u,i.y=_}return h}else{let o=!1;if(mt(e)&&t.type==1){let a=e;e=t,t=a;let p=n;n=s,s=p,o=!0}if(e.type==1&&mt(t)){let a=e.polygon,p=t.circle||t.capsule,c=en(t),h=-1e100,u=null,_=a.edges.head;for(;_!=null;){let m=_.elt,x=m.gnormx*p.worldCOMx+m.gnormy*p.worldCOMy-m.gprojection-c;if(x>l){h=x;break}x>0?x>h&&(h=x,u=m):h<0&&x>h&&(h=x,u=m),_=_.next}if(h<l){let m=u.gp0,x=u.gp1,y=p.worldCOMy*u.gnormx-p.worldCOMx*u.gnormy;if(y<=m.y*u.gnormx-m.x*u.gnormy){let z=0,f=0;z=p.worldCOMx-m.x,f=p.worldCOMy-m.y;let v=Math.sqrt(z*z+f*f);if(h=v-c,h<l){if(v==0)z=1,f=0;else{let b=1/v;z*=b,f*=b}let E=0;n.x=m.x+z*E,n.y=m.y+f*E;let d=-c;s.x=p.worldCOMx+z*d,s.y=p.worldCOMy+f*d,i.x=z,i.y=f}}else if(y>=x.y*u.gnormx-x.x*u.gnormy){let z=0,f=0;z=p.worldCOMx-x.x,f=p.worldCOMy-x.y;let v=Math.sqrt(z*z+f*f);if(h=v-c,h<l){if(v==0)z=1,f=0;else{let b=1/v;z*=b,f*=b}let E=0;n.x=x.x+z*E,n.y=x.y+f*E;let d=-c;s.x=p.worldCOMx+z*d,s.y=p.worldCOMy+f*d,i.x=z,i.y=f}}else{let z=-c;s.x=p.worldCOMx+u.gnormx*z,s.y=p.worldCOMy+u.gnormy*z;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 o&&(i.x=-i.x,i.y=-i.y),h}else{let a=e.polygon,p=t.polygon,c=-1e100,h=null,u=null,_=0,m=a.edges.head;for(;m!=null;){let x=m.elt,y=1e100,z=p.gverts.next;for(;z!=null;){let f=z,v=x.gnormx*f.x+x.gnormy*f.y;v<y&&(y=v),z=z.next}if(y-=x.gprojection,y>l){c=y;break}y>0?y>c&&(c=y,h=x,_=1):c<0&&y>c&&(c=y,h=x,_=1),m=m.next}if(c<l){let x=p.edges.head;for(;x!=null;){let y=x.elt,z=1e100,f=a.gverts.next;for(;f!=null;){let v=f,E=y.gnormx*v.x+y.gnormy*v.y;E<z&&(z=E),f=f.next}if(z-=y.gprojection,z>l){c=z;break}z>0?z>c&&(c=z,u=y,_=2):c<0&&z>c&&(c=z,u=y,_=2),x=x.next}if(c<l){let y,z,f;if(_==1)y=a,z=p,f=h;else{y=p,z=a,f=u;let b=n;n=s,s=b,o=!o}let v=null,E=1e100,d=z.edges.head;for(;d!=null;){let b=d.elt,C=f.gnormx*b.gnormx+f.gnormy*b.gnormy;C<E&&(E=C,v=b),d=d.next}if(o?(i.x=-f.gnormx,i.y=-f.gnormy):(i.x=f.gnormx,i.y=f.gnormy),c>=0){let b=f.gp0,C=f.gp1,P=v.gp0,g=v.gp1,O=0,N=0,M=0,k=0;O=C.x-b.x,N=C.y-b.y,M=g.x-P.x,k=g.y-P.y;let Z=1/(O*O+N*N),A=1/(M*M+k*k),S=-(O*(b.x-P.x)+N*(b.y-P.y))*Z,R=-(O*(b.x-g.x)+N*(b.y-g.y))*Z,j=-(M*(P.x-b.x)+k*(P.y-b.y))*A,q=-(M*(P.x-C.x)+k*(P.y-C.y))*A;S<0?S=0:S>1&&(S=1),R<0?R=0:R>1&&(R=1),j<0?j=0:j>1&&(j=1),q<0?q=0:q>1&&(q=1);let J=0,G=0,L=S;J=b.x+O*L,G=b.y+N*L;let V=0,Y=0,$=R;V=b.x+O*$,Y=b.y+N*$;let H=0,X=0,ee=j;H=P.x+M*ee,X=P.y+k*ee;let W=0,F=0,D=q;W=P.x+M*D,F=P.y+k*D;let T=0,U=0;T=J-P.x,U=G-P.y;let Q=T*T+U*U,K=0,ie=0;K=V-g.x,ie=Y-g.y;let oe=K*K+ie*ie,se=0,ne=0;se=H-b.x,ne=X-b.y;let ae=se*se+ne*ne,le=0,_e=0;le=W-C.x,_e=F-C.y;let ce=le*le+_e*_e,he=0,te=0,xe=null;Q<oe?(he=J,te=G,xe=P):(he=V,te=Y,xe=g,Q=oe);let de=0,me=0,Ce=null;if(ae<ce?(de=H,me=X,Ce=b):(de=W,me=F,Ce=C,ae=ce),Q<ae?(n.x=he,n.y=te,s.x=xe.x,s.y=xe.y,c=Math.sqrt(Q)):(s.x=de,s.y=me,n.x=Ce.x,n.y=Ce.y,c=Math.sqrt(ae)),c!=0){i.x=s.x-n.x,i.y=s.y-n.y;let Te=1/c;i.x*=Te,i.y*=Te,o&&(i.x=-i.x,i.y=-i.y)}return c}else{let b=0,C=0;b=v.gp0.x,C=v.gp0.y;let P=0,g=0;P=v.gp1.x,g=v.gp1.y;let O=0,N=0;O=P-b,N=g-C;let M=f.gnormy*b-f.gnormx*C,k=f.gnormy*P-f.gnormx*g,Z=1/(k-M),A=(-f.tp1-M)*Z;if(A>r.Config.epsilon){let q=A;b+=O*q,C+=N*q}let S=(-f.tp0-k)*Z;if(S<-r.Config.epsilon){let q=S;P+=O*q,g+=N*q}let R=b*f.gnormx+C*f.gnormy-f.gprojection,j=P*f.gnormx+g*f.gnormy-f.gprojection;if(R<j){s.x=b,s.y=C;let q=-R;return n.x=s.x+f.gnormx*q,n.y=s.y+f.gnormy*q,R}else{s.x=P,s.y=g;let q=-j;return n.x=s.x+f.gnormx*q,n.y=s.y+f.gnormy*q,j}}}else return l}else return l}}}};var Re=class Re{static lt(e,t){return e.y<t.y?!0:e.y==t.y?e.x<t.x:!1}static right_turn(e,t,n){let s=n.x-t.x,i=n.y-t.y,l=t.x-e.x;return(t.y-e.y)*s-l*i}static delaunay(e,t,n,s){let i=n.x-t.x,l=n.y-t.y,r=t.x-e.x,o=t.y-e.y,a,p,c;return o*i-r*l>=0?c=!0:(i=s.x-n.x,l=s.y-n.y,r=n.x-t.x,o=n.y-t.y,c=o*i-r*l>=0),c?p=!0:(i=e.x-s.x,l=e.y-s.y,r=s.x-n.x,o=s.y-n.y,p=o*i-r*l>=0),p?a=!0:(i=t.x-e.x,l=t.y-e.y,r=e.x-s.x,o=e.y-s.y,a=o*i-r*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 o=t;for(;;){let a=o;if(a.sort(),a.mag=a.x*a.x+a.y*a.y,o=o.next,o==n)break}}Re.edgeSet==null&&(ul.zpp_pool==null?Re.edgeSet=new ul:(Re.edgeSet=ul.zpp_pool,ul.zpp_pool=Re.edgeSet.next,Re.edgeSet.next=null),Re.edgeSet.lt=Jt.edge_lt,Re.edgeSet.swapped=Jt.edge_swap);let s;Jt.zpp_pool==null?s=new Jt:(s=Jt.zpp_pool,Jt.zpp_pool=s.next,s.next=null);let i=e.vertices,l=e.vertices;if(i!=null){let o=i;for(;;){let a=o,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(!Re.delaunay(a,p,h,u)){let _;Jt.zpp_pool==null?_=new Jt:(_=Jt.zpp_pool,Jt.zpp_pool=_.next,_.next=null),_.a=a,_.b=h,a.id<h.id?(_.id=a.id,_.di=h.id):(_.id=h.id,_.di=a.id);let m=_;s.add(m),m.node=Re.edgeSet.insert(m)}p=h,c=c.next}if(o=o.next,o==l)break}}for(;s.next!=null;){let o=s.pop_unsafe(),a=o.a,p=o.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}}Re.edgeSet.remove_node(o.node);let _=o;_.a=_.b=null,_.node=null,_.next=Jt.zpp_pool,Jt.zpp_pool=_}let r=s;r.a=r.b=null,r.node=null,r.next=Jt.zpp_pool,Jt.zpp_pool=r}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}}Re.queue==null&&(Re.queue=new $i);let l=n.prev,r=n.next;for(Re.queue.add(n);l!=t||r!=t;)l==t||r!=t&&(l.y<r.y||l.y==r.y&&l.x<r.x)?(Re.queue.add(r),r.rightchain=!1,r=r.next):(Re.queue.add(l),l.rightchain=!0,l=l.prev);Re.queue.add(t),Re.stack==null&&(Re.stack=new $i),Re.stack.add(Re.queue.pop_unsafe());let o=Re.queue.pop_unsafe();for(Re.stack.add(o);;){let a=Re.queue.pop_unsafe();if(Re.queue.head==null)break;if(a.rightchain!=Re.stack.head.elt.rightchain){for(;;){let p=Re.stack.pop_unsafe();if(Re.stack.head==null)break;e.add_diagonal(p,a)}Re.stack.add(o)}else{let p=Re.stack.pop_unsafe();for(;Re.stack.head!=null;){let c=Re.stack.head.elt,h=a.x-p.x,u=a.y-p.y,_=p.x-c.x,x=(p.y-c.y)*h-_*u;if(a.rightchain&&x>=0||!a.rightchain&&x<=0)break;e.add_diagonal(c,a),p=c,Re.stack.pop()}Re.stack.add(p)}Re.stack.add(a),o=a}if(Re.stack.head!=null)for(Re.stack.pop();Re.stack.head!=null;){let a=Re.stack.pop_unsafe();if(Re.stack.head==null)break;e.add_diagonal(n,a)}return e}};Re.queue=null,Re.stack=null,Re.edgeSet=null;var qi=Re;var wl=class wl{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&&wl._wrapFn&&(this.outer=wl._wrapFn(this)),this.outer}};wl._zpp=null,wl._wrapFn=null;var Wi=wl;var br=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 An=class An{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;An.initFields(this)}static initFields(e){let t=An._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=On.Interactor(),e.cbsets=new t.util.ZNPList_ZPP_CallbackSet,e.cbTypes=new t.util.ZNPList_ZPP_CbType}static get(e,t){let n=e.id<t.id?e.id:t.id,s=e.id<t.id?t.id:e.id,i=e.cbsets.length<t.cbsets.length?e.cbsets:t.cbsets,l=null,r=i.head;for(;r!=null;){let o=r.elt;if(o.id==n&&o.di==s){l=o;break}r=r.next}return l}static int_callback(e,t,n){let s=e.int1,i=e.int2,l,r=t.options1,o=s.cbTypes;if(r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.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=An._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=An._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,r;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?r=new t.util.ZNPNode_ZPP_CbType:(r=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=r.next,r.next=null),r.elt=e;let o=r;s==null?(o.next=l.head,l.head=o):(o.next=s.next,s.next=o),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=gt.zpp_pool,gt.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=An._nape;e.zpp_inner_i.group=this.group;let n=this.outer_i;n.zpp_inner_i.wrap_cbTypes==null&&n.zpp_inner_i.setupcbTypes();let s=n.zpp_inner_i.wrap_cbTypes;s.zpp_inner.valmod();let i=t.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let l=i.zpp_inner;l.zpp_inner.valmod(),l.zpp_inner.zip_length&&(l.zpp_inner.zip_length=!1,l.zpp_inner.user_length=l.zpp_inner.inner.length);let r=l.zpp_inner.user_length;i.zpp_critical=!0;let o;if(i.zpp_i<r?o=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,o=!1),!o)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){An._initialized||(An._initialized=!0,An._zpp=e,An._nape=t)}};An._nape=null,An._zpp=null,An._initialized=!1;var pn=An;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;pn.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;fe.zpp_pool==null?t=new fe:(t=fe.zpp_pool,fe.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 r=l.constraints.head;for(;r!=null;)r.elt.outer.visitBodies(this.connectedBodies_cont.bind(this)),r=r.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 r=l.data;if(r!==this){let p=r.outer;s.zpp_inner.reverse_flag?s.push(p):s.unshift(p)}let o=l.parent;o!=null&&(l===o.prev?o.prev=null:o.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=o}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 o=l.elt;if(!o.sleeping&&(e===4||o.type===e)){let a=o.b1===this?o.b2:o.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 r=je.bodyset;if(r.parent!=null){let o=r.parent;for(;o!=null;)if(o.prev!=null)o=o.prev;else if(o.next!=null)o=o.next;else{let a=o.parent;a!=null&&(o===a.prev?a.prev=null:a.next=null,o.parent=null);let p=o;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,o=a}r.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 r=this.aabb.maxx-this.aabb.minx,o=this.aabb.maxy-this.aabb.miny,a=r*r+o*o,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,r=(i*this.axisx+n*this.axisy)*l;this.axisy=(i*this.axisy-n*this.axisx)*l,this.axisx=r}}}sweepValidate(e){if(e.type===0)e.worldCOMx=this.posx+(this.axisy*e.localCOMx-this.axisx*e.localCOMy),e.worldCOMy=this.posy+(e.localCOMx*this.axisx+e.localCOMy*this.axisy);else{let t=e.polygon,n=t.lverts.next,s=t.gverts.next;for(;s!=null;){let p=s,c=n;n=n.next,p.x=this.posx+(this.axisy*c.x-this.axisx*c.y),p.y=this.posy+(c.x*this.axisx+c.y*this.axisy),s=s.next}let i=t.edges.head,l=t.gverts.next,r=l;for(l=l.next;l!=null;){let p=l,c=i.elt;i=i.next,c.gnormx=this.axisy*c.lnormx-this.axisx*c.lnormy,c.gnormy=c.lnormx*this.axisx+c.lnormy*this.axisy,c.gprojection=this.posx*c.gnormx+this.posy*c.gnormy+c.lprojection,c.tp0=r.y*c.gnormx-r.x*c.gnormy,c.tp1=p.y*c.gnormx-p.x*c.gnormy,r=p,l=l.next}let o=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=r.y*a.gnormx-r.x*a.gnormy,a.tp1=o.y*a.gnormx-o.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(ue.poolVec2==null?l=new i.geom.Vec2:(l=ue.poolVec2,ue.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===ue.nextVec2&&(ue.nextVec2=null)),l.zpp_inner==null){let r;pe.zpp_pool==null?r=new pe:(r=pe.zpp_pool,pe.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=e,r.y=t,l.zpp_inner=r,l.zpp_inner.outer=l}else{if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let o;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x===e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),o=l.zpp_inner.y===t):o=!1,o||(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner._invalidate!=null&&l.zpp_inner._invalidate(l.zpp_inner))}return l.zpp_inner.weak=!1,l}setupPosition(){this.wrap_pos=this._setupVec2Wrapper(this.posx,this.posy,null,null),this.wrap_pos.zpp_inner._inuse=!0,this.world?this.wrap_pos.zpp_inner._immutable=!0:(this.wrap_pos.zpp_inner._invalidate=this.pos_invalidate.bind(this),this.wrap_pos.zpp_inner._validate=this.pos_validate.bind(this))}setupVelocity(){this.wrap_vel=this._setupVec2Wrapper(this.velx,this.vely,null,null),this.wrap_vel.zpp_inner._inuse=!0,this.world?this.wrap_vel.zpp_inner._immutable=!0:(this.wrap_vel.zpp_inner._invalidate=this.vel_invalidate.bind(this),this.wrap_vel.zpp_inner._validate=this.vel_validate.bind(this))}setupkinvel(){this.wrap_kinvel=this._setupVec2Wrapper(this.kinvelx,this.kinvely,null,null),this.wrap_kinvel.zpp_inner._inuse=!0,this.world?this.wrap_kinvel.zpp_inner._immutable=!0:(this.wrap_kinvel.zpp_inner._invalidate=this.kinvel_invalidate.bind(this),this.wrap_kinvel.zpp_inner._validate=this.kinvel_validate.bind(this))}setupsvel(){this.wrap_svel=this._setupVec2Wrapper(this.svelx,this.svely,null,null),this.wrap_svel.zpp_inner._inuse=!0,this.world?this.wrap_svel.zpp_inner._immutable=!0:(this.wrap_svel.zpp_inner._invalidate=this.svel_invalidate.bind(this),this.wrap_svel.zpp_inner._validate=this.svel_validate.bind(this))}setupForce(){this.wrap_force=this._setupVec2Wrapper(this.forcex,this.forcey,null,null),this.wrap_force.zpp_inner._inuse=!0,this.world?this.wrap_force.zpp_inner._immutable=!0:(this.wrap_force.zpp_inner._invalidate=this.force_invalidate.bind(this),this.wrap_force.zpp_inner._validate=this.force_validate.bind(this))}cvel_validate(){this.wrapcvel.zpp_inner.x=this.velx+this.kinvelx,this.wrapcvel.zpp_inner.y=this.vely+this.kinvely}setup_cvel(){this.wrapcvel=this._setupVec2Wrapper(this.velx+this.kinvelx,this.vely+this.kinvely,null,null),this.wrapcvel.zpp_inner._inuse=!0,this.wrapcvel.zpp_inner._immutable=!0,this.wrapcvel.zpp_inner._validate=this.cvel_validate.bind(this)}invalidate_rot(){this.zip_axis=!0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}validate_axis(){this.zip_axis&&(this.zip_axis=!1,this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}quick_validate_axis(){this.zip_axis&&(this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}delta_rot(e){if(e*e>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let t=e*e,n=1-.5*t,s=1-t*t/8,i=(n*this.axisx+e*this.axisy)*s;this.axisy=(n*this.axisy-e*this.axisx)*s,this.axisx=i}this.zip_axis=!1}invalidate_mass(){this.zip_mass=!0,this.invalidate_gravMass()}validate_mass(){if(this.zip_mass||this.massMode===0&&!1){if(this.zip_mass=!1,this.massMode===0){this.cmass=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cmass+=n.area*n.material.density,t=t.next}}this.type===2&&!this.nomove?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0)}}invalidate_gravMass(){this.gravMassMode!==1&&(this.zip_gravMass=!0),this.gravMassMode!==2&&(this.zip_gravMassScale=!0),this.wake()}validate_gravMass(){this.zip_gravMass&&(this.zip_gravMass=!1,this.validate_mass(),this.gravMassMode===0?(this.validate_mass(),this.gravMass=this.cmass):this.gravMassMode===2&&(this.validate_mass(),this.gravMass=this.cmass*this.gravMassScale))}invalidate_gravMassScale(){this.gravMassMode!==2?this.zip_gravMassScale=!0:this.invalidate_gravMass()}validate_gravMassScale(){this.zip_gravMassScale&&(this.zip_gravMassScale=!1,this.gravMassMode===0?this.gravMassScale=1:this.gravMassMode===1&&(this.validate_mass(),this.gravMassScale=this.gravMass/this.cmass))}invalidate_inertia(){this.zip_inertia=!0,this.wake()}validate_inertia(){if(this.zip_inertia||this.inertiaMode===0&&!1){if(this.zip_inertia=!1,this.inertiaMode===0){this.cinertia=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cinertia+=n.inertia*n.area*n.material.density,t=t.next}}this.type===2&&!this.norotate?(this.inertia=this.cinertia,this.sinertia=this.iinertia=1/this.inertia):(this.inertia=1/0,this.sinertia=this.iinertia=0)}}invalidate_wake(){this.wake()}invalidate_aabb(){this.zip_aabb=!0}validate_aabb(){if(this.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(this.zip_aabb){this.zip_aabb=!1,this.aabb.minx=1/0,this.aabb.miny=1/0,this.aabb.maxx=-1/0,this.aabb.maxy=-1/0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.zip_aabb&&t.body!=null&&(t.zip_aabb=!1,t.type===0?this._validateCircleAABB(t.circle):this._validatePolygonAABB(t.polygon)),t.aabb.minx<this.aabb.minx&&(this.aabb.minx=t.aabb.minx),t.aabb.maxx>this.aabb.maxx&&(this.aabb.maxx=t.aabb.maxx),t.aabb.miny<this.aabb.miny&&(this.aabb.miny=t.aabb.miny),t.aabb.maxy>this.aabb.maxy&&(this.aabb.maxy=t.aabb.maxy),e=e.next}}}_validateCircleAABB(e){e.zip_worldCOM&&e.body!=null&&(e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type===1&&this._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)),this.validate_axis(),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy));let t=e.radius;e.aabb.minx=e.worldCOMx-t,e.aabb.miny=e.worldCOMy-t,e.aabb.maxx=e.worldCOMx+t,e.aabb.maxy=e.worldCOMy+t}_validatePolygonAABB(e){if(e.zip_gverts&&e.body!=null){e.zip_gverts=!1,e.validate_lverts(),this.validate_axis();let s=e.lverts.next,i=e.gverts.next;for(;i!=null;){let l=i,r=s;s=s.next,l.x=e.body.posx+(e.body.axisy*r.x-e.body.axisx*r.y),l.y=e.body.posy+(r.x*e.body.axisx+r.y*e.body.axisy),i=i.next}}if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let t=e.gverts.next;e.aabb.minx=t.x,e.aabb.miny=t.y,e.aabb.maxx=t.x,e.aabb.maxy=t.y;let n=e.gverts.next.next;for(;n!=null;){let s=n;s.x<e.aabb.minx&&(e.aabb.minx=s.x),s.x>e.aabb.maxx&&(e.aabb.maxx=s.x),s.y<e.aabb.miny&&(e.aabb.miny=s.y),s.y>e.aabb.maxy&&(e.aabb.maxy=s.y),n=n.next}}aabb_validate(){if(this.shapes.head==null)throw new Error("Error: bounds only makes sense when Body has shapes");this.validate_aabb()}invalidate_localCOM(){this.zip_localCOM=!0,this.zip_worldCOM=!0}invalidate_worldCOM(){this.zip_worldCOM=!0}_computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y,e.localCOMx+=e.lverts.next.next.x,e.localCOMy+=e.lverts.next.next.y,e.localCOMx*=.5,e.localCOMy*=.5;else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let p=n;t+=i.x*(p.y-s.y);let c=p.y*i.x-p.x*i.y;e.localCOMx+=(i.x+p.x)*c,e.localCOMy+=(i.y+p.y)*c,s=i,i=p,n=n.next}n=e.lverts.next;let l=n;t+=i.x*(l.y-s.y);let r=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*r,e.localCOMy+=(i.y+l.y)*r,s=i,i=l,n=n.next;let o=n;t+=i.x*(o.y-s.y);let a=o.y*i.x-o.x*i.y;e.localCOMx+=(i.x+o.x)*a,e.localCOMy+=(i.y+o.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 r=l;r.elt=null,r.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=r,e.modified=!0,e.length--,e.pushmod=!0;break}s=i,i=i.next}}copy(){let e=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(pn.prototype))n!=="constructor"&&!(n in je.prototype)&&(je.prototype[n]=pn.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 Gn=je;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;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=fn._zpp;pn.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=fn._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=fn._zppOf(e);t.compound=null,this.space!=null&&this.space.remBody(t)}bodies_modifiable(){this.immutable_midstep("Compound::bodies")}constraints_adder(e){let t=fn._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=fn._zppOf(e);t.compound=null,this.space!=null&&this.space.remConstraint(t)}constraints_modifiable(){this.immutable_midstep("Compound::constraints")}compounds_adder(e){let t=fn._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=fn._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=fn._nape,s=fn._zpp,i=e==null;e==null&&(e=[]),t==null&&(t=[]);let l=new n.phys.Compound,r=this.compounds.head;for(;r!=null;){let c=r.elt.copy(e,t);if(c.zpp_inner.immutable_midstep("Compound::compound"),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_compounds.remove(c),l!=null)){let h=l.zpp_inner.wrap_compounds;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c)}r=r.next}let o=this.bodies.head;for(;o!=null;){let p=o.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)}o=o.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(pn.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(fn.prototype,e)&&(fn.prototype[e]=pn.prototype[e])}};fn._nape=null,fn._zpp=null,fn._wrapFn=null;var di=fn;var Ht=class Ht{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 Ht._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Ht._wrapFn)this.outer=Ht._wrapFn(this);else{this.outer=new Ht._nape.phys.FluidProperties;let e=this.outer.zpp_inner;e.outer=null,e.next=Ht.zpp_pool,Ht.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Ht._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Ht.zpp_pool==null?e=new Ht:(e=Ht.zpp_pool,Ht.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=Ht._zpp,t=Ht._nape,n=this.gravityx??0,s=this.gravityy??0;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let r=!1;l._validate!=null&&l._validate(),(l.x!==n||l.y!==s)&&(r=!0),r&&(l.x=n,l.y=s,l._invalidate!=null&&l._invalidate(l))}i.zpp_inner.weak=!1,this.wrap_gravity=i,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=this.gravity_invalidate.bind(this),this.wrap_gravity.zpp_inner._validate=this.gravity_validate.bind(this)}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_fluidprops(),e=e.next}};Ht.zpp_pool=null,Ht._nape=null,Ht._zpp=null,Ht._wrapFn=null;var qn=Ht;var tn=class tn{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 tn._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(tn._wrapFn)this.outer=tn._wrapFn(this);else{this.outer=new tn._nape.phys.Material;let e=this.outer.zpp_inner;e.outer=null,e.next=tn.zpp_pool,tn.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new tn._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e=new tn;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}};tn.zpp_pool=null,tn.WAKE=1,tn.PROPS=2,tn.ANGDRAG=4,tn.ARBITERS=8,tn._nape=null,tn._zpp=null,tn._wrapFn=null;var Ie=tn;var Wn=class Wn{constructor(e){this.outer=null;this.body=null;this.type=0;this.area=0;this.zip_area_inertia=!1;this.inertia=0;this.angDrag=0;this.zip_angDrag=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;this.sweepRadius=0;this.zip_sweepRadius=!1;this.sweepCoef=0;this.circle=null;this.polygon=null;this.refmaterial=null;this.material=null;this.filter=null;this.fluidProperties=null;this.fluidEnabled=!1;this.sensorEnabled=!1;this.sweep=null;this.node=null;this.pairs=null;this.aabb=null;this.zip_aabb=!1;this.ishape=null;this.userData=null;e!==void 0&&this._initShape(e)}static _initEnums(e,t){let n=()=>{t.internal=!0;let s=new e.shape.ShapeType;return t.internal=!1,s};t.ShapeType_CIRCLE==null&&(t.ShapeType_CIRCLE=n()),t.ShapeType_POLYGON==null&&(t.ShapeType_POLYGON=n()),t.ShapeType_CAPSULE==null&&(t.ShapeType_CAPSULE=n()),Wn.types=[t.ShapeType_CIRCLE,t.ShapeType_POLYGON,t.ShapeType_CAPSULE]}_initShape(e){let t=Wn._zpp;pn.initFields(this),this.pairs=new t.util.ZNPList_ZPP_AABBPair,this.ishape=this,this.type=e;let n;fe.zpp_pool==null?n=new fe:(n=fe.zpp_pool,fe.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 Ie,this.sweepRadius=this.sweepCoef=0}static _init(){if(!Wn._initialized){Wn._initialized=!0;for(let e of Object.getOwnPropertyNames(pn.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(Wn.prototype,e)&&(Wn.prototype[e]=pn.prototype[e])}}isCircle(){return this.type===0}isPolygon(){return this.type===1}isCapsule(){return!!this._isCapsule}invalidate_sweepRadius(){this.zip_sweepRadius=!0}validate_sweepRadius(){this.zip_sweepRadius&&(this.zip_sweepRadius=!1,this.type===0?this.circle.__validate_sweepRadius():this.polygon.__validate_sweepRadius())}clear(){this.type===0?this.circle.__clear():this.polygon.__clear()}validate_aabb(){this.zip_aabb&&this.body!=null&&(this.zip_aabb=!1,this.type===0?this.circle.__validate_aabb():this.polygon.__validate_aabb())}force_validate_aabb(){this.type===0?this.circle._force_validate_aabb():this.polygon._force_validate_aabb()}invalidate_aabb(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}validate_area_inertia(){this.zip_area_inertia&&(this.zip_area_inertia=!1,this.type===0?this.circle.__validate_area_inertia():this.polygon.__validate_area_inertia())}validate_angDrag(){(this.zip_angDrag||this.refmaterial.dynamicFriction!==this.material.dynamicFriction)&&(this.zip_angDrag=!1,this.refmaterial.dynamicFriction=this.material.dynamicFriction,this.type===0?this.circle.__validate_angDrag():this.polygon.__validate_angDrag())}validate_localCOM(){this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy))}validate_worldCOM(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.validate_localCOM();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy)}}getworldCOM(){if(this.body==null)throw new Error("Error: worldCOM only makes sense when Shape belongs to a Body");this.validate_worldCOM(),this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy}invalidate_area_inertia(){this.zip_area_inertia=!0,this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia())}invalidate_angDrag(){this.zip_angDrag=!0}invalidate_localCOM(){this.zip_localCOM=!0,this.invalidate_area_inertia(),this.type===0&&(this.zip_sweepRadius=!0),this.invalidate_angDrag(),this.invalidate_worldCOM(),this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0)}invalidate_worldCOM(){this.zip_worldCOM=!0,this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}invalidate_material(e){(e&Ie.WAKE)!==0&&this.wake(),(e&Ie.ARBITERS)!==0&&this.body!=null&&this.body.refreshArbiters(),(e&Ie.PROPS)!==0&&this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia()),(e&Ie.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=Wn._zpp,t=this.type===0?this.circle.__copy():this.polygon.__copy();this.zip_area_inertia?t.invalidate_area_inertia():(t.area=this.area,t.inertia=this.inertia),this.zip_sweepRadius?t.zip_sweepRadius=!0:(t.sweepRadius=this.sweepRadius,t.sweepCoef=this.sweepCoef),this.zip_angDrag?t.invalidate_angDrag():t.angDrag=this.angDrag,this.zip_aabb?(t.zip_aabb=!0,t.body!=null&&(t.body.zip_aabb=!0)):(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy);let n=t.material;n.outer=null,n.next=Ie.zpp_pool,Ie.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}};Wn._nape=null,Wn._zpp=null,Wn.types=[],Wn._initialized=!1;var Ji=Wn;var Jn=class Jn{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(Jn._initialized)return;Jn._initialized=!0;let t=Jn._zpp.shape.ZPP_Shape.prototype,n=Jn.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=Jn._zpp,t=Jn._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=Jn._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=Jn._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}};Jn._nape=null,Jn._zpp=null,Jn._initialized=!1;var Si=Jn;var bn=class bn{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&&(bn._wrapFn?this.outer=bn._wrapFn(this):(bn.internal=!0,this.outer=new bn._nape.shape.Edge,bn.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=bn._zpp,t=bn._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=bn._zpp,t=bn._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)}};bn.zpp_pool=null,bn.internal=!1,bn._nape=null,bn._zpp=null,bn._wrapFn=null;var $e=bn;var Zt=class Zt{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=Zt._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(Zt._initialized)return;Zt._initialized=!0;let t=Zt._zpp.shape.ZPP_Shape.prototype,n=Zt.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=Zt._zpp;e.zpp_inner._invalidate=this.lverts_pa_invalidate.bind(this),e.zpp_inner._isimmutable=this.lverts_pa_immutable.bind(this);let n=null,s=null,i=this.lverts.next;for(;i!=null&&i!==e.zpp_inner;)n=n==null?this.gverts.next:n.next,s=s==null?this.edges.head:s.next,i=i.next;let l;if(t.geom.ZPP_Vec2.zpp_pool==null?l=new t.geom.ZPP_Vec2:(l=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!0,l.x=0,l.y=0,this.gverts.insert(n,l),this.lverts.next.next!=null)if(this.lverts.next.next.next==null){let r;$e.zpp_pool==null?r=new $e:(r=$e.zpp_pool,$e.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.add(r);let o;$e.zpp_pool==null?o=new $e:(o=$e.zpp_pool,$e.zpp_pool=o.next,o.next=null),o.polygon=this,this.edges.add(o),this.edgeCnt+=2}else{let r;$e.zpp_pool==null?r=new $e:(r=$e.zpp_pool,$e.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.insert(s,r),this.edgeCnt++}l._validate=this.gverts_pa_validate.bind(this)}lverts_subber(e){this.cleanup_lvert(e.zpp_inner)}lverts_invalidate(e){this.invalidate_lverts()}lverts_validate(){this.validate_lverts()}lverts_modifiable(){if(this.immutable_midstep("Polygon::localVerts"),this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}gverts_validate(){this._validateGverts()}edges_validate(){this.validate_lverts()}getlverts(){let e=Zt._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=Zt._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=Zt._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 _=s.x-h.x,m=s.y-h.y,x=Math.sqrt(_*_+m*m);u.length=x;let y=1/x;_*=y,m*=y;let z=_;_=-m,m=z,u.lprojection=_*s.x+m*s.y,u.lnormx=_,u.lnormy=m,u.wrap_lnorm!=null&&(u.wrap_lnorm.zpp_inner.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 r=s.x-i.x,o=s.y-i.y,a=Math.sqrt(r*r+o*o);l.length=a;let p=1/a;r*=p,o*=p;let c=r;r=-o,o=c,l.lprojection=r*s.x+o*s.y,l.lnormx=r,l.lnormy=o,l.wrap_lnorm!=null&&(l.wrap_lnorm.zpp_inner.x=r,l.wrap_lnorm.zpp_inner.y=o)}}validate_gverts(){this._validateGverts()}validate_gaxi(){if(this.zip_gaxi&&this.body!=null){this.zip_gaxi=!1,this.validate_laxi();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this._validateGverts();let t=this.edges.head,n=this.gverts.next,s=n;for(n=n.next;n!=null;){let r=n,o=t.elt;t=t.next,o.gp0=s,o.gp1=r,o.gnormx=e.axisy*o.lnormx-e.axisx*o.lnormy,o.gnormy=o.lnormx*e.axisx+o.lnormy*e.axisy,o.gprojection=e.posx*o.gnormx+e.posy*o.gnormy+o.lprojection,o.wrap_gnorm!=null&&(o.wrap_gnorm.zpp_inner.x=o.gnormx,o.wrap_gnorm.zpp_inner.y=o.gnormy),o.tp0=o.gp0.y*o.gnormx-o.gp0.x*o.gnormy,o.tp1=o.gp1.y*o.gnormx-o.gp1.x*o.gnormy,s=r,n=n.next}let i=this.gverts.next,l=t.elt;l.gp0=s,l.gp1=i,l.gnormx=e.axisy*l.lnormx-e.axisx*l.lnormy,l.gnormy=l.lnormx*e.axisx+l.lnormy*e.axisy,l.gprojection=e.posx*l.gnormx+e.posy*l.gnormy+l.lprojection,l.wrap_gnorm!=null&&(l.wrap_gnorm.zpp_inner.x=l.gnormx,l.wrap_gnorm.zpp_inner.y=l.gnormy),l.tp0=l.gp0.y*l.gnormx-l.gp0.x*l.gnormy,l.tp1=l.gp1.y*l.gnormx-l.gp1.x*l.gnormy}}_validateGverts(){if(this.zip_gverts&&this.body!=null){this.zip_gverts=!1,this.validate_lverts();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let t=this.lverts.next,n=this.gverts.next;for(;n!=null;){let s=n,i=t;t=t.next,s.x=e.posx+(e.axisy*i.x-e.axisx*i.y),s.y=e.posy+(i.x*e.axisx+i.y*e.axisy),n=n.next}}}cleanup_lvert(e){let t=Zt._zpp,n=null,s=null,i=this.lverts.next;for(;i!=null&&i!==e;)n=n==null?this.gverts.next:n.next,s=s==null?this.edges.head:s.next,i=i.next;let l=n==null?this.gverts.next:n.next;this.gverts.erase(n);let r=l;if(r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=r,this.edgeCnt===2){let o=this.edges.pop_unsafe();o.polygon=null,o.next=$e.zpp_pool,$e.zpp_pool=o,o=this.edges.pop_unsafe(),o.polygon=null,o.next=$e.zpp_pool,$e.zpp_pool=o,this.edgeCnt=0}else if(this.edgeCnt!==0){let o=s==null?this.edges.head.elt:s.next.elt;this.edges.erase(s),o.polygon=null,o.next=$e.zpp_pool,$e.zpp_pool=o,this.edgeCnt--}}splice_collinear(){this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real())}splice_collinear_real(){let e=Zt._nape;if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)return;let t=null,n=this.lverts.next;for(;n!=null;){let i=n.next==null?this.lverts.next:n.next,l=n.x-i.x,r=n.y-i.y;l*l+r*r<e.Config.epsilon*e.Config.epsilon?(this.cleanup_lvert(n),n=this.lverts.erase(t)):(t=n,n=n.next)}if(this.lverts.next==null)return;let s;for(;;){s=!1;let i=this.lverts.next;for(;i!=null;){let l=i.next==null?this.lverts.next:i.next,r=l.next==null?this.lverts.next:l.next,o=l.x-i.x,a=l.y-i.y,p=r.x-l.x,h=(r.y-l.y)*o-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=Zt._nape,t=Zt._zpp;if(this.zip_valid){if(this.zip_valid=!1,this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real()),this.lverts.length<3)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;if(this.validate_lverts(),this.validate_area_inertia(),this.area<e.Config.epsilon)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;{let n=!1,s=!1,i=!0,l=this.lverts.next,r=l;l=l.next;let o=l;for(l=l.next;l!=null;){let a=l,p=a.x-o.x,c=a.y-o.y,h=o.x-r.x,_=(o.y-r.y)*p-h*c;if(_>e.Config.epsilon?s=!0:_<-e.Config.epsilon&&(n=!0),s&&n){i=!1;break}r=o,o=a,l=l.next}if(i){l=this.lverts.next;let a=l,p=a.x-o.x,c=a.y-o.y,h=o.x-r.x,_=(o.y-r.y)*p-h*c;if(_>e.Config.epsilon?s=!0:_<-e.Config.epsilon&&(n=!0),!(s&&n)){r=o,o=a,l=l.next;let m=l,x=m.x-o.x,y=m.y-o.y,z=o.x-r.x,v=(o.y-r.y)*x-z*y;v>e.Config.epsilon?s=!0:v<-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,_=u.next;for(;_!=null&&a;){let m=_;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,_=_.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,_=u.next;for(;_!=null&&a;){let m=_;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,_=_.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,r=e.y-n.y,o=t.x-e.x,a=t.y-e.y,p=s.x-n.x,c=s.y-n.y,h=a*p-o*c;if(h*h>i.Config.epsilon){h=1/h;let u=(c*l-p*r)*h;if(u>i.Config.epsilon&&u<1-i.Config.epsilon){let _=(a*l-o*r)*h;if(_>i.Config.epsilon&&_<1-i.Config.epsilon)return!1}}return!0}__validate_aabb(){if(this._validateGverts(),this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let e=this.gverts.next;this.aabb.minx=e.x,this.aabb.miny=e.y,this.aabb.maxx=e.x,this.aabb.maxy=e.y;let t=this.gverts.next.next;for(;t!=null;){let n=t;n.x<this.aabb.minx&&(this.aabb.minx=n.x),n.x>this.aabb.maxx&&(this.aabb.maxx=n.x),n.y<this.aabb.miny&&(this.aabb.miny=n.y),n.y>this.aabb.maxy&&(this.aabb.maxy=n.y),t=t.next}}_force_validate_aabb(){let e=this.body,t=this.lverts.next,n=this.gverts.next,s=t;t=t.next,n.x=e.posx+(e.axisy*s.x-e.axisx*s.y),n.y=e.posy+(s.x*e.axisx+s.y*e.axisy),this.aabb.minx=n.x,this.aabb.miny=n.y,this.aabb.maxx=n.x,this.aabb.maxy=n.y;let i=this.gverts.next.next;for(;i!=null;){let l=i,r=t;t=t.next,l.x=e.posx+(e.axisy*r.x-e.axisx*r.y),l.y=e.posy+(r.x*e.axisx+r.y*e.axisy),l.x<this.aabb.minx&&(this.aabb.minx=l.x),l.x>this.aabb.maxx&&(this.aabb.maxx=l.x),l.y<this.aabb.miny&&(this.aabb.miny=l.y),l.y>this.aabb.maxy&&(this.aabb.maxy=l.y),i=i.next}}__validate_sweepRadius(){let e=0,t=0;this.validate_laxi();let n=this.lverts.next;for(;n!=null;){let i=n,l=i.x*i.x+i.y*i.y;l>e&&(e=l),n=n.next}let s=this.edges.head;for(;s!=null;){let i=s.elt;if(i.lprojection<t&&(t=i.lprojection,t<0))break;s=s.next}t<0&&(t=0),this.sweepRadius=Math.sqrt(e),this.sweepCoef=this.sweepRadius-t}__validate_area_inertia(){if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)this.area=0,this.inertia=0;else{this.area=0;let e=0,t=0,n=this.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let p=n,c=i.y*s.x-i.x*s.y,h=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y);e+=c*h,t+=c,this.area+=i.x*(p.y-s.y),s=i,i=p,n=n.next}n=this.lverts.next;let l=n,r=i.y*s.x-i.x*s.y,o=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y);e+=r*o,t+=r,this.area+=i.x*(l.y-s.y),s=i,i=l,n=n.next;let a=n;r=i.y*s.x-i.x*s.y,o=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y),e+=r*o,t+=r,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=Zt._nape;if(this.lverts.length<3)throw new Error("Error: Polygon's with less than 3 vertices have no meaningful angDrag");this.validate_area_inertia(),this.validate_laxi();let t=0,n=this.edges.head,s=0,i=this.lverts.next,l=i,r=i.next;for(;r!=null;){let o=r,a=n.elt;n=n.next,s+=a.length;let p=o.x-l.x,c=o.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,_=l.x,m=l.y;_+=p*u,m+=c*u;let x=a.lnormy*l.x-a.lnormx*l.y,y=a.lnormy*_-a.lnormx*m,z=(y*y*y-x*x*x)/(3*(y-x));t+=z*u*a.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,_=l.x,m=l.y;_+=p*u,m+=c*u;let x=a.lnormy*_-a.lnormx*m,y=a.lnormy*o.x-a.lnormx*o.y,z=(y*y*y-x*x*x)/(3*(y-x));t+=z*e.Config.fluidVacuumDrag*(1-u)*a.length*e.Config.fluidAngularDrag}l=o,r=r.next}{let o=this.lverts.next,a=n.elt;s+=a.length;let p=o.x-l.x,c=o.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,_=l.x,m=l.y;_+=p*u,m+=c*u;let x=a.lnormy*l.x-a.lnormx*l.y,y=a.lnormy*_-a.lnormx*m,z=(y*y*y-x*x*x)/(3*(y-x));t+=z*u*a.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,_=l.x,m=l.y;_+=p*u,m+=c*u;let x=a.lnormy*_-a.lnormx*m,y=a.lnormy*o.x-a.lnormx*o.y,z=(y*y*y-x*x*x)/(3*(y-x));t+=z*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 o=t;e+=s.x*(o.y-n.y);let a=o.y*s.x-o.x*s.y;this.localCOMx+=(s.x+o.x)*a,this.localCOMy+=(s.y+o.y)*a,n=s,s=o,t=t.next}t=this.lverts.next;let i=t;e+=s.x*(i.y-n.y);let l=i.y*s.x-i.x*s.y;this.localCOMx+=(s.x+i.x)*l,this.localCOMy+=(s.y+i.y)*l,n=s,s=i,t=t.next;let r=t;e+=s.x*(r.y-n.y),l=r.y*s.x-r.x*s.y,this.localCOMx+=(s.x+r.x)*l,this.localCOMy+=(s.y+r.y)*l,e=1/(3*e),this.localCOMx*=e,this.localCOMy*=e}}localCOM_validate(){if(this.lverts.next==null)throw new Error("Error: An empty polygon does not have any meaningful localCOM");this.validate_localCOM()}localCOM_invalidate(e){this.validate_localCOM();let t=e.x-this.localCOMx,n=e.y-this.localCOMy,s=this.lverts.next;for(;s!=null;)s.x+=t,s.y+=n,s=s.next;this.invalidate_lverts()}setupLocalCOM(){let e=Zt._zpp,t=Zt._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();let s=this;if(s._isCapsule){let i=((e<0?-e:e)+(t<0?-t:t))/2;s._capsuleRadius*=i,s._capsuleHalfLength*=i}}__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=Zt._nape,t=this;if(t._isCapsule){let r=2*(t._capsuleHalfLength+t._capsuleRadius),o=2*t._capsuleRadius;this.validate_localCOM();let a=this.localCOMx,p=this.localCOMy,c;return(a!==0||p!==0)&&(c=new e.geom.Vec2(a,p),c.zpp_inner.weak=!0),new e.shape.Capsule(r,o,c).zpp_inner_zn}this.outer_zn.zpp_inner_zn.wrap_lverts==null&&this.outer_zn.zpp_inner_zn.getlverts();let n=this.outer_zn.zpp_inner_zn.wrap_lverts,s=[],i=n.iterator();for(;i.hasNext();)s.push(i.next());return new e.shape.Polygon(s).zpp_inner_zn}};Zt._nape=null,Zt._zpp=null,Zt._initialized=!1;var Un=Zt;var ss=class ss{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 r=1;l.localCOMx+=l.lverts.next.next.x*r,l.localCOMy+=l.lverts.next.next.y*r;let o=.5;l.localCOMx*=o,l.localCOMy*=o}else{l.localCOMx=0,l.localCOMy=0;let r=0,o=l.lverts.next,a=o;o=o.next;let p=o;for(o=o.next;o!=null;){let x=o;r+=p.x*(x.y-a.y);let y=x.y*p.x-x.x*p.y;l.localCOMx+=(p.x+x.x)*y,l.localCOMy+=(p.y+x.y)*y,a=p,p=x,o=o.next}o=l.lverts.next;let c=o;r+=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,o=o.next;let u=o;r+=p.x*(u.y-a.y);let _=u.y*p.x-u.x*p.y;l.localCOMx+=(p.x+u.x)*_,l.localCOMy+=(p.y+u.y)*_,r=1/(3*r);let m=r;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,r=t.gverts.next;for(;r!=null;){let o=r,a=l;l=l.next,o.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),o.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),r=r.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next}}}else{let t=this.dynab,n=e.node;if(!n.synced){if(!t.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let i=e.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=!1,i.zip_localCOM){if(i.zip_localCOM=!1,i.type==1){let 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 v=f.y*u.x-f.x*u.y;a.localCOMx+=(u.x+f.x)*v,a.localCOMy+=(u.y+f.y)*v,h=u,u=f,c=c.next}c=a.lverts.next;let _=c;p+=u.x*(_.y-h.y);let m=_.y*u.x-_.x*u.y;a.localCOMx+=(u.x+_.x)*m,a.localCOMy+=(u.y+_.y)*m,h=u,u=_,c=c.next;let x=c;p+=u.x*(x.y-h.y);let y=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*y,a.localCOMy+=(u.y+x.y)*y,p=1/(3*p);let z=p;a.localCOMx*=z,a.localCOMy*=z}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let o=i.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let l=i.radius,r=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-r,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+r}else{let i=e.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let o=i.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.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 r=i.gverts.next.next;for(;r!=null;){let o=r;o.x<i.aabb.minx&&(i.aabb.minx=o.x),o.x>i.aabb.maxx&&(i.aabb.maxx=o.x),o.y<i.aabb.miny&&(i.aabb.miny=o.y),o.y>i.aabb.maxy&&(i.aabb.maxy=o.y),r=r.next}}let s;if(n.dyn==(e.body.type==1?!1:!e.body.component.sleeping)){let i=n.aabb,l=e.aabb;s=!(l.minx>=i.minx&&l.miny>=i.miny&&l.maxx<=i.maxx&&l.maxy<=i.maxy)}else s=!0;s&&(n.synced=!0,n.snext=t.syncs,t.syncs=n)}}}broadphase(e,t){}clear(){}shapesUnderPoint(e,t,n,s){return null}bodiesUnderPoint(e,t,n,s){return null}updateAABBShape(e){let t=ss._zpp,n=ss._nape;if(this.aabbShape==null){t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new n.phys.BodyType,t.util.ZPP_Flags.internal=!1);let r=new n.phys.Body(t.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,o=this.aabbShape=new n.shape.Polygon(n.shape.Polygon.rect(e.minx,e.miny,e.maxx-e.minx,e.maxy-e.miny));r.zpp_inner.reverse_flag?r.push(o):r.unshift(o)}else{let l=this.aabbShape.zpp_inner.aabb,r=(e.maxx-e.minx)/(l.maxx-l.minx),o=(e.maxy-e.miny)/(l.maxy-l.miny);this.matrix==null&&(this.matrix=new n.geom.Mat23);let a=this.matrix;if(r!==r)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=r;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 _=h.zpp_inner.c;if(_!==_)throw new Error("Error: Mat23::b cannot be NaN");c.zpp_inner.b=_;let m=c.zpp_inner;m._invalidate!=null&&m._invalidate();let x=this.matrix;if(o!==o)throw new Error("Error: Mat23::d cannot be NaN");x.zpp_inner.d=o;let y=x.zpp_inner;y._invalidate!=null&&y._invalidate();let z=this.matrix,f=e.minx-r*l.minx;if(f!==f)throw new Error("Error: Mat23::tx cannot be NaN");z.zpp_inner.tx=f;let v=z.zpp_inner;v._invalidate!=null&&v._invalidate();let E=this.matrix,d=e.miny-o*l.miny;if(d!==d)throw new Error("Error: Mat23::ty cannot be NaN");E.zpp_inner.ty=d;let b=E.zpp_inner;b._invalidate!=null&&b._invalidate(),this.aabbShape.transform(this.matrix)}let s=this.aabbShape.zpp_inner;if(s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let l=s.circle;if(l.zip_worldCOM&&l.body!=null){if(l.zip_worldCOM=!1,l.zip_localCOM){if(l.zip_localCOM=!1,l.type==1){let p=l.polygon;if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(p.lverts.next.next==null)p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;else if(p.lverts.next.next.next==null){p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;let c=1;p.localCOMx+=p.lverts.next.next.x*c,p.localCOMy+=p.lverts.next.next.y*c;let h=.5;p.localCOMx*=h,p.localCOMy*=h}else{p.localCOMx=0,p.localCOMy=0;let c=0,h=p.lverts.next,u=h;h=h.next;let _=h;for(h=h.next;h!=null;){let v=h;c+=_.x*(v.y-u.y);let E=v.y*_.x-v.x*_.y;p.localCOMx+=(_.x+v.x)*E,p.localCOMy+=(_.y+v.y)*E,u=_,_=v,h=h.next}h=p.lverts.next;let m=h;c+=_.x*(m.y-u.y);let x=m.y*_.x-m.x*_.y;p.localCOMx+=(_.x+m.x)*x,p.localCOMy+=(_.y+m.y)*x,u=_,_=m,h=h.next;let y=h;c+=_.x*(y.y-u.y);let z=y.y*_.x-y.x*_.y;p.localCOMx+=(_.x+y.x)*z,p.localCOMy+=(_.y+y.y)*z,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 r=l.radius,o=l.radius;l.aabb.minx=l.worldCOMx-r,l.aabb.miny=l.worldCOMy-o,l.aabb.maxx=l.worldCOMx+r,l.aabb.maxy=l.worldCOMy+o}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 r=l.gverts.next;l.aabb.minx=r.x,l.aabb.miny=r.y,l.aabb.maxx=r.x,l.aabb.maxy=r.y;let o=l.gverts.next.next;for(;o!=null;){let a=o;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),o=o.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,_=i.gverts.next;for(;_!=null;){let m=_,x=u;u=u.next,m.x=i.body.posx+(i.body.axisy*x.x-i.body.axisx*x.y),m.y=i.body.posy+(x.x*i.body.axisx+x.y*i.body.axisy),_=_.next}}let r=i.edges.head,o=i.gverts.next,a=o;for(o=o.next;o!=null;){let h=o,u=r.elt;r=r.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,o=o.next}let p=i.gverts.next,c=r.elt;r=r.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=ss._zpp,i=ss._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 o=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 _;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 x=c.zpp_inner;x._validate!=null&&x._validate(),_=c.zpp_inner.y==p}else _=!1;if(!_){c.zpp_inner.x=a,c.zpp_inner.y=p;let x=c.zpp_inner;x._invalidate!=null&&x._invalidate(x)}}c.zpp_inner.weak=!1;let h=this.circShape=new i.shape.Circle(n,c);o.zpp_inner.reverse_flag?o.push(h):o.unshift(h)}else{let r=this.circShape.zpp_inner.circle,o=n/r.radius;this.matrix==null&&(this.matrix=new i.geom.Mat23);let a=this.matrix,p=this.matrix;if(o!==o)throw new Error("Error: Mat23::d cannot be NaN");p.zpp_inner.d=o;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 _=this.matrix,m=this.matrix;m.zpp_inner.c=0;let x=m.zpp_inner;x._invalidate!=null&&x._invalidate();let y=m.zpp_inner.c;if(y!==y)throw new Error("Error: Mat23::b cannot be NaN");_.zpp_inner.b=y;let z=_.zpp_inner;z._invalidate!=null&&z._invalidate();let f=this.matrix,v=e-o*r.localCOMx;if(v!==v)throw new Error("Error: Mat23::tx cannot be NaN");f.zpp_inner.tx=v;let E=f.zpp_inner;E._invalidate!=null&&E._invalidate();let d=this.matrix,b=t-o*r.localCOMy;if(b!==b)throw new Error("Error: Mat23::ty cannot be NaN");d.zpp_inner.ty=b;let C=d.zpp_inner;C._invalidate!=null&&C._invalidate(),this.circShape.transform(this.matrix)}let l=this.circShape.zpp_inner;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let r=l.circle;if(r.zip_worldCOM&&r.body!=null){if(r.zip_worldCOM=!1,r.zip_localCOM){if(r.zip_localCOM=!1,r.type==1){let c=r.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let h=1;c.localCOMx+=c.lverts.next.next.x*h,c.localCOMy+=c.lverts.next.next.y*h;let u=.5;c.localCOMx*=u,c.localCOMy*=u}else{c.localCOMx=0,c.localCOMy=0;let h=0,u=c.lverts.next,_=u;u=u.next;let m=u;for(u=u.next;u!=null;){let E=u;h+=m.x*(E.y-_.y);let d=E.y*m.x-E.x*m.y;c.localCOMx+=(m.x+E.x)*d,c.localCOMy+=(m.y+E.y)*d,_=m,m=E,u=u.next}u=c.lverts.next;let x=u;h+=m.x*(x.y-_.y);let y=x.y*m.x-x.x*m.y;c.localCOMx+=(m.x+x.x)*y,c.localCOMy+=(m.y+x.y)*y,_=m,m=x,u=u.next;let z=u;h+=m.x*(z.y-_.y);let f=z.y*m.x-z.x*m.y;c.localCOMx+=(m.x+z.x)*f,c.localCOMy+=(m.y+z.y)*f,h=1/(3*h);let v=h;c.localCOMx*=v,c.localCOMy*=v}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let p=r.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),r.worldCOMx=r.body.posx+(r.body.axisy*r.localCOMx-r.body.axisx*r.localCOMy),r.worldCOMy=r.body.posy+(r.localCOMx*r.body.axisx+r.localCOMy*r.body.axisy)}let o=r.radius,a=r.radius;r.aabb.minx=r.worldCOMx-o,r.aabb.miny=r.worldCOMy-a,r.aabb.maxx=r.worldCOMx+o,r.aabb.maxy=r.worldCOMy+a}else{let r=l.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let p=r.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=r.lverts.next,h=r.gverts.next;for(;h!=null;){let u=h,_=c;c=c.next,u.x=r.body.posx+(r.body.axisy*_.x-r.body.axisx*_.y),u.y=r.body.posy+(_.x*r.body.axisx+_.y*r.body.axisy),h=h.next}}if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let o=r.gverts.next;r.aabb.minx=o.x,r.aabb.miny=o.y,r.aabb.maxx=o.x,r.aabb.maxy=o.y;let a=r.gverts.next.next;for(;a!=null;){let p=a;p.x<r.aabb.minx&&(r.aabb.minx=p.x),p.x>r.aabb.maxx&&(r.aabb.maxx=p.x),p.y<r.aabb.miny&&(r.aabb.miny=p.y),p.y>r.aabb.maxy&&(r.aabb.maxy=p.y),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 r=t.gverts.next,o=s.elt;s=s.next,o.gp0=l,o.gp1=r,o.gnormx=t.body.axisy*o.lnormx-t.body.axisx*o.lnormy,o.gnormy=o.lnormx*t.body.axisx+o.lnormy*t.body.axisy,o.gprojection=t.body.posx*o.gnormx+t.body.posy*o.gnormy+o.lprojection,o.wrap_gnorm!=null&&(o.wrap_gnorm.zpp_inner.x=o.gnormx,o.wrap_gnorm.zpp_inner.y=o.gnormy),o.tp0=o.gp0.y*o.gnormx-o.gp0.x*o.gnormy,o.tp1=o.gp1.y*o.gnormx-o.gp1.x*o.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let r=1;l.localCOMx+=l.lverts.next.next.x*r,l.localCOMy+=l.lverts.next.next.y*r;let o=.5;l.localCOMx*=o,l.localCOMy*=o}else{l.localCOMx=0,l.localCOMy=0;let r=0,o=l.lverts.next,a=o;o=o.next;let p=o;for(o=o.next;o!=null;){let x=o;r+=p.x*(x.y-a.y);let y=x.y*p.x-x.x*p.y;l.localCOMx+=(p.x+x.x)*y,l.localCOMy+=(p.y+x.y)*y,a=p,p=x,o=o.next}o=l.lverts.next;let c=o;r+=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,o=o.next;let u=o;r+=p.x*(u.y-a.y);let _=u.y*p.x-u.x*p.y;l.localCOMx+=(p.x+u.x)*_,l.localCOMy+=(p.y+u.y)*_,r=1/(3*r);let m=r;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,r=t.gverts.next;for(;r!=null;){let o=r,a=l;l=l.next,o.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),o.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),r=r.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next}}if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let s=1;n.localCOMx+=n.lverts.next.next.x*s,n.localCOMy+=n.lverts.next.next.y*s;let i=.5;n.localCOMx*=i,n.localCOMy*=i}else{n.localCOMx=0,n.localCOMy=0;let s=0,i=n.lverts.next,l=i;i=i.next;let r=i;for(i=i.next;i!=null;){let u=i;s+=r.x*(u.y-l.y);let _=u.y*r.x-u.x*r.y;n.localCOMx+=(r.x+u.x)*_,n.localCOMy+=(r.y+u.y)*_,l=r,r=u,i=i.next}i=n.lverts.next;let o=i;s+=r.x*(o.y-l.y);let a=o.y*r.x-o.x*r.y;n.localCOMx+=(r.x+o.x)*a,n.localCOMy+=(r.y+o.y)*a,l=r,r=o,i=i.next;let p=i;s+=r.x*(p.y-l.y);let c=p.y*r.x-p.x*r.y;n.localCOMx+=(r.x+p.x)*c,n.localCOMy+=(r.y+p.y)*c,s=1/(3*s);let h=s;n.localCOMx*=h,n.localCOMy*=h}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}shapesInShape(e,t,n,s){return null}bodiesInShape(e,t,n,s){return null}rayCast(e,t,n){return null}rayMultiCast(e,t,n,s){return null}};ss._zpp=null,ss._nape=null;var ni=ss;var Be=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(){fe.zpp_pool==null?this.aabb=new fe:(this.aabb=fe.zpp_pool,fe.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=fe.zpp_pool,fe.zpp_pool=e,this.child1=this.child2=this.parent=null,this.next=null,this.snext=null,this.mnext=null}isLeaf(){return this.child1==null}};Be.zpp_pool=null;var ct=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}};ct.zpp_pool=null;var Dt=class Dt{constructor(){this.root=null}static _initStatics(){Dt.tmpaabb=new fe}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=fe.zpp_pool,fe.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Be.zpp_pool,Be.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=Dt.tmpaabb,_=n.aabb;u.minx=_.minx<t.minx?_.minx:t.minx,u.miny=_.miny<t.miny?_.miny:t.miny,u.maxx=_.maxx>t.maxx?_.maxx:t.maxx,u.maxy=_.maxy>t.maxy?_.maxy:t.maxy;let m=Dt.tmpaabb,x=(m.maxx-m.minx+(m.maxy-m.miny))*2,y=2*x,z=2*(x-h),f=Dt.tmpaabb,v=a.aabb;f.minx=t.minx<v.minx?t.minx:v.minx,f.miny=t.miny<v.miny?t.miny:v.miny,f.maxx=t.maxx>v.maxx?t.maxx:v.maxx,f.maxy=t.maxy>v.maxy?t.maxy:v.maxy;let E;if(a.child1==null){let P=Dt.tmpaabb;E=(P.maxx-P.minx+(P.maxy-P.miny))*2+z}else{let P=a.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,O=Dt.tmpaabb;E=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+z}let d=Dt.tmpaabb,b=p.aabb;d.minx=t.minx<b.minx?t.minx:b.minx,d.miny=t.miny<b.miny?t.miny:b.miny,d.maxx=t.maxx>b.maxx?t.maxx:b.maxx,d.maxy=t.maxy>b.maxy?t.maxy:b.maxy;let C;if(p.child1==null){let P=Dt.tmpaabb;C=(P.maxx-P.minx+(P.maxy-P.miny))*2+z}else{let P=p.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,O=Dt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+z}if(y<E&&y<C)break;n=E<C?a:p}let s=n,i=s.parent,l;Be.zpp_pool==null?l=new Be:(l=Be.zpp_pool,Be.zpp_pool=l.next,l.next=null),fe.zpp_pool==null?l.aabb=new fe:(l.aabb=fe.zpp_pool,fe.zpp_pool=l.aabb.next,l.aabb.next=null),l.moved=!1,l.synced=!1,l.first_sync=!1,l.parent=i;let r=l.aabb,o=s.aabb;for(r.minx=t.minx<o.minx?t.minx:o.minx,r.miny=t.miny<o.miny?t.miny:o.miny,r.maxx=t.maxx>o.maxx?t.maxx:o.maxx,r.maxy=t.maxy>o.maxy?t.maxy:o.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 x=n.child1,y=n.child2,z=y.height-x.height;if(z>1){let f=y.child1,v=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>v.height){y.child2=f,n.child2=v,v.parent=n;let E=n.aabb,d=x.aabb,b=v.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=y.aabb,P=n.aabb,g=f.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=x.height,N=v.height;n.height=1+(O>N?O:N);let M=n.height,k=f.height;y.height=1+(M>k?M:k)}else{y.child2=v,n.child2=f,f.parent=n;let E=n.aabb,d=x.aabb,b=f.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=y.aabb,P=n.aabb,g=v.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=x.height,N=f.height;n.height=1+(O>N?O:N);let M=n.height,k=v.height;y.height=1+(M>k?M:k)}n=y}else if(z<-1){let f=x.child1,v=x.child2;if(x.child1=n,x.parent=n.parent,n.parent=x,x.parent!=null?x.parent.child1==n?x.parent.child1=x:x.parent.child2=x:this.root=x,f.height>v.height){x.child2=f,n.child1=v,v.parent=n;let E=n.aabb,d=y.aabb,b=v.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=x.aabb,P=n.aabb,g=f.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=y.height,N=v.height;n.height=1+(O>N?O:N);let M=n.height,k=f.height;x.height=1+(M>k?M:k)}else{x.child2=v,n.child1=f,f.parent=n;let E=n.aabb,d=y.aabb,b=f.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=x.aabb,P=n.aabb,g=v.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=y.height,N=f.height;n.height=1+(O>N?O:N);let M=n.height,k=v.height;x.height=1+(M>k?M:k)}n=x}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,_=a.aabb,m=p.aabb;u.minx=_.minx<m.minx?_.minx:m.minx,u.miny=_.miny<m.miny?_.miny:m.miny,u.maxx=_.maxx>m.maxx?_.maxx:m.maxx,u.maxy=_.maxy>m.maxy?_.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=Dt.tmpaabb,_=n.aabb;u.minx=_.minx<t.minx?_.minx:t.minx,u.miny=_.miny<t.miny?_.miny:t.miny,u.maxx=_.maxx>t.maxx?_.maxx:t.maxx,u.maxy=_.maxy>t.maxy?_.maxy:t.maxy;let m=Dt.tmpaabb,x=(m.maxx-m.minx+(m.maxy-m.miny))*2,y=2*x,z=2*(x-h),f=Dt.tmpaabb,v=a.aabb;f.minx=t.minx<v.minx?t.minx:v.minx,f.miny=t.miny<v.miny?t.miny:v.miny,f.maxx=t.maxx>v.maxx?t.maxx:v.maxx,f.maxy=t.maxy>v.maxy?t.maxy:v.maxy;let E;if(a.child1==null){let P=Dt.tmpaabb;E=(P.maxx-P.minx+(P.maxy-P.miny))*2+z}else{let P=a.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,O=Dt.tmpaabb;E=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+z}let d=Dt.tmpaabb,b=p.aabb;d.minx=t.minx<b.minx?t.minx:b.minx,d.miny=t.miny<b.miny?t.miny:b.miny,d.maxx=t.maxx>b.maxx?t.maxx:b.maxx,d.maxy=t.maxy>b.maxy?t.maxy:b.maxy;let C;if(p.child1==null){let P=Dt.tmpaabb;C=(P.maxx-P.minx+(P.maxy-P.miny))*2+z}else{let P=p.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,O=Dt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-g+z}if(y<E&&y<C)break;n=E<C?a:p}let s=n,i=s.parent,l;Be.zpp_pool==null?l=new Be:(l=Be.zpp_pool,Be.zpp_pool=l.next,l.next=null),fe.zpp_pool==null?l.aabb=new fe:(l.aabb=fe.zpp_pool,fe.zpp_pool=l.aabb.next,l.aabb.next=null),l.moved=!1,l.synced=!1,l.first_sync=!1,l.parent=i;let r=l.aabb,o=s.aabb;for(r.minx=t.minx<o.minx?t.minx:o.minx,r.miny=t.miny<o.miny?t.miny:o.miny,r.maxx=t.maxx>o.maxx?t.maxx:o.maxx,r.maxy=t.maxy>o.maxy?t.maxy:o.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 x=n.child1,y=n.child2,z=y.height-x.height;if(z>1){let f=y.child1,v=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>v.height){y.child2=f,n.child2=v,v.parent=n;let E=n.aabb,d=x.aabb,b=v.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=y.aabb,P=n.aabb,g=f.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=x.height,N=v.height;n.height=1+(O>N?O:N);let M=n.height,k=f.height;y.height=1+(M>k?M:k)}else{y.child2=v,n.child2=f,f.parent=n;let E=n.aabb,d=x.aabb,b=f.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=y.aabb,P=n.aabb,g=v.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=x.height,N=f.height;n.height=1+(O>N?O:N);let M=n.height,k=v.height;y.height=1+(M>k?M:k)}n=y}else if(z<-1){let f=x.child1,v=x.child2;if(x.child1=n,x.parent=n.parent,n.parent=x,x.parent!=null?x.parent.child1==n?x.parent.child1=x:x.parent.child2=x:this.root=x,f.height>v.height){x.child2=f,n.child1=v,v.parent=n;let E=n.aabb,d=y.aabb,b=v.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=x.aabb,P=n.aabb,g=f.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=y.height,N=v.height;n.height=1+(O>N?O:N);let M=n.height,k=f.height;x.height=1+(M>k?M:k)}else{x.child2=v,n.child1=f,f.parent=n;let E=n.aabb,d=y.aabb,b=f.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=x.aabb,P=n.aabb,g=v.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=y.height,N=f.height;n.height=1+(O>N?O:N);let M=n.height,k=v.height;x.height=1+(M>k?M:k)}n=x}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,_=a.aabb,m=p.aabb;u.minx=_.minx<m.minx?_.minx:m.minx,u.miny=_.miny<m.miny?_.miny:m.miny,u.maxx=_.maxx>m.maxx?_.maxx:m.maxx,u.maxy=_.maxy>m.maxy?_.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=fe.zpp_pool,fe.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Be.zpp_pool,Be.zpp_pool=i;let r=n;for(;r!=null;){if(r.child1==null||r.height<2)r=r;else{let x=r.child1,y=r.child2,z=y.height-x.height;if(z>1){let f=y.child1,v=y.child2;if(y.child1=r,y.parent=r.parent,r.parent=y,y.parent!=null?y.parent.child1==r?y.parent.child1=y:y.parent.child2=y:this.root=y,f.height>v.height){y.child2=f,r.child2=v,v.parent=r;let E=r.aabb,d=x.aabb,b=v.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=y.aabb,P=r.aabb,g=f.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=x.height,N=v.height;r.height=1+(O>N?O:N);let M=r.height,k=f.height;y.height=1+(M>k?M:k)}else{y.child2=v,r.child2=f,f.parent=r;let E=r.aabb,d=x.aabb,b=f.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=y.aabb,P=r.aabb,g=v.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=x.height,N=f.height;r.height=1+(O>N?O:N);let M=r.height,k=v.height;y.height=1+(M>k?M:k)}r=y}else if(z<-1){let f=x.child1,v=x.child2;if(x.child1=r,x.parent=r.parent,r.parent=x,x.parent!=null?x.parent.child1==r?x.parent.child1=x:x.parent.child2=x:this.root=x,f.height>v.height){x.child2=f,r.child1=v,v.parent=r;let E=r.aabb,d=y.aabb,b=v.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=x.aabb,P=r.aabb,g=f.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=y.height,N=v.height;r.height=1+(O>N?O:N);let M=r.height,k=f.height;x.height=1+(M>k?M:k)}else{x.child2=v,r.child1=f,f.parent=r;let E=r.aabb,d=y.aabb,b=f.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=x.aabb,P=r.aabb,g=v.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=y.height,N=f.height;r.height=1+(O>N?O:N);let M=r.height,k=v.height;x.height=1+(M>k?M:k)}r=x}else r=r}let o=r,a=o.child1,p=o.child2,c=o.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 _=a.height,m=p.height;o.height=1+(_>m?_:m),r=o.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=fe.zpp_pool,fe.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Be.zpp_pool,Be.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=fe.zpp_pool,fe.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Be.zpp_pool,Be.zpp_pool=i;let r=n;for(;r!=null;){if(r.child1==null||r.height<2)r=r;else{let x=r.child1,y=r.child2,z=y.height-x.height;if(z>1){let f=y.child1,v=y.child2;if(y.child1=r,y.parent=r.parent,r.parent=y,y.parent!=null?y.parent.child1==r?y.parent.child1=y:y.parent.child2=y:this.root=y,f.height>v.height){y.child2=f,r.child2=v,v.parent=r;let E=r.aabb,d=x.aabb,b=v.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=y.aabb,P=r.aabb,g=f.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=x.height,N=v.height;r.height=1+(O>N?O:N);let M=r.height,k=f.height;y.height=1+(M>k?M:k)}else{y.child2=v,r.child2=f,f.parent=r;let E=r.aabb,d=x.aabb,b=f.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=y.aabb,P=r.aabb,g=v.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=x.height,N=f.height;r.height=1+(O>N?O:N);let M=r.height,k=v.height;y.height=1+(M>k?M:k)}r=y}else if(z<-1){let f=x.child1,v=x.child2;if(x.child1=r,x.parent=r.parent,r.parent=x,x.parent!=null?x.parent.child1==r?x.parent.child1=x:x.parent.child2=x:this.root=x,f.height>v.height){x.child2=f,r.child1=v,v.parent=r;let E=r.aabb,d=y.aabb,b=v.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=x.aabb,P=r.aabb,g=f.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=y.height,N=v.height;r.height=1+(O>N?O:N);let M=r.height,k=f.height;x.height=1+(M>k?M:k)}else{x.child2=v,r.child1=f,f.parent=r;let E=r.aabb,d=y.aabb,b=f.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let C=x.aabb,P=r.aabb,g=v.aabb;C.minx=P.minx<g.minx?P.minx:g.minx,C.miny=P.miny<g.miny?P.miny:g.miny,C.maxx=P.maxx>g.maxx?P.maxx:g.maxx,C.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let O=y.height,N=f.height;r.height=1+(O>N?O:N);let M=r.height,k=v.height;x.height=1+(M>k?M:k)}r=x}else r=r}let o=r,a=o.child1,p=o.child2,c=o.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 _=a.height,m=p.height;o.height=1+(_>m?_:m),r=o.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=fe.zpp_pool,fe.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Be.zpp_pool,Be.zpp_pool=i}}}balance(e){if(e.child1==null||e.height<2)return e;{let t=e.child1,n=e.child2,s=n.height-t.height;if(s>1){let i=n.child1,l=n.child2;if(n.child1=e,n.parent=e.parent,e.parent=n,n.parent!=null?n.parent.child1==e?n.parent.child1=n:n.parent.child2=n:this.root=n,i.height>l.height){n.child2=i,e.child2=l,l.parent=e;let r=e.aabb,o=t.aabb,a=l.aabb;r.minx=o.minx<a.minx?o.minx:a.minx,r.miny=o.miny<a.miny?o.miny:a.miny,r.maxx=o.maxx>a.maxx?o.maxx:a.maxx,r.maxy=o.maxy>a.maxy?o.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,_=l.height;e.height=1+(u>_?u:_);let m=e.height,x=i.height;n.height=1+(m>x?m:x)}else{n.child2=l,e.child2=i,i.parent=e;let r=e.aabb,o=t.aabb,a=i.aabb;r.minx=o.minx<a.minx?o.minx:a.minx,r.miny=o.miny<a.miny?o.miny:a.miny,r.maxx=o.maxx>a.maxx?o.maxx:a.maxx,r.maxy=o.maxy>a.maxy?o.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,_=i.height;e.height=1+(u>_?u:_);let m=e.height,x=l.height;n.height=1+(m>x?m:x)}return n}else if(s<-1){let i=t.child1,l=t.child2;if(t.child1=e,t.parent=e.parent,e.parent=t,t.parent!=null?t.parent.child1==e?t.parent.child1=t:t.parent.child2=t:this.root=t,i.height>l.height){t.child2=i,e.child1=l,l.parent=e;let r=e.aabb,o=n.aabb,a=l.aabb;r.minx=o.minx<a.minx?o.minx:a.minx,r.miny=o.miny<a.miny?o.miny:a.miny,r.maxx=o.maxx>a.maxx?o.maxx:a.maxx,r.maxy=o.maxy>a.maxy?o.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,_=l.height;e.height=1+(u>_?u:_);let m=e.height,x=i.height;t.height=1+(m>x?m:x)}else{t.child2=l,e.child1=i,i.parent=e;let r=e.aabb,o=n.aabb,a=i.aabb;r.minx=o.minx<a.minx?o.minx:a.minx,r.miny=o.miny<a.miny?o.miny:a.miny,r.maxx=o.maxx>a.maxx?o.maxx:a.maxx,r.maxy=o.maxy>a.maxy?o.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,_=i.height;e.height=1+(u>_?u:_);let m=e.height,x=l.height;t.height=1+(m>x?m:x)}return t}else return e}}};Dt.tmpaabb=null;var lt=Dt;var ve=class ve extends ni{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 lt,this.dtree=new lt}_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;Be.zpp_pool==null?n=new Be:(n=Be.zpp_pool,Be.zpp_pool=n.next,n.next=null),fe.zpp_pool==null?n.aabb=new fe:(n.aabb=fe.zpp_pool,fe.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,r=this.syncs;for(;r!=null&&r!=n;)l=r,r=r.snext;l==null?this.syncs=r.snext:l.snext=r.snext,r.snext=null,n.synced=!1}if(n.moved){let l=null,r=this.moves;for(;r!=null&&r!=n;)l=r,r=r.mnext;l==null?this.moves=r.mnext:l.mnext=r.mnext,r.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=ct.zpp_pool,ct.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=fe.zpp_pool,fe.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Be.zpp_pool,Be.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 v=f.y*u.x-f.x*u.y;a.localCOMx+=(u.x+f.x)*v,a.localCOMy+=(u.y+f.y)*v,h=u,u=f,c=c.next}c=a.lverts.next;let _=c;p+=u.x*(_.y-h.y);let m=_.y*u.x-_.x*u.y;a.localCOMx+=(u.x+_.x)*m,a.localCOMy+=(u.y+_.y)*m,h=u,u=_,c=c.next;let x=c;p+=u.x*(x.y-h.y);let y=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*y,a.localCOMy+=(u.y+x.y)*y,p=1/(3*p);let z=p;a.localCOMx*=z,a.localCOMy*=z}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let o=i.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let l=i.radius,r=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-r,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+r}else{let i=t.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let o=i.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.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 r=i.gverts.next.next;for(;r!=null;){let o=r;o.x<i.aabb.minx&&(i.aabb.minx=o.x),o.x>i.aabb.maxx&&(i.aabb.maxx=o.x),o.y<i.aabb.miny&&(i.aabb.miny=o.y),o.y>i.aabb.maxy&&(i.aabb.maxy=o.y),r=r.next}}let s;if(n.dyn==(t.body.type==1?!1:!t.body.component.sleeping)){let i=n.aabb,l=t.aabb;s=!(l.minx>=i.minx&&l.miny>=i.miny&&l.maxx<=i.maxx&&l.maxy<=i.maxy)}else s=!0;s&&(n.synced=!0,n.snext=this.syncs,this.syncs=n)}}sync_broadphase(){if(this.space.validation(),this.syncs!=null)if(this.moves==null){let t=this.syncs;for(;t!=null;){let s=t.shape;if(t.first_sync)t.first_sync=!1;else{let o=t.dyn?this.dtree:this.stree;if(t==o.root)o.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=fe.zpp_pool,fe.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Be.zpp_pool,Be.zpp_pool=h;let _=p;for(;_!=null;){if(_.child1==null||_.height<2)_=_;else{let d=_.child1,b=_.child2,C=b.height-d.height;if(C>1){let P=b.child1,g=b.child2;if(b.child1=_,b.parent=_.parent,_.parent=b,b.parent!=null?b.parent.child1==_?b.parent.child1=b:b.parent.child2=b:o.root=b,P.height>g.height){b.child2=P,_.child2=g,g.parent=_;let O=_.aabb,N=d.aabb,M=g.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=b.aabb,Z=_.aabb,A=P.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=d.height,R=g.height;_.height=1+(S>R?S:R);let j=_.height,q=P.height;b.height=1+(j>q?j:q)}else{b.child2=g,_.child2=P,P.parent=_;let O=_.aabb,N=d.aabb,M=P.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=b.aabb,Z=_.aabb,A=g.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=d.height,R=P.height;_.height=1+(S>R?S:R);let j=_.height,q=g.height;b.height=1+(j>q?j:q)}_=b}else if(C<-1){let P=d.child1,g=d.child2;if(d.child1=_,d.parent=_.parent,_.parent=d,d.parent!=null?d.parent.child1==_?d.parent.child1=d:d.parent.child2=d:o.root=d,P.height>g.height){d.child2=P,_.child1=g,g.parent=_;let O=_.aabb,N=b.aabb,M=g.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=d.aabb,Z=_.aabb,A=P.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=b.height,R=g.height;_.height=1+(S>R?S:R);let j=_.height,q=P.height;d.height=1+(j>q?j:q)}else{d.child2=g,_.child1=P,P.parent=_;let O=_.aabb,N=b.aabb,M=P.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=d.aabb,Z=_.aabb,A=g.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=b.height,R=P.height;_.height=1+(S>R?S:R);let j=_.height,q=g.height;d.height=1+(j>q?j:q)}_=d}else _=_}let m=_.child1,x=_.child2,y=_.aabb,z=m.aabb,f=x.aabb;y.minx=z.minx<f.minx?z.minx:f.minx,y.miny=z.miny<f.miny?z.miny:f.miny,y.maxx=z.maxx>f.maxx?z.maxx:f.maxx,y.maxy=z.maxy>f.maxy?z.maxy:f.maxy;let v=m.height,E=x.height;_.height=1+(v>E?v:E),_=_.parent}}else{o.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=fe.zpp_pool,fe.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Be.zpp_pool,Be.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 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 h=o.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 _=.5;h.localCOMx*=_,h.localCOMy*=_}else{h.localCOMx=0,h.localCOMy=0;let u=0,_=h.lverts.next,m=_;_=_.next;let x=_;for(_=_.next;_!=null;){let d=_;u+=x.x*(d.y-m.y);let b=d.y*x.x-d.x*x.y;h.localCOMx+=(x.x+d.x)*b,h.localCOMy+=(x.y+d.y)*b,m=x,x=d,_=_.next}_=h.lverts.next;let y=_;u+=x.x*(y.y-m.y);let z=y.y*x.x-y.x*x.y;h.localCOMx+=(x.x+y.x)*z,h.localCOMy+=(x.y+y.y)*z,m=x,x=y,_=_.next;let f=_;u+=x.x*(f.y-m.y);let v=f.y*x.x-f.x*x.y;h.localCOMx+=(x.x+f.x)*v,h.localCOMy+=(x.y+f.y)*v,u=1/(3*u);let E=u;h.localCOMx*=E,h.localCOMy*=E}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let c=o.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.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 a=o.radius,p=o.radius;o.aabb.minx=o.worldCOMx-a,o.aabb.miny=o.worldCOMy-p,o.aabb.maxx=o.worldCOMx+a,o.aabb.maxy=o.worldCOMy+p}else{let o=s.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let c=o.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=o.lverts.next,u=o.gverts.next;for(;u!=null;){let _=u,m=h;h=h.next,_.x=o.body.posx+(o.body.axisy*m.x-o.body.axisx*m.y),_.y=o.body.posy+(m.x*o.body.axisx+m.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let a=o.gverts.next;o.aabb.minx=a.x,o.aabb.miny=a.y,o.aabb.maxx=a.x,o.aabb.maxy=a.y;let p=o.gverts.next.next;for(;p!=null;){let c=p;c.x<o.aabb.minx&&(o.aabb.minx=c.x),c.x>o.aabb.maxx&&(o.aabb.maxx=c.x),c.y<o.aabb.miny&&(o.aabb.miny=c.y),c.y>o.aabb.maxy&&(o.aabb.maxy=c.y),p=p.next}}let l=s.aabb;i.minx=l.minx-3,i.miny=l.miny-3,i.maxx=l.maxx+3,i.maxy=l.maxy+3;let r=(t.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(r.root==null)r.root=t,r.root.parent=null;else{let o=t.aabb,a=r.root;for(;a.child1!=null;){let m=a.child1,x=a.child2,y=a.aabb,z=(y.maxx-y.minx+(y.maxy-y.miny))*2,f=lt.tmpaabb,v=a.aabb;f.minx=v.minx<o.minx?v.minx:o.minx,f.miny=v.miny<o.miny?v.miny:o.miny,f.maxx=v.maxx>o.maxx?v.maxx:o.maxx,f.maxy=v.maxy>o.maxy?v.maxy:o.maxy;let E=lt.tmpaabb,d=(E.maxx-E.minx+(E.maxy-E.miny))*2,b=2*d,C=2*(d-z),P=lt.tmpaabb,g=m.aabb;P.minx=o.minx<g.minx?o.minx:g.minx,P.miny=o.miny<g.miny?o.miny:g.miny,P.maxx=o.maxx>g.maxx?o.maxx:g.maxx,P.maxy=o.maxy>g.maxy?o.maxy:g.maxy;let O;if(m.child1==null){let Z=lt.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=lt.tmpaabb;O=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}let N=lt.tmpaabb,M=x.aabb;N.minx=o.minx<M.minx?o.minx:M.minx,N.miny=o.miny<M.miny?o.miny:M.miny,N.maxx=o.maxx>M.maxx?o.maxx:M.maxx,N.maxy=o.maxy>M.maxy?o.maxy:M.maxy;let k;if(x.child1==null){let Z=lt.tmpaabb;k=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=x.aabb,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=lt.tmpaabb;k=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}if(b<O&&b<k)break;a=O<k?m:x}let p=a,c=p.parent,h;Be.zpp_pool==null?h=new Be:(h=Be.zpp_pool,Be.zpp_pool=h.next,h.next=null),fe.zpp_pool==null?h.aabb=new fe:(h.aabb=fe.zpp_pool,fe.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,_=p.aabb;for(u.minx=o.minx<_.minx?o.minx:_.minx,u.miny=o.miny<_.miny?o.miny:_.miny,u.maxx=o.maxx>_.maxx?o.maxx:_.maxx,u.maxy=o.maxy>_.maxy?o.maxy:_.maxy,h.height=p.height+1,c!=null?(c.child1==p?c.child1=h:c.child2=h,h.child1=p,h.child2=t,p.parent=h,t.parent=h):(h.child1=p,h.child2=t,p.parent=h,t.parent=h,r.root=h),a=t.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else{let d=a.child1,b=a.child2,C=b.height-d.height;if(C>1){let P=b.child1,g=b.child2;if(b.child1=a,b.parent=a.parent,a.parent=b,b.parent!=null?b.parent.child1==a?b.parent.child1=b:b.parent.child2=b:r.root=b,P.height>g.height){b.child2=P,a.child2=g,g.parent=a;let O=a.aabb,N=d.aabb,M=g.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=b.aabb,Z=a.aabb,A=P.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=d.height,R=g.height;a.height=1+(S>R?S:R);let j=a.height,q=P.height;b.height=1+(j>q?j:q)}else{b.child2=g,a.child2=P,P.parent=a;let O=a.aabb,N=d.aabb,M=P.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=b.aabb,Z=a.aabb,A=g.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=d.height,R=P.height;a.height=1+(S>R?S:R);let j=a.height,q=g.height;b.height=1+(j>q?j:q)}a=b}else if(C<-1){let P=d.child1,g=d.child2;if(d.child1=a,d.parent=a.parent,a.parent=d,d.parent!=null?d.parent.child1==a?d.parent.child1=d:d.parent.child2=d:r.root=d,P.height>g.height){d.child2=P,a.child1=g,g.parent=a;let O=a.aabb,N=b.aabb,M=g.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=d.aabb,Z=a.aabb,A=P.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=b.height,R=g.height;a.height=1+(S>R?S:R);let j=a.height,q=P.height;d.height=1+(j>q?j:q)}else{d.child2=g,a.child1=P,P.parent=a;let O=a.aabb,N=b.aabb,M=P.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=d.aabb,Z=a.aabb,A=g.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=b.height,R=P.height;a.height=1+(S>R?S:R);let j=a.height,q=g.height;d.height=1+(j>q?j:q)}a=d}else a=a}let m=a.child1,x=a.child2,y=m.height,z=x.height;a.height=1+(y>z?y:z);let f=a.aabb,v=m.aabb,E=x.aabb;f.minx=v.minx<E.minx?v.minx:E.minx,f.miny=v.miny<E.miny?v.miny:E.miny,f.maxx=v.maxx>E.maxx?v.maxx:E.maxx,f.maxy=v.maxy>E.maxy?v.maxy:E.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 o=n.dyn?this.dtree:this.stree;if(n==o.root)o.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=fe.zpp_pool,fe.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Be.zpp_pool,Be.zpp_pool=h;let _=p;for(;_!=null;){if(_.child1==null||_.height<2)_=_;else{let d=_.child1,b=_.child2,C=b.height-d.height;if(C>1){let P=b.child1,g=b.child2;if(b.child1=_,b.parent=_.parent,_.parent=b,b.parent!=null?b.parent.child1==_?b.parent.child1=b:b.parent.child2=b:o.root=b,P.height>g.height){b.child2=P,_.child2=g,g.parent=_;let O=_.aabb,N=d.aabb,M=g.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=b.aabb,Z=_.aabb,A=P.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=d.height,R=g.height;_.height=1+(S>R?S:R);let j=_.height,q=P.height;b.height=1+(j>q?j:q)}else{b.child2=g,_.child2=P,P.parent=_;let O=_.aabb,N=d.aabb,M=P.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=b.aabb,Z=_.aabb,A=g.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=d.height,R=P.height;_.height=1+(S>R?S:R);let j=_.height,q=g.height;b.height=1+(j>q?j:q)}_=b}else if(C<-1){let P=d.child1,g=d.child2;if(d.child1=_,d.parent=_.parent,_.parent=d,d.parent!=null?d.parent.child1==_?d.parent.child1=d:d.parent.child2=d:o.root=d,P.height>g.height){d.child2=P,_.child1=g,g.parent=_;let O=_.aabb,N=b.aabb,M=g.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=d.aabb,Z=_.aabb,A=P.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=b.height,R=g.height;_.height=1+(S>R?S:R);let j=_.height,q=P.height;d.height=1+(j>q?j:q)}else{d.child2=g,_.child1=P,P.parent=_;let O=_.aabb,N=b.aabb,M=P.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=d.aabb,Z=_.aabb,A=g.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=b.height,R=P.height;_.height=1+(S>R?S:R);let j=_.height,q=g.height;d.height=1+(j>q?j:q)}_=d}else _=_}let m=_.child1,x=_.child2,y=_.aabb,z=m.aabb,f=x.aabb;y.minx=z.minx<f.minx?z.minx:f.minx,y.miny=z.miny<f.miny?z.miny:f.miny,y.maxx=z.maxx>f.maxx?z.maxx:f.maxx,y.maxy=z.maxy>f.maxy?z.maxy:f.maxy;let v=m.height,E=x.height;_.height=1+(v>E?v:E),_=_.parent}}else{o.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=fe.zpp_pool,fe.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Be.zpp_pool,Be.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 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 h=o.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 _=.5;h.localCOMx*=_,h.localCOMy*=_}else{h.localCOMx=0,h.localCOMy=0;let u=0,_=h.lverts.next,m=_;_=_.next;let x=_;for(_=_.next;_!=null;){let d=_;u+=x.x*(d.y-m.y);let b=d.y*x.x-d.x*x.y;h.localCOMx+=(x.x+d.x)*b,h.localCOMy+=(x.y+d.y)*b,m=x,x=d,_=_.next}_=h.lverts.next;let y=_;u+=x.x*(y.y-m.y);let z=y.y*x.x-y.x*x.y;h.localCOMx+=(x.x+y.x)*z,h.localCOMy+=(x.y+y.y)*z,m=x,x=y,_=_.next;let f=_;u+=x.x*(f.y-m.y);let v=f.y*x.x-f.x*x.y;h.localCOMx+=(x.x+f.x)*v,h.localCOMy+=(x.y+f.y)*v,u=1/(3*u);let E=u;h.localCOMx*=E,h.localCOMy*=E}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let c=o.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.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 a=o.radius,p=o.radius;o.aabb.minx=o.worldCOMx-a,o.aabb.miny=o.worldCOMy-p,o.aabb.maxx=o.worldCOMx+a,o.aabb.maxy=o.worldCOMy+p}else{let o=s.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let c=o.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=o.lverts.next,u=o.gverts.next;for(;u!=null;){let _=u,m=h;h=h.next,_.x=o.body.posx+(o.body.axisy*m.x-o.body.axisx*m.y),_.y=o.body.posy+(m.x*o.body.axisx+m.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let a=o.gverts.next;o.aabb.minx=a.x,o.aabb.miny=a.y,o.aabb.maxx=a.x,o.aabb.maxy=a.y;let p=o.gverts.next.next;for(;p!=null;){let c=p;c.x<o.aabb.minx&&(o.aabb.minx=c.x),c.x>o.aabb.maxx&&(o.aabb.maxx=c.x),c.y<o.aabb.miny&&(o.aabb.miny=c.y),c.y>o.aabb.maxy&&(o.aabb.maxy=c.y),p=p.next}}let l=s.aabb;i.minx=l.minx-3,i.miny=l.miny-3,i.maxx=l.maxx+3,i.maxy=l.maxy+3;let r=(n.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(r.root==null)r.root=n,r.root.parent=null;else{let o=n.aabb,a=r.root;for(;a.child1!=null;){let m=a.child1,x=a.child2,y=a.aabb,z=(y.maxx-y.minx+(y.maxy-y.miny))*2,f=lt.tmpaabb,v=a.aabb;f.minx=v.minx<o.minx?v.minx:o.minx,f.miny=v.miny<o.miny?v.miny:o.miny,f.maxx=v.maxx>o.maxx?v.maxx:o.maxx,f.maxy=v.maxy>o.maxy?v.maxy:o.maxy;let E=lt.tmpaabb,d=(E.maxx-E.minx+(E.maxy-E.miny))*2,b=2*d,C=2*(d-z),P=lt.tmpaabb,g=m.aabb;P.minx=o.minx<g.minx?o.minx:g.minx,P.miny=o.miny<g.miny?o.miny:g.miny,P.maxx=o.maxx>g.maxx?o.maxx:g.maxx,P.maxy=o.maxy>g.maxy?o.maxy:g.maxy;let O;if(m.child1==null){let Z=lt.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=lt.tmpaabb;O=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}let N=lt.tmpaabb,M=x.aabb;N.minx=o.minx<M.minx?o.minx:M.minx,N.miny=o.miny<M.miny?o.miny:M.miny,N.maxx=o.maxx>M.maxx?o.maxx:M.maxx,N.maxy=o.maxy>M.maxy?o.maxy:M.maxy;let k;if(x.child1==null){let Z=lt.tmpaabb;k=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+C}else{let Z=x.aabb,A=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,S=lt.tmpaabb;k=(S.maxx-S.minx+(S.maxy-S.miny))*2-A+C}if(b<O&&b<k)break;a=O<k?m:x}let p=a,c=p.parent,h;Be.zpp_pool==null?h=new Be:(h=Be.zpp_pool,Be.zpp_pool=h.next,h.next=null),fe.zpp_pool==null?h.aabb=new fe:(h.aabb=fe.zpp_pool,fe.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,_=p.aabb;for(u.minx=o.minx<_.minx?o.minx:_.minx,u.miny=o.miny<_.miny?o.miny:_.miny,u.maxx=o.maxx>_.maxx?o.maxx:_.maxx,u.maxy=o.maxy>_.maxy?o.maxy:_.maxy,h.height=p.height+1,c!=null?(c.child1==p?c.child1=h:c.child2=h,h.child1=p,h.child2=n,p.parent=h,n.parent=h):(h.child1=p,h.child2=n,p.parent=h,n.parent=h,r.root=h),a=n.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else{let d=a.child1,b=a.child2,C=b.height-d.height;if(C>1){let P=b.child1,g=b.child2;if(b.child1=a,b.parent=a.parent,a.parent=b,b.parent!=null?b.parent.child1==a?b.parent.child1=b:b.parent.child2=b:r.root=b,P.height>g.height){b.child2=P,a.child2=g,g.parent=a;let O=a.aabb,N=d.aabb,M=g.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=b.aabb,Z=a.aabb,A=P.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=d.height,R=g.height;a.height=1+(S>R?S:R);let j=a.height,q=P.height;b.height=1+(j>q?j:q)}else{b.child2=g,a.child2=P,P.parent=a;let O=a.aabb,N=d.aabb,M=P.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=b.aabb,Z=a.aabb,A=g.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=d.height,R=P.height;a.height=1+(S>R?S:R);let j=a.height,q=g.height;b.height=1+(j>q?j:q)}a=b}else if(C<-1){let P=d.child1,g=d.child2;if(d.child1=a,d.parent=a.parent,a.parent=d,d.parent!=null?d.parent.child1==a?d.parent.child1=d:d.parent.child2=d:r.root=d,P.height>g.height){d.child2=P,a.child1=g,g.parent=a;let O=a.aabb,N=b.aabb,M=g.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=d.aabb,Z=a.aabb,A=P.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=b.height,R=g.height;a.height=1+(S>R?S:R);let j=a.height,q=P.height;d.height=1+(j>q?j:q)}else{d.child2=g,a.child1=P,P.parent=a;let O=a.aabb,N=b.aabb,M=P.aabb;O.minx=N.minx<M.minx?N.minx:M.minx,O.miny=N.miny<M.miny?N.miny:M.miny,O.maxx=N.maxx>M.maxx?N.maxx:M.maxx,O.maxy=N.maxy>M.maxy?N.maxy:M.maxy;let k=d.aabb,Z=a.aabb,A=g.aabb;k.minx=Z.minx<A.minx?Z.minx:A.minx,k.miny=Z.miny<A.miny?Z.miny:A.miny,k.maxx=Z.maxx>A.maxx?Z.maxx:A.maxx,k.maxy=Z.maxy>A.maxy?Z.maxy:A.maxy;let S=b.height,R=P.height;a.height=1+(S>R?S:R);let j=a.height,q=g.height;d.height=1+(j>q?j:q)}a=d}else a=a}let m=a.child1,x=a.child2,y=m.height,z=x.height;a.height=1+(y>z?y:z);let f=a.aabb,v=m.aabb,E=x.aabb;f.minx=v.minx<E.minx?v.minx:E.minx,f.miny=v.miny<E.miny?v.miny:E.miny,f.maxx=v.maxx>E.maxx?v.maxx:E.maxx,f.maxy=v.maxy>E.maxy?v.maxy:E.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 _=c;_.height=-1;let m=_.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=fe.zpp_pool,fe.zpp_pool=m,_.child1=_.child2=_.parent=null,_.next=null,_.snext=null,_.mnext=null,_.next=Be.zpp_pool,Be.zpp_pool=_;let x=h;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else{let C=x.child1,P=x.child2,g=P.height-C.height;if(g>1){let O=P.child1,N=P.child2;if(P.child1=x,P.parent=x.parent,x.parent=P,P.parent!=null?P.parent.child1==x?P.parent.child1=P:P.parent.child2=P:p.root=P,O.height>N.height){P.child2=O,x.child2=N,N.parent=x;let M=x.aabb,k=C.aabb,Z=N.aabb;M.minx=k.minx<Z.minx?k.minx:Z.minx,M.miny=k.miny<Z.miny?k.miny:Z.miny,M.maxx=k.maxx>Z.maxx?k.maxx:Z.maxx,M.maxy=k.maxy>Z.maxy?k.maxy:Z.maxy;let A=P.aabb,S=x.aabb,R=O.aabb;A.minx=S.minx<R.minx?S.minx:R.minx,A.miny=S.miny<R.miny?S.miny:R.miny,A.maxx=S.maxx>R.maxx?S.maxx:R.maxx,A.maxy=S.maxy>R.maxy?S.maxy:R.maxy;let j=C.height,q=N.height;x.height=1+(j>q?j:q);let J=x.height,G=O.height;P.height=1+(J>G?J:G)}else{P.child2=N,x.child2=O,O.parent=x;let M=x.aabb,k=C.aabb,Z=O.aabb;M.minx=k.minx<Z.minx?k.minx:Z.minx,M.miny=k.miny<Z.miny?k.miny:Z.miny,M.maxx=k.maxx>Z.maxx?k.maxx:Z.maxx,M.maxy=k.maxy>Z.maxy?k.maxy:Z.maxy;let A=P.aabb,S=x.aabb,R=N.aabb;A.minx=S.minx<R.minx?S.minx:R.minx,A.miny=S.miny<R.miny?S.miny:R.miny,A.maxx=S.maxx>R.maxx?S.maxx:R.maxx,A.maxy=S.maxy>R.maxy?S.maxy:R.maxy;let j=C.height,q=O.height;x.height=1+(j>q?j:q);let J=x.height,G=N.height;P.height=1+(J>G?J:G)}x=P}else if(g<-1){let O=C.child1,N=C.child2;if(C.child1=x,C.parent=x.parent,x.parent=C,C.parent!=null?C.parent.child1==x?C.parent.child1=C:C.parent.child2=C:p.root=C,O.height>N.height){C.child2=O,x.child1=N,N.parent=x;let M=x.aabb,k=P.aabb,Z=N.aabb;M.minx=k.minx<Z.minx?k.minx:Z.minx,M.miny=k.miny<Z.miny?k.miny:Z.miny,M.maxx=k.maxx>Z.maxx?k.maxx:Z.maxx,M.maxy=k.maxy>Z.maxy?k.maxy:Z.maxy;let A=C.aabb,S=x.aabb,R=O.aabb;A.minx=S.minx<R.minx?S.minx:R.minx,A.miny=S.miny<R.miny?S.miny:R.miny,A.maxx=S.maxx>R.maxx?S.maxx:R.maxx,A.maxy=S.maxy>R.maxy?S.maxy:R.maxy;let j=P.height,q=N.height;x.height=1+(j>q?j:q);let J=x.height,G=O.height;C.height=1+(J>G?J:G)}else{C.child2=N,x.child1=O,O.parent=x;let M=x.aabb,k=P.aabb,Z=O.aabb;M.minx=k.minx<Z.minx?k.minx:Z.minx,M.miny=k.miny<Z.miny?k.miny:Z.miny,M.maxx=k.maxx>Z.maxx?k.maxx:Z.maxx,M.maxy=k.maxy>Z.maxy?k.maxy:Z.maxy;let A=C.aabb,S=x.aabb,R=N.aabb;A.minx=S.minx<R.minx?S.minx:R.minx,A.miny=S.miny<R.miny?S.miny:R.miny,A.maxx=S.maxx>R.maxx?S.maxx:R.maxx,A.maxy=S.maxy>R.maxy?S.maxy:R.maxy;let j=P.height,q=O.height;x.height=1+(j>q?j:q);let J=x.height,G=N.height;C.height=1+(J>G?J:G)}x=C}else x=x}let y=x.child1,z=x.child2,f=x.aabb,v=y.aabb,E=z.aabb;f.minx=v.minx<E.minx?v.minx:E.minx,f.miny=v.miny<E.miny?v.miny:E.miny,f.maxx=v.maxx>E.maxx?v.maxx:E.maxx,f.maxy=v.maxy>E.maxy?v.maxy:E.maxy;let d=y.height,b=z.height;x.height=1+(d>b?d:b),x=x.parent}}else{p.root=u,u.parent=null;let _=c;_.height=-1;let m=_.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=fe.zpp_pool,fe.zpp_pool=m,_.child1=_.child2=_.parent=null,_.next=null,_.snext=null,_.mnext=null,_.next=Be.zpp_pool,Be.zpp_pool=_}}}let r=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 _=p.polygon;if(_.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(_.lverts.next.next==null)_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;else if(_.lverts.next.next.next==null){_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;let m=1;_.localCOMx+=_.lverts.next.next.x*m,_.localCOMy+=_.lverts.next.next.y*m;let x=.5;_.localCOMx*=x,_.localCOMy*=x}else{_.localCOMx=0,_.localCOMy=0;let m=0,x=_.lverts.next,y=x;x=x.next;let z=x;for(x=x.next;x!=null;){let C=x;m+=z.x*(C.y-y.y);let P=C.y*z.x-C.x*z.y;_.localCOMx+=(z.x+C.x)*P,_.localCOMy+=(z.y+C.y)*P,y=z,z=C,x=x.next}x=_.lverts.next;let f=x;m+=z.x*(f.y-y.y);let v=f.y*z.x-f.x*z.y;_.localCOMx+=(z.x+f.x)*v,_.localCOMy+=(z.y+f.y)*v,y=z,z=f,x=x.next;let E=x;m+=z.x*(E.y-y.y);let d=E.y*z.x-E.x*z.y;_.localCOMx+=(z.x+E.x)*d,_.localCOMy+=(z.y+E.y)*d,m=1/(3*m);let b=m;_.localCOMx*=b,_.localCOMy*=b}}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 _=p.lverts.next,m=p.gverts.next;for(;m!=null;){let x=m,y=_;_=_.next,x.x=p.body.posx+(p.body.axisy*y.x-p.body.axisx*y.y),x.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 o=l.aabb;r.minx=o.minx-3,r.miny=o.miny-3,r.maxx=o.maxx+3,r.maxy=o.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,z=c.child2,f=c.aabb,v=(f.maxx-f.minx+(f.maxy-f.miny))*2,E=lt.tmpaabb,d=c.aabb;E.minx=d.minx<p.minx?d.minx:p.minx,E.miny=d.miny<p.miny?d.miny:p.miny,E.maxx=d.maxx>p.maxx?d.maxx:p.maxx,E.maxy=d.maxy>p.maxy?d.maxy:p.maxy;let b=lt.tmpaabb,C=(b.maxx-b.minx+(b.maxy-b.miny))*2,P=2*C,g=2*(C-v),O=lt.tmpaabb,N=y.aabb;O.minx=p.minx<N.minx?p.minx:N.minx,O.miny=p.miny<N.miny?p.miny:N.miny,O.maxx=p.maxx>N.maxx?p.maxx:N.maxx,O.maxy=p.maxy>N.maxy?p.maxy:N.maxy;let M;if(y.child1==null){let S=lt.tmpaabb;M=(S.maxx-S.minx+(S.maxy-S.miny))*2+g}else{let S=y.aabb,R=(S.maxx-S.minx+(S.maxy-S.miny))*2,j=lt.tmpaabb;M=(j.maxx-j.minx+(j.maxy-j.miny))*2-R+g}let k=lt.tmpaabb,Z=z.aabb;k.minx=p.minx<Z.minx?p.minx:Z.minx,k.miny=p.miny<Z.miny?p.miny:Z.miny,k.maxx=p.maxx>Z.maxx?p.maxx:Z.maxx,k.maxy=p.maxy>Z.maxy?p.maxy:Z.maxy;let A;if(z.child1==null){let S=lt.tmpaabb;A=(S.maxx-S.minx+(S.maxy-S.miny))*2+g}else{let S=z.aabb,R=(S.maxx-S.minx+(S.maxy-S.miny))*2,j=lt.tmpaabb;A=(j.maxx-j.minx+(j.maxy-j.miny))*2-R+g}if(P<M&&P<A)break;c=M<A?y:z}let h=c,u=h.parent,_;Be.zpp_pool==null?_=new Be:(_=Be.zpp_pool,Be.zpp_pool=_.next,_.next=null),fe.zpp_pool==null?_.aabb=new fe:(_.aabb=fe.zpp_pool,fe.zpp_pool=_.aabb.next,_.aabb.next=null),_.moved=!1,_.synced=!1,_.first_sync=!1,_.parent=u;let m=_.aabb,x=h.aabb;for(m.minx=p.minx<x.minx?p.minx:x.minx,m.miny=p.miny<x.miny?p.miny:x.miny,m.maxx=p.maxx>x.maxx?p.maxx:x.maxx,m.maxy=p.maxy>x.maxy?p.maxy:x.maxy,_.height=h.height+1,u!=null?(u.child1==h?u.child1=_:u.child2=_,_.child1=h,_.child2=s,h.parent=_,s.parent=_):(_.child1=h,_.child2=s,h.parent=_,s.parent=_,a.root=_),c=s.parent;c!=null;){if(c.child1==null||c.height<2)c=c;else{let C=c.child1,P=c.child2,g=P.height-C.height;if(g>1){let O=P.child1,N=P.child2;if(P.child1=c,P.parent=c.parent,c.parent=P,P.parent!=null?P.parent.child1==c?P.parent.child1=P:P.parent.child2=P:a.root=P,O.height>N.height){P.child2=O,c.child2=N,N.parent=c;let M=c.aabb,k=C.aabb,Z=N.aabb;M.minx=k.minx<Z.minx?k.minx:Z.minx,M.miny=k.miny<Z.miny?k.miny:Z.miny,M.maxx=k.maxx>Z.maxx?k.maxx:Z.maxx,M.maxy=k.maxy>Z.maxy?k.maxy:Z.maxy;let A=P.aabb,S=c.aabb,R=O.aabb;A.minx=S.minx<R.minx?S.minx:R.minx,A.miny=S.miny<R.miny?S.miny:R.miny,A.maxx=S.maxx>R.maxx?S.maxx:R.maxx,A.maxy=S.maxy>R.maxy?S.maxy:R.maxy;let j=C.height,q=N.height;c.height=1+(j>q?j:q);let J=c.height,G=O.height;P.height=1+(J>G?J:G)}else{P.child2=N,c.child2=O,O.parent=c;let M=c.aabb,k=C.aabb,Z=O.aabb;M.minx=k.minx<Z.minx?k.minx:Z.minx,M.miny=k.miny<Z.miny?k.miny:Z.miny,M.maxx=k.maxx>Z.maxx?k.maxx:Z.maxx,M.maxy=k.maxy>Z.maxy?k.maxy:Z.maxy;let A=P.aabb,S=c.aabb,R=N.aabb;A.minx=S.minx<R.minx?S.minx:R.minx,A.miny=S.miny<R.miny?S.miny:R.miny,A.maxx=S.maxx>R.maxx?S.maxx:R.maxx,A.maxy=S.maxy>R.maxy?S.maxy:R.maxy;let j=C.height,q=O.height;c.height=1+(j>q?j:q);let J=c.height,G=N.height;P.height=1+(J>G?J:G)}c=P}else if(g<-1){let O=C.child1,N=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>N.height){C.child2=O,c.child1=N,N.parent=c;let M=c.aabb,k=P.aabb,Z=N.aabb;M.minx=k.minx<Z.minx?k.minx:Z.minx,M.miny=k.miny<Z.miny?k.miny:Z.miny,M.maxx=k.maxx>Z.maxx?k.maxx:Z.maxx,M.maxy=k.maxy>Z.maxy?k.maxy:Z.maxy;let A=C.aabb,S=c.aabb,R=O.aabb;A.minx=S.minx<R.minx?S.minx:R.minx,A.miny=S.miny<R.miny?S.miny:R.miny,A.maxx=S.maxx>R.maxx?S.maxx:R.maxx,A.maxy=S.maxy>R.maxy?S.maxy:R.maxy;let j=P.height,q=N.height;c.height=1+(j>q?j:q);let J=c.height,G=O.height;C.height=1+(J>G?J:G)}else{C.child2=N,c.child1=O,O.parent=c;let M=c.aabb,k=P.aabb,Z=O.aabb;M.minx=k.minx<Z.minx?k.minx:Z.minx,M.miny=k.miny<Z.miny?k.miny:Z.miny,M.maxx=k.maxx>Z.maxx?k.maxx:Z.maxx,M.maxy=k.maxy>Z.maxy?k.maxy:Z.maxy;let A=C.aabb,S=c.aabb,R=N.aabb;A.minx=S.minx<R.minx?S.minx:R.minx,A.miny=S.miny<R.miny?S.miny:R.miny,A.maxx=S.maxx>R.maxx?S.maxx:R.maxx,A.maxy=S.maxy>R.maxy?S.maxy:R.maxy;let j=P.height,q=O.height;c.height=1+(j>q?j:q);let J=c.height,G=N.height;C.height=1+(J>G?J:G)}c=C}else c=c}let y=c.child1,z=c.child2,f=y.height,v=z.height;c.height=1+(f>v?f:v);let E=c.aabb,d=y.aabb,b=z.aabb;E.minx=d.minx<b.minx?d.minx:b.minx,E.miny=d.miny<b.miny?d.miny:b.miny,E.maxx=d.maxx>b.maxx?d.maxx:b.maxx,E.maxy=d.maxy>b.maxy?d.maxy:b.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 r=l;if(r.moved)continue;r.moved=!1;let o=r.shape;if(o.body.component.sleeping)continue;let p=r.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!=r)if(u.child1==null){let _=u.shape;if(_.body!=o.body&&!(_.body.type==1&&o.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 x,y;o.id<_.id?(x=o.id,y=_.id):(x=_.id,y=o.id);let z=o.pairs.length<_.pairs.length?o:_,f=null,v=z.pairs.head;for(;v!=null;){let O=v.elt;if(O.id==x&&O.di==y){f=O;break}v=v.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}ct.zpp_pool==null?f=new ct:(f=ct.zpp_pool,ct.zpp_pool=f.next,f.next=null),f.n1=r,f.n2=u,f.id=x,f.di=y,this._linkPair(f),f.first=!0;let E=o.pairs,d;ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new ve._zpp.util.ZNPNode_ZPP_AABBPair:(d=ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=f;let b=d;b.next=E.head,E.head=b,E.modified=!0,E.length++;let C=_.pairs,P;ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new ve._zpp.util.ZNPNode_ZPP_AABBPair:(P=ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=f;let g=P;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let _=u.aabb;_.miny<=p.maxy&&p.miny<=_.maxy&&_.minx<=p.maxx&&p.minx<=_.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!=r)if(u.child1==null){let _=u.shape;if(_.body!=o.body&&!(_.body.type==1&&o.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 x,y;o.id<_.id?(x=o.id,y=_.id):(x=_.id,y=o.id);let z=o.pairs.length<_.pairs.length?o:_,f=null,v=z.pairs.head;for(;v!=null;){let O=v.elt;if(O.id==x&&O.di==y){f=O;break}v=v.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}ct.zpp_pool==null?f=new ct:(f=ct.zpp_pool,ct.zpp_pool=f.next,f.next=null),f.n1=r,f.n2=u,f.id=x,f.di=y,this._linkPair(f),f.first=!0;let E=o.pairs,d;ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new ve._zpp.util.ZNPNode_ZPP_AABBPair:(d=ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=f;let b=d;b.next=E.head,E.head=b,E.modified=!0,E.length++;let C=_.pairs,P;ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new ve._zpp.util.ZNPNode_ZPP_AABBPair:(P=ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=f;let g=P;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let _=u.aabb;_.miny<=p.maxy&&p.miny<=_.maxy&&_.minx<=p.maxx&&p.minx<=_.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 r=l;r.moved=!1;let o=r.shape;if(o.body.component.sleeping)continue;let p=r.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!=r)if(u.child1==null){let _=u.shape;if(_.body!=o.body&&!(_.body.type==1&&o.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 x,y;o.id<_.id?(x=o.id,y=_.id):(x=_.id,y=o.id);let z=o.pairs.length<_.pairs.length?o:_,f=null,v=z.pairs.head;for(;v!=null;){let O=v.elt;if(O.id==x&&O.di==y){f=O;break}v=v.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}ct.zpp_pool==null?f=new ct:(f=ct.zpp_pool,ct.zpp_pool=f.next,f.next=null),f.n1=r,f.n2=u,f.id=x,f.di=y,this._linkPair(f),f.first=!0;let E=o.pairs,d;ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new ve._zpp.util.ZNPNode_ZPP_AABBPair:(d=ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=f;let b=d;b.next=E.head,E.head=b,E.modified=!0,E.length++;let C=_.pairs,P;ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new ve._zpp.util.ZNPNode_ZPP_AABBPair:(P=ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=f;let g=P;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let _=u.aabb;_.miny<=p.maxy&&p.miny<=_.maxy&&_.minx<=p.maxx&&p.minx<=_.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!=r)if(u.child1==null){let _=u.shape;if(_.body!=o.body&&!(_.body.type==1&&o.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 x,y;o.id<_.id?(x=o.id,y=_.id):(x=_.id,y=o.id);let z=o.pairs.length<_.pairs.length?o:_,f=null,v=z.pairs.head;for(;v!=null;){let O=v.elt;if(O.id==x&&O.di==y){f=O;break}v=v.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}ct.zpp_pool==null?f=new ct:(f=ct.zpp_pool,ct.zpp_pool=f.next,f.next=null),f.n1=r,f.n2=u,f.id=x,f.di=y,this._linkPair(f),f.first=!0;let E=o.pairs,d;ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new ve._zpp.util.ZNPNode_ZPP_AABBPair:(d=ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=f;let b=d;b.next=E.head,E.head=b,E.modified=!0,E.length++;let C=_.pairs,P;ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new ve._zpp.util.ZNPNode_ZPP_AABBPair:(P=ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=f;let g=P;g.next=C.head,C.head=g,C.modified=!0,C.length++}}}else{let _=u.aabb;_.miny<=p.maxy&&p.miny<=_.maxy&&_.minx<=p.maxx&&p.minx<=_.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,_=i.n2.aabb;l=!(_.miny<=u.maxy&&u.miny<=_.maxy&&_.minx<=u.maxx&&u.minx<=_.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=ct.zpp_pool,ct.zpp_pool=i,i=u;continue}let r=i.n1.shape,o=r.body,a=i.n2.shape,p=a.body;if(!i.first&&(o.component.sleeping||o.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=r.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(r,a,o.type!=2||p.type!=2,i.arb,!1):i.arb=t.continuousEvent(r,a,o.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=ct.zpp_pool,ct.zpp_pool=n,this.pairs=t}this.dtree.clear(),this.stree.clear()}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l;pe.zpp_pool==null?l=new pe:(l=pe.zpp_pool,pe.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let r=l,o=i??new ve._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h;if(s!=null){let u=p.shape.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.shape.type==0?Ze.circleContains(p.shape.circle,r)&&o.push(p.shape.outer):Ze.polyContains(p.shape.polygon,r)&&o.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h;if(s!=null){let u=p.shape.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.shape.type==0?Ze.circleContains(p.shape.circle,r)&&o.push(p.shape.outer):Ze.polyContains(p.shape.polygon,r)&&o.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let a=r;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=pe.zpp_pool,pe.zpp_pool=a,o}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l;pe.zpp_pool==null?l=new pe:(l=pe.zpp_pool,pe.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let r=l,o=i??new ve._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!o.has(h)){let u;if(s!=null){let _=p.shape.filter;u=(_.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&_.collisionGroup)!=0}else u=!0;u&&(p.shape.type==0?Ze.circleContains(p.shape.circle,r)&&o.push(h):Ze.polyContains(p.shape.polygon,r)&&o.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!o.has(h)){let u;if(s!=null){let _=p.shape.filter;u=(_.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&_.collisionGroup)!=0}else u=!0;u&&(p.shape.type==0?Ze.circleContains(p.shape.circle,r)&&o.push(h):Ze.polyContains(p.shape.polygon,r)&&o.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let a=r;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=pe.zpp_pool,pe.zpp_pool=a,o}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new ve._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._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>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.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&&o.push(a.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new ve._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&&o.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(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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)Ze.containTest(this.aabbShape.zpp_inner,a.shape)&&o.push(a.shape.outer);else{let u=a.shape.aabb;(u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy||Ze.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&o.push(a.shape.outer)}else{let u;if(s){let _=a.shape.aabb;u=_.minx>=r.minx&&_.miny>=r.miny&&_.maxx<=r.maxx&&_.maxy<=r.maxy}else u=!0;u&&o.push(a.shape.outer)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._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>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.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&&o.push(a.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new ve._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&&o.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(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.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)Ze.containTest(this.aabbShape.zpp_inner,a.shape)&&o.push(a.shape.outer);else{let u=a.shape.aabb;(u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy||Ze.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&o.push(a.shape.outer)}else{let u;if(s){let _=a.shape.aabb;u=_.minx>=r.minx&&_.miny>=r.miny&&_.maxx<=r.maxx&&_.maxy<=r.maxy}else u=!0;u&&o.push(a.shape.outer)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}return o}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new ve._nape.phys.BodyList;if(this.failed==null&&(this.failed=new ve._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._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>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.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;o.has(h)||o.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new ve._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;o.has(u)||o.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(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let _=a.shape.filter;u=(_.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&_.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(h)){let _=Ze.containTest(this.aabbShape.zpp_inner,a.shape);!o.has(h)&&_?o.push(h):_||(o.remove(h),this.failed.push(h))}}else!o.has(h)&&Ze.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&o.push(h);else if(s){if(!this.failed.has(h)){let _=a.shape.aabb,m=_.minx>=r.minx&&_.miny>=r.miny&&_.maxx<=r.maxx&&_.maxy<=r.maxy;!o.has(h)&&m?o.push(h):m||(o.remove(h),this.failed.push(h))}}else{let _;if(o.has(h))_=!1;else{let m=a.shape.aabb;_=m.minx>=r.minx&&m.miny>=r.miny&&m.maxx<=r.maxx&&m.maxy<=r.maxy}_&&o.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 ve._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>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.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;o.has(h)||o.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new ve._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;o.has(u)||o.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(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let _=a.shape.filter;u=(_.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&_.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(h)){let _=Ze.containTest(this.aabbShape.zpp_inner,a.shape);!o.has(h)&&_?o.push(h):_||(o.remove(h),this.failed.push(h))}}else!o.has(h)&&Ze.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&o.push(h);else if(s){if(!this.failed.has(h)){let _=a.shape.aabb,m=_.minx>=r.minx&&_.miny>=r.miny&&_.maxx<=r.maxx&&_.maxy<=r.maxy;!o.has(h)&&m?o.push(h):m||(o.remove(h),this.failed.push(h))}}else{let _;if(o.has(h))_=!1;else{let m=a.shape.aabb;_=m.minx>=r.minx&&m.miny>=r.miny&&m.maxx<=r.maxx&&m.maxy<=r.maxy}_&&o.push(h)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}return this.failed.clear(),o}shapesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new ve._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._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.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.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?Ze.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):Ze.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 ve._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.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.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?Ze.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):Ze.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,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new ve._nape.phys.BodyList;if(this.failed==null&&(this.failed=new ve._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._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.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(p.child1==null){let h=p.shape.body.outer,u;if(l!=null){let _=p.shape.filter;u=(_.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&_.collisionGroup)!=0}else u=!0;if(u)if(i){if(!this.failed.has(h)){let _=Ze.containTest(this.circShape.zpp_inner,p.shape);!a.has(h)&&_?a.push(h):_||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ze.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 ve._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.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(p.child1==null){let h=p.shape.body.outer,u;if(l!=null){let _=p.shape.filter;u=(_.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&_.collisionGroup)!=0}else u=!0;if(u)if(i){if(!this.failed.has(h)){let _=Ze.containTest(this.circShape.zpp_inner,p.shape);!a.has(h)&&_?a.push(h):_||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ze.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,r=i??new ve._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(o.child1==null){let p;if(s!=null){let c=o.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ze.containTest(t,o.shape)&&r.push(o.shape.outer):Ze.testCollide_safe(o.shape,t)&&r.push(o.shape.outer))}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(o.child1==null){let p;if(s!=null){let c=o.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ze.containTest(t,o.shape)&&r.push(o.shape.outer):Ze.testCollide_safe(o.shape,t)&&r.push(o.shape.outer))}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}return r}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new ve._nape.phys.BodyList;if(this.failed==null&&(this.failed=new ve._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(o.child1==null){let p=o.shape.body.outer,c;if(s!=null){let h=o.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=Ze.containTest(t,o.shape);!r.has(p)&&h?r.push(p):h||(r.remove(p),this.failed.push(p))}}else!r.has(p)&&Ze.testCollide_safe(o.shape,t)&&r.push(p)}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(o.child1==null){let p=o.shape.body.outer,c;if(s!=null){let h=o.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=Ze.containTest(t,o.shape);!r.has(p)&&h?r.push(p):h||(r.remove(p),this.failed.push(p))}}else!r.has(p)&&Ze.testCollide_safe(o.shape,t)&&r.push(p)}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}return this.failed.clear(),r}rayCast(t,n,s){this.openlist==null&&(this.openlist=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let i=t.maxdist;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb)){let r=t.aabbsect(this.dtree.root.aabb);if(r>=0&&r<i){this.dtree.root.rayt=r;let o=null,a=this.openlist.head;for(;a!=null;){let _=a.elt;if(this.dtree.root.rayt<_.rayt)break;o=a,a=a.next}let p=this.openlist,c=this.dtree.root,h;ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new ve._zpp.util.ZNPNode_ZPP_AABBNode:(h=ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;o==null?(u.next=p.head,p.head=u):(u.next=o.next,o.next=u),p.pushmod=p.modified=!0,p.length++}}if(this.stree.root!=null&&t.aabbtest(this.stree.root.aabb)){let r=t.aabbsect(this.stree.root.aabb);if(r>=0&&r<i){this.stree.root.rayt=r;let o=null,a=this.openlist.head;for(;a!=null;){let _=a.elt;if(this.stree.root.rayt<_.rayt)break;o=a,a=a.next}let p=this.openlist,c=this.stree.root,h;ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new ve._zpp.util.ZNPNode_ZPP_AABBNode:(h=ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;o==null?(u.next=p.head,p.head=u):(u.next=o.next,o.next=u),p.pushmod=p.modified=!0,p.length++}}let l=null;for(;this.openlist.head!=null;){let r=this.openlist.pop_unsafe();if(r.rayt>=i)break;if(r.child1==null){let o=r.shape,a;if(s!=null){let p=o.filter;a=(p.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&p.collisionGroup)!=0}else a=!0;if(a){let p=o.type==0?t.circlesect(o.circle,n,i):t.aabbtest(o.aabb)?t.polysect(o.polygon,n,i):null;if(p!=null){if(p.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(i=p.zpp_inner.toiDistance,l!=null){if(l.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");l.zpp_inner.free()}l=p}}}else{if(r.child1!=null&&t.aabbtest(r.child1.aabb)){let o=t.aabbsect(r.child1.aabb);if(o>=0&&o<i){r.child1.rayt=o;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(r.child1.rayt<m.rayt)break;a=p,p=p.next}let c=this.openlist,h=r.child1,u;ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new ve._zpp.util.ZNPNode_ZPP_AABBNode:(u=ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let _=u;a==null?(_.next=c.head,c.head=_):(_.next=a.next,a.next=_),c.pushmod=c.modified=!0,c.length++}}if(r.child2!=null&&t.aabbtest(r.child2.aabb)){let o=t.aabbsect(r.child2.aabb);if(o>=0&&o<i){r.child2.rayt=o;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(r.child2.rayt<m.rayt)break;a=p,p=p.next}let c=this.openlist,h=r.child2,u;ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new ve._zpp.util.ZNPNode_ZPP_AABBNode:(u=ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ve._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let _=u;a==null?(_.next=c.head,c.head=_):(_.next=a.next,a.next=_),c.pushmod=c.modified=!0,c.length++}}}}return this.openlist.clear(),l}rayMultiCast(t,n,s,i){this.openlist==null&&(this.openlist=new ve._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let l=t.maxdist>=1/0,r=i??new ve._nape.geom.RayResultList;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb))if(l)this.openlist.add(this.dtree.root);else{let o=t.aabbsect(this.dtree.root.aabb);o>=0&&o<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 o=t.aabbsect(this.stree.root.aabb);o>=0&&o<t.maxdist&&this.openlist.add(this.stree.root)}for(;this.openlist.head!=null;){let o=this.openlist.pop_unsafe();if(o.child1==null){let a=o.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,r):t.aabbtest(a.aabb)&&t.polysect2(a.polygon,n,r))}else{if(o.child1!=null&&t.aabbtest(o.child1.aabb))if(l)this.openlist.add(o.child1);else{let a=t.aabbsect(o.child1.aabb);a>=0&&a<t.maxdist&&this.openlist.add(o.child1)}if(o.child2!=null&&t.aabbtest(o.child2.aabb))if(l)this.openlist.add(o.child2);else{let a=t.aabbsect(o.child2.aabb);a>=0&&a<t.maxdist&&this.openlist.add(o.child2)}}}return this.openlist.clear(),r}};ve._zpp=null,ve._nape=null,ve.FATTEN=3,ve.VEL_STEPS=2;var vl=ve;var nr=class nr{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 nr._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}};nr.zpp_pool=null,nr._zpp=null;var wt=nr;var ir=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}};ir.zpp_pool=null;var ii=class ii{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 ii._zpp.util.ZNPList_ZPP_Arbiter}static get(e,t){let n;return ii.zpp_pool==null?n=new ii:(n=ii.zpp_pool,ii.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=ii._zpp.util.ZNPNode_ZPP_Arbiter;l.zpp_pool==null?i=new l:(i=l.zpp_pool,l.zpp_pool=i.next,i.next=null),i.elt=e;let r=i;return r.next=s.head,s.head=r,s.modified=!0,s.length++,!0}}try_remove_arb(e){let t=this.arbiters,n=null,s=t.head,i=!1;for(;s!=null;){if(s.elt==e){let l,r;n==null?(l=t.head,r=l.next,t.head=r,t.head==null&&(t.pushmod=!0)):(l=n.next,r=l.next,n.next=r,r==null&&(t.pushmod=!0));let o=l;o.elt=null;let a=ii._zpp.util.ZNPNode_ZPP_Arbiter;o.next=a.zpp_pool,a.zpp_pool=o,t.modified=!0,t.length--,t.pushmod=!0,i=!0;break}n=s,s=s.next}return i}remove_arb(e){let t=this.arbiters,n=null,s=t.head;for(;s!=null;){if(s.elt==e){let i,l;n==null?(i=t.head,l=i.next,t.head=l,t.head==null&&(t.pushmod=!0)):(i=n.next,l=i.next,n.next=l,l==null&&(t.pushmod=!0));let r=i;r.elt=null;let o=ii._zpp.util.ZNPNode_ZPP_Arbiter;r.next=o.zpp_pool,o.zpp_pool=r,t.modified=!0,t.length--,t.pushmod=!0;break}n=s,s=s.next}}empty_arb(e){let t=!0,n=this.arbiters.head;for(;n!=null;)if((n.elt.type&e)==0){n=n.next;continue}else{t=!1;break}return t}really_empty(){return this.arbiters.head==null}sleeping(){let e=!0,t=this.arbiters.head;for(;t!=null;)if(t.elt.sleeping){t=t.next;continue}else{e=!1;break}return e}};ii.zpp_pool=null,ii._zpp=null;var cn=ii;var Ui=class Ui{constructor(e){this.cbsets=null;this.space=null;let t=Ui._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=Ui._zpp.callbacks.ZPP_CbSet.setlt,this.space=e}get(e){if(e.head==null)return null;let t=Ui._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 o=t.get(e);this.cbsets.insert(o),o.manager=this,l=o}n.cbTypes=s;let r=n;for(r.listeners.clear(),r.zip_listeners=!0,r.bodylisteners.clear(),r.zip_bodylisteners=!0,r.conlisteners.clear(),r.zip_conlisteners=!0;r.cbTypes.head!=null;)r.cbTypes.pop_unsafe().cbsets.remove(r);return r.next=t.zpp_pool,t.zpp_pool=r,l}remove(e){let t=Ui._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=Ui._zpp.callbacks.ZPP_CbSet,s=Ui._zpp.callbacks.ZPP_CbSetPair,i=null,r=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;r!=null;){let o=r.elt;if(o.a==e&&o.b==t||o.a==t&&o.b==e){i=o;break}r=r.next}if(i==null){let o;s.zpp_pool==null?o=new s:(o=s.zpp_pool,s.zpp_pool=o.next,o.next=null),o.zip_listeners=!0,n.setlt(e,t)?(o.a=e,o.b=t):(o.a=t,o.b=e),i=o,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}};Ui._zpp=null;var ks=Ui;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,xt.internal=!0,this.precb=xt._createPreCb(),this.precb.zpp_inner=new xt,xt.internal=!1,this.sortcontacts=!0,this.pre_dt=0;let n;t!=null?(I.Broadphase_DYNAMIC_AABB_TREE==null&&(I.internal=!0,I.Broadphase_DYNAMIC_AABB_TREE=new B._nape.space.Broadphase,I.internal=!1),n=t==I.Broadphase_DYNAMIC_AABB_TREE):n=!0,n?this.bphase=new B._zpp.space.ZPP_DynAABBPhase(this):(I.Broadphase_SPATIAL_HASH==null&&(I.internal=!0,I.Broadphase_SPATIAL_HASH=new B._nape.space.Broadphase,I.internal=!1),t==I.Broadphase_SPATIAL_HASH?this.bphase=new B._zpp.space.ZPP_SpatialHashPhase(this):(I.Broadphase_SWEEP_AND_PRUNE==null&&(I.internal=!0,I.Broadphase_SWEEP_AND_PRUNE=new B._nape.space.Broadphase,I.internal=!1),t==I.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 wt,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=Gn.__static(),this.__static.zpp_inner.space=this,this.callbacks=new xt,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 cn,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 ks(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;pe.zpp_pool==null?s=new pe:(s=pe.zpp_pool,pe.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y==t}else i=!1;if(!i){n.zpp_inner.x=e,n.zpp_inner.y=t;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}n.zpp_inner.weak=!1,this.wrap_gravity=n,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=s=>this.gravity_invalidate(s),this.wrap_gravity.zpp_inner._validate=()=>this.gravity_validate()}gravity_invalidate(e){if(this.midstep)throw new Error("Error: Space::gravity cannot be set during space step");this.gravityx=e.x,this.gravityy=e.y;let t=new B._zpp.util.ZNPList_ZPP_Compound,n=this.bodies.head;for(;n!=null;){let l=n.elt;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!1)),n=n.next}let s=this.compounds.head;for(;s!=null;){let i=s.elt;t.add(i),s=s.next}for(;t.head!=null;){let i=t.pop_unsafe(),l=i.bodies.head;for(;l!=null;){let 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 r=i.compounds.head;for(;r!=null;){let o=r.elt;t.add(o),r=r.next}}}gravity_validate(){this.wrap_gravity.zpp_inner.x=this.gravityx,this.wrap_gravity.zpp_inner.y=this.gravityy}clear(){for(;this.listeners.head!=null;){let t=this.listeners.pop_unsafe();this.remListener(t)}for(;this.callbackset_list.next!=null;){let t=this.callbackset_list.pop_unsafe();t.arbiters.clear();let n=t;n.int1=n.int2=null,n.id=n.di=-1,n.freed=!0,n.next=cn.zpp_pool,cn.zpp_pool=n}for(;this.c_arbiters_true.head!=null;){let t=this.c_arbiters_true.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,r=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,s.modified=!0,s.length--,s.pushmod=!0,r=!0;break}i=l,l=l.next}let o=t.b2.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,o.modified=!0,o.length--,o.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=we.zpp_pool,we.zpp_pool=l;let r=t.innards,o=r.next;r.next=o.next,o._inuse=!1,r.next==null&&(r.pushmod=!0),r.modified=!0,r.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=Pt.zpp_pool,Pt.zpp_pool=n,t.pre_dt=-1}for(;this.c_arbiters_false.head!=null;){let t=this.c_arbiters_false.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,r=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,s.modified=!0,s.length--,s.pushmod=!0,r=!0;break}i=l,l=l.next}let o=t.b2.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,o.modified=!0,o.length--,o.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=we.zpp_pool,we.zpp_pool=l;let r=t.innards,o=r.next;r.next=o.next,o._inuse=!1,r.next==null&&(r.pushmod=!0),r.modified=!0,r.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=Pt.zpp_pool,Pt.zpp_pool=n,t.pre_dt=-1}for(;this.s_arbiters.head!=null;){let t=this.s_arbiters.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,r=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,s.modified=!0,s.length--,s.pushmod=!0,r=!0;break}i=l,l=l.next}let o=t.b2.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,o.modified=!0,o.length--,o.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=Wt.zpp_pool,Wt.zpp_pool=n}for(;this.f_arbiters.head!=null;){let t=this.f_arbiters.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,r=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,s.modified=!0,s.length--,s.pushmod=!0,r=!0;break}i=l,l=l.next}let o=t.b2.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,o.modified=!0,o.length--,o.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=At.zpp_pool,At.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=wt.zpp_pool,wt.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=wt.zpp_pool,wt.zpp_pool=s}}t.removedFromSpace(),t.space=null}this.kinematics.clear();let e=new B._zpp.util.ZNPList_ZPP_Compound;for(;this.compounds.head!=null;){let t=this.compounds.pop_unsafe();e.add(t)}for(;e.head!=null;){let t=e.pop_unsafe();t.removedFromSpace(),t.space=null;let n=t.bodies.head;for(;n!=null;){let l=n.elt;if(l.component!=null){let r=l.component.island;if(r!=null){for(;r.comps.head!=null;){let a=r.comps.pop_unsafe();a.sleeping=!1,a.island=null,a.parent=a,a.rank=0}let o=r;o.next=wt.zpp_pool,wt.zpp_pool=o}}l.removedFromSpace(),l.space=null,n=n.next}let s=t.constraints.head;for(;s!=null;){let l=s.elt;if(l.component!=null){let r=l.component.island;if(r!=null){for(;r.comps.head!=null;){let a=r.comps.pop_unsafe();a.sleeping=!1,a.island=null,a.parent=a,a.rank=0}let o=r;o.next=wt.zpp_pool,wt.zpp_pool=o}}l.removedFromSpace(),l.space=null,s=s.next}let i=t.compounds.head;for(;i!=null;){let l=i.elt;e.add(l),i=i.next}}this.staticsleep.clear(),this.live.clear(),this.live_constraints.clear(),this.stamp=0,this.time=0,this.mrca1.clear(),this.mrca2.clear(),this.prelisteners.clear(),this.cbsets.clear()}bodies_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_bodies.remove(e),this.addBody(e.zpp_inner),!0):!1}bodies_subber(e){this.remBody(e.zpp_inner)}bodies_modifiable(){if(this.midstep)throw new Error("Error: Space::bodies cannot be set during space step()")}compounds_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.wrap_compounds.remove(e),this.addCompound(e.zpp_inner),!0):!1}compounds_subber(e){this.remCompound(e.zpp_inner)}compounds_modifiable(){if(this.midstep)throw new Error("Error: Space::compounds cannot be set during space step()")}constraints_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_constraints.remove(e),this.addConstraint(e.zpp_inner),!0):!1}constraints_subber(e){this.remConstraint(e.zpp_inner)}constraints_modifiable(){if(this.midstep)throw new Error("Error: Space::constraints cannot be set during space step()")}listeners_adder(e){return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_listeners.remove(e),this.addListener(e.zpp_inner),!0):!1}listeners_subber(e){this.remListener(e.zpp_inner)}listeners_modifiable(){if(this.midstep)throw new Error("Error: Space::listeners cannot be set during space step()")}revoke_listener(e){}unrevoke_listener(e){}addListener(e){e.space=this,e.addedToSpace();let t=e.interaction!=null}remListener(e){let t=e.interaction!=null;e.removedFromSpace(),e.space=null}add_callbackset(e){let t=e.int1.cbsets,n;B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?n=new B._zpp.util.ZNPNode_ZPP_CallbackSet:(n=B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=n.next,n.next=null),n.elt=e;let s=n;s.next=t.head,t.head=s,t.modified=!0,t.length++;let i=e.int2.cbsets,l;B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?l=new B._zpp.util.ZNPNode_ZPP_CallbackSet:(l=B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;r.next=i.head,i.head=r,i.modified=!0,i.length++;let o=this.callbackset_list;e._inuse=!0;let a=e;a.next=o.next,o.next=a,o.modified=!0,o.length++}remove_callbackset(e){e.lazydel=!0;let t=e.int1.cbsets,n=null,s=t.head,i=!1;for(;s!=null;){if(s.elt==e){let p,c;n==null?(p=t.head,c=p.next,t.head=c,t.head==null&&(t.pushmod=!0)):(p=n.next,c=p.next,n.next=c,c==null&&(t.pushmod=!0));let h=p;h.elt=null,h.next=B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=h,t.modified=!0,t.length--,t.pushmod=!0,i=!0;break}n=s,s=s.next}let l=e.int2.cbsets,r=null,o=l.head,a=!1;for(;o!=null;){if(o.elt==e){let p,c;r==null?(p=l.head,c=p.next,l.head=c,l.head==null&&(l.pushmod=!0)):(p=r.next,c=p.next,r.next=c,c==null&&(l.pushmod=!0));let h=p;h.elt=null,h.next=B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,B._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=h,l.modified=!0,l.length--,l.pushmod=!0,a=!0;break}r=o,o=o.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 o=this.mrca1.head;for(;o!=null;){let a=o.elt,p=this.mrca2.head;for(;p!=null;){let c=p.elt,h=a.cbSet,u=c.cbSet;h.validate(),u.validate();let _=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;Ve.zpp_pool==null?C=new Ve:(C=Ve.zpp_pool,Ve.zpp_pool=C.next,C.next=null),C.zip_listeners=!0,gt.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 z=B._zpp.phys.ZPP_Interactor.get(a,c);z.remove_arb(l),l.present--;let f=h.manager,v=null,d=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;d!=null;){let C=d.elt;if(C.a==h&&C.b==u||C.a==u&&C.b==h){v=C;break}d=d.next}if(v==null){let C;Ve.zpp_pool==null?C=new Ve:(C=Ve.zpp_pool,Ve.zpp_pool=C.next,C.next=null),C.zip_listeners=!0,gt.setlt(h,u)?(C.a=h,C.b=u):(C.a=u,C.b=h),v=C,h.cbpairs.add(v),u!=h&&u.cbpairs.add(v)}v.zip_listeners&&(v.zip_listeners=!1,v.__validate());let b=v.listeners.head;for(;b!=null;){let C=b.elt;if(C.event==1&&(C.itype&l.type)!=0&&z.empty_arb(C.itype)){let P=this.push_callback(C);P.event=1;let g=z.int1,O=z.int2,N,M=C.options1,k=g.cbTypes;if(M.nonemptyintersection(k,M.includes)&&!M.nonemptyintersection(k,M.excludes)){let Z=C.options2,A=O.cbTypes;N=Z.nonemptyintersection(A,Z.includes)&&!Z.nonemptyintersection(A,Z.excludes)}else N=!1;N?(P.int1=g,P.int2=O):(P.int1=O,P.int2=g),P.set=z}b=b.next}z.arbiters.head==null&&this.remove_callbackset(z),p=p.next}o=o.next}}if(l.b1!=n&&l.b1.type==2){let o=l.b1;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))}if(l.b2!=n&&l.b2.type==2){let o=l.b2;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))}if(l.cleared=!0,n==null||l.b2==n){let o=l.b1.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,o.modified=!0,o.length--,o.pushmod=!0,c=!0;break}a=p,p=p.next}}if(n==null||l.b1==n){let o=l.b2.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=!0));let _=h;_.elt=null,_.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=_,o.modified=!0,o.length--,o.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 r=i.body;r.world||(r.component.waket=this.stamp+(this.midstep?0:1),r.type==3&&(r.kinematicDelaySleep=!0),r.component.sleeping&&this.really_wake(r,!1))}this.bphase.insert(i),i.addedToSpace(),s=s.next}e.type==1?this.static_validation(e):e.type!=2&&t!=3&&this.kinematics.add(e)}remBody(e,t){if(t==null&&(t=-1),e.type==1){let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0)),this.staticsleep.remove(e)}else if(e.type==2){let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0)),this.live.remove(e)}else{t!=3&&this.kinematics.remove(e);let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0)),this.staticsleep.remove(e)}let n=e.shapes.head;for(;n!=null;){let s=n.elt;this.removed_shape(s,!0),n=n.next}e.removedFromSpace(),e.space=null}shapesUnderPoint(e,t,n,s){return this.bphase.shapesUnderPoint(e,t,n,s)}bodiesUnderPoint(e,t,n,s){return this.bphase.bodiesUnderPoint(e,t,n,s)}shapesInAABB(e,t,n,s,i){return this.bphase.shapesInAABB(e.zpp_inner,t,n,s,i)}bodiesInAABB(e,t,n,s,i){return this.bphase.bodiesInAABB(e.zpp_inner,t,n,s,i)}shapesInCircle(e,t,n,s,i){let l=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=e.zpp_inner;r._validate!=null&&r._validate();let o=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(o,e.zpp_inner.y,t,n,s,i)}bodiesInCircle(e,t,n,s,i){let l=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=e.zpp_inner;r._validate!=null&&r._validate();let o=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(o,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 j=S.polygon;if(j.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(j.lverts.next.next==null)j.localCOMx=j.lverts.next.x,j.localCOMy=j.lverts.next.y;else if(j.lverts.next.next.next==null){j.localCOMx=j.lverts.next.x,j.localCOMy=j.lverts.next.y;let q=1;j.localCOMx+=j.lverts.next.next.x*q,j.localCOMy+=j.lverts.next.next.y*q;let J=.5;j.localCOMx*=J,j.localCOMy*=J}else{j.localCOMx=0,j.localCOMy=0;let q=0,J=j.lverts.next,G=J;J=J.next;let L=J;for(J=J.next;J!=null;){let ee=J;q+=L.x*(ee.y-G.y);let W=ee.y*L.x-ee.x*L.y;j.localCOMx+=(L.x+ee.x)*W,j.localCOMy+=(L.y+ee.y)*W,G=L,L=ee,J=J.next}J=j.lverts.next;let V=J;q+=L.x*(V.y-G.y);let Y=V.y*L.x-V.x*L.y;j.localCOMx+=(L.x+V.x)*Y,j.localCOMy+=(L.y+V.y)*Y,G=L,L=V,J=J.next;let $=J;q+=L.x*($.y-G.y);let H=$.y*L.x-$.x*L.y;j.localCOMx+=(L.x+$.x)*H,j.localCOMy+=(L.y+$.y)*H,q=1/(3*q);let X=q;j.localCOMx*=X,j.localCOMy*=X}}S.wrap_localCOM!=null&&(S.wrap_localCOM.zpp_inner.x=S.localCOMx,S.wrap_localCOM.zpp_inner.y=S.localCOMy)}let R=S.body;R.zip_axis&&(R.zip_axis=!1,R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.rot)),S.worldCOMx=S.body.posx+(S.body.axisy*S.localCOMx-S.body.axisx*S.localCOMy),S.worldCOMy=S.body.posy+(S.localCOMx*S.body.axisx+S.localCOMy*S.body.axisy)}}else{let S=e.polygon;if(S.zip_gaxi&&S.body!=null){S.zip_gaxi=!1,S.validate_laxi();let R=S.body;if(R.zip_axis&&(R.zip_axis=!1,R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.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 Y=S.lverts.next,$=S.gverts.next;for(;$!=null;){let H=$,X=Y;Y=Y.next,H.x=S.body.posx+(S.body.axisy*X.x-S.body.axisx*X.y),H.y=S.body.posy+(X.x*S.body.axisx+X.y*S.body.axisy),$=$.next}}let j=S.edges.head,q=S.gverts.next,J=q;for(q=q.next;q!=null;){let V=q,Y=j.elt;j=j.next,Y.gp0=J,Y.gp1=V,Y.gnormx=S.body.axisy*Y.lnormx-S.body.axisx*Y.lnormy,Y.gnormy=Y.lnormx*S.body.axisx+Y.lnormy*S.body.axisy,Y.gprojection=S.body.posx*Y.gnormx+S.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,J=V,q=q.next}let G=S.gverts.next,L=j.elt;j=j.next,L.gp0=J,L.gp1=G,L.gnormx=S.body.axisy*L.lnormx-S.body.axisx*L.lnormy,L.gnormy=L.lnormx*S.body.axisx+L.lnormy*S.body.axisy,L.gprojection=S.body.posx*L.gnormx+S.body.posy*L.gnormy+L.lprojection,L.wrap_gnorm!=null&&(L.wrap_gnorm.zpp_inner.x=L.gnormx,L.wrap_gnorm.zpp_inner.y=L.gnormy),L.tp0=L.gp0.y*L.gnormx-L.gp0.x*L.gnormy,L.tp1=L.gp1.y*L.gnormx-L.gp1.x*L.gnormy}}let l=e.body,r=l.posx,o=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 R=l.sweep_angvel*a;if(l.rot+=R,R*R>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let j=R*R,q=1-.5*j,J=1-j*j/8,G=(q*l.axisx+R*l.axisy)*J;l.axisy=(q*l.axisy-R*l.axisx)*J,l.axisx=G}}}let p=l.posx,c=l.posy;e.validate_sweepRadius();let h=e.sweepRadius,u;fe.zpp_pool==null?u=new fe:(u=fe.zpp_pool,fe.zpp_pool=u.next,u.next=null);let _=r,m=p;u.minx=(_<m?_:m)-h;let x=r,y=p;u.maxx=(x>y?x:y)+h;let z=o,f=c;u.miny=(z<f?z:f)-h;let v=o,E=c;u.maxy=(v>E?v:E)+h;let d=this.convexShapeList=this.bphase.shapesInAABB(u,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),b=u;b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b.wrap_min=b.wrap_max=null,b._invalidate=null,b._validate=null,b.next=fe.zpp_pool,fe.zpp_pool=b;let C=0,P=0;C=0,P=0;let g=0,O=0;g=0,O=0;let N=null,M=t+1;d.zpp_inner.valmod();let k=B._nape.shape.ShapeIterator.get(d);for(;;){k.zpp_inner.zpp_inner.valmod();let S=k.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 R=S.zpp_inner.user_length;k.zpp_critical=!0;let j;if(k.zpp_i<R?j=!0:(k.zpp_next=B._nape.shape.ShapeIterator.zpp_pool,B._nape.shape.ShapeIterator.zpp_pool=k,k.zpp_inner=null,j=!1),!j)break;k.zpp_critical=!1;let q=k.zpp_inner.at(k.zpp_i++);if(q!=e.outer&&(q.zpp_inner.body!=null?q.zpp_inner.body.outer:null)!=l.outer){if(i.s1=e,i.s2=q.zpp_inner,s){q.zpp_inner.validate_sweepRadius(),(q.zpp_inner.body!=null?q.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(q.zpp_inner.body!=null?q.zpp_inner.body.outer:null).zpp_inner.angvel,(q.zpp_inner.body!=null?q.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,mn.dynamicSweep(i,t,0,0,!0);let J=(q.zpp_inner.body!=null?q.zpp_inner.body.outer:null).zpp_inner,G=0-J.sweepTime;if(G!=0){J.sweepTime=0;let Y=G;if(J.posx+=J.velx*Y,J.posy+=J.vely*Y,J.angvel!=0){let $=J.sweep_angvel*G;if(J.rot+=$,$*$>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let H=$*$,X=1-.5*H,ee=1-H*H/8,W=(X*J.axisx+$*J.axisy)*ee;J.axisy=(X*J.axisy-$*J.axisx)*ee,J.axisx=W}}}let L=(q.zpp_inner.body!=null?q.zpp_inner.body.outer:null).zpp_inner,V=q.zpp_inner;if(V.type==0)V.worldCOMx=L.posx+(L.axisy*V.localCOMx-L.axisx*V.localCOMy),V.worldCOMy=L.posy+(V.localCOMx*L.axisx+V.localCOMy*L.axisy);else{let Y=V.polygon,$=Y.lverts.next,H=Y.gverts.next;for(;H!=null;){let T=H,U=$;$=$.next,T.x=L.posx+(L.axisy*U.x-L.axisx*U.y),T.y=L.posy+(U.x*L.axisx+U.y*L.axisy),H=H.next}let X=Y.edges.head,ee=Y.gverts.next,W=ee;for(ee=ee.next;ee!=null;){let T=ee,U=X.elt;X=X.next,U.gnormx=L.axisy*U.lnormx-L.axisx*U.lnormy,U.gnormy=U.lnormx*L.axisx+U.lnormy*L.axisy,U.gprojection=L.posx*U.gnormx+L.posy*U.gnormy+U.lprojection,U.tp0=W.y*U.gnormx-W.x*U.gnormy,U.tp1=T.y*U.gnormx-T.x*U.gnormy,W=T,ee=ee.next}let F=Y.gverts.next,D=X.elt;X=X.next,D.gnormx=L.axisy*D.lnormx-L.axisx*D.lnormy,D.gnormy=D.lnormx*L.axisx+D.lnormy*L.axisy,D.gprojection=L.posx*D.gnormx+L.posy*D.gnormy+D.lprojection,D.tp0=W.y*D.gnormx-W.x*D.gnormy,D.tp1=F.y*D.gnormx-F.x*D.gnormy}}else mn.staticSweep(i,t,0,0);i.toi*=t,i.toi>0&&i.toi<M&&(M=i.toi,C=i.axis.x,P=i.axis.y,g=i.c2.x,O=i.c2.y,N=q)}}d.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 R=l.sweep_angvel*A;if(l.rot+=R,R*R>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let j=R*R,q=1-.5*j,J=1-j*j/8,G=(q*l.axisx+R*l.axisy)*J;l.axisy=(q*l.axisy-R*l.axisx)*J,l.axisx=G}}}if(e.type==0)e.worldCOMx=l.posx+(l.axisy*e.localCOMx-l.axisx*e.localCOMy),e.worldCOMy=l.posy+(e.localCOMx*l.axisx+e.localCOMy*l.axisy);else{let S=e.polygon,R=S.lverts.next,j=S.gverts.next;for(;j!=null;){let Y=j,$=R;R=R.next,Y.x=l.posx+(l.axisy*$.x-l.axisx*$.y),Y.y=l.posy+($.x*l.axisx+$.y*l.axisy),j=j.next}let q=S.edges.head,J=S.gverts.next,G=J;for(J=J.next;J!=null;){let Y=J,$=q.elt;q=q.next,$.gnormx=l.axisy*$.lnormx-l.axisx*$.lnormy,$.gnormy=$.lnormx*l.axisx+$.lnormy*l.axisy,$.gprojection=l.posx*$.gnormx+l.posy*$.gnormy+$.lprojection,$.tp0=G.y*$.gnormx-G.x*$.gnormy,$.tp1=Y.y*$.gnormx-Y.x*$.gnormy,G=Y,J=J.next}let L=S.gverts.next,V=q.elt;q=q.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=G.y*V.gnormx-G.x*V.gnormy,V.tp1=L.y*V.gnormx-L.x*V.gnormy}if(M<=t){let S=-C,R=-P;if(R==null&&(R=0),S==null&&(S=0),S!=S||R!=R)throw new Error("Error: Vec2 components cannot be NaN");let j;if(B._zpp.util.ZPP_PubPool.poolVec2==null?j=new B._nape.geom.Vec2:(j=B._zpp.util.ZPP_PubPool.poolVec2,B._zpp.util.ZPP_PubPool.poolVec2=j.zpp_pool,j.zpp_pool=null,j.zpp_disp=!1,j==B._zpp.util.ZPP_PubPool.nextVec2&&(B._zpp.util.ZPP_PubPool.nextVec2=null)),j.zpp_inner==null){let L;pe.zpp_pool==null?L=new pe:(L=pe.zpp_pool,pe.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=S,L.y=R,j.zpp_inner=L,j.zpp_inner.outer=j}else{if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=j.zpp_inner;if(L._immutable)throw new Error("Error: Vec2 is immutable");if(L._isimmutable!=null&&L._isimmutable(),S!=S||R!=R)throw new Error("Error: Vec2 components cannot be NaN");let V;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Y=j.zpp_inner;if(Y._validate!=null&&Y._validate(),j.zpp_inner.x==S){if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let $=j.zpp_inner;$._validate!=null&&$._validate(),V=j.zpp_inner.y==R}else V=!1;if(!V){j.zpp_inner.x=S,j.zpp_inner.y=R;let $=j.zpp_inner;$._invalidate!=null&&$._invalidate($)}}j.zpp_inner.weak=!1;let q=g,J=O;if(J==null&&(J=0),q==null&&(q=0),q!=q||J!=J)throw new Error("Error: Vec2 components cannot be NaN");let G;if(B._zpp.util.ZPP_PubPool.poolVec2==null?G=new B._nape.geom.Vec2:(G=B._zpp.util.ZPP_PubPool.poolVec2,B._zpp.util.ZPP_PubPool.poolVec2=G.zpp_pool,G.zpp_pool=null,G.zpp_disp=!1,G==B._zpp.util.ZPP_PubPool.nextVec2&&(B._zpp.util.ZPP_PubPool.nextVec2=null)),G.zpp_inner==null){let L;pe.zpp_pool==null?L=new pe:(L=pe.zpp_pool,pe.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=q,L.y=J,G.zpp_inner=L,G.zpp_inner.outer=G}else{if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=G.zpp_inner;if(L._immutable)throw new Error("Error: Vec2 is immutable");if(L._isimmutable!=null&&L._isimmutable(),q!=q||J!=J)throw new Error("Error: Vec2 components cannot be NaN");let V;if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Y=G.zpp_inner;if(Y._validate!=null&&Y._validate(),G.zpp_inner.x==q){if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let $=G.zpp_inner;$._validate!=null&&$._validate(),V=G.zpp_inner.y==J}else V=!1;if(!V){G.zpp_inner.x=q,G.zpp_inner.y=J;let $=G.zpp_inner;$._invalidate!=null&&$._invalidate($)}}return G.zpp_inner.weak=!1,B._zpp.geom.ZPP_ConvexRayResult.getConvex(j,G,M,N)}else return null}prepareCast(e){if(e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let s=t.polygon;if(s.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(s.lverts.next.next==null)s.localCOMx=s.lverts.next.x,s.localCOMy=s.lverts.next.y;else if(s.lverts.next.next.next==null){s.localCOMx=s.lverts.next.x,s.localCOMy=s.lverts.next.y;let i=1;s.localCOMx+=s.lverts.next.next.x*i,s.localCOMy+=s.lverts.next.next.y*i;let l=.5;s.localCOMx*=l,s.localCOMy*=l}else{s.localCOMx=0,s.localCOMy=0;let i=0,l=s.lverts.next,r=l;l=l.next;let o=l;for(l=l.next;l!=null;){let _=l;i+=o.x*(_.y-r.y);let m=_.y*o.x-_.x*o.y;s.localCOMx+=(o.x+_.x)*m,s.localCOMy+=(o.y+_.y)*m,r=o,o=_,l=l.next}l=s.lverts.next;let a=l;i+=o.x*(a.y-r.y);let p=a.y*o.x-a.x*o.y;s.localCOMx+=(o.x+a.x)*p,s.localCOMy+=(o.y+a.y)*p,r=o,o=a,l=l.next;let c=l;i+=o.x*(c.y-r.y);let h=c.y*o.x-c.x*o.y;s.localCOMx+=(o.x+c.x)*h,s.localCOMy+=(o.y+c.y)*h,i=1/(3*i);let u=i;s.localCOMx*=u,s.localCOMy*=u}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let n=t.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}}else{let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let 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 r=t.gverts.next,o=s.elt;s=s.next,o.gp0=l,o.gp1=r,o.gnormx=t.body.axisy*o.lnormx-t.body.axisx*o.lnormy,o.gnormy=o.lnormx*t.body.axisx+o.lnormy*t.body.axisy,o.gprojection=t.body.posx*o.gnormx+t.body.posy*o.gnormy+o.lprojection,o.wrap_gnorm!=null&&(o.wrap_gnorm.zpp_inner.x=o.gnormx,o.wrap_gnorm.zpp_inner.y=o.gnormy),o.tp0=o.gp0.y*o.gnormx-o.gp0.x*o.gnormy,o.tp1=o.gp1.y*o.gnormx-o.gp1.x*o.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,R=S;S=S.next;let j=S;for(S=S.next;S!=null;){let Y=S;A+=j.x*(Y.y-R.y);let $=Y.y*j.x-Y.x*j.y;Z.localCOMx+=(j.x+Y.x)*$,Z.localCOMy+=(j.y+Y.y)*$,R=j,j=Y,S=S.next}S=Z.lverts.next;let q=S;A+=j.x*(q.y-R.y);let J=q.y*j.x-q.x*j.y;Z.localCOMx+=(j.x+q.x)*J,Z.localCOMy+=(j.y+q.y)*J,R=j,j=q,S=S.next;let G=S;A+=j.x*(G.y-R.y);let L=G.y*j.x-G.x*j.y;Z.localCOMx+=(j.x+G.x)*L,Z.localCOMy+=(j.y+G.y)*L,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 k=M.body;k.zip_axis&&(k.zip_axis=!1,k.axisx=Math.sin(k.rot),k.axisy=Math.cos(k.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 k=M.body;if(k.zip_axis&&(k.zip_axis=!1,k.axisx=Math.sin(k.rot),k.axisy=Math.cos(k.rot)),M.zip_gverts&&M.body!=null){M.zip_gverts=!1,M.validate_lverts();let q=M.body;q.zip_axis&&(q.zip_axis=!1,q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot));let J=M.lverts.next,G=M.gverts.next;for(;G!=null;){let L=G,V=J;J=J.next,L.x=M.body.posx+(M.body.axisy*V.x-M.body.axisx*V.y),L.y=M.body.posy+(V.x*M.body.axisx+V.y*M.body.axisy),G=G.next}}let Z=M.edges.head,A=M.gverts.next,S=A;for(A=A.next;A!=null;){let q=A,J=Z.elt;Z=Z.next,J.gp0=S,J.gp1=q,J.gnormx=M.body.axisy*J.lnormx-M.body.axisx*J.lnormy,J.gnormy=J.lnormx*M.body.axisx+J.lnormy*M.body.axisy,J.gprojection=M.body.posx*J.gnormx+M.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,S=q,A=A.next}let R=M.gverts.next,j=Z.elt;Z=Z.next,j.gp0=S,j.gp1=R,j.gnormx=M.body.axisy*j.lnormx-M.body.axisx*j.lnormy,j.gnormy=j.lnormx*M.body.axisx+j.lnormy*M.body.axisy,j.gprojection=M.body.posx*j.gnormx+M.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 r=e.body,o=r.posx,a=r.posy;r.sweepTime=0,r.sweep_angvel=r.angvel;let p=t-r.sweepTime;if(p!=0){r.sweepTime=t;let M=p;if(r.posx+=r.velx*M,r.posy+=r.vely*M,r.angvel!=0){let k=r.sweep_angvel*p;if(r.rot+=k,k*k>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let Z=k*k,A=1-.5*Z,S=1-Z*Z/8,R=(A*r.axisx+k*r.axisy)*S;r.axisy=(A*r.axisy-k*r.axisx)*S,r.axisx=R}}}let c=r.posx,h=r.posy;e.validate_sweepRadius();let u=e.sweepRadius,_;fe.zpp_pool==null?_=new fe:(_=fe.zpp_pool,fe.zpp_pool=_.next,_.next=null);let m=o,x=c;_.minx=(m<x?m:x)-u;let y=o,z=c;_.maxx=(y>z?y:z)+u;let f=a,v=h;_.miny=(f<v?f:v)-u;let E=a,d=h;_.maxy=(E>d?E:d)+u;let b=this.convexShapeList=this.bphase.shapesInAABB(_,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),C=_;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=fe.zpp_pool,fe.zpp_pool=C;let P=i??new B._nape.geom.ConvexResultList;b.zpp_inner.valmod();let g=B._nape.shape.ShapeIterator.get(b);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 k=M.zpp_inner.user_length;g.zpp_critical=!0;let Z;if(g.zpp_i<k?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)!=r.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,mn.dynamicSweep(l,t,0,0,!0);let S=(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner,R=0-S.sweepTime;if(R!=0){S.sweepTime=0;let J=R;if(S.posx+=S.velx*J,S.posy+=S.vely*J,S.angvel!=0){let G=S.sweep_angvel*R;if(S.rot+=G,G*G>1e-4)S.axisx=Math.sin(S.rot),S.axisy=Math.cos(S.rot);else{let L=G*G,V=1-.5*L,Y=1-L*L/8,$=(V*S.axisx+G*S.axisy)*Y;S.axisy=(V*S.axisy-G*S.axisx)*Y,S.axisx=$}}}let j=(A.zpp_inner.body!=null?A.zpp_inner.body.outer:null).zpp_inner,q=A.zpp_inner;if(q.type==0)q.worldCOMx=j.posx+(j.axisy*q.localCOMx-j.axisx*q.localCOMy),q.worldCOMy=j.posy+(q.localCOMx*j.axisx+q.localCOMy*j.axisy);else{let J=q.polygon,G=J.lverts.next,L=J.gverts.next;for(;L!=null;){let ee=L,W=G;G=G.next,ee.x=j.posx+(j.axisy*W.x-j.axisx*W.y),ee.y=j.posy+(W.x*j.axisx+W.y*j.axisy),L=L.next}let V=J.edges.head,Y=J.gverts.next,$=Y;for(Y=Y.next;Y!=null;){let ee=Y,W=V.elt;V=V.next,W.gnormx=j.axisy*W.lnormx-j.axisx*W.lnormy,W.gnormy=W.lnormx*j.axisx+W.lnormy*j.axisy,W.gprojection=j.posx*W.gnormx+j.posy*W.gnormy+W.lprojection,W.tp0=$.y*W.gnormx-$.x*W.gnormy,W.tp1=ee.y*W.gnormx-ee.x*W.gnormy,$=ee,Y=Y.next}let H=J.gverts.next,X=V.elt;V=V.next,X.gnormx=j.axisy*X.lnormx-j.axisx*X.lnormy,X.gnormy=X.lnormx*j.axisx+X.lnormy*j.axisy,X.gprojection=j.posx*X.gnormx+j.posy*X.gnormy+X.lprojection,X.tp0=$.y*X.gnormx-$.x*X.gnormy,X.tp1=H.y*X.gnormx-H.x*X.gnormy}}else mn.staticSweep(l,t,0,0);if(l.toi*=t,l.toi>0){let S=-l.axis.x,R=-l.axis.y;if(R==null&&(R=0),S==null&&(S=0),S!=S||R!=R)throw new Error("Error: Vec2 components cannot be NaN");let j;if(B._zpp.util.ZPP_PubPool.poolVec2==null?j=new B._nape.geom.Vec2:(j=B._zpp.util.ZPP_PubPool.poolVec2,B._zpp.util.ZPP_PubPool.poolVec2=j.zpp_pool,j.zpp_pool=null,j.zpp_disp=!1,j==B._zpp.util.ZPP_PubPool.nextVec2&&(B._zpp.util.ZPP_PubPool.nextVec2=null)),j.zpp_inner==null){let ee;pe.zpp_pool==null?ee=new pe:(ee=pe.zpp_pool,pe.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=S,ee.y=R,j.zpp_inner=ee,j.zpp_inner.outer=j}else{if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=j.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),S!=S||R!=R)throw new Error("Error: Vec2 components cannot be NaN");let W;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=j.zpp_inner;if(F._validate!=null&&F._validate(),j.zpp_inner.x==S){if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=j.zpp_inner;D._validate!=null&&D._validate(),W=j.zpp_inner.y==R}else W=!1;if(!W){j.zpp_inner.x=S,j.zpp_inner.y=R;let D=j.zpp_inner;D._invalidate!=null&&D._invalidate(D)}}j.zpp_inner.weak=!1;let q=l.c2.x,J=l.c2.y;if(J==null&&(J=0),q==null&&(q=0),q!=q||J!=J)throw new Error("Error: Vec2 components cannot be NaN");let G;if(B._zpp.util.ZPP_PubPool.poolVec2==null?G=new B._nape.geom.Vec2:(G=B._zpp.util.ZPP_PubPool.poolVec2,B._zpp.util.ZPP_PubPool.poolVec2=G.zpp_pool,G.zpp_pool=null,G.zpp_disp=!1,G==B._zpp.util.ZPP_PubPool.nextVec2&&(B._zpp.util.ZPP_PubPool.nextVec2=null)),G.zpp_inner==null){let ee;pe.zpp_pool==null?ee=new pe:(ee=pe.zpp_pool,pe.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=q,ee.y=J,G.zpp_inner=ee,G.zpp_inner.outer=G}else{if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=G.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),q!=q||J!=J)throw new Error("Error: Vec2 components cannot be NaN");let W;if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=G.zpp_inner;if(F._validate!=null&&F._validate(),G.zpp_inner.x==q){if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=G.zpp_inner;D._validate!=null&&D._validate(),W=G.zpp_inner.y==J}else W=!1;if(!W){G.zpp_inner.x=q,G.zpp_inner.y=J;let D=G.zpp_inner;D._invalidate!=null&&D._invalidate(D)}}G.zpp_inner.weak=!1;let L=B._zpp.geom.ZPP_ConvexRayResult.getConvex(j,G,l.toi,A),V=null,Y=P.zpp_inner.inner.head;for(;Y!=null;){let ee=Y.elt;if(L.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(L.zpp_inner.toiDistance<ee.zpp_inner.toiDistance)break;V=Y,Y=Y.next}let $=P.zpp_inner.inner,H;B._zpp.util.ZNPNode_ConvexResult.zpp_pool==null?H=new B._zpp.util.ZNPNode_ConvexResult:(H=B._zpp.util.ZNPNode_ConvexResult.zpp_pool,B._zpp.util.ZNPNode_ConvexResult.zpp_pool=H.next,H.next=null),H.elt=L;let X=H;V==null?(X.next=$.head,$.head=X):(X.next=V.next,V.next=X),$.pushmod=$.modified=!0,$.length++}}}b.clear();let O=l;O.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=O;let N=0-r.sweepTime;if(N!=0){r.sweepTime=0;let M=N;if(r.posx+=r.velx*M,r.posy+=r.vely*M,r.angvel!=0){let k=r.sweep_angvel*N;if(r.rot+=k,k*k>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let Z=k*k,A=1-.5*Z,S=1-Z*Z/8,R=(A*r.axisx+k*r.axisy)*S;r.axisy=(A*r.axisy-k*r.axisx)*S,r.axisx=R}}}if(e.type==0)e.worldCOMx=r.posx+(r.axisy*e.localCOMx-r.axisx*e.localCOMy),e.worldCOMy=r.posy+(e.localCOMx*r.axisx+e.localCOMy*r.axisy);else{let M=e.polygon,k=M.lverts.next,Z=M.gverts.next;for(;Z!=null;){let J=Z,G=k;k=k.next,J.x=r.posx+(r.axisy*G.x-r.axisx*G.y),J.y=r.posy+(G.x*r.axisx+G.y*r.axisy),Z=Z.next}let A=M.edges.head,S=M.gverts.next,R=S;for(S=S.next;S!=null;){let J=S,G=A.elt;A=A.next,G.gnormx=r.axisy*G.lnormx-r.axisx*G.lnormy,G.gnormy=G.lnormx*r.axisx+G.lnormy*r.axisy,G.gprojection=r.posx*G.gnormx+r.posy*G.gnormy+G.lprojection,G.tp0=R.y*G.gnormx-R.x*G.gnormy,G.tp1=J.y*G.gnormx-J.x*G.gnormy,R=J,S=S.next}let j=M.gverts.next,q=A.elt;A=A.next,q.gnormx=r.axisy*q.lnormx-r.axisx*q.lnormy,q.gnormy=q.lnormx*r.axisx+q.lnormy*r.axisy,q.gprojection=r.posx*q.gnormx+r.posy*q.gnormy+q.lprojection,q.tp0=R.y*q.gnormx-R.x*q.gnormy,q.tp1=j.y*q.gnormx-j.x*q.gnormy}return P}push_callback(e){let t;return xt.zpp_pool==null?t=new xt:(t=xt.zpp_pool,xt.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 r=l.elt;r.type==1&&(r.polygon.invalidate_gverts(),r.polygon.invalidate_gaxi()),r.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 r=null;for(;l!=null;){i++;let o=l,a=0,p=s;for(;o!=null&&a<s;)a++,o=o.next;for(;a>0||p>0&&o!=null;){let c;a==0?(c=o,o=o.next,p--):p==0||o==null||t(l.elt)<=t(o.elt)?(c=l,l=l.next,a--):(c=o,o=o.next,p--),r!=null?r.next=c:n=c,r=c}l=o}if(r.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 o=0;o<s;o++){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 _=u.head,m=null,x=null,y=null,z=null,f=1,v,E,d;for(;;){for(v=0,x=_,_=null,m=_;x!=null;){for(++v,y=x,E=0,d=f;y!=null&&E<f;)++E,y=y.next;for(;E>0||d>0&&y!=null;)E==0?(z=y,y=y.next,--d):d==0||y==null||(x.elt.active&&y.elt.active?x.elt.oc1.dist<y.elt.oc1.dist:!this.deterministic||this._arbiterSortKey(x.elt)<=this._arbiterSortKey(y.elt))?(z=x,x=x.next,--E):(z=y,y=y.next,--d),m!=null?m.next=z:_=z,m=z;x=y}if(m.next=null,f<<=1,!(v>1))break}u.head=_,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 _=this.staticsleep,m,x;c==null?(m=_.head,x=m.next,_.head=x,_.head==null&&(_.pushmod=!0)):(m=c.next,x=m.next,c.next=x,x==null&&(_.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,_.modified=!0,_.length--,_.pushmod=!0,h=x;continue}c=h,h=h.next}this.doForests(i),this.sleepArbiters()}}finally{this.midstep=!1}let l=null,r=this.callbackset_list.next;for(;r!=null;){let o=r;if(o.arbiters.head==null){let f=this.callbackset_list,v,E;l==null?(v=f.next,E=v.next,f.next=E,f.next==null&&(f.pushmod=!0)):(v=l.next,E=v.next,l.next=E,E==null&&(f.pushmod=!0)),v._inuse=!1,f.modified=!0,f.length--,f.pushmod=!0,r=E;let d=o;d.int1=d.int2=null,d.id=d.di=-1,d.freed=!0,d.next=cn.zpp_pool,cn.zpp_pool=d;continue}let a;a=!0;let p=o.arbiters.head;for(;p!=null;)if(p.elt.sleeping){p=p.next;continue}else{a=!1;break}let c=a,h=o.int1.cbSet,u=o.int2.cbSet,_=h.manager,m=null,y=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;y!=null;){let f=y.elt;if(f.a==h&&f.b==u||f.a==u&&f.b==h){m=f;break}y=y.next}if(m==null){let f;Ve.zpp_pool==null?f=new Ve:(f=Ve.zpp_pool,Ve.zpp_pool=f.next,f.next=null),f.zip_listeners=!0,gt.setlt(h,u)?(f.a=h,f.b=u):(f.a=u,f.b=h),m=f,h.cbpairs.add(m),u!=h&&u.cbpairs.add(m)}m.zip_listeners&&(m.zip_listeners=!1,m.__validate());let z=m.listeners.head;for(;z!=null;){let f=z.elt;if(f.event==6&&(!c||f.allowSleepingCallbacks)&&!o.empty_arb(f.itype)){let v=this.push_callback(f);v.event=6;let E=o.int1,d=o.int2,b,C=f.options1,P=E.cbTypes;if(C.nonemptyintersection(P,C.includes)&&!C.nonemptyintersection(P,C.excludes)){let g=f.options2,O=d.cbTypes;b=g.nonemptyintersection(O,g.includes)&&!g.nonemptyintersection(O,g.excludes)}else b=!1;b?(v.int1=E,v.int2=d):(v.int1=d,v.int2=E),v.set=o}z=z.next}l=r,r=r.next}for(;!this.callbacks.empty();){let o=this.callbacks.pop();o.listener.type==0?o.listener.body.handler(o.wrapper_body()):o.listener.type==1?o.listener.constraint.handler(o.wrapper_con()):o.listener.type==2&&o.listener.interaction.handleri(o.wrapper_int());let a=o;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=xt.zpp_pool,xt.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,r=2,o=!1,a=null,p=null,c=this.toiEvents.head;for(;c!=null;){let y=c.elt,z=y.s1.body,f=y.s2.body;if(z.sweepFrozen&&f.sweepFrozen)if(y.toi!=0&&Ze.testCollide_safe(y.s1,y.s2))y.toi=0;else{c=this.toiEvents.erase(p);let v=y;v.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=v;continue}if(y.frozen1!=z.sweepFrozen||y.frozen2!=f.sweepFrozen)if(y.kinematic){c=this.toiEvents.erase(p);let v=y;v.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=v;continue}else{if(y.frozen1=z.sweepFrozen,y.frozen2=f.sweepFrozen,y.frozen1){let v=y.s1;y.s1=y.s2,y.s2=v,y.frozen1=!1,y.frozen2=!0}if(mn.staticSweep(y,e,0,B._nape.Config.collisionSlopCCD),y.toi<0){c=this.toiEvents.erase(p);let v=y;v.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=v;continue}}y.toi>=0&&(y.toi<r||!o&&y.kinematic)&&(l=y,r=y.toi,o=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,z=y-h.sweepTime;if(z!=0){h.sweepTime=y;let v=z;if(h.posx+=h.velx*v,h.posy+=h.vely*v,h.angvel!=0){let E=h.sweep_angvel*z;if(h.rot+=E,E*E>1e-4)h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot);else{let d=E*E,b=1-.5*d,C=1-d*d/8,P=(b*h.axisx+E*h.axisy)*C;h.axisy=(b*h.axisy-E*h.axisx)*C,h.axisx=P}}}let f=l.s1;if(f.type==0)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 v=f.polygon,E=v.lverts.next,d=v.gverts.next;for(;d!=null;){let N=d,M=E;E=E.next,N.x=h.posx+(h.axisy*M.x-h.axisx*M.y),N.y=h.posy+(M.x*h.axisx+M.y*h.axisy),d=d.next}let b=v.edges.head,C=v.gverts.next,P=C;for(C=C.next;C!=null;){let N=C,M=b.elt;b=b.next,M.gnormx=h.axisy*M.lnormx-h.axisx*M.lnormy,M.gnormy=M.lnormx*h.axisx+M.lnormy*h.axisy,M.gprojection=h.posx*M.gnormx+h.posy*M.gnormy+M.lprojection,M.tp0=P.y*M.gnormx-P.x*M.gnormy,M.tp1=N.y*M.gnormx-N.x*M.gnormy,P=N,C=C.next}let g=v.gverts.next,O=b.elt;b=b.next,O.gnormx=h.axisy*O.lnormx-h.axisx*O.lnormy,O.gnormy=O.lnormx*h.axisx+O.lnormy*h.axisy,O.gprojection=h.posx*O.gnormx+h.posy*O.gnormy+O.lprojection,O.tp0=P.y*O.gnormx-P.x*O.gnormy,O.tp1=g.y*O.gnormx-g.x*O.gnormy}}if(!u.sweepFrozen){let y=n*e,z=y-u.sweepTime;if(z!=0){u.sweepTime=y;let v=z;if(u.posx+=u.velx*v,u.posy+=u.vely*v,u.angvel!=0){let E=u.sweep_angvel*z;if(u.rot+=E,E*E>1e-4)u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot);else{let d=E*E,b=1-.5*d,C=1-d*d/8,P=(b*u.axisx+E*u.axisy)*C;u.axisy=(b*u.axisy-E*u.axisx)*C,u.axisx=P}}}let f=l.s2;if(f.type==0)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 v=f.polygon,E=v.lverts.next,d=v.gverts.next;for(;d!=null;){let N=d,M=E;E=E.next,N.x=u.posx+(u.axisy*M.x-u.axisx*M.y),N.y=u.posy+(M.x*u.axisx+M.y*u.axisy),d=d.next}let b=v.edges.head,C=v.gverts.next,P=C;for(C=C.next;C!=null;){let N=C,M=b.elt;b=b.next,M.gnormx=u.axisy*M.lnormx-u.axisx*M.lnormy,M.gnormy=M.lnormx*u.axisx+M.lnormy*u.axisy,M.gprojection=u.posx*M.gnormx+u.posy*M.gnormy+M.lprojection,M.tp0=P.y*M.gnormx-P.x*M.gnormy,M.tp1=N.y*M.gnormx-N.x*M.gnormy,P=N,C=C.next}let g=v.gverts.next,O=b.elt;b=b.next,O.gnormx=u.axisy*O.lnormx-u.axisx*O.lnormy,O.gnormy=O.lnormx*u.axisx+O.lnormy*u.axisy,O.gprojection=u.posx*O.gnormx+u.posy*O.gnormy+O.lprojection,O.tp0=P.y*O.gnormx-P.x*O.gnormy,O.tp1=g.y*O.gnormx-g.x*O.gnormy}}let _=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==Ne.COL&&m.active&&(m.immState&1)!=0){let y=m.colarb,z=y.nx*y.c1.jnAcc-y.ny*y.c1.jtAcc,f=y.ny*y.c1.jnAcc+y.nx*y.c1.jtAcc,v=y.b1.imass;y.b1.velx-=z*v,y.b1.vely-=f*v,y.b1.angvel-=y.b1.iinertia*(f*y.c1.r1x-z*y.c1.r1y);let E=y.b2.imass;if(y.b2.velx+=z*E,y.b2.vely+=f*E,y.b2.angvel+=y.b2.iinertia*(f*y.c1.r2x-z*y.c1.r2y),y.hc2){let le=y.nx*y.c2.jnAcc-y.ny*y.c2.jtAcc,_e=y.ny*y.c2.jnAcc+y.nx*y.c2.jtAcc,ce=y.b1.imass;y.b1.velx-=le*ce,y.b1.vely-=_e*ce,y.b1.angvel-=y.b1.iinertia*(_e*y.c2.r1x-le*y.c2.r1y);let he=y.b2.imass;y.b2.velx+=le*he,y.b2.vely+=_e*he,y.b2.angvel+=y.b2.iinertia*(_e*y.c2.r2x-le*y.c2.r2y)}y.b2.angvel+=y.jrAcc*y.b2.iinertia,y.b1.angvel-=y.jrAcc*y.b1.iinertia;let d=m.colarb,b=d.k1x+d.b2.velx-d.c1.r2y*d.b2.angvel-(d.b1.velx-d.c1.r1y*d.b1.angvel),C=d.k1y+d.b2.vely+d.c1.r2x*d.b2.angvel-(d.b1.vely+d.c1.r1x*d.b1.angvel),P=(C*d.nx-b*d.ny+d.surfacex)*d.c1.tMass,g=d.c1.friction*d.c1.jnAcc,O=d.c1.jtAcc,N=O-P;N>g?N=g:N<-g&&(N=-g),P=N-O,d.c1.jtAcc=N;let M=-d.ny*P,k=d.nx*P;if(d.b2.velx+=M*d.b2.imass,d.b2.vely+=k*d.b2.imass,d.b1.velx-=M*d.b1.imass,d.b1.vely-=k*d.b1.imass,d.b2.angvel+=d.rt1b*P*d.b2.iinertia,d.b1.angvel-=d.rt1a*P*d.b1.iinertia,d.hc2){let le=d.k2x+d.b2.velx-d.c2.r2y*d.b2.angvel-(d.b1.velx-d.c2.r1y*d.b1.angvel),_e=d.k2y+d.b2.vely+d.c2.r2x*d.b2.angvel-(d.b1.vely+d.c2.r1x*d.b1.angvel);P=(_e*d.nx-le*d.ny+d.surfacex)*d.c2.tMass,g=d.c2.friction*d.c2.jnAcc,O=d.c2.jtAcc,N=O-P,N>g?N=g:N<-g&&(N=-g),P=N-O,d.c2.jtAcc=N,M=-d.ny*P,k=d.nx*P,d.b2.velx+=M*d.b2.imass,d.b2.vely+=k*d.b2.imass,d.b1.velx-=M*d.b1.imass,d.b1.vely-=k*d.b1.imass,d.b2.angvel+=d.rt2b*P*d.b2.iinertia,d.b1.angvel-=d.rt2a*P*d.b1.iinertia,b=d.k1x+d.b2.velx-d.c1.r2y*d.b2.angvel-(d.b1.velx-d.c1.r1y*d.b1.angvel),C=d.k1y+d.b2.vely+d.c1.r2x*d.b2.angvel-(d.b1.vely+d.c1.r1x*d.b1.angvel),le=d.k2x+d.b2.velx-d.c2.r2y*d.b2.angvel-(d.b1.velx-d.c2.r1y*d.b1.angvel),_e=d.k2y+d.b2.vely+d.c2.r2x*d.b2.angvel-(d.b1.vely+d.c2.r1x*d.b1.angvel);let ce=d.c1.jnAcc,he=d.c2.jnAcc,te=b*d.nx+C*d.ny+d.surfacey+d.c1.bounce-(d.Ka*ce+d.Kb*he),xe=le*d.nx+_e*d.ny+d.surfacey+d.c2.bounce-(d.Kb*ce+d.Kc*he),de=-(d.kMassa*te+d.kMassb*xe),me=-(d.kMassb*te+d.kMassc*xe);de>=0&&me>=0?(te=de-ce,xe=me-he,d.c1.jnAcc=de,d.c2.jnAcc=me):(de=-d.c1.nMass*te,de>=0&&d.Kb*de+xe>=0?(te=de-ce,xe=-he,d.c1.jnAcc=de,d.c2.jnAcc=0):(me=-d.c2.nMass*xe,me>=0&&d.Kb*me+te>=0?(te=-ce,xe=me-he,d.c1.jnAcc=0,d.c2.jnAcc=me):te>=0&&xe>=0?(te=-ce,xe=-he,d.c1.jnAcc=d.c2.jnAcc=0):(te=0,xe=0))),P=te+xe,M=d.nx*P,k=d.ny*P,d.b2.velx+=M*d.b2.imass,d.b2.vely+=k*d.b2.imass,d.b1.velx-=M*d.b1.imass,d.b1.vely-=k*d.b1.imass,d.b2.angvel+=(d.rn1b*te+d.rn2b*xe)*d.b2.iinertia,d.b1.angvel-=(d.rn1a*te+d.rn2a*xe)*d.b1.iinertia}else d.radius!=0&&(P=(d.b2.angvel-d.b1.angvel)*d.rMass,g=d.rfric*d.c1.jnAcc,O=d.jrAcc,d.jrAcc-=P,d.jrAcc>g?d.jrAcc=g:d.jrAcc<-g&&(d.jrAcc=-g),P=d.jrAcc-O,d.b2.angvel+=P*d.b2.iinertia,d.b1.angvel-=P*d.b1.iinertia),b=d.k1x+d.b2.velx-d.c1.r2y*d.b2.angvel-(d.b1.velx-d.c1.r1y*d.b1.angvel),C=d.k1y+d.b2.vely+d.c1.r2x*d.b2.angvel-(d.b1.vely+d.c1.r1x*d.b1.angvel),P=(d.c1.bounce+(d.nx*b+d.ny*C)+d.surfacey)*d.c1.nMass,O=d.c1.jnAcc,N=O-P,N<0&&(N=0),P=N-O,d.c1.jnAcc=N,M=d.nx*P,k=d.ny*P,d.b2.velx+=M*d.b2.imass,d.b2.vely+=k*d.b2.imass,d.b1.velx-=M*d.b1.imass,d.b1.vely-=k*d.b1.imass,d.b2.angvel+=d.rn1b*P*d.b2.iinertia,d.b1.angvel-=d.rn1a*P*d.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),R=(S*Z.nx-A*Z.ny+Z.surfacex)*Z.c1.tMass,j=Z.c1.friction*Z.c1.jnAcc,q=Z.c1.jtAcc,J=q-R;J>j?J=j:J<-j&&(J=-j),R=J-q,Z.c1.jtAcc=J;let G=-Z.ny*R,L=Z.nx*R;if(Z.b2.velx+=G*Z.b2.imass,Z.b2.vely+=L*Z.b2.imass,Z.b1.velx-=G*Z.b1.imass,Z.b1.vely-=L*Z.b1.imass,Z.b2.angvel+=Z.rt1b*R*Z.b2.iinertia,Z.b1.angvel-=Z.rt1a*R*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),_e=Z.k2y+Z.b2.vely+Z.c2.r2x*Z.b2.angvel-(Z.b1.vely+Z.c2.r1x*Z.b1.angvel);R=(_e*Z.nx-le*Z.ny+Z.surfacex)*Z.c2.tMass,j=Z.c2.friction*Z.c2.jnAcc,q=Z.c2.jtAcc,J=q-R,J>j?J=j:J<-j&&(J=-j),R=J-q,Z.c2.jtAcc=J,G=-Z.ny*R,L=Z.nx*R,Z.b2.velx+=G*Z.b2.imass,Z.b2.vely+=L*Z.b2.imass,Z.b1.velx-=G*Z.b1.imass,Z.b1.vely-=L*Z.b1.imass,Z.b2.angvel+=Z.rt2b*R*Z.b2.iinertia,Z.b1.angvel-=Z.rt2a*R*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),_e=Z.k2y+Z.b2.vely+Z.c2.r2x*Z.b2.angvel-(Z.b1.vely+Z.c2.r1x*Z.b1.angvel);let ce=Z.c1.jnAcc,he=Z.c2.jnAcc,te=A*Z.nx+S*Z.ny+Z.surfacey+Z.c1.bounce-(Z.Ka*ce+Z.Kb*he),xe=le*Z.nx+_e*Z.ny+Z.surfacey+Z.c2.bounce-(Z.Kb*ce+Z.Kc*he),de=-(Z.kMassa*te+Z.kMassb*xe),me=-(Z.kMassb*te+Z.kMassc*xe);de>=0&&me>=0?(te=de-ce,xe=me-he,Z.c1.jnAcc=de,Z.c2.jnAcc=me):(de=-Z.c1.nMass*te,de>=0&&Z.Kb*de+xe>=0?(te=de-ce,xe=-he,Z.c1.jnAcc=de,Z.c2.jnAcc=0):(me=-Z.c2.nMass*xe,me>=0&&Z.Kb*me+te>=0?(te=-ce,xe=me-he,Z.c1.jnAcc=0,Z.c2.jnAcc=me):te>=0&&xe>=0?(te=-ce,xe=-he,Z.c1.jnAcc=Z.c2.jnAcc=0):(te=0,xe=0))),R=te+xe,G=Z.nx*R,L=Z.ny*R,Z.b2.velx+=G*Z.b2.imass,Z.b2.vely+=L*Z.b2.imass,Z.b1.velx-=G*Z.b1.imass,Z.b1.vely-=L*Z.b1.imass,Z.b2.angvel+=(Z.rn1b*te+Z.rn2b*xe)*Z.b2.iinertia,Z.b1.angvel-=(Z.rn1a*te+Z.rn2a*xe)*Z.b1.iinertia}else Z.radius!=0&&(R=(Z.b2.angvel-Z.b1.angvel)*Z.rMass,j=Z.rfric*Z.c1.jnAcc,q=Z.jrAcc,Z.jrAcc-=R,Z.jrAcc>j?Z.jrAcc=j:Z.jrAcc<-j&&(Z.jrAcc=-j),R=Z.jrAcc-q,Z.b2.angvel+=R*Z.b2.iinertia,Z.b1.angvel-=R*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),R=(Z.c1.bounce+(Z.nx*A+Z.ny*S)+Z.surfacey)*Z.c1.nMass,q=Z.c1.jnAcc,J=q-R,J<0&&(J=0),R=J-q,Z.c1.jnAcc=J,G=Z.nx*R,L=Z.ny*R,Z.b2.velx+=G*Z.b2.imass,Z.b2.vely+=L*Z.b2.imass,Z.b1.velx-=G*Z.b1.imass,Z.b1.vely-=L*Z.b1.imass,Z.b2.angvel+=Z.rn1b*R*Z.b2.iinertia,Z.b1.angvel-=Z.rn1a*R*Z.b1.iinertia;let V=m.colarb,Y=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),H=($*V.nx-Y*V.ny+V.surfacex)*V.c1.tMass,X=V.c1.friction*V.c1.jnAcc,ee=V.c1.jtAcc,W=ee-H;W>X?W=X:W<-X&&(W=-X),H=W-ee,V.c1.jtAcc=W;let F=-V.ny*H,D=V.nx*H;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*H*V.b2.iinertia,V.b1.angvel-=V.rt1a*H*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),_e=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);H=(_e*V.nx-le*V.ny+V.surfacex)*V.c2.tMass,X=V.c2.friction*V.c2.jnAcc,ee=V.c2.jtAcc,W=ee-H,W>X?W=X:W<-X&&(W=-X),H=W-ee,V.c2.jtAcc=W,F=-V.ny*H,D=V.nx*H,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*H*V.b2.iinertia,V.b1.angvel-=V.rt2a*H*V.b1.iinertia,Y=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),_e=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);let ce=V.c1.jnAcc,he=V.c2.jnAcc,te=Y*V.nx+$*V.ny+V.surfacey+V.c1.bounce-(V.Ka*ce+V.Kb*he),xe=le*V.nx+_e*V.ny+V.surfacey+V.c2.bounce-(V.Kb*ce+V.Kc*he),de=-(V.kMassa*te+V.kMassb*xe),me=-(V.kMassb*te+V.kMassc*xe);de>=0&&me>=0?(te=de-ce,xe=me-he,V.c1.jnAcc=de,V.c2.jnAcc=me):(de=-V.c1.nMass*te,de>=0&&V.Kb*de+xe>=0?(te=de-ce,xe=-he,V.c1.jnAcc=de,V.c2.jnAcc=0):(me=-V.c2.nMass*xe,me>=0&&V.Kb*me+te>=0?(te=-ce,xe=me-he,V.c1.jnAcc=0,V.c2.jnAcc=me):te>=0&&xe>=0?(te=-ce,xe=-he,V.c1.jnAcc=V.c2.jnAcc=0):(te=0,xe=0))),H=te+xe,F=V.nx*H,D=V.ny*H,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*xe)*V.b2.iinertia,V.b1.angvel-=(V.rn1a*te+V.rn2a*xe)*V.b1.iinertia}else V.radius!=0&&(H=(V.b2.angvel-V.b1.angvel)*V.rMass,X=V.rfric*V.c1.jnAcc,ee=V.jrAcc,V.jrAcc-=H,V.jrAcc>X?V.jrAcc=X:V.jrAcc<-X&&(V.jrAcc=-X),H=V.jrAcc-ee,V.b2.angvel+=H*V.b2.iinertia,V.b1.angvel-=H*V.b1.iinertia),Y=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),H=(V.c1.bounce+(V.nx*Y+V.ny*$)+V.surfacey)*V.c1.nMass,ee=V.c1.jnAcc,W=ee-H,W<0&&(W=0),H=W-ee,V.c1.jnAcc=W,F=V.nx*H,D=V.ny*H,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*H*V.b2.iinertia,V.b1.angvel-=V.rn1a*H*V.b1.iinertia;let T=m.colarb,U=T.k1x+T.b2.velx-T.c1.r2y*T.b2.angvel-(T.b1.velx-T.c1.r1y*T.b1.angvel),Q=T.k1y+T.b2.vely+T.c1.r2x*T.b2.angvel-(T.b1.vely+T.c1.r1x*T.b1.angvel),K=(Q*T.nx-U*T.ny+T.surfacex)*T.c1.tMass,ie=T.c1.friction*T.c1.jnAcc,oe=T.c1.jtAcc,se=oe-K;se>ie?se=ie:se<-ie&&(se=-ie),K=se-oe,T.c1.jtAcc=se;let ne=-T.ny*K,ae=T.nx*K;if(T.b2.velx+=ne*T.b2.imass,T.b2.vely+=ae*T.b2.imass,T.b1.velx-=ne*T.b1.imass,T.b1.vely-=ae*T.b1.imass,T.b2.angvel+=T.rt1b*K*T.b2.iinertia,T.b1.angvel-=T.rt1a*K*T.b1.iinertia,T.hc2){let le=T.k2x+T.b2.velx-T.c2.r2y*T.b2.angvel-(T.b1.velx-T.c2.r1y*T.b1.angvel),_e=T.k2y+T.b2.vely+T.c2.r2x*T.b2.angvel-(T.b1.vely+T.c2.r1x*T.b1.angvel);K=(_e*T.nx-le*T.ny+T.surfacex)*T.c2.tMass,ie=T.c2.friction*T.c2.jnAcc,oe=T.c2.jtAcc,se=oe-K,se>ie?se=ie:se<-ie&&(se=-ie),K=se-oe,T.c2.jtAcc=se,ne=-T.ny*K,ae=T.nx*K,T.b2.velx+=ne*T.b2.imass,T.b2.vely+=ae*T.b2.imass,T.b1.velx-=ne*T.b1.imass,T.b1.vely-=ae*T.b1.imass,T.b2.angvel+=T.rt2b*K*T.b2.iinertia,T.b1.angvel-=T.rt2a*K*T.b1.iinertia,U=T.k1x+T.b2.velx-T.c1.r2y*T.b2.angvel-(T.b1.velx-T.c1.r1y*T.b1.angvel),Q=T.k1y+T.b2.vely+T.c1.r2x*T.b2.angvel-(T.b1.vely+T.c1.r1x*T.b1.angvel),le=T.k2x+T.b2.velx-T.c2.r2y*T.b2.angvel-(T.b1.velx-T.c2.r1y*T.b1.angvel),_e=T.k2y+T.b2.vely+T.c2.r2x*T.b2.angvel-(T.b1.vely+T.c2.r1x*T.b1.angvel);let ce=T.c1.jnAcc,he=T.c2.jnAcc,te=U*T.nx+Q*T.ny+T.surfacey+T.c1.bounce-(T.Ka*ce+T.Kb*he),xe=le*T.nx+_e*T.ny+T.surfacey+T.c2.bounce-(T.Kb*ce+T.Kc*he),de=-(T.kMassa*te+T.kMassb*xe),me=-(T.kMassb*te+T.kMassc*xe);de>=0&&me>=0?(te=de-ce,xe=me-he,T.c1.jnAcc=de,T.c2.jnAcc=me):(de=-T.c1.nMass*te,de>=0&&T.Kb*de+xe>=0?(te=de-ce,xe=-he,T.c1.jnAcc=de,T.c2.jnAcc=0):(me=-T.c2.nMass*xe,me>=0&&T.Kb*me+te>=0?(te=-ce,xe=me-he,T.c1.jnAcc=0,T.c2.jnAcc=me):te>=0&&xe>=0?(te=-ce,xe=-he,T.c1.jnAcc=T.c2.jnAcc=0):(te=0,xe=0))),K=te+xe,ne=T.nx*K,ae=T.ny*K,T.b2.velx+=ne*T.b2.imass,T.b2.vely+=ae*T.b2.imass,T.b1.velx-=ne*T.b1.imass,T.b1.vely-=ae*T.b1.imass,T.b2.angvel+=(T.rn1b*te+T.rn2b*xe)*T.b2.iinertia,T.b1.angvel-=(T.rn1a*te+T.rn2a*xe)*T.b1.iinertia}else T.radius!=0&&(K=(T.b2.angvel-T.b1.angvel)*T.rMass,ie=T.rfric*T.c1.jnAcc,oe=T.jrAcc,T.jrAcc-=K,T.jrAcc>ie?T.jrAcc=ie:T.jrAcc<-ie&&(T.jrAcc=-ie),K=T.jrAcc-oe,T.b2.angvel+=K*T.b2.iinertia,T.b1.angvel-=K*T.b1.iinertia),U=T.k1x+T.b2.velx-T.c1.r2y*T.b2.angvel-(T.b1.velx-T.c1.r1y*T.b1.angvel),Q=T.k1y+T.b2.vely+T.c1.r2x*T.b2.angvel-(T.b1.vely+T.c1.r1x*T.b1.angvel),K=(T.c1.bounce+(T.nx*U+T.ny*Q)+T.surfacey)*T.c1.nMass,oe=T.c1.jnAcc,se=oe-K,se<0&&(se=0),K=se-oe,T.c1.jnAcc=se,ne=T.nx*K,ae=T.ny*K,T.b2.velx+=ne*T.b2.imass,T.b2.vely+=ae*T.b2.imass,T.b1.velx-=ne*T.b1.imass,T.b1.vely-=ae*T.b1.imass,T.b2.angvel+=T.rn1b*K*T.b2.iinertia,T.b1.angvel-=T.rn1a*K*T.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==Ne.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 x=l;x.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=x}for(;this.toiEvents.head!=null;){let r=this.toiEvents.pop_unsafe();r.next=B._zpp.geom.ZPP_ToiEvent.zpp_pool,B._zpp.geom.ZPP_ToiEvent.zpp_pool=r}let s=this.kinematics.head;for(;s!=null;){let l=s.elt,r=e-l.sweepTime;if(r!=0){l.sweepTime=e;let o=r;if(l.posx+=l.velx*o,l.posy+=l.vely*o,l.angvel!=0){let a=l.sweep_angvel*r;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 r=e-l.sweepTime;if(r!=0){l.sweepTime=e;let o=r;if(l.posx+=l.velx*o,l.posy+=l.vely*o,l.angvel!=0){let a=l.sweep_angvel*r;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,_;if(c)_=!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 x=m==null?null:m.group,y;if(x==null)y=!1;else{let z=t;for(;z!=null&&z.group==null;)z.ishape!=null?z=z.ishape.body:z.icompound!=null?z=z.icompound.compound:z=z.ibody.compound;let f=z==null?null:z.group;if(f==null)y=!1;else{let v=!1;for(;x!=null&&f!=null;){if(x==f){v=x.ignore;break}x.depth<f.depth?f=f.group:x=x.group}y=v}}_=!y}if(_){let m;if(e.sensorEnabled||t.sensorEnabled){let x=e.filter,y=t.filter;m=(x.sensorMask&y.sensorGroup)!=0&&(y.sensorMask&x.sensorGroup)!=0}else m=!1;if(m)u=2;else{let x;if(e.fluidEnabled||t.fluidEnabled){let y=e.filter,z=t.filter;x=(y.fluidMask&z.fluidGroup)!=0&&(z.fluidMask&y.fluidGroup)!=0}else x=!1;if(x&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0))u=0;else{let y=e.filter,z=t.filter;u=(y.collisionMask&z.collisionGroup)!=0&&(z.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 r=e.body,o=t.body;if(n||r.bullet||o.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=r.type==3||o.type==3;if(n&&!p)e.body.type!=2?(a.s2=e,a.s1=t):(a.s1=e,a.s2=t),a.kinematic=!1,mn.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}mn.staticSweep(a,this.pre_dt,0,B._nape.Config.collisionSlopCCD)}else mn.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,r=l.bodies.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}let o=l.compounds.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,r=i.ishape!=null?i.ishape:null,o=l.arbiters.head;for(;o!=null;){let a=o.elt;if(a.present==0){o=o.next;continue}if(r!=null&&!(a.ws1==r||a.ws2==r)){o=o.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 _=B._zpp.phys.ZPP_Interactor.get(c,u);if(_!=null){for(;_.arbiters.head!=null;){let m=_.arbiters.pop_unsafe();m.present--}this.remove_callbackset(_)}h=h.next}p=p.next}o=o.next}}}}nullInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,s=n.bodies.head;for(;s!=null;){let l=s.elt;this.nullInteractorType(l,t),s=s.next}let i=n.compounds.head;for(;i!=null;){let l=i.elt;this.nullInteractorType(l,t),i=i.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,s=e.ishape!=null?e.ishape:null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(l.present==0){i=i.next;continue}if(s!=null&&!(l.ws1==s||l.ws2==s)){i=i.next;continue}this.MRCA_chains(l.ws1,l.ws2);let r=this.mrca1.head;for(;r!=null;){let o=r.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(o!=t&&p!=t){a=a.next;continue}let c=B._zpp.phys.ZPP_Interactor.get(o,p);c!=null&&(l.present--,c.remove_arb(l),c.arbiters.head==null&&this.remove_callbackset(c)),a=a.next}r=r.next}i=i.next}}}freshListenerType(e,t){let n=new B._zpp.util.ZNPList_ZPP_Interactor,s=e.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next}if(e!=t){let i=t.interactors.head;for(;i!=null;){let l=i.elt;n.add(l),i=i.next}}for(;n.head!=null;){let i=n.pop_unsafe();if(i.icompound!=null){let l=i.icompound,r=l.bodies.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}let o=l.compounds.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,r=i.ishape!=null?i.ishape:null,o=l.arbiters.head;for(;o!=null;){let a=o.elt;if(!a.presentable){o=o.next;continue}if(r!=null&&!(a.ws1==r||a.ws2==r)){o=o.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 _=B._zpp.phys.ZPP_Interactor.get(c,u);_==null&&(_=cn.get(c,u),this.add_callbackset(_));let m,x;x=!1;let y=_.arbiters.head;for(;y!=null;){if(y.elt==a){x=!0;break}y=y.next}if(x)m=!1;else{let z=_.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 v=f;v.next=z.head,z.head=v,z.modified=!0,z.length++,m=!0}m&&a.present++,h=h.next}p=p.next}o=o.next}}}}freshInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,s=n.bodies.head;for(;s!=null;){let l=s.elt;this.freshInteractorType(l,t),s=s.next}let i=n.compounds.head;for(;i!=null;){let l=i.elt;this.freshInteractorType(l,t),i=i.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,s=e.ishape!=null?e.ishape:null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(!l.presentable){i=i.next;continue}if(s!=null&&!(l.ws1==s||l.ws2==s)){i=i.next;continue}this.MRCA_chains(l.ws1,l.ws2);let r=this.mrca1.head;for(;r!=null;){let o=r.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(o!=t&&p!=t){a=a.next;continue}let c=o.cbSet,h=p.cbSet;c.validate(),h.validate();let u=c.manager,_=null,x=(c.cbpairs.length<h.cbpairs.length?c.cbpairs:h.cbpairs).head;for(;x!=null;){let y=x.elt;if(y.a==c&&y.b==h||y.a==h&&y.b==c){_=y;break}x=x.next}if(_==null){let y;Ve.zpp_pool==null?y=new Ve:(y=Ve.zpp_pool,Ve.zpp_pool=y.next,y.next=null),y.zip_listeners=!0,gt.setlt(c,h)?(y.a=c,y.b=h):(y.a=h,y.b=c),_=y,c.cbpairs.add(_),h!=c&&h.cbpairs.add(_)}if(_.zip_listeners&&(_.zip_listeners=!1,_.__validate()),_.listeners.head!=null){let y=B._zpp.phys.ZPP_Interactor.get(o,p);y==null&&(y=cn.get(o,p),this.add_callbackset(y));let z,f;f=!1;let v=y.arbiters.head;for(;v!=null;){if(v.elt==l){f=!0;break}v=v.next}if(f)z=!1;else{let E=y.arbiters,d;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?d=new B._zpp.util.ZNPNode_ZPP_Arbiter:(d=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=d.next,d.next=null),d.elt=l;let b=d;b.next=E.head,E.head=b,E.modified=!0,E.length++,z=!0}z&&l.present++}a=a.next}r=r.next}i=i.next}}}wakeCompound(e){let t=e.bodies.head;for(;t!=null;){let l=t.elt;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!1)),t=t.next}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.wake_constraint(i),n=n.next}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.wakeCompound(i),s=s.next}}wakeIsland(e){for(;e.comps.head!=null;){let n=e.comps.pop_unsafe();if(n.waket=this.stamp+(this.midstep?0:1),n.isBody){let s=n.body;this.live.add(s);let i=s.arbiters.head;for(;i!=null;){let l=i.elt;if(l.sleeping)if(l.sleeping=!1,l.up_stamp+=this.stamp-l.sleep_stamp,l.type==Ne.COL){let r=l.colarb;if(r.stat){let o=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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}else{let o=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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}}else if(l.type==Ne.FLUID){let r=this.f_arbiters,o=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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}else{let r=this.s_arbiters,o=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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}i=i.next}if(this.bodyCbWake(s),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0,s.type!=1){let l=s.shapes.head;for(;l!=null;){let r=l.elt;r.node!=null&&this.bphase.sync(r),l=l.next}}}else{let s=n.constraint,i=this.live_constraints,l;B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?l=new B._zpp.util.ZNPNode_ZPP_Constraint:(l=B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=l.next,l.next=null),l.elt=s;let r=l;r.next=i.head,i.head=r,i.modified=!0,i.length++,this.constraintCbWake(s),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0}}let t=e;t.next=wt.zpp_pool,wt.zpp_pool=t}non_inlined_wake(e,t){t==null&&(t=!1);let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,t))}really_wake(e,t){if(t==null&&(t=!1),e.component.island==null){if(e.component.sleeping=!1,e.type==3||e.type==1){let i=this.staticsleep,l;B._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?l=new B._zpp.util.ZNPNode_ZPP_Body:(l=B._zpp.util.ZNPNode_ZPP_Body.zpp_pool,B._zpp.util.ZNPNode_ZPP_Body.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;r.next=i.head,i.head=r,i.modified=!0,i.length++}else{let i=this.live,l;B._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?l=new B._zpp.util.ZNPNode_ZPP_Body:(l=B._zpp.util.ZNPNode_ZPP_Body.zpp_pool,B._zpp.util.ZNPNode_ZPP_Body.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;r.next=i.head,i.head=r,i.modified=!0,i.length++}let n=e.constraints.head;for(;n!=null;){let i=n.elt;i.space==this&&this.wake_constraint(i),n=n.next}let s=e.arbiters.head;for(;s!=null;){let i=s.elt;if(i.sleeping)if(i.sleeping=!1,i.up_stamp+=this.stamp+(this.midstep?0:1)-i.sleep_stamp,i.type==Ne.COL){let l=i.colarb;if(l.stat){let r=this.c_arbiters_true,o;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(o=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=o.next,o.next=null),o.elt=l;let a=o;a.next=r.head,r.head=a,r.modified=!0,r.length++}else{let r=this.c_arbiters_false,o;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(o=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=o.next,o.next=null),o.elt=l;let a=o;a.next=r.head,r.head=a,r.modified=!0,r.length++}}else if(i.type==Ne.FLUID){let l=this.f_arbiters,r=i.fluidarb,o;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(o=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=o.next,o.next=null),o.elt=r;let a=o;a.next=l.head,l.head=a,l.modified=!0,l.length++}else{let l=this.s_arbiters,r=i.sensorarb,o;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(o=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=o.next,o.next=null),o.elt=r;let a=o;a.next=l.head,l.head=a,l.modified=!0,l.length++}if(i.type!=Ne.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 o=i.b1.component,a=null;for(;o!=o.parent;){let p=o.parent;o.parent=a,a=o,o=p}for(;a!=null;){let p=a.parent;a.parent=o,a=p}l=o}let r;if(i.b2.component==i.b2.component.parent)r=i.b2.component;else{let o=i.b2.component,a=null;for(;o!=o.parent;){let p=o.parent;o.parent=a,a=o,o=p}for(;a!=null;){let p=a.parent;a.parent=o,a=p}r=o}l!=r&&(l.rank<r.rank?l.parent=r:l.rank>r.rank?r.parent=l:(r.parent=l,l.rank++))}t=t.next}let n=this.f_arbiters.head;for(;n!=null;){let i=n.elt;if(!i.cleared&&i.up_stamp==this.stamp&&(i.immState&1)!=0&&i.b1.type==2&&i.b2.type==2){let l;if(i.b1.component==i.b1.component.parent)l=i.b1.component;else{let o=i.b1.component,a=null;for(;o!=o.parent;){let p=o.parent;o.parent=a,a=o,o=p}for(;a!=null;){let p=a.parent;a.parent=o,a=p}l=o}let r;if(i.b2.component==i.b2.component.parent)r=i.b2.component;else{let o=i.b2.component,a=null;for(;o!=o.parent;){let p=o.parent;o.parent=a,a=o,o=p}for(;a!=null;){let p=a.parent;a.parent=o,a=p}r=o}l!=r&&(l.rank<r.rank?l.parent=r:l.rank>r.rank?r.parent=l:(r.parent=l,l.rank++))}n=n.next}let s=this.live_constraints.head;for(;s!=null;)s.elt.forest(),s=s.next;for(;this.live.head!=null;){let i=this.live,l=i.head.elt;i.pop();let r=l,o=r.component,a;if(o==o.parent)a=o;else{let _=o,m=null;for(;_!=_.parent;){let x=_.parent;_.parent=m,m=_,_=x}for(;m!=null;){let x=m.parent;m.parent=_,m=x}a=_}if(a.island==null){wt.zpp_pool==null?a.island=new wt:(a.island=wt.zpp_pool,wt.zpp_pool=a.island.next,a.island.next=null),a.island.waket=0;let _=this.islands,m=a.island;m._inuse=!0;let x=m;x.next=_.next,_.next=x,_.modified=!0,_.length++,a.island.sleep=!0}o.island=a.island;let p=o.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=o;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++;let u=r.atRest(e);o.island.sleep=o.island.sleep&&u,o.waket>o.island.waket&&(o.island.waket=o.waket)}for(;this.live_constraints.head!=null;){let i=this.live_constraints,l=i.head.elt;i.pop();let o=l.component,a;if(o==o.parent)a=o;else{let u=o,_=null;for(;u!=u.parent;){let m=u.parent;u.parent=_,_=u,u=m}for(;_!=null;){let m=_.parent;_.parent=u,_=m}a=u}o.island=a.island;let p=o.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=o;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++,o.waket>o.island.waket&&(o.island.waket=o.waket)}for(;this.islands.next!=null;){let i=this.islands,l=i.next;i.pop();let r=l;if(this.deterministic&&this._sortLinkedList(r.comps,o=>o.isBody?o.body.id:o.constraint.id+1e9),r.sleep){let o=r.comps.head;for(;o!=null;){let a=o.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}o=o.next}}else{for(;r.comps.head!=null;){let a=r.comps,p=a.head.elt;a.pop();let c=p;if(c.waket=r.waket,c.isBody){let h=this.live,u=c.body,_;B._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_Body:(_=B._zpp.util.ZNPNode_ZPP_Body.zpp_pool,B._zpp.util.ZNPNode_ZPP_Body.zpp_pool=_.next,_.next=null),_.elt=u;let m=_;m.next=h.head,h.head=m,h.modified=!0,h.length++}else{let h=this.live_constraints,u=c.constraint,_;B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?_=new B._zpp.util.ZNPNode_ZPP_Constraint:(_=B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,B._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=_.next,_.next=null),_.elt=u;let m=_;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 o=r;o.next=wt.zpp_pool,wt.zpp_pool=o}}}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 _,m;e==null?(_=t.head,m=_.next,t.head=m,t.head==null&&(t.pushmod=!0)):(_=e.next,m=_.next,e.next=m,m==null&&(t.pushmod=!0));let x=_;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=x,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,r=l.head,o=!1;for(o&&r==null&&(o=!1,l=null,i=null);r!=null;){let u=r.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=!0;let _,m;i==null?(_=l.head,m=_.next,l.head=m,l.head==null&&(l.pushmod=!0)):(_=i.next,m=_.next,i.next=m,m==null&&(l.pushmod=!0));let x=_;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,r=m,o&&r==null&&(o=!1,l=null,i=null);continue}i=r,r=r.next,o&&r==null&&(o=!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 _,m;a==null?(_=p.head,m=_.next,p.head=m,p.head==null&&(p.pushmod=!0)):(_=a.next,m=_.next,a.next=m,m==null&&(p.pushmod=!0));let x=_;x.elt=null,x.next=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=x,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 r=s.circle;if(r.zip_worldCOM&&r.body!=null){if(r.zip_worldCOM=!1,r.zip_localCOM){if(r.zip_localCOM=!1,r.type==1){let c=r.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let h=1;c.localCOMx+=c.lverts.next.next.x*h,c.localCOMy+=c.lverts.next.next.y*h;let u=.5;c.localCOMx*=u,c.localCOMy*=u}else{c.localCOMx=0,c.localCOMy=0;let h=0,u=c.lverts.next,_=u;u=u.next;let m=u;for(u=u.next;u!=null;){let E=u;h+=m.x*(E.y-_.y);let d=E.y*m.x-E.x*m.y;c.localCOMx+=(m.x+E.x)*d,c.localCOMy+=(m.y+E.y)*d,_=m,m=E,u=u.next}u=c.lverts.next;let x=u;h+=m.x*(x.y-_.y);let y=x.y*m.x-x.x*m.y;c.localCOMx+=(m.x+x.x)*y,c.localCOMy+=(m.y+x.y)*y,_=m,m=x,u=u.next;let z=u;h+=m.x*(z.y-_.y);let f=z.y*m.x-z.x*m.y;c.localCOMx+=(m.x+z.x)*f,c.localCOMy+=(m.y+z.y)*f,h=1/(3*h);let v=h;c.localCOMx*=v,c.localCOMy*=v}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let p=r.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),r.worldCOMx=r.body.posx+(r.body.axisy*r.localCOMx-r.body.axisx*r.localCOMy),r.worldCOMy=r.body.posy+(r.localCOMx*r.body.axisx+r.localCOMy*r.body.axisy)}let o=r.radius,a=r.radius;r.aabb.minx=r.worldCOMx-o,r.aabb.miny=r.worldCOMy-a,r.aabb.maxx=r.worldCOMx+o,r.aabb.maxy=r.worldCOMy+a}else{let r=s.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let p=r.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=r.lverts.next,h=r.gverts.next;for(;h!=null;){let u=h,_=c;c=c.next,u.x=r.body.posx+(r.body.axisy*_.x-r.body.axisx*_.y),u.y=r.body.posy+(_.x*r.body.axisx+_.y*r.body.axisy),h=h.next}}if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let o=r.gverts.next;r.aabb.minx=o.x,r.aabb.miny=o.y,r.aabb.maxx=o.x,r.aabb.maxy=o.y;let a=r.gverts.next.next;for(;a!=null;){let p=a;p.x<r.aabb.minx&&(r.aabb.minx=p.x),p.x>r.aabb.maxx&&(r.aabb.maxx=p.x),p.y<r.aabb.miny&&(r.aabb.miny=p.y),p.y>r.aabb.maxy&&(r.aabb.maxy=p.y),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(I.ValidationResult_VALID==null&&(I.internal=!0,I.ValidationResult_VALID=new B._nape.shape.ValidationResult,I.internal=!1),i!=I.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+n.polygon.outer.toString()+" is invalid : "+i.toString());let l=n.polygon;if(l.zip_gaxi&&l.body!=null){l.zip_gaxi=!1,l.validate_laxi();let r=l.body;if(r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let u=l.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let _=l.lverts.next,m=l.gverts.next;for(;m!=null;){let x=m,y=_;_=_.next,x.x=l.body.posx+(l.body.axisy*y.x-l.body.axisx*y.y),x.y=l.body.posy+(y.x*l.body.axisx+y.y*l.body.axisy),m=m.next}}let o=l.edges.head,a=l.gverts.next,p=a;for(a=a.next;a!=null;){let u=a,_=o.elt;o=o.next,_.gp0=p,_.gp1=u,_.gnormx=l.body.axisy*_.lnormx-l.body.axisx*_.lnormy,_.gnormy=_.lnormx*l.body.axisx+_.lnormy*l.body.axisy,_.gprojection=l.body.posx*_.gnormx+l.body.posy*_.gnormy+_.lprojection,_.wrap_gnorm!=null&&(_.wrap_gnorm.zpp_inner.x=_.gnormx,_.wrap_gnorm.zpp_inner.y=_.gnormy),_.tp0=_.gp0.y*_.gnormx-_.gp0.x*_.gnormy,_.tp1=_.gp1.y*_.gnormx-_.gp1.x*_.gnormy,p=u,a=a.next}let c=l.gverts.next,h=o.elt;o=o.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 o=l.elt;if(o.type==1){let a=o.polygon;a.zip_sanitation&&(a.zip_sanitation=!1,a.splice_collinear_real());let p=o.polygon.valid();if(I.ValidationResult_VALID==null&&(I.internal=!0,I.ValidationResult_VALID=new B._nape.shape.ValidationResult,I.internal=!1),p!=I.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+o.polygon.outer.toString()+" is invalid : "+p.toString());let c=o.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 z=c.body;z.zip_axis&&(z.zip_axis=!1,z.axisx=Math.sin(z.rot),z.axisy=Math.cos(z.rot));let f=c.lverts.next,v=c.gverts.next;for(;v!=null;){let E=v,d=f;f=f.next,E.x=c.body.posx+(c.body.axisy*d.x-c.body.axisx*d.y),E.y=c.body.posy+(d.x*c.body.axisx+d.y*c.body.axisy),v=v.next}}let u=c.edges.head,_=c.gverts.next,m=_;for(_=_.next;_!=null;){let z=_,f=u.elt;u=u.next,f.gp0=m,f.gp1=z,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=z,_=_.next}let x=c.gverts.next,y=u.elt;u=u.next,y.gp0=m,y.gp1=x,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}}o.validate_sweepRadius(),o.sweepRadius>i.sweepRadius&&(i.sweepRadius=o.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 o=i.shapes.head;for(;o!=null;){let a=o.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 x=h.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 y=1;x.localCOMx+=x.lverts.next.next.x*y,x.localCOMy+=x.lverts.next.next.y*y;let z=.5;x.localCOMx*=z,x.localCOMy*=z}else{x.localCOMx=0,x.localCOMy=0;let y=0,z=x.lverts.next,f=z;z=z.next;let v=z;for(z=z.next;z!=null;){let g=z;y+=v.x*(g.y-f.y);let O=g.y*v.x-g.x*v.y;x.localCOMx+=(v.x+g.x)*O,x.localCOMy+=(v.y+g.y)*O,f=v,v=g,z=z.next}z=x.lverts.next;let E=z;y+=v.x*(E.y-f.y);let d=E.y*v.x-E.x*v.y;x.localCOMx+=(v.x+E.x)*d,x.localCOMy+=(v.y+E.y)*d,f=v,v=E,z=z.next;let b=z;y+=v.x*(b.y-f.y);let C=b.y*v.x-b.x*v.y;x.localCOMx+=(v.x+b.x)*C,x.localCOMy+=(v.y+b.y)*C,y=1/(3*y);let P=y;x.localCOMx*=P,x.localCOMy*=P}}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,_=h.radius;h.aabb.minx=h.worldCOMx-u,h.aabb.miny=h.worldCOMy-_,h.aabb.maxx=h.worldCOMx+u,h.aabb.maxy=h.worldCOMy+_}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 x=h.lverts.next,y=h.gverts.next;for(;y!=null;){let z=y,f=x;x=x.next,z.x=h.body.posx+(h.body.axisy*f.x-h.body.axisx*f.y),z.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 _=h.gverts.next.next;for(;_!=null;){let m=_;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),_=_.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),o=o.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 o=i.cbSet.bodylisteners.head;for(;o!=null;){let a=o.elt;if(a.event!=2){o=o.next;continue}let p=this.push_callback(a);p.event=2,p.body=i,o=o.next}}i.component.woken=!1;let r=i.shapes.head;for(;r!=null;){let o=r.elt;this.bphase.sync(o),r=r.next}t=t.next}let n=this.kinematics.head;for(;n!=null;){let i=n.elt;i.sweepRadius=0;let l=i.shapes.head;for(;l!=null;){let o=l.elt;if(o.type==1){let a=o.polygon;a.zip_sanitation&&(a.zip_sanitation=!1,a.splice_collinear_real());let p=o.polygon.valid();if(I.ValidationResult_VALID==null&&(I.internal=!0,I.ValidationResult_VALID=new B._nape.shape.ValidationResult,I.internal=!1),p!=I.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+o.polygon.outer.toString()+" is invalid : "+p.toString());let c=o.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 z=c.body;z.zip_axis&&(z.zip_axis=!1,z.axisx=Math.sin(z.rot),z.axisy=Math.cos(z.rot));let f=c.lverts.next,v=c.gverts.next;for(;v!=null;){let E=v,d=f;f=f.next,E.x=c.body.posx+(c.body.axisy*d.x-c.body.axisx*d.y),E.y=c.body.posy+(d.x*c.body.axisx+d.y*c.body.axisy),v=v.next}}let u=c.edges.head,_=c.gverts.next,m=_;for(_=_.next;_!=null;){let z=_,f=u.elt;u=u.next,f.gp0=m,f.gp1=z,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=z,_=_.next}let x=c.gverts.next,y=u.elt;u=u.next,y.gp0=m,y.gp1=x,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}}o.validate_sweepRadius(),o.sweepRadius>i.sweepRadius&&(i.sweepRadius=o.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 o=i.shapes.head;for(;o!=null;){let a=o.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 x=h.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 y=1;x.localCOMx+=x.lverts.next.next.x*y,x.localCOMy+=x.lverts.next.next.y*y;let z=.5;x.localCOMx*=z,x.localCOMy*=z}else{x.localCOMx=0,x.localCOMy=0;let y=0,z=x.lverts.next,f=z;z=z.next;let v=z;for(z=z.next;z!=null;){let g=z;y+=v.x*(g.y-f.y);let O=g.y*v.x-g.x*v.y;x.localCOMx+=(v.x+g.x)*O,x.localCOMy+=(v.y+g.y)*O,f=v,v=g,z=z.next}z=x.lverts.next;let E=z;y+=v.x*(E.y-f.y);let d=E.y*v.x-E.x*v.y;x.localCOMx+=(v.x+E.x)*d,x.localCOMy+=(v.y+E.y)*d,f=v,v=E,z=z.next;let b=z;y+=v.x*(b.y-f.y);let C=b.y*v.x-b.x*v.y;x.localCOMx+=(v.x+b.x)*C,x.localCOMy+=(v.y+b.y)*C,y=1/(3*y);let P=y;x.localCOMx*=P,x.localCOMy*=P}}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,_=h.radius;h.aabb.minx=h.worldCOMx-u,h.aabb.miny=h.worldCOMy-_,h.aabb.maxx=h.worldCOMx+u,h.aabb.maxy=h.worldCOMy+_}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 x=h.lverts.next,y=h.gverts.next;for(;y!=null;){let z=y,f=x;x=x.next,z.x=h.body.posx+(h.body.axisy*f.x-h.body.axisx*f.y),z.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 _=h.gverts.next.next;for(;_!=null;){let m=_;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),_=_.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),o=o.next}}i.validate_worldCOM()}if(i.validate_gravMass(),i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),!i.nomove&&i.type==2&&i.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!i.norotate&&i.type==2&&i.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");let r=i.shapes.head;for(;r!=null;){let o=r.elt;this.bphase.sync(o),r=r.next}n=n.next}let s=this.live_constraints.head;for(;s!=null;){let i=s.elt;if(i.active){if(i.validate(),i.component.woken&&i.cbSet!=null){let l=i.cbSet.conlisteners.head;for(;l!=null;){let r=l.elt;if(r.event!=2){l=l.next;continue}let o=this.push_callback(r);o.event=2,o.constraint=i,l=l.next}}i.component.woken=!1}s=s.next}}updateVel(e){let t=null,n=1-e*this.global_lin_drag,s=1-e*this.global_ang_drag,i=this.live.head;for(;i!=null;){let l=i.elt;if(l.smass!=0){let r=e*l.imass;l.velx=n*l.velx+(l.forcex+this.gravityx*l.gravMass)*r,l.vely=n*l.vely+(l.forcey+this.gravityy*l.gravMass)*r}if(l.sinertia!=0){let r=0,o=0;r=l.worldCOMx-l.posx,o=l.worldCOMy-l.posy;let a=l.torque+(this.gravityy*r-this.gravityx*o)*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 r=l;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let o=i.sweep_angvel*l;if(i.rot+=o,o*o>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let a=o*o,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+o*i.axisy)*c;i.axisy=(p*i.axisy-o*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let r=B._nape.Config.staticCCDLinearThreshold*i.sweepRadius,o=B._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>r*r||i.angvel*i.angvel*e*e>o*o||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,_=u.minx,m=u.miny,x=u.maxx,y=u.maxy,z=a*e*h.sweepCoef*.008333333333333333|0;z>8&&(z=8);let f=a*e/z,v=e-i.sweepTime;if(v!=0){i.sweepTime=e;let b=v;if(i.posx+=i.velx*b,i.posy+=i.vely*b,i.angvel!=0){let C=i.sweep_angvel*v;if(i.rot+=C,C*C>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let P=C*C,g=1-.5*P,O=1-P*P/8,N=(g*i.axisx+C*i.axisy)*O;i.axisy=(g*i.axisy-C*i.axisx)*O,i.axisx=N}}}if(h.type==0){let b=h.circle;b.worldCOMx=b.body.posx+(b.body.axisy*b.localCOMx-b.body.axisx*b.localCOMy),b.worldCOMy=b.body.posy+(b.localCOMx*b.body.axisx+b.localCOMy*b.body.axisy),b.aabb.minx=b.worldCOMx-b.radius,b.aabb.miny=b.worldCOMy-b.radius,b.aabb.maxx=b.worldCOMx+b.radius,b.aabb.maxy=b.worldCOMy+b.radius}else{let b=h.polygon,C=b.lverts.next,P=b.gverts.next,g=C;C=C.next,P.x=b.body.posx+(b.body.axisy*g.x-b.body.axisx*g.y),P.y=b.body.posy+(g.x*b.body.axisx+g.y*b.body.axisy),b.aabb.minx=P.x,b.aabb.miny=P.y,b.aabb.maxx=P.x,b.aabb.maxy=P.y;let O=b.gverts.next.next;for(;O!=null;){let N=O,M=C;C=C.next,N.x=b.body.posx+(b.body.axisy*M.x-b.body.axisx*M.y),N.y=b.body.posy+(M.x*b.body.axisx+M.y*b.body.axisy),N.x<b.aabb.minx&&(b.aabb.minx=N.x),N.x>b.aabb.maxx&&(b.aabb.maxx=N.x),N.y<b.aabb.miny&&(b.aabb.miny=N.y),N.y>b.aabb.maxy&&(b.aabb.maxy=N.y),O=O.next}}_<u.minx?u.minx=_:_=u.minx,m<u.miny?u.miny=m:m=u.miny,x>u.maxx?u.maxx=x:x=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;let E=1,d=z;for(;E<d;){let b=E++,C=f*b*p,P=C-i.sweepTime;if(P!=0){i.sweepTime=C;let g=P;if(i.posx+=i.velx*g,i.posy+=i.vely*g,i.angvel!=0){let O=i.sweep_angvel*P;if(i.rot+=O,O*O>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let N=O*O,M=1-.5*N,k=1-N*N/8,Z=(M*i.axisx+O*i.axisy)*k;i.axisy=(M*i.axisy-O*i.axisx)*k,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,N=g.gverts.next,M=O;O=O.next,N.x=g.body.posx+(g.body.axisy*M.x-g.body.axisx*M.y),N.y=g.body.posy+(M.x*g.body.axisx+M.y*g.body.axisy),g.aabb.minx=N.x,g.aabb.miny=N.y,g.aabb.maxx=N.x,g.aabb.maxy=N.y;let k=g.gverts.next.next;for(;k!=null;){let Z=k,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),k=k.next}}_<u.minx?u.minx=_:_=u.minx,m<u.miny?u.miny=m:m=u.miny,x>u.maxx?u.maxx=x:x=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 r=l;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let o=i.sweep_angvel*l;if(i.rot+=o,o*o>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let a=o*o,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+o*i.axisy)*c;i.axisy=(p*i.axisy-o*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let r=B._nape.Config.staticCCDLinearThreshold*i.sweepRadius,o=B._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>r*r||i.angvel*i.angvel*e*e>o*o||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,_=u.minx,m=u.miny,x=u.maxx,y=u.maxy,z=a*e*h.sweepCoef*.008333333333333333|0;z>8&&(z=8);let f=a*e/z,v=e-i.sweepTime;if(v!=0){i.sweepTime=e;let b=v;if(i.posx+=i.velx*b,i.posy+=i.vely*b,i.angvel!=0){let C=i.sweep_angvel*v;if(i.rot+=C,C*C>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let P=C*C,g=1-.5*P,O=1-P*P/8,N=(g*i.axisx+C*i.axisy)*O;i.axisy=(g*i.axisy-C*i.axisx)*O,i.axisx=N}}}if(h.type==0){let b=h.circle;b.worldCOMx=b.body.posx+(b.body.axisy*b.localCOMx-b.body.axisx*b.localCOMy),b.worldCOMy=b.body.posy+(b.localCOMx*b.body.axisx+b.localCOMy*b.body.axisy),b.aabb.minx=b.worldCOMx-b.radius,b.aabb.miny=b.worldCOMy-b.radius,b.aabb.maxx=b.worldCOMx+b.radius,b.aabb.maxy=b.worldCOMy+b.radius}else{let b=h.polygon,C=b.lverts.next,P=b.gverts.next,g=C;C=C.next,P.x=b.body.posx+(b.body.axisy*g.x-b.body.axisx*g.y),P.y=b.body.posy+(g.x*b.body.axisx+g.y*b.body.axisy),b.aabb.minx=P.x,b.aabb.miny=P.y,b.aabb.maxx=P.x,b.aabb.maxy=P.y;let O=b.gverts.next.next;for(;O!=null;){let N=O,M=C;C=C.next,N.x=b.body.posx+(b.body.axisy*M.x-b.body.axisx*M.y),N.y=b.body.posy+(M.x*b.body.axisx+M.y*b.body.axisy),N.x<b.aabb.minx&&(b.aabb.minx=N.x),N.x>b.aabb.maxx&&(b.aabb.maxx=N.x),N.y<b.aabb.miny&&(b.aabb.miny=N.y),N.y>b.aabb.maxy&&(b.aabb.maxy=N.y),O=O.next}}_<u.minx?u.minx=_:_=u.minx,m<u.miny?u.miny=m:m=u.miny,x>u.maxx?u.maxx=x:x=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;let E=1,d=z;for(;E<d;){let b=E++,C=f*b*p,P=C-i.sweepTime;if(P!=0){i.sweepTime=C;let g=P;if(i.posx+=i.velx*g,i.posy+=i.vely*g,i.angvel!=0){let O=i.sweep_angvel*P;if(i.rot+=O,O*O>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let N=O*O,M=1-.5*N,k=1-N*N/8,Z=(M*i.axisx+O*i.axisy)*k;i.axisy=(M*i.axisy-O*i.axisx)*k,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,N=g.gverts.next,M=O;O=O.next,N.x=g.body.posx+(g.body.axisy*M.x-g.body.axisx*M.y),N.y=g.body.posy+(M.x*g.body.axisx+M.y*g.body.axisy),g.aabb.minx=N.x,g.aabb.miny=N.y,g.aabb.maxx=N.x,g.aabb.maxy=N.y;let k=g.gverts.next.next;for(;k!=null;){let Z=k,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),k=k.next}}_<u.minx?u.minx=_:_=u.minx,m<u.miny?u.miny=m:m=u.miny,x>u.maxx?u.maxx=x:x=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 r=e.ws1,o=e.ws2,a=this.mrca1;for(;a.head!=null;){let _=a.head;a.head=_.next;let m=_;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 _=p.head;p.head=_.next;let m=_;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,r.cbSet!=null){let _=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=r;let x=m;x.next=_.head,_.head=x,_.modified=!0,_.length++}if(r.body.cbSet!=null){let _=this.mrca1,m=r.body,x;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?x=new B._zpp.util.ZNPNode_ZPP_Interactor:(x=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=x.next,x.next=null),x.elt=m;let y=x;y.next=_.head,_.head=y,_.modified=!0,_.length++}if(o.cbSet!=null){let _=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=o;let x=m;x.next=_.head,_.head=x,_.modified=!0,_.length++}if(o.body.cbSet!=null){let _=this.mrca2,m=o.body,x;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?x=new B._zpp.util.ZNPNode_ZPP_Interactor:(x=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=x.next,x.next=null),x.elt=m;let y=x;y.next=_.head,_.head=y,_.modified=!0,_.length++}let c=r.body.compound,h=o.body.compound;for(;c!=h;){let _=c==null?0:c.depth,m=h==null?0:h.depth;if(_<m){if(h.cbSet!=null){let x=this.mrca2,y;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?y=new B._zpp.util.ZNPNode_ZPP_Interactor:(y=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y.next,y.next=null),y.elt=h;let z=y;z.next=x.head,x.head=z,x.modified=!0,x.length++}h=h.compound}else{if(c.cbSet!=null){let x=this.mrca1,y;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?y=new B._zpp.util.ZNPNode_ZPP_Interactor:(y=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y.next,y.next=null),y.elt=c;let z=y;z.next=x.head,x.head=z,x.modified=!0,x.length++}c=c.compound}}let u=this.mrca1.head;for(;u!=null;){let _=u.elt,m=this.mrca2.head;for(;m!=null;){let x=m.elt,y=_.cbSet,z=x.cbSet,f=y.manager,v=null,d=(y.cbpairs.length<z.cbpairs.length?y.cbpairs:z.cbpairs).head;for(;d!=null;){let C=d.elt;if(C.a==y&&C.b==z||C.a==z&&C.b==y){v=C;break}d=d.next}if(v==null){let C;Ve.zpp_pool==null?C=new Ve:(C=Ve.zpp_pool,Ve.zpp_pool=C.next,C.next=null),C.zip_listeners=!0,gt.setlt(y,z)?(C.a=y,C.b=z):(C.a=z,C.b=y),v=C,y.cbpairs.add(v),z!=y&&z.cbpairs.add(v)}if(v.zip_listeners&&(v.zip_listeners=!1,v.__validate()),v.listeners.head==null){m=m.next;continue}let b=B._zpp.phys.ZPP_Interactor.get(_,x);if(l||e.intchange){b==null&&(b=cn.get(_,x),this.add_callbackset(b));let C=y.manager,P=null,O=(y.cbpairs.length<z.cbpairs.length?y.cbpairs:z.cbpairs).head;for(;O!=null;){let A=O.elt;if(A.a==y&&A.b==z||A.a==z&&A.b==y){P=A;break}O=O.next}if(P==null){let A;Ve.zpp_pool==null?A=new Ve:(A=Ve.zpp_pool,Ve.zpp_pool=A.next,A.next=null),A.zip_listeners=!0,gt.setlt(y,z)?(A.a=y,A.b=z):(A.a=z,A.b=y),P=A,y.cbpairs.add(P),z!=y&&z.cbpairs.add(P)}P.zip_listeners&&(P.zip_listeners=!1,P.__validate());let N=P.listeners.head;for(;N!=null;){let A=N.elt;if(A.event==0&&(A.itype&e.type)!=0&&b.empty_arb(A.itype)){let S=this.push_callback(A);S.event=0;let R=b.int1,j=b.int2,q,J=A.options1,G=R.cbTypes;if(J.nonemptyintersection(G,J.includes)&&!J.nonemptyintersection(G,J.excludes)){let L=A.options2,V=j.cbTypes;q=L.nonemptyintersection(V,L.includes)&&!L.nonemptyintersection(V,L.excludes)}else q=!1;q?(S.int1=R,S.int2=j):(S.int1=j,S.int2=R),S.set=b}N=N.next}let M,k;k=!1;let Z=b.arbiters.head;for(;Z!=null;){if(Z.elt==e){k=!0;break}Z=Z.next}if(k)M=!1;else{let A=b.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 R=S;R.next=A.head,A.head=R,A.modified=!0,A.length++,M=!0}M&&e.present++}else{e.present--,b.remove_arb(e);let C=y.manager,P=null,O=(y.cbpairs.length<z.cbpairs.length?y.cbpairs:z.cbpairs).head;for(;O!=null;){let M=O.elt;if(M.a==y&&M.b==z||M.a==z&&M.b==y){P=M;break}O=O.next}if(P==null){let M;Ve.zpp_pool==null?M=new Ve:(M=Ve.zpp_pool,Ve.zpp_pool=M.next,M.next=null),M.zip_listeners=!0,gt.setlt(y,z)?(M.a=y,M.b=z):(M.a=z,M.b=y),P=M,y.cbpairs.add(P),z!=y&&z.cbpairs.add(P)}P.zip_listeners&&(P.zip_listeners=!1,P.__validate());let N=P.listeners.head;for(;N!=null;){let M=N.elt;if(M.event==1&&(M.itype&e.type)!=0&&b.empty_arb(M.itype)){let k=this.push_callback(M);k.event=1;let Z=b.int1,A=b.int2,S,R=M.options1,j=Z.cbTypes;if(R.nonemptyintersection(j,R.includes)&&!R.nonemptyintersection(j,R.excludes)){let q=M.options2,J=A.cbTypes;S=q.nonemptyintersection(J,q.includes)&&!q.nonemptyintersection(J,q.excludes)}else S=!1;S?(k.int1=Z,k.int2=A):(k.int1=A,k.int2=Z),k.set=b}N=N.next}b.arbiters.head==null&&this.remove_callbackset(b)}m=m.next}u=u.next}}e.fresh=!1,e.intchange=!1}if(e.cleared||e.up_stamp+(e.type==Ne.COL?B._nape.Config.arbiterExpirationDelay:0)<this.stamp){if(e.type==Ne.SENSOR){let i=e.sensorarb;if(!i.cleared){let r=i.b1.arbiters,o=null,a=r.head,p=!1;for(;a!=null;){if(a.elt==i){let m,x;o==null?(m=r.head,x=m.next,r.head=x,r.head==null&&(r.pushmod=!0)):(m=o.next,x=m.next,o.next=x,x==null&&(r.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,r.modified=!0,r.length--,r.pushmod=!0,p=!0;break}o=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,_=!1;for(;u!=null;){if(u.elt==i){let m,x;h==null?(m=c.head,x=m.next,c.head=x,c.head==null&&(c.pushmod=!0)):(m=h.next,x=m.next,h.next=x,x==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,_=!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=Wt.zpp_pool,Wt.zpp_pool=l}else if(e.type==Ne.FLUID){let i=e.fluidarb;if(!i.cleared){let r=i.b1.arbiters,o=null,a=r.head,p=!1;for(;a!=null;){if(a.elt==i){let m,x;o==null?(m=r.head,x=m.next,r.head=x,r.head==null&&(r.pushmod=!0)):(m=o.next,x=m.next,o.next=x,x==null&&(r.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,r.modified=!0,r.length--,r.pushmod=!0,p=!0;break}o=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,_=!1;for(;u!=null;){if(u.elt==i){let m,x;h==null?(m=c.head,x=m.next,c.head=x,c.head==null&&(c.pushmod=!0)):(m=h.next,x=m.next,h.next=x,x==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,_=!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=At.zpp_pool,At.zpp_pool=l,i.pre_dt=-1}else{let i=e.colarb;if(!i.cleared){let r=i.b1.arbiters,o=null,a=r.head,p=!1;for(;a!=null;){if(a.elt==i){let m,x;o==null?(m=r.head,x=m.next,r.head=x,r.head==null&&(r.pushmod=!0)):(m=o.next,x=m.next,o.next=x,x==null&&(r.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,r.modified=!0,r.length--,r.pushmod=!0,p=!0;break}o=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,_=!1;for(;u!=null;){if(u.elt==i){let m,x;h==null?(m=c.head,x=m.next,c.head=x,c.head==null&&(c.pushmod=!0)):(m=h.next,x=m.next,h.next=x,x==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,_=!0;break}h=u,u=u.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}for(i.b1=i.b2=null,i.active=!1,i.intchange=!1;i.contacts.next!=null;){let r=i.contacts,o=r.next;r.pop();let a=o;a.arbiter=null,a.next=we.zpp_pool,we.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=Pt.zpp_pool,Pt.zpp_pool=l,i.pre_dt=-1}return!0}let s=e.active;if(e.active=e.presentable=e.up_stamp==this.stamp,(e.immState&1)!=0){if(e.active&&e.type!=Ne.SENSOR)if(e.colarb!=null){let i=e.colarb;i.invalidated&&(i.invalidated=!1,i.userdef_restitution||(i.s1.material.elasticity<=-1/0||i.s2.material.elasticity<=-1/0?i.restitution=0:i.s1.material.elasticity>=1/0||i.s2.material.elasticity>=1/0?i.restitution=1:i.restitution=(i.s1.material.elasticity+i.s2.material.elasticity)/2,i.restitution<0&&(i.restitution=0),i.restitution>1&&(i.restitution=1)),i.userdef_dyn_fric||(i.dyn_fric=Math.sqrt(i.s1.material.dynamicFriction*i.s2.material.dynamicFriction)),i.userdef_stat_fric||(i.stat_fric=Math.sqrt(i.s1.material.staticFriction*i.s2.material.staticFriction)),i.userdef_rfric||(i.rfric=Math.sqrt(i.s1.material.rollingFriction*i.s2.material.rollingFriction))),i.pre_dt==-1&&(i.pre_dt=t);let l=t/i.pre_dt;i.pre_dt=t;let r=i.b1.smass+i.b2.smass;i.hc2=!1;let o=!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,_=i.contacts.next;for(;_!=null;){let x=_;if(x.stamp+B._nape.Config.arbiterExpirationDelay<i.stamp){let f=i.contacts,v,E;c==null?(v=f.next,E=v.next,f.next=E,f.next==null&&(f.pushmod=!0)):(v=c.next,E=v.next,c.next=E,E==null&&(f.pushmod=!0)),v._inuse=!1,f.modified=!0,f.length--,f.pushmod=!0,_=E;let d=i.innards,b,C;h==null?(b=d.next,C=b.next,d.next=C,d.next==null&&(d.pushmod=!0)):(b=h.next,C=b.next,h.next=C,C==null&&(d.pushmod=!0)),b._inuse=!1,d.modified=!0,d.length--,d.pushmod=!0,u=C;let P=x;P.arbiter=null,P.next=we.zpp_pool,we.zpp_pool=P;continue}let y=x.inner,z=x.active;if(x.active=x.stamp==i.stamp,x.active){o?(o=!1,i.c1=y,i.oc1=x):(i.hc2=!0,i.c2=y,i.oc2=x),y.r2x=x.px-i.b2.posx,y.r2y=x.py-i.b2.posy,y.r1x=x.px-i.b1.posx,y.r1y=x.py-i.b1.posy;let f=y.r2x*i.nx+y.r2y*i.ny,v=r+i.b2.sinertia*(f*f),E=y.r1x*i.nx+y.r1y*i.ny;v+=i.b1.sinertia*(E*E),y.tMass=v<B._nape.Config.epsilon*B._nape.Config.epsilon?0:1/v;let d=i.ny*y.r2x-i.nx*y.r2y,b=r+i.b2.sinertia*(d*d),C=i.ny*y.r1x-i.nx*y.r1y;b+=i.b1.sinertia*(C*C),y.nMass=b<B._nape.Config.epsilon*B._nape.Config.epsilon?0:1/b;let P=0,g=0,O=i.b2.angvel+i.b2.kinangvel;P=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,P-=i.b1.velx+i.b1.kinvelx-y.r1y*O,g-=i.b1.vely+i.b1.kinvely+y.r1x*O;let N=i.nx*P+i.ny*g;x.elasticity=i.restitution,y.bounce=N*x.elasticity,y.bounce>-B._nape.Config.elasticThreshold&&(y.bounce=0),N=g*i.nx-P*i.ny;let M=B._nape.Config.staticFrictionThreshold;N*N>M*M?y.friction=i.dyn_fric:y.friction=i.stat_fric,y.jnAcc*=l,y.jtAcc*=l}z!=x.active&&(i.contacts.modified=!0),c=_,h=u,u=u.next,_=_.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let x=i.c1;i.c1=i.c2,i.c2=x;let y=i.oc1;i.oc1=i.oc2,i.oc2=y,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(o=!0)}else i.hpc2=!1;if(i.jrAcc*=l,o||(i.rn1a=i.ny*i.c1.r1x-i.nx*i.c1.r1y,i.rt1a=i.c1.r1x*i.nx+i.c1.r1y*i.ny,i.rn1b=i.ny*i.c1.r2x-i.nx*i.c1.r2y,i.rt1b=i.c1.r2x*i.nx+i.c1.r2y*i.ny,i.k1x=i.b2.kinvelx-i.c1.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c1.r1y*i.b1.kinangvel),i.k1y=i.b2.kinvely+i.c1.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c1.r1x*i.b1.kinangvel)),i.hc2)if(i.rn2a=i.ny*i.c2.r1x-i.nx*i.c2.r1y,i.rt2a=i.c2.r1x*i.nx+i.c2.r1y*i.ny,i.rn2b=i.ny*i.c2.r2x-i.nx*i.c2.r2y,i.rt2b=i.c2.r2x*i.nx+i.c2.r2y*i.ny,i.k2x=i.b2.kinvelx-i.c2.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c2.r1y*i.b1.kinangvel),i.k2y=i.b2.kinvely+i.c2.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c2.r1x*i.b1.kinangvel),i.kMassa=r+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=r+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=r+i.b1.sinertia*i.rn2a*i.rn2a+i.b2.sinertia*i.rn2b*i.rn2b,i.kMassa*i.kMassa+2*i.kMassb*i.kMassb+i.kMassc*i.kMassc<B._nape.Config.illConditionedThreshold*(i.kMassa*i.kMassc-i.kMassb*i.kMassb)){i.Ka=i.kMassa,i.Kb=i.kMassb,i.Kc=i.kMassc;let y=i.kMassa*i.kMassc-i.kMassb*i.kMassb;if(y!=y)i.kMassa=i.kMassb=i.kMassc=0;else if(y==0){let z=0;i.kMassa!=0?i.kMassa=1/i.kMassa:(i.kMassa=0,z|=1),i.kMassc!=0?i.kMassc=1/i.kMassc:(i.kMassc=0,z|=2),i.kMassb=0}else{y=1/y;let z=i.kMassc*y;i.kMassc=i.kMassa*y,i.kMassa=z,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),o&&(e.active=!1)}else{let i=e.fluidarb;i.pre_dt==-1&&(i.pre_dt=t);let l=t/i.pre_dt;i.pre_dt=t,i.r1x=i.centroidx-i.b1.posx,i.r1y=i.centroidy-i.b1.posy,i.r2x=i.centroidx-i.b2.posx,i.r2y=i.centroidy-i.b2.posy;let r=0,o=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(r=i.ws1.fluidProperties.gravityx,o=i.ws1.fluidProperties.gravityy):(r=this.gravityx,o=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,x=i.overlap*i.ws2.fluidProperties.density;if(m>x){let y=m+x;c-=r*y,h-=o*y}else if(m<x){let y=m+x;c+=a*y,h+=p*y}else{let y=0,z=0;y=r+a,z=o+p;let f=.5;if(y*=f,z*=f,i.ws1.worldCOMx*y+i.ws1.worldCOMy*z>i.ws2.worldCOMx*y+i.ws2.worldCOMy*z){let v=m+x;c-=y*v,h-=z*v}else{let v=m+x;c+=y*v,h+=z*v}}}else if(i.ws1.fluidEnabled){let x=i.overlap*i.ws1.fluidProperties.density;c-=r*x,h-=o*x}else if(i.ws2.fluidEnabled){let x=i.overlap*i.ws2.fluidProperties.density;c+=a*x,h+=p*x}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 v=2*Math.PI*m;i.agamma=1/(t*v*(2+v*t));let E=1/(1+i.agamma),d=t*v*v*i.agamma;i.agamma*=E,i.wMass*=E}else i.wMass=0,i.agamma=0;let x=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(!(x*x+y*y<B._nape.Config.epsilon*B._nape.Config.epsilon)){let f=x*x+y*y,E=1/Math.sqrt(f);x*=E,y*=E,i.nx=x,i.ny=y}let z=0;if(i.ws1.fluidEnabled){let f=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)z-=f*i.ws2.circle.radius*B._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else{let v=i.ws2.polygon,E=0,d=0,b=v.edges.head;for(;b!=null;){let C=b.elt;E+=C.length;let P=f*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);P>0&&(P*=-B._nape.Config.fluidVacuumDrag,P=P),d-=P*.5*B._nape.Config.fluidLinearDrag,b=b.next}z+=d/E}}if(i.ws2.fluidEnabled){let f=-i.ws2.fluidProperties.viscosity*i.overlap/i.ws1.area;if(i.ws1.type==0)z-=f*i.ws1.circle.radius*B._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else{let v=i.ws1.polygon,E=0,d=0,b=v.edges.head;for(;b!=null;){let C=b.elt;E+=C.length;let P=f*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);P>0&&(P*=-B._nape.Config.fluidVacuumDrag,P=P),d-=P*.5*B._nape.Config.fluidLinearDrag,b=b.next}z+=d/E}}if(z!=0){let f=i.b1.smass+i.b2.smass,v=0,E=0,d=0;if(v=f,E=0,d=f,i.b1.sinertia!=0){let N=i.r1x*i.b1.sinertia,M=i.r1y*i.b1.sinertia;v+=M*i.r1y,E+=-M*i.r1x,d+=N*i.r1x}if(i.b2.sinertia!=0){let N=i.r2x*i.b2.sinertia,M=i.r2y*i.b2.sinertia;v+=M*i.r2y,E+=-M*i.r2x,d+=N*i.r2x}let b=v*d-E*E;if(b!=b)d=0,E=d,v=E;else if(b==0){let N=0;v!=0?v=1/v:(v=0,N|=1),d!=0?d=1/d:(d=0,N|=2),E=0}else{b=1/b;let N=d*b;d=v*b,v=N,E*=-b}i.vMassa=v,i.vMassb=E,i.vMassc=d;let C,P=2*Math.PI*z;i.lgamma=1/(t*P*(2+P*t));let g=1/(1+i.lgamma);C=t*P*P*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 _=l;i.dampx*=_,i.dampy*=_,i.adamp*=l}}else if(e.colarb!=null){let i=e.colarb,l=!0,r=null,o=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 _=i.contacts,m,x;r==null?(m=_.next,x=m.next,_.next=x,_.next==null&&(_.pushmod=!0)):(m=r.next,x=m.next,r.next=x,x==null&&(_.pushmod=!0)),m._inuse=!1,_.modified=!0,_.length--,_.pushmod=!0,p=x;let y=i.innards,z,f;o==null?(z=y.next,f=z.next,y.next=f,y.next==null&&(y.pushmod=!0)):(z=o.next,f=z.next,o.next=f,f==null&&(y.pushmod=!0)),z._inuse=!1,y.modified=!0,y.length--,y.pushmod=!0,a=f;let v=c;v.arbiter=null,v.next=we.zpp_pool,we.zpp_pool=v;continue}let h=c.inner,u=c.active;c.active=c.stamp==i.stamp,c.active&&(l?(l=!1,i.c1=h,i.oc1=c):(i.hc2=!0,i.c2=h,i.oc2=c)),u!=c.active&&(i.contacts.modified=!0),r=p,o=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 r,o;s==null?(r=e.head,o=r.next,e.head=o,e.head==null&&(e.pushmod=!0)):(r=s.next,o=r.next,s.next=o,o==null&&(e.pushmod=!0)),r.elt=null,r.next=t.zpp_pool,t.zpp_pool=r,e.modified=!0,e.length--,e.pushmod=!0,i=o;continue}s=i,i=i.next}}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let o=n.elt;if(o.preStep(e)){n=this.live_constraints.erase(t),o.broken(),this.constraintCbBreak(o),o.removeOnBreak?(o.component.sleeping=!0,this.midstep=!1,o.compound!=null?o.compound.wrap_constraints.remove(o.outer):this.wrap_constraints.remove(o.outer),this.midstep=!0):o.active=!1,o.clearcache();continue}t=n,n=n.next}let s=null,i=this.c_arbiters_true,l=i.head,r=this.c_arbiters_false!=null;for(r&&l==null&&(r=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);l!=null;){let o=l.elt;if(this.presteparb(o,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,r&&l==null&&(r=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);continue}s=l,l=l.next,r&&l==null&&(r=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null)}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 r=i.b2.imass;i.b2.velx+=i.dampx*r,i.b2.vely+=i.dampy*r,i.b1.angvel-=i.b1.iinertia*(i.dampy*i.r1x-i.dampx*i.r1y),i.b2.angvel+=i.b2.iinertia*(i.dampy*i.r2x-i.dampx*i.r2y),i.b1.angvel-=i.adamp*i.b1.iinertia,i.b2.angvel+=i.adamp*i.b2.iinertia}e=e.next}let t=this.c_arbiters_false.head,n=!0;for(t==null&&(t=this.c_arbiters_true.head,n=!1);t!=null;){let i=t.elt;if(i.active&&(i.immState&1)!=0){let l=i.nx*i.c1.jnAcc-i.ny*i.c1.jtAcc,r=i.ny*i.c1.jnAcc+i.nx*i.c1.jtAcc,o=i.b1.imass;i.b1.velx-=l*o,i.b1.vely-=r*o,i.b1.angvel-=i.b1.iinertia*(r*i.c1.r1x-l*i.c1.r1y);let a=i.b2.imass;if(i.b2.velx+=l*a,i.b2.vely+=r*a,i.b2.angvel+=i.b2.iinertia*(r*i.c1.r2x-l*i.c1.r2y),i.hc2){let p=i.nx*i.c2.jnAcc-i.ny*i.c2.jtAcc,c=i.ny*i.c2.jnAcc+i.nx*i.c2.jtAcc,h=i.b1.imass;i.b1.velx-=p*h,i.b1.vely-=c*h,i.b1.angvel-=i.b1.iinertia*(c*i.c2.r1x-p*i.c2.r1y);let u=i.b2.imass;i.b2.velx+=p*u,i.b2.vely+=c*u,i.b2.angvel+=i.b2.iinertia*(c*i.c2.r2x-p*i.c2.r2y)}i.b2.angvel+=i.jrAcc*i.b2.iinertia,i.b1.angvel-=i.jrAcc*i.b1.iinertia}t=t.next,n&&t==null&&(t=this.c_arbiters_true.head,n=!1)}let s=this.live_constraints.head;for(;s!=null;)s.elt.warmStart(),s=s.next}iterateVel(e){let t=0,n=e;for(;t<n;){let s=t++,i=this.f_arbiters.head;for(;i!=null;){let p=i.elt;if(p.active&&(p.immState&1)!=0&&!p.nodrag){let c=p.b1.angvel+p.b1.kinangvel,h=p.b2.angvel+p.b2.kinangvel,u=p.b1.velx+p.b1.kinvelx-p.r1y*c-(p.b2.velx+p.b2.kinvelx-p.r2y*h),_=p.b1.vely+p.b1.kinvely+p.r1x*c-(p.b2.vely+p.b2.kinvely+p.r2x*h),m=p.vMassa*u+p.vMassb*_;_=p.vMassb*u+p.vMassc*_,u=m;let x=p.lgamma;u-=p.dampx*x,_-=p.dampy*x;let y=1;p.dampx+=u*y,p.dampy+=_*y;let z=p.b1.imass;p.b1.velx-=u*z,p.b1.vely-=_*z;let f=p.b2.imass;p.b2.velx+=u*f,p.b2.vely+=_*f,p.b1.angvel-=p.b1.iinertia*(_*p.r1x-u*p.r1y),p.b2.angvel+=p.b2.iinertia*(_*p.r2x-u*p.r2y);let v=(c-h)*p.wMass-p.adamp*p.agamma;p.adamp+=v,p.b1.angvel-=v*p.b1.iinertia,p.b2.angvel+=v*p.b2.iinertia}i=i.next}let l=null,r=this.live_constraints.head;for(;r!=null;){let p=r.elt;if(p.applyImpulseVel()){r=this.live_constraints.erase(l),p.broken(),this.constraintCbBreak(p),p.removeOnBreak?(p.component.sleeping=!0,this.midstep=!1,p.compound!=null?p.compound.wrap_constraints.remove(p.outer):this.wrap_constraints.remove(p.outer),this.midstep=!0):p.active=!1,p.clearcache();continue}l=r,r=r.next}let o=this.c_arbiters_false.head,a=!0;for(o==null&&(o=this.c_arbiters_true.head,a=!1);o!=null;){let p=o.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,_=p.c1.friction*p.c1.jnAcc,m=p.c1.jtAcc,x=m-u;x>_?x=_:x<-_&&(x=-_),u=x-m,p.c1.jtAcc=x;let y=-p.ny*u,z=p.nx*u;if(p.b2.velx+=y*p.b2.imass,p.b2.vely+=z*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=z*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),v=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);u=(v*p.nx-f*p.ny+p.surfacex)*p.c2.tMass,_=p.c2.friction*p.c2.jnAcc,m=p.c2.jtAcc,x=m-u,x>_?x=_:x<-_&&(x=-_),u=x-m,p.c2.jtAcc=x,y=-p.ny*u,z=p.nx*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=z*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=z*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),v=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);let E=p.c1.jnAcc,d=p.c2.jnAcc,b=c*p.nx+h*p.ny+p.surfacey+p.c1.bounce-(p.Ka*E+p.Kb*d),C=f*p.nx+v*p.ny+p.surfacey+p.c2.bounce-(p.Kb*E+p.Kc*d),P=-(p.kMassa*b+p.kMassb*C),g=-(p.kMassb*b+p.kMassc*C);P>=0&&g>=0?(b=P-E,C=g-d,p.c1.jnAcc=P,p.c2.jnAcc=g):(P=-p.c1.nMass*b,P>=0&&p.Kb*P+C>=0?(b=P-E,C=-d,p.c1.jnAcc=P,p.c2.jnAcc=0):(g=-p.c2.nMass*C,g>=0&&p.Kb*g+b>=0?(b=-E,C=g-d,p.c1.jnAcc=0,p.c2.jnAcc=g):b>=0&&C>=0?(b=-E,C=-d,p.c1.jnAcc=p.c2.jnAcc=0):(b=0,C=0))),u=b+C,y=p.nx*u,z=p.ny*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=z*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=z*p.b1.imass,p.b2.angvel+=(p.rn1b*b+p.rn2b*C)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*b+p.rn2a*C)*p.b1.iinertia}else p.radius!=0&&(u=(p.b2.angvel-p.b1.angvel)*p.rMass,_=p.rfric*p.c1.jnAcc,m=p.jrAcc,p.jrAcc-=u,p.jrAcc>_?p.jrAcc=_:p.jrAcc<-_&&(p.jrAcc=-_),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,x=m-u,x<0&&(x=0),u=x-m,p.c1.jnAcc=x,y=p.nx*u,z=p.ny*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=z*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=z*p.b1.imass,p.b2.angvel+=p.rn1b*u*p.b2.iinertia,p.b1.angvel-=p.rn1a*u*p.b1.iinertia}o=o.next,a&&o==null&&(o=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 r=this.c_arbiters_false.head,o=!0;for(r==null&&(r=this.c_arbiters_true.head,o=!1);r!=null;){let a=r.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 _=0,m=0;_=a.b1.axisy*p.lr1x-a.b1.axisx*p.lr1y,m=p.lr1x*a.b1.axisx+p.lr1y*a.b1.axisy;let x=1;_+=a.b1.posx*x,m+=a.b1.posy*x;let y=0,z=0;y=c-_,z=h-m;let f=Math.sqrt(y*y+z*z),v=a.radius-B._nape.Config.collisionSlop,E=f-v;if(y*a.nx+z*a.ny<0&&(y=-y,z=-z,E-=a.radius),E<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 d=1/f;y*=d,z*=d;let b=.5*(_+c),C=.5*(m+h),P=f-v;_=b-a.b1.posx,m=C-a.b1.posy,c=b-a.b2.posx,h=C-a.b2.posy;let g=z*_-y*m,O=z*c-y*h,N=a.b2.smass+O*O*a.b2.sinertia+a.b1.smass+g*g*a.b1.sinertia;if(N!=0){let M=-a.biasCoef*P/N,k=0,Z=0,A=M;k=y*A,Z=z*A;let S=a.b1.imass;a.b1.posx-=k*S,a.b1.posy-=Z*S;let R=a.b1,j=-g*a.b1.iinertia*M;if(R.rot+=j,j*j>1e-4)R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.rot);else{let L=j*j,V=1-.5*L,Y=1-L*L/8,$=(V*R.axisx+j*R.axisy)*Y;R.axisy=(V*R.axisy-j*R.axisx)*Y,R.axisx=$}let q=a.b2.imass;a.b2.posx+=k*q,a.b2.posy+=Z*q;let J=a.b2,G=O*a.b2.iinertia*M;if(J.rot+=G,G*G>1e-4)J.axisx=Math.sin(J.rot),J.axisy=Math.cos(J.rot);else{let L=G*G,V=1-.5*L,Y=1-L*L/8,$=(V*J.axisx+G*J.axisy)*Y;J.axisy=(V*J.axisy-G*J.axisx)*Y,J.axisx=$}}}}else{let p=0,c=0,h,u=0,_=0,m=0,x=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,_=a.c1.lr1x*a.b2.axisx+a.c1.lr1y*a.b2.axisy;let f=1;if(u+=a.b2.posx*f,_+=a.b2.posy*f,a.hpc2){m=a.b2.axisy*a.c2.lr1x-a.b2.axisx*a.c2.lr1y,x=a.c2.lr1x*a.b2.axisx+a.c2.lr1y*a.b2.axisy;let v=1;m+=a.b2.posx*v,x+=a.b2.posy*v}}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,_=a.c1.lr1x*a.b1.axisx+a.c1.lr1y*a.b1.axisy;let f=1;if(u+=a.b1.posx*f,_+=a.b1.posy*f,a.hpc2){m=a.b1.axisy*a.c2.lr1x-a.b1.axisx*a.c2.lr1y,x=a.c2.lr1x*a.b1.axisx+a.c2.lr1y*a.b1.axisy;let v=1;m+=a.b1.posx*v,x+=a.b1.posy*v}}let y=u*p+_*c-h-a.radius;y+=B._nape.Config.collisionSlop;let z=0;if(a.hpc2&&(z=m*p+x*c-h-a.radius,z+=B._nape.Config.collisionSlop),y<0||z<0){a.rev&&(p=-p,c=-c);let f=0,v=0;f=u-a.b1.posx,v=_-a.b1.posy;let E=0,d=0;E=u-a.b2.posx,d=_-a.b2.posy;let b=0,C=0,P=0,g=0;if(a.hpc2){b=m-a.b1.posx,C=x-a.b1.posy,P=m-a.b2.posx,g=x-a.b2.posy;let O=c*f-p*v,N=c*E-p*d,M=c*b-p*C,k=c*P-p*g,Z=a.b1.smass+a.b2.smass;a.kMassa=Z+a.b1.sinertia*O*O+a.b2.sinertia*N*N,a.kMassb=Z+a.b1.sinertia*O*M+a.b2.sinertia*N*k,a.kMassc=Z+a.b1.sinertia*M*M+a.b2.sinertia*k*k;let A=0,S=0,R=0;A=a.kMassa,S=a.kMassb,R=a.kMassc;let j=y*a.biasCoef,q=z*a.biasCoef;for(;;){let J=0,G=0;J=j,G=q,J=-J,G=-G;let L=a.kMassa*a.kMassc-a.kMassb*a.kMassb;if(L!=L)G=0,J=G;else if(L==0)a.kMassa!=0?J/=a.kMassa:J=0,a.kMassc!=0?G/=a.kMassc:G=0;else{L=1/L;let $=L*(a.kMassc*J-a.kMassb*G);G=L*(a.kMassa*G-a.kMassb*J),J=$}if(J>=0&&G>=0){let $=(J+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let H=a.b1,X=-a.b1.iinertia*(O*J+M*G);if(H.rot+=X,X*X>1e-4)H.axisx=Math.sin(H.rot),H.axisy=Math.cos(H.rot);else{let D=X*X,T=1-.5*D,U=1-D*D/8,Q=(T*H.axisx+X*H.axisy)*U;H.axisy=(T*H.axisy-X*H.axisx)*U,H.axisx=Q}let ee=(J+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let W=a.b2,F=a.b2.iinertia*(N*J+k*G);if(W.rot+=F,F*F>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let D=F*F,T=1-.5*D,U=1-D*D/8,Q=(T*W.axisx+F*W.axisy)*U;W.axisy=(T*W.axisy-F*W.axisx)*U,W.axisx=Q}break}J=-j/A,G=0;let V=S*J+q;if(J>=0&&V>=0){let $=(J+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let H=a.b1,X=-a.b1.iinertia*(O*J+M*G);if(H.rot+=X,X*X>1e-4)H.axisx=Math.sin(H.rot),H.axisy=Math.cos(H.rot);else{let D=X*X,T=1-.5*D,U=1-D*D/8,Q=(T*H.axisx+X*H.axisy)*U;H.axisy=(T*H.axisy-X*H.axisx)*U,H.axisx=Q}let ee=(J+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let W=a.b2,F=a.b2.iinertia*(N*J+k*G);if(W.rot+=F,F*F>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let D=F*F,T=1-.5*D,U=1-D*D/8,Q=(T*W.axisx+F*W.axisy)*U;W.axisy=(T*W.axisy-F*W.axisx)*U,W.axisx=Q}break}J=0,G=-q/R;let Y=S*G+j;if(G>=0&&Y>=0){let $=(J+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let H=a.b1,X=-a.b1.iinertia*(O*J+M*G);if(H.rot+=X,X*X>1e-4)H.axisx=Math.sin(H.rot),H.axisy=Math.cos(H.rot);else{let D=X*X,T=1-.5*D,U=1-D*D/8,Q=(T*H.axisx+X*H.axisy)*U;H.axisy=(T*H.axisy-X*H.axisx)*U,H.axisx=Q}let ee=(J+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let W=a.b2,F=a.b2.iinertia*(N*J+k*G);if(W.rot+=F,F*F>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let D=F*F,T=1-.5*D,U=1-D*D/8,Q=(T*W.axisx+F*W.axisy)*U;W.axisy=(T*W.axisy-F*W.axisx)*U,W.axisx=Q}break}break}}else{let O=c*f-p*v,N=c*E-p*d,M=a.b2.smass+N*N*a.b2.sinertia+a.b1.smass+O*O*a.b1.sinertia;if(M!=0){let k=-a.biasCoef*y/M,Z=0,A=0,S=k;Z=p*S,A=c*S;let R=a.b1.imass;a.b1.posx-=Z*R,a.b1.posy-=A*R;let j=a.b1,q=-O*a.b1.iinertia*k;if(j.rot+=q,q*q>1e-4)j.axisx=Math.sin(j.rot),j.axisy=Math.cos(j.rot);else{let V=q*q,Y=1-.5*V,$=1-V*V/8,H=(Y*j.axisx+q*j.axisy)*$;j.axisy=(Y*j.axisy-q*j.axisx)*$,j.axisx=H}let J=a.b2.imass;a.b2.posx+=Z*J,a.b2.posy+=A*J;let G=a.b2,L=N*a.b2.iinertia*k;if(G.rot+=L,L*L>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else{let V=L*L,Y=1-.5*V,$=1-V*V/8,H=(Y*G.axisx+L*G.axisy)*$;G.axisy=(Y*G.axisy-L*G.axisx)*$,G.axisx=H}}}}}r=r.next,o&&r==null&&(r=this.c_arbiters_true.head,o=!1)}}}group_ignore(e,t){let n=e;for(;n!=null&&n.group==null;)n.ishape!=null?n=n.ishape.body:n.icompound!=null?n=n.icompound.compound:n=n.ibody.compound;let s=n==null?null:n.group;if(s==null)return!1;{let i=t;for(;i!=null&&i.group==null;)i.ishape!=null?i=i.ishape.body:i.icompound!=null?i=i.icompound.compound:i=i.ibody.compound;let l=i==null?null:i.group;if(l==null)return!1;{let r=!1;for(;s!=null&&l!=null;){if(s==l){r=s.ignore;break}s.depth<l.depth?l=l.group:s=s.group}return r}}}interactionType(e,t,n,s){let i;i=!1;let l=n.constraints.head;for(;l!=null;){let o=l.elt;if(o.ignore&&o.pair_exists(n.id,s.id)){i=!0;break}l=l.next}let r;if(i)r=!1;else{let o=e;for(;o!=null&&o.group==null;)o.ishape!=null?o=o.ishape.body:o.icompound!=null?o=o.icompound.compound:o=o.ibody.compound;let a=o==null?null:o.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}}r=!p}if(r){let o;if(e.sensorEnabled||t.sensorEnabled){let a=e.filter,p=t.filter;o=(a.sensorMask&p.sensorGroup)!=0&&(p.sensorMask&a.sensorGroup)!=0}else o=!1;if(o)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,r=e.body,o=t.body,a;a=!1;let p=r.constraints.head;for(;p!=null;){let u=p.elt;if(u.ignore&&u.pair_exists(r.id,o.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 _=u==null?null:u.group,m;if(_==null)m=!1;else{let x=t;for(;x!=null&&x.group==null;)x.ishape!=null?x=x.ishape.body:x.icompound!=null?x=x.icompound.compound:x=x.ibody.compound;let y=x==null?null:x.group;if(y==null)m=!1;else{let z=!1;for(;_!=null&&y!=null;){if(_==y){z=_.ignore;break}_.depth<y.depth?y=y.group:_=_.group}m=z}}h=!m}if(h){let u;if(e.sensorEnabled||t.sensorEnabled){let _=e.filter,m=t.filter;u=(_.sensorMask&m.sensorGroup)!=0&&(m.sensorMask&_.sensorGroup)!=0}else u=!1;if(u)c=2;else{let _;if(e.fluidEnabled||t.fluidEnabled){let m=e.filter,x=t.filter;_=(m.fluidMask&x.fluidGroup)!=0&&(x.fluidMask&m.fluidGroup)!=0}else _=!1;if(_&&!(r.imass==0&&o.imass==0&&r.iinertia==0&&o.iinertia==0))c=0;else{let m=e.filter,x=t.filter;c=(m.collisionMask&x.collisionGroup)!=0&&(x.collisionMask&m.collisionGroup)!=0&&!(r.imass==0&&o.imass==0&&r.iinertia==0&&o.iinertia==0)?1:-1}}}else c=-1;if(c!=-1){let u,_;e.type>t.type?(u=t,_=e):e.type==t.type?e.id<t.id?(u=e,_=t):(_=e,u=t):(u=e,_=t);let m=u==t;if(c==0){let x;if(s==null){let E=null,b=(r.arbiters.length<o.arbiters.length?r:o).arbiters.head;for(;b!=null;){let C=b.elt;if(C.id==u.id&&C.di==_.id){E=C;break}b=b.next}x=E}else x=s;let y=x==null,z,f=!1;if(y)At.zpp_pool==null?z=new At:(z=At.zpp_pool,At.zpp_pool=z.next,z.next=null);else if(x.fluidarb==null){x.cleared=!0;{let d=x.b1.arbiters,b=null,C=d.head,P=!1;for(;C!=null;){if(C.elt==x){let g,O;b==null?(g=d.head,O=g.next,d.head=O,d.head==null&&(d.pushmod=!0)):(g=b.next,O=g.next,b.next=O,O==null&&(d.pushmod=!0));let N=g;N.elt=null,N.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=N,d.modified=!0,d.length--,d.pushmod=!0,P=!0;break}b=C,C=C.next}}{let d=x.b2.arbiters,b=null,C=d.head,P=!1;for(;C!=null;){if(C.elt==x){let g,O;b==null?(g=d.head,O=g.next,d.head=O,d.head==null&&(d.pushmod=!0)):(g=b.next,O=g.next,b.next=O,O==null&&(d.pushmod=!0));let N=g;N.elt=null,N.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=N,d.modified=!0,d.length--,d.pushmod=!0,P=!0;break}b=C,C=C.next}}x.pair!=null&&(x.pair.arb=null,x.pair=null),x.active=!1,this.f_arbiters.modified=!0,At.zpp_pool==null?z=new At:(z=At.zpp_pool,At.zpp_pool=z.next,z.next=null),z.intchange=!0,y=!0,f=!0}else z=x.fluidarb;let v=4;if(y||z.stamp!=this.stamp||i)if(z.stamp=this.stamp,Ze.flowCollide(u,_,z)){if(y){let E=_.id;z.b1=e.body,z.ws1=e,z.b2=t.body,z.ws2=t,z.id=u.id,z.di=E;let d=z.b1.arbiters,b;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?b=new B._zpp.util.ZNPNode_ZPP_Arbiter:(b=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b.next,b.next=null),b.elt=z;let C=b;C.next=d.head,d.head=C,d.modified=!0,d.length++;let P=z.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=z;let O=g;O.next=P.head,P.head=O,P.modified=!0,P.length++,z.active=!0,z.present=0,z.cleared=!1,z.sleeping=!1,z.fresh=!1,z.presentable=!1,z.nx=0,z.ny=1,z.dampx=0,z.dampy=0,z.adamp=0;let N=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=z;let k=M;k.next=N.head,N.head=k,N.modified=!0,N.length++,z.fresh=!f}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&i;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let E=!1,d=z.ws1.id>z.ws2.id?z.ws2:z.ws1,b=z.ws1.id>z.ws2.id?z.ws1:z.ws2,C=this.mrca1;for(;C.head!=null;){let M=C.head;C.head=M.next;let k=M;k.elt=null,k.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k,C.head==null&&(C.pushmod=!0),C.modified=!0,C.length--}C.pushmod=!0;let P=this.mrca2;for(;P.head!=null;){let M=P.head;P.head=M.next;let k=M;k.elt=null,k.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}if(P.pushmod=!0,d.cbSet!=null){let M=this.mrca1,k;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?k=new B._zpp.util.ZNPNode_ZPP_Interactor:(k=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k.next,k.next=null),k.elt=d;let Z=k;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(d.body.cbSet!=null){let M=this.mrca1,k=d.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=k;let A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}if(b.cbSet!=null){let M=this.mrca2,k;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?k=new B._zpp.util.ZNPNode_ZPP_Interactor:(k=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k.next,k.next=null),k.elt=b;let Z=k;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(b.body.cbSet!=null){let M=this.mrca2,k=b.body,Z;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?Z=new B._zpp.util.ZNPNode_ZPP_Interactor:(Z=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z.next,Z.next=null),Z.elt=k;let A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}let g=d.body.compound,O=b.body.compound;for(;g!=O;){let M=g==null?0:g.depth,k=O==null?0:O.depth;if(M<k){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 N=this.mrca1.head;for(;N!=null;){let M=N.elt,k=this.mrca2.head;for(;k!=null;){let Z=k.elt,A=M.cbSet,S=Z.cbSet,R=A.manager,j=null,J=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;J!=null;){let F=J.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){j=F;break}J=J.next}if(j==null){let F;Ve.zpp_pool==null?F=new Ve:(F=Ve.zpp_pool,Ve.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,gt.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),j=F,A.cbpairs.add(j),S!=A&&S.cbpairs.add(j)}if(j.zip_listeners&&(j.zip_listeners=!1,j.__validate()),j.listeners.head==null){k=k.next;continue}let G=null,L=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 Y=null,$=A.manager,H=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){H=F;break}ee=ee.next}if(H==null){let F;Ve.zpp_pool==null?F=new Ve:(F=Ve.zpp_pool,Ve.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,gt.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),H=F,A.cbpairs.add(H),S!=A&&S.cbpairs.add(H)}H.zip_listeners&&(H.zip_listeners=!1,H.__validate());let W=H.listeners.head;for(;W!=null;){let F=W.elt;if(F.event==5&&(F.itype&v)!=0){let D=this.prelisteners,T;B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?T=new B._zpp.util.ZNPNode_ZPP_InteractionListener:(T=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=T.next,T.next=null),T.elt=F;let U=T;Y==null?(U.next=D.head,D.head=U):(U.next=Y.next,Y.next=U),D.pushmod=D.modified=!0,D.length++,Y=U,E=E||!F.pure}W=W.next}if(this.prelisteners.head==null){k=k.next;continue}if(G=B._zpp.phys.ZPP_Interactor.get(M,Z),G==null&&(L=cn.get(M,Z),this.add_callbackset(L)),G==null||(G.FLUIDstamp!=this.stamp||i)&&(G.FLUIDstate&4)==0){if(L!=null&&(G=L),G!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(G.COLLISIONstamp=this.stamp,G.SENSORstamp=this.stamp,G.FLUIDstamp=this.stamp):G.FLUIDstamp=this.stamp,U=U.next}z.mutable=!0,z.wrap_position!=null&&(z.wrap_position.zpp_inner._immutable=!1);let F=z.active;z.active=!0;let D=!1;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=G;let T=this.prelisteners.head;for(;T!=null;){let U=T.elt;this.precb.zpp_inner.listener=U;let Q=this.precb.zpp_inner,K=G.int1,ie=G.int2,oe,se=U.options1,ne=K.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=U.options2,_e=ie.cbTypes;oe=le.nonemptyintersection(_e,le.includes)&&!le.nonemptyintersection(_e,le.excludes)}else oe=!1;oe?(Q.int1=K,Q.int2=ie):(Q.int1=ie,Q.int2=K),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let ae=U.handlerp(this.precb);if(ae!=null){let le;I.PreFlag_ACCEPT==null&&(I.internal=!0,I.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,I.internal=!1),ae==I.PreFlag_ACCEPT?le=5:(I.PreFlag_ACCEPT_ONCE==null&&(I.internal=!0,I.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,I.internal=!1),ae==I.PreFlag_ACCEPT_ONCE?le=1:(I.PreFlag_IGNORE==null&&(I.internal=!0,I.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,I.internal=!1),le=ae==I.PreFlag_IGNORE?6:2)),z.immState=le}T=T.next}if(z.mutable=!1,z.wrap_position!=null&&(z.wrap_position.zpp_inner._immutable=!0),z.active=F,G!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7&&(G.COLLISIONstate=z.immState,G.SENSORstate=z.immState),G.FLUIDstate=z.immState,U=U.next}}else G==null?(z.immState&4)==0&&(z.immState=1):z.immState=G.FLUIDstate;k=k.next}N=N.next}if(E&&(z.immState&4)==0){if(z.b1.type==2){let M=z.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}if(z.b1.type==2){let M=z.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}}}if((z.immState&1)!=0){if(z.b1.type==2&&z.b1.component.sleeping){let E=z.b1;E.world||(E.component.waket=this.stamp+(this.midstep?0:1),E.type==3&&(E.kinematicDelaySleep=!0),E.component.sleeping&&this.really_wake(E,!1))}if(z.b2.type==2&&z.b2.component.sleeping){let E=z.b2;E.world||(E.component.waket=this.stamp+(this.midstep?0:1),E.type==3&&(E.kinematicDelaySleep=!0),E.component.sleeping&&this.really_wake(E,!1))}}if(z.sleeping){z.sleeping=!1;let E=this.f_arbiters,d;B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?d=new B._zpp.util.ZNPNode_ZPP_FluidArbiter:(d=B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=d.next,d.next=null),d.elt=z;let b=d;b.next=E.head,E.head=b,E.modified=!0,E.length++}l=z}else if(y){let E=z;E.next=At.zpp_pool,At.zpp_pool=E,l=null}else l=z;else l=z}else if(c==1){let x=n?this.c_arbiters_true:this.c_arbiters_false,y;if(s==null){let d=null,C=(r.arbiters.length<o.arbiters.length?r:o).arbiters.head;for(;C!=null;){let P=C.elt;if(P.id==u.id&&P.di==_.id){d=P;break}C=C.next}y=d}else y=s;let z=y==null,f,v=!1;if(z)Pt.zpp_pool==null?f=new Pt:(f=Pt.zpp_pool,Pt.zpp_pool=f.next,f.next=null),f.stat=n;else if(y.colarb==null){y.cleared=!0;{let b=y.b1.arbiters,C=null,P=b.head,g=!1;for(;P!=null;){if(P.elt==y){let O,N;C==null?(O=b.head,N=O.next,b.head=N,b.head==null&&(b.pushmod=!0)):(O=C.next,N=O.next,C.next=N,N==null&&(b.pushmod=!0));let M=O;M.elt=null,M.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,b.modified=!0,b.length--,b.pushmod=!0,g=!0;break}C=P,P=P.next}}{let b=y.b2.arbiters,C=null,P=b.head,g=!1;for(;P!=null;){if(P.elt==y){let O,N;C==null?(O=b.head,N=O.next,b.head=N,b.head==null&&(b.pushmod=!0)):(O=C.next,N=O.next,C.next=N,N==null&&(b.pushmod=!0));let M=O;M.elt=null,M.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,b.modified=!0,b.length--,b.pushmod=!0,g=!0;break}C=P,P=P.next}}y.pair!=null&&(y.pair.arb=null,y.pair=null),y.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,f.stat=n,z=!0,v=!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),x.add(f)));let E=1;if(z||f.stamp!=this.stamp||i)if(f.stamp=this.stamp,Ze.contactCollide(u,_,f,m)){if(z){let d=_.id;f.b1=e.body,f.ws1=e,f.b2=t.body,f.ws2=t,f.id=u.id,f.di=d;let b=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 P=C;P.next=b.head,b.head=P,b.modified=!0,b.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 N=O;N.next=g.head,g.head=N,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 k=M;k.next=x.head,x.head=k,x.modified=!0,x.length++,f.fresh=!v}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 d=!1,b=f.ws1.id>f.ws2.id?f.ws2:f.ws1,C=f.ws1.id>f.ws2.id?f.ws1:f.ws2,P=this.mrca1;for(;P.head!=null;){let k=P.head;P.head=k.next;let Z=k;Z.elt=null,Z.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}P.pushmod=!0;let g=this.mrca2;for(;g.head!=null;){let k=g.head;g.head=k.next;let Z=k;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,b.cbSet!=null){let k=this.mrca1,Z;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?Z=new B._zpp.util.ZNPNode_ZPP_Interactor:(Z=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z.next,Z.next=null),Z.elt=b;let A=Z;A.next=k.head,k.head=A,k.modified=!0,k.length++}if(b.body.cbSet!=null){let k=this.mrca1,Z=b.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=k.head,k.head=S,k.modified=!0,k.length++}if(C.cbSet!=null){let k=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=k.head,k.head=A,k.modified=!0,k.length++}if(C.body.cbSet!=null){let k=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=k.head,k.head=S,k.modified=!0,k.length++}let O=b.body.compound,N=C.body.compound;for(;O!=N;){let k=O==null?0:O.depth,Z=N==null?0:N.depth;if(k<Z){if(N.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=N;let R=S;R.next=A.head,A.head=R,A.modified=!0,A.length++}N=N.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 R=S;R.next=A.head,A.head=R,A.modified=!0,A.length++}O=O.compound}}let M=this.mrca1.head;for(;M!=null;){let k=M.elt,Z=this.mrca2.head;for(;Z!=null;){let A=Z.elt,S=k.cbSet,R=A.cbSet,j=S.manager,q=null,G=(S.cbpairs.length<R.cbpairs.length?S.cbpairs:R.cbpairs).head;for(;G!=null;){let D=G.elt;if(D.a==S&&D.b==R||D.a==R&&D.b==S){q=D;break}G=G.next}if(q==null){let D;Ve.zpp_pool==null?D=new Ve:(D=Ve.zpp_pool,Ve.zpp_pool=D.next,D.next=null),D.zip_listeners=!0,gt.setlt(S,R)?(D.a=S,D.b=R):(D.a=R,D.b=S),q=D,S.cbpairs.add(q),R!=S&&R.cbpairs.add(q)}if(q.zip_listeners&&(q.zip_listeners=!1,q.__validate()),q.listeners.head==null){Z=Z.next;continue}let L=null,V=null,Y=this.prelisteners;for(;Y.head!=null;){let D=Y.head;Y.head=D.next;let T=D;T.elt=null,T.next=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=T,Y.head==null&&(Y.pushmod=!0),Y.modified=!0,Y.length--}Y.pushmod=!0;let $=null,H=S.manager,X=null,W=(S.cbpairs.length<R.cbpairs.length?S.cbpairs:R.cbpairs).head;for(;W!=null;){let D=W.elt;if(D.a==S&&D.b==R||D.a==R&&D.b==S){X=D;break}W=W.next}if(X==null){let D;Ve.zpp_pool==null?D=new Ve:(D=Ve.zpp_pool,Ve.zpp_pool=D.next,D.next=null),D.zip_listeners=!0,gt.setlt(S,R)?(D.a=S,D.b=R):(D.a=R,D.b=S),X=D,S.cbpairs.add(X),R!=S&&R.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&E)!=0){let T=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=T.head,T.head=Q):(Q.next=$.next,$.next=Q),T.pushmod=T.modified=!0,T.length++,$=Q,d=d||!D.pure}F=F.next}if(this.prelisteners.head==null){Z=Z.next;continue}if(L=B._zpp.phys.ZPP_Interactor.get(k,A),L==null&&(V=cn.get(k,A),this.add_callbackset(V)),L==null||(L.COLLISIONstamp!=this.stamp||i)&&(L.COLLISIONstate&4)==0){if(V!=null&&(L=V),L!=null){let ne=this.prelisteners.head;for(;ne!=null;)ne.elt.itype==7?(L.COLLISIONstamp=this.stamp,L.SENSORstamp=this.stamp,L.FLUIDstamp=this.stamp):L.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 T=!1,U=!0,Q=null,K=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 _e=f.contacts,ce,he;Q==null?(ce=_e.next,he=ce.next,_e.next=he,_e.next==null&&(_e.pushmod=!0)):(ce=Q.next,he=ce.next,Q.next=he,he==null&&(_e.pushmod=!0)),ce._inuse=!1,_e.modified=!0,_e.length--,_e.pushmod=!0,oe=he;let te=f.innards,xe,de;K==null?(xe=te.next,de=xe.next,te.next=de,te.next==null&&(te.pushmod=!0)):(xe=K.next,de=xe.next,K.next=de,de==null&&(te.pushmod=!0)),xe._inuse=!1,te.modified=!0,te.length--,te.pushmod=!0,ie=de;let me=ne;me.arbiter=null,me.next=we.zpp_pool,we.zpp_pool=me;continue}let ae=ne.inner,le=ne.active;ne.active=ne.stamp==f.stamp,ne.active&&(U?(U=!1,f.c1=ae,f.oc1=ne):(f.hc2=!0,f.c2=ae,f.oc2=ne)),le!=ne.active&&(f.contacts.modified=!0),Q=oe,K=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 ae=f.oc1;f.oc1=f.oc2,f.oc2=ae,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=L;let se=this.prelisteners.head;for(;se!=null;){let ne=se.elt;this.precb.zpp_inner.listener=ne;let ae=this.precb.zpp_inner,le=L.int1,_e=L.int2,ce,he=ne.options1,te=le.cbTypes;if(he.nonemptyintersection(te,he.includes)&&!he.nonemptyintersection(te,he.excludes)){let de=ne.options2,me=_e.cbTypes;ce=de.nonemptyintersection(me,de.includes)&&!de.nonemptyintersection(me,de.excludes)}else ce=!1;ce?(ae.int1=le,ae.int2=_e):(ae.int1=_e,ae.int2=le),this.precb.zpp_inner.pre_swapped=k!=this.precb.zpp_inner.int1;let xe=ne.handlerp(this.precb);if(xe!=null){let de;I.PreFlag_ACCEPT==null&&(I.internal=!0,I.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,I.internal=!1),xe==I.PreFlag_ACCEPT?de=5:(I.PreFlag_ACCEPT_ONCE==null&&(I.internal=!0,I.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,I.internal=!1),xe==I.PreFlag_ACCEPT_ONCE?de=1:(I.PreFlag_IGNORE==null&&(I.internal=!0,I.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,I.internal=!1),de=xe==I.PreFlag_IGNORE?6:2)),f.immState=de}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,L!=null){let ne=this.prelisteners.head;for(;ne!=null;)ne.elt.itype==7?(L.COLLISIONstate=f.immState,L.SENSORstate=f.immState,L.FLUIDstate=f.immState):L.COLLISIONstate=f.immState,ne=ne.next}}else L==null?(f.immState&4)==0&&(f.immState=1):f.immState=L.COLLISIONstate;Z=Z.next}M=M.next}if(d&&(f.immState&4)==0){if(f.b1.type==2){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.b1.type==2){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.immState&1)!=0){if(f.b1.type==2&&f.b1.component.sleeping){let d=f.b1;d.world||(d.component.waket=this.stamp+(this.midstep?0:1),d.type==3&&(d.kinematicDelaySleep=!0),d.component.sleeping&&this.really_wake(d,!1))}if(f.b2.type==2&&f.b2.component.sleeping){let d=f.b2;d.world||(d.component.waket=this.stamp+(this.midstep?0:1),d.type==3&&(d.kinematicDelaySleep=!0),d.component.sleeping&&this.really_wake(d,!1))}}if(f.sleeping){f.sleeping=!1;let d;B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?d=new B._zpp.util.ZNPNode_ZPP_ColArbiter:(d=B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=d.next,d.next=null),d.elt=f;let b=d;b.next=x.head,x.head=b,x.modified=!0,x.length++}l=f}else if(z){let d=f;d.userdef_dyn_fric=!1,d.userdef_stat_fric=!1,d.userdef_restitution=!1,d.userdef_rfric=!1,d.__ref_edge1=d.__ref_edge2=null,d.next=Pt.zpp_pool,Pt.zpp_pool=d,l=null}else l=f;else l=f}else{let x;if(s==null){let E=null,b=(r.arbiters.length<o.arbiters.length?r:o).arbiters.head;for(;b!=null;){let C=b.elt;if(C.id==u.id&&C.di==_.id){E=C;break}b=b.next}x=E}else x=s;let y=x==null,z,f=!1;if(y)Wt.zpp_pool==null?z=new Wt:(z=Wt.zpp_pool,Wt.zpp_pool=z.next,z.next=null);else if(x.sensorarb==null){x.cleared=!0;{let d=x.b1.arbiters,b=null,C=d.head,P=!1;for(;C!=null;){if(C.elt==x){let g,O;b==null?(g=d.head,O=g.next,d.head=O,d.head==null&&(d.pushmod=!0)):(g=b.next,O=g.next,b.next=O,O==null&&(d.pushmod=!0));let N=g;N.elt=null,N.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=N,d.modified=!0,d.length--,d.pushmod=!0,P=!0;break}b=C,C=C.next}}{let d=x.b2.arbiters,b=null,C=d.head,P=!1;for(;C!=null;){if(C.elt==x){let g,O;b==null?(g=d.head,O=g.next,d.head=O,d.head==null&&(d.pushmod=!0)):(g=b.next,O=g.next,b.next=O,O==null&&(d.pushmod=!0));let N=g;N.elt=null,N.next=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=N,d.modified=!0,d.length--,d.pushmod=!0,P=!0;break}b=C,C=C.next}}x.pair!=null&&(x.pair.arb=null,x.pair=null),x.active=!1,this.f_arbiters.modified=!0,Wt.zpp_pool==null?z=new Wt:(z=Wt.zpp_pool,Wt.zpp_pool=z.next,z.next=null),z.intchange=!0,y=!0,f=!0}else z=x.sensorarb;let v=2;if(y||z.stamp!=this.stamp||i)if(z.stamp=this.stamp,Ze.testCollide(u,_)){if(y){let E=_.id;z.b1=e.body,z.ws1=e,z.b2=t.body,z.ws2=t,z.id=u.id,z.di=E;let d=z.b1.arbiters,b;B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?b=new B._zpp.util.ZNPNode_ZPP_Arbiter:(b=B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b.next,b.next=null),b.elt=z;let C=b;C.next=d.head,d.head=C,d.modified=!0,d.length++;let P=z.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=z;let O=g;O.next=P.head,P.head=O,P.modified=!0,P.length++,z.active=!0,z.present=0,z.cleared=!1,z.sleeping=!1,z.fresh=!1,z.presentable=!1;let N=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=z;let k=M;k.next=N.head,N.head=k,N.modified=!0,N.length++,z.fresh=!f}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&i;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let E=!1,d=z.ws1.id>z.ws2.id?z.ws2:z.ws1,b=z.ws1.id>z.ws2.id?z.ws1:z.ws2,C=this.mrca1;for(;C.head!=null;){let M=C.head;C.head=M.next;let k=M;k.elt=null,k.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k,C.head==null&&(C.pushmod=!0),C.modified=!0,C.length--}C.pushmod=!0;let P=this.mrca2;for(;P.head!=null;){let M=P.head;P.head=M.next;let k=M;k.elt=null,k.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}if(P.pushmod=!0,d.cbSet!=null){let M=this.mrca1,k;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?k=new B._zpp.util.ZNPNode_ZPP_Interactor:(k=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k.next,k.next=null),k.elt=d;let Z=k;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(d.body.cbSet!=null){let M=this.mrca1,k=d.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=k;let A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}if(b.cbSet!=null){let M=this.mrca2,k;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?k=new B._zpp.util.ZNPNode_ZPP_Interactor:(k=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k.next,k.next=null),k.elt=b;let Z=k;Z.next=M.head,M.head=Z,M.modified=!0,M.length++}if(b.body.cbSet!=null){let M=this.mrca2,k=b.body,Z;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?Z=new B._zpp.util.ZNPNode_ZPP_Interactor:(Z=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=Z.next,Z.next=null),Z.elt=k;let A=Z;A.next=M.head,M.head=A,M.modified=!0,M.length++}let g=d.body.compound,O=b.body.compound;for(;g!=O;){let M=g==null?0:g.depth,k=O==null?0:O.depth;if(M<k){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 N=this.mrca1.head;for(;N!=null;){let M=N.elt,k=this.mrca2.head;for(;k!=null;){let Z=k.elt,A=M.cbSet,S=Z.cbSet,R=A.manager,j=null,J=(A.cbpairs.length<S.cbpairs.length?A.cbpairs:S.cbpairs).head;for(;J!=null;){let F=J.elt;if(F.a==A&&F.b==S||F.a==S&&F.b==A){j=F;break}J=J.next}if(j==null){let F;Ve.zpp_pool==null?F=new Ve:(F=Ve.zpp_pool,Ve.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,gt.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),j=F,A.cbpairs.add(j),S!=A&&S.cbpairs.add(j)}if(j.zip_listeners&&(j.zip_listeners=!1,j.__validate()),j.listeners.head==null){k=k.next;continue}let G=null,L=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 Y=null,$=A.manager,H=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){H=F;break}ee=ee.next}if(H==null){let F;Ve.zpp_pool==null?F=new Ve:(F=Ve.zpp_pool,Ve.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,gt.setlt(A,S)?(F.a=A,F.b=S):(F.a=S,F.b=A),H=F,A.cbpairs.add(H),S!=A&&S.cbpairs.add(H)}H.zip_listeners&&(H.zip_listeners=!1,H.__validate());let W=H.listeners.head;for(;W!=null;){let F=W.elt;if(F.event==5&&(F.itype&v)!=0){let D=this.prelisteners,T;B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?T=new B._zpp.util.ZNPNode_ZPP_InteractionListener:(T=B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,B._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=T.next,T.next=null),T.elt=F;let U=T;Y==null?(U.next=D.head,D.head=U):(U.next=Y.next,Y.next=U),D.pushmod=D.modified=!0,D.length++,Y=U,E=E||!F.pure}W=W.next}if(this.prelisteners.head==null){k=k.next;continue}if(G=B._zpp.phys.ZPP_Interactor.get(M,Z),G==null&&(L=cn.get(M,Z),this.add_callbackset(L)),G==null||(G.SENSORstamp!=this.stamp||i)&&(G.SENSORstate&4)==0){if(L!=null&&(G=L),G!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(G.COLLISIONstamp=this.stamp,G.SENSORstamp=this.stamp,G.FLUIDstamp=this.stamp):G.SENSORstamp=this.stamp,U=U.next}let F=z.active;z.active=!0;let D=!1;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=G;let T=this.prelisteners.head;for(;T!=null;){let U=T.elt;this.precb.zpp_inner.listener=U;let Q=this.precb.zpp_inner,K=G.int1,ie=G.int2,oe,se=U.options1,ne=K.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=U.options2,_e=ie.cbTypes;oe=le.nonemptyintersection(_e,le.includes)&&!le.nonemptyintersection(_e,le.excludes)}else oe=!1;oe?(Q.int1=K,Q.int2=ie):(Q.int1=ie,Q.int2=K),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let ae=U.handlerp(this.precb);if(ae!=null){let le;I.PreFlag_ACCEPT==null&&(I.internal=!0,I.PreFlag_ACCEPT=new B._nape.callbacks.PreFlag,I.internal=!1),ae==I.PreFlag_ACCEPT?le=5:(I.PreFlag_ACCEPT_ONCE==null&&(I.internal=!0,I.PreFlag_ACCEPT_ONCE=new B._nape.callbacks.PreFlag,I.internal=!1),ae==I.PreFlag_ACCEPT_ONCE?le=1:(I.PreFlag_IGNORE==null&&(I.internal=!0,I.PreFlag_IGNORE=new B._nape.callbacks.PreFlag,I.internal=!1),le=ae==I.PreFlag_IGNORE?6:2)),z.immState=le}T=T.next}if(z.active=F,G!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(G.COLLISIONstate=z.immState,G.SENSORstate=z.immState,G.FLUIDstate=z.immState):G.SENSORstate=z.immState,U=U.next}}else G==null?(z.immState&4)==0&&(z.immState=1):z.immState=G.SENSORstate;k=k.next}N=N.next}if(E&&(z.immState&4)==0){if(z.b1.type!=1){let M=z.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}if(z.b2.type!=1){let M=z.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}}}if(z.sleeping){z.sleeping=!1;let E=this.s_arbiters,d;B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?d=new B._zpp.util.ZNPNode_ZPP_SensorArbiter:(d=B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,B._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=d.next,d.next=null),d.elt=z;let b=d;b.next=E.head,E.head=b,E.modified=!0,E.length++}l=z}else if(y){let E=z;E.next=Wt.zpp_pool,Wt.zpp_pool=E,l=null}else l=z;else l=z}}return l}MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let r=n.head;n.head=r.next;let o=r;o.elt=null,o.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let r=s.head;s.head=r.next;let o=r;o.elt=null,o.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let r=this.mrca1,o;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_Interactor:(o=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=e;let a=o;a.next=r.head,r.head=a,r.modified=!0,r.length++}if(e.body.cbSet!=null){let r=this.mrca1,o=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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}if(t.cbSet!=null){let r=this.mrca2,o;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_Interactor:(o=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=t;let a=o;a.next=r.head,r.head=a,r.modified=!0,r.length++}if(t.body.cbSet!=null){let r=this.mrca2,o=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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let r=i==null?0:i.depth,o=l==null?0:l.depth;if(r<o){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 r=n.head;n.head=r.next;let o=r;o.elt=null,o.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let r=s.head;s.head=r.next;let o=r;o.elt=null,o.next=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let r=this.mrca1,o;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_Interactor:(o=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=e;let a=o;a.next=r.head,r.head=a,r.modified=!0,r.length++}if(e.body.cbSet!=null){let r=this.mrca1,o=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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}if(t.cbSet!=null){let r=this.mrca2,o;B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new B._zpp.util.ZNPNode_ZPP_Interactor:(o=B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,B._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=t;let a=o;a.next=r.head,r.head=a,r.modified=!0,r.length++}if(t.body.cbSet!=null){let r=this.mrca2,o=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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let r=i==null?0:i.depth,o=l==null?0:l.depth;if(r<o){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 Ki=B;var si=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}};si.zpp_pool=null;var zn=class zn extends ni{constructor(t){super();this.failed=null;this.list=null;this.space=t,this.is_sweep=!0,this.sweep=this}__insert(t){let n;si.zpp_pool==null?n=new si:(n=si.zpp_pool,si.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=si.zpp_pool,si.zpp_pool=s}__sync(t){if(!this.space.continuous&&t.zip_aabb&&t.body!=null)if(t.zip_aabb=!1,t.type==0){let n=t.circle;if(n.zip_worldCOM&&n.body!=null){if(n.zip_worldCOM=!1,n.zip_localCOM){if(n.zip_localCOM=!1,n.type==1){let r=n.polygon;if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(r.lverts.next.next==null)r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;else if(r.lverts.next.next.next==null){r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;let o=1;r.localCOMx+=r.lverts.next.next.x*o,r.localCOMy+=r.lverts.next.next.y*o;let a=.5;r.localCOMx*=a,r.localCOMy*=a}else{r.localCOMx=0,r.localCOMy=0;let o=0,a=r.lverts.next,p=a;a=a.next;let c=a;for(a=a.next;a!=null;){let y=a;o+=c.x*(y.y-p.y);let z=y.y*c.x-y.x*c.y;r.localCOMx+=(c.x+y.x)*z,r.localCOMy+=(c.y+y.y)*z,p=c,c=y,a=a.next}a=r.lverts.next;let h=a;o+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;r.localCOMx+=(c.x+h.x)*u,r.localCOMy+=(c.y+h.y)*u,p=c,c=h,a=a.next;let _=a;o+=c.x*(_.y-p.y);let m=_.y*c.x-_.x*c.y;r.localCOMx+=(c.x+_.x)*m,r.localCOMy+=(c.y+_.y)*m,o=1/(3*o);let x=o;r.localCOMx*=x,r.localCOMy*=x}}n.wrap_localCOM!=null&&(n.wrap_localCOM.zpp_inner.x=n.localCOMx,n.wrap_localCOM.zpp_inner.y=n.localCOMy)}let l=n.body;l.zip_axis&&(l.zip_axis=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot)),n.worldCOMx=n.body.posx+(n.body.axisy*n.localCOMx-n.body.axisx*n.localCOMy),n.worldCOMy=n.body.posy+(n.localCOMx*n.body.axisx+n.localCOMy*n.body.axisy)}let s=n.radius,i=n.radius;n.aabb.minx=n.worldCOMx-s,n.aabb.miny=n.worldCOMy-i,n.aabb.maxx=n.worldCOMx+s,n.aabb.maxy=n.worldCOMy+i}else{let n=t.polygon;if(n.zip_gverts&&n.body!=null){n.zip_gverts=!1,n.validate_lverts();let l=n.body;l.zip_axis&&(l.zip_axis=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot));let r=n.lverts.next,o=n.gverts.next;for(;o!=null;){let a=o,p=r;r=r.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),o=o.next}}if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let s=n.gverts.next;n.aabb.minx=s.x,n.aabb.miny=s.y,n.aabb.maxx=s.x,n.aabb.maxy=s.y;let i=n.gverts.next.next;for(;i!=null;){let l=i;l.x<n.aabb.minx&&(n.aabb.minx=l.x),l.x>n.aabb.maxx&&(n.aabb.maxx=l.x),l.y<n.aabb.miny&&(n.aabb.miny=l.y),l.y>n.aabb.maxy&&(n.aabb.maxy=l.y),i=i.next}}}sync_broadphase(){if(this.space.validation(),this.list!=null){let t=this.list.next;for(;t!=null;){let n=t.next,s=t.prev;if(s!=null&&t.aabb.minx>s.aabb.minx){t=n;continue}for(;s.prev!=null&&s.prev.aabb.minx>t.aabb.minx;)s=s.prev;let i=t.prev;i.next=t.next,t.next!=null&&(t.next.prev=i),s.prev==null?(t.prev=null,this.list=t,t.next=s,s.prev=t):(t.prev=s.prev,s.prev=t,t.prev.next=t,t.next=s),t=n}}}sync_broadphase_fast(){let t=this.list.next;for(;t!=null;){let n=t.next,s=t.prev;if(s!=null&&t.aabb.minx>s.aabb.minx){t=n;continue}for(;s.prev!=null&&s.prev.aabb.minx>t.aabb.minx;)s=s.prev;let i=t.prev;i.next=t.next,t.next!=null&&(t.next.prev=i),s.prev==null?(t.prev=null,this.list=t,t.next=s,s.prev=t):(t.prev=s.prev,s.prev=t,t.prev.next=t,t.next=s),t=n}}broadphase(t,n){if(this.list!=null){let s=this.list.next;for(;s!=null;){let l=s.next,r=s.prev;if(r!=null&&s.aabb.minx>r.aabb.minx){s=l;continue}for(;r.prev!=null&&r.prev.aabb.minx>s.aabb.minx;)r=r.prev;let o=s.prev;o.next=s.next,s.next!=null&&(s.next.prev=o),r.prev==null?(s.prev=null,this.list=s,s.next=r,r.prev=s):(s.prev=r.prev,r.prev=s,s.prev.next=s,s.next=r),s=l}let i=this.list;for(;i!=null;){let l=i.next,r=i.shape,o=r.body,a=i.aabb.maxx;for(;l!=null&&!(l.aabb.minx>a);){let p=l.shape,c=p.body;if(c==o){l=l.next;continue}if(o.type==1&&c.type==1){l=l.next;continue}if(o.component.sleeping&&c.component.sleeping){l=l.next;continue}let h=r.aabb,u=p.aabb;u.miny>h.maxy||h.miny>u.maxy||(n?t.narrowPhase(r,p,o.type!=2||c.type!=2,null,!1):t.continuousEvent(r,p,o.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=pe.get(t,n),r=i??new zn._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.minx>t;)o=o.next;for(;o!=null&&o.aabb.minx<=t;){if(o.aabb.maxx>=t&&o.aabb.miny<=n&&o.aabb.maxy>=n){let p=o.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?Ze.circleContains(p.circle,l)&&r.push(p.outer):Ze.polyContains(p.polygon,l)&&r.push(p.outer))}o=o.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=pe.zpp_pool,pe.zpp_pool=a,r}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l=pe.get(t,n),r=i??new zn._nape.phys.BodyList,o=this.list;for(;o!=null&&o.aabb.minx>t;)o=o.next;for(;o!=null&&o.aabb.minx<=t;){if(o.aabb.maxx>=t&&o.aabb.miny<=n&&o.aabb.maxy>=n){let p=o.shape,c=p.body.outer;if(!r.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?Ze.circleContains(p.circle,l)&&r.push(c):Ze.polyContains(p.polygon,l)&&r.push(c))}}o=o.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=pe.zpp_pool,pe.zpp_pool=a,r}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new zn._nape.shape.ShapeList,a=this.list;for(;a!=null&&a.aabb.maxx<r.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=r.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)Ze.containTest(this.aabbShape.zpp_inner,p)&&o.push(p.outer);else{let h=a.aabb;if(h.minx>=r.minx&&h.miny>=r.miny&&h.maxx<=r.maxx&&h.maxy<=r.maxy)o.push(p.outer);else{let u=a.aabb;r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx&&Ze.testCollide_safe(p,this.aabbShape.zpp_inner)&&o.push(p.outer)}}else{let h;if(s){let u=a.aabb;h=u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy}else{let u=a.aabb;h=r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx}h&&o.push(p.outer)}a=a.next}return o}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new zn._nape.phys.BodyList;this.failed==null&&(this.failed=new zn._nape.phys.BodyList);let a=this.list;for(;a!=null&&a.aabb.maxx<r.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=r.maxx;){let p=a.shape,c=p.body.outer,h=a.aabb;if(r.miny<=h.maxy&&h.miny<=r.maxy&&r.minx<=h.maxx&&h.minx<=r.maxx){let u;if(i!=null){let _=p.filter;u=(_.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&_.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(c)){let _=Ze.containTest(this.aabbShape.zpp_inner,p);!o.has(c)&&_?o.push(c):_||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ze.testCollide_safe(p,this.aabbShape.zpp_inner)&&o.push(c);else if(s){if(!this.failed.has(c)){let _=p.aabb,m=_.minx>=r.minx&&_.miny>=r.miny&&_.maxx<=r.maxx&&_.maxy<=r.maxy;!o.has(c)&&m?o.push(c):m||(o.remove(c),this.failed.push(c))}}else{let _;if(o.has(c))_=!1;else{let m=p.aabb;_=m.minx>=r.minx&&m.miny>=r.miny&&m.maxx<=r.maxx&&m.maxy<=r.maxy}_&&o.push(c)}}a=a.next}return this.failed.clear(),o}shapesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new zn._nape.shape.ShapeList,p=this.list;for(;p!=null&&p.aabb.maxx<o.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=o.maxx;){let c=p.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx){let h=p.shape,u;if(l!=null){let _=h.filter;u=(_.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&_.collisionGroup)!=0}else u=!0;u&&(i?Ze.containTest(this.circShape.zpp_inner,h)&&a.push(h.outer):Ze.testCollide_safe(h,this.circShape.zpp_inner)&&a.push(h.outer))}p=p.next}return a}bodiesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new zn._nape.phys.BodyList;this.failed==null&&(this.failed=new zn._nape.phys.BodyList);let p=this.list;for(;p!=null&&p.aabb.maxx<o.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=o.maxx;){let c=p.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx){let h=p.shape,u=h.body.outer,_;if(l!=null){let m=h.filter;_=(m.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&m.collisionGroup)!=0}else _=!0;if(_)if(i){if(!this.failed.has(u)){let m=Ze.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)&&Ze.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,r=i??new zn._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.maxx<l.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=l.maxx;){let a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=o.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?Ze.containTest(t,p)&&r.push(p.outer):Ze.testCollide_safe(p,t)&&r.push(p.outer))}o=o.next}return r}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new zn._nape.phys.BodyList;this.failed==null&&(this.failed=new zn._nape.phys.BodyList);let o=this.list;for(;o!=null&&o.aabb.maxx<l.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=l.maxx;){let a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=o.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=Ze.containTest(t,p);!r.has(c)&&u?r.push(c):u||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ze.testCollide_safe(t,p)&&r.push(c)}o=o.next}return this.failed.clear(),r}rayCast(t,n,s){this.sync_broadphase(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,r=null;if(t.dirx==0){let 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,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free()}r=u}}}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 _=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.shape.polygon,n,l);if(_!=null){if(_.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=_.zpp_inner.toiDistance,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free()}r=_}}}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,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free()}r=u}}}a=a.next}}let o=i;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=fe.zpp_pool,fe.zpp_pool=o,r}rayMultiCast(t,n,s,i){this.sync_broadphase(),t.validate_dir();let l=t.rayAABB(),r=i??new zn._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,r):t.polysect2(a.shape.polygon,n,r)),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,r):t.polysect2(a.shape.polygon,n,r)),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,r):t.polysect2(a.shape.polygon,n,r)),a=a.next}}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=fe.zpp_pool,fe.zpp_pool=o,r}};zn._zpp=null,zn._nape=null;var gl=zn;function No(w){w.length=0,this.push(w)}var nn=class nn extends ni{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 r=n.polygon;if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(r.lverts.next.next==null)r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;else if(r.lverts.next.next.next==null){r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;let o=1;r.localCOMx+=r.lverts.next.next.x*o,r.localCOMy+=r.lverts.next.next.y*o;let a=.5;r.localCOMx*=a,r.localCOMy*=a}else{r.localCOMx=0,r.localCOMy=0;let o=0,a=r.lverts.next,p=a;a=a.next;let c=a;for(a=a.next;a!=null;){let y=a;o+=c.x*(y.y-p.y);let z=y.y*c.x-y.x*c.y;r.localCOMx+=(c.x+y.x)*z,r.localCOMy+=(c.y+y.y)*z,p=c,c=y,a=a.next}a=r.lverts.next;let h=a;o+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;r.localCOMx+=(c.x+h.x)*u,r.localCOMy+=(c.y+h.y)*u,p=c,c=h,a=a.next;let _=a;o+=c.x*(_.y-p.y);let m=_.y*c.x-_.x*c.y;r.localCOMx+=(c.x+_.x)*m,r.localCOMy+=(c.y+_.y)*m,o=1/(3*o);let x=o;r.localCOMx*=x,r.localCOMy*=x}}n.wrap_localCOM!=null&&(n.wrap_localCOM.zpp_inner.x=n.localCOMx,n.wrap_localCOM.zpp_inner.y=n.localCOMy)}let l=n.body;l.zip_axis&&(l.zip_axis=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot)),n.worldCOMx=n.body.posx+(n.body.axisy*n.localCOMx-n.body.axisx*n.localCOMy),n.worldCOMy=n.body.posy+(n.localCOMx*n.body.axisx+n.localCOMy*n.body.axisy)}let s=n.radius,i=n.radius;n.aabb.minx=n.worldCOMx-s,n.aabb.miny=n.worldCOMy-i,n.aabb.maxx=n.worldCOMx+s,n.aabb.maxy=n.worldCOMy+i}else{let n=t.polygon;if(n.zip_gverts&&n.body!=null){n.zip_gverts=!1,n.validate_lverts();let l=n.body;l.zip_axis&&(l.zip_axis=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot));let r=n.lverts.next,o=n.gverts.next;for(;o!=null;){let a=o,p=r;r=r.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),o=o.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 r=0;r<this.shapes.length;r++){let o=this.shapes[r].aabb;o!=null&&(t+=o.maxx-o.minx,n+=o.maxy-o.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%nn.TUNE_INTERVAL===0)&&this.autoTuneCellSize();let i=this.invCellSize,l=this.grid,r=this.cellPool;l.forEach(No,r),l.clear();let o=this.testedPairs;o.clear();for(let a=0;a<s;a++){let p=this.shapes[a],c=p.aabb,h=p.__shIdx,u=c.minx*i|0,_=c.miny*i|0,m=c.maxx*i|0,x=c.maxy*i|0;if(u===m&&_===x){let z=u*73856093^_*19349663,f=l.get(z);f===void 0&&(f=r.length>0?r.pop():[],l.set(z,f));let v=f.length,E=p.body,d=E.type,b=E.component.sleeping;for(let C=0;C<v;C++){let P=f[C],g=P.body;if(g===E||d===1&&g.type===1||b&&g.component.sleeping)continue;let O=P.aabb;O.miny>c.maxy||c.miny>O.maxy||O.minx>c.maxx||c.minx>O.maxx||(n?t.narrowPhase(p,P,d!==2||g.type!==2,null,!1):t.continuousEvent(p,P,d!==2||g.type!==2,null,!1))}f.push(p)}else for(let z=u;z<=m;z++)for(let f=_;f<=x;f++){let v=z*73856093^f*19349663,E=l.get(v);E===void 0&&(E=r.length>0?r.pop():[],l.set(v,E));let d=E.length,b=p.body,C=b.type,P=b.component.sleeping;for(let g=0;g<d;g++){let O=E[g],N=O.body;if(N===b||C===1&&N.type===1||P&&N.component.sleeping)continue;let M=O.__shIdx,k=h<M?h:M,Z=h<M?M:h,A=Z*Z+k;if(o.has(A))continue;o.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||N.type!==2,null,!1):t.continuousEvent(p,O,C!==2||N.type!==2,null,!1))}E.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=pe.get(t,n),r=i??new nn._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?Ze.circleContains(p.circle,l)&&r.push(p.outer):Ze.polyContains(p.polygon,l)&&r.push(p.outer))}}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=pe.zpp_pool,pe.zpp_pool=o,r}bodiesUnderPoint(t,n,s,i){this.space.validation();let l=pe.get(t,n),r=i??new nn._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(!r.has(h)){let u;if(s!=null){let _=p.filter;u=(_.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&_.collisionGroup)!=0}else u=!0;u&&(p.type==0?Ze.circleContains(p.circle,l)&&r.push(h):Ze.polyContains(p.polygon,l)&&r.push(h))}}}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=pe.zpp_pool,pe.zpp_pool=o,r}shapesInAABB(t,n,s,i,l){this.space.validation(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new nn._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)Ze.containTest(this.aabbShape.zpp_inner,p)&&o.push(p.outer);else{let h=p.aabb;if(h.minx>=r.minx&&h.miny>=r.miny&&h.maxx<=r.maxx&&h.maxy<=r.maxy)o.push(p.outer);else{let u=p.aabb;r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx&&Ze.testCollide_safe(p,this.aabbShape.zpp_inner)&&o.push(p.outer)}}else{let h;if(s){let u=p.aabb;h=u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy}else{let u=p.aabb;h=r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx}h&&o.push(p.outer)}}return o}bodiesInAABB(t,n,s,i,l){this.space.validation(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._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(r.miny<=h.maxy&&h.miny<=r.maxy&&r.minx<=h.maxx&&h.minx<=r.maxx){let u;if(i!=null){let _=p.filter;u=(_.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&_.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(c)){let _=Ze.containTest(this.aabbShape.zpp_inner,p);!o.has(c)&&_?o.push(c):_||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ze.testCollide_safe(p,this.aabbShape.zpp_inner)&&o.push(c);else if(s){if(!this.failed.has(c)){let _=p.aabb,m=_.minx>=r.minx&&_.miny>=r.miny&&_.maxx<=r.maxx&&_.maxy<=r.maxy;!o.has(c)&&m?o.push(c):m||(o.remove(c),this.failed.push(c))}}else{let _;if(o.has(c))_=!1;else{let m=p.aabb;_=m.minx>=r.minx&&m.miny>=r.miny&&m.maxx<=r.maxx&&m.maxy<=r.maxy}_&&o.push(c)}}}return this.failed.clear(),o}shapesInCircle(t,n,s,i,l,r){this.space.validation(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new nn._nape.shape.ShapeList;for(let p=0;p<this.shapes.length;p++){let c=this.shapes[p],h=c.aabb;if(o.miny<=h.maxy&&h.miny<=o.maxy&&o.minx<=h.maxx&&h.minx<=o.maxx){let u;if(l!=null){let _=c.filter;u=(_.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&_.collisionGroup)!=0}else u=!0;u&&(i?Ze.containTest(this.circShape.zpp_inner,c)&&a.push(c.outer):Ze.testCollide_safe(c,this.circShape.zpp_inner)&&a.push(c.outer))}}return a}bodiesInCircle(t,n,s,i,l,r){this.space.validation(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._nape.phys.BodyList);for(let p=0;p<this.shapes.length;p++){let c=this.shapes[p],h=c.aabb;if(o.miny<=h.maxy&&h.miny<=o.maxy&&o.minx<=h.maxx&&h.minx<=o.maxx){let u=c.body.outer,_;if(l!=null){let m=c.filter;_=(m.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&m.collisionGroup)!=0}else _=!0;if(_)if(i){if(!this.failed.has(u)){let m=Ze.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)&&Ze.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,r=i??new nn._nape.shape.ShapeList;for(let o=0;o<this.shapes.length;o++){let a=this.shapes[o],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?Ze.containTest(t,a)&&r.push(a.outer):Ze.testCollide_safe(a,t)&&r.push(a.outer))}}return r}bodiesInShape(t,n,s,i){this.space.validation(),this.validateShape(t);let l=t.aabb,r=i??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._nape.phys.BodyList);for(let o=0;o<this.shapes.length;o++){let a=this.shapes[o],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=Ze.containTest(t,a);!r.has(c)&&u?r.push(c):u||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ze.testCollide_safe(t,a)&&r.push(c)}}return this.failed.clear(),r}rayCast(t,n,s){this.space.validation(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,r=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 _=p.type==0?t.circlesect(p.circle,n,l):t.polysect(p.polygon,n,l);if(_!=null){if(_.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=_.zpp_inner.toiDistance,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free()}r=_}}}}let o=i;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=fe.zpp_pool,fe.zpp_pool=o,r}rayMultiCast(t,n,s,i){this.space.validation(),t.validate_dir();let l=t.rayAABB(),r=i??new nn._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,r):t.polysect2(p.polygon,n,r))}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=fe.zpp_pool,fe.zpp_pool=o,r}};nn._zpp=null,nn._nape=null,nn.TUNE_INTERVAL=120;var Cl=nn;function Yr(){let w={},e={};return w.callbacks={},w.constraint={},w.dynamics={},w.geom={},w.phys={},w.shape={},w.space={},w.util={},e.ZPP_Const=Xi,e.ZPP_ID=On,e.callbacks||(e.callbacks={}),xt._nape=w,xt._zpp=e,e.callbacks.ZPP_Callback=xt,gt._zpp=e,e.callbacks.ZPP_CbSet=gt,Ve._zpp=e,e.callbacks.ZPP_CbSetPair=Ve,e.util||(e.util={}),Kr(e),ut._zpp=e,e.callbacks.ZPP_CbType=ut,e.util.ZPP_Flags=I,Ue._nape=w,Ue._zpp=e,e.callbacks.ZPP_Listener=Ue,e.callbacks.ZPP_BodyListener=_l,e.callbacks.ZPP_ConstraintListener=xl,e.callbacks.ZPP_InteractionListener=es,Gt._nape=w,Gt._zpp=e,e.callbacks.ZPP_OptionType=Gt,e.constraint||(e.constraint={}),ke._nape=w,ke._zpp=e,e.constraint.ZPP_Constraint=ke,e.constraint.ZPP_AngleJoint=We,e.constraint.ZPP_CopyHelper=xi,e.constraint.ZPP_DistanceJoint=Ci,e.constraint.ZPP_LineJoint=Zi,e.constraint.ZPP_MotorJoint=Mi,e.constraint.ZPP_PivotJoint=Ei,e.constraint.ZPP_PulleyJoint=ki,e.constraint.ZPP_UserConstraint=yl,e.constraint.ZPP_UserBody=dl,e.constraint.ZPP_WeldJoint=Ni,e.dynamics||(e.dynamics={}),Ne._nape=w,Ne._zpp=e,e.dynamics.ZPP_Arbiter=Ne,e.dynamics.ZPP_SensorArbiter=Wt,At._nape=w,At._zpp=e,e.dynamics.ZPP_FluidArbiter=At,Pt._nape=w,Pt._zpp=e,e.dynamics.ZPP_ColArbiter=Pt,e.dynamics.ZPP_IContact=ts,we._nape=w,we._zpp=e,e.dynamics.ZPP_Contact=we,pt._nape=w,pt._zpp=e,e.dynamics.ZPP_InteractionFilter=pt,Fi._zpp=e,e.dynamics.ZPP_InteractionGroup=Fi,Oi._nape=w,Oi._zpp=e,e.dynamics.ZPP_SpaceArbiterList=Oi,e.geom||(e.geom={}),fe._nape=w,fe._zpp=e,e.geom.ZPP_AABB=fe,e.geom.ZPP_Collide=Ze,e.geom.ZPP_Convex=ml,e.geom.ZPP_ConvexRayResult=jt,e.geom.ZPP_CutVert=st,e.geom.ZPP_CutInt=dt,e.geom.ZPP_Cutter=fl,e.geom.ZPP_Geom=an,e.geom.ZPP_GeomVert=ge,ge._createVec2Fn=function(){return new w.geom.Vec2},e.geom.ZPP_GeomPoly=bl,e.geom.ZPP_MarchSpan=ei,e.geom.ZPP_MarchPair=ti,Ps._init(e,w),e.geom.ZPP_MarchingSquares=Ps,Gi._nape=w,e.geom.ZPP_Mat23=Gi,e.geom.ZPP_MatMN=ws,e.geom.ZPP_Monotone=$t,e.geom.ZPP_PartitionVertex=Je,e.geom.ZPP_PartitionedPoly=Qe,e.geom.ZPP_Ray=zl,e.geom.ZPP_SimpleVert=Oe,e.geom.ZPP_SimpleSeg=Kt,e.geom.ZPP_SimpleEvent=Me,e.geom.ZPP_SimpleSweep=Zs,e.geom.ZPP_Simple=is,e.geom.ZPP_SimplifyV=Rn,e.geom.ZPP_SimplifyP=Fe,e.geom.ZPP_Simplify=Pl,e.geom.ZPP_ToiEvent=tr,e.geom.ZPP_SweepDistance=mn,e.geom.ZPP_PartitionPair=Jt,e.geom.ZPP_Triangular=qi,e.geom.ZPP_Vec2=pe,Wi._zpp=e,e.geom.ZPP_Vec3=Wi,e.geom.ZPP_VecMath=br,e.phys||(e.phys={}),e.phys.ZPP_Interactor=pn,pn._init(e,w),Gn._init(e,w),e.phys.ZPP_Body=Gn,di._nape=w,di._zpp=e,di._init(),e.phys.ZPP_Compound=di,qn._nape=w,qn._zpp=e,e.phys.ZPP_FluidProperties=qn,Ie._nape=w,Ie._zpp=e,e.phys.ZPP_Material=Ie,e.shape||(e.shape={}),Ji._nape=w,Ji._zpp=e,Ji._init(),e.shape.ZPP_Shape=Ji,Si._nape=w,Si._zpp=e,Si._init(),e.shape.ZPP_Circle=Si,$e._nape=w,$e._zpp=e,e.shape.ZPP_Edge=$e,Un._nape=w,Un._zpp=e,Un._init(),e.shape.ZPP_Polygon=Un,e.space||(e.space={}),ni._zpp=e,ni._nape=w,e.space.ZPP_Broadphase=ni,e.space.ZPP_AABBNode=Be,e.space.ZPP_AABBPair=ct,e.space.ZPP_AABBTree=lt,vl._zpp=e,vl._nape=w,e.space.ZPP_DynAABBPhase=vl,wt._zpp=e,e.space.ZPP_Island=wt,e.space.ZPP_Component=ir,cn._zpp=e,e.space.ZPP_CallbackSet=cn,ks._zpp=e,e.space.ZPP_CbSetManager=ks,Ki._zpp=e,Ki._nape=w,e.space.ZPP_Space=Ki,e.space.ZPP_SweepData=si,gl._zpp=e,gl._nape=w,e.space.ZPP_SweepPhase=gl,Cl._zpp=e,Cl._nape=w,e.space.ZPP_SpatialHashPhase=Cl,e.util.ZNPArray2_Float=rl,e.util.ZNPArray2_ZPP_GeomVert=ol,e.util.ZNPArray2_ZPP_MarchPair=al,e.util.Hashable2_Boolfalse=De,e.util.FastHash2_Hashable2_Boolfalse=ds,e.util.ZPP_Math=fr,e.util.ZPP_PubPool=ue,e.callbacks.ZPP_InteractionListener._initStatics(e),e.geom.ZPP_Collide._initStatics(e),e.space.ZPP_AABBTree._initStatics(),w.__zpp=e,w}var zr;function re(){return zr||(zr=Yr()),zr}var Hr=!1;function li(){if(Hr)return;let w=zr;if(!w?.callbacks?.CbEvent||!w?.callbacks?.CbType||!w?.callbacks?.ListenerType||!w?.dynamics?.ArbiterType||!w?.phys?.BodyType||!w?.shape?.ShapeType)return;Hr=!0;let e=w.__zpp;e.callbacks.ZPP_CbType._initEnums(w),e.callbacks.ZPP_Listener._initEnums(w,e.util.ZPP_Flags),e.dynamics.ZPP_Arbiter._initEnums(w,e.util.ZPP_Flags),e.phys.ZPP_Body._initEnums(w,e.util.ZPP_Flags),e.shape.ZPP_Shape._initEnums(w,e.util.ZPP_Flags)}var Fr={epsilon:1e-8,fluidAngularDragFriction:2.5,fluidAngularDrag:100,fluidVacuumDrag:.5,fluidLinearDrag:.5,collisionSlop:.2,collisionSlopCCD:.5,distanceThresholdCCD:.05,staticCCDLinearThreshold:.05,staticCCDAngularThreshold:.005,bulletCCDLinearThreshold:.125,bulletCCDAngularThreshold:.0125,dynamicSweepLinearThreshold:17,dynamicSweepAngularThreshold:.6,angularCCDSlipScale:.75,arbiterExpirationDelay:6,staticFrictionThreshold:2,elasticThreshold:20,sleepDelay:60,linearSleepThreshold:.2,angularSleepThreshold:.4,contactBiasCoef:.3,contactStaticBiasCoef:.6,contactContinuousBiasCoef:.4,contactContinuousStaticBiasCoef:.5,constraintLinearSlop:.1,constraintAngularSlop:.001,illConditionedThreshold:2e8},Xr=re();Xr.Config=Object.assign(Xr.Config||{},Fr);function be(w,e,t){for(;w[e]!=null;){let n=w[e][t];w[e][t]=null,w[e]=n}}var Pr=class{static version(){return"Nape 2.0.19"}static clearObjectPools(){let e=re(),t=e.__zpp;be(e.constraint.ConstraintIterator,"zpp_pool","zpp_next"),be(e.phys.InteractorIterator,"zpp_pool","zpp_next"),be(e.phys.BodyIterator,"zpp_pool","zpp_next"),be(e.phys.CompoundIterator,"zpp_pool","zpp_next"),be(e.callbacks.ListenerIterator,"zpp_pool","zpp_next"),be(e.callbacks.CbTypeIterator,"zpp_pool","zpp_next"),be(e.geom.ConvexResultIterator,"zpp_pool","zpp_next"),be(e.geom.GeomPolyIterator,"zpp_pool","zpp_next"),be(e.geom.Vec2Iterator,"zpp_pool","zpp_next"),be(e.geom.RayResultIterator,"zpp_pool","zpp_next"),be(e.shape.ShapeIterator,"zpp_pool","zpp_next"),be(e.shape.EdgeIterator,"zpp_pool","zpp_next"),be(e.dynamics.ContactIterator,"zpp_pool","zpp_next"),be(e.dynamics.ArbiterIterator,"zpp_pool","zpp_next"),be(e.dynamics.InteractionGroupIterator,"zpp_pool","zpp_next"),be(t.util.ZNPNode_ZPP_CbType,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_CallbackSet,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Shape,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Body,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Constraint,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Compound,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Arbiter,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_InteractionListener,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_CbSet,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Interactor,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_BodyListener,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_CbSetPair,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_ConstraintListener,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_CutInt,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_CutVert,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_PartitionVertex,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_SimplifyP,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_PartitionedPoly,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_GeomVert,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_SimpleVert,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_SimpleEvent,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Vec2,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_AABBPair,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Edge,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_AABBNode,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Component,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_FluidArbiter,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_SensorArbiter,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_Listener,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_ColArbiter,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_InteractionGroup,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_ToiEvent,"zpp_pool","next"),be(t.util.ZNPNode_ConvexResult,"zpp_pool","next"),be(t.util.ZNPNode_ZPP_GeomPoly,"zpp_pool","next"),be(t.util.ZNPNode_RayResult,"zpp_pool","next"),be(t.phys.ZPP_Material,"zpp_pool","next"),be(t.phys.ZPP_FluidProperties,"zpp_pool","next"),be(t.callbacks.ZPP_CbSetPair,"zpp_pool","next"),be(t.callbacks.ZPP_Callback,"zpp_pool","next"),be(t.callbacks.ZPP_CbSet,"zpp_pool","next"),be(t.geom.ZPP_GeomVert,"zpp_pool","next"),be(t.geom.ZPP_GeomVertexIterator,"zpp_pool","next"),be(t.geom.ZPP_Mat23,"zpp_pool","next"),be(t.geom.ZPP_CutVert,"zpp_pool","next"),be(t.geom.ZPP_CutInt,"zpp_pool","next"),be(t.geom.ZPP_Vec2,"zpp_pool","next"),be(t.geom.ZPP_PartitionVertex,"zpp_pool","next"),be(t.geom.ZPP_SimplifyV,"zpp_pool","next"),be(t.geom.ZPP_SimplifyP,"zpp_pool","next"),be(t.geom.ZPP_PartitionedPoly,"zpp_pool","next"),be(t.geom.ZPP_PartitionPair,"zpp_pool","next"),be(t.geom.ZPP_AABB,"zpp_pool","next"),be(t.geom.ZPP_SimpleVert,"zpp_pool","next"),be(t.geom.ZPP_SimpleSeg,"zpp_pool","next"),be(t.geom.ZPP_SimpleEvent,"zpp_pool","next"),be(t.util.Hashable2_Boolfalse,"zpp_pool","next"),be(t.geom.ZPP_ToiEvent,"zpp_pool","next"),be(t.geom.ZPP_MarchSpan,"zpp_pool","next"),be(t.geom.ZPP_MarchPair,"zpp_pool","next"),be(t.shape.ZPP_Edge,"zpp_pool","next"),be(t.space.ZPP_SweepData,"zpp_pool","next"),be(t.space.ZPP_AABBNode,"zpp_pool","next"),be(t.space.ZPP_AABBPair,"zpp_pool","next"),be(t.dynamics.ZPP_Contact,"zpp_pool","next"),be(t.space.ZPP_Island,"zpp_pool","next"),be(t.space.ZPP_Component,"zpp_pool","next"),be(t.space.ZPP_CallbackSet,"zpp_pool","next"),be(t.dynamics.ZPP_SensorArbiter,"zpp_pool","next"),be(t.dynamics.ZPP_FluidArbiter,"zpp_pool","next"),be(t.dynamics.ZPP_ColArbiter,"zpp_pool","next"),be(t.dynamics.ZPP_InteractionFilter,"zpp_pool","next"),be(t.util.ZPP_Set_ZPP_Body,"zpp_pool","next"),be(t.util.ZPP_Set_ZPP_CbSetPair,"zpp_pool","next"),be(t.util.ZPP_Set_ZPP_PartitionVertex,"zpp_pool","next"),be(t.util.ZPP_Set_ZPP_PartitionPair,"zpp_pool","next"),be(t.util.ZPP_Set_ZPP_SimpleVert,"zpp_pool","next"),be(t.util.ZPP_Set_ZPP_SimpleSeg,"zpp_pool","next"),be(t.util.ZPP_Set_ZPP_SimpleEvent,"zpp_pool","next"),be(t.util.ZPP_Set_ZPP_CbSet,"zpp_pool","next"),be(t.util.ZPP_PubPool,"poolGeomPoly","zpp_pool"),be(t.util.ZPP_PubPool,"poolVec2","zpp_pool"),be(t.util.ZPP_PubPool,"poolVec3","zpp_pool")}};var Qr=new WeakMap;function ze(w,e){if(!w)return null;let t=Qr.get(w);return t||(t=e(w),Qr.set(w,t)),t}var Se=class w{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;pe.zpp_pool==null?n=new pe:(n=pe.zpp_pool,pe.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(ue.poolVec2==null?s=new w:(s=ue.poolVec2,ue.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===ue.nextVec2&&(ue.nextVec2=null)),s.zpp_inner==null){let i;pe.zpp_pool==null?i=new pe:(i=pe.zpp_pool,pe.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 w?e:e?e instanceof pe?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?w._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 w._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 w._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 w._poolGet(s,i,n)}static fromAngle(e,t=!1){return w.fromPolar(1,e,t)}static lerp(e,t,n,s=!1){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot lerp with null Vec2");if(n!==n)throw new Error("Error: Cannot lerp with NaN t");e.zpp_inner.validate(),t.zpp_inner.validate();let i=e.zpp_inner.x+n*(t.zpp_inner.x-e.zpp_inner.x),l=e.zpp_inner.y+n*(t.zpp_inner.y-e.zpp_inner.y),r=w._poolGet(i,l,s);return w._disposeWeak(e),w._disposeWeak(t),r}static eq(e,t,n=0){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null){let r=e==null&&t==null;return e!=null&&w._disposeWeak(e),t!=null&&w._disposeWeak(t),r}e.zpp_inner.validate(),t.zpp_inner.validate();let s=e.zpp_inner.x-t.zpp_inner.x,i=e.zpp_inner.y-t.zpp_inner.y,l=(s<0?-s:s)<=n&&(i<0?-i:i)<=n;return w._disposeWeak(e),w._disposeWeak(t),l}static dsq(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,s=e.zpp_inner.y;t.zpp_inner.validate();let i=t.zpp_inner.x,l=t.zpp_inner.y,r=n-i,o=s-l,a=r*r+o*o;return w._disposeWeak(e),w._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,r=n-i,o=s-l,a=Math.sqrt(r*r+o*o);return w._disposeWeak(e),w._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),w._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 w._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=w._poolGet(n,s,!0);i.normalise();let l=e.sub(i.muleq(2*i.dot(e)),t);return w._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 w._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=w._poolGet(n,s,t);return w._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=w._poolGet(s,i,n);return w._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=w._poolGet(n,s,t);return w._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 w._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),w._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),w._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 w._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 w._disposeWeak(e),t}perp(e=!1){this._checkDisposed(),this._validate();let t=-this.zpp_inner.y,n=this.zpp_inner.x;return w._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,ue.nextVec2!=null?ue.nextVec2.zpp_pool=this:ue.poolVec2=this,ue.nextVec2=this,this.zpp_disp=!0,e.free(),e.next=pe.zpp_pool,pe.zpp_pool=e}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};pe._wrapFn=w=>ze(w,e=>{let t=Object.create(Se.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Oo=re();Oo.geom.Vec2=Se;var Xe=class w{constructor(e=0,t=0,n=0){this.zpp_pool=null;this.zpp_disp=!1;let s=new Wi;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 w?e:e?e instanceof Wi?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?w._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=0){let s;return ue.poolVec3==null?s=new w:(s=ue.poolVec3,ue.poolVec3=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===ue.nextVec3&&(ue.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(),w.get(this.zpp_inner.x,this.zpp_inner.y,this.zpp_inner.z)}xy(e=!1){return this._checkDisposed(),this.zpp_inner.validate(),Se.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,ue.nextVec3!=null?ue.nextVec3.zpp_pool=this:ue.poolVec3=this,ue.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+" }"}};Wi._wrapFn=w=>ze(w,e=>{let t=Object.create(Xe.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Ns=class w{get _inner(){return this}constructor(e=1,t=0,n=0,s=1,i=0,l=0){let r=Gi.get();this.zpp_inner=r,r.outer=this;let o=["a","b","tx","c","d","ty"],a=[e,t,i,n,s,l];for(let p=0;p<a.length;p++)if(a[p]!==a[p])throw new Error("Error: Mat23::"+o[p]+" cannot be NaN");r.setas(e,t,n,s,i,l)}static rotation(e){if(e!==e)throw new Error("Error: Cannot create rotation matrix with NaN angle");let t=Math.cos(e),n=Math.sin(e);return new w(t,-n,n,t,0,0)}static translation(e,t){return new w(1,0,0,1,e,t)}static scale(e,t){return new w(e,0,0,t,0,0)}static _wrap(e){return e instanceof w?e:e?e instanceof Gi?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?w._wrap(e.zpp_inner):null:null}_setProp(e,t){if(t!==t)throw new Error("Error: Mat23::"+e+" cannot be NaN");this.zpp_inner[e]=t,this.zpp_inner.invalidate()}get a(){return this.zpp_inner.a}set a(e){this._setProp("a",e)}get b(){return this.zpp_inner.b}set b(e){this._setProp("b",e)}get c(){return this.zpp_inner.c}set c(e){this._setProp("c",e)}get d(){return this.zpp_inner.d}set d(e){this._setProp("d",e)}get tx(){return this.zpp_inner.tx}set tx(e){this._setProp("tx",e)}get ty(){return this.zpp_inner.ty}set ty(e){this._setProp("ty",e)}get determinant(){return this.zpp_inner.a*this.zpp_inner.d-this.zpp_inner.b*this.zpp_inner.c}clone(){return this.copy()}equals(e,t=0){if(e==null)return!1;let n=this.zpp_inner,s=e.zpp_inner,i=n.a-s.a,l=n.b-s.b,r=n.c-s.c,o=n.d-s.d,a=n.tx-s.tx,p=n.ty-s.ty;return(i<0?-i:i)<=t&&(l<0?-l:l)<=t&&(r<0?-r:r)<=t&&(o<0?-o:o)<=t&&(a<0?-a:a)<=t&&(p<0?-p:p)<=t}copy(){return new w(this.zpp_inner.a,this.zpp_inner.b,this.zpp_inner.c,this.zpp_inner.d,this.zpp_inner.tx,this.zpp_inner.ty)}set(e){if(e==null)throw new Error("Error: Cannot set form null matrix");let t=e.zpp_inner;return this.zpp_inner.setas(t.a,t.b,t.c,t.d,t.tx,t.ty),this.zpp_inner.invalidate(),this}setAs(e=1,t=0,n=0,s=1,i=0,l=0){return this.zpp_inner.setas(e,t,n,s,i,l),this.zpp_inner.invalidate(),this}reset(){return this.setAs()}singular(){let{a:e,b:t,c:n,d:s}=this.zpp_inner,i=e*e+t*t+n*n+s*s,l=e*s-t*n;l<0&&(l=-l);let r=re();return i>r.Config.illConditionedThreshold*l}inverse(){if(this.singular())throw new Error("Error: Matrix is singular and cannot be inverted");let{a:e,b:t,c:n,d:s,tx:i,ty:l}=this.zpp_inner,r=1/(e*s-t*n);return new w(s*r,-t*r,-n*r,e*r,(t*l-s*i)*r,(n*i-e*l)*r)}transpose(){let{a:e,b:t,c:n,d:s,tx:i,ty:l}=this.zpp_inner;return new w(e,n,t,s,-e*i-n*l,-t*i-s*l)}concat(e){if(e==null)throw new Error("Error: Cannot concatenate with null Mat23");let t=e.zpp_inner,n=this.zpp_inner;return new w(t.a*n.a+t.b*n.c,t.a*n.b+t.b*n.d,t.c*n.a+t.d*n.c,t.c*n.b+t.d*n.d,t.a*n.tx+t.b*n.ty+t.tx,t.c*n.tx+t.d*n.ty+t.ty)}transform(e,t=!1,n=!1){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 transform null Vec2");e.zpp_inner.validate();let s=e.zpp_inner.x,i=e.zpp_inner.y,{a:l,b:r,c:o,d:a,tx:p,ty:c}=this.zpp_inner,h,u;t?(h=s*l+i*r,u=s*o+i*a):(h=s*l+i*r+p,u=s*o+i*a+c);let _=Se.get(h,u,n);return e.zpp_inner.weak&&e.dispose(),_}inverseTransform(e,t=!1,n=!1){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 transform null Vec2");if(this.singular())throw new Error("Error: Matrix is singular and inverse transformation cannot be performed");let{a:s,b:i,c:l,d:r,tx:o,ty:a}=this.zpp_inner,p=1/(s*r-i*l);e.zpp_inner.validate();let c=e.zpp_inner.x,h=e.zpp_inner.y,u,_;if(t)u=(c*r-h*i)*p,_=(h*s-c*l)*p;else{let x=c-o,y=h-a;u=(x*r-y*i)*p,_=(y*s-x*l)*p}let m=Se.get(u,_,n);return e.zpp_inner.weak&&e.dispose(),m}equiorthogonal(){if(this.singular())return!1;let{a:e,b:t,c:n,d:s}=this.zpp_inner,i=re(),l=e*t+n*s;if(l*l>=i.Config.epsilon)return!1;let r=e*e+t*t-n*n-s*s;return r*r<i.Config.epsilon}orthogonal(){let{a:e,b:t,c:n,d:s}=this.zpp_inner,i=re(),l=e*t+n*s;if(l*l>=i.Config.epsilon)return!1;let r=e*e+t*t-1,o=n*n+s*s-1;return r*r<i.Config.epsilon&&o*o<i.Config.epsilon}_orthogonaliseImpl(e){let{a:t,b:n,c:s,d:i}=this.zpp_inner,l=re(),r=Math.sqrt(t*t+s*s),o=Math.sqrt(n*n+i*i);if(r*r<l.Config.epsilon||o*o<l.Config.epsilon)throw new Error("Error: Matrix is singular and cannot be "+(e?"equiorthogonal":"orthogonal")+"ised");let a=e?(r+o)/2:1;r=a/r,o=a/o,this.a=this.zpp_inner.a*r,this.c=this.zpp_inner.c*r,this.b=this.zpp_inner.b*o,this.d=this.zpp_inner.d*o;let p=this.zpp_inner.a*this.zpp_inner.b+this.zpp_inner.c*this.zpp_inner.d,c=.25*Math.PI-.5*Math.acos(p/(a*a));this.zpp_inner.a*this.zpp_inner.d-this.zpp_inner.b*this.zpp_inner.c>0&&(c=-c);let h=Math.sin(c),u=Math.cos(c),_=this.zpp_inner.a*u-this.zpp_inner.c*h,m=this.zpp_inner.b*u+this.zpp_inner.d*h,x=this.zpp_inner.c*u+this.zpp_inner.a*h,y=this.zpp_inner.d*u-this.zpp_inner.b*h;return this.c=x,this.a=_,this.d=y,this.b=m,this.zpp_inner.invalidate(),this}equiorthogonalise(){return this.equiorthogonal()?this:this._orthogonaliseImpl(!0)}orthogonalise(){return this.orthogonal()?this:this._orthogonaliseImpl(!1)}toString(){let{a:e,b:t,c:n,d:s,tx:i,ty:l}=this.zpp_inner;return"{ a: "+e+" b: "+t+" c: "+n+" d: "+s+" tx: "+i+" ty: "+l+" }"}};Gi._wrapFn=w=>ze(w,e=>{let t=Object.create(Ns.prototype);return t.zpp_inner=e,e.outer=t,t});var yi=class w{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 ws(e,t),this.zpp_inner.outer=this}static _wrap(e){return e instanceof w?e:e?e instanceof ws?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?w._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 w(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 w(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 w(this.zpp_inner.m,t.zpp_inner.n);for(let s=0;s<this.zpp_inner.m;s++)for(let i=0;i<t.zpp_inner.n;i++){let l=0;for(let r=0;r<this.zpp_inner.n;r++)l+=this.zpp_inner.x[s*this.zpp_inner.n+r]*t.zpp_inner.x[r*t.zpp_inner.n+i];n.zpp_inner.x[s*n.zpp_inner.n+i]=l}return n}},So=re();So.geom.MatMN=yi;var Kn=class w{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;fe.zpp_pool==null?i=new fe:(i=fe.zpp_pool,fe.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=t,i.maxx=e+n,i.maxy=t+s,this.zpp_inner=i,i.outer=this}static fromPoints(e){if(e==null||e.length===0)throw new Error("Error: AABB::fromPoints requires at least one point");let t=e[0];if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");t.zpp_inner.validate();let n=t.zpp_inner.x,s=t.zpp_inner.y,i=n,l=s;for(let r=1;r<e.length;r++){let o=e[r];if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(o==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");o.zpp_inner.validate();let a=o.zpp_inner.x,p=o.zpp_inner.y;a<n&&(n=a),p<s&&(s=p),a>i&&(i=a),p>l&&(l=p)}return new w(n,s,i-n,l-s)}static _wrap(e){return e instanceof w?e:e?e instanceof fe?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?w._wrap(e.zpp_inner):null:null}get x(){return this.zpp_inner.validate(),this.zpp_inner.minx}set x(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::x cannot be NaN");this.zpp_inner.maxx+=e-this.zpp_inner.minx,this.zpp_inner.minx=e,this.zpp_inner.invalidate()}}get y(){return this.zpp_inner.validate(),this.zpp_inner.miny}set y(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::y cannot be NaN");this.zpp_inner.maxy+=e-this.zpp_inner.miny,this.zpp_inner.miny=e,this.zpp_inner.invalidate()}}get width(){return this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx}set width(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::width cannot be NaN");if(e<0)throw new Error("Error: AABB::width ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxx=this.zpp_inner.minx+e,this.zpp_inner.invalidate()}}get height(){return this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny}set height(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::height cannot be NaN");if(e<0)throw new Error("Error: AABB::height ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxy=this.zpp_inner.miny+e,this.zpp_inner.invalidate()}}get min(){return this.zpp_inner.getmin(),this.zpp_inner.wrap_min}set min(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::min");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::min components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::min components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let s=e.zpp_inner.x;this.zpp_inner.getmax();let i=this.zpp_inner.wrap_max;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),s>i.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.y;this.zpp_inner.getmin();let r=this.zpp_inner.wrap_max;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(r.zpp_inner._validate!=null&&r.zpp_inner._validate(),l>r.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let o=this.zpp_inner.wrap_min;this._assignVec2(o,e),e.zpp_inner.weak&&this._disposeVec2(e)}get max(){return this.zpp_inner.getmax(),this.zpp_inner.wrap_max}set max(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::max");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::max components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::max components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let s=e.zpp_inner.x;this.zpp_inner.getmin();let i=this.zpp_inner.wrap_min;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),s<i.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.y;this.zpp_inner.getmin();let r=this.zpp_inner.wrap_min;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(r.zpp_inner._validate!=null&&r.zpp_inner._validate(),l<r.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let o=this.zpp_inner.wrap_max;this._assignVec2(o,e),e.zpp_inner.weak&&this._disposeVec2(e)}_assignVec2(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=e.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t==null)throw new Error("Error: Cannot assign null Vec2");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let s=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let i=t.zpp_inner.y;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e.zpp_inner._validate!=null&&e.zpp_inner._validate(),e.zpp_inner.x==s){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate(),r=e.zpp_inner.y==i}else r=!1;r||(e.zpp_inner.x=s,e.zpp_inner.y=i,e.zpp_inner._invalidate!=null&&e.zpp_inner._invalidate(e.zpp_inner))}_disposeVec2(e){let n=re().zpp_nape;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=e.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let i=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let l=e;l.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=l:n.util.ZPP_PubPool.poolVec2=l,n.util.ZPP_PubPool.nextVec2=l,l.zpp_disp=!0;let r=i;r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r}clone(){return this.copy()}equals(e,t=0){if(e==null)return!1;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.minx-e.zpp_inner.minx,s=this.zpp_inner.miny-e.zpp_inner.miny,i=this.zpp_inner.maxx-e.zpp_inner.maxx,l=this.zpp_inner.maxy-e.zpp_inner.maxy;return(n<0?-n:n)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t&&(l<0?-l:l)<=t}copy(){this.zpp_inner.validate();let e=this.zpp_inner;return fe.get(e.minx,e.miny,e.maxx,e.maxy).wrapper()}toString(){return this.zpp_inner.validate(),this.zpp_inner.toString()}};fe._wrapFn=w=>ze(w,e=>{let t=Object.create(Kn.prototype);return t.zpp_inner=e,e.outer=t,t});var Os=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate Winding derp!")}static get UNDEFINED(){return I.Winding_UNDEFINED==null&&(I.internal=!0,I.Winding_UNDEFINED=new w,I.internal=!1),I.Winding_UNDEFINED}static get CLOCKWISE(){return I.Winding_CLOCKWISE==null&&(I.internal=!0,I.Winding_CLOCKWISE=new w,I.internal=!1),I.Winding_CLOCKWISE}static get ANTICLOCKWISE(){return I.Winding_ANTICLOCKWISE==null&&(I.internal=!0,I.Winding_ANTICLOCKWISE=new w,I.internal=!1),I.Winding_ANTICLOCKWISE}toString(){return this===I.Winding_UNDEFINED?"UNDEFINED":this===I.Winding_CLOCKWISE?"CLOCKWISE":this===I.Winding_ANTICLOCKWISE?"ANTICLOCKWISE":""}},Ao=re();Ao.geom.Winding=Os;function wr(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.x}function vr(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Zl(w){w.zpp_inner.weak&&w.dispose()}var Ai=class w{get _inner(){return this}constructor(e,t){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Ray::origin cannot be null");if(t?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: Ray::direction cannot be null");let n=new zl;this.zpp_inner=n;let s=wr(e),i=vr(e);n.origin.zpp_inner.x=s,n.origin.zpp_inner.y=i,n.origin.zpp_inner._invalidate!=null&&n.origin.zpp_inner._invalidate(n.origin.zpp_inner),Zl(e);let l=wr(t),r=vr(t);n.direction.zpp_inner.x=l,n.direction.zpp_inner.y=r,n.direction.zpp_inner._invalidate!=null&&n.direction.zpp_inner._invalidate(n.direction.zpp_inner),Zl(t),n.zip_dir=!0,n.maxdist=1/0}static _wrap(e){return e==null?null:e instanceof w?e:ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t.zpp_inner??t,n})}static fromSegment(e,t){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Ray::fromSegment::start is null");if(t?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: Ray::fromSegment::end is null");let n=t.sub(e,!0),s=new w(e,n),i=wr(e),l=vr(e),r=wr(t),o=vr(t),a=r-i,p=o-l,c=Math.sqrt(a*a+p*p);if(c!==c)throw new Error("Error: maxDistance cannot be NaN");return s.zpp_inner.maxdist=c,Zl(e),Zl(t),s}get origin(){return this.zpp_inner.origin}set origin(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Ray::origin cannot be null");this.zpp_inner.origin.set(e),Zl(e)}get direction(){return this.zpp_inner.direction}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: Ray::direction cannot be null");this.zpp_inner.direction.set(e),this.zpp_inner.zip_dir=!0,Zl(e)}get maxDistance(){return this.zpp_inner.maxdist}set maxDistance(e){if(e!==e)throw new Error("Error: maxDistance cannot be NaN");this.zpp_inner.maxdist=e}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}aabb(){return Kn._wrap(this.zpp_inner.rayAABB())}at(e,t=!1){this.zpp_inner.validate_dir();let n=this.zpp_inner.origin.zpp_inner;n._validate!=null&&n._validate();let s=n.x,i=n.y,l=s+e*this.zpp_inner.dirx,r=i+e*this.zpp_inner.diry;return Se.get(l,r,t)}clone(){return this.copy()}copy(){let e=new w(this.zpp_inner.origin,this.zpp_inner.direction),t=this.zpp_inner.maxdist;if(t!==t)throw new Error("Error: maxDistance cannot be NaN");return e.zpp_inner.maxdist=t,e}};var Ss=class w{get _inner(){return this}constructor(){if(this.zpp_inner=null,!jt.internal)throw new Error("Error: ConvexResult cannot be instantiated derp!")}static _wrap(e){if(!e)return null;if(e instanceof w)return e;let t=e.zpp_inner??e;return ze(t,n=>{let s=Object.create(w.prototype);return s.zpp_inner=n,s})}get normal(){return this._disposed(),Se._wrap(this.zpp_inner.normal)}get position(){return this._disposed(),Se._wrap(this.zpp_inner.position)}get toi(){return this._disposed(),this.zpp_inner.toiDistance}get shape(){return this._disposed(),this.zpp_inner.shape}dispose(){this._disposed(),this.zpp_inner.free()}toString(){return this._disposed(),"{ shape: "+String(this.zpp_inner.shape)+" toi: "+this.zpp_inner.toiDistance+" }"}_disposed(){if(this.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used")}};jt._createConvexResult=()=>new Ss;var As=class w{get _inner(){return this}constructor(){if(this.zpp_inner=null,!jt.internal)throw new Error("Error: RayResult cannot be instantiated derp!")}static _wrap(e){if(!e)return null;if(e instanceof w)return e;let t=e.zpp_inner??e;return ze(t,n=>{let s=Object.create(w.prototype);return s.zpp_inner=n,s})}get normal(){return this._disposed(),Se._wrap(this.zpp_inner.normal)}get distance(){return this._disposed(),this.zpp_inner.toiDistance}get inner(){return this._disposed(),this.zpp_inner.inner}get shape(){return this._disposed(),this.zpp_inner.shape}dispose(){this._disposed(),this.zpp_inner.free()}toString(){return this._disposed(),"{ shape: "+String(this.zpp_inner.shape)+" distance: "+this.zpp_inner.toiDistance+" ?inner: "+String(this.zpp_inner.inner)+" }"}_disposed(){if(this.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used")}};jt._createRayResult=()=>new As;function Vs(w){return w?.zpp_inner??w?._inner?.zpp_inner}function gr(w){return w?.zpp_inner??w?._inner?.zpp_inner}function Cr(w,e){if(w!=null&&w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=w.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");t._isimmutable!=null&&t._isimmutable()}function Ml(w,e){if(Vs(w)?.body?.outer==null)throw new Error(`Error: Shape must be part of a Body to calculate ${e}`)}var El=class{static distanceBody(e,t,n,s){Cr(n,"out1"),Cr(s,"out2");let i=gr(e),l=gr(t);if(i.shapes.head==null||l.shapes.head==null)throw new Error("Error: Bodies cannot be empty in calculating distances");let r=i.shapes.head;for(;r!=null;)an.validateShape(r.elt),r=r.next;for(r=l.shapes.head;r!=null;)an.validateShape(r.elt),r=r.next;return mn.distanceBody(i,l,n.zpp_inner,s.zpp_inner)}static distance(e,t,n,s){Cr(n,"out1"),Cr(s,"out2"),Ml(e,"distances"),Ml(t,"distances");let i=Vs(e),l=Vs(t);an.validateShape(i),an.validateShape(l);let r;pe.zpp_pool==null?r=new pe:(r=pe.zpp_pool,pe.zpp_pool=r.next,r.next=null),r.weak=!1;let o=mn.distance(i,l,n.zpp_inner,s.zpp_inner,r,1e100);return r.next=pe.zpp_pool,pe.zpp_pool=r,o}static intersectsBody(e,t){let n=gr(e),s=gr(t);if(n.shapes.head==null||s.shapes.head==null)throw new Error("Error: Bodies must have shapes to test for intersection.");let i=n.shapes.head;for(;i!=null;)an.validateShape(i.elt),i=i.next;for(i=s.shapes.head;i!=null;)an.validateShape(i.elt),i=i.next;let l=n.aabb,r=s.aabb;if(l.minx>r.maxx||l.maxx<r.minx||l.miny>r.maxy||l.maxy<r.miny)return!1;let o=n.shapes.head;for(;o!=null;){let a=s.shapes.head;for(;a!=null;){if(Ze.testCollide_safe(o.elt,a.elt))return!0;a=a.next}o=o.next}return!1}static intersects(e,t){Ml(e,"intersection"),Ml(t,"intersection");let n=Vs(e),s=Vs(t);an.validateShape(n),an.validateShape(s);let i=n.aabb,l=s.aabb;return i.minx>l.maxx||i.maxx<l.minx||i.miny>l.maxy||i.maxy<l.miny?!1:Ze.testCollide_safe(n,s)}static contains(e,t){Ml(e,"containment"),Ml(t,"containment");let n=Vs(e),s=Vs(t);return an.validateShape(n),an.validateShape(s),Ze.containTest(n,s)}};var Vi=class Vi{constructor(){this.ptr=null;this.start=null;this.first=!1;this.forward=!1;this.outer=null;this.next=null;Vi.internal=!0;let e=re();this.outer=new e.geom.GeomVertexIterator,Vi.internal=!1}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.outer.zpp_inner=n,n.ptr=e,n.forward=t,n.start=e,n.first=e!=null,n.outer}free(){this.outer.zpp_inner=null,this.ptr=this.start=null}alloc(){}};Vi.zpp_pool=null,Vi.internal=!1;var ri=Vi;var Ii=class w{constructor(e){this.zpp_pool=null;this.zpp_disp=!1;this.zpp_inner=new bl(this),e!=null&&(w._addVertices(this,e),this.skipForward(1),w._disposeWeakInputs(e))}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: GeomPoly has been disposed and cannot be used!")}static _createVert(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 _pushVert(e,t){e.zpp_inner.vertices==null?e.zpp_inner.vertices=t.prev=t.next=t:(t.prev=e.zpp_inner.vertices,t.next=e.zpp_inner.vertices.next,e.zpp_inner.vertices.next.prev=t,e.zpp_inner.vertices.next=t),e.zpp_inner.vertices=t}static _unshiftVert(e,t){e.zpp_inner.vertices==null?e.zpp_inner.vertices=t.prev=t.next=t:(t.next=e.zpp_inner.vertices,t.prev=e.zpp_inner.vertices.prev,e.zpp_inner.vertices.prev.next=t,e.zpp_inner.vertices.prev=t),e.zpp_inner.vertices=t}static _freeVert(e){e.free(),e.next=ge.zpp_pool,ge.zpp_pool=e}_popHead(){let e=this.zpp_inner.vertices;if(e.prev===e)e.next=e.prev=null,this.zpp_inner.vertices=null;else{let t=e.prev;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null,this.zpp_inner.vertices=t}return e}_shiftHead(){let e=this.zpp_inner.vertices;if(e.prev===e)e.next=e.prev=null,this.zpp_inner.vertices=null;else{let t=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null,this.zpp_inner.vertices=t}return e}_isDegenRing(){let e=this.zpp_inner.vertices;return e==null||e.next==null||e.prev===e.next}_forEachVert(e){let t=this.zpp_inner.vertices;if(t!=null){let n=t;do e(n),n=n.next;while(n!==t)}}_extremalVert(e,t){if(this._checkDisposed(),this.zpp_inner.vertices==null){let i=t?e==="y"?"topmost":"leftmost":e==="y"?"bottommost":"rightmost";throw new Error("Error: empty GeomPoly has no defineable "+i+" vertex")}let n=this.zpp_inner.vertices,s=n.next;for(;s!==this.zpp_inner.vertices;)(t?s[e]<n[e]:s[e]>n[e])&&(n=s),s=s.next;return n.wrapper()}static _addVertices(e,t){let n=re();if(t instanceof Array)for(let s=0;s<t.length;s++){let i=t[s];if(i==null)throw new Error("Error: Array<Vec2> contains null objects");if(!(i instanceof Se))throw new Error("Error: Array<Vec2> contains non Vec2 objects");let l=i;if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");l.zpp_inner.validate();let r=l.zpp_inner.x;l.zpp_inner.validate();let o=l.zpp_inner.y,a=w._createVert(r,o);w._pushVert(e,a)}else if(t instanceof n.geom.Vec2List){let s=t.iterator();for(;s.hasNext();){let i=s.next();if(i==null)throw new Error("Error: Vec2List contains null objects");if(i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.zpp_inner.validate();let l=i.zpp_inner.x;i.zpp_inner.validate();let r=i.zpp_inner.y,o=w._createVert(l,r);w._pushVert(e,o)}}else if(t instanceof w){if(t.zpp_disp)throw new Error("Error: GeomPoly has been disposed and cannot be used!");let s=t.zpp_inner.vertices;if(s!=null){let i=s;do{let l=w._createVert(i.x,i.y);w._pushVert(e,l),i=i.next}while(i!==s)}}else throw new Error("Error: Invalid type for polygon object, should be Array<Vec2>, Vec2List, GeomPoly or for flash10+ flash.Vector<Vec2>")}static _disposeWeakInputs(e){if(e instanceof Array){let t=0;for(;t<e.length;){let n=e[t];n.zpp_inner&&n.zpp_inner.weak?(n.dispose(),e.splice(t,1)):t++}}else if(e instanceof re().geom.Vec2List){let t=e;t.zpp_inner._validate!=null&&t.zpp_inner._validate();let n=t.zpp_inner.inner,s=null,i=n.head;for(;i!=null;){let l=i.elt;l.outer&&l.outer.zpp_inner&&l.outer.zpp_inner.weak?(i=n.erase(s),l.outer.zpp_inner.weak&&l.outer.dispose()):(s=i,i=i.next)}}}static get(e){let t;return ue.poolGeomPoly==null?t=new w:(t=ue.poolGeomPoly,ue.poolGeomPoly=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t===ue.nextGeomPoly&&(ue.nextGeomPoly=null)),e!=null&&(w._addVertices(t,e),t.skipForward(1),w._disposeWeakInputs(e)),t}empty(){return this._checkDisposed(),this.zpp_inner.vertices==null}size(){this._checkDisposed();let e=0;return this._forEachVert(()=>e++),e}iterator(){return this._checkDisposed(),ri.get(this.zpp_inner.vertices,!0)}forwardIterator(){return this._checkDisposed(),ri.get(this.zpp_inner.vertices,!0)}backwardsIterator(){return this._checkDisposed(),ri.get(this.zpp_inner.vertices,!1)}current(){if(this._checkDisposed(),this.zpp_inner.vertices==null)throw new Error("Error: GeomPoly is empty");return this.zpp_inner.vertices.wrapper()}push(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 push null vertex");e.zpp_inner.validate();let t=e.zpp_inner.x;e.zpp_inner.validate();let n=e.zpp_inner.y,s=w._createVert(t,n);return w._pushVert(this,s),e.zpp_inner.weak&&e.dispose(),this}pop(){if(this._checkDisposed(),this.zpp_inner.vertices==null)throw new Error("Error: Cannot pop from empty polygon");let e=this._popHead();return w._freeVert(e),this}unshift(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 unshift null vertex");e.zpp_inner.validate();let t=e.zpp_inner.x;e.zpp_inner.validate();let n=e.zpp_inner.y,s=w._createVert(t,n);return w._unshiftVert(this,s),e.zpp_inner.weak&&e.dispose(),this}shift(){if(this._checkDisposed(),this.zpp_inner.vertices==null)throw new Error("Error: Cannot shift from empty polygon");let e=this._shiftHead();return w._freeVert(e),this}skipForward(e){if(this._checkDisposed(),this.zpp_inner.vertices!=null){if(e>0)for(;e-- >0;)this.zpp_inner.vertices=this.zpp_inner.vertices.next;else if(e<0)for(;e++<0;)this.zpp_inner.vertices=this.zpp_inner.vertices.prev}return this}skipBackwards(e){return this._checkDisposed(),this.skipForward(-e)}erase(e){for(this._checkDisposed();e!==0&&this.zpp_inner.vertices!=null;){let t;e>0?(t=this._shiftHead(),--e):(t=this._popHead(),++e),w._freeVert(t)}return this}clear(){for(this._checkDisposed();this.zpp_inner.vertices!=null;){let e=this._shiftHead();w._freeVert(e)}return this}copy(){this._checkDisposed();let e=w.get();return this._forEachVert(t=>{let n=w._createVert(t.x,t.y);w._pushVert(e,n)}),e.skipForward(1)}dispose(){if(this.zpp_disp)throw new Error("Error: GeomPoly has been disposed and cannot be used!");this.clear(),this.zpp_pool=null,ue.nextGeomPoly!=null?ue.nextGeomPoly.zpp_pool=this:ue.poolGeomPoly=this,ue.nextGeomPoly=this,this.zpp_disp=!0}area(){if(this._checkDisposed(),this._isDegenRing())return 0;let e=0;this._forEachVert(n=>{e+=n.x*(n.next.y-n.prev.y)});let t=e*.5;return t<0?-t:t}winding(){if(this._checkDisposed(),this._isDegenRing())return I.Winding_UNDEFINED==null&&(I.internal=!0,I.Winding_UNDEFINED=new(re()).geom.Winding,I.internal=!1),I.Winding_UNDEFINED;let e=0;this._forEachVert(n=>{e+=n.x*(n.next.y-n.prev.y)});let t=e*.5;return t>0?(I.Winding_CLOCKWISE==null&&(I.internal=!0,I.Winding_CLOCKWISE=new(re()).geom.Winding,I.internal=!1),I.Winding_CLOCKWISE):t===0?(I.Winding_UNDEFINED==null&&(I.internal=!0,I.Winding_UNDEFINED=new(re()).geom.Winding,I.internal=!1),I.Winding_UNDEFINED):(I.Winding_ANTICLOCKWISE==null&&(I.internal=!0,I.Winding_ANTICLOCKWISE=new(re()).geom.Winding,I.internal=!1),I.Winding_ANTICLOCKWISE)}contains(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: GeomPoly::contains point cannot be null");e.zpp_inner.validate();let t=e.zpp_inner.x;e.zpp_inner.validate();let n=e.zpp_inner.y,s=!1;return this._forEachVert(i=>{let l=i.prev;(i.y<n&&l.y>=n||l.y<n&&i.y>=n)&&(i.x<=t||l.x<=t)&&i.x+(n-i.y)/(l.y-i.y)*(l.x-i.x)<t&&(s=!s)}),e.zpp_inner.weak&&e.dispose(),s}isClockwise(){let e=this.winding();return I.Winding_CLOCKWISE==null&&(I.internal=!0,I.Winding_CLOCKWISE=new(re()).geom.Winding,I.internal=!1),e===I.Winding_CLOCKWISE}isConvex(){if(this._checkDisposed(),this._isDegenRing())return!0;let e=!1,t=!1,n=!0,s=this.zpp_inner.vertices,i=s;do{let l=i,r=l.prev,o=l.next,a=o.x-l.x,p=o.y-l.y,c=l.x-r.x,u=(l.y-r.y)*a-c*p;if(u>0?t=!0:u<0&&(e=!0),t&&e){n=!1;break}i=i.next}while(i!==s);return n}isSimple(){return this._checkDisposed(),this._isDegenRing()?!0:is.isSimple(this.zpp_inner.vertices)}isMonotone(){return this._checkDisposed(),this._isDegenRing()?!0:$t.isMonotone(this.zpp_inner.vertices)}isDegenerate(){return this._checkDisposed(),this._isDegenRing()?!0:this.area()<re().Config.epsilon}simplify(e){if(this._checkDisposed(),e<=0)throw new Error("Error: Epsilon should be > 0 for simplifying a GeomPoly");if(this._isDegenRing())return this.copy();let t=Pl.simplify(this.zpp_inner.vertices,e),n=w.get();return n.zpp_inner.vertices=t,n}simpleDecomposition(e){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let t=re(),n=this.zpp_inner.vertices;Qe.sharedGVList==null&&(Qe.sharedGVList=new ui);let s=is.decompose(n,Qe.sharedGVList),i=e??new t.geom.GeomPolyList;for(;s.head!=null;){let l=s.pop_unsafe(),r=w.get();r.zpp_inner.vertices=l,i.zpp_inner.reverse_flag?i.push(r):i.unshift(r)}return i}monotoneDecomposition(e){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let t=re(),n=this.zpp_inner.vertices;$t.sharedPPoly==null&&($t.sharedPPoly=new Qe);let s=$t.decompose(n,$t.sharedPPoly);Qe.sharedGVList==null&&(Qe.sharedGVList=new ui);let i=s.extract(Qe.sharedGVList),l=e??new t.geom.GeomPolyList;for(;i.head!=null;){let r=i.pop_unsafe(),o=w.get();o.zpp_inner.vertices=r,l.zpp_inner.reverse_flag?l.push(o):l.unshift(o)}return l}convexDecomposition(e=!1,t){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let n=re(),s=this.zpp_inner.vertices;$t.sharedPPoly==null&&($t.sharedPPoly=new Qe);let i=$t.decompose(s,$t.sharedPPoly);Qe.sharedPPList==null&&(Qe.sharedPPList=new ys);let l=i.extract_partitions(Qe.sharedPPList),r=t??new n.geom.GeomPolyList;for(;l.head!=null;){let o=l.pop_unsafe();qi.triangulate(o),e&&qi.optimise(o),ml.optimise(o),Qe.sharedGVList==null&&(Qe.sharedGVList=new ui);let a=o.extract(Qe.sharedGVList),p=o;for(p.next=Qe.zpp_pool,Qe.zpp_pool=p;a.head!=null;){let c=a.pop_unsafe(),h=w.get();h.zpp_inner.vertices=c,r.zpp_inner.reverse_flag?r.push(h):r.unshift(h)}}return r}triangularDecomposition(e=!1,t){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let n=re(),s=this.zpp_inner.vertices;$t.sharedPPoly==null&&($t.sharedPPoly=new Qe);let i=$t.decompose(s,$t.sharedPPoly);Qe.sharedPPList==null&&(Qe.sharedPPList=new ys);let l=i.extract_partitions(Qe.sharedPPList),r=t??new n.geom.GeomPolyList;for(;l.head!=null;){let o=l.pop_unsafe();qi.triangulate(o),e&&qi.optimise(o),Qe.sharedGVList==null&&(Qe.sharedGVList=new ui);let a=o.extract(Qe.sharedGVList),p=o;for(p.next=Qe.zpp_pool,Qe.zpp_pool=p;a.head!=null;){let c=a.pop_unsafe(),h=w.get();h.zpp_inner.vertices=c,r.zpp_inner.reverse_flag?r.push(h):r.unshift(h)}}return r}inflate(e){this._checkDisposed();let t=w.get();return this.isClockwise()&&(e=-e),this._forEachVert(n=>{let s=n.prev,i=n.next,l=n.x-s.x,r=n.y-s.y,o=i.x-n.x,a=i.y-n.y,p=Math.sqrt(l*l+r*r),c=-r/p*e,h=l/p*e,u=Math.sqrt(o*o+a*a),_=-a/u*e,m=o/u*e,x=_-c,y=m-h,z=a*x-o*y,f=z===0?0:z/(a*l-o*r),v=n.x+c+l*f,E=n.y+h+r*f,d=Se.get(v,E);t.push(d)}),t.skipForward(1)}cut(e,t,n=!1,s=!1,i){if(this._checkDisposed(),!(this._isDegenRing()||is.isSimple(this.zpp_inner.vertices)))throw new Error("Error: Cut requires a truly simple polygon");if(e==null||t==null)throw new Error("Error: Cannot cut with null start/end's");if(e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=fl.run(this.zpp_inner.vertices,e,t,n,s,i);return e.zpp_inner.weak&&e.dispose(),t.zpp_inner.weak&&t.dispose(),l}transform(e){if(this._checkDisposed(),e==null)throw new Error("Error: Cannot transform by null matrix");return this._forEachVert(t=>{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}),this}bounds(){if(this._checkDisposed(),this.zpp_inner.vertices==null)throw new Error("Error: empty GeomPoly has no defineable bounds");let e=1e100,t=1e100,n=-1e100,s=-1e100;return this._forEachVert(i=>{i.x<e&&(e=i.x),i.y<t&&(t=i.y),i.x>n&&(n=i.x),i.y>s&&(s=i.y)}),new Kn(e,t,n-e,s-t)}top(){return this._extremalVert("y",!0)}bottom(){return this._extremalVert("y",!1)}left(){return this._extremalVert("x",!0)}right(){return this._extremalVert("x",!1)}toString(){let e="GeomPoly[",t=this.zpp_inner.vertices;if(t!=null){let n=t;do n!==t&&(e+=","),e+="{"+n.x+","+n.y+"}",n=n.next;while(n!==t)}return e+"]"}};var kl=class{static run(e,t,n,s=2,i=null,l=!0,r=null){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: MarchingSquares requires an iso function to operate");if(t==null)throw new Error("Error: MarchingSquares requires an AABB to define bounds of surface extraction");if(n==null)throw new Error("Error: MarchingSquares requires a Vec2 to define cell size for surface extraction");let o=n.zpp_inner;if(o._validate!=null&&o._validate(),o.x<=0||o.y<=0)throw new Error("Error: MarchingSquares cannot operate with non-positive cell dimensions");if(s<0)throw new Error("Error: MarchingSquares cannot use a negative quality value for interpolation");if(i!=null){let u=i.zpp_inner;if(u._validate!=null&&u._validate(),u.x<=0||u.y<=0)throw new Error("Error: MarchingSquares cannot with non-positive sub-grid dimensions")}let a=re(),p=r??new a.geom.GeomPolyList,c=Ps,h=t.zpp_inner;if(h._validate!=null&&h._validate(),i==null){let u=h.minx,_=h.miny,m=h.maxx,x=h.maxy;c.run(e,u,_,m,x,n,s,l,p)}else{let u=i.zpp_inner;u._validate!=null&&u._validate();let _=h.maxx-h.minx,m=h.maxy-h.miny,x=_/u.x,y=m/u.y,z=x|0,f=y|0;z!==x&&++z,f!==y&&++f;for(let v=0;v<z;v++){let E=h.minx+u.x*v,d=v===z-1?h.maxx:E+u.x;for(let b=0;b<f;b++){let C=h.miny+u.y*b,P=b===f-1?h.maxy:C+u.y;c.run(e,E,C,d,P,n,s,l,p)}}}return o.weak&&n.dispose(),i!=null&&i.zpp_inner.weak&&i.dispose(),p}};var ls=class{constructor(){this.outer=null;this.inner=null;this.immutable=!1;this._invalidated=!1;this._invalidate=null;this._validate=null;this._modifiable=null;this.adder=null;this.post_adder=null;this.subber=null;this.dontremove=!1;this.reverse_flag=!1;this.at_index=0;this.at_ite=null;this.push_ite=null;this.zip_length=!1;this.user_length=0;this.inner=new Lr,this._invalidated=!0}static get(e,t){t==null&&(t=!1);let n=re(),s=new n.geom.Vec2List;return s.zpp_inner.inner=e,t&&(s.zpp_inner.immutable=!0),s.zpp_inner.zip_length=!0,s}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)}};ls.internal=!1;function Is(w){if(w.outer==null){let e=re();w.outer=new e.geom.Vec2;let t=w.outer.zpp_inner;t.outer!=null&&(t.outer.zpp_inner=null,t.outer=null),t._isimmutable=null,t._validate=null,t._invalidate=null,t.next=pe.zpp_pool,pe.zpp_pool=t,w.outer.zpp_inner=w}return w.outer}function Mt(){if(this.zpp_next=null,this.zpp_critical=!1,this.zpp_i=0,this.zpp_inner=null,!ls.internal)throw new Error("Error: Cannot instantiate Vec2Iterator derp!")}Mt.zpp_pool=null;Mt.get=function(w){let e;return Mt.zpp_pool==null?(ls.internal=!0,e=new Mt,ls.internal=!1):(e=Mt.zpp_pool,Mt.zpp_pool=e.zpp_next),e.zpp_i=0,e.zpp_inner=w,e.zpp_critical=!1,e};Mt.prototype.zpp_inner=null;Mt.prototype.zpp_i=null;Mt.prototype.zpp_critical=null;Mt.prototype.zpp_next=null;Mt.prototype.hasNext=function(){this.zpp_inner.zpp_inner.valmod();let w=this.zpp_inner.zpp_gl();return this.zpp_critical=!0,this.zpp_i<w?!0:(this.zpp_next=Mt.zpp_pool,Mt.zpp_pool=this,this.zpp_inner=null,!1)};Mt.prototype.next=function(){return this.zpp_critical=!1,this.zpp_inner.at(this.zpp_i++)};function ht(){this.zpp_inner=null,this.zpp_inner=new ls,this.zpp_inner.outer=this}ht.fromArray=function(w){if(w==null)throw new Error("Error: Cannot convert null Array to Nape list");let e=re(),t=new e.geom.Vec2List;for(let n=0;n<w.length;n++)t.push(w[n]);return t};ht.prototype.zpp_inner=null;Object.defineProperty(ht.prototype,"length",{get:function(){return this.zpp_gl()}});ht.prototype.zpp_gl=function(){return this.zpp_inner.valmod(),this.zpp_inner.zip_length&&(this.zpp_inner.zip_length=!1,this.zpp_inner.user_length=this.zpp_inner.inner.length),this.zpp_inner.user_length};ht.prototype.zpp_vm=function(){this.zpp_inner.valmod()};ht.prototype.has=function(w){return this.zpp_vm(),this.zpp_inner.inner.has(w.zpp_inner)};ht.prototype.at=function(w){if(this.zpp_vm(),w<0||w>=this.zpp_gl())throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(w=this.zpp_gl()-1-w),w<this.zpp_inner.at_index||this.zpp_inner.at_ite==null)this.zpp_inner.at_index=w,this.zpp_inner.at_ite=this.zpp_inner.inner.iterator_at(w);else for(;this.zpp_inner.at_index!=w;)this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;return Is(this.zpp_inner.at_ite.elt)};ht.prototype.push=function(w){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(w):!0;return e&&(this.zpp_inner.reverse_flag?this.zpp_inner.inner.add(w.zpp_inner):(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.empty()?null:this.zpp_inner.inner.iterator_at(this.zpp_gl()-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,w.zpp_inner)),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(w)),e};ht.prototype.unshift=function(w){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(w):!0;return e&&(this.zpp_inner.reverse_flag?(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.empty()?null:this.zpp_inner.inner.iterator_at(this.zpp_gl()-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,w.zpp_inner)):this.zpp_inner.inner.add(w.zpp_inner),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(w)),e};ht.prototype.pop=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.empty())throw new Error("Error: Cannot remove from empty list");this.zpp_vm();let w;if(this.zpp_inner.reverse_flag){w=this.zpp_inner.inner.head.elt;let e=Is(w);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}else{this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let e=this.zpp_gl()==1?null:this.zpp_inner.inner.iterator_at(this.zpp_gl()-2);w=e==null?this.zpp_inner.inner.head.elt:e.next.elt;let t=Is(w);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(e)}return this.zpp_inner.invalidate(),Is(w)};ht.prototype.shift=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.empty())throw new Error("Error: Cannot remove from empty list");this.zpp_vm();let w;if(this.zpp_inner.reverse_flag){this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let e=this.zpp_gl()==1?null:this.zpp_inner.inner.iterator_at(this.zpp_gl()-2);w=e==null?this.zpp_inner.inner.head.elt:e.next.elt;let t=Is(w);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(e)}else{w=this.zpp_inner.inner.head.elt;let e=Is(w);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}return this.zpp_inner.invalidate(),Is(w)};ht.prototype.add=function(w){return this.zpp_inner.reverse_flag?this.push(w):this.unshift(w)};ht.prototype.remove=function(w){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=!1,t=this.zpp_inner.inner.head;for(;t!=null;){if(t.elt==w.zpp_inner){e=!0;break}t=t.next}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(w),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(w.zpp_inner),this.zpp_inner.invalidate()),e};ht.prototype.clear=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.reverse_flag)for(;!this.empty();)this.pop();else for(;!this.empty();)this.shift()};ht.prototype.empty=function(){return this.zpp_gl()==0};ht.prototype.iterator=function(){return this.zpp_vm(),Mt.get(this)};ht.prototype.copy=function(w){w==null&&(w=!1);let e=re(),t=new e.geom.Vec2List,n=Mt.get(this);for(;n.hasNext();){let s=n.next(),i;if(w){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=s.zpp_inner;l._validate!=null&&l._validate();let r=s.zpp_inner.x,o=s.zpp_inner;o._validate!=null&&o._validate();let a=s.zpp_inner.y,p;if(ue.poolVec2==null?p=new e.geom.Vec2:(p=ue.poolVec2,ue.poolVec2=p.zpp_pool,p.zpp_pool=null,p.zpp_disp=!1,p==ue.nextVec2&&(ue.nextVec2=null)),p.zpp_inner==null){let c;pe.zpp_pool==null?c=new pe:(c=pe.zpp_pool,pe.zpp_pool=c.next,c.next=null),c.weak=!1,c._immutable=!1,c.x=r,c.y=a,p.zpp_inner=c,p.zpp_inner.outer=p}else p.zpp_inner.x=r,p.zpp_inner.y=a,p.zpp_inner._invalidate!=null&&p.zpp_inner._invalidate(p.zpp_inner);p.zpp_inner.weak=!1,i=p}else i=s;t.push(i)}return t};ht.prototype.merge=function(w){if(w==null)throw new Error("Error: Cannot merge with null list");let e=w.iterator();for(;e.hasNext();){let t=e.next();this.has(t)||this.add(t)}};ht.prototype.toString=function(){let w="[",e=!0,t=Mt.get(this);for(;t.hasNext();){let n=t.next();e||(w+=","),w+=n==null?"NULL":n.toString(),e=!1}return w+"]"};ht.prototype.foreach=function(w){if(w==null)throw new Error("Error: Cannot execute null on list elements");let e=this.iterator();for(;e.hasNext();)try{w(e.next())}catch{e.zpp_next=Mt.zpp_pool,Mt.zpp_pool=e,e.zpp_inner=null;break}return this};ht.prototype[Symbol.iterator]=function(){let w=Mt.get(this);return{next(){return w.hasNext()?{value:w.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};ht.prototype.filter=function(w){if(w==null)throw new Error("Error: Cannot select elements of list with null");let e=0;for(;e<this.zpp_gl();){let t=this.at(e);try{w(t)?++e:this.remove(t)}catch{break}}return this};function Ts(){if(!ri.internal)throw new Error("Error: Cannot instantiate GeomVertexIterator")}Ts.prototype.zpp_inner=null;Ts.prototype.hasNext=function(){if(this.zpp_inner==null)throw new Error("Error: Iterator has been disposed");let w=this.zpp_inner.ptr!=this.zpp_inner.start||this.zpp_inner.first;if(this.zpp_inner.first=!1,!w){let e=this.zpp_inner;e.outer.zpp_inner=null,e.ptr=e.start=null,e.next=ri.zpp_pool,ri.zpp_pool=e}return w};Ts.prototype.next=function(){if(this.zpp_inner==null)throw new Error("Error: Iterator has been disposed");let w=this.zpp_inner.ptr;if(w.wrap==null){let t=w.x,n=w.y;if(t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");let s=re(),i;if(ue.poolVec2==null?i=new s.geom.Vec2:(i=ue.poolVec2,ue.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==ue.nextVec2&&(ue.nextVec2=null)),i.zpp_inner==null){let l;pe.zpp_pool==null?l=new pe:(l=pe.zpp_pool,pe.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n,i.zpp_inner=l,i.zpp_inner.outer=i}else{if(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");l._isimmutable!=null&&l._isimmutable(),l.x==t&&l.y==n||(l.x=t,l.y=n,l._invalidate!=null&&l._invalidate(l))}i.zpp_inner.weak=!1,w.wrap=i,w.wrap.zpp_inner._inuse=!0,w.wrap.zpp_inner._invalidate=l=>w.modwrap(l),w.wrap.zpp_inner._validate=()=>w.getwrap()}let e=w.wrap;return this.zpp_inner.ptr=this.zpp_inner.forward?this.zpp_inner.ptr.next:this.zpp_inner.ptr.prev,e};Ts.prototype[Symbol.iterator]=function(){return{_it:this,next(){return this._it.hasNext()?{value:this._it.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};var Vo=re();Vo.geom.GeomVertexIterator=Ts;var Ti=class{constructor(){this.outer=null;this.inner=null;this.immutable=!1;this._invalidated=!1;this._invalidate=null;this._validate=null;this._modifiable=null;this.adder=null;this.post_adder=null;this.subber=null;this.dontremove=!1;this.reverse_flag=!1;this.at_index=0;this.at_ite=null;this.push_ite=null;this.zip_length=!1;this.user_length=0;this.inner=new we,this._invalidated=!0}static get(e,t){t==null&&(t=!1);let n=re(),s=new n.dynamics.ContactList;return s.zpp_inner.inner=e,t&&(s.zpp_inner.immutable=!0),s.zpp_inner.zip_length=!0,s}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)}};Ti.internal=!1;var sr,lr,rr;function Zr(w){sr=w}function $r(w){lr=w}function eo(w){rr=w}var or=class or{constructor(){this._inner=void 0,this.zpp_inner_i=null}static _wrap(e){return e?e instanceof or?e:e.isBody&&e.isBody()&&sr?sr(e):e.isShape&&e.isShape()&&lr?lr(e):e.isCompound&&e.isCompound()&&rr?rr(e):ze(e,t=>{let n=Object.create(or.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 sr?sr(e):e}return null}get castShape(){if(this.zpp_inner_i.ishape!=null){let e=this.zpp_inner_i.ishape.outer;return lr?lr(e):e}return null}get castCompound(){if(this.zpp_inner_i.icompound!=null){let e=this.zpp_inner_i.icompound.outer;return rr?rr(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""}};or.zpp_internalAlloc=!1;var oi=or;var Nl=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 Yn=class w{get _inner(){return this}constructor(e=1,t=1){let n;if(qn.zpp_pool==null?n=new qn:(n=qn.zpp_pool,qn.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 w?e:e?e instanceof qn?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?w._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=re().zpp_nape;if(e==null){if(this.zpp_inner.wrap_gravity!=null){this.zpp_inner.wrap_gravity.zpp_inner._inuse=!1;let s=this.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),s.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let l=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let r=s;r.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=r:n.util.ZPP_PubPool.poolVec2=r,n.util.ZPP_PubPool.nextVec2=r,r.zpp_disp=!0;let o=l;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,this.zpp_inner.wrap_gravity=null}}else{if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity();let s=this.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;l._validate!=null&&l._validate();let r=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;o._validate!=null&&o._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(),r!=r||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==r){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=s.zpp_inner;u._validate!=null&&u._validate(),c=s.zpp_inner.y==a}else c=!1;if(!c){s.zpp_inner.x=r,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 _=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 x=_;x.outer!=null&&(x.outer.zpp_inner=null,x.outer=null),x._isimmutable=null,x._validate=null,x._invalidate=null,x.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=x}}}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=re();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=re().zpp_nape,n=new w(this.zpp_inner.density*1e3,this.zpp_inner.viscosity);this.zpp_inner.userData!=null&&(n.zpp_inner.userData={...this.zpp_inner.userData});let s=this.zpp_inner.wrap_gravity;if(s==null){if(n.zpp_inner.wrap_gravity!=null){n.zpp_inner.wrap_gravity.zpp_inner._inuse=!1;let i=n.zpp_inner.wrap_gravity;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),i.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let r=i.zpp_inner;i.zpp_inner.outer=null,i.zpp_inner=null;let o=i;o.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=o:t.util.ZPP_PubPool.poolVec2=o,t.util.ZPP_PubPool.nextVec2=o,o.zpp_disp=!0;let a=r;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 r=s.zpp_inner;r._validate!=null&&r._validate();let o=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(),o!=o||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==o){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let _=i.zpp_inner;_._validate!=null&&_._validate(),h=i.zpp_inner.y==p}else h=!1;if(!h){i.zpp_inner.x=o,i.zpp_inner.y=p;let _=i.zpp_inner;_._invalidate!=null&&_._invalidate(_)}if(s.zpp_inner.weak){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let _=s.zpp_inner;if(_._immutable)throw new Error("Error: Vec2 is immutable");if(_._isimmutable!=null&&_._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 x=s;x.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=x:t.util.ZPP_PubPool.poolVec2=x,t.util.ZPP_PubPool.nextVec2=x,x.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)+" }"}};qn._wrapFn=w=>ze(w,e=>{let t=Object.create(Yn.prototype);return t.zpp_inner=e,e.outer=t,t});var Io=re();Io.phys.FluidProperties=Yn;var Yi=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate ShapeType derp!")}static get CIRCLE(){return I.ShapeType_CIRCLE==null&&(I.internal=!0,I.ShapeType_CIRCLE=new w,I.internal=!1),I.ShapeType_CIRCLE}static get POLYGON(){return I.ShapeType_POLYGON==null&&(I.internal=!0,I.ShapeType_POLYGON=new w,I.internal=!1),I.ShapeType_POLYGON}static get CAPSULE(){return I.ShapeType_CAPSULE==null&&(I.internal=!0,I.ShapeType_CAPSULE=new w,I.internal=!1),I.ShapeType_CAPSULE}toString(){return this===I.ShapeType_CIRCLE?"CIRCLE":this===I.ShapeType_POLYGON?"POLYGON":this===I.ShapeType_CAPSULE?"CAPSULE":""}},To=re();To.shape.ShapeType=Yi;li();var ar,pr,cr;function to(w){ar=w}function no(w){pr=w}function io(w){cr=w}var Mn=class w extends oi{constructor(){super()}static _wrap(e){if(!e)return null;let t=e.zpp_inner??e;if(t._isCapsule&&cr)return cr(e);let n=e.isCircle?e.isCircle()?0:e.isPolygon?.()?1:t.type??-1:t.type??-1;return n===0&&ar?ar(e):n===1&&pr?pr(e):e.outer?e.outer:ze(e,s=>{let i=Object.create(w.prototype);return i._inner=s,i.zpp_inner=s.zpp_inner??s,i.zpp_inner_i=s.zpp_inner_i??s,i})}get type(){return Ji.types[this.zpp_inner.type]}isCircle(){return this.zpp_inner.type===0}isPolygon(){return this.zpp_inner.type===1}isCapsule(){return!!this.zpp_inner._isCapsule}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 ar?ar(t):t}return null}get castPolygon(){let e=this.zpp_inner;if(e.type===1){let t=e.polygon.outer_zn;return pr?pr(t):t}return null}get castCapsule(){let e=this.zpp_inner;if(e._isCapsule){let t=e.outer;return cr?cr(t):t}return null}get worldCOM(){let e=this.zpp_inner;return e.wrap_worldCOM==null&&this._setupWorldCOM(),e.wrap_worldCOM}get localCOM(){let e=this.zpp_inner;return e.wrap_localCOM==null&&(e.type===0?e.circle.setupLocalCOM():e.polygon.setupLocalCOM()),e.wrap_localCOM}set localCOM(e){let t=this.zpp_inner;if(t.immutable_midstep("Body::localCOM"),e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Shape::localCOM cannot be null");t.wrap_localCOM==null&&(t.type===0?t.circle.setupLocalCOM():t.polygon.setupLocalCOM()),t.wrap_localCOM.set(e),e.zpp_inner.weak&&e.dispose()}get area(){let e=this.zpp_inner;return e.validate_area_inertia(),e.area}get inertia(){let e=this.zpp_inner;return e.validate_area_inertia(),e.inertia}get angDrag(){let e=this.zpp_inner;return e.validate_angDrag(),e.angDrag}get material(){return this.zpp_inner.material.wrapper()}set material(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::material"),e==null)throw new Error("Error: Cannot assign null as Shape material");t.setMaterial(e.zpp_inner)}get filter(){return this.zpp_inner.filter.wrapper()}set filter(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::filter"),e==null)throw new Error("Error: Cannot assign null as Shape filter");t.setFilter(e.zpp_inner)}get fluidProperties(){let e=this.zpp_inner;return e.immutable_midstep("Shape::fluidProperties"),e.fluidProperties==null&&e.setFluid(new Yn().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 Yn().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 Yn;t.setFluid(n.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new Yn().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=re();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");an.validateShape(t);let n=e.zpp_inner;n._validate!=null&&n._validate();let s=Ze.shapeContains(t,n);return n.weak&&e.dispose(),s}copy(){let e=this.zpp_inner.copy();return e instanceof w?e:w._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=re(),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(ue.poolVec2==null?i=new e.geom.Vec2:(i=ue.poolVec2,ue.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i===ue.nextVec2&&(ue.nextVec2=null)),i.zpp_inner==null){let l;pe.zpp_pool==null?l=new pe:(l=pe.zpp_pool,pe.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 Bi={SHAPES:1,JOINTS:2,CONTACTS:4,AABB:8,CENTER_OF_MASS:16,VELOCITIES:32,ALL:63};var ai=class w{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 Ki(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 w?e:e instanceof Ki?e.outer?e.outer:ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?.outer?e.zpp_inner.outer:ze(e,t=>{let n=Object.create(w.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?(I.Broadphase_SPATIAL_HASH==null&&(I.internal=!0,I.Broadphase_SPATIAL_HASH=new(re()).space.Broadphase,I.internal=!1),I.Broadphase_SPATIAL_HASH):this.zpp_inner.bphase.is_sweep?(I.Broadphase_SWEEP_AND_PRUNE==null&&(I.internal=!0,I.Broadphase_SWEEP_AND_PRUNE=new(re()).space.Broadphase,I.internal=!1),I.Broadphase_SWEEP_AND_PRUNE):(I.Broadphase_DYNAMIC_AABB_TREE==null&&(I.internal=!0,I.Broadphase_DYNAMIC_AABB_TREE=new(re()).space.Broadphase,I.internal=!1),I.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 Ke._wrap(this.zpp_inner.__static)}get arbiters(){if(this.zpp_inner.wrap_arbiters==null){let e=new Oi;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=re(),n=this.zpp_inner.wrap_bodies;n.zpp_inner.valmod();let s=t.phys.BodyIterator.get(n);for(;;){s.zpp_inner.zpp_inner.valmod();let r=s.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let o=r.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=o){s.zpp_next=t.phys.BodyIterator.zpp_pool,t.phys.BodyIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1,e(s.zpp_inner.at(s.zpp_i++))}let i=this.zpp_inner.wrap_compounds;i.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(i);for(;;){l.zpp_inner.zpp_inner.valmod();let r=l.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let o=r.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=o){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=re(),n=this.zpp_inner.wrap_constraints;n.zpp_inner.valmod();let s=t.constraint.ConstraintIterator.get(n);for(;;){s.zpp_inner.zpp_inner.valmod();let r=s.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let o=r.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=o){s.zpp_next=t.constraint.ConstraintIterator.zpp_pool,t.constraint.ConstraintIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1,e(s.zpp_inner.at(s.zpp_i++))}let i=this.zpp_inner.wrap_compounds;i.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(i);for(;;){l.zpp_inner.zpp_inner.valmod();let r=l.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let o=r.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=o){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=re(),n=this.zpp_inner.wrap_compounds;n.zpp_inner.valmod();let s=t.phys.CompoundIterator.get(n);for(;;){s.zpp_inner.zpp_inner.valmod();let i=s.zpp_inner;i.zpp_inner.valmod(),i.zpp_inner.zip_length&&(i.zpp_inner.zip_length=!1,i.zpp_inner.user_length=i.zpp_inner.inner.length);let l=i.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=l){s.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1;let r=s.zpp_inner.at(s.zpp_i++);e(r),r.visitCompounds(e)}}interactionType(e,t){if(e==null||t==null)throw new Error("Error: Cannot evaluate interaction type for null shapes");let n=e.zpp_inner,s=t.zpp_inner;if((n.body!=null?n.body.outer:null)==null||(s.body!=null?s.body.outer:null)==null)throw new Error("Error: Cannot evaluate interaction type for shapes not part of a Body");let i=n.body,l=s.body;if(i.type==1&&l.type==1||i.outer==l.outer)return null;let r=!1,o=i.constraints.head;for(;o!=null;){let u=o.elt;if(u.ignore&&u.pair_exists(i.id,l.id)){r=!0;break}o=o.next}let a;if(r)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 _=u==null?null:u.group,m;if(_==null)m=!1;else{let x=s;for(;x!=null&&x.group==null;)x.ishape!=null?x=x.ishape.body:x.icompound!=null?x=x.icompound.compound:x=x.ibody.compound;let y=x==null?null:x.group;if(y==null)m=!1;else{let z=!1;for(;_!=null&&y!=null;){if(_==y){z=_.ignore;break}_.depth<y.depth?y=y.group:_=_.group}m=z}}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?(I.InteractionType_SENSOR==null&&(I.internal=!0,I.InteractionType_SENSOR=new(re()).callbacks.InteractionType,I.internal=!1),I.InteractionType_SENSOR):(n.fluidEnabled||s.fluidEnabled)&&(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0&&!h?(I.InteractionType_FLUID==null&&(I.internal=!0,I.InteractionType_FLUID=new(re()).callbacks.InteractionType,I.internal=!1),I.InteractionType_FLUID):(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!h?(I.InteractionType_COLLISION==null&&(I.internal=!0,I.InteractionType_COLLISION=new(re()).callbacks.InteractionType,I.internal=!1),I.InteractionType_COLLISION):null}shapesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes under a null point :)");let s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,r=t==null?null:t.zpp_inner??t,o=this.zpp_inner.shapesUnderPoint(i,l,r,n);return s.weak&&e.dispose(),o}bodiesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects under a null point :)");let s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,r=t==null?null:t.zpp_inner??t,o=this.zpp_inner.bodiesUnderPoint(i,l,r,n);return s.weak&&e.dispose(),o}shapesInAABB(e,t=!1,n=!0,s,i){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null AABB :)");let l=e.zpp_inner;if(l._validate!=null&&l._validate(),l.maxx-l.minx==0||l.maxy-l.miny==0)throw new Error("Error: Cannot evaluate shapes in degenerate AABB :/");let r=s==null?null:s.zpp_inner??s;return this.zpp_inner.shapesInAABB(e,n,t,r,i)}bodiesInAABB(e,t=!1,n=!0,s,i){if(e==null)throw new Error("Error: Cannot evaluate objects in a null AABB :)");let l=e.zpp_inner;if(l._validate!=null&&l._validate(),l.maxx-l.minx==0||l.maxy-l.miny==0)throw new Error("Error: Cannot evaluate objects in degenerate AABB :/");let r=s==null?null:s.zpp_inner??s;return this.zpp_inner.bodiesInAABB(e,n,t,r,i)}shapesInCircle(e,t,n=!1,s,i){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let l=s==null?null:s.zpp_inner??s,r=this.zpp_inner.shapesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),r}bodiesInCircle(e,t,n=!1,s,i){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let l=s==null?null:s.zpp_inner??s,r=this.zpp_inner.bodiesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),r}shapesInShape(e,t=!1,n,s){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null shapes :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(i.type==1){let r=i.polygon.valid();if(I.ValidationResult_VALID==null&&(I.internal=!0,I.ValidationResult_VALID=new(re()).shape.ValidationResult,I.internal=!1),r!=I.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+r.toString())}let l=n==null?null:n.zpp_inner??n;return this.zpp_inner.shapesInShape(i,t,l,s)}bodiesInShape(e,t=!1,n,s){if(e==null)throw new Error("Error: Cannot evaluate bodies in a null shapes :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(i.type==1){let r=i.polygon.valid();if(I.ValidationResult_VALID==null&&(I.internal=!0,I.ValidationResult_VALID=new(re()).shape.ValidationResult,I.internal=!1),r!=I.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+r.toString())}let l=n==null?null:n.zpp_inner??n;return this.zpp_inner.bodiesInShape(i,t,l,s)}shapesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let s=re(),i=n??new s.shape.ShapeList,l=e.zpp_inner.wrap_shapes;l.zpp_inner.valmod();let r=s.shape.ShapeIterator.get(l);for(;;){r.zpp_inner.zpp_inner.valmod();let o=r.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 a=o.zpp_inner.user_length;if(r.zpp_critical=!0,r.zpp_i>=a){r.zpp_next=s.shape.ShapeIterator.zpp_pool,s.shape.ShapeIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let p=r.zpp_inner.at(r.zpp_i++);this.shapesInShape(p,!1,t,i)}return i}bodiesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let s=re(),i=n??new s.phys.BodyList,l=e.zpp_inner.wrap_shapes;l.zpp_inner.valmod();let r=s.shape.ShapeIterator.get(l);for(;;){r.zpp_inner.zpp_inner.valmod();let o=r.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 a=o.zpp_inner.user_length;if(r.zpp_critical=!0,r.zpp_i>=a){r.zpp_next=s.shape.ShapeIterator.zpp_pool,s.shape.ShapeIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let p=r.zpp_inner.at(r.zpp_i++);this.bodiesInShape(p,!1,t,i)}return i}convexCast(e,t,n=!1,s){if(e==null)throw new Error("Error: Cannot cast null shape :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexCast(i,t,s,n)}convexMultiCast(e,t,n=!1,s,i){if(e==null)throw new Error("Error: Cannot cast null shape :)");let l=e.zpp_inner;if((l.body!=null?l.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexMultiCast(l,t,s,n,i)}rayCast(e,t=!1,n){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayCast(e,t,n)}rayMultiCast(e,t=!1,n,s){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayMultiCast(e,t,n,s)}debugDraw(e,t=Bi.ALL){if(e==null)throw new Error("Error: drawer cannot be null for Space::debugDraw");let n=(t&Bi.SHAPES)!==0,s=(t&Bi.JOINTS)!==0,i=(t&Bi.CONTACTS)!==0,l=(t&Bi.AABB)!==0,r=(t&Bi.CENTER_OF_MASS)!==0,o=(t&Bi.VELOCITIES)!==0,a=4283417591,p=4287669422,c=4294948685,h=4289058471,u=4293874512,_=1157627903,m=4294961979,x=4291728344;if(this.visitBodies(y=>{let z=y.zpp_inner,f=z.type===2,E=z.type===1?p:f?a:c;if(n){let d=z.shapes.head;for(;d!=null;){let b=d.elt;if(b.type===0){let C=b.circle;b.zip_worldCOM&&b.validate_worldCOM();let P=b.worldCOMx,g=b.worldCOMy,O=C.radius,N=z.rot,M=P+Math.cos(N)*O,k=g+Math.sin(N)*O,Z={x:P,y:g},A={x:M,y:k};f?e.drawSolidCircle(Z,O,A,E):e.drawCircle(Z,O,E)}else if(b.type===1){let C=b.polygon;C.zip_gverts&&C.validate_gverts();let P=[],g=C.gverts.next;for(;g!=null;)P.push({x:g.x,y:g.y}),g=g.next;P.length>=3&&(f?e.drawSolidPolygon(P,E):e.drawPolygon(P,E))}d=d.next}}if(l&&!z.world){let d=z.aabb,b=d.minx,C=d.miny,P=d.maxx,g=d.maxy;e.drawSegment({x:b,y:C},{x:P,y:C},_),e.drawSegment({x:P,y:C},{x:P,y:g},_),e.drawSegment({x:P,y:g},{x:b,y:g},_),e.drawSegment({x:b,y:g},{x:b,y:C},_)}if(r&&!z.world&&(z.validate_worldCOM(),e.drawPoint({x:z.worldCOMx,y:z.worldCOMy},m)),o&&!z.world&&f){let d=z.posx,b=z.posy;e.drawSegment({x:d,y:b},{x:d+z.velx,y:b+z.vely},x)}}),s&&this.visitConstraints(y=>{if(!y.debugDraw)return;let z=y.zpp_inner,f=z.b1,v=z.b2,E=z.a1worldx??(f!=null?f.posx:0),d=z.a1worldy??(f!=null?f.posy:0),b=z.a2worldx??(v!=null?v.posx:0),C=z.a2worldy??(v!=null?v.posy:0);e.drawSegment({x:E,y:d},{x:b,y:C},h),e.drawPoint({x:E,y:d},h),e.drawPoint({x:b,y:C},h)}),i){let y=z=>{if(z==null)return;let f=z.head;for(;f!=null;){let v=f.elt;if(v!=null){let E=v.nx,d=v.ny,b=v.contacts?.next;for(;b!=null;){let C=b.px,P=b.py;e.drawPoint({x:C,y:P},u),e.drawSegment({x:C,y:P},{x:C+E*8,y:P+d*8},u),b=b.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 Rr=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 Hn(w,e,t,n){let s=re(),i=s.__zpp;class l extends Rr{constructor(){super(),this.inner=new i.util[w]}static get(o,a=!1){let p=new s[e][t];return p.zpp_inner.inner=o,a&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}}return l.internal=!1,i.util[n]=l,l}var hr=null,Gr=null,qr=null;hr=Hn("ZNPList_ZPP_Constraint","constraint","ConstraintList","ZPP_ConstraintList");Hn("ZNPList_ZPP_Body","phys","BodyList","ZPP_BodyList");Gr=Hn("ZNPList_ZPP_Interactor","phys","InteractorList","ZPP_InteractorList");Hn("ZNPList_ZPP_Compound","phys","CompoundList","ZPP_CompoundList");Hn("ZNPList_ZPP_Listener","callbacks","ListenerList","ZPP_ListenerList");Hn("ZNPList_ZPP_CbType","callbacks","CbTypeList","ZPP_CbTypeList");Hn("ZNPList_ZPP_GeomPoly","geom","GeomPolyList","ZPP_GeomPolyList");Hn("ZNPList_RayResult","geom","RayResultList","ZPP_RayResultList");Hn("ZNPList_ConvexResult","geom","ConvexResultList","ZPP_ConvexResultList");Hn("ZNPList_ZPP_Edge","shape","EdgeList","ZPP_EdgeList");Hn("ZNPList_ZPP_Shape","shape","ShapeList","ZPP_ShapeList");Hn("ZNPList_ZPP_InteractionGroup","dynamics","InteractionGroupList","ZPP_InteractionGroupList");qr=Hn("ZNPList_ZPP_Arbiter","dynamics","ArbiterList","ZPP_ArbiterList");function mi(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.x}function fi(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.y}function pi(w){if(w!=null&&w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}function Xn(w){w.zpp_inner.weak&&w.dispose()}function Ol(w,e,t,n,s){if(pi(t),t==null)throw new Error("Error: Body::"+w+" cannot be null");return e==null&&n!=null&&(n(),e=s()),e.set(t),e}function Mr(w,e,t){return Se.get(w,e,t)}function Pn(w,e){return I[w]==null&&(I.internal=!0,I[w]=e(),I.internal=!1),I[w]}var Ke=class w extends oi{constructor(t,n){super();this.debugDraw=!0;let s=new Gn;this.zpp_inner=s,s.outer=this,s.outer_i=this,this.zpp_inner_i=s,this._inner=this,n!=null?(pi(n),s.posx=mi(n),s.posy=fi(n)):(s.posx=0,s.posy=0);let i=re(),l;if(t==null?l=Pn("BodyType_DYNAMIC",()=>new i.phys.BodyType):l=t,s.immutable_midstep("Body::type"),s.world)throw new Error("Error: Space::world is immutable");if(Gn.types[s.type]!==l){if(l==null)throw new Error("Error: Cannot use null BodyType");let r=so(l,i);r===1&&s.space!=null&&(s.velx=0,s.vely=0,s.angvel=0),s.invalidate_type(),s.space!=null?s.space.transmitType(s,r):s.type=r}n!=null&&Xn(n),s.insert_cbtype(ut.ANY_BODY.zpp_inner)}static _wrap(t){return t?t instanceof w?t:t instanceof Gn?ze(t,n=>{let s=Object.create(w.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?w._wrap(t.zpp_inner):ze(t,n=>{let s=Object.create(w.prototype);return s._inner=n,s}):null}get type(){return Gn.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(Gn.types[n.type]!==t){if(t==null)throw new Error("Error: Cannot use null BodyType");let s=re(),i=so(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){Ol("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){Ol("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){Ol("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){Ol("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){Ol("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 Nl(this.zpp_inner.wrap_shapes,Mn._wrap)}get space(){return this.zpp_inner.space==null?null:ai._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 Kn._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=Se.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=Se.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=re(),n=Pn("MassMode_DEFAULT",()=>new t.phys.MassMode),s=Pn("MassMode_FIXED",()=>new t.phys.MassMode);return[n,s][this.zpp_inner.massMode]}set massMode(t){let n=re();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=Pn("MassMode_DEFAULT",()=>new n.phys.MassMode);this.zpp_inner.massMode=t===s?0:1,this.zpp_inner.invalidate_mass()}get inertiaMode(){let t=re(),n=Pn("InertiaMode_DEFAULT",()=>new t.phys.InertiaMode),s=Pn("InertiaMode_FIXED",()=>new t.phys.InertiaMode);return[n,s][this.zpp_inner.inertiaMode]}set inertiaMode(t){let n=re();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=Pn("InertiaMode_FIXED",()=>new n.phys.InertiaMode);this.zpp_inner.inertiaMode=t===s?1:0,this.zpp_inner.invalidate_inertia()}get gravMassMode(){let t=re(),n=Pn("GravMassMode_DEFAULT",()=>new t.phys.GravMassMode),s=Pn("GravMassMode_FIXED",()=>new t.phys.GravMassMode),i=Pn("GravMassMode_SCALED",()=>new t.phys.GravMassMode);return[n,s,i][this.zpp_inner.gravMassMode]}set gravMassMode(t){let n=re();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=Pn("GravMassMode_SCALED",()=>new n.phys.GravMassMode);if(t===s)this.zpp_inner.gravMassMode=2;else{let i=Pn("GravMassMode_DEFAULT",()=>new n.phys.GravMassMode);this.zpp_inner.gravMassMode=t===i?0:1}this.zpp_inner.invalidate_gravMass()}copy(){if(this.zpp_inner.world)throw new Error("Error: Space::world cannot be copied");return this.zpp_inner.copy()}toString(){let t=this.zpp_inner;return(t.world?"(space::world":"("+(t.type===2?"dynamic":t.type===1?"static":"kinematic"))+")#"+this.zpp_inner_i.id}integrate(t){if(t!==t)throw new Error("Cannot integrate by NaN time");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t===0)return this;let n=this.zpp_inner;n.sweepTime=0,n.sweep_angvel=n.angvel;let s=t-n.sweepTime;if(s!==0&&(n.sweepTime=t,n.posx+=n.velx*s,n.posy+=n.vely*s,n.angvel!==0)){let i=n.sweep_angvel*s;if(n.rot+=i,i*i>1e-4)n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot);else{let l=i*i,r=1-.5*l,o=1-l*l/8,a=(r*n.axisx+i*n.axisy)*o;n.axisy=(r*n.axisy-i*n.axisx)*o,n.axisx=a}}return lo(n),n.zip_worldCOM=!0,n.zip_axis=!0,lo(n),n.zip_worldCOM=!0,n.sweepTime=0,this}localPointToWorld(t,n=!1){if(pi(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=mi(t),i=fi(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,r=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return Xn(t),Mr(l+this.zpp_inner.posx,r+this.zpp_inner.posy,n)}worldPointToLocal(t,n=!1){if(pi(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=mi(t)-this.zpp_inner.posx,i=fi(t)-this.zpp_inner.posy,l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,r=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return Xn(t),Mr(l,r,n)}localVectorToWorld(t,n=!1){if(pi(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=mi(t),i=fi(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,r=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return Xn(t),Mr(l,r,n)}worldVectorToLocal(t,n=!1){if(pi(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=mi(t),i=fi(t),l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,r=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return Xn(t),Mr(l,r,n)}applyImpulse(t,n,s=!1){if(pi(t),n!=null&&pi(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 Xn(t),n!=null&&Xn(n),this;this.zpp_inner.validate_mass();let i=this.zpp_inner.imass,l=mi(t),r=fi(t);if(this.zpp_inner.velx+=l*i,this.zpp_inner.vely+=r*i,n!=null){let o=mi(n)-this.zpp_inner.posx,a=fi(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(r*o-l*a)*this.zpp_inner.iinertia,Xn(n)}return s||this.zpp_inner.type===2&&this.zpp_inner.wake(),Xn(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(pi(t),t==null)throw new Error("Cannot set velocity for null target position");if(s===0)throw new Error("deltaTime cannot be 0 for setVelocityFromTarget");let i=1/s;this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity(),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let l=t.sub(this.zpp_inner.wrap_pos,!0).muleq(i);this.zpp_inner.wrap_vel.set(l);let r=(n-this.zpp_inner.rot)*i;if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.angvel!==r){if(r!==r)throw new Error("Error: Body::angularVel cannot be NaN");if(this.zpp_inner.type===1)throw new Error("Error: A static object cannot be given a velocity");this.zpp_inner.angvel=r,this.zpp_inner.wake()}return Xn(t),this}translateShapes(t){if(this.zpp_inner.immutable_midstep("Body::translateShapes()"),pi(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,Xn(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=Se.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-=mi(n),this.zpp_inner.pre_posy-=fi(n)),t.dispose(),n.dispose(),this}rotate(t,n){if(pi(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);Ol("position",this.zpp_inner.wrap_pos,l,()=>this.zpp_inner.setupPosition(),()=>this.zpp_inner.wrap_pos),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),i.dispose();{let r=this.zpp_inner.rot+n,o=this.zpp_inner;if(o.immutable_midstep("Body::rotation"),o.world)throw new Error("Error: Space::world is immutable");if(o.type===1&&o.space!=null)throw new Error("Error: Static objects cannot be rotated once inside a Space");if(o.rot!==r){if(r!==r)throw new Error("Error: Body::rotation cannot be NaN");o.rot=r,o.invalidate_rot(),o.wake()}}return t.zpp_inner.weak=s,Xn(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=re(),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(pi(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,Xn(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=Ne.COL|Ne.SENSOR|Ne.FLUID;else{let l=re(),r=Pn("InteractionType_COLLISION",()=>new l.callbacks.InteractionType);if(t===r)i=Ne.COL;else{let o=Pn("InteractionType_SENSOR",()=>new l.callbacks.InteractionType);i=t===o?Ne.SENSOR:Ne.FLUID}}return this.zpp_inner.interactingBodies(i,s)}normalImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ne.COL,s=>s.collisionArbiter.normalImpulse(this,n),t)}tangentImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ne.COL,s=>s.collisionArbiter.tangentImpulse(this,n),t)}totalContactsImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ne.COL,s=>s.collisionArbiter.totalImpulse(this,n),t)}rollingImpulse(t=null,n=!1){let s=0,l=this._getArbiters().iterator();for(;;){l.zpp_inner.zpp_inner.valmod();let r=l.zpp_inner.zpp_gl();if(l.zpp_critical=!0,l.zpp_i>=r){l.zpp_next=re().dynamics.ArbiterIterator.zpp_pool,re().dynamics.ArbiterIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1;let o=l.zpp_inner.at(l.zpp_i++),a=o.zpp_inner;a.type===Ne.COL&&(t!=null&&a.b2!==t.zpp_inner&&a.b1!==t.zpp_inner||(s+=o.collisionArbiter.rollingImpulse(this,n)))}return s}buoyancyImpulse(t=null){return this._arbiterImpulseQuery(Ne.FLUID,n=>n.fluidArbiter.buoyancyImpulse(this),t)}dragImpulse(t=null){return this._arbiterImpulseQuery(Ne.FLUID,n=>n.fluidArbiter.dragImpulse(this),t)}totalFluidImpulse(t=null){return this._arbiterImpulseQuery(Ne.FLUID,n=>n.fluidArbiter.totalImpulse(this),t)}constraintsImpulse(){let t=0,n=0,s=0,i=this.zpp_inner.constraints.head;for(;i!=null;){let r=i.elt.outer.bodyImpulse(this),o=r.zpp_inner;o._validate!=null&&o._validate(),t+=o.x,o._validate!=null&&o._validate(),n+=o.y,o._validate!=null&&o._validate(),s+=o.z,r.dispose(),i=i.next}return Xe.get(t,n,s)}totalImpulse(t=null,n=!1){let s=0,i=0,l=0,o=this._getArbiters().iterator();for(;;){o.zpp_inner.zpp_inner.valmod();let p=o.zpp_inner.zpp_gl();if(o.zpp_critical=!0,o.zpp_i>=p){o.zpp_next=re().dynamics.ArbiterIterator.zpp_pool,re().dynamics.ArbiterIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let h=o.zpp_inner.at(o.zpp_i++).zpp_inner;if(h.type===Ne.SENSOR||t!=null&&h.b2!==t.zpp_inner&&h.b1!==t.zpp_inner)continue;let u=h.wrapper().totalImpulse(this,n),_=u.zpp_inner;_._validate!=null&&_._validate(),s+=_.x,_._validate!=null&&_._validate(),i+=_.y,_._validate!=null&&_._validate(),l+=_.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 Xe.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=Se.get(0,0),i=this._getArbiters().iterator();for(;;){i.zpp_inner.zpp_inner.valmod();let _=i.zpp_inner.zpp_gl();if(i.zpp_critical=!0,i.zpp_i>=_){i.zpp_next=re().dynamics.ArbiterIterator.zpp_pool,re().dynamics.ArbiterIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1;let x=i.zpp_inner.at(i.zpp_i++).totalImpulse(this),y=x.xy();n.addeq(y);let z=mi(y),f=fi(y);t+=Math.sqrt(z*z+f*f),y.dispose(),x.dispose()}let r=this._getConstraints();r.zpp_inner.valmod();let o=re().constraint.ConstraintIterator.get(r);for(;;){o.zpp_inner.zpp_inner.valmod();let _=o.zpp_inner;_.zpp_inner.valmod(),_.zpp_inner.zip_length&&(_.zpp_inner.zip_length=!1,_.zpp_inner.user_length=_.zpp_inner.inner.length);let m=_.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=m){o.zpp_next=re().constraint.ConstraintIterator.zpp_pool,re().constraint.ConstraintIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let y=o.zpp_inner.at(o.zpp_i++).bodyImpulse(this),z=y.xy();n.addeq(z);let f=mi(z),v=fi(z);t+=Math.sqrt(f*f+v*v),z.dispose(),y.dispose()}let a=mi(n),p=fi(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=qr.get(this.zpp_inner.arbiters,!0)),this.zpp_inner.wrap_arbiters}_getConstraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=hr.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}_arbiterImpulseQuery(t,n,s){let i=0,l=0,r=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=re().dynamics.ArbiterIterator.zpp_pool,re().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),_=u.zpp_inner;_._validate!=null&&_._validate(),i+=_.x,_._validate!=null&&_._validate(),l+=_.y,_._validate!=null&&_._validate(),r+=_.z,u.dispose()}return Xe.get(i,l,r)}};function so(w,e){let t=Pn("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(w===t)return 2;let n=Pn("BodyType_KINEMATIC",()=>new e.phys.BodyType);return w===n?3:1}function lo(w){let e=w.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 Bo=re();Bo.phys.Body=Ke;Zr(w=>Ke._wrap(w));var bi=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate BodyType derp!")}static get STATIC(){return I.BodyType_STATIC==null&&(I.internal=!0,I.BodyType_STATIC=new w,I.internal=!1),I.BodyType_STATIC}static get DYNAMIC(){return I.BodyType_DYNAMIC==null&&(I.internal=!0,I.BodyType_DYNAMIC=new w,I.internal=!1),I.BodyType_DYNAMIC}static get KINEMATIC(){return I.BodyType_KINEMATIC==null&&(I.internal=!0,I.BodyType_KINEMATIC=new w,I.internal=!1),I.BodyType_KINEMATIC}toString(){return this===I.BodyType_STATIC?"STATIC":this===I.BodyType_DYNAMIC?"DYNAMIC":this===I.BodyType_KINEMATIC?"KINEMATIC":""}},Lo=re();Lo.phys.BodyType=bi;li();var zi=class w extends oi{constructor(){super();let e=new di;this.zpp_inner=e,e.outer=this,e.outer_i=this,this.zpp_inner_i=e,this._inner=this,e.insert_cbtype(ut.ANY_COMPOUND.zpp_inner)}static _wrap(e){return e?e instanceof w?e:e instanceof di?ze(e,t=>{let n=Object.create(w.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?w._wrap(e.zpp_inner):ze(e,t=>{let n=Object.create(w.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:ai._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 Se(0,0),n=0;if(this.visitBodies(s=>{if(s.zpp_inner.wrap_shapes.zpp_inner.inner.head!=null){if(s.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");s.zpp_inner.wrap_worldCOM==null&&s.zpp_inner.getworldCOM();let l=s.zpp_inner.wrap_worldCOM;if(s.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(s.zpp_inner.validate_mass(),s.zpp_inner.massMode==0&&s.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");let r=s.zpp_inner.cmass;t.addeq(l.mul(r,!0)),n+=r}}),n===0)throw new Error("Error: COM of an empty Compound is undefined silly");return t.muleq(1/n),e&&(t.zpp_inner.weak=!0),t}translate(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot translate by null Vec2");let t=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(n=>{n.zpp_inner.wrap_pos==null&&n.zpp_inner.setupPosition(),n.zpp_inner.wrap_pos.addeq(e)}),e.zpp_inner.weak=t,e.zpp_inner.weak&&e.dispose(),this}rotate(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot rotate about a null Vec2");if(t!==t)throw new Error("Error: Cannot rotate by NaN radians");let n=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(s=>{s.rotate(e,t)}),e.zpp_inner.weak=n,e.zpp_inner.weak&&e.dispose(),this}toString(){return"Compound"+this.zpp_inner.id}};di._wrapFn=w=>ze(w,e=>{let t=Object.create(zi.prototype);return t.zpp_inner=e,e.outer=t,e.outer_i=t,t.zpp_inner_i=e,t._inner=t,t});Object.defineProperty(zi.prototype,"bodies",{get:function(){return this.zpp_inner.wrap_bodies},configurable:!0});Object.defineProperty(zi.prototype,"constraints",{get:function(){return this.zpp_inner.wrap_constraints},configurable:!0});Object.defineProperty(zi.prototype,"compounds",{get:function(){return this.zpp_inner.wrap_compounds},configurable:!0});var Bs=class w{get _inner(){return this}constructor(e=0,t=1,n=2,s=1,i=.001){let l;if(Ie.zpp_pool==null?l=new Ie:(l=Ie.zpp_pool,Ie.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(Ie.WAKE|Ie.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(Ie.WAKE|Ie.ANGDRAG|Ie.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(Ie.WAKE|Ie.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(Ie.WAKE|Ie.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(Ie.WAKE|Ie.ARBITERS)}}static _wrap(e){return e instanceof w?e:e?e instanceof Ie?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?w._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(Ie.WAKE|Ie.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(Ie.WAKE|Ie.ANGDRAG|Ie.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(Ie.WAKE|Ie.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(Ie.WAKE|Ie.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(Ie.WAKE|Ie.ARBITERS)}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}copy(){let e=new w(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 w(.4,.2,.38,.7,.005)}static steel(){return new w(.2,.57,.74,7.8,.001)}static ice(){return new w(.3,.03,.1,.9,1e-4)}static rubber(){return new w(.8,1,1.4,1.5,.01)}static glass(){return new w(.4,.4,.94,2.6,.002)}static sand(){return new w(-1,.45,.6,1.6,16)}};Ie._wrapFn=w=>ze(w,e=>{let t=Object.create(Bs.prototype);return t.zpp_inner=e,e.outer=t,t});var Ls=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate GravMassMode derp!")}static get DEFAULT(){return I.GravMassMode_DEFAULT==null&&(I.internal=!0,I.GravMassMode_DEFAULT=new w,I.internal=!1),I.GravMassMode_DEFAULT}static get FIXED(){return I.GravMassMode_FIXED==null&&(I.internal=!0,I.GravMassMode_FIXED=new w,I.internal=!1),I.GravMassMode_FIXED}static get SCALED(){return I.GravMassMode_SCALED==null&&(I.internal=!0,I.GravMassMode_SCALED=new w,I.internal=!1),I.GravMassMode_SCALED}toString(){return this===I.GravMassMode_DEFAULT?"DEFAULT":this===I.GravMassMode_FIXED?"FIXED":this===I.GravMassMode_SCALED?"SCALED":""}},jo=re();jo.phys.GravMassMode=Ls;var js=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate InertiaMode derp!")}static get DEFAULT(){return I.InertiaMode_DEFAULT==null&&(I.internal=!0,I.InertiaMode_DEFAULT=new w,I.internal=!1),I.InertiaMode_DEFAULT}static get FIXED(){return I.InertiaMode_FIXED==null&&(I.internal=!0,I.InertiaMode_FIXED=new w,I.internal=!1),I.InertiaMode_FIXED}toString(){return this===I.InertiaMode_DEFAULT?"DEFAULT":this===I.InertiaMode_FIXED?"FIXED":""}},Do=re();Do.phys.InertiaMode=js;var Ds=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate MassMode derp!")}static get DEFAULT(){return I.MassMode_DEFAULT==null&&(I.internal=!0,I.MassMode_DEFAULT=new w,I.internal=!1),I.MassMode_DEFAULT}static get FIXED(){return I.MassMode_FIXED==null&&(I.internal=!0,I.MassMode_FIXED=new w,I.internal=!1),I.MassMode_FIXED}toString(){return this===I.MassMode_DEFAULT?"DEFAULT":this===I.MassMode_FIXED?"FIXED":""}},Fo=re();Fo.phys.MassMode=Ds;var rs=class w extends Mn{constructor(e=50,t,n,s){super();let i=re(),l=new Si;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>Xi.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");l.radius=e,l.invalidate_radius()}if(t!=null){if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=t.zpp_inner;r._validate!=null&&r._validate(),l.localCOMx=r.x,r._validate!=null&&r._validate(),l.localCOMy=r.y,r.weak&&t.dispose()}else l.localCOMx=0,l.localCOMy=0;n==null?Ie.zpp_pool!=null?(l.material=Ie.zpp_pool,Ie.zpp_pool=l.material.next,l.material.next=null):l.material=new Ie:(l.immutable_midstep("Shape::material"),l.setMaterial(n.zpp_inner),l.material.wrapper()),s==null?pt.zpp_pool!=null?(l.filter=pt.zpp_pool,pt.zpp_pool=l.filter.next,l.filter.next=null):l.filter=new pt:(l.immutable_midstep("Shape::filter"),l.setFilter(s.zpp_inner),l.filter.wrapper()),l.insert_cbtype(ut.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof w?e:e instanceof Si?ze(e,t=>{let n=Object.create(w.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?w._wrap(e.zpp_inner_zn):ze(e,t=>{let n=Object.create(w.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=re();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>Xi.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}};to(w=>rs._wrap(w));var Ro=re();Ro.shape.Circle=rs;var Pi=class w extends Mn{constructor(e,t,n){super();let s=re();if(e==null)throw new Error("Error: localVerts cannot be null");let i=new Un;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 Se))throw new Error("Error: Array<Vec2> contains non Vec2 objects");if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.wrap_lverts==null&&i.getlverts();let r=l.zpp_inner;r._validate!=null&&r._validate();let o=r.x;r._validate!=null&&r._validate();let a=r.y,p=new Se(o,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,r=l.iterator();for(;;){r.zpp_inner.zpp_inner.valmod();let c=r.zpp_inner.zpp_gl();if(r.zpp_critical=!0,r.zpp_i>=c){r.zpp_next=s.geom.Vec2Iterator.zpp_pool,s.geom.Vec2Iterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let h=r.zpp_inner.at(r.zpp_i++);if(h==null)throw new Error("Error: Vec2List contains null objects");if(h.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.wrap_lverts==null&&i.getlverts();let u=h.zpp_inner;u._validate!=null&&u._validate();let _=u.x;u._validate!=null&&u._validate();let m=u.y,x=new Se(_,m);i.wrap_lverts.push(x)}l.zpp_inner._validate!=null&&l.zpp_inner._validate();let o=l.zpp_inner.inner,a=null,p=o.head;for(;p!=null;){let c=p.elt;c.outer?.zpp_inner?.weak?(p=o.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 r=l;do{i.wrap_lverts==null&&i.getlverts();let o=new Se(r.x,r.y);i.wrap_lverts.push(o),r=r.next}while(r!==l)}}else throw new Error("Error: Invalid type for polygon object, should be Array<Vec2>, Vec2List, GeomPoly or for flash10+ flash.Vector<Vec2>");t==null?Ie.zpp_pool!=null?(i.material=Ie.zpp_pool,Ie.zpp_pool=i.material.next,i.material.next=null):i.material=new Ie:(i.immutable_midstep("Shape::material"),i.setMaterial(t.zpp_inner),i.material.wrapper()),n==null?pt.zpp_pool!=null?(i.filter=pt.zpp_pool,pt.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new pt:(i.immutable_midstep("Shape::filter"),i.setFilter(n.zpp_inner),i.filter.wrapper()),i.insert_cbtype(ut.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof w?e:e instanceof Un?ze(e,t=>{let n=Object.create(w.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?w._wrap(e.zpp_inner_zn):ze(e,t=>{let n=Object.create(w.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 Se(e,t);l.zpp_inner.weak=i;let r=new Se(e+n,t);r.zpp_inner.weak=i;let o=new Se(e+n,t+s);o.zpp_inner.weak=i;let a=new Se(e,t+s);return a.zpp_inner.weak=i,[l,r,o,a]}static box(e,t=e,n=!1){if(e!==e||t!==t)throw new Error("Error: Polygon.box cannot accept NaN arguments");return w.rect(-e/2,-t/2,e,t,n)}static regular(e,t,n,s=0,i=!1){if(e!==e||t!==t||s!==s)throw new Error("Error: Polygon.regular cannot accept NaN arguments");let l=[],r=Math.PI*2/n;for(let o=0;o<n;o++){let a=o*r+s,p=Math.cos(a)*e,c=Math.sin(a)*t,h=new Se(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()}};no(w=>Pi._wrap(w));var Go=re();Go.shape.Polygon=Pi;var qo=8;function ro(w,e,t=qo){let n=[];for(let s=0;s<=t;s++){let i=-Math.PI/2+Math.PI*s/t;n.push({x:w+e*Math.cos(i),y:e*Math.sin(i)})}for(let s=0;s<=t;s++){let i=Math.PI/2+Math.PI*s/t;n.push({x:-w+e*Math.cos(i),y:e*Math.sin(i)})}return n}var os=class w extends Mn{constructor(e=100,t=40,n,s,i){if(super(),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 l=t/2,r=(e-t)/2;this._radius=l,this._halfLength=r;let o=new Un;this.zpp_inner_zn=o,this.zpp_inner=o,this.zpp_inner_i=o,o.outer=this,o.outer_zn=this,o.outer_i=this,this._inner=this,o._isCapsule=!0,o._capsuleRadius=l,o._capsuleHalfLength=r;let a=0,p=0;if(n!=null){if(n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=n.zpp_inner;h._validate!=null&&h._validate(),a=h.x,h._validate!=null&&h._validate(),p=h.y,h.weak&&n.dispose()}let c=ro(r,l);o.wrap_lverts==null&&o.getlverts();for(let h of c){let u=new Se(h.x+a,h.y+p);o.wrap_lverts.push(u)}s==null?Ie.zpp_pool!=null?(o.material=Ie.zpp_pool,Ie.zpp_pool=o.material.next,o.material.next=null):o.material=new Ie:(o.immutable_midstep("Shape::material"),o.setMaterial(s.zpp_inner),o.material.wrapper()),i==null?pt.zpp_pool!=null?(o.filter=pt.zpp_pool,pt.zpp_pool=o.filter.next,o.filter.next=null):o.filter=new pt:(o.immutable_midstep("Shape::filter"),o.setFilter(i.zpp_inner),o.filter.wrapper()),o.insert_cbtype(ut.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof w?e:e instanceof Un&&e._isCapsule?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner_zn=t,n.zpp_inner=t,n.zpp_inner_i=t,n._radius=t._capsuleRadius??0,n._halfLength=t._capsuleHalfLength??0,t.outer=n,t.outer_zn=n,t.outer_i=n,n._inner=n,n}):e.zpp_inner_zn?w._wrap(e.zpp_inner_zn):ze(e,t=>{let n=Object.create(w.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i,n._radius=t._capsuleRadius??0,n._halfLength=t._capsuleHalfLength??0,n}):null}get type(){return Yi.CAPSULE}isPolygon(){return!1}isCapsule(){return!0}get radius(){return this.zpp_inner_zn._capsuleRadius??this._radius}set radius(e){let t=this.zpp_inner_zn,n=re();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!==this._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");this._radius=e,t._capsuleRadius=e,this._regenerateVertices()}}get halfLength(){return this.zpp_inner_zn._capsuleHalfLength??this._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!==this._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");this._halfLength=e,t._capsuleHalfLength=e,this._regenerateVertices()}}_regenerateVertices(){let e=this.zpp_inner_zn;e.validate_localCOM();let t=e.localCOMx,n=e.localCOMy;for(e.wrap_lverts==null&&e.getlverts();e.wrap_lverts.length>0;)e.wrap_lverts.pop();let s=ro(this._halfLength,this._radius);for(let i of s){let l=new Se(i.x+t,i.y+n);e.wrap_lverts.push(l)}}get width(){return 2*(this.halfLength+this.radius)}get height(){return 2*this.radius}};io(w=>os._wrap(w));var Wo=re();Wo.shape.Capsule=os;var Fs=class w{constructor(){if(!$e.internal)throw new Error("Error: Cannot instantiate an Edge derp!")}static _wrap(e){return e?e instanceof w?e:e instanceof $e?ze(e,t=>{$e.internal=!0;let n=new w;return $e.internal=!1,n.zpp_inner=t,t.outer=n,n}):null:null}get polygon(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.outer_zn}get localNormal(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.wrap_lnorm==null&&e.getlnorm(),e.wrap_lnorm}get worldNormal(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.wrap_gnorm==null&&e.getgnorm(),e.wrap_gnorm}get length(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_laxi(),e.length}get localProjection(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_laxi(),e.lprojection}get worldProjection(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");if(e.polygon.body==null)throw new Error("Error: Edge world projection only makes sense for Polygons contained within a rigid body");return e.polygon.validate_gaxi(),e.gprojection}get localVertex1(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_laxi(),this._wrapVert(e.lp0)}get localVertex2(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_laxi(),this._wrapVert(e.lp1)}get worldVertex1(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_gaxi(),this._wrapVert(e.gp0)}get worldVertex2(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_gaxi(),this._wrapVert(e.gp1)}toString(){let e=this.zpp_inner;return e.polygon==null?"Edge(object-pooled)":e.polygon.body==null?(e.polygon.validate_laxi(),"{ localNormal : { x: "+e.lnormx+" y: "+e.lnormy+" } }"):(e.polygon.validate_gaxi(),"{ localNormal : { x: "+e.lnormx+" y: "+e.lnormy+" } worldNormal : { x: "+e.gnormx+" y: "+e.gnormy+" } }")}_wrapVert(e){let t=re();if(e.outer==null){e.outer=new t.geom.Vec2;let n=e.outer.zpp_inner;n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=pe.zpp_pool,pe.zpp_pool=n,e.outer.zpp_inner=e}return e.outer}};$e._wrapFn=w=>ze(w,e=>{$e.internal=!0;let t=new Fs;return $e.internal=!1,t.zpp_inner=e,e.outer=t,t});var Rs=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate ValidationResult derp!")}static get VALID(){return I.ValidationResult_VALID==null&&(I.internal=!0,I.ValidationResult_VALID=new w,I.internal=!1),I.ValidationResult_VALID}static get DEGENERATE(){return I.ValidationResult_DEGENERATE==null&&(I.internal=!0,I.ValidationResult_DEGENERATE=new w,I.internal=!1),I.ValidationResult_DEGENERATE}static get CONCAVE(){return I.ValidationResult_CONCAVE==null&&(I.internal=!0,I.ValidationResult_CONCAVE=new w,I.internal=!1),I.ValidationResult_CONCAVE}static get SELF_INTERSECTING(){return I.ValidationResult_SELF_INTERSECTING==null&&(I.internal=!0,I.ValidationResult_SELF_INTERSECTING=new w,I.internal=!1),I.ValidationResult_SELF_INTERSECTING}toString(){return this===I.ValidationResult_VALID?"VALID":this===I.ValidationResult_DEGENERATE?"DEGENERATE":this===I.ValidationResult_CONCAVE?"CONCAVE":this===I.ValidationResult_SELF_INTERSECTING?"SELF_INTERSECTING":""}},Jo=re();Jo.shape.ValidationResult=Rs;var Sl=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate Broadphase derp!")}static get DYNAMIC_AABB_TREE(){return I.Broadphase_DYNAMIC_AABB_TREE==null&&(I.internal=!0,I.Broadphase_DYNAMIC_AABB_TREE=new w,I.internal=!1),I.Broadphase_DYNAMIC_AABB_TREE}static get SWEEP_AND_PRUNE(){return I.Broadphase_SWEEP_AND_PRUNE==null&&(I.internal=!0,I.Broadphase_SWEEP_AND_PRUNE=new w,I.internal=!1),I.Broadphase_SWEEP_AND_PRUNE}static get SPATIAL_HASH(){return I.Broadphase_SPATIAL_HASH==null&&(I.internal=!0,I.Broadphase_SPATIAL_HASH=new w,I.internal=!1),I.Broadphase_SPATIAL_HASH}toString(){return this===I.Broadphase_DYNAMIC_AABB_TREE?"DYNAMIC_AABB_TREE":this===I.Broadphase_SWEEP_AND_PRUNE?"SWEEP_AND_PRUNE":this===I.Broadphase_SPATIAL_HASH?"SPATIAL_HASH":""}};var Hi=class w{get _inner(){return this}constructor(e=1,t=-1,n=1,s=-1,i=1,l=-1){let r;pt.zpp_pool==null?r=new pt:(r=pt.zpp_pool,pt.zpp_pool=r.next,r.next=null),this.zpp_inner=r,r.outer=this,r.collisionGroup!=e&&(r.collisionGroup=e,r.invalidate()),r.collisionMask!=t&&(r.collisionMask=t,r.invalidate()),r.sensorGroup!=n&&(r.sensorGroup=n,r.invalidate()),r.sensorMask!=s&&(r.sensorMask=s,r.invalidate()),r.fluidGroup!=i&&(r.fluidGroup=i,r.invalidate()),r.fluidMask!=l&&(r.fluidMask=l,r.invalidate())}static _wrap(e){return e instanceof w?e:e?e instanceof pt?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?w._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=re();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 w(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)+" }"}};pt._wrapFn=w=>ze(w,e=>{let t=Object.create(Hi.prototype);return t.zpp_inner=e,e.outer=t,t});var Gs=class w{get _inner(){return this}constructor(e=!1){let t=new Fi;this.zpp_inner=t,t.outer=this,t.ignore!=e&&(t.invalidate(!0),t.ignore=e)}static _wrap(e){return e instanceof w?e:e?e instanceof Fi?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?w._wrap(e.zpp_inner):null:null}get group(){return this.zpp_inner.group==null?null:this.zpp_inner.group.outer}set group(e){if(e===this)throw new Error("Error: Cannot assign InteractionGroup to itself");this.zpp_inner.setGroup(e==null?null:e.zpp_inner)}get ignore(){return this.zpp_inner.ignore}set ignore(e){this.zpp_inner.ignore!=e&&(this.zpp_inner.invalidate(!0),this.zpp_inner.ignore=e)}get interactors(){if(this.zpp_inner.wrap_interactors==null){let e=re();this.zpp_inner.wrap_interactors=e.zpp_nape.util.ZPP_InteractorList.get(this.zpp_inner.interactors,!0)}return this.zpp_inner.wrap_interactors}get groups(){if(this.zpp_inner.wrap_groups==null){let e=re();this.zpp_inner.wrap_groups=e.zpp_nape.util.ZPP_InteractionGroupList.get(this.zpp_inner.groups,!0)}return this.zpp_inner.wrap_groups}toString(){let e="InteractionGroup";return this.zpp_inner.ignore&&(e+=":ignore"),e}};Fi._wrapFn=w=>ze(w,e=>{let t=Object.create(Gs.prototype);return t.zpp_inner=e,e.outer=t,t});var qs=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate ArbiterType derp!")}static get COLLISION(){return I.ArbiterType_COLLISION==null&&(I.internal=!0,I.ArbiterType_COLLISION=new w,I.internal=!1),I.ArbiterType_COLLISION}static get SENSOR(){return I.ArbiterType_SENSOR==null&&(I.internal=!0,I.ArbiterType_SENSOR=new w,I.internal=!1),I.ArbiterType_SENSOR}static get FLUID(){return I.ArbiterType_FLUID==null&&(I.internal=!0,I.ArbiterType_FLUID=new w,I.internal=!1),I.ArbiterType_FLUID}toString(){return this===I.ArbiterType_COLLISION?"COLLISION":this===I.ArbiterType_SENSOR?"SENSOR":this===I.ArbiterType_FLUID?"FLUID":""}},Uo=re();Uo.dynamics.ArbiterType=qs;li();var wi=class{get _inner(){return this}constructor(){if(this.zpp_inner=null,!Ne.internal)throw new Error("Error: Cannot instantiate Arbiter derp!")}get isSleeping(){return this._activeCheck(),this.zpp_inner.sleeping}get type(){return Ne.types[this.zpp_inner.type]}get collisionArbiter(){return this.zpp_inner.type==Ne.COL?this.zpp_inner.colarb.outer_zn:null}get fluidArbiter(){return this.zpp_inner.type==Ne.FLUID?this.zpp_inner.fluidarb.outer_zn:null}get shape1(){return this._activeCheck(),this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws2.outer:this.zpp_inner.ws1.outer}get shape2(){return this._activeCheck(),this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws1.outer:this.zpp_inner.ws2.outer}get body1(){return this._activeCheck(),this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.b2.outer:this.zpp_inner.b1.outer}get body2(){return this._activeCheck(),this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.b1.outer:this.zpp_inner.b2.outer}get state(){this._activeCheck();let e=re(),t=this.zpp_inner.immState;return t==5?(I.PreFlag_ACCEPT==null&&(I.internal=!0,I.PreFlag_ACCEPT=new e.callbacks.PreFlag,I.internal=!1),I.PreFlag_ACCEPT):t==1?(I.PreFlag_ACCEPT_ONCE==null&&(I.internal=!0,I.PreFlag_ACCEPT_ONCE=new e.callbacks.PreFlag,I.internal=!1),I.PreFlag_ACCEPT_ONCE):t==6?(I.PreFlag_IGNORE==null&&(I.internal=!0,I.PreFlag_IGNORE=new e.callbacks.PreFlag,I.internal=!1),I.PreFlag_IGNORE):(I.PreFlag_IGNORE_ONCE==null&&(I.internal=!0,I.PreFlag_IGNORE_ONCE=new e.callbacks.PreFlag,I.internal=!1),I.PreFlag_IGNORE_ONCE)}isCollisionArbiter(){return this.zpp_inner.type==Ne.COL}isFluidArbiter(){return this.zpp_inner.type==Ne.FLUID}isSensorArbiter(){return this.zpp_inner.type==Ne.SENSOR}totalImpulse(e=null,t=!1){return this._activeCheck(),e!=null&&this._checkBody(e),Xe.get(0,0,0)}toString(){let e=this.zpp_inner.type==Ne.COL?"CollisionArbiter":this.zpp_inner.type==Ne.FLUID?"FluidArbiter":"SensorArbiter";if(this.zpp_inner.cleared)return e+"(object-pooled)";this._activeCheck();let t=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws2.outer:this.zpp_inner.ws1.outer,n=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws1.outer:this.zpp_inner.ws2.outer,s=e+"("+t.toString()+"|"+n.toString()+")";return this.zpp_inner.type==Ne.COL&&(s+="["+["SD","DD"][this.zpp_inner.colarb.stat?0:1]+"]"),s+="<-"+this.state.toString(),s}_activeCheck(){if(!this.zpp_inner.active)throw new Error("Error: Arbiter not currently in use")}_checkBody(e){let t=this.zpp_inner,n=t.ws1.id>t.ws2.id?t.b2.outer:t.b1.outer,s=t.ws1.id>t.ws2.id?t.b1.outer:t.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Arbiter does not relate to body")}},Ko=re();Ko.dynamics.Arbiter=wi;var Al=class extends wi{constructor(){super()}get contacts(){return this._activeCheck(),this.zpp_inner.colarb.wrap_contacts==null&&this.zpp_inner.colarb.setupcontacts(),this.zpp_inner.colarb.wrap_contacts}get normal(){return this._activeCheck(),this.zpp_inner.colarb.wrap_normal==null&&this.zpp_inner.colarb.getnormal(),this.zpp_inner.colarb.wrap_normal}get radius(){return this._activeCheck(),this.zpp_inner.colarb.radius}get referenceEdge1(){this._activeCheck();let e=this.zpp_inner.colarb.__ref_edge1;if(e!=null){let t=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws2.outer:this.zpp_inner.ws1.outer;t.zpp_inner.type==1?t.zpp_inner!=e.polygon&&(e=this.zpp_inner.colarb.__ref_edge2):e=this.zpp_inner.colarb.__ref_edge2}return e==null?null:e.wrapper()}get referenceEdge2(){this._activeCheck();let e=this.zpp_inner.colarb.__ref_edge1;if(e!=null){let t=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws1.outer:this.zpp_inner.ws2.outer;t.zpp_inner.type==1?t.zpp_inner!=e.polygon&&(e=this.zpp_inner.colarb.__ref_edge2):e=this.zpp_inner.colarb.__ref_edge2}return e==null?null:e.wrapper()}get elasticity(){return this._activeCheck(),this.zpp_inner.colarb.validate_props(),this.zpp_inner.colarb.restitution}set elasticity(e){if(this._mutableCheck("elasticity"),e!==e)throw new Error("Error: CollisionArbiter::elasticity cannot be NaN");if(e<0)throw new Error("Error: CollisionArbiter::elasticity cannot be negative");this.zpp_inner.colarb.restitution=e,this.zpp_inner.colarb.userdef_restitution=!0,this._activeCheck(),this.zpp_inner.colarb.validate_props()}get dynamicFriction(){return this._activeCheck(),this.zpp_inner.colarb.validate_props(),this.zpp_inner.colarb.dyn_fric}set dynamicFriction(e){if(this._mutableCheck("dynamicFriction"),e!==e)throw new Error("Error: CollisionArbiter::dynamicFriction cannot be NaN");if(e<0)throw new Error("Error: CollisionArbiter::dynamicFriction cannot be negative");this.zpp_inner.colarb.dyn_fric=e,this.zpp_inner.colarb.userdef_dyn_fric=!0,this._activeCheck(),this.zpp_inner.colarb.validate_props()}get staticFriction(){return this._activeCheck(),this.zpp_inner.colarb.validate_props(),this.zpp_inner.colarb.stat_fric}set staticFriction(e){if(this._mutableCheck("staticFriction"),e!==e)throw new Error("Error: CollisionArbiter::staticFriction cannot be NaN");if(e<0)throw new Error("Error: CollisionArbiter::staticFriction cannot be negative");this.zpp_inner.colarb.stat_fric=e,this.zpp_inner.colarb.userdef_stat_fric=!0,this._activeCheck(),this.zpp_inner.colarb.validate_props()}get rollingFriction(){return this._activeCheck(),this.zpp_inner.colarb.validate_props(),this.zpp_inner.colarb.rfric}set rollingFriction(e){if(this._mutableCheck("rollingFriction"),e!==e)throw new Error("Error: CollisionArbiter::rollingFriction cannot be NaN");if(e<0)throw new Error("Error: CollisionArbiter::rollingFriction cannot be negative");this.zpp_inner.colarb.rfric=e,this.zpp_inner.colarb.userdef_rfric=!0,this._activeCheck(),this.zpp_inner.colarb.validate_props()}firstVertex(){return this._activeCheck(),this.zpp_inner.colarb.__ref_edge1!=null!=(this.zpp_inner.colarb.__ref_edge2!=null)?this.zpp_inner.colarb.__ref_vertex==-1:!1}secondVertex(){return this._activeCheck(),this.zpp_inner.colarb.__ref_edge1!=null!=(this.zpp_inner.colarb.__ref_edge2!=null)?this.zpp_inner.colarb.__ref_vertex==1:!1}normalImpulse(e=null,t=!1){return this._activeCheck(),e!=null&&this._checkBody(e),this._accumulateImpulse("normalImpulse",e,t)}tangentImpulse(e=null,t=!1){return this._activeCheck(),e!=null&&this._checkBody(e),this._accumulateImpulse("tangentImpulse",e,t)}totalImpulse(e=null,t=!1){return this._activeCheck(),e!=null&&this._checkBody(e),this._accumulateImpulse("totalImpulse",e,t)}rollingImpulse(e=null,t=!1){this._activeCheck(),e!=null&&this._checkBody(e);let n=this.zpp_inner.colarb;return!t||n.oc1.fresh?n.oc1.wrapper().rollingImpulse(e):0}_mutableCheck(e){if(!this.zpp_inner.colarb.mutable)throw new Error("Error: CollisionArbiter::"+e+" is only mutable during a pre-handler")}_accumulateImpulse(e,t,n){let s=0,i=0,l=0,r=this.zpp_inner.colarb;if(!n||r.oc1.fresh){let o=r.oc1.wrapper()[e](t),a=o.zpp_inner;a._validate!=null&&a._validate(),s+=a.x,a._validate!=null&&a._validate(),i+=a.y,a._validate!=null&&a._validate(),l+=a.z,o.dispose()}if(r.hc2&&(!n||r.oc2.fresh)){let o=r.oc2.wrapper()[e](t),a=o.zpp_inner;a._validate!=null&&a._validate(),s+=a.x,a._validate!=null&&a._validate(),i+=a.y,a._validate!=null&&a._validate(),l+=a.z,o.dispose()}return Xe.get(s,i,l)}};var Vl=class extends wi{constructor(){super()}get position(){return this._activeCheck(),this.zpp_inner.fluidarb.wrap_position==null&&this.zpp_inner.fluidarb.getposition(),Se._wrap(this.zpp_inner.fluidarb.wrap_position)}set position(e){if(!this.zpp_inner.fluidarb.mutable)throw new Error("Error: Arbiter is mutable only within a pre-handler");if(e==null)throw new Error("Error: FluidArbiter::position cannot be null");this._activeCheck(),this.zpp_inner.fluidarb.wrap_position==null&&this.zpp_inner.fluidarb.getposition(),this.zpp_inner.fluidarb.wrap_position.set(e)}get overlap(){return this._activeCheck(),this.zpp_inner.fluidarb.overlap}set overlap(e){if(!this.zpp_inner.fluidarb.mutable)throw new Error("Error: Arbiter is mutable only within a pre-handler");if(e!==e)throw new Error("Error: FluidArbiter::overlap cannot be NaN");if(e<=0||e==1/0)throw new Error("Error: FluidArbiter::overlap must be strictly positive and non infinite");this.zpp_inner.fluidarb.overlap=e}buoyancyImpulse(e=null){this._activeCheck(),e!=null&&this._checkBody(e);let t=this.zpp_inner.fluidarb;return e==null?Xe.get(t.buoyx,t.buoyy,0):e.zpp_inner==this.zpp_inner.b2?Xe.get(t.buoyx,t.buoyy,t.buoyy*t.r2x-t.buoyx*t.r2y):Xe.get(-t.buoyx,-t.buoyy,-(t.buoyy*t.r1x-t.buoyx*t.r1y))}dragImpulse(e=null){this._activeCheck(),e!=null&&this._checkBody(e);let t=this.zpp_inner.fluidarb,n=e==null||e.zpp_inner==this.zpp_inner.b2?1:-1;return Xe.get(t.dampx*n,t.dampy*n,t.adamp*n)}totalImpulse(e=null,t=!1){this._activeCheck(),e!=null&&this._checkBody(e);let n=this.buoyancyImpulse(e),s=this.dragImpulse(e),i=n.zpp_inner,l=s.zpp_inner;return i._validate!=null&&i._validate(),l._validate!=null&&l._validate(),l.x=l.x+i.x,i._validate!=null&&i._validate(),l._validate!=null&&l._validate(),l.y=l.y+i.y,i._validate!=null&&i._validate(),l._validate!=null&&l._validate(),l.z=l.z+i.z,n.dispose(),s}};var Ws=class{get _inner(){return this}constructor(){if(this.zpp_inner=null,!we.internal)throw new Error("Error: Cannot instantiate Contact derp!")}get arbiter(){if(this.zpp_inner.arbiter==null)return null;let e=this.zpp_inner.arbiter.outer;return e.zpp_inner.type==Ne.COL?e.zpp_inner.colarb.outer_zn:null}get penetration(){return this._inactiveCheck(),-this.zpp_inner.dist}get position(){return this._inactiveCheck(),this.zpp_inner.wrap_position==null&&this.zpp_inner.getposition(),Se._wrap(this.zpp_inner.wrap_position)}get fresh(){return this._inactiveCheck(),this.zpp_inner.fresh}get friction(){return this._inactiveCheck(),this.zpp_inner.inner.friction}normalImpulse(e=null){this._inactiveCheck();let t=this.zpp_inner.arbiter.colarb,n=this.zpp_inner.inner,s=n.jnAcc;return e==null?Xe.get(t.nx*s,t.ny*s):(this._checkBody(e,t),e==t.b1.outer?Xe.get(t.nx*-s,t.ny*-s,-(t.ny*n.r1x-t.nx*n.r1y)*s):Xe.get(t.nx*s,t.ny*s,(t.ny*n.r2x-t.nx*n.r2y)*s))}tangentImpulse(e=null){this._inactiveCheck();let t=this.zpp_inner.arbiter.colarb,n=this.zpp_inner.inner,s=n.jtAcc;return e==null?Xe.get(-t.ny*s,t.nx*s):(this._checkBody(e,t),e==t.b1.outer?Xe.get(t.ny*s,-t.nx*s,-(n.r1x*t.nx+n.r1y*t.ny)*s):Xe.get(-t.ny*s,t.nx*s,(n.r2x*t.nx+n.r2y*t.ny)*s))}rollingImpulse(e=null){this._inactiveCheck();let t=this.zpp_inner.arbiter.colarb,n=t.jrAcc;return e==null?n:(this._checkBody(e,t),e==t.b1.outer?-n:n)}totalImpulse(e=null){this._inactiveCheck();let t=this.zpp_inner.arbiter.colarb,n=this.zpp_inner.inner,s=n.jnAcc,i=n.jtAcc,l=t.jrAcc;if(e==null)return Xe.get(t.nx*s-t.ny*i,t.ny*s+t.nx*i,l);this._checkBody(e,t);let r=t.nx*s-t.ny*i,o=t.ny*s+t.nx*i;return e==t.b1.outer?Xe.get(-r,-o,-(o*n.r1x-r*n.r1y)-l):Xe.get(r,o,o*n.r2x-r*n.r2y+l)}toString(){return this.zpp_inner.arbiter==null||this.zpp_inner.arbiter.cleared?"{object-pooled}":"{Contact}"}_inactiveCheck(){if(this.zpp_inner.inactiveme())throw new Error("Error: Contact not currently in use")}_checkBody(e,t){if(e!=t.b1.outer&&e!=t.b2.outer)throw new Error("Error: Contact does not relate to the given body")}};we._wrapFn=w=>{we.internal=!0;let e=new Ws;return we.internal=!1,e.zpp_inner=w,w.outer=e,e};function Yo(w){let e=0,t=w.inner.next;for(;t!=null;)t.active&&t.arbiter.active&&e++,t=t.next;return e}function Vn(w){return w.valmod(),w.zip_length&&(w.zip_length=!1,w.user_length=Yo(w)),w.user_length}function ft(){if(this.zpp_next=null,this.zpp_critical=!1,this.zpp_i=0,this.zpp_inner=null,!Ti.internal)throw new Error("Error: Cannot instantiate ContactIterator derp!")}ft.zpp_pool=null;ft.get=function(w){let e;return ft.zpp_pool==null?(Ti.internal=!0,e=new ft,Ti.internal=!1):(e=ft.zpp_pool,ft.zpp_pool=e.zpp_next),e.zpp_i=0,e.zpp_inner=w,e.zpp_critical=!1,e};ft.prototype.zpp_inner=null;ft.prototype.zpp_i=null;ft.prototype.zpp_critical=null;ft.prototype.zpp_next=null;ft.prototype.hasNext=function(){this.zpp_inner.zpp_inner.valmod();let w=Vn(this.zpp_inner.zpp_inner);return this.zpp_critical=!0,this.zpp_i<w?!0:(this.zpp_next=ft.zpp_pool,ft.zpp_pool=this,this.zpp_inner=null,!1)};ft.prototype.next=function(){return this.zpp_critical=!1,this.zpp_inner.at(this.zpp_i++)};function Et(){this.zpp_inner=null,this.zpp_inner=new Ti,this.zpp_inner.outer=this}Et.fromArray=function(w){if(w==null)throw new Error("Error: Cannot convert null Array to Nape list");let e=re(),t=new e.dynamics.ContactList;for(let n=0;n<w.length;n++)t.push(w[n]);return t};Et.prototype.zpp_inner=null;Object.defineProperty(Et.prototype,"length",{get:function(){return Vn(this.zpp_inner)}});Et.prototype.has=function(w){return this.zpp_inner.valmod(),this.zpp_inner.inner.has(w.zpp_inner)};Et.prototype.at=function(w){this.zpp_inner.valmod();let e=Vn(this.zpp_inner);if(w<0||w>=e)throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(w=Vn(this.zpp_inner)-1-w),w<this.zpp_inner.at_index||this.zpp_inner.at_ite==null)for(this.zpp_inner.at_index=0,this.zpp_inner.at_ite=this.zpp_inner.inner.next;;){let t=this.zpp_inner.at_ite;if(t.active&&t.arbiter.active)break;this.zpp_inner.at_ite=this.zpp_inner.at_ite.next}for(;this.zpp_inner.at_index!=w;)for(this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;;){let t=this.zpp_inner.at_ite;if(t.active&&t.arbiter.active)break;this.zpp_inner.at_ite=this.zpp_inner.at_ite.next}return this.zpp_inner.at_ite.wrapper()};Et.prototype.push=function(w){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(w):!0;if(e){if(this.zpp_inner.reverse_flag)this.zpp_inner.inner.add(w.zpp_inner);else{if(this.zpp_inner.push_ite==null){let t=Vn(this.zpp_inner);t==0?this.zpp_inner.push_ite=null:this.zpp_inner.push_ite=this.zpp_inner.inner.iterator_at(t-1)}this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,w.zpp_inner)}this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(w)}return e};Et.prototype.unshift=function(w){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(w):!0;if(e){if(this.zpp_inner.reverse_flag){if(this.zpp_inner.push_ite==null){let t=Vn(this.zpp_inner);t==0?this.zpp_inner.push_ite=null:this.zpp_inner.push_ite=this.zpp_inner.inner.iterator_at(t-1)}this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,w.zpp_inner)}else this.zpp_inner.inner.add(w.zpp_inner);this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(w)}return e};Et.prototype.pop=function(){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");if(this.zpp_inner.modify_test(),Vn(this.zpp_inner)==0)throw new Error("Error: Cannot remove from empty list");this.zpp_inner.valmod();let e;if(this.zpp_inner.reverse_flag){e=this.zpp_inner.inner.next;let t=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}else{this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let t=Vn(this.zpp_inner),n;t==1?n=null:n=this.zpp_inner.inner.iterator_at(t-2),e=n==null?this.zpp_inner.inner.next:n.next;let s=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(s),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(n)}return this.zpp_inner.invalidate(),e.wrapper()};Et.prototype.shift=function(){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");if(this.zpp_inner.modify_test(),Vn(this.zpp_inner)==0)throw new Error("Error: Cannot remove from empty list");this.zpp_inner.valmod();let e;if(this.zpp_inner.reverse_flag){this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let t=Vn(this.zpp_inner),n;t==1?n=null:n=this.zpp_inner.inner.iterator_at(t-2),e=n==null?this.zpp_inner.inner.next:n.next;let s=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(s),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(n)}else{e=this.zpp_inner.inner.next;let t=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}return this.zpp_inner.invalidate(),e.wrapper()};Et.prototype.add=function(w){return this.zpp_inner.reverse_flag?this.push(w):this.unshift(w)};Et.prototype.remove=function(w){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let e=!1,t=this.zpp_inner.inner.next;for(;t!=null;){if(t==w.zpp_inner){e=!0;break}t=t.next}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(w),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(w.zpp_inner),this.zpp_inner.invalidate()),e};Et.prototype.clear=function(){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");if(this.zpp_inner.reverse_flag)for(;Vn(this.zpp_inner)!=0;)this.pop();else for(;Vn(this.zpp_inner)!=0;)this.shift()};Et.prototype.empty=function(){return Vn(this.zpp_inner)==0};Et.prototype.iterator=function(){return this.zpp_inner.valmod(),ft.get(this)};Et.prototype.copy=function(w){w==null&&(w=!1);let e=re(),t=new e.dynamics.ContactList;this.zpp_inner.valmod();let n=ft.get(this);for(;n.hasNext();){let s=n.next();if(w)throw new Error("Error: Contact is not a copyable type");t.push(s)}return t};Et.prototype.merge=function(w){if(w==null)throw new Error("Error: Cannot merge with null list");w.zpp_inner.valmod();let e=ft.get(w);for(;e.hasNext();){let t=e.next();this.has(t)||(this.zpp_inner.reverse_flag?this.push(t):this.unshift(t))}};Et.prototype.toString=function(){let w="[",e=!0;this.zpp_inner.valmod();let t=ft.get(this);for(;t.hasNext();){let n=t.next();e||(w+=","),w+=n==null?"NULL":n.toString(),e=!1}return w+"]"};Et.prototype.foreach=function(w){if(w==null)throw new Error("Error: Cannot execute null on list elements");this.zpp_inner.valmod();let e=ft.get(this);for(;e.hasNext();)try{w(e.next())}catch{e.zpp_next=ft.zpp_pool,ft.zpp_pool=e,e.zpp_inner=null;break}return this};Et.prototype[Symbol.iterator]=function(){let w=ft.get(this);return{next(){return w.hasNext()?{value:w.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};Et.prototype.filter=function(w){if(w==null)throw new Error("Error: Cannot select elements of list with null");let e=0;for(;;){let t=Vn(this.zpp_inner);if(!(e<t))break;let n=this.at(e);try{w(n)?++e:this.remove(n)}catch{break}}return this};var _t=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate CbEvent derp!")}static get BEGIN(){return I.CbEvent_BEGIN==null&&(I.internal=!0,I.CbEvent_BEGIN=new w,I.internal=!1),I.CbEvent_BEGIN}static get ONGOING(){return I.CbEvent_ONGOING==null&&(I.internal=!0,I.CbEvent_ONGOING=new w,I.internal=!1),I.CbEvent_ONGOING}static get END(){return I.CbEvent_END==null&&(I.internal=!0,I.CbEvent_END=new w,I.internal=!1),I.CbEvent_END}static get WAKE(){return I.CbEvent_WAKE==null&&(I.internal=!0,I.CbEvent_WAKE=new w,I.internal=!1),I.CbEvent_WAKE}static get SLEEP(){return I.CbEvent_SLEEP==null&&(I.internal=!0,I.CbEvent_SLEEP=new w,I.internal=!1),I.CbEvent_SLEEP}static get BREAK(){return I.CbEvent_BREAK==null&&(I.internal=!0,I.CbEvent_BREAK=new w,I.internal=!1),I.CbEvent_BREAK}static get PRE(){return I.CbEvent_PRE==null&&(I.internal=!0,I.CbEvent_PRE=new w,I.internal=!1),I.CbEvent_PRE}toString(){return this===I.CbEvent_BEGIN?"BEGIN":this===I.CbEvent_ONGOING?"ONGOING":this===I.CbEvent_END?"END":this===I.CbEvent_WAKE?"WAKE":this===I.CbEvent_SLEEP?"SLEEP":this===I.CbEvent_BREAK?"BREAK":this===I.CbEvent_PRE?"PRE":""}},Ho=re();Ho.callbacks.CbEvent=_t;li();var Js=class w{get _inner(){return this}constructor(){this.zpp_inner=new ut,this.zpp_inner.outer=this}static get ANY_BODY(){return ut.ANY_BODY}static get ANY_CONSTRAINT(){return ut.ANY_CONSTRAINT}static get ANY_SHAPE(){return ut.ANY_SHAPE}static get ANY_COMPOUND(){return ut.ANY_COMPOUND}get id(){return this.zpp_inner.id}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get interactors(){return this.zpp_inner.wrap_interactors==null&&(this.zpp_inner.wrap_interactors=Gr.get(this.zpp_inner.interactors,!0)),this.zpp_inner.wrap_interactors}get constraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=hr.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}including(e){return new(re()).callbacks.OptionType(this).including(e)}excluding(e){return new(re()).callbacks.OptionType(this).excluding(e)}toString(){return this===ut.ANY_BODY?"ANY_BODY":this===ut.ANY_SHAPE?"ANY_SHAPE":this===ut.ANY_COMPOUND?"ANY_COMPOUND":this===ut.ANY_CONSTRAINT?"ANY_CONSTRAINT":"CbType#"+this.zpp_inner.id}static _wrap(e){return e instanceof w?e:e?e instanceof ut?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?w._wrap(e.zpp_inner):null:null}},Xo=re();Xo.callbacks.CbType=Js;li();var hn=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate InteractionType derp!")}static get COLLISION(){return I.InteractionType_COLLISION==null&&(I.internal=!0,I.InteractionType_COLLISION=new w,I.internal=!1),I.InteractionType_COLLISION}static get SENSOR(){return I.InteractionType_SENSOR==null&&(I.internal=!0,I.InteractionType_SENSOR=new w,I.internal=!1),I.InteractionType_SENSOR}static get FLUID(){return I.InteractionType_FLUID==null&&(I.internal=!0,I.InteractionType_FLUID=new w,I.internal=!1),I.InteractionType_FLUID}static get ANY(){return I.InteractionType_ANY==null&&(I.internal=!0,I.InteractionType_ANY=new w,I.internal=!1),I.InteractionType_ANY}toString(){return this===I.InteractionType_COLLISION?"COLLISION":this===I.InteractionType_SENSOR?"SENSOR":this===I.InteractionType_FLUID?"FLUID":this===I.InteractionType_ANY?"ANY":""}},Qo=re();Qo.callbacks.InteractionType=hn;var ci=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate PreFlag derp!")}static get ACCEPT(){return I.PreFlag_ACCEPT==null&&(I.internal=!0,I.PreFlag_ACCEPT=new w,I.internal=!1),I.PreFlag_ACCEPT}static get IGNORE(){return I.PreFlag_IGNORE==null&&(I.internal=!0,I.PreFlag_IGNORE=new w,I.internal=!1),I.PreFlag_IGNORE}static get ACCEPT_ONCE(){return I.PreFlag_ACCEPT_ONCE==null&&(I.internal=!0,I.PreFlag_ACCEPT_ONCE=new w,I.internal=!1),I.PreFlag_ACCEPT_ONCE}static get IGNORE_ONCE(){return I.PreFlag_IGNORE_ONCE==null&&(I.internal=!0,I.PreFlag_IGNORE_ONCE=new w,I.internal=!1),I.PreFlag_IGNORE_ONCE}toString(){return this===I.PreFlag_ACCEPT?"ACCEPT":this===I.PreFlag_IGNORE?"IGNORE":this===I.PreFlag_ACCEPT_ONCE?"ACCEPT_ONCE":this===I.PreFlag_IGNORE_ONCE?"IGNORE_ONCE":""}},$o=re();$o.callbacks.PreFlag=ci;var Us=class w{get _inner(){return this}constructor(e,t){this.zpp_inner=new Gt,this.zpp_inner.outer=this,e!=null&&this.including(e),t!=null&&this.excluding(t)}get includes(){return this.zpp_inner.wrap_includes==null&&this.zpp_inner.setup_includes(),this.zpp_inner.wrap_includes}get excludes(){return this.zpp_inner.wrap_excludes==null&&this.zpp_inner.setup_excludes(),this.zpp_inner.wrap_excludes}including(e){return this.zpp_inner.append(this.zpp_inner.includes,e),this}excluding(e){return this.zpp_inner.append(this.zpp_inner.excludes,e),this}toString(){this.zpp_inner.wrap_includes==null&&this.zpp_inner.setup_includes();let e=this.zpp_inner.wrap_includes.toString();this.zpp_inner.wrap_excludes==null&&this.zpp_inner.setup_excludes();let t=this.zpp_inner.wrap_excludes.toString();return"@{"+e+" excluding "+t+"}"}static _wrap(e){return e instanceof w?e:e?e instanceof Gt?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?w._wrap(e.zpp_inner):null:null}},ea=re();ea.callbacks.OptionType=Us;function ta(w){return w===_t.BEGIN?0:w===_t.END?1:w===_t.WAKE?2:w===_t.SLEEP?3:w===_t.BREAK?4:w===_t.PRE?5:w===_t.ONGOING?6:-1}var In=class w{get _inner(){return this}constructor(){if(!Ue.internal)throw new Error("Error: Cannot instantiate Listener derp!");this.zpp_inner=null}static _wrap(e){return e instanceof w?e:e&&e instanceof Ue?ze(e,t=>{if(t.outer)return t.outer;let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,n}):null}get type(){return Ue.types[this.zpp_inner.type]}get event(){return Ue.events[this.zpp_inner.event]}set event(e){if(e==null)throw new Error("Error: Cannot set listener event type to null");if(Ue.events[this.zpp_inner.event]!=e){let t=ta(e);this.zpp_inner.swapEvent(t)}}get precedence(){return this.zpp_inner.precedence}set precedence(e){this.zpp_inner.precedence!=e&&(this.zpp_inner.precedence=e,this.zpp_inner.invalidate_precedence())}get space(){return this.zpp_inner.space==null?null:ai._wrap(this.zpp_inner.space.outer)}set space(e){let t=e!=null?e._inner??e:null;if((this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=t)if(this.zpp_inner.space!=null&&this.zpp_inner.space.wrap_listeners.remove(this),t!=null){let s=t.zpp_inner.wrap_listeners;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}else this.zpp_inner.space=null}toString(){let t=["BEGIN","END","WAKE","SLEEP","BREAK","PRE","ONGOING"][this.zpp_inner.event];if(this.zpp_inner.type==0){let n=this.zpp_inner.body;return"BodyListener{"+t+"::"+String(n.outer_zn.zpp_inner_zn.options.outer)+"}"}else if(this.zpp_inner.type==1){let n=this.zpp_inner.constraint;return"ConstraintListener{"+t+"::"+String(n.outer_zn.zpp_inner_zn.options.outer)+"}"}else{let n=this.zpp_inner.interaction,s;switch(n.itype){case 1:s="COLLISION";break;case 2:s="SENSOR";break;case 4:s="FLUID";break;default:s="ALL"}return this.zpp_inner.type==2?"InteractionListener{"+t+"#"+s+"::"+String(n.outer_zni.zpp_inner_zn.options1.outer)+":"+String(n.outer_zni.zpp_inner_zn.options2.outer)+"} precedence="+this.zpp_inner.precedence:"PreListener{"+s+"::"+String(n.outer_znp.zpp_inner_zn.options1.outer)+":"+String(n.outer_znp.zpp_inner_zn.options2.outer)+"} precedence="+this.zpp_inner.precedence}}};var Ks=class w{constructor(){if(!I.internal)throw new Error("Error: Cannot instantiate ListenerType derp!")}static get BODY(){return I.ListenerType_BODY==null&&(I.internal=!0,I.ListenerType_BODY=new w,I.internal=!1),I.ListenerType_BODY}static get CONSTRAINT(){return I.ListenerType_CONSTRAINT==null&&(I.internal=!0,I.ListenerType_CONSTRAINT=new w,I.internal=!1),I.ListenerType_CONSTRAINT}static get INTERACTION(){return I.ListenerType_INTERACTION==null&&(I.internal=!0,I.ListenerType_INTERACTION=new w,I.internal=!1),I.ListenerType_INTERACTION}static get PRE(){return I.ListenerType_PRE==null&&(I.internal=!0,I.ListenerType_PRE=new w,I.internal=!1),I.ListenerType_PRE}toString(){return this===I.ListenerType_BODY?"BODY":this===I.ListenerType_CONSTRAINT?"CONSTRAINT":this===I.ListenerType_INTERACTION?"INTERACTION":this===I.ListenerType_PRE?"PRE":""}},na=re();na.callbacks.ListenerType=Ks;li();var Tn=class{constructor(){this.zpp_inner=null;if(!xt.internal)throw new Error("Error: Callback cannot be instantiated derp!")}get event(){return Ue.events[this.zpp_inner.event]}get listener(){return this.zpp_inner.listener.outer}toString(){return""}};var Il=class extends Tn{get body(){return this.zpp_inner.body.outer}toString(){return"Cb:"+["WAKE","SLEEP"][this.zpp_inner.event-2]+":"+this.zpp_inner.body.outer.toString()+" : listener: "+String(this.zpp_inner.listener.outer)}};var Tl=class extends Tn{get constraint(){return this.zpp_inner.constraint.outer}toString(){return"Cb:"+["WAKE","SLEEP","BREAK"][this.zpp_inner.event-2]+":"+this.zpp_inner.constraint.outer.toString()+" : listener: "+String(this.zpp_inner.listener.outer)}};var Bl=class extends Tn{get int1(){return this.zpp_inner.int1.outer_i}get int2(){return this.zpp_inner.int2.outer_i}get arbiters(){return this.zpp_inner.wrap_arbiters}toString(){return"Cb:"+["BEGIN","END","","","","","ONGOING"][this.zpp_inner.event]+":"+this.zpp_inner.int1.outer_i.toString()+"/"+this.zpp_inner.int2.outer_i.toString()+" : "+this.zpp_inner.wrap_arbiters.toString()+" : listener: "+String(this.zpp_inner.listener.outer)}};var Ll=class extends Tn{get arbiter(){return this.zpp_inner.pre_arbiter.wrapper()}get int1(){return this.zpp_inner.int1.outer_i}get int2(){return this.zpp_inner.int2.outer_i}get swapped(){return this.zpp_inner.pre_swapped}toString(){return"Cb:PRE::"+this.zpp_inner.int1.outer_i.toString()+"/"+this.zpp_inner.int2.outer_i.toString()+" : "+this.zpp_inner.pre_arbiter.wrapper().toString()+" : listnener: "+String(this.zpp_inner.listener.outer)}};var jl=class extends In{constructor(e,t,n,s=0){if(Ue.internal=!0,super(),Ue.internal=!1,n==null)throw new Error("Error: BodyListener::handler cannot be null");let i;if(e===_t.WAKE)i=2;else if(e===_t.SLEEP)i=3;else throw new Error("Error: cbEvent '"+e.toString()+"' is not a valid event type for a BodyListener");this.zpp_inner_zn=new _l(Gt.argument(t),i,n),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zn=this,this.zpp_inner.precedence=s}get options(){return this.zpp_inner_zn.options.outer}set options(e){this.zpp_inner_zn.options.set(e.zpp_inner)}get handler(){return this.zpp_inner_zn.handler}set handler(e){if(e==null)throw new Error("Error: BodyListener::handler cannot be null");this.zpp_inner_zn.handler=e}};var Dl=class extends In{constructor(e,t,n,s=0){if(Ue.internal=!0,super(),Ue.internal=!1,n==null)throw new Error("Error: ConstraintListener::handler cannot be null");let i;if(e===_t.WAKE)i=2;else if(e===_t.SLEEP)i=3;else if(e===_t.BREAK)i=4;else throw new Error("Error: cbEvent '"+e.toString()+"' is not a valid event type for a ConstraintListener");this.zpp_inner_zn=new xl(Gt.argument(t),i,n),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zn=this,this.zpp_inner.precedence=s}get options(){return this.zpp_inner_zn.options.outer}set options(e){this.zpp_inner_zn.options.set(e.zpp_inner)}get handler(){return this.zpp_inner_zn.handler}set handler(e){if(e==null)throw new Error("Error: ConstraintListener::handler cannot be null");this.zpp_inner_zn.handler=e}};function ur(w){return w===hn.COLLISION?1:w===hn.SENSOR?2:w===hn.FLUID?4:7}function Ys(w){return w==1?hn.COLLISION:w==2?hn.SENSOR:w==4?hn.FLUID:w==7?hn.ANY:null}var Fl=class extends In{constructor(e,t,n,s,i,l=0){if(Ue.internal=!0,super(),Ue.internal=!1,i==null)throw new Error("Error: InteractionListener::handler cannot be null");if(e==null)throw new Error("Error: CbEvent cannot be null for InteractionListener");let r;if(e===_t.BEGIN)r=0;else if(e===_t.END)r=1;else if(e===_t.ONGOING)r=6;else throw new Error("Error: CbEvent '"+e.toString()+"' is not a valid event type for InteractionListener");if(this.zpp_inner_zn=new es(Gt.argument(n),Gt.argument(s),r,2),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zni=this,this.zpp_inner.precedence=l,this.zpp_inner_zn.handleri=i,t==null)throw new Error("Error: Cannot set listener interaction type to null");Ys(this.zpp_inner_zn.itype)!=t&&(this.zpp_inner_zn.itype=ur(t))}get options1(){return this.zpp_inner_zn.options1.outer}set options1(e){this.zpp_inner_zn.options1.set(e.zpp_inner)}get options2(){return this.zpp_inner_zn.options2.outer}set options2(e){this.zpp_inner_zn.options2.set(e.zpp_inner)}get handler(){return this.zpp_inner_zn.handleri}set handler(e){if(e==null)throw new Error("Error: InteractionListener::handler cannot be null");this.zpp_inner_zn.handleri=e}get interactionType(){return Ys(this.zpp_inner_zn.itype)}set interactionType(e){if(e==null)throw new Error("Error: Cannot set listener interaction type to null");Ys(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=ur(e))}get allowSleepingCallbacks(){return this.zpp_inner_zn.allowSleepingCallbacks}set allowSleepingCallbacks(e){this.zpp_inner_zn.allowSleepingCallbacks=e}};var as=class extends In{constructor(e,t,n,s,i=0,l=!1){if(Ue.internal=!0,super(),Ue.internal=!1,s==null)throw new Error("Error: PreListener must take a handler!");if(this.zpp_inner_zn=new es(Gt.argument(t),Gt.argument(n),5,3),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_znp=this,this.zpp_inner.precedence=i,this.zpp_inner_zn.pure=l,this.zpp_inner_zn.handlerp=s,e==null)throw new Error("Error: Cannot set listener interaction type to null");Ys(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=ur(e))}get options1(){return this.zpp_inner_zn.options1.outer}set options1(e){this.zpp_inner_zn.options1.set(e.zpp_inner)}get options2(){return this.zpp_inner_zn.options2.outer}set options2(e){this.zpp_inner_zn.options2.set(e.zpp_inner)}get handler(){return this.zpp_inner_zn.handlerp}set handler(e){if(e==null)throw new Error("Error: PreListener must take a non-null handler!");this.zpp_inner_zn.handlerp=e,this.zpp_inner_zn.wake()}get pure(){return this.zpp_inner_zn.pure}set pure(e){e||this.zpp_inner_zn.wake(),this.zpp_inner_zn.pure=e}get interactionType(){return Ys(this.zpp_inner_zn.itype)}set interactionType(e){if(e==null)throw new Error("Error: Cannot set listener interaction type to null");Ys(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=ur(e))}};var Hs=class Hs{constructor(){this.debugDraw=!0;this._inner=this}static _wrap(e){return e==null?null:e instanceof Hs?e:e.zpp_inner?.outer instanceof Hs?e.zpp_inner.outer:ze(e,t=>{let n=Object.create(Hs.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 Hs._wrap(this.zpp_inner.copy())}toString(){return"{Constraint}"}};Hs.zpp_internalAlloc=!1;var kt=Hs;var Xs=class w extends kt{constructor(e,t,n,s,i=1){super();let l=new We;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 w?e:e.zpp_inner?.outer instanceof w?e.zpp_inner.outer:e instanceof We?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ze(e,t=>{let n=Object.create(w.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:Ke._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:Ke._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=re(),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=re();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}};We._wrapFn=w=>ze(w,e=>{let t=Object.create(Xs.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function oo(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.x}function ao(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Er(w){w.zpp_inner.weak&&w.dispose()}var Qs=class w extends kt{constructor(e,t,n,s,i,l){super();let r=new Ci;if(this.zpp_inner=r,r.outer=this,r.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");let o=oo(n),a=ao(n);if(r.a1localx=o,r.a1localy=a,Er(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=oo(s),c=ao(s);if(r.a2localx=p,r.a2localy=c,Er(s),this.zpp_inner.immutable_midstep("DistanceJoint::jointMin"),i!==i)throw new Error("Error: DistanceJoint::jointMin cannot be NaN");if(i<0)throw new Error("Error: DistanceJoint::jointMin must be >= 0");if(r.jointMin!=i&&(r.jointMin=i,r.wake()),this.zpp_inner.immutable_midstep("DistanceJoint::jointMax"),l!==l)throw new Error("Error: DistanceJoint::jointMax cannot be NaN");if(l<0)throw new Error("Error: DistanceJoint::jointMax must be >= 0");r.jointMax!=l&&(r.jointMax=l,r.wake())}static _wrap(e){return e==null?null:e instanceof w?e:e.zpp_inner?.outer instanceof w?e.zpp_inner.outer:e instanceof Ci?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ze(e,t=>{let n=Object.create(w.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:Ke._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:Ke._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),Er(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),Er(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=re(),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=re();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};Ci._wrapFn=w=>ze(w,e=>{let t=Object.create(Qs.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Wr(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Jr(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Rl(w){w.zpp_inner.weak&&w.dispose()}var $s=class w extends kt{constructor(e,t,n,s,i,l,r){super();let o=new Zi;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");if(o.a1localx=Wr(n),o.a1localy=Jr(n),Rl(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(o.a2localx=Wr(s),o.a2localy=Jr(s),Rl(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(o.nlocalx=Wr(i),o.nlocaly=Jr(i),o.zip_n=!0,Rl(i),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),l!==l)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(o.jointMin!=l&&(o.jointMin=l,o.wake()),this.zpp_inner.immutable_midstep("LineJoint::jointMax"),r!==r)throw new Error("Error: AngleJoint::jointMax cannot be NaN");o.jointMax!=r&&(o.jointMax=r,o.wake())}static _wrap(e){return e==null?null:e instanceof w?e:e.zpp_inner?.outer instanceof w?e.zpp_inner.outer:e instanceof Zi?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ze(e,t=>{let n=Object.create(w.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:Ke._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:Ke._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),Rl(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),Rl(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),Rl(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=re(),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=re();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}};Zi._wrapFn=w=>ze(w,e=>{let t=Object.create($s.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var el=class w extends kt{constructor(e,t,n=0,s=1){super();let i=new Mi;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 w?e:e.zpp_inner?.outer instanceof w?e.zpp_inner.outer:e instanceof Mi?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ze(e,t=>{let n=Object.create(w.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:Ke._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:Ke._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=re(),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=re();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}};Mi._wrapFn=w=>ze(w,e=>{let t=Object.create(el.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function po(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.x}function co(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.y}function kr(w){w.zpp_inner.weak&&w.dispose()}var tl=class w extends kt{constructor(e,t,n,s){super();let i=new Ei;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=po(n),i.a1localy=co(n),kr(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=po(s),i.a2localy=co(s),kr(s)}static _wrap(e){return e==null?null:e instanceof w?e:e.zpp_inner?.outer instanceof w?e.zpp_inner.outer:e instanceof Ei?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ze(e,t=>{let n=Object.create(w.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:Ke._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:Ke._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),kr(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),kr(e)}impulse(){let e=re(),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=re();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}};Ei._wrapFn=w=>ze(w,e=>{let t=Object.create(tl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function _r(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.x}function xr(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.y}function dr(w){w.zpp_inner.weak&&w.dispose()}var nl=class w extends kt{constructor(e,t,n,s,i,l,r,o,a,p,c=1){super();let h=new ki;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,_)=>{h.a1localx=u,h.a1localy=_}),this._setAnchorInit(l,"anchor2",(u,_)=>{h.a2localx=u,h.a2localy=_}),this._setAnchorInit(r,"anchor3",(u,_)=>{h.a3localx=u,h.a3localy=_}),this._setAnchorInit(o,"anchor4",(u,_)=>{h.a4localx=u,h.a4localy=_}),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(_r(e),xr(e)),dr(e)}static _wrap(e){return e==null?null:e instanceof w?e:e.zpp_inner?.outer instanceof w?e.zpp_inner.outer:e instanceof ki?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ze(e,t=>{let n=Object.create(w.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:Ke._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}get body2(){return this.zpp_inner.b2==null?null:Ke._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}get body3(){return this.zpp_inner.b3==null?null:Ke._wrap(this.zpp_inner.b3)}set body3(e){this._setBody3(e)}get body4(){return this.zpp_inner.b4==null?null:Ke._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(),_r(e),xr(e),this.zpp_inner.wrap_a1.set(e),dr(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(),_r(e),xr(e),this.zpp_inner.wrap_a2.set(e),dr(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(),_r(e),xr(e),this.zpp_inner.wrap_a3.set(e),dr(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(),_r(e),xr(e),this.zpp_inner.wrap_a4.set(e),dr(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 yi(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):Xe.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}};ki._wrapFn=w=>ze(w,e=>{let t=Object.create(nl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function ho(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.x}function uo(w){if(w.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=w.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Nr(w){w.zpp_inner.weak&&w.dispose()}var il=class w extends kt{constructor(e,t,n,s,i=0){super();let l=new Ni;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),Nr(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),Nr(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 w?e:e.zpp_inner?.outer instanceof w?e.zpp_inner.outer:e instanceof Ni?ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ze(e,t=>{let n=Object.create(w.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:Ke._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:Ke._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),Nr(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),Nr(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=re(),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=re();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}};Ni._wrapFn=w=>ze(w,e=>{let t=Object.create(il.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var Gl=class w extends kt{constructor(e,t=!1){if(super(),e<1)throw new Error("Error: Constraint dimension must be at least 1");let n=new yl(e,t);this.zpp_inner=n,n.outer=this,n.outer_zn=this}static _wrap(e){return e==null?null:e instanceof w?e:e.zpp_inner?.outer instanceof w?e.zpp_inner.outer:ze(e,t=>{let n=Object.create(w.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}__bindVec2(){let e=new Se;return e.zpp_inner._inuse=!0,e.zpp_inner._invalidate=this.zpp_inner.bindVec2_invalidate.bind(this.zpp_inner),e}__copy(){throw new Error("Error: UserConstraint::__copy must be overriden")}__broken(){}__validate(){}__draw(e){}__prepare(){}__position(e){throw new Error("Error: UserConstraint::__position must be overriden")}__velocity(e){throw new Error("Error: Userconstraint::__velocity must be overriden")}__eff_mass(e){throw new Error("Error: UserConstraint::__eff_mass must be overriden")}__clamp(e){}__impulse(e,t,n){throw new Error("Error: UserConstraint::__impulse must be overriden")}impulse(){let e=this.zpp_inner.dim,t=new yi(e,1);for(let n=0;n<e;n++){if(n<0||n>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");t.zpp_inner.x[n*t.zpp_inner.n]=this.zpp_inner.jAcc[n]}return t}bodyImpulse(e){if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let t=!1;for(let n of this.zpp_inner.bodies)if(n.body==e.zpp_inner){t=!0;break}if(!t)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):Xe.get()}visitBodies(e){let t=this.zpp_inner.bodies.length,n=0;for(;n<t;){let s=this.zpp_inner.bodies[n];if(s.body!=null){let i=!1;for(let l=n+1;l<t;l++)if(this.zpp_inner.bodies[l].body==s.body){i=!0;break}i||e(s.body.outer)}++n}}__invalidate(){this.zpp_inner.immutable_midstep("UserConstraint::invalidate()"),this.zpp_inner.active&&(this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=null&&this.zpp_inner.wake()}__registerBody(e,t){if(this.zpp_inner.immutable_midstep("UserConstraint::registerBody(..)"),e!=t){if(e!=null){if(!this.zpp_inner.remBody(e.zpp_inner))throw new Error("Error: oldBody is not registered to the cosntraint");this.zpp_inner.active&&(this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=null&&e.zpp_inner.wake()}t!=null&&this.zpp_inner.addBody(t.zpp_inner),this.zpp_inner.wake(),t?.zpp_inner.wake()}return t}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};function Bn(w){let{typeName:e,namespaceParts:t,zppListClass:n,wrapElement:s,unwrapElement:i}=w,l=re(),r=l.__zpp,o=()=>r.util[n],a=()=>{let x=l;for(let y=1;y<t.length;y++)x=x[t[y]];return x};function p(){if(this.zpp_next=null,this.zpp_critical=!1,this.zpp_i=0,this.zpp_inner=null,!o().internal)throw new Error("Error: Cannot instantiate "+e+"Iterator derp!")}p.zpp_pool=null,p.get=function(x){let y,z=o();return p.zpp_pool==null?(z.internal=!0,y=new p,z.internal=!1):(y=p.zpp_pool,p.zpp_pool=y.zpp_next),y.zpp_i=0,y.zpp_inner=x,y.zpp_critical=!1,y},p.prototype.zpp_inner=null,p.prototype.zpp_i=null,p.prototype.zpp_critical=null,p.prototype.zpp_next=null,p.prototype.hasNext=function(){this.zpp_inner.zpp_inner.valmod();let x=this.zpp_inner;x.zpp_inner.valmod(),x.zpp_inner.zip_length&&(x.zpp_inner.zip_length=!1,x.zpp_inner.user_length=x.zpp_inner.inner.length);let y=x.zpp_inner.user_length;return this.zpp_critical=!0,this.zpp_i<y?!0:(this.zpp_next=p.zpp_pool,p.zpp_pool=this,this.zpp_inner=null,!1)},p.prototype.next=function(){return this.zpp_critical=!1,this.zpp_inner.at(this.zpp_i++)};function c(){this.zpp_inner=null,this.zpp_inner=new(o()),this.zpp_inner.outer=this}c.fromArray=function(x){if(x==null)throw new Error("Error: Cannot convert null Array to Nape list");let y=new c;for(let z=0;z<x.length;z++)y.push(x[z]);return y},c.prototype.zpp_inner=null,c.prototype.zpp_gl=function(){return this.zpp_inner.valmod(),this.zpp_inner.zip_length&&(this.zpp_inner.zip_length=!1,this.zpp_inner.user_length=this.zpp_inner.inner.length),this.zpp_inner.user_length};function h(x){return 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),x.zpp_inner.user_length}Object.defineProperty(c.prototype,"length",{get:function(){return h(this)}}),c.prototype.has=function(x){return this.zpp_inner.valmod(),this.zpp_inner.inner.has(i(x))},c.prototype.at=function(x){if(this.zpp_inner.valmod(),x<0||x>=h(this))throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(x=h(this)-1-x),x<this.zpp_inner.at_index||this.zpp_inner.at_ite==null)this.zpp_inner.at_index=x,this.zpp_inner.at_ite=this.zpp_inner.inner.iterator_at(x);else for(;this.zpp_inner.at_index!=x;)this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;return s(this.zpp_inner.at_ite.elt)},c.prototype.push=function(x){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let y=this.zpp_inner.adder!=null?this.zpp_inner.adder(x):!0;return y&&(this.zpp_inner.reverse_flag?this.zpp_inner.inner.add(i(x)):(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.zpp_inner.inner.head==null?null:this.zpp_inner.inner.iterator_at(h(this)-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,i(x))),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(x)),y},c.prototype.unshift=function(x){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let y=this.zpp_inner.adder!=null?this.zpp_inner.adder(x):!0;return y&&(this.zpp_inner.reverse_flag?(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.zpp_inner.inner.head==null?null:this.zpp_inner.inner.iterator_at(h(this)-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,i(x))):this.zpp_inner.inner.add(i(x)),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(x)),y},c.prototype.pop=function(){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");if(this.zpp_inner.modify_test(),this.zpp_inner.inner.head==null)throw new Error("Error: Cannot remove from empty list");this.zpp_inner.valmod();let x;if(this.zpp_inner.reverse_flag){x=this.zpp_inner.inner.head.elt;let y=s(x);this.zpp_inner.subber!=null&&this.zpp_inner.subber(y),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}else{this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let y;h(this)==1?y=null:y=this.zpp_inner.inner.iterator_at(h(this)-2),x=y==null?this.zpp_inner.inner.head.elt:y.next.elt;let z=s(x);this.zpp_inner.subber!=null&&this.zpp_inner.subber(z),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(y)}return this.zpp_inner.invalidate(),s(x)},c.prototype.shift=function(){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");if(this.zpp_inner.modify_test(),this.zpp_inner.inner.head==null)throw new Error("Error: Cannot remove from empty list");this.zpp_inner.valmod();let x;if(this.zpp_inner.reverse_flag){this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let y;h(this)==1?y=null:y=this.zpp_inner.inner.iterator_at(h(this)-2),x=y==null?this.zpp_inner.inner.head.elt:y.next.elt;let z=s(x);this.zpp_inner.subber!=null&&this.zpp_inner.subber(z),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(y)}else{x=this.zpp_inner.inner.head.elt;let y=s(x);this.zpp_inner.subber!=null&&this.zpp_inner.subber(y),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}return this.zpp_inner.invalidate(),s(x)},c.prototype.add=function(x){return this.zpp_inner.reverse_flag?this.push(x):this.unshift(x)},c.prototype.remove=function(x){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let y=!1,z=this.zpp_inner.inner.head,f=i(x);for(;z!=null;){if(z.elt==f){y=!0;break}z=z.next}return y&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(x),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(f),this.zpp_inner.invalidate()),y},c.prototype.clear=function(){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");if(this.zpp_inner.reverse_flag)for(;this.zpp_inner.inner.head!=null;)this.pop();else for(;this.zpp_inner.inner.head!=null;)this.shift()},c.prototype.empty=function(){return this.zpp_inner.inner.head==null},c.prototype.iterator=function(){return this.zpp_inner.valmod(),p.get(this)},c.prototype.copy=function(x){x==null&&(x=!1);let y=new c,z=p.get(this);for(;z.hasNext();){let f=z.next();if(x)throw new Error("Error: "+e+" is not a copyable type");y.push(f)}return y},c.prototype.merge=function(x){if(x==null)throw new Error("Error: Cannot merge with null list");let y=p.get(x);for(;y.hasNext();){let z=y.next();this.has(z)||(this.zpp_inner.reverse_flag?this.push(z):this.unshift(z))}},c.prototype.toString=function(){let x="[",y=!0,z=p.get(this);for(;z.hasNext();){let f=z.next();y||(x+=","),x+=f==null?"NULL":f.toString(),y=!1}return x+"]"},c.prototype.foreach=function(x){if(x==null)throw new Error("Error: Cannot execute null on list elements");this.zpp_inner.valmod();let y=p.get(this);for(;y.hasNext();)try{x(y.next())}catch{y.zpp_next=p.zpp_pool,p.zpp_pool=y,y.zpp_inner=null;break}return this},c.prototype.filter=function(x){if(x==null)throw new Error("Error: Cannot select elements of list with null");let y=0;for(;y<h(this);){let z=this.at(y);try{x(z)?++y:this.remove(z)}catch{break}}return this},c.prototype.toArray=function(){let x=[],y=p.get(this);for(;y.hasNext();)x.push(y.next());return x},c.prototype[Symbol.iterator]=function(){let x=p.get(this);return{next(){return x.hasNext()?{value:x.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};let u=a(),_=e+"Iterator",m=e+"List";return u[_]=p,u[m]=c,{Iterator:p,List:c}}var ps=w=>w.outer,Li=w=>w.zpp_inner??(w._inner?w._inner.zpp_inner??w._inner:w);Bn({typeName:"CbType",namespaceParts:["nape","callbacks"],zppListClass:"ZPP_CbTypeList",wrapElement:ps,unwrapElement:Li});Bn({typeName:"Listener",namespaceParts:["nape","callbacks"],zppListClass:"ZPP_ListenerList",wrapElement:ps,unwrapElement:Li});Bn({typeName:"Constraint",namespaceParts:["nape","constraint"],zppListClass:"ZPP_ConstraintList",wrapElement:ps,unwrapElement:Li});Bn({typeName:"InteractionGroup",namespaceParts:["nape","dynamics"],zppListClass:"ZPP_InteractionGroupList",wrapElement:ps,unwrapElement:Li});Bn({typeName:"GeomPoly",namespaceParts:["nape","geom"],zppListClass:"ZPP_GeomPolyList",wrapElement:ps,unwrapElement:Li});Bn({typeName:"Body",namespaceParts:["nape","phys"],zppListClass:"ZPP_BodyList",wrapElement:ps,unwrapElement:Li});Bn({typeName:"Compound",namespaceParts:["nape","phys"],zppListClass:"ZPP_CompoundList",wrapElement:ps,unwrapElement:Li});Bn({typeName:"Shape",namespaceParts:["nape","shape"],zppListClass:"ZPP_ShapeList",wrapElement:ps,unwrapElement:Li});Bn({typeName:"Arbiter",namespaceParts:["nape","dynamics"],zppListClass:"ZPP_ArbiterList",wrapElement:w=>w.wrapper(),unwrapElement:Li});Bn({typeName:"Edge",namespaceParts:["nape","shape"],zppListClass:"ZPP_EdgeList",wrapElement:w=>w.wrapper(),unwrapElement:Li});Bn({typeName:"ConvexResult",namespaceParts:["nape","geom"],zppListClass:"ZPP_ConvexResultList",wrapElement:w=>w,unwrapElement:w=>w});Bn({typeName:"RayResult",namespaceParts:["nape","geom"],zppListClass:"ZPP_RayResultList",wrapElement:w=>w,unwrapElement:w=>w});Bn({typeName:"Interactor",namespaceParts:["nape","phys"],zppListClass:"ZPP_InteractorList",wrapElement:w=>w.outer_i,unwrapElement:w=>w.zpp_inner_i});function sl(w){if(w.outer==null){let e=re();w.outer=new e.geom.Vec2;let t=w.outer.zpp_inner;t.outer!=null&&(t.outer.zpp_inner=null,t.outer=null),t._isimmutable=null,t._validate=null,t._invalidate=null,t.next=pe.zpp_pool,pe.zpp_pool=t,w.outer.zpp_inner=w}return w.outer}function Xt(){this.at_index=0,this.at_ite=null,this.zip_length=!1,this._length=0,this.inner=null,ht.call(this),this.at_ite=null,this.at_index=0,this.zip_length=!0,this._length=0}for(let w in ht.prototype)Xt.prototype[w]=ht.prototype[w];Object.defineProperty(Xt.prototype,"length",{get:function(){return this.zpp_gl()},configurable:!0});Xt.prototype.inner=null;Xt.prototype._length=0;Xt.prototype.zip_length=!1;Xt.prototype.at_ite=null;Xt.prototype.at_index=0;Xt.get=function(w,e){e==null&&(e=!1);let t=new Xt;return t.inner=w,t.zpp_inner.immutable=e,t};Xt.prototype.zpp_gl=function(){if(this.zpp_vm(),this.zip_length){this._length=0;let w=this.inner.next;for(;w!=null;)this._length++,w=w.next;this.zip_length=!1}return this._length};Xt.prototype.zpp_vm=function(){this.zpp_inner.validate(),this.inner.modified&&(this.zip_length=!0,this._length=0,this.at_ite=null)};Xt.prototype.at=function(w){if(this.zpp_vm(),w<0||w>=this.zpp_gl())throw new Error("Error: Index out of bounds");for(this.zpp_inner.reverse_flag&&(w=this.zpp_gl()-1-w),(w<this.at_index||this.at_ite==null)&&(this.at_index=0,this.at_ite=this.inner.next);this.at_index!==w;)this.at_index++,this.at_ite=this.at_ite.next;return sl(this.at_ite)};Xt.prototype.push=function(w){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.zpp_vm(),w.zpp_inner._inuse)throw new Error("Error: Vec2 is already in use");let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(w):!0;if(e){if(this.zpp_inner.reverse_flag)this.inner.add(w.zpp_inner);else{let t=this.inner.iterator_at(this.zpp_gl()-1);this.inner.insert(t,w.zpp_inner)}this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(w)}return e};Xt.prototype.unshift=function(w){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.zpp_vm(),w.zpp_inner._inuse)throw new Error("Error: Vec2 is already in use");let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(w):!0;if(e){if(this.zpp_inner.reverse_flag){let t=this.inner.iterator_at(this.zpp_gl()-1);this.inner.insert(t,w.zpp_inner)}else this.inner.add(w.zpp_inner);this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(w)}return e};Xt.prototype.pop=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.empty())throw new Error("Error: Cannot remove from empty list");this.zpp_vm();let w;if(this.zpp_inner.reverse_flag){w=this.inner.next;let e=sl(w);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.inner.pop()}else{this.at_ite!=null&&this.at_ite.next==null&&(this.at_ite=null);let e=this.zpp_gl()===1?null:this.inner.iterator_at(this.zpp_gl()-2);w=e==null?this.inner.next:e.next;let t=sl(w);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.inner.erase(e)}return this.zpp_inner.invalidate(),sl(w)};Xt.prototype.shift=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.empty())throw new Error("Error: Cannot remove from empty list");this.zpp_vm();let w;if(this.zpp_inner.reverse_flag){this.at_ite!=null&&this.at_ite.next==null&&(this.at_ite=null);let e=this.zpp_gl()===1?null:this.inner.iterator_at(this.zpp_gl()-2);w=e==null?this.inner.next:e.next;let t=sl(w);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.inner.erase(e)}else{w=this.inner.next;let e=sl(w);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.inner.pop()}return this.zpp_inner.invalidate(),sl(w)};Xt.prototype.remove=function(w){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=!1,t=this.inner.next;for(;t!=null;){if(w.zpp_inner===t){e=!0;break}t=t.next}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(w),this.zpp_inner.dontremove||this.inner.remove(w.zpp_inner),this.zpp_inner.invalidate()),e};Xt.prototype.clear=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.reverse_flag)for(;!this.empty();)this.pop();else for(;!this.empty();)this.shift()};var ia=re(),sa=ia.__zpp;sa.util.ZPP_MixVec2List=Xt;var Ae=re();Ae.Config=Object.assign(Ae.Config||{},Fr);Ae.util.Debug=Pr;Ae.geom.Vec2=Se;Ae.geom.Vec3=Xe;Ae.geom.Mat23=Ns;Ae.geom.MatMN=yi;Ae.geom.AABB=Kn;Ae.geom.Winding=Os;Ae.geom.Ray=Ai;Ae.geom.ConvexResult=Ss;Ae.geom.RayResult=As;Ae.geom.Geom=El;Ae.geom.GeomPoly=Ii;Ae.geom.MarchingSquares=kl;Ae.geom.Vec2Iterator=Mt;Ae.geom.Vec2List=ht;Ae.geom.GeomVertexIterator=Ts;Ae.__zpp.geom.ZPP_GeomVertexIterator=ri;Ae.__zpp.util.ZPP_ContactList=Ti;Ae.phys.Interactor=oi;Ae.phys.Body=Ke;Zr(w=>Ke._wrap(w));Ae.phys.BodyType=bi;Ae.phys.Compound=zi;eo(w=>zi._wrap(w));Ae.phys.FluidProperties=Yn;Ae.phys.Material=Bs;Ae.phys.GravMassMode=Ls;Ae.phys.InertiaMode=js;Ae.phys.MassMode=Ds;Ae.shape.Shape=Mn;$r(w=>Mn._wrap(w));Ae.shape.Circle=rs;Ae.shape.Polygon=Pi;Ae.shape.Capsule=os;Ae.shape.Edge=Fs;Ae.shape.ShapeType=Yi;Ae.shape.ValidationResult=Rs;Ae.space.Space=ai;Ae.space.Broadphase=Sl;Ae.dynamics.InteractionFilter=Hi;Ae.dynamics.InteractionGroup=Gs;Ae.dynamics.ArbiterType=qs;Ae.dynamics.Arbiter=wi;Ne._createColArb=()=>new Al;Ne._createFluidArb=()=>new Vl;Ae.dynamics.Contact=Ws;Ae.dynamics.ContactIterator=ft;Ae.dynamics.ContactList=Et;Ae.callbacks.CbEvent=_t;Ae.callbacks.CbType=Js;Ae.callbacks.InteractionType=hn;Ae.callbacks.PreFlag=ci;Ae.callbacks.OptionType=Us;Ae.callbacks.Listener=In;Ae.callbacks.ListenerType=Ks;Ae.callbacks.Callback=Tn;xt._createBodyCb=()=>new Il;xt._createConCb=()=>new Tl;xt._createIntCb=()=>new Bl;xt._createPreCb=()=>new Ll;Ae.callbacks.BodyListener=jl;Ae.callbacks.ConstraintListener=Dl;Ae.callbacks.InteractionListener=Fl;Ae.callbacks.PreListener=as;Ae.constraint.Constraint=kt;We._createFn=(...w)=>new Xs(...w);Ci._createFn=(...w)=>new Qs(...w);Zi._createFn=(...w)=>new $s(...w);Mi._createFn=(...w)=>new el(...w);Ei._createFn=(...w)=>new tl(...w);ki._createFn=(...w)=>new nl(...w);Ni._createFn=(...w)=>new il(...w);Ae.constraint.UserConstraint=Gl;var Or=class{drawSegment(e,t,n){}drawCircle(e,t,n){}drawSolidCircle(e,t,n,s){}drawPolygon(e,t){}drawSolidPolygon(e,t){}drawCapsule(e,t,n,s){}drawSolidCapsule(e,t,n,s){}drawPoint(e,t){}};function _o(w,e){if(w==null)throw new Error("Error: vertices cannot be null");let t;if(w instanceof Ii){if(w.zpp_disp)throw new Error("Error: GeomPoly has been disposed and cannot be used!");t=w.copy()}else{if(!Array.isArray(w))throw new Error("Error: vertices must be an Array<Vec2> or GeomPoly");if(w.length<3)throw new Error("Error: At least 3 vertices are required, got "+w.length);for(let a=0;a<w.length;a++)if(w[a]==null)throw new Error("Error: vertices["+a+"] is null");t=new Ii(w)}if(t.size()<3)throw t.dispose(),new Error("Error: At least 3 vertices are required, got "+t.size());if(t.isDegenerate())throw t.dispose(),new Error("Error: Polygon is degenerate (zero area)");if(!t.isSimple())throw t.dispose(),new Error("Error: Polygon is self-intersecting");let n=e?.simplify??0;if(n>0){let a=t.simplify(n);if(t.dispose(),t=a,t.size()<3||t.isDegenerate())throw t.dispose(),new Error("Error: Polygon became degenerate after simplification (epsilon too large)")}if(!t.isClockwise()){let a=[],p=t.forwardIterator();for(;p.hasNext();){let c=p.next();a.push(Se.get(c.x,c.y))}t.dispose(),a.reverse(),t=new Ii(a)}let s=e?.material,i=e?.filter,l=e?.delaunay??!1,r=new Ke(e?.type??bi.DYNAMIC,e?.position);if(t.isConvex())return r.shapes.add(new Pi(t,s,i)),t.dispose(),r;let o=t.convexDecomposition(l);for(let a of o)r.shapes.add(new Pi(a,s,i));return t.dispose(),r}var Sr=class{constructor(e,t,n={}){this._oneWayListener=null;this._grounded=!1;this._groundNormal=null;this._groundBody=null;this._onMovingPlatform=!1;this._slopeAngle=0;this._wallLeft=!1;this._wallRight=!1;this._timeSinceGrounded=0;this.space=e,this.body=t,this._maxSlopeAngle=n.maxSlopeAngle??Math.PI/4,this._maxSlopeCos=Math.cos(this._maxSlopeAngle);let s=256;if(n.filter)this._filter=n.filter;else{let i=t.shapes;for(let l=0;l<i.length;l++){let o=i.at(l).filter;o.collisionGroup=o.collisionGroup|s}this._filter=new Hi(1,~s)}n.oneWayPlatformTag&&n.characterTag&&this._setupOneWayPlatforms(n.oneWayPlatformTag,n.characterTag)}get grounded(){return this._grounded}get groundNormal(){return this._groundNormal}get groundBody(){return this._groundBody}get timeSinceGrounded(){return this._timeSinceGrounded}get maxSlopeAngle(){return this._maxSlopeAngle}set maxSlopeAngle(e){this._maxSlopeAngle=e,this._maxSlopeCos=Math.cos(e)}setVelocity(e,t){this.body.velocity=new Se(e,t)}update(){this._wallLeft=!1,this._wallRight=!1;let e=this.body.position.x,t=this.body.position.y;return this._detectGround(e,t),this._detectWalls(e,t),this._grounded&&this._groundBody?this._onMovingPlatform=this._groundBody.type===bi.KINEMATIC:this._onMovingPlatform=!1,this._grounded?this._timeSinceGrounded=0:this._timeSinceGrounded+=1/60,{grounded:this._grounded,groundNormal:this._groundNormal,groundBody:this._groundBody,onMovingPlatform:this._onMovingPlatform,slopeAngle:this._slopeAngle,wallLeft:this._wallLeft,wallRight:this._wallRight,timeSinceGrounded:this._timeSinceGrounded}}destroy(){this._oneWayListener&&(this._oneWayListener.space=null,this._oneWayListener=null)}_detectGround(e,t){let s=this._getCharacterRadius(0,1)+4,i=new Ai(new Se(e,t),new Se(0,1));i.maxDistance=s;let l=this.space.rayCast(i,!1,this._filter);if(l&&l.distance<=s){let r=l.normal.y;if(r<0){let o=-r;if(o>=this._maxSlopeCos){this._grounded=!0,this._groundNormal=new Se(l.normal.x,l.normal.y),this._groundBody=l.shape?.body??null,this._slopeAngle=Math.acos(Math.min(1,o));return}}}this._grounded=!1,this._groundNormal=null,this._groundBody=null,this._slopeAngle=0}_detectWalls(e,t){let s=this._getCharacterRadius(1,0)+2,i=new Ai(new Se(e,t),new Se(-1,0));i.maxDistance=s;let l=this.space.rayCast(i,!1,this._filter);l&&l.distance<=s&&Math.abs(l.normal.x)>.7&&(this._wallLeft=!0);let r=new Ai(new Se(e,t),new Se(1,0));r.maxDistance=s;let o=this.space.rayCast(r,!1,this._filter);o&&o.distance<=s&&Math.abs(o.normal.x)>.7&&(this._wallRight=!0)}_setupOneWayPlatforms(e,t){let n=new as(hn.COLLISION,e,t,s=>{try{let i=s.arbiter.collisionArbiter;if(!i)return ci.ACCEPT;let l=i.normal.y,r=s.swapped;return l>0!==r?ci.IGNORE:ci.ACCEPT}catch{return ci.ACCEPT}},0,!0);n.space=this.space,this._oneWayListener=n}_getCharacterRadius(e,t){let n=this.body.shapes.at(0);if(!n)return 0;if(n.isCircle())return n.castCircle?.radius??0;if(n.isCapsule()){let r=n.castCapsule;if(r){let o=r.radius,a=r.halfLength,p=this.body.rotation,c=Math.cos(p),h=Math.sin(p);return Math.abs(e*c+t*h)*a+o}}let s=n.bounds,i=s.width/2,l=s.height/2;return Math.abs(e)*i+Math.abs(t)*l}};var la="3.18.0";0&&(module.exports={AABB,AngleJoint,Arbiter,ArbiterType,Body,BodyCallback,BodyListener,BodyType,Broadphase,Callback,Capsule,CbEvent,CbType,CharacterController,Circle,CollisionArbiter,Compound,Constraint,ConstraintCallback,ConstraintListener,Contact,ConvexResult,DebugDraw,DebugDrawFlags,DistanceJoint,Edge,FluidArbiter,FluidProperties,Geom,GeomPoly,GravMassMode,InertiaMode,InteractionCallback,InteractionFilter,InteractionGroup,InteractionListener,InteractionType,Interactor,LineJoint,Listener,ListenerType,MarchingSquares,MassMode,Mat23,MatMN,Material,MotorJoint,NapeList,OptionType,PivotJoint,Polygon,PreCallback,PreFlag,PreListener,PulleyJoint,Ray,RayResult,Shape,ShapeType,Space,UserConstraint,VERSION,ValidationResult,Vec2,Vec3,WeldJoint,Winding,createConcaveBody});
|
|
1
|
+
'use strict';var chunkKHH45HMB_cjs=require('./chunk-KHH45HMB.cjs');var Pt={epsilon:1e-8,fluidAngularDragFriction:2.5,fluidAngularDrag:100,fluidVacuumDrag:.5,fluidLinearDrag:.5,collisionSlop:.2,collisionSlopCCD:.5,distanceThresholdCCD:.05,staticCCDLinearThreshold:.05,staticCCDAngularThreshold:.005,bulletCCDLinearThreshold:.125,bulletCCDAngularThreshold:.0125,dynamicSweepLinearThreshold:17,dynamicSweepAngularThreshold:.6,angularCCDSlipScale:.75,arbiterExpirationDelay:6,staticFrictionThreshold:2,elasticThreshold:20,sleepDelay:60,linearSleepThreshold:.2,angularSleepThreshold:.4,contactBiasCoef:.3,contactStaticBiasCoef:.6,contactContinuousBiasCoef:.4,contactContinuousStaticBiasCoef:.5,constraintLinearSlop:.1,constraintAngularSlop:.001,illConditionedThreshold:2e8},jt=chunkKHH45HMB_cjs.E();jt.Config=Object.assign(jt.Config||{},Pt);function l(n,e,t){for(;n[e]!=null;){let r=n[e][t];n[e][t]=null,n[e]=r;}}var Xe=class{static version(){return "Nape 2.0.19"}static clearObjectPools(){let e=chunkKHH45HMB_cjs.E(),t=e.__zpp;l(e.constraint.ConstraintIterator,"zpp_pool","zpp_next"),l(e.phys.InteractorIterator,"zpp_pool","zpp_next"),l(e.phys.BodyIterator,"zpp_pool","zpp_next"),l(e.phys.CompoundIterator,"zpp_pool","zpp_next"),l(e.callbacks.ListenerIterator,"zpp_pool","zpp_next"),l(e.callbacks.CbTypeIterator,"zpp_pool","zpp_next"),l(e.geom.ConvexResultIterator,"zpp_pool","zpp_next"),l(e.geom.GeomPolyIterator,"zpp_pool","zpp_next"),l(e.geom.Vec2Iterator,"zpp_pool","zpp_next"),l(e.geom.RayResultIterator,"zpp_pool","zpp_next"),l(e.shape.ShapeIterator,"zpp_pool","zpp_next"),l(e.shape.EdgeIterator,"zpp_pool","zpp_next"),l(e.dynamics.ContactIterator,"zpp_pool","zpp_next"),l(e.dynamics.ArbiterIterator,"zpp_pool","zpp_next"),l(e.dynamics.InteractionGroupIterator,"zpp_pool","zpp_next"),l(t.util.ZNPNode_ZPP_CbType,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_CallbackSet,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Shape,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Body,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Constraint,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Compound,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Arbiter,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_InteractionListener,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_CbSet,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Interactor,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_BodyListener,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_CbSetPair,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_ConstraintListener,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_CutInt,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_CutVert,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_PartitionVertex,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_SimplifyP,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_PartitionedPoly,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_GeomVert,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_SimpleVert,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_SimpleEvent,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Vec2,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_AABBPair,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Edge,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_AABBNode,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Component,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_FluidArbiter,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_SensorArbiter,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_Listener,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_ColArbiter,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_InteractionGroup,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_ToiEvent,"zpp_pool","next"),l(t.util.ZNPNode_ConvexResult,"zpp_pool","next"),l(t.util.ZNPNode_ZPP_GeomPoly,"zpp_pool","next"),l(t.util.ZNPNode_RayResult,"zpp_pool","next"),l(t.phys.ZPP_Material,"zpp_pool","next"),l(t.phys.ZPP_FluidProperties,"zpp_pool","next"),l(t.callbacks.ZPP_CbSetPair,"zpp_pool","next"),l(t.callbacks.ZPP_Callback,"zpp_pool","next"),l(t.callbacks.ZPP_CbSet,"zpp_pool","next"),l(t.geom.ZPP_GeomVert,"zpp_pool","next"),l(t.geom.ZPP_GeomVertexIterator,"zpp_pool","next"),l(t.geom.ZPP_Mat23,"zpp_pool","next"),l(t.geom.ZPP_CutVert,"zpp_pool","next"),l(t.geom.ZPP_CutInt,"zpp_pool","next"),l(t.geom.ZPP_Vec2,"zpp_pool","next"),l(t.geom.ZPP_PartitionVertex,"zpp_pool","next"),l(t.geom.ZPP_SimplifyV,"zpp_pool","next"),l(t.geom.ZPP_SimplifyP,"zpp_pool","next"),l(t.geom.ZPP_PartitionedPoly,"zpp_pool","next"),l(t.geom.ZPP_PartitionPair,"zpp_pool","next"),l(t.geom.ZPP_AABB,"zpp_pool","next"),l(t.geom.ZPP_SimpleVert,"zpp_pool","next"),l(t.geom.ZPP_SimpleSeg,"zpp_pool","next"),l(t.geom.ZPP_SimpleEvent,"zpp_pool","next"),l(t.util.Hashable2_Boolfalse,"zpp_pool","next"),l(t.geom.ZPP_ToiEvent,"zpp_pool","next"),l(t.geom.ZPP_MarchSpan,"zpp_pool","next"),l(t.geom.ZPP_MarchPair,"zpp_pool","next"),l(t.shape.ZPP_Edge,"zpp_pool","next"),l(t.space.ZPP_SweepData,"zpp_pool","next"),l(t.space.ZPP_AABBNode,"zpp_pool","next"),l(t.space.ZPP_AABBPair,"zpp_pool","next"),l(t.dynamics.ZPP_Contact,"zpp_pool","next"),l(t.space.ZPP_Island,"zpp_pool","next"),l(t.space.ZPP_Component,"zpp_pool","next"),l(t.space.ZPP_CallbackSet,"zpp_pool","next"),l(t.dynamics.ZPP_SensorArbiter,"zpp_pool","next"),l(t.dynamics.ZPP_FluidArbiter,"zpp_pool","next"),l(t.dynamics.ZPP_ColArbiter,"zpp_pool","next"),l(t.dynamics.ZPP_InteractionFilter,"zpp_pool","next"),l(t.util.ZPP_Set_ZPP_Body,"zpp_pool","next"),l(t.util.ZPP_Set_ZPP_CbSetPair,"zpp_pool","next"),l(t.util.ZPP_Set_ZPP_PartitionVertex,"zpp_pool","next"),l(t.util.ZPP_Set_ZPP_PartitionPair,"zpp_pool","next"),l(t.util.ZPP_Set_ZPP_SimpleVert,"zpp_pool","next"),l(t.util.ZPP_Set_ZPP_SimpleSeg,"zpp_pool","next"),l(t.util.ZPP_Set_ZPP_SimpleEvent,"zpp_pool","next"),l(t.util.ZPP_Set_ZPP_CbSet,"zpp_pool","next"),l(t.util.ZPP_PubPool,"poolGeomPoly","zpp_pool"),l(t.util.ZPP_PubPool,"poolVec2","zpp_pool"),l(t.util.ZPP_PubPool,"poolVec3","zpp_pool");}};var fe=class n{get _inner(){return this}constructor(e=1,t=0,r=0,i=1,p=0,s=0){let a=chunkKHH45HMB_cjs.A.get();this.zpp_inner=a,a.outer=this;let c=["a","b","tx","c","d","ty"],f=[e,t,p,r,i,s];for(let u=0;u<f.length;u++)if(f[u]!==f[u])throw new Error("Error: Mat23::"+c[u]+" cannot be NaN");a.setas(e,t,r,i,p,s);}static rotation(e){if(e!==e)throw new Error("Error: Cannot create rotation matrix with NaN angle");let t=Math.cos(e),r=Math.sin(e);return new n(t,-r,r,t,0,0)}static translation(e,t){return new n(1,0,0,1,e,t)}static scale(e,t){return new n(e,0,0,t,0,0)}static _wrap(e){return e instanceof n?e:e?e instanceof chunkKHH45HMB_cjs.A?chunkKHH45HMB_cjs.G(e,t=>{let r=Object.create(n.prototype);return r.zpp_inner=t,t.outer=r,r}):e.zpp_inner?n._wrap(e.zpp_inner):null:null}_setProp(e,t){if(t!==t)throw new Error("Error: Mat23::"+e+" cannot be NaN");this.zpp_inner[e]=t,this.zpp_inner.invalidate();}get a(){return this.zpp_inner.a}set a(e){this._setProp("a",e);}get b(){return this.zpp_inner.b}set b(e){this._setProp("b",e);}get c(){return this.zpp_inner.c}set c(e){this._setProp("c",e);}get d(){return this.zpp_inner.d}set d(e){this._setProp("d",e);}get tx(){return this.zpp_inner.tx}set tx(e){this._setProp("tx",e);}get ty(){return this.zpp_inner.ty}set ty(e){this._setProp("ty",e);}get determinant(){return this.zpp_inner.a*this.zpp_inner.d-this.zpp_inner.b*this.zpp_inner.c}clone(){return this.copy()}equals(e,t=0){if(e==null)return false;let r=this.zpp_inner,i=e.zpp_inner,p=r.a-i.a,s=r.b-i.b,a=r.c-i.c,c=r.d-i.d,f=r.tx-i.tx,u=r.ty-i.ty;return (p<0?-p:p)<=t&&(s<0?-s:s)<=t&&(a<0?-a:a)<=t&&(c<0?-c:c)<=t&&(f<0?-f:f)<=t&&(u<0?-u:u)<=t}copy(){return new n(this.zpp_inner.a,this.zpp_inner.b,this.zpp_inner.c,this.zpp_inner.d,this.zpp_inner.tx,this.zpp_inner.ty)}set(e){if(e==null)throw new Error("Error: Cannot set form null matrix");let t=e.zpp_inner;return this.zpp_inner.setas(t.a,t.b,t.c,t.d,t.tx,t.ty),this.zpp_inner.invalidate(),this}setAs(e=1,t=0,r=0,i=1,p=0,s=0){return this.zpp_inner.setas(e,t,r,i,p,s),this.zpp_inner.invalidate(),this}reset(){return this.setAs()}singular(){let{a:e,b:t,c:r,d:i}=this.zpp_inner,p=e*e+t*t+r*r+i*i,s=e*i-t*r;s<0&&(s=-s);let a=chunkKHH45HMB_cjs.E();return p>a.Config.illConditionedThreshold*s}inverse(){if(this.singular())throw new Error("Error: Matrix is singular and cannot be inverted");let{a:e,b:t,c:r,d:i,tx:p,ty:s}=this.zpp_inner,a=1/(e*i-t*r);return new n(i*a,-t*a,-r*a,e*a,(t*s-i*p)*a,(r*p-e*s)*a)}transpose(){let{a:e,b:t,c:r,d:i,tx:p,ty:s}=this.zpp_inner;return new n(e,r,t,i,-e*p-r*s,-t*p-i*s)}concat(e){if(e==null)throw new Error("Error: Cannot concatenate with null Mat23");let t=e.zpp_inner,r=this.zpp_inner;return new n(t.a*r.a+t.b*r.c,t.a*r.b+t.b*r.d,t.c*r.a+t.d*r.c,t.c*r.b+t.d*r.d,t.a*r.tx+t.b*r.ty+t.tx,t.c*r.tx+t.d*r.ty+t.ty)}transform(e,t=false,r=false){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 transform null Vec2");e.zpp_inner.validate();let i=e.zpp_inner.x,p=e.zpp_inner.y,{a:s,b:a,c,d:f,tx:u,ty:m}=this.zpp_inner,y,g;t?(y=i*s+p*a,g=i*c+p*f):(y=i*s+p*a+u,g=i*c+p*f+m);let R=chunkKHH45HMB_cjs.H.get(y,g,r);return e.zpp_inner.weak&&e.dispose(),R}inverseTransform(e,t=false,r=false){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 transform null Vec2");if(this.singular())throw new Error("Error: Matrix is singular and inverse transformation cannot be performed");let{a:i,b:p,c:s,d:a,tx:c,ty:f}=this.zpp_inner,u=1/(i*a-p*s);e.zpp_inner.validate();let m=e.zpp_inner.x,y=e.zpp_inner.y,g,R;if(t)g=(m*a-y*p)*u,R=(y*i-m*s)*u;else {let _=m-c,h=y-f;g=(_*a-h*p)*u,R=(h*i-_*s)*u;}let J=chunkKHH45HMB_cjs.H.get(g,R,r);return e.zpp_inner.weak&&e.dispose(),J}equiorthogonal(){if(this.singular())return false;let{a:e,b:t,c:r,d:i}=this.zpp_inner,p=chunkKHH45HMB_cjs.E(),s=e*t+r*i;if(s*s>=p.Config.epsilon)return false;let a=e*e+t*t-r*r-i*i;return a*a<p.Config.epsilon}orthogonal(){let{a:e,b:t,c:r,d:i}=this.zpp_inner,p=chunkKHH45HMB_cjs.E(),s=e*t+r*i;if(s*s>=p.Config.epsilon)return false;let a=e*e+t*t-1,c=r*r+i*i-1;return a*a<p.Config.epsilon&&c*c<p.Config.epsilon}_orthogonaliseImpl(e){let{a:t,b:r,c:i,d:p}=this.zpp_inner,s=chunkKHH45HMB_cjs.E(),a=Math.sqrt(t*t+i*i),c=Math.sqrt(r*r+p*p);if(a*a<s.Config.epsilon||c*c<s.Config.epsilon)throw new Error("Error: Matrix is singular and cannot be "+(e?"equiorthogonal":"orthogonal")+"ised");let f=e?(a+c)/2:1;a=f/a,c=f/c,this.a=this.zpp_inner.a*a,this.c=this.zpp_inner.c*a,this.b=this.zpp_inner.b*c,this.d=this.zpp_inner.d*c;let u=this.zpp_inner.a*this.zpp_inner.b+this.zpp_inner.c*this.zpp_inner.d,m=.25*Math.PI-.5*Math.acos(u/(f*f));this.zpp_inner.a*this.zpp_inner.d-this.zpp_inner.b*this.zpp_inner.c>0&&(m=-m);let y=Math.sin(m),g=Math.cos(m),R=this.zpp_inner.a*g-this.zpp_inner.c*y,J=this.zpp_inner.b*g+this.zpp_inner.d*y,_=this.zpp_inner.c*g+this.zpp_inner.a*y,h=this.zpp_inner.d*g-this.zpp_inner.b*y;return this.c=_,this.a=R,this.d=h,this.b=J,this.zpp_inner.invalidate(),this}equiorthogonalise(){return this.equiorthogonal()?this:this._orthogonaliseImpl(true)}orthogonalise(){return this.orthogonal()?this:this._orthogonaliseImpl(false)}toString(){let{a:e,b:t,c:r,d:i,tx:p,ty:s}=this.zpp_inner;return "{ a: "+e+" b: "+t+" c: "+r+" d: "+i+" tx: "+p+" ty: "+s+" }"}};chunkKHH45HMB_cjs.A._wrapFn=n=>chunkKHH45HMB_cjs.G(n,e=>{let t=Object.create(fe.prototype);return t.zpp_inner=e,e.outer=t,t});function et(n){if(n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=n.zpp_inner;return e._validate!=null&&e._validate(),e.x}function tt(n){if(n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=n.zpp_inner;return e._validate!=null&&e._validate(),e.y}function me(n){n.zpp_inner.weak&&n.dispose();}var q=class n{get _inner(){return this}constructor(e,t){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Ray::origin cannot be null");if(t?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: Ray::direction cannot be null");let r=new chunkKHH45HMB_cjs.B;this.zpp_inner=r;let i=et(e),p=tt(e);r.origin.zpp_inner.x=i,r.origin.zpp_inner.y=p,r.origin.zpp_inner._invalidate!=null&&r.origin.zpp_inner._invalidate(r.origin.zpp_inner),me(e);let s=et(t),a=tt(t);r.direction.zpp_inner.x=s,r.direction.zpp_inner.y=a,r.direction.zpp_inner._invalidate!=null&&r.direction.zpp_inner._invalidate(r.direction.zpp_inner),me(t),r.zip_dir=true,r.maxdist=1/0;}static _wrap(e){return e==null?null:e instanceof n?e:chunkKHH45HMB_cjs.G(e,t=>{let r=Object.create(n.prototype);return r.zpp_inner=t.zpp_inner??t,r})}static fromSegment(e,t){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Ray::fromSegment::start is null");if(t?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: Ray::fromSegment::end is null");let r=t.sub(e,true),i=new n(e,r),p=et(e),s=tt(e),a=et(t),c=tt(t),f=a-p,u=c-s,m=Math.sqrt(f*f+u*u);if(m!==m)throw new Error("Error: maxDistance cannot be NaN");return i.zpp_inner.maxdist=m,me(e),me(t),i}get origin(){return this.zpp_inner.origin}set origin(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Ray::origin cannot be null");this.zpp_inner.origin.set(e),me(e);}get direction(){return this.zpp_inner.direction}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: Ray::direction cannot be null");this.zpp_inner.direction.set(e),this.zpp_inner.zip_dir=true,me(e);}get maxDistance(){return this.zpp_inner.maxdist}set maxDistance(e){if(e!==e)throw new Error("Error: maxDistance cannot be NaN");this.zpp_inner.maxdist=e;}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}aabb(){return chunkKHH45HMB_cjs.K._wrap(this.zpp_inner.rayAABB())}at(e,t=false){this.zpp_inner.validate_dir();let r=this.zpp_inner.origin.zpp_inner;r._validate!=null&&r._validate();let i=r.x,p=r.y,s=i+e*this.zpp_inner.dirx,a=p+e*this.zpp_inner.diry;return chunkKHH45HMB_cjs.H.get(s,a,t)}clone(){return this.copy()}copy(){let e=new n(this.zpp_inner.origin,this.zpp_inner.direction),t=this.zpp_inner.maxdist;if(t!==t)throw new Error("Error: maxDistance cannot be NaN");return e.zpp_inner.maxdist=t,e}};var ze=class n{get _inner(){return this}constructor(){if(this.zpp_inner=null,!chunkKHH45HMB_cjs.x.internal)throw new Error("Error: ConvexResult cannot be instantiated derp!")}static _wrap(e){if(!e)return null;if(e instanceof n)return e;let t=e.zpp_inner??e;return chunkKHH45HMB_cjs.G(t,r=>{let i=Object.create(n.prototype);return i.zpp_inner=r,i})}get normal(){return this._disposed(),chunkKHH45HMB_cjs.H._wrap(this.zpp_inner.normal)}get position(){return this._disposed(),chunkKHH45HMB_cjs.H._wrap(this.zpp_inner.position)}get toi(){return this._disposed(),this.zpp_inner.toiDistance}get shape(){return this._disposed(),this.zpp_inner.shape}dispose(){this._disposed(),this.zpp_inner.free();}toString(){return this._disposed(),"{ shape: "+String(this.zpp_inner.shape)+" toi: "+this.zpp_inner.toiDistance+" }"}_disposed(){if(this.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used")}};chunkKHH45HMB_cjs.x._createConvexResult=()=>new ze;var de=class n{get _inner(){return this}constructor(){if(this.zpp_inner=null,!chunkKHH45HMB_cjs.x.internal)throw new Error("Error: RayResult cannot be instantiated derp!")}static _wrap(e){if(!e)return null;if(e instanceof n)return e;let t=e.zpp_inner??e;return chunkKHH45HMB_cjs.G(t,r=>{let i=Object.create(n.prototype);return i.zpp_inner=r,i})}get normal(){return this._disposed(),chunkKHH45HMB_cjs.H._wrap(this.zpp_inner.normal)}get distance(){return this._disposed(),this.zpp_inner.toiDistance}get inner(){return this._disposed(),this.zpp_inner.inner}get shape(){return this._disposed(),this.zpp_inner.shape}dispose(){this._disposed(),this.zpp_inner.free();}toString(){return this._disposed(),"{ shape: "+String(this.zpp_inner.shape)+" distance: "+this.zpp_inner.toiDistance+" ?inner: "+String(this.zpp_inner.inner)+" }"}_disposed(){if(this.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used")}};chunkKHH45HMB_cjs.x._createRayResult=()=>new de;function ie(n){return n?.zpp_inner??n?._inner?.zpp_inner}function nt(n){return n?.zpp_inner??n?._inner?.zpp_inner}function rt(n,e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=n.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");t._isimmutable!=null&&t._isimmutable();}function ye(n,e){if(ie(n)?.body?.outer==null)throw new Error(`Error: Shape must be part of a Body to calculate ${e}`)}var Se=class{static distanceBody(e,t,r,i){rt(r),rt(i);let p=nt(e),s=nt(t);if(p.shapes.head==null||s.shapes.head==null)throw new Error("Error: Bodies cannot be empty in calculating distances");let a=p.shapes.head;for(;a!=null;)chunkKHH45HMB_cjs.y.validateShape(a.elt),a=a.next;for(a=s.shapes.head;a!=null;)chunkKHH45HMB_cjs.y.validateShape(a.elt),a=a.next;return chunkKHH45HMB_cjs.C.distanceBody(p,s,r.zpp_inner,i.zpp_inner)}static distance(e,t,r,i){rt(r),rt(i),ye(e,"distances"),ye(t,"distances");let p=ie(e),s=ie(t);chunkKHH45HMB_cjs.y.validateShape(p),chunkKHH45HMB_cjs.y.validateShape(s);let a;chunkKHH45HMB_cjs.l.zpp_pool==null?a=new chunkKHH45HMB_cjs.l:(a=chunkKHH45HMB_cjs.l.zpp_pool,chunkKHH45HMB_cjs.l.zpp_pool=a.next,a.next=null),a.weak=false;let c=chunkKHH45HMB_cjs.C.distance(p,s,r.zpp_inner,i.zpp_inner,a,1e100);return a.next=chunkKHH45HMB_cjs.l.zpp_pool,chunkKHH45HMB_cjs.l.zpp_pool=a,c}static intersectsBody(e,t){let r=nt(e),i=nt(t);if(r.shapes.head==null||i.shapes.head==null)throw new Error("Error: Bodies must have shapes to test for intersection.");let p=r.shapes.head;for(;p!=null;)chunkKHH45HMB_cjs.y.validateShape(p.elt),p=p.next;for(p=i.shapes.head;p!=null;)chunkKHH45HMB_cjs.y.validateShape(p.elt),p=p.next;let s=r.aabb,a=i.aabb;if(s.minx>a.maxx||s.maxx<a.minx||s.miny>a.maxy||s.maxy<a.miny)return false;let c=r.shapes.head;for(;c!=null;){let f=i.shapes.head;for(;f!=null;){if(chunkKHH45HMB_cjs.w.testCollide_safe(c.elt,f.elt))return true;f=f.next;}c=c.next;}return false}static intersects(e,t){ye(e,"intersection"),ye(t,"intersection");let r=ie(e),i=ie(t);chunkKHH45HMB_cjs.y.validateShape(r),chunkKHH45HMB_cjs.y.validateShape(i);let p=r.aabb,s=i.aabb;return p.minx>s.maxx||p.maxx<s.minx||p.miny>s.maxy||p.maxy<s.miny?false:chunkKHH45HMB_cjs.w.testCollide_safe(r,i)}static contains(e,t){ye(e,"containment"),ye(t,"containment");let r=ie(e),i=ie(t);return chunkKHH45HMB_cjs.y.validateShape(r),chunkKHH45HMB_cjs.y.validateShape(i),chunkKHH45HMB_cjs.w.containTest(r,i)}};var Ze=class{static run(e,t,r,i=2,p=null,s=true,a=null){if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(p!=null&&p.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: MarchingSquares requires an iso function to operate");if(t==null)throw new Error("Error: MarchingSquares requires an AABB to define bounds of surface extraction");if(r==null)throw new Error("Error: MarchingSquares requires a Vec2 to define cell size for surface extraction");let c=r.zpp_inner;if(c._validate!=null&&c._validate(),c.x<=0||c.y<=0)throw new Error("Error: MarchingSquares cannot operate with non-positive cell dimensions");if(i<0)throw new Error("Error: MarchingSquares cannot use a negative quality value for interpolation");if(p!=null){let g=p.zpp_inner;if(g._validate!=null&&g._validate(),g.x<=0||g.y<=0)throw new Error("Error: MarchingSquares cannot with non-positive sub-grid dimensions")}let f=chunkKHH45HMB_cjs.E(),u=a??new f.geom.GeomPolyList,m=chunkKHH45HMB_cjs.z,y=t.zpp_inner;if(y._validate!=null&&y._validate(),p==null){let g=y.minx,R=y.miny,J=y.maxx,_=y.maxy;m.run(e,g,R,J,_,r,i,s,u);}else {let g=p.zpp_inner;g._validate!=null&&g._validate();let R=y.maxx-y.minx,J=y.maxy-y.miny,_=R/g.x,h=J/g.y,b=_|0,G=h|0;b!==_&&++b,G!==h&&++G;for(let Ye=0;Ye<b;Ye++){let vt=y.minx+g.x*Ye,Kt=Ye===b-1?y.maxx:vt+g.x;for(let je=0;je<G;je++){let Nt=y.miny+g.y*je,Jt=je===G-1?y.maxy:Nt+g.y;m.run(e,vt,Nt,Kt,Jt,r,i,s,u);}}}return c.weak&&r.dispose(),p!=null&&p.zpp_inner.weak&&p.dispose(),u}};var Q=class{constructor(){this.outer=null;this.inner=null;this.immutable=false;this._invalidated=false;this._invalidate=null;this._validate=null;this._modifiable=null;this.adder=null;this.post_adder=null;this.subber=null;this.dontremove=false;this.reverse_flag=false;this.at_index=0;this.at_ite=null;this.push_ite=null;this.zip_length=false;this.user_length=0;this.inner=new chunkKHH45HMB_cjs.c,this._invalidated=true;}static get(e,t){t==null&&(t=false);let r=chunkKHH45HMB_cjs.E(),i=new r.geom.Vec2List;return i.zpp_inner.inner=e,t&&(i.zpp_inner.immutable=true),i.zpp_inner.zip_length=true,i}valmod(){this.validate(),this.inner.modified&&(this.inner.pushmod&&(this.push_ite=null),this.at_ite=null,this.inner.modified=false,this.inner.pushmod=false,this.zip_length=true);}modified(){this.zip_length=true,this.at_ite=null,this.push_ite=null;}modify_test(){this._modifiable!=null&&this._modifiable();}validate(){this._invalidated&&(this._invalidated=false,this._validate!=null&&this._validate());}invalidate(){this._invalidated=true,this._invalidate!=null&&this._invalidate(this);}};Q.internal=false;function oe(n){if(n.outer==null){let e=chunkKHH45HMB_cjs.E();n.outer=new e.geom.Vec2;let t=n.outer.zpp_inner;t.outer!=null&&(t.outer.zpp_inner=null,t.outer=null),t._isimmutable=null,t._validate=null,t._invalidate=null,t.next=chunkKHH45HMB_cjs.l.zpp_pool,chunkKHH45HMB_cjs.l.zpp_pool=t,n.outer.zpp_inner=n;}return n.outer}function I(){if(this.zpp_next=null,this.zpp_critical=false,this.zpp_i=0,this.zpp_inner=null,!Q.internal)throw new Error("Error: Cannot instantiate Vec2Iterator derp!")}I.zpp_pool=null;I.get=function(n){let e;return I.zpp_pool==null?(Q.internal=true,e=new I,Q.internal=false):(e=I.zpp_pool,I.zpp_pool=e.zpp_next),e.zpp_i=0,e.zpp_inner=n,e.zpp_critical=false,e};I.prototype.zpp_inner=null;I.prototype.zpp_i=null;I.prototype.zpp_critical=null;I.prototype.zpp_next=null;I.prototype.hasNext=function(){this.zpp_inner.zpp_inner.valmod();let n=this.zpp_inner.zpp_gl();return this.zpp_critical=true,this.zpp_i<n?true:(this.zpp_next=I.zpp_pool,I.zpp_pool=this,this.zpp_inner=null,false)};I.prototype.next=function(){return this.zpp_critical=false,this.zpp_inner.at(this.zpp_i++)};function E(){this.zpp_inner=null,this.zpp_inner=new Q,this.zpp_inner.outer=this;}E.fromArray=function(n){if(n==null)throw new Error("Error: Cannot convert null Array to Nape list");let e=chunkKHH45HMB_cjs.E(),t=new e.geom.Vec2List;for(let r=0;r<n.length;r++)t.push(n[r]);return t};E.prototype.zpp_inner=null;Object.defineProperty(E.prototype,"length",{get:function(){return this.zpp_gl()}});E.prototype.zpp_gl=function(){return this.zpp_inner.valmod(),this.zpp_inner.zip_length&&(this.zpp_inner.zip_length=false,this.zpp_inner.user_length=this.zpp_inner.inner.length),this.zpp_inner.user_length};E.prototype.zpp_vm=function(){this.zpp_inner.valmod();};E.prototype.has=function(n){return this.zpp_vm(),this.zpp_inner.inner.has(n.zpp_inner)};E.prototype.at=function(n){if(this.zpp_vm(),n<0||n>=this.zpp_gl())throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(n=this.zpp_gl()-1-n),n<this.zpp_inner.at_index||this.zpp_inner.at_ite==null)this.zpp_inner.at_index=n,this.zpp_inner.at_ite=this.zpp_inner.inner.iterator_at(n);else for(;this.zpp_inner.at_index!=n;)this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;return oe(this.zpp_inner.at_ite.elt)};E.prototype.push=function(n){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(n):true;return e&&(this.zpp_inner.reverse_flag?this.zpp_inner.inner.add(n.zpp_inner):(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.empty()?null:this.zpp_inner.inner.iterator_at(this.zpp_gl()-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,n.zpp_inner)),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(n)),e};E.prototype.unshift=function(n){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(n):true;return e&&(this.zpp_inner.reverse_flag?(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.empty()?null:this.zpp_inner.inner.iterator_at(this.zpp_gl()-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,n.zpp_inner)):this.zpp_inner.inner.add(n.zpp_inner),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(n)),e};E.prototype.pop=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.empty())throw new Error("Error: Cannot remove from empty list");this.zpp_vm();let n;if(this.zpp_inner.reverse_flag){n=this.zpp_inner.inner.head.elt;let e=oe(n);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.zpp_inner.inner.pop();}else {this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let e=this.zpp_gl()==1?null:this.zpp_inner.inner.iterator_at(this.zpp_gl()-2);n=e==null?this.zpp_inner.inner.head.elt:e.next.elt;let t=oe(n);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(e);}return this.zpp_inner.invalidate(),oe(n)};E.prototype.shift=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.empty())throw new Error("Error: Cannot remove from empty list");this.zpp_vm();let n;if(this.zpp_inner.reverse_flag){this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let e=this.zpp_gl()==1?null:this.zpp_inner.inner.iterator_at(this.zpp_gl()-2);n=e==null?this.zpp_inner.inner.head.elt:e.next.elt;let t=oe(n);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(e);}else {n=this.zpp_inner.inner.head.elt;let e=oe(n);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.zpp_inner.inner.pop();}return this.zpp_inner.invalidate(),oe(n)};E.prototype.add=function(n){return this.zpp_inner.reverse_flag?this.push(n):this.unshift(n)};E.prototype.remove=function(n){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=false,t=this.zpp_inner.inner.head;for(;t!=null;){if(t.elt==n.zpp_inner){e=true;break}t=t.next;}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(n),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(n.zpp_inner),this.zpp_inner.invalidate()),e};E.prototype.clear=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.reverse_flag)for(;!this.empty();)this.pop();else for(;!this.empty();)this.shift();};E.prototype.empty=function(){return this.zpp_gl()==0};E.prototype.iterator=function(){return this.zpp_vm(),I.get(this)};E.prototype.copy=function(n){n==null&&(n=false);let e=chunkKHH45HMB_cjs.E(),t=new e.geom.Vec2List,r=I.get(this);for(;r.hasNext();){let i=r.next(),p;if(n){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=i.zpp_inner;s._validate!=null&&s._validate();let a=i.zpp_inner.x,c=i.zpp_inner;c._validate!=null&&c._validate();let f=i.zpp_inner.y,u;if(chunkKHH45HMB_cjs.b.poolVec2==null?u=new e.geom.Vec2:(u=chunkKHH45HMB_cjs.b.poolVec2,chunkKHH45HMB_cjs.b.poolVec2=u.zpp_pool,u.zpp_pool=null,u.zpp_disp=false,u==chunkKHH45HMB_cjs.b.nextVec2&&(chunkKHH45HMB_cjs.b.nextVec2=null)),u.zpp_inner==null){let m;chunkKHH45HMB_cjs.l.zpp_pool==null?m=new chunkKHH45HMB_cjs.l:(m=chunkKHH45HMB_cjs.l.zpp_pool,chunkKHH45HMB_cjs.l.zpp_pool=m.next,m.next=null),m.weak=false,m._immutable=false,m.x=a,m.y=f,u.zpp_inner=m,u.zpp_inner.outer=u;}else u.zpp_inner.x=a,u.zpp_inner.y=f,u.zpp_inner._invalidate!=null&&u.zpp_inner._invalidate(u.zpp_inner);u.zpp_inner.weak=false,p=u;}else p=i;t.push(p);}return t};E.prototype.merge=function(n){if(n==null)throw new Error("Error: Cannot merge with null list");let e=n.iterator();for(;e.hasNext();){let t=e.next();this.has(t)||this.add(t);}};E.prototype.toString=function(){let n="[",e=true,t=I.get(this);for(;t.hasNext();){let r=t.next();e||(n+=","),n+=r==null?"NULL":r.toString(),e=false;}return n+"]"};E.prototype.foreach=function(n){if(n==null)throw new Error("Error: Cannot execute null on list elements");let e=this.iterator();for(;e.hasNext();)try{n(e.next());}catch{e.zpp_next=I.zpp_pool,I.zpp_pool=e,e.zpp_inner=null;break}return this};E.prototype[Symbol.iterator]=function(){let n=I.get(this);return {next(){return n.hasNext()?{value:n.next(),done:false}:{value:void 0,done:true}},[Symbol.iterator](){return this}}};E.prototype.filter=function(n){if(n==null)throw new Error("Error: Cannot select elements of list with null");let e=0;for(;e<this.zpp_gl();){let t=this.at(e);try{n(t)?++e:this.remove(t);}catch{break}}return this};function pe(){if(!chunkKHH45HMB_cjs.M.internal)throw new Error("Error: Cannot instantiate GeomVertexIterator")}pe.prototype.zpp_inner=null;pe.prototype.hasNext=function(){if(this.zpp_inner==null)throw new Error("Error: Iterator has been disposed");let n=this.zpp_inner.ptr!=this.zpp_inner.start||this.zpp_inner.first;if(this.zpp_inner.first=false,!n){let e=this.zpp_inner;e.outer.zpp_inner=null,e.ptr=e.start=null,e.next=chunkKHH45HMB_cjs.M.zpp_pool,chunkKHH45HMB_cjs.M.zpp_pool=e;}return n};pe.prototype.next=function(){if(this.zpp_inner==null)throw new Error("Error: Iterator has been disposed");let n=this.zpp_inner.ptr;if(n.wrap==null){let t=n.x,r=n.y;if(t!==t||r!==r)throw new Error("Error: Vec2 components cannot be NaN");let i=chunkKHH45HMB_cjs.E(),p;if(chunkKHH45HMB_cjs.b.poolVec2==null?p=new i.geom.Vec2:(p=chunkKHH45HMB_cjs.b.poolVec2,chunkKHH45HMB_cjs.b.poolVec2=p.zpp_pool,p.zpp_pool=null,p.zpp_disp=false,p==chunkKHH45HMB_cjs.b.nextVec2&&(chunkKHH45HMB_cjs.b.nextVec2=null)),p.zpp_inner==null){let s;chunkKHH45HMB_cjs.l.zpp_pool==null?s=new chunkKHH45HMB_cjs.l:(s=chunkKHH45HMB_cjs.l.zpp_pool,chunkKHH45HMB_cjs.l.zpp_pool=s.next,s.next=null),s.weak=false,s._immutable=false,s.x=t,s.y=r,p.zpp_inner=s,p.zpp_inner.outer=p;}else {if(p.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=p.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable(),s.x==t&&s.y==r||(s.x=t,s.y=r,s._invalidate!=null&&s._invalidate(s));}p.zpp_inner.weak=false,n.wrap=p,n.wrap.zpp_inner._inuse=true,n.wrap.zpp_inner._invalidate=s=>n.modwrap(s),n.wrap.zpp_inner._validate=()=>n.getwrap();}let e=n.wrap;return this.zpp_inner.ptr=this.zpp_inner.forward?this.zpp_inner.ptr.next:this.zpp_inner.ptr.prev,e};pe.prototype[Symbol.iterator]=function(){return {_it:this,next(){return this._it.hasNext()?{value:this._it.next(),done:false}:{value:void 0,done:true}},[Symbol.iterator](){return this}}};var $t=chunkKHH45HMB_cjs.E();$t.geom.GeomVertexIterator=pe;var Y=class{constructor(){this.outer=null;this.inner=null;this.immutable=false;this._invalidated=false;this._invalidate=null;this._validate=null;this._modifiable=null;this.adder=null;this.post_adder=null;this.subber=null;this.dontremove=false;this.reverse_flag=false;this.at_index=0;this.at_ite=null;this.push_ite=null;this.zip_length=false;this.user_length=0;this.inner=new chunkKHH45HMB_cjs.u,this._invalidated=true;}static get(e,t){t==null&&(t=false);let r=chunkKHH45HMB_cjs.E(),i=new r.dynamics.ContactList;return i.zpp_inner.inner=e,t&&(i.zpp_inner.immutable=true),i.zpp_inner.zip_length=true,i}valmod(){this.validate(),this.inner.modified&&(this.inner.pushmod&&(this.push_ite=null),this.at_ite=null,this.inner.modified=false,this.inner.pushmod=false,this.zip_length=true);}modified(){this.zip_length=true,this.at_ite=null,this.push_ite=null;}modify_test(){this._modifiable!=null&&this._modifiable();}validate(){this._invalidated&&(this._invalidated=false,this._validate!=null&&this._validate());}invalidate(){this._invalidated=true,this._invalidate!=null&&this._invalidate(this);}};Y.internal=false;var be=class n{constructor(){if(!chunkKHH45HMB_cjs.D.internal)throw new Error("Error: Cannot instantiate an Edge derp!")}static _wrap(e){return e?e instanceof n?e:e instanceof chunkKHH45HMB_cjs.D?chunkKHH45HMB_cjs.G(e,t=>{chunkKHH45HMB_cjs.D.internal=true;let r=new n;return chunkKHH45HMB_cjs.D.internal=false,r.zpp_inner=t,t.outer=r,r}):null:null}get polygon(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.outer_zn}get localNormal(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.wrap_lnorm==null&&e.getlnorm(),e.wrap_lnorm}get worldNormal(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.wrap_gnorm==null&&e.getgnorm(),e.wrap_gnorm}get length(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_laxi(),e.length}get localProjection(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_laxi(),e.lprojection}get worldProjection(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");if(e.polygon.body==null)throw new Error("Error: Edge world projection only makes sense for Polygons contained within a rigid body");return e.polygon.validate_gaxi(),e.gprojection}get localVertex1(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_laxi(),this._wrapVert(e.lp0)}get localVertex2(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_laxi(),this._wrapVert(e.lp1)}get worldVertex1(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_gaxi(),this._wrapVert(e.gp0)}get worldVertex2(){let e=this.zpp_inner;if(e.polygon==null)throw new Error("Error: Edge not current in use");return e.polygon.validate_gaxi(),this._wrapVert(e.gp1)}toString(){let e=this.zpp_inner;return e.polygon==null?"Edge(object-pooled)":e.polygon.body==null?(e.polygon.validate_laxi(),"{ localNormal : { x: "+e.lnormx+" y: "+e.lnormy+" } }"):(e.polygon.validate_gaxi(),"{ localNormal : { x: "+e.lnormx+" y: "+e.lnormy+" } worldNormal : { x: "+e.gnormx+" y: "+e.gnormy+" } }")}_wrapVert(e){let t=chunkKHH45HMB_cjs.E();if(e.outer==null){e.outer=new t.geom.Vec2;let r=e.outer.zpp_inner;r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=chunkKHH45HMB_cjs.l.zpp_pool,chunkKHH45HMB_cjs.l.zpp_pool=r,e.outer.zpp_inner=e;}return e.outer}};chunkKHH45HMB_cjs.D._wrapFn=n=>chunkKHH45HMB_cjs.G(n,e=>{chunkKHH45HMB_cjs.D.internal=true;let t=new be;return chunkKHH45HMB_cjs.D.internal=false,t.zpp_inner=e,e.outer=t,t});var ge=class n{constructor(){if(!chunkKHH45HMB_cjs.a.internal)throw new Error("Error: Cannot instantiate ValidationResult derp!")}static get VALID(){return chunkKHH45HMB_cjs.a.ValidationResult_VALID==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ValidationResult_VALID=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ValidationResult_VALID}static get DEGENERATE(){return chunkKHH45HMB_cjs.a.ValidationResult_DEGENERATE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ValidationResult_DEGENERATE=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ValidationResult_DEGENERATE}static get CONCAVE(){return chunkKHH45HMB_cjs.a.ValidationResult_CONCAVE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ValidationResult_CONCAVE=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ValidationResult_CONCAVE}static get SELF_INTERSECTING(){return chunkKHH45HMB_cjs.a.ValidationResult_SELF_INTERSECTING==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ValidationResult_SELF_INTERSECTING=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ValidationResult_SELF_INTERSECTING}toString(){return this===chunkKHH45HMB_cjs.a.ValidationResult_VALID?"VALID":this===chunkKHH45HMB_cjs.a.ValidationResult_DEGENERATE?"DEGENERATE":this===chunkKHH45HMB_cjs.a.ValidationResult_CONCAVE?"CONCAVE":this===chunkKHH45HMB_cjs.a.ValidationResult_SELF_INTERSECTING?"SELF_INTERSECTING":""}},Qt=chunkKHH45HMB_cjs.E();Qt.shape.ValidationResult=ge;var we=class n{get _inner(){return this}constructor(e=false){let t=new chunkKHH45HMB_cjs.v;this.zpp_inner=t,t.outer=this,t.ignore!=e&&(t.invalidate(true),t.ignore=e);}static _wrap(e){return e instanceof n?e:e?e instanceof chunkKHH45HMB_cjs.v?chunkKHH45HMB_cjs.G(e,t=>{let r=Object.create(n.prototype);return r.zpp_inner=t,t.outer=r,r}):e.zpp_inner?n._wrap(e.zpp_inner):null:null}get group(){return this.zpp_inner.group==null?null:this.zpp_inner.group.outer}set group(e){if(e===this)throw new Error("Error: Cannot assign InteractionGroup to itself");this.zpp_inner.setGroup(e==null?null:e.zpp_inner);}get ignore(){return this.zpp_inner.ignore}set ignore(e){this.zpp_inner.ignore!=e&&(this.zpp_inner.invalidate(true),this.zpp_inner.ignore=e);}get interactors(){if(this.zpp_inner.wrap_interactors==null){let e=chunkKHH45HMB_cjs.E();this.zpp_inner.wrap_interactors=e.zpp_nape.util.ZPP_InteractorList.get(this.zpp_inner.interactors,true);}return this.zpp_inner.wrap_interactors}get groups(){if(this.zpp_inner.wrap_groups==null){let e=chunkKHH45HMB_cjs.E();this.zpp_inner.wrap_groups=e.zpp_nape.util.ZPP_InteractionGroupList.get(this.zpp_inner.groups,true);}return this.zpp_inner.wrap_groups}toString(){let e="InteractionGroup";return this.zpp_inner.ignore&&(e+=":ignore"),e}};chunkKHH45HMB_cjs.v._wrapFn=n=>chunkKHH45HMB_cjs.G(n,e=>{let t=Object.create(we.prototype);return t.zpp_inner=e,e.outer=t,t});var Ee=class n{constructor(){if(!chunkKHH45HMB_cjs.a.internal)throw new Error("Error: Cannot instantiate ArbiterType derp!")}static get COLLISION(){return chunkKHH45HMB_cjs.a.ArbiterType_COLLISION==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ArbiterType_COLLISION=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ArbiterType_COLLISION}static get SENSOR(){return chunkKHH45HMB_cjs.a.ArbiterType_SENSOR==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ArbiterType_SENSOR=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ArbiterType_SENSOR}static get FLUID(){return chunkKHH45HMB_cjs.a.ArbiterType_FLUID==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ArbiterType_FLUID=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ArbiterType_FLUID}toString(){return this===chunkKHH45HMB_cjs.a.ArbiterType_COLLISION?"COLLISION":this===chunkKHH45HMB_cjs.a.ArbiterType_SENSOR?"SENSOR":this===chunkKHH45HMB_cjs.a.ArbiterType_FLUID?"FLUID":""}},Xt=chunkKHH45HMB_cjs.E();Xt.dynamics.ArbiterType=Ee;chunkKHH45HMB_cjs.F();var j=class{get _inner(){return this}constructor(){if(this.zpp_inner=null,!chunkKHH45HMB_cjs.t.internal)throw new Error("Error: Cannot instantiate Arbiter derp!")}get isSleeping(){return this._activeCheck(),this.zpp_inner.sleeping}get type(){return chunkKHH45HMB_cjs.t.types[this.zpp_inner.type]}get collisionArbiter(){return this.zpp_inner.type==chunkKHH45HMB_cjs.t.COL?this.zpp_inner.colarb.outer_zn:null}get fluidArbiter(){return this.zpp_inner.type==chunkKHH45HMB_cjs.t.FLUID?this.zpp_inner.fluidarb.outer_zn:null}get shape1(){return this._activeCheck(),this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws2.outer:this.zpp_inner.ws1.outer}get shape2(){return this._activeCheck(),this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws1.outer:this.zpp_inner.ws2.outer}get body1(){return this._activeCheck(),this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.b2.outer:this.zpp_inner.b1.outer}get body2(){return this._activeCheck(),this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.b1.outer:this.zpp_inner.b2.outer}get state(){this._activeCheck();let e=chunkKHH45HMB_cjs.E(),t=this.zpp_inner.immState;return t==5?(chunkKHH45HMB_cjs.a.PreFlag_ACCEPT==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.PreFlag_ACCEPT=new e.callbacks.PreFlag,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.PreFlag_ACCEPT):t==1?(chunkKHH45HMB_cjs.a.PreFlag_ACCEPT_ONCE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.PreFlag_ACCEPT_ONCE=new e.callbacks.PreFlag,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.PreFlag_ACCEPT_ONCE):t==6?(chunkKHH45HMB_cjs.a.PreFlag_IGNORE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.PreFlag_IGNORE=new e.callbacks.PreFlag,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.PreFlag_IGNORE):(chunkKHH45HMB_cjs.a.PreFlag_IGNORE_ONCE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.PreFlag_IGNORE_ONCE=new e.callbacks.PreFlag,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.PreFlag_IGNORE_ONCE)}isCollisionArbiter(){return this.zpp_inner.type==chunkKHH45HMB_cjs.t.COL}isFluidArbiter(){return this.zpp_inner.type==chunkKHH45HMB_cjs.t.FLUID}isSensorArbiter(){return this.zpp_inner.type==chunkKHH45HMB_cjs.t.SENSOR}totalImpulse(e=null,t=false){return this._activeCheck(),e!=null&&this._checkBody(e),chunkKHH45HMB_cjs.I.get(0,0,0)}toString(){let e=this.zpp_inner.type==chunkKHH45HMB_cjs.t.COL?"CollisionArbiter":this.zpp_inner.type==chunkKHH45HMB_cjs.t.FLUID?"FluidArbiter":"SensorArbiter";if(this.zpp_inner.cleared)return e+"(object-pooled)";this._activeCheck();let t=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws2.outer:this.zpp_inner.ws1.outer,r=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws1.outer:this.zpp_inner.ws2.outer,i=e+"("+t.toString()+"|"+r.toString()+")";return this.zpp_inner.type==chunkKHH45HMB_cjs.t.COL&&(i+="["+["SD","DD"][this.zpp_inner.colarb.stat?0:1]+"]"),i+="<-"+this.state.toString(),i}_activeCheck(){if(!this.zpp_inner.active)throw new Error("Error: Arbiter not currently in use")}_checkBody(e){let t=this.zpp_inner,r=t.ws1.id>t.ws2.id?t.b2.outer:t.b1.outer,i=t.ws1.id>t.ws2.id?t.b1.outer:t.b2.outer;if(e!=r&&e!=i)throw new Error("Error: Arbiter does not relate to body")}},en=chunkKHH45HMB_cjs.E();en.dynamics.Arbiter=j;var Ve=class extends j{constructor(){super();}get contacts(){return this._activeCheck(),this.zpp_inner.colarb.wrap_contacts==null&&this.zpp_inner.colarb.setupcontacts(),this.zpp_inner.colarb.wrap_contacts}get normal(){return this._activeCheck(),this.zpp_inner.colarb.wrap_normal==null&&this.zpp_inner.colarb.getnormal(),this.zpp_inner.colarb.wrap_normal}get radius(){return this._activeCheck(),this.zpp_inner.colarb.radius}get referenceEdge1(){this._activeCheck();let e=this.zpp_inner.colarb.__ref_edge1;if(e!=null){let t=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws2.outer:this.zpp_inner.ws1.outer;t.zpp_inner.type==1?t.zpp_inner!=e.polygon&&(e=this.zpp_inner.colarb.__ref_edge2):e=this.zpp_inner.colarb.__ref_edge2;}return e==null?null:e.wrapper()}get referenceEdge2(){this._activeCheck();let e=this.zpp_inner.colarb.__ref_edge1;if(e!=null){let t=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws1.outer:this.zpp_inner.ws2.outer;t.zpp_inner.type==1?t.zpp_inner!=e.polygon&&(e=this.zpp_inner.colarb.__ref_edge2):e=this.zpp_inner.colarb.__ref_edge2;}return e==null?null:e.wrapper()}get elasticity(){return this._activeCheck(),this.zpp_inner.colarb.validate_props(),this.zpp_inner.colarb.restitution}set elasticity(e){if(this._mutableCheck("elasticity"),e!==e)throw new Error("Error: CollisionArbiter::elasticity cannot be NaN");if(e<0)throw new Error("Error: CollisionArbiter::elasticity cannot be negative");this.zpp_inner.colarb.restitution=e,this.zpp_inner.colarb.userdef_restitution=true,this._activeCheck(),this.zpp_inner.colarb.validate_props();}get dynamicFriction(){return this._activeCheck(),this.zpp_inner.colarb.validate_props(),this.zpp_inner.colarb.dyn_fric}set dynamicFriction(e){if(this._mutableCheck("dynamicFriction"),e!==e)throw new Error("Error: CollisionArbiter::dynamicFriction cannot be NaN");if(e<0)throw new Error("Error: CollisionArbiter::dynamicFriction cannot be negative");this.zpp_inner.colarb.dyn_fric=e,this.zpp_inner.colarb.userdef_dyn_fric=true,this._activeCheck(),this.zpp_inner.colarb.validate_props();}get staticFriction(){return this._activeCheck(),this.zpp_inner.colarb.validate_props(),this.zpp_inner.colarb.stat_fric}set staticFriction(e){if(this._mutableCheck("staticFriction"),e!==e)throw new Error("Error: CollisionArbiter::staticFriction cannot be NaN");if(e<0)throw new Error("Error: CollisionArbiter::staticFriction cannot be negative");this.zpp_inner.colarb.stat_fric=e,this.zpp_inner.colarb.userdef_stat_fric=true,this._activeCheck(),this.zpp_inner.colarb.validate_props();}get rollingFriction(){return this._activeCheck(),this.zpp_inner.colarb.validate_props(),this.zpp_inner.colarb.rfric}set rollingFriction(e){if(this._mutableCheck("rollingFriction"),e!==e)throw new Error("Error: CollisionArbiter::rollingFriction cannot be NaN");if(e<0)throw new Error("Error: CollisionArbiter::rollingFriction cannot be negative");this.zpp_inner.colarb.rfric=e,this.zpp_inner.colarb.userdef_rfric=true,this._activeCheck(),this.zpp_inner.colarb.validate_props();}firstVertex(){return this._activeCheck(),this.zpp_inner.colarb.__ref_edge1!=null!=(this.zpp_inner.colarb.__ref_edge2!=null)?this.zpp_inner.colarb.__ref_vertex==-1:false}secondVertex(){return this._activeCheck(),this.zpp_inner.colarb.__ref_edge1!=null!=(this.zpp_inner.colarb.__ref_edge2!=null)?this.zpp_inner.colarb.__ref_vertex==1:false}normalImpulse(e=null,t=false){return this._activeCheck(),e!=null&&this._checkBody(e),this._accumulateImpulse("normalImpulse",e,t)}tangentImpulse(e=null,t=false){return this._activeCheck(),e!=null&&this._checkBody(e),this._accumulateImpulse("tangentImpulse",e,t)}totalImpulse(e=null,t=false){return this._activeCheck(),e!=null&&this._checkBody(e),this._accumulateImpulse("totalImpulse",e,t)}rollingImpulse(e=null,t=false){this._activeCheck(),e!=null&&this._checkBody(e);let r=this.zpp_inner.colarb;return !t||r.oc1.fresh?r.oc1.wrapper().rollingImpulse(e):0}_mutableCheck(e){if(!this.zpp_inner.colarb.mutable)throw new Error("Error: CollisionArbiter::"+e+" is only mutable during a pre-handler")}_accumulateImpulse(e,t,r){let i=0,p=0,s=0,a=this.zpp_inner.colarb;if(!r||a.oc1.fresh){let c=a.oc1.wrapper()[e](t),f=c.zpp_inner;f._validate!=null&&f._validate(),i+=f.x,f._validate!=null&&f._validate(),p+=f.y,f._validate!=null&&f._validate(),s+=f.z,c.dispose();}if(a.hc2&&(!r||a.oc2.fresh)){let c=a.oc2.wrapper()[e](t),f=c.zpp_inner;f._validate!=null&&f._validate(),i+=f.x,f._validate!=null&&f._validate(),p+=f.y,f._validate!=null&&f._validate(),s+=f.z,c.dispose();}return chunkKHH45HMB_cjs.I.get(i,p,s)}};var Oe=class extends j{constructor(){super();}get position(){return this._activeCheck(),this.zpp_inner.fluidarb.wrap_position==null&&this.zpp_inner.fluidarb.getposition(),chunkKHH45HMB_cjs.H._wrap(this.zpp_inner.fluidarb.wrap_position)}set position(e){if(!this.zpp_inner.fluidarb.mutable)throw new Error("Error: Arbiter is mutable only within a pre-handler");if(e==null)throw new Error("Error: FluidArbiter::position cannot be null");this._activeCheck(),this.zpp_inner.fluidarb.wrap_position==null&&this.zpp_inner.fluidarb.getposition(),this.zpp_inner.fluidarb.wrap_position.set(e);}get overlap(){return this._activeCheck(),this.zpp_inner.fluidarb.overlap}set overlap(e){if(!this.zpp_inner.fluidarb.mutable)throw new Error("Error: Arbiter is mutable only within a pre-handler");if(e!==e)throw new Error("Error: FluidArbiter::overlap cannot be NaN");if(e<=0||e==1/0)throw new Error("Error: FluidArbiter::overlap must be strictly positive and non infinite");this.zpp_inner.fluidarb.overlap=e;}buoyancyImpulse(e=null){this._activeCheck(),e!=null&&this._checkBody(e);let t=this.zpp_inner.fluidarb;return e==null?chunkKHH45HMB_cjs.I.get(t.buoyx,t.buoyy,0):e.zpp_inner==this.zpp_inner.b2?chunkKHH45HMB_cjs.I.get(t.buoyx,t.buoyy,t.buoyy*t.r2x-t.buoyx*t.r2y):chunkKHH45HMB_cjs.I.get(-t.buoyx,-t.buoyy,-(t.buoyy*t.r1x-t.buoyx*t.r1y))}dragImpulse(e=null){this._activeCheck(),e!=null&&this._checkBody(e);let t=this.zpp_inner.fluidarb,r=e==null||e.zpp_inner==this.zpp_inner.b2?1:-1;return chunkKHH45HMB_cjs.I.get(t.dampx*r,t.dampy*r,t.adamp*r)}totalImpulse(e=null,t=false){this._activeCheck(),e!=null&&this._checkBody(e);let r=this.buoyancyImpulse(e),i=this.dragImpulse(e),p=r.zpp_inner,s=i.zpp_inner;return p._validate!=null&&p._validate(),s._validate!=null&&s._validate(),s.x=s.x+p.x,p._validate!=null&&p._validate(),s._validate!=null&&s._validate(),s.y=s.y+p.y,p._validate!=null&&p._validate(),s._validate!=null&&s._validate(),s.z=s.z+p.z,r.dispose(),i}};var Pe=class{get _inner(){return this}constructor(){if(this.zpp_inner=null,!chunkKHH45HMB_cjs.u.internal)throw new Error("Error: Cannot instantiate Contact derp!")}get arbiter(){if(this.zpp_inner.arbiter==null)return null;let e=this.zpp_inner.arbiter.outer;return e.zpp_inner.type==chunkKHH45HMB_cjs.t.COL?e.zpp_inner.colarb.outer_zn:null}get penetration(){return this._inactiveCheck(),-this.zpp_inner.dist}get position(){return this._inactiveCheck(),this.zpp_inner.wrap_position==null&&this.zpp_inner.getposition(),chunkKHH45HMB_cjs.H._wrap(this.zpp_inner.wrap_position)}get fresh(){return this._inactiveCheck(),this.zpp_inner.fresh}get friction(){return this._inactiveCheck(),this.zpp_inner.inner.friction}normalImpulse(e=null){this._inactiveCheck();let t=this.zpp_inner.arbiter.colarb,r=this.zpp_inner.inner,i=r.jnAcc;return e==null?chunkKHH45HMB_cjs.I.get(t.nx*i,t.ny*i):(this._checkBody(e,t),e==t.b1.outer?chunkKHH45HMB_cjs.I.get(t.nx*-i,t.ny*-i,-(t.ny*r.r1x-t.nx*r.r1y)*i):chunkKHH45HMB_cjs.I.get(t.nx*i,t.ny*i,(t.ny*r.r2x-t.nx*r.r2y)*i))}tangentImpulse(e=null){this._inactiveCheck();let t=this.zpp_inner.arbiter.colarb,r=this.zpp_inner.inner,i=r.jtAcc;return e==null?chunkKHH45HMB_cjs.I.get(-t.ny*i,t.nx*i):(this._checkBody(e,t),e==t.b1.outer?chunkKHH45HMB_cjs.I.get(t.ny*i,-t.nx*i,-(r.r1x*t.nx+r.r1y*t.ny)*i):chunkKHH45HMB_cjs.I.get(-t.ny*i,t.nx*i,(r.r2x*t.nx+r.r2y*t.ny)*i))}rollingImpulse(e=null){this._inactiveCheck();let t=this.zpp_inner.arbiter.colarb,r=t.jrAcc;return e==null?r:(this._checkBody(e,t),e==t.b1.outer?-r:r)}totalImpulse(e=null){this._inactiveCheck();let t=this.zpp_inner.arbiter.colarb,r=this.zpp_inner.inner,i=r.jnAcc,p=r.jtAcc,s=t.jrAcc;if(e==null)return chunkKHH45HMB_cjs.I.get(t.nx*i-t.ny*p,t.ny*i+t.nx*p,s);this._checkBody(e,t);let a=t.nx*i-t.ny*p,c=t.ny*i+t.nx*p;return e==t.b1.outer?chunkKHH45HMB_cjs.I.get(-a,-c,-(c*r.r1x-a*r.r1y)-s):chunkKHH45HMB_cjs.I.get(a,c,c*r.r2x-a*r.r2y+s)}toString(){return this.zpp_inner.arbiter==null||this.zpp_inner.arbiter.cleared?"{object-pooled}":"{Contact}"}_inactiveCheck(){if(this.zpp_inner.inactiveme())throw new Error("Error: Contact not currently in use")}_checkBody(e,t){if(e!=t.b1.outer&&e!=t.b2.outer)throw new Error("Error: Contact does not relate to the given body")}};chunkKHH45HMB_cjs.u._wrapFn=n=>{chunkKHH45HMB_cjs.u.internal=true;let e=new Pe;return chunkKHH45HMB_cjs.u.internal=false,e.zpp_inner=n,n.outer=e,e};function tn(n){let e=0,t=n.inner.next;for(;t!=null;)t.active&&t.arbiter.active&&e++,t=t.next;return e}function V(n){return n.valmod(),n.zip_length&&(n.zip_length=false,n.user_length=tn(n)),n.user_length}function v(){if(this.zpp_next=null,this.zpp_critical=false,this.zpp_i=0,this.zpp_inner=null,!Y.internal)throw new Error("Error: Cannot instantiate ContactIterator derp!")}v.zpp_pool=null;v.get=function(n){let e;return v.zpp_pool==null?(Y.internal=true,e=new v,Y.internal=false):(e=v.zpp_pool,v.zpp_pool=e.zpp_next),e.zpp_i=0,e.zpp_inner=n,e.zpp_critical=false,e};v.prototype.zpp_inner=null;v.prototype.zpp_i=null;v.prototype.zpp_critical=null;v.prototype.zpp_next=null;v.prototype.hasNext=function(){this.zpp_inner.zpp_inner.valmod();let n=V(this.zpp_inner.zpp_inner);return this.zpp_critical=true,this.zpp_i<n?true:(this.zpp_next=v.zpp_pool,v.zpp_pool=this,this.zpp_inner=null,false)};v.prototype.next=function(){return this.zpp_critical=false,this.zpp_inner.at(this.zpp_i++)};function A(){this.zpp_inner=null,this.zpp_inner=new Y,this.zpp_inner.outer=this;}A.fromArray=function(n){if(n==null)throw new Error("Error: Cannot convert null Array to Nape list");let e=chunkKHH45HMB_cjs.E(),t=new e.dynamics.ContactList;for(let r=0;r<n.length;r++)t.push(n[r]);return t};A.prototype.zpp_inner=null;Object.defineProperty(A.prototype,"length",{get:function(){return V(this.zpp_inner)}});A.prototype.has=function(n){return this.zpp_inner.valmod(),this.zpp_inner.inner.has(n.zpp_inner)};A.prototype.at=function(n){this.zpp_inner.valmod();let e=V(this.zpp_inner);if(n<0||n>=e)throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(n=V(this.zpp_inner)-1-n),n<this.zpp_inner.at_index||this.zpp_inner.at_ite==null)for(this.zpp_inner.at_index=0,this.zpp_inner.at_ite=this.zpp_inner.inner.next;;){let t=this.zpp_inner.at_ite;if(t.active&&t.arbiter.active)break;this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;}for(;this.zpp_inner.at_index!=n;)for(this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;;){let t=this.zpp_inner.at_ite;if(t.active&&t.arbiter.active)break;this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;}return this.zpp_inner.at_ite.wrapper()};A.prototype.push=function(n){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(n):true;if(e){if(this.zpp_inner.reverse_flag)this.zpp_inner.inner.add(n.zpp_inner);else {if(this.zpp_inner.push_ite==null){let t=V(this.zpp_inner);t==0?this.zpp_inner.push_ite=null:this.zpp_inner.push_ite=this.zpp_inner.inner.iterator_at(t-1);}this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,n.zpp_inner);}this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(n);}return e};A.prototype.unshift=function(n){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(n):true;if(e){if(this.zpp_inner.reverse_flag){if(this.zpp_inner.push_ite==null){let t=V(this.zpp_inner);t==0?this.zpp_inner.push_ite=null:this.zpp_inner.push_ite=this.zpp_inner.inner.iterator_at(t-1);}this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,n.zpp_inner);}else this.zpp_inner.inner.add(n.zpp_inner);this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(n);}return e};A.prototype.pop=function(){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");if(this.zpp_inner.modify_test(),V(this.zpp_inner)==0)throw new Error("Error: Cannot remove from empty list");this.zpp_inner.valmod();let e;if(this.zpp_inner.reverse_flag){e=this.zpp_inner.inner.next;let t=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.pop();}else {this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let t=V(this.zpp_inner),r;t==1?r=null:r=this.zpp_inner.inner.iterator_at(t-2),e=r==null?this.zpp_inner.inner.next:r.next;let i=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(i),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(r);}return this.zpp_inner.invalidate(),e.wrapper()};A.prototype.shift=function(){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");if(this.zpp_inner.modify_test(),V(this.zpp_inner)==0)throw new Error("Error: Cannot remove from empty list");this.zpp_inner.valmod();let e;if(this.zpp_inner.reverse_flag){this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let t=V(this.zpp_inner),r;t==1?r=null:r=this.zpp_inner.inner.iterator_at(t-2),e=r==null?this.zpp_inner.inner.next:r.next;let i=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(i),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(r);}else {e=this.zpp_inner.inner.next;let t=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.pop();}return this.zpp_inner.invalidate(),e.wrapper()};A.prototype.add=function(n){return this.zpp_inner.reverse_flag?this.push(n):this.unshift(n)};A.prototype.remove=function(n){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let e=false,t=this.zpp_inner.inner.next;for(;t!=null;){if(t==n.zpp_inner){e=true;break}t=t.next;}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(n),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(n.zpp_inner),this.zpp_inner.invalidate()),e};A.prototype.clear=function(){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");if(this.zpp_inner.reverse_flag)for(;V(this.zpp_inner)!=0;)this.pop();else for(;V(this.zpp_inner)!=0;)this.shift();};A.prototype.empty=function(){return V(this.zpp_inner)==0};A.prototype.iterator=function(){return this.zpp_inner.valmod(),v.get(this)};A.prototype.copy=function(n){n==null&&(n=false);let e=chunkKHH45HMB_cjs.E(),t=new e.dynamics.ContactList;this.zpp_inner.valmod();let r=v.get(this);for(;r.hasNext();){let i=r.next();if(n)throw new Error("Error: Contact is not a copyable type");t.push(i);}return t};A.prototype.merge=function(n){if(n==null)throw new Error("Error: Cannot merge with null list");n.zpp_inner.valmod();let e=v.get(n);for(;e.hasNext();){let t=e.next();this.has(t)||(this.zpp_inner.reverse_flag?this.push(t):this.unshift(t));}};A.prototype.toString=function(){let n="[",e=true;this.zpp_inner.valmod();let t=v.get(this);for(;t.hasNext();){let r=t.next();e||(n+=","),n+=r==null?"NULL":r.toString(),e=false;}return n+"]"};A.prototype.foreach=function(n){if(n==null)throw new Error("Error: Cannot execute null on list elements");this.zpp_inner.valmod();let e=v.get(this);for(;e.hasNext();)try{n(e.next());}catch{e.zpp_next=v.zpp_pool,v.zpp_pool=e,e.zpp_inner=null;break}return this};A.prototype[Symbol.iterator]=function(){let n=v.get(this);return {next(){return n.hasNext()?{value:n.next(),done:false}:{value:void 0,done:true}},[Symbol.iterator](){return this}}};A.prototype.filter=function(n){if(n==null)throw new Error("Error: Cannot select elements of list with null");let e=0;for(;;){let t=V(this.zpp_inner);if(!(e<t))break;let r=this.at(e);try{n(r)?++e:this.remove(r);}catch{break}}return this};var C=class n{constructor(){if(!chunkKHH45HMB_cjs.a.internal)throw new Error("Error: Cannot instantiate CbEvent derp!")}static get BEGIN(){return chunkKHH45HMB_cjs.a.CbEvent_BEGIN==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.CbEvent_BEGIN=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.CbEvent_BEGIN}static get ONGOING(){return chunkKHH45HMB_cjs.a.CbEvent_ONGOING==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.CbEvent_ONGOING=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.CbEvent_ONGOING}static get END(){return chunkKHH45HMB_cjs.a.CbEvent_END==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.CbEvent_END=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.CbEvent_END}static get WAKE(){return chunkKHH45HMB_cjs.a.CbEvent_WAKE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.CbEvent_WAKE=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.CbEvent_WAKE}static get SLEEP(){return chunkKHH45HMB_cjs.a.CbEvent_SLEEP==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.CbEvent_SLEEP=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.CbEvent_SLEEP}static get BREAK(){return chunkKHH45HMB_cjs.a.CbEvent_BREAK==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.CbEvent_BREAK=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.CbEvent_BREAK}static get PRE(){return chunkKHH45HMB_cjs.a.CbEvent_PRE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.CbEvent_PRE=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.CbEvent_PRE}toString(){return this===chunkKHH45HMB_cjs.a.CbEvent_BEGIN?"BEGIN":this===chunkKHH45HMB_cjs.a.CbEvent_ONGOING?"ONGOING":this===chunkKHH45HMB_cjs.a.CbEvent_END?"END":this===chunkKHH45HMB_cjs.a.CbEvent_WAKE?"WAKE":this===chunkKHH45HMB_cjs.a.CbEvent_SLEEP?"SLEEP":this===chunkKHH45HMB_cjs.a.CbEvent_BREAK?"BREAK":this===chunkKHH45HMB_cjs.a.CbEvent_PRE?"PRE":""}},nn=chunkKHH45HMB_cjs.E();nn.callbacks.CbEvent=C;chunkKHH45HMB_cjs.F();var Ce=class n{get _inner(){return this}constructor(){this.zpp_inner=new chunkKHH45HMB_cjs.e,this.zpp_inner.outer=this;}static get ANY_BODY(){return chunkKHH45HMB_cjs.e.ANY_BODY}static get ANY_CONSTRAINT(){return chunkKHH45HMB_cjs.e.ANY_CONSTRAINT}static get ANY_SHAPE(){return chunkKHH45HMB_cjs.e.ANY_SHAPE}static get ANY_COMPOUND(){return chunkKHH45HMB_cjs.e.ANY_COMPOUND}get id(){return this.zpp_inner.id}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get interactors(){return this.zpp_inner.wrap_interactors==null&&(this.zpp_inner.wrap_interactors=chunkKHH45HMB_cjs.Z.get(this.zpp_inner.interactors,true)),this.zpp_inner.wrap_interactors}get constraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=chunkKHH45HMB_cjs.Y.get(this.zpp_inner.constraints,true)),this.zpp_inner.wrap_constraints}including(e){return new(chunkKHH45HMB_cjs.E()).callbacks.OptionType(this).including(e)}excluding(e){return new(chunkKHH45HMB_cjs.E()).callbacks.OptionType(this).excluding(e)}toString(){return this===chunkKHH45HMB_cjs.e.ANY_BODY?"ANY_BODY":this===chunkKHH45HMB_cjs.e.ANY_SHAPE?"ANY_SHAPE":this===chunkKHH45HMB_cjs.e.ANY_COMPOUND?"ANY_COMPOUND":this===chunkKHH45HMB_cjs.e.ANY_CONSTRAINT?"ANY_CONSTRAINT":"CbType#"+this.zpp_inner.id}static _wrap(e){return e instanceof n?e:e?e instanceof chunkKHH45HMB_cjs.e?chunkKHH45HMB_cjs.G(e,t=>{let r=Object.create(n.prototype);return r.zpp_inner=t,t.outer=r,r}):e.zpp_inner?n._wrap(e.zpp_inner):null:null}},rn=chunkKHH45HMB_cjs.E();rn.callbacks.CbType=Ce;chunkKHH45HMB_cjs.F();var Z=class n{constructor(){if(!chunkKHH45HMB_cjs.a.internal)throw new Error("Error: Cannot instantiate InteractionType derp!")}static get COLLISION(){return chunkKHH45HMB_cjs.a.InteractionType_COLLISION==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.InteractionType_COLLISION=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.InteractionType_COLLISION}static get SENSOR(){return chunkKHH45HMB_cjs.a.InteractionType_SENSOR==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.InteractionType_SENSOR=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.InteractionType_SENSOR}static get FLUID(){return chunkKHH45HMB_cjs.a.InteractionType_FLUID==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.InteractionType_FLUID=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.InteractionType_FLUID}static get ANY(){return chunkKHH45HMB_cjs.a.InteractionType_ANY==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.InteractionType_ANY=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.InteractionType_ANY}toString(){return this===chunkKHH45HMB_cjs.a.InteractionType_COLLISION?"COLLISION":this===chunkKHH45HMB_cjs.a.InteractionType_SENSOR?"SENSOR":this===chunkKHH45HMB_cjs.a.InteractionType_FLUID?"FLUID":this===chunkKHH45HMB_cjs.a.InteractionType_ANY?"ANY":""}},on=chunkKHH45HMB_cjs.E();on.callbacks.InteractionType=Z;var W=class n{constructor(){if(!chunkKHH45HMB_cjs.a.internal)throw new Error("Error: Cannot instantiate PreFlag derp!")}static get ACCEPT(){return chunkKHH45HMB_cjs.a.PreFlag_ACCEPT==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.PreFlag_ACCEPT=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.PreFlag_ACCEPT}static get IGNORE(){return chunkKHH45HMB_cjs.a.PreFlag_IGNORE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.PreFlag_IGNORE=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.PreFlag_IGNORE}static get ACCEPT_ONCE(){return chunkKHH45HMB_cjs.a.PreFlag_ACCEPT_ONCE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.PreFlag_ACCEPT_ONCE=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.PreFlag_ACCEPT_ONCE}static get IGNORE_ONCE(){return chunkKHH45HMB_cjs.a.PreFlag_IGNORE_ONCE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.PreFlag_IGNORE_ONCE=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.PreFlag_IGNORE_ONCE}toString(){return this===chunkKHH45HMB_cjs.a.PreFlag_ACCEPT?"ACCEPT":this===chunkKHH45HMB_cjs.a.PreFlag_IGNORE?"IGNORE":this===chunkKHH45HMB_cjs.a.PreFlag_ACCEPT_ONCE?"ACCEPT_ONCE":this===chunkKHH45HMB_cjs.a.PreFlag_IGNORE_ONCE?"IGNORE_ONCE":""}},pn=chunkKHH45HMB_cjs.E();pn.callbacks.PreFlag=W;var xe=class n{get _inner(){return this}constructor(e,t){this.zpp_inner=new chunkKHH45HMB_cjs.j,this.zpp_inner.outer=this,e!=null&&this.including(e),t!=null&&this.excluding(t);}get includes(){return this.zpp_inner.wrap_includes==null&&this.zpp_inner.setup_includes(),this.zpp_inner.wrap_includes}get excludes(){return this.zpp_inner.wrap_excludes==null&&this.zpp_inner.setup_excludes(),this.zpp_inner.wrap_excludes}including(e){return this.zpp_inner.append(this.zpp_inner.includes,e),this}excluding(e){return this.zpp_inner.append(this.zpp_inner.excludes,e),this}toString(){this.zpp_inner.wrap_includes==null&&this.zpp_inner.setup_includes();let e=this.zpp_inner.wrap_includes.toString();this.zpp_inner.wrap_excludes==null&&this.zpp_inner.setup_excludes();let t=this.zpp_inner.wrap_excludes.toString();return "@{"+e+" excluding "+t+"}"}static _wrap(e){return e instanceof n?e:e?e instanceof chunkKHH45HMB_cjs.j?chunkKHH45HMB_cjs.G(e,t=>{let r=Object.create(n.prototype);return r.zpp_inner=t,t.outer=r,r}):e.zpp_inner?n._wrap(e.zpp_inner):null:null}},sn=chunkKHH45HMB_cjs.E();sn.callbacks.OptionType=xe;function an(n){return n===C.BEGIN?0:n===C.END?1:n===C.WAKE?2:n===C.SLEEP?3:n===C.BREAK?4:n===C.PRE?5:n===C.ONGOING?6:-1}var B=class n{get _inner(){return this}constructor(){if(!chunkKHH45HMB_cjs.f.internal)throw new Error("Error: Cannot instantiate Listener derp!");this.zpp_inner=null;}static _wrap(e){return e instanceof n?e:e&&e instanceof chunkKHH45HMB_cjs.f?chunkKHH45HMB_cjs.G(e,t=>{if(t.outer)return t.outer;let r=Object.create(n.prototype);return r.zpp_inner=t,t.outer=r,r}):null}get type(){return chunkKHH45HMB_cjs.f.types[this.zpp_inner.type]}get event(){return chunkKHH45HMB_cjs.f.events[this.zpp_inner.event]}set event(e){if(e==null)throw new Error("Error: Cannot set listener event type to null");if(chunkKHH45HMB_cjs.f.events[this.zpp_inner.event]!=e){let t=an(e);this.zpp_inner.swapEvent(t);}}get precedence(){return this.zpp_inner.precedence}set precedence(e){this.zpp_inner.precedence!=e&&(this.zpp_inner.precedence=e,this.zpp_inner.invalidate_precedence());}get space(){return this.zpp_inner.space==null?null:chunkKHH45HMB_cjs.X._wrap(this.zpp_inner.space.outer)}set space(e){let t=e!=null?e._inner??e:null;if((this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=t)if(this.zpp_inner.space!=null&&this.zpp_inner.space.wrap_listeners.remove(this),t!=null){let i=t.zpp_inner.wrap_listeners;i.zpp_inner.reverse_flag?i.push(this):i.unshift(this);}else this.zpp_inner.space=null;}toString(){let t=["BEGIN","END","WAKE","SLEEP","BREAK","PRE","ONGOING"][this.zpp_inner.event];if(this.zpp_inner.type==0){let r=this.zpp_inner.body;return "BodyListener{"+t+"::"+String(r.outer_zn.zpp_inner_zn.options.outer)+"}"}else if(this.zpp_inner.type==1){let r=this.zpp_inner.constraint;return "ConstraintListener{"+t+"::"+String(r.outer_zn.zpp_inner_zn.options.outer)+"}"}else {let r=this.zpp_inner.interaction,i;switch(r.itype){case 1:i="COLLISION";break;case 2:i="SENSOR";break;case 4:i="FLUID";break;default:i="ALL";}return this.zpp_inner.type==2?"InteractionListener{"+t+"#"+i+"::"+String(r.outer_zni.zpp_inner_zn.options1.outer)+":"+String(r.outer_zni.zpp_inner_zn.options2.outer)+"} precedence="+this.zpp_inner.precedence:"PreListener{"+i+"::"+String(r.outer_znp.zpp_inner_zn.options1.outer)+":"+String(r.outer_znp.zpp_inner_zn.options2.outer)+"} precedence="+this.zpp_inner.precedence}}};var ve=class n{constructor(){if(!chunkKHH45HMB_cjs.a.internal)throw new Error("Error: Cannot instantiate ListenerType derp!")}static get BODY(){return chunkKHH45HMB_cjs.a.ListenerType_BODY==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ListenerType_BODY=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ListenerType_BODY}static get CONSTRAINT(){return chunkKHH45HMB_cjs.a.ListenerType_CONSTRAINT==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ListenerType_CONSTRAINT=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ListenerType_CONSTRAINT}static get INTERACTION(){return chunkKHH45HMB_cjs.a.ListenerType_INTERACTION==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ListenerType_INTERACTION=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ListenerType_INTERACTION}static get PRE(){return chunkKHH45HMB_cjs.a.ListenerType_PRE==null&&(chunkKHH45HMB_cjs.a.internal=true,chunkKHH45HMB_cjs.a.ListenerType_PRE=new n,chunkKHH45HMB_cjs.a.internal=false),chunkKHH45HMB_cjs.a.ListenerType_PRE}toString(){return this===chunkKHH45HMB_cjs.a.ListenerType_BODY?"BODY":this===chunkKHH45HMB_cjs.a.ListenerType_CONSTRAINT?"CONSTRAINT":this===chunkKHH45HMB_cjs.a.ListenerType_INTERACTION?"INTERACTION":this===chunkKHH45HMB_cjs.a.ListenerType_PRE?"PRE":""}},ln=chunkKHH45HMB_cjs.E();ln.callbacks.ListenerType=ve;chunkKHH45HMB_cjs.F();var F=class{constructor(){this.zpp_inner=null;if(!chunkKHH45HMB_cjs.d.internal)throw new Error("Error: Callback cannot be instantiated derp!")}get event(){return chunkKHH45HMB_cjs.f.events[this.zpp_inner.event]}get listener(){return this.zpp_inner.listener.outer}toString(){return ""}};var Re=class extends F{get body(){return this.zpp_inner.body.outer}toString(){return "Cb:"+["WAKE","SLEEP"][this.zpp_inner.event-2]+":"+this.zpp_inner.body.outer.toString()+" : listener: "+String(this.zpp_inner.listener.outer)}};var ke=class extends F{get constraint(){return this.zpp_inner.constraint.outer}toString(){return "Cb:"+["WAKE","SLEEP","BREAK"][this.zpp_inner.event-2]+":"+this.zpp_inner.constraint.outer.toString()+" : listener: "+String(this.zpp_inner.listener.outer)}};var Be=class extends F{get int1(){return this.zpp_inner.int1.outer_i}get int2(){return this.zpp_inner.int2.outer_i}get arbiters(){return this.zpp_inner.wrap_arbiters}toString(){return "Cb:"+["BEGIN","END","","","","","ONGOING"][this.zpp_inner.event]+":"+this.zpp_inner.int1.outer_i.toString()+"/"+this.zpp_inner.int2.outer_i.toString()+" : "+this.zpp_inner.wrap_arbiters.toString()+" : listener: "+String(this.zpp_inner.listener.outer)}};var Fe=class extends F{get arbiter(){return this.zpp_inner.pre_arbiter.wrapper()}get int1(){return this.zpp_inner.int1.outer_i}get int2(){return this.zpp_inner.int2.outer_i}get swapped(){return this.zpp_inner.pre_swapped}toString(){return "Cb:PRE::"+this.zpp_inner.int1.outer_i.toString()+"/"+this.zpp_inner.int2.outer_i.toString()+" : "+this.zpp_inner.pre_arbiter.wrapper().toString()+" : listnener: "+String(this.zpp_inner.listener.outer)}};var Ge=class extends B{constructor(e,t,r,i=0){if(chunkKHH45HMB_cjs.f.internal=true,super(),chunkKHH45HMB_cjs.f.internal=false,r==null)throw new Error("Error: BodyListener::handler cannot be null");let p;if(e===C.WAKE)p=2;else if(e===C.SLEEP)p=3;else throw new Error("Error: cbEvent '"+e.toString()+"' is not a valid event type for a BodyListener");this.zpp_inner_zn=new chunkKHH45HMB_cjs.g(chunkKHH45HMB_cjs.j.argument(t),p,r),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zn=this,this.zpp_inner.precedence=i;}get options(){return this.zpp_inner_zn.options.outer}set options(e){this.zpp_inner_zn.options.set(e.zpp_inner);}get handler(){return this.zpp_inner_zn.handler}set handler(e){if(e==null)throw new Error("Error: BodyListener::handler cannot be null");this.zpp_inner_zn.handler=e;}};var De=class extends B{constructor(e,t,r,i=0){if(chunkKHH45HMB_cjs.f.internal=true,super(),chunkKHH45HMB_cjs.f.internal=false,r==null)throw new Error("Error: ConstraintListener::handler cannot be null");let p;if(e===C.WAKE)p=2;else if(e===C.SLEEP)p=3;else if(e===C.BREAK)p=4;else throw new Error("Error: cbEvent '"+e.toString()+"' is not a valid event type for a ConstraintListener");this.zpp_inner_zn=new chunkKHH45HMB_cjs.h(chunkKHH45HMB_cjs.j.argument(t),p,r),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zn=this,this.zpp_inner.precedence=i;}get options(){return this.zpp_inner_zn.options.outer}set options(e){this.zpp_inner_zn.options.set(e.zpp_inner);}get handler(){return this.zpp_inner_zn.handler}set handler(e){if(e==null)throw new Error("Error: ConstraintListener::handler cannot be null");this.zpp_inner_zn.handler=e;}};function Me(n){return n===Z.COLLISION?1:n===Z.SENSOR?2:n===Z.FLUID?4:7}function se(n){return n==1?Z.COLLISION:n==2?Z.SENSOR:n==4?Z.FLUID:n==7?Z.ANY:null}var Ue=class extends B{constructor(e,t,r,i,p,s=0){if(chunkKHH45HMB_cjs.f.internal=true,super(),chunkKHH45HMB_cjs.f.internal=false,p==null)throw new Error("Error: InteractionListener::handler cannot be null");if(e==null)throw new Error("Error: CbEvent cannot be null for InteractionListener");let a;if(e===C.BEGIN)a=0;else if(e===C.END)a=1;else if(e===C.ONGOING)a=6;else throw new Error("Error: CbEvent '"+e.toString()+"' is not a valid event type for InteractionListener");if(this.zpp_inner_zn=new chunkKHH45HMB_cjs.i(chunkKHH45HMB_cjs.j.argument(r),chunkKHH45HMB_cjs.j.argument(i),a,2),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zni=this,this.zpp_inner.precedence=s,this.zpp_inner_zn.handleri=p,t==null)throw new Error("Error: Cannot set listener interaction type to null");se(this.zpp_inner_zn.itype)!=t&&(this.zpp_inner_zn.itype=Me(t));}get options1(){return this.zpp_inner_zn.options1.outer}set options1(e){this.zpp_inner_zn.options1.set(e.zpp_inner);}get options2(){return this.zpp_inner_zn.options2.outer}set options2(e){this.zpp_inner_zn.options2.set(e.zpp_inner);}get handler(){return this.zpp_inner_zn.handleri}set handler(e){if(e==null)throw new Error("Error: InteractionListener::handler cannot be null");this.zpp_inner_zn.handleri=e;}get interactionType(){return se(this.zpp_inner_zn.itype)}set interactionType(e){if(e==null)throw new Error("Error: Cannot set listener interaction type to null");se(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=Me(e));}get allowSleepingCallbacks(){return this.zpp_inner_zn.allowSleepingCallbacks}set allowSleepingCallbacks(e){this.zpp_inner_zn.allowSleepingCallbacks=e;}};var ae=class extends B{constructor(e,t,r,i,p=0,s=false){if(chunkKHH45HMB_cjs.f.internal=true,super(),chunkKHH45HMB_cjs.f.internal=false,i==null)throw new Error("Error: PreListener must take a handler!");if(this.zpp_inner_zn=new chunkKHH45HMB_cjs.i(chunkKHH45HMB_cjs.j.argument(t),chunkKHH45HMB_cjs.j.argument(r),5,3),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_znp=this,this.zpp_inner.precedence=p,this.zpp_inner_zn.pure=s,this.zpp_inner_zn.handlerp=i,e==null)throw new Error("Error: Cannot set listener interaction type to null");se(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=Me(e));}get options1(){return this.zpp_inner_zn.options1.outer}set options1(e){this.zpp_inner_zn.options1.set(e.zpp_inner);}get options2(){return this.zpp_inner_zn.options2.outer}set options2(e){this.zpp_inner_zn.options2.set(e.zpp_inner);}get handler(){return this.zpp_inner_zn.handlerp}set handler(e){if(e==null)throw new Error("Error: PreListener must take a non-null handler!");this.zpp_inner_zn.handlerp=e,this.zpp_inner_zn.wake();}get pure(){return this.zpp_inner_zn.pure}set pure(e){e||this.zpp_inner_zn.wake(),this.zpp_inner_zn.pure=e;}get interactionType(){return se(this.zpp_inner_zn.itype)}set interactionType(e){if(e==null)throw new Error("Error: Cannot set listener interaction type to null");se(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=Me(e));}};var We=class n extends chunkKHH45HMB_cjs.ka{constructor(e,t=false){if(super(),e<1)throw new Error("Error: Constraint dimension must be at least 1");let r=new chunkKHH45HMB_cjs.r(e,t);this.zpp_inner=r,r.outer=this,r.outer_zn=this;}static _wrap(e){return e==null?null:e instanceof n?e:e.zpp_inner?.outer instanceof n?e.zpp_inner.outer:chunkKHH45HMB_cjs.G(e,t=>{let r=Object.create(n.prototype);return r.zpp_inner=t.zpp_inner??t,r.zpp_inner.outer=r,r.zpp_inner.outer_zn=r,r})}__bindVec2(){let e=new chunkKHH45HMB_cjs.H;return e.zpp_inner._inuse=true,e.zpp_inner._invalidate=this.zpp_inner.bindVec2_invalidate.bind(this.zpp_inner),e}__copy(){throw new Error("Error: UserConstraint::__copy must be overriden")}__broken(){}__validate(){}__draw(e){}__prepare(){}__position(e){throw new Error("Error: UserConstraint::__position must be overriden")}__velocity(e){throw new Error("Error: Userconstraint::__velocity must be overriden")}__eff_mass(e){throw new Error("Error: UserConstraint::__eff_mass must be overriden")}__clamp(e){}__impulse(e,t,r){throw new Error("Error: UserConstraint::__impulse must be overriden")}impulse(){let e=this.zpp_inner.dim,t=new chunkKHH45HMB_cjs.J(e,1);for(let r=0;r<e;r++){if(r<0||r>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");t.zpp_inner.x[r*t.zpp_inner.n]=this.zpp_inner.jAcc[r];}return t}bodyImpulse(e){if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let t=false;for(let r of this.zpp_inner.bodies)if(r.body==e.zpp_inner){t=true;break}if(!t)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):chunkKHH45HMB_cjs.I.get()}visitBodies(e){let t=this.zpp_inner.bodies.length,r=0;for(;r<t;){let i=this.zpp_inner.bodies[r];if(i.body!=null){let p=false;for(let s=r+1;s<t;s++)if(this.zpp_inner.bodies[s].body==i.body){p=true;break}p||e(i.body.outer);}++r;}}__invalidate(){this.zpp_inner.immutable_midstep("UserConstraint::invalidate()"),this.zpp_inner.active&&(this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=null&&this.zpp_inner.wake();}__registerBody(e,t){if(this.zpp_inner.immutable_midstep("UserConstraint::registerBody(..)"),e!=t){if(e!=null){if(!this.zpp_inner.remBody(e.zpp_inner))throw new Error("Error: oldBody is not registered to the cosntraint");this.zpp_inner.active&&(this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=null&&e.zpp_inner.wake();}t!=null&&this.zpp_inner.addBody(t.zpp_inner),this.zpp_inner.wake(),t?.zpp_inner.wake();}return t}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e;}};function O(n){let{typeName:e,namespaceParts:t,zppListClass:r,wrapElement:i,unwrapElement:p}=n,s=chunkKHH45HMB_cjs.E(),a=s.__zpp,c=()=>a.util[r],f=()=>{let _=s;for(let h=1;h<t.length;h++)_=_[t[h]];return _};function u(){if(this.zpp_next=null,this.zpp_critical=false,this.zpp_i=0,this.zpp_inner=null,!c().internal)throw new Error("Error: Cannot instantiate "+e+"Iterator derp!")}u.zpp_pool=null,u.get=function(_){let h,b=c();return u.zpp_pool==null?(b.internal=true,h=new u,b.internal=false):(h=u.zpp_pool,u.zpp_pool=h.zpp_next),h.zpp_i=0,h.zpp_inner=_,h.zpp_critical=false,h},u.prototype.zpp_inner=null,u.prototype.zpp_i=null,u.prototype.zpp_critical=null,u.prototype.zpp_next=null,u.prototype.hasNext=function(){this.zpp_inner.zpp_inner.valmod();let _=this.zpp_inner;_.zpp_inner.valmod(),_.zpp_inner.zip_length&&(_.zpp_inner.zip_length=false,_.zpp_inner.user_length=_.zpp_inner.inner.length);let h=_.zpp_inner.user_length;return this.zpp_critical=true,this.zpp_i<h?true:(this.zpp_next=u.zpp_pool,u.zpp_pool=this,this.zpp_inner=null,false)},u.prototype.next=function(){return this.zpp_critical=false,this.zpp_inner.at(this.zpp_i++)};function m(){this.zpp_inner=null,this.zpp_inner=new(c()),this.zpp_inner.outer=this;}m.fromArray=function(_){if(_==null)throw new Error("Error: Cannot convert null Array to Nape list");let h=new m;for(let b=0;b<_.length;b++)h.push(_[b]);return h},m.prototype.zpp_inner=null,m.prototype.zpp_gl=function(){return this.zpp_inner.valmod(),this.zpp_inner.zip_length&&(this.zpp_inner.zip_length=false,this.zpp_inner.user_length=this.zpp_inner.inner.length),this.zpp_inner.user_length};function y(_){return _.zpp_inner.valmod(),_.zpp_inner.zip_length&&(_.zpp_inner.zip_length=false,_.zpp_inner.user_length=_.zpp_inner.inner.length),_.zpp_inner.user_length}Object.defineProperty(m.prototype,"length",{get:function(){return y(this)}}),m.prototype.has=function(_){return this.zpp_inner.valmod(),this.zpp_inner.inner.has(p(_))},m.prototype.at=function(_){if(this.zpp_inner.valmod(),_<0||_>=y(this))throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(_=y(this)-1-_),_<this.zpp_inner.at_index||this.zpp_inner.at_ite==null)this.zpp_inner.at_index=_,this.zpp_inner.at_ite=this.zpp_inner.inner.iterator_at(_);else for(;this.zpp_inner.at_index!=_;)this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;return i(this.zpp_inner.at_ite.elt)},m.prototype.push=function(_){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let h=this.zpp_inner.adder!=null?this.zpp_inner.adder(_):true;return h&&(this.zpp_inner.reverse_flag?this.zpp_inner.inner.add(p(_)):(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.zpp_inner.inner.head==null?null:this.zpp_inner.inner.iterator_at(y(this)-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,p(_))),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(_)),h},m.prototype.unshift=function(_){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let h=this.zpp_inner.adder!=null?this.zpp_inner.adder(_):true;return h&&(this.zpp_inner.reverse_flag?(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.zpp_inner.inner.head==null?null:this.zpp_inner.inner.iterator_at(y(this)-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,p(_))):this.zpp_inner.inner.add(p(_)),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(_)),h},m.prototype.pop=function(){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");if(this.zpp_inner.modify_test(),this.zpp_inner.inner.head==null)throw new Error("Error: Cannot remove from empty list");this.zpp_inner.valmod();let _;if(this.zpp_inner.reverse_flag){_=this.zpp_inner.inner.head.elt;let h=i(_);this.zpp_inner.subber!=null&&this.zpp_inner.subber(h),this.zpp_inner.dontremove||this.zpp_inner.inner.pop();}else {this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let h;y(this)==1?h=null:h=this.zpp_inner.inner.iterator_at(y(this)-2),_=h==null?this.zpp_inner.inner.head.elt:h.next.elt;let b=i(_);this.zpp_inner.subber!=null&&this.zpp_inner.subber(b),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(h);}return this.zpp_inner.invalidate(),i(_)},m.prototype.shift=function(){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");if(this.zpp_inner.modify_test(),this.zpp_inner.inner.head==null)throw new Error("Error: Cannot remove from empty list");this.zpp_inner.valmod();let _;if(this.zpp_inner.reverse_flag){this.zpp_inner.at_ite!=null&&this.zpp_inner.at_ite.next==null&&(this.zpp_inner.at_ite=null);let h;y(this)==1?h=null:h=this.zpp_inner.inner.iterator_at(y(this)-2),_=h==null?this.zpp_inner.inner.head.elt:h.next.elt;let b=i(_);this.zpp_inner.subber!=null&&this.zpp_inner.subber(b),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(h);}else {_=this.zpp_inner.inner.head.elt;let h=i(_);this.zpp_inner.subber!=null&&this.zpp_inner.subber(h),this.zpp_inner.dontremove||this.zpp_inner.inner.pop();}return this.zpp_inner.invalidate(),i(_)},m.prototype.add=function(_){return this.zpp_inner.reverse_flag?this.push(_):this.unshift(_)},m.prototype.remove=function(_){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let h=false,b=this.zpp_inner.inner.head,G=p(_);for(;b!=null;){if(b.elt==G){h=true;break}b=b.next;}return h&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(_),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(G),this.zpp_inner.invalidate()),h},m.prototype.clear=function(){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");if(this.zpp_inner.reverse_flag)for(;this.zpp_inner.inner.head!=null;)this.pop();else for(;this.zpp_inner.inner.head!=null;)this.shift();},m.prototype.empty=function(){return this.zpp_inner.inner.head==null},m.prototype.iterator=function(){return this.zpp_inner.valmod(),u.get(this)},m.prototype.copy=function(_){_==null&&(_=false);let h=new m,b=u.get(this);for(;b.hasNext();){let G=b.next();if(_)throw new Error("Error: "+e+" is not a copyable type");h.push(G);}return h},m.prototype.merge=function(_){if(_==null)throw new Error("Error: Cannot merge with null list");let h=u.get(_);for(;h.hasNext();){let b=h.next();this.has(b)||(this.zpp_inner.reverse_flag?this.push(b):this.unshift(b));}},m.prototype.toString=function(){let _="[",h=true,b=u.get(this);for(;b.hasNext();){let G=b.next();h||(_+=","),_+=G==null?"NULL":G.toString(),h=false;}return _+"]"},m.prototype.foreach=function(_){if(_==null)throw new Error("Error: Cannot execute null on list elements");this.zpp_inner.valmod();let h=u.get(this);for(;h.hasNext();)try{_(h.next());}catch{h.zpp_next=u.zpp_pool,u.zpp_pool=h,h.zpp_inner=null;break}return this},m.prototype.filter=function(_){if(_==null)throw new Error("Error: Cannot select elements of list with null");let h=0;for(;h<y(this);){let b=this.at(h);try{_(b)?++h:this.remove(b);}catch{break}}return this},m.prototype.toArray=function(){let _=[],h=u.get(this);for(;h.hasNext();)_.push(h.next());return _},m.prototype[Symbol.iterator]=function(){let _=u.get(this);return {next(){return _.hasNext()?{value:_.next(),done:false}:{value:void 0,done:true}},[Symbol.iterator](){return this}}};let g=f(),R=e+"Iterator",J=e+"List";return g[R]=u,g[J]=m,{Iterator:u,List:m}}var X=n=>n.outer,K=n=>n.zpp_inner??(n._inner?n._inner.zpp_inner??n._inner:n);O({typeName:"CbType",namespaceParts:["nape","callbacks"],zppListClass:"ZPP_CbTypeList",wrapElement:X,unwrapElement:K});O({typeName:"Listener",namespaceParts:["nape","callbacks"],zppListClass:"ZPP_ListenerList",wrapElement:X,unwrapElement:K});O({typeName:"Constraint",namespaceParts:["nape","constraint"],zppListClass:"ZPP_ConstraintList",wrapElement:X,unwrapElement:K});O({typeName:"InteractionGroup",namespaceParts:["nape","dynamics"],zppListClass:"ZPP_InteractionGroupList",wrapElement:X,unwrapElement:K});O({typeName:"GeomPoly",namespaceParts:["nape","geom"],zppListClass:"ZPP_GeomPolyList",wrapElement:X,unwrapElement:K});O({typeName:"Body",namespaceParts:["nape","phys"],zppListClass:"ZPP_BodyList",wrapElement:X,unwrapElement:K});O({typeName:"Compound",namespaceParts:["nape","phys"],zppListClass:"ZPP_CompoundList",wrapElement:X,unwrapElement:K});O({typeName:"Shape",namespaceParts:["nape","shape"],zppListClass:"ZPP_ShapeList",wrapElement:X,unwrapElement:K});O({typeName:"Arbiter",namespaceParts:["nape","dynamics"],zppListClass:"ZPP_ArbiterList",wrapElement:n=>n.wrapper(),unwrapElement:K});O({typeName:"Edge",namespaceParts:["nape","shape"],zppListClass:"ZPP_EdgeList",wrapElement:n=>n.wrapper(),unwrapElement:K});O({typeName:"ConvexResult",namespaceParts:["nape","geom"],zppListClass:"ZPP_ConvexResultList",wrapElement:n=>n,unwrapElement:n=>n});O({typeName:"RayResult",namespaceParts:["nape","geom"],zppListClass:"ZPP_RayResultList",wrapElement:n=>n,unwrapElement:n=>n});O({typeName:"Interactor",namespaceParts:["nape","phys"],zppListClass:"ZPP_InteractorList",wrapElement:n=>n.outer_i,unwrapElement:n=>n.zpp_inner_i});function le(n){if(n.outer==null){let e=chunkKHH45HMB_cjs.E();n.outer=new e.geom.Vec2;let t=n.outer.zpp_inner;t.outer!=null&&(t.outer.zpp_inner=null,t.outer=null),t._isimmutable=null,t._validate=null,t._invalidate=null,t.next=chunkKHH45HMB_cjs.l.zpp_pool,chunkKHH45HMB_cjs.l.zpp_pool=t,n.outer.zpp_inner=n;}return n.outer}function L(){this.at_index=0,this.at_ite=null,this.zip_length=false,this._length=0,this.inner=null,E.call(this),this.at_ite=null,this.at_index=0,this.zip_length=true,this._length=0;}for(let n in E.prototype)L.prototype[n]=E.prototype[n];Object.defineProperty(L.prototype,"length",{get:function(){return this.zpp_gl()},configurable:true});L.prototype.inner=null;L.prototype._length=0;L.prototype.zip_length=false;L.prototype.at_ite=null;L.prototype.at_index=0;L.get=function(n,e){e==null&&(e=false);let t=new L;return t.inner=n,t.zpp_inner.immutable=e,t};L.prototype.zpp_gl=function(){if(this.zpp_vm(),this.zip_length){this._length=0;let n=this.inner.next;for(;n!=null;)this._length++,n=n.next;this.zip_length=false;}return this._length};L.prototype.zpp_vm=function(){this.zpp_inner.validate(),this.inner.modified&&(this.zip_length=true,this._length=0,this.at_ite=null);};L.prototype.at=function(n){if(this.zpp_vm(),n<0||n>=this.zpp_gl())throw new Error("Error: Index out of bounds");for(this.zpp_inner.reverse_flag&&(n=this.zpp_gl()-1-n),(n<this.at_index||this.at_ite==null)&&(this.at_index=0,this.at_ite=this.inner.next);this.at_index!==n;)this.at_index++,this.at_ite=this.at_ite.next;return le(this.at_ite)};L.prototype.push=function(n){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.zpp_vm(),n.zpp_inner._inuse)throw new Error("Error: Vec2 is already in use");let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(n):true;if(e){if(this.zpp_inner.reverse_flag)this.inner.add(n.zpp_inner);else {let t=this.inner.iterator_at(this.zpp_gl()-1);this.inner.insert(t,n.zpp_inner);}this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(n);}return e};L.prototype.unshift=function(n){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.zpp_vm(),n.zpp_inner._inuse)throw new Error("Error: Vec2 is already in use");let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(n):true;if(e){if(this.zpp_inner.reverse_flag){let t=this.inner.iterator_at(this.zpp_gl()-1);this.inner.insert(t,n.zpp_inner);}else this.inner.add(n.zpp_inner);this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(n);}return e};L.prototype.pop=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.empty())throw new Error("Error: Cannot remove from empty list");this.zpp_vm();let n;if(this.zpp_inner.reverse_flag){n=this.inner.next;let e=le(n);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.inner.pop();}else {this.at_ite!=null&&this.at_ite.next==null&&(this.at_ite=null);let e=this.zpp_gl()===1?null:this.inner.iterator_at(this.zpp_gl()-2);n=e==null?this.inner.next:e.next;let t=le(n);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.inner.erase(e);}return this.zpp_inner.invalidate(),le(n)};L.prototype.shift=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.empty())throw new Error("Error: Cannot remove from empty list");this.zpp_vm();let n;if(this.zpp_inner.reverse_flag){this.at_ite!=null&&this.at_ite.next==null&&(this.at_ite=null);let e=this.zpp_gl()===1?null:this.inner.iterator_at(this.zpp_gl()-2);n=e==null?this.inner.next:e.next;let t=le(n);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.inner.erase(e);}else {n=this.inner.next;let e=le(n);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.inner.pop();}return this.zpp_inner.invalidate(),le(n)};L.prototype.remove=function(n){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=false,t=this.inner.next;for(;t!=null;){if(n.zpp_inner===t){e=true;break}t=t.next;}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(n),this.zpp_inner.dontremove||this.inner.remove(n.zpp_inner),this.zpp_inner.invalidate()),e};L.prototype.clear=function(){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.reverse_flag)for(;!this.empty();)this.pop();else for(;!this.empty();)this.shift();};var _n=chunkKHH45HMB_cjs.E(),un=_n.__zpp;un.util.ZPP_MixVec2List=L;var z=chunkKHH45HMB_cjs.E();z.Config=Object.assign(z.Config||{},Pt);z.util.Debug=Xe;z.geom.Vec2=chunkKHH45HMB_cjs.H;z.geom.Vec3=chunkKHH45HMB_cjs.I;z.geom.Mat23=fe;z.geom.MatMN=chunkKHH45HMB_cjs.J;z.geom.AABB=chunkKHH45HMB_cjs.K;z.geom.Winding=chunkKHH45HMB_cjs.L;z.geom.Ray=q;z.geom.ConvexResult=ze;z.geom.RayResult=de;z.geom.Geom=Se;z.geom.GeomPoly=chunkKHH45HMB_cjs.N;z.geom.MarchingSquares=Ze;z.geom.Vec2Iterator=I;z.geom.Vec2List=E;z.geom.GeomVertexIterator=pe;z.__zpp.geom.ZPP_GeomVertexIterator=chunkKHH45HMB_cjs.M;z.__zpp.util.ZPP_ContactList=Y;z.phys.Interactor=chunkKHH45HMB_cjs.R;z.phys.Body=chunkKHH45HMB_cjs._;chunkKHH45HMB_cjs.O(n=>chunkKHH45HMB_cjs._._wrap(n));z.phys.BodyType=chunkKHH45HMB_cjs.$;z.phys.Compound=chunkKHH45HMB_cjs.aa;chunkKHH45HMB_cjs.Q(n=>chunkKHH45HMB_cjs.aa._wrap(n));z.phys.FluidProperties=chunkKHH45HMB_cjs.T;z.phys.Material=chunkKHH45HMB_cjs.ba;z.phys.GravMassMode=chunkKHH45HMB_cjs.ca;z.phys.InertiaMode=chunkKHH45HMB_cjs.da;z.phys.MassMode=chunkKHH45HMB_cjs.ea;z.shape.Shape=chunkKHH45HMB_cjs.V;chunkKHH45HMB_cjs.P(n=>chunkKHH45HMB_cjs.V._wrap(n));z.shape.Circle=chunkKHH45HMB_cjs.fa;z.shape.Polygon=chunkKHH45HMB_cjs.ga;z.shape.Capsule=chunkKHH45HMB_cjs.ha;z.shape.Edge=be;z.shape.ShapeType=chunkKHH45HMB_cjs.U;z.shape.ValidationResult=ge;z.space.Space=chunkKHH45HMB_cjs.X;z.space.Broadphase=chunkKHH45HMB_cjs.ia;z.dynamics.InteractionFilter=chunkKHH45HMB_cjs.ja;z.dynamics.InteractionGroup=we;z.dynamics.ArbiterType=Ee;z.dynamics.Arbiter=j;chunkKHH45HMB_cjs.t._createColArb=()=>new Ve;chunkKHH45HMB_cjs.t._createFluidArb=()=>new Oe;z.dynamics.Contact=Pe;z.dynamics.ContactIterator=v;z.dynamics.ContactList=A;z.callbacks.CbEvent=C;z.callbacks.CbType=Ce;z.callbacks.InteractionType=Z;z.callbacks.PreFlag=W;z.callbacks.OptionType=xe;z.callbacks.Listener=B;z.callbacks.ListenerType=ve;z.callbacks.Callback=F;chunkKHH45HMB_cjs.d._createBodyCb=()=>new Re;chunkKHH45HMB_cjs.d._createConCb=()=>new ke;chunkKHH45HMB_cjs.d._createIntCb=()=>new Be;chunkKHH45HMB_cjs.d._createPreCb=()=>new Fe;z.callbacks.BodyListener=Ge;z.callbacks.ConstraintListener=De;z.callbacks.InteractionListener=Ue;z.callbacks.PreListener=ae;z.constraint.Constraint=chunkKHH45HMB_cjs.ka;chunkKHH45HMB_cjs.k._createFn=(...n)=>new chunkKHH45HMB_cjs.la(...n);chunkKHH45HMB_cjs.m._createFn=(...n)=>new chunkKHH45HMB_cjs.ma(...n);chunkKHH45HMB_cjs.n._createFn=(...n)=>new chunkKHH45HMB_cjs.na(...n);chunkKHH45HMB_cjs.o._createFn=(...n)=>new chunkKHH45HMB_cjs.oa(...n);chunkKHH45HMB_cjs.p._createFn=(...n)=>new chunkKHH45HMB_cjs.pa(...n);chunkKHH45HMB_cjs.q._createFn=(...n)=>new chunkKHH45HMB_cjs.qa(...n);chunkKHH45HMB_cjs.s._createFn=(...n)=>new chunkKHH45HMB_cjs.ra(...n);z.constraint.UserConstraint=We;var Ct=class{drawSegment(e,t,r){}drawCircle(e,t,r){}drawSolidCircle(e,t,r,i){}drawPolygon(e,t){}drawSolidPolygon(e,t){}drawCapsule(e,t,r,i){}drawSolidCapsule(e,t,r,i){}drawPoint(e,t){}};function hn(n,e){if(n==null)throw new Error("Error: vertices cannot be null");let t;if(n instanceof chunkKHH45HMB_cjs.N){if(n.zpp_disp)throw new Error("Error: GeomPoly has been disposed and cannot be used!");t=n.copy();}else {if(!Array.isArray(n))throw new Error("Error: vertices must be an Array<Vec2> or GeomPoly");if(n.length<3)throw new Error("Error: At least 3 vertices are required, got "+n.length);for(let f=0;f<n.length;f++)if(n[f]==null)throw new Error("Error: vertices["+f+"] is null");t=new chunkKHH45HMB_cjs.N(n);}if(t.size()<3)throw t.dispose(),new Error("Error: At least 3 vertices are required, got "+t.size());if(t.isDegenerate())throw t.dispose(),new Error("Error: Polygon is degenerate (zero area)");if(!t.isSimple())throw t.dispose(),new Error("Error: Polygon is self-intersecting");let r=e?.simplify??0;if(r>0){let f=t.simplify(r);if(t.dispose(),t=f,t.size()<3||t.isDegenerate())throw t.dispose(),new Error("Error: Polygon became degenerate after simplification (epsilon too large)")}if(!t.isClockwise()){let f=[],u=t.forwardIterator();for(;u.hasNext();){let m=u.next();f.push(chunkKHH45HMB_cjs.H.get(m.x,m.y));}t.dispose(),f.reverse(),t=new chunkKHH45HMB_cjs.N(f);}let i=e?.material,p=e?.filter,s=e?.delaunay??false,a=new chunkKHH45HMB_cjs._(e?.type??chunkKHH45HMB_cjs.$.DYNAMIC,e?.position);if(t.isConvex())return a.shapes.add(new chunkKHH45HMB_cjs.ga(t,i,p)),t.dispose(),a;let c=t.convexDecomposition(s);for(let f of c)a.shapes.add(new chunkKHH45HMB_cjs.ga(f,i,p));return t.dispose(),a}var xt=class{constructor(e,t,r={}){this._oneWayListener=null;this._grounded=false;this._groundNormal=null;this._groundBody=null;this._onMovingPlatform=false;this._slopeAngle=0;this._wallLeft=false;this._wallRight=false;this._timeSinceGrounded=0;this.space=e,this.body=t,this._maxSlopeAngle=r.maxSlopeAngle??Math.PI/4,this._maxSlopeCos=Math.cos(this._maxSlopeAngle);let i=256;if(r.filter)this._filter=r.filter;else {let p=t.shapes;for(let s=0;s<p.length;s++){let c=p.at(s).filter;c.collisionGroup=c.collisionGroup|i;}this._filter=new chunkKHH45HMB_cjs.ja(1,~i);}r.oneWayPlatformTag&&r.characterTag&&this._setupOneWayPlatforms(r.oneWayPlatformTag,r.characterTag);}get grounded(){return this._grounded}get groundNormal(){return this._groundNormal}get groundBody(){return this._groundBody}get timeSinceGrounded(){return this._timeSinceGrounded}get maxSlopeAngle(){return this._maxSlopeAngle}set maxSlopeAngle(e){this._maxSlopeAngle=e,this._maxSlopeCos=Math.cos(e);}setVelocity(e,t){this.body.velocity=new chunkKHH45HMB_cjs.H(e,t);}update(){this._wallLeft=false,this._wallRight=false;let e=this.body.position.x,t=this.body.position.y;return this._detectGround(e,t),this._detectWalls(e,t),this._grounded&&this._groundBody?this._onMovingPlatform=this._groundBody.type===chunkKHH45HMB_cjs.$.KINEMATIC:this._onMovingPlatform=false,this._grounded?this._timeSinceGrounded=0:this._timeSinceGrounded+=1/60,{grounded:this._grounded,groundNormal:this._groundNormal,groundBody:this._groundBody,onMovingPlatform:this._onMovingPlatform,slopeAngle:this._slopeAngle,wallLeft:this._wallLeft,wallRight:this._wallRight,timeSinceGrounded:this._timeSinceGrounded}}destroy(){this._oneWayListener&&(this._oneWayListener.space=null,this._oneWayListener=null);}_detectGround(e,t){let i=this._getCharacterRadius(0,1)+4,p=new q(new chunkKHH45HMB_cjs.H(e,t),new chunkKHH45HMB_cjs.H(0,1));p.maxDistance=i;let s=this.space.rayCast(p,false,this._filter);if(s&&s.distance<=i){let a=s.normal.y;if(a<0){let c=-a;if(c>=this._maxSlopeCos){this._grounded=true,this._groundNormal=new chunkKHH45HMB_cjs.H(s.normal.x,s.normal.y),this._groundBody=s.shape?.body??null,this._slopeAngle=Math.acos(Math.min(1,c));return}}}this._grounded=false,this._groundNormal=null,this._groundBody=null,this._slopeAngle=0;}_detectWalls(e,t){let i=this._getCharacterRadius(1,0)+2,p=new q(new chunkKHH45HMB_cjs.H(e,t),new chunkKHH45HMB_cjs.H(-1,0));p.maxDistance=i;let s=this.space.rayCast(p,false,this._filter);s&&s.distance<=i&&Math.abs(s.normal.x)>.7&&(this._wallLeft=true);let a=new q(new chunkKHH45HMB_cjs.H(e,t),new chunkKHH45HMB_cjs.H(1,0));a.maxDistance=i;let c=this.space.rayCast(a,false,this._filter);c&&c.distance<=i&&Math.abs(c.normal.x)>.7&&(this._wallRight=true);}_setupOneWayPlatforms(e,t){let r=new ae(Z.COLLISION,e,t,i=>{try{let p=i.arbiter.collisionArbiter;if(!p)return W.ACCEPT;let s=p.normal.y,a=i.swapped;return s>0!==a?W.IGNORE:W.ACCEPT}catch{return W.ACCEPT}},0,true);r.space=this.space,this._oneWayListener=r;}_getCharacterRadius(e,t){let r=this.body.shapes.at(0);if(!r)return 0;if(r.isCircle())return r.castCircle?.radius??0;if(r.isCapsule()){let a=r.castCapsule;if(a){let c=a.radius,f=a.halfLength,u=this.body.rotation,m=Math.cos(u),y=Math.sin(u);return Math.abs(e*m+t*y)*f+c}}let i=r.bounds,p=i.width/2,s=i.height/2;return Math.abs(e)*p+Math.abs(t)*s}};var Xp="3.20.0";Object.defineProperty(exports,"AABB",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.K}});Object.defineProperty(exports,"AngleJoint",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.la}});Object.defineProperty(exports,"Body",{enumerable:true,get:function(){return chunkKHH45HMB_cjs._}});Object.defineProperty(exports,"BodyType",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.$}});Object.defineProperty(exports,"Broadphase",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ia}});Object.defineProperty(exports,"Capsule",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ha}});Object.defineProperty(exports,"Circle",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.fa}});Object.defineProperty(exports,"Compound",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.aa}});Object.defineProperty(exports,"Constraint",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ka}});Object.defineProperty(exports,"DebugDrawFlags",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.W}});Object.defineProperty(exports,"DistanceJoint",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ma}});Object.defineProperty(exports,"FluidProperties",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.T}});Object.defineProperty(exports,"GeomPoly",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.N}});Object.defineProperty(exports,"GravMassMode",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ca}});Object.defineProperty(exports,"InertiaMode",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.da}});Object.defineProperty(exports,"InteractionFilter",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ja}});Object.defineProperty(exports,"Interactor",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.R}});Object.defineProperty(exports,"LineJoint",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.na}});Object.defineProperty(exports,"MassMode",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ea}});Object.defineProperty(exports,"MatMN",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.J}});Object.defineProperty(exports,"Material",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ba}});Object.defineProperty(exports,"MotorJoint",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.oa}});Object.defineProperty(exports,"NapeList",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.S}});Object.defineProperty(exports,"PivotJoint",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.pa}});Object.defineProperty(exports,"Polygon",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ga}});Object.defineProperty(exports,"PulleyJoint",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.qa}});Object.defineProperty(exports,"Shape",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.V}});Object.defineProperty(exports,"ShapeType",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.U}});Object.defineProperty(exports,"Space",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.X}});Object.defineProperty(exports,"Vec2",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.H}});Object.defineProperty(exports,"Vec3",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.I}});Object.defineProperty(exports,"WeldJoint",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.ra}});Object.defineProperty(exports,"Winding",{enumerable:true,get:function(){return chunkKHH45HMB_cjs.L}});exports.Arbiter=j;exports.ArbiterType=Ee;exports.BodyCallback=Re;exports.BodyListener=Ge;exports.Callback=F;exports.CbEvent=C;exports.CbType=Ce;exports.CharacterController=xt;exports.CollisionArbiter=Ve;exports.ConstraintCallback=ke;exports.ConstraintListener=De;exports.Contact=Pe;exports.ConvexResult=ze;exports.DebugDraw=Ct;exports.Edge=be;exports.FluidArbiter=Oe;exports.Geom=Se;exports.InteractionCallback=Be;exports.InteractionGroup=we;exports.InteractionListener=Ue;exports.InteractionType=Z;exports.Listener=B;exports.ListenerType=ve;exports.MarchingSquares=Ze;exports.Mat23=fe;exports.OptionType=xe;exports.PreCallback=Fe;exports.PreFlag=W;exports.PreListener=ae;exports.Ray=q;exports.RayResult=de;exports.UserConstraint=We;exports.VERSION=Xp;exports.ValidationResult=ge;exports.createConcaveBody=hn;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|